net: wireless: rockchip_wlan: add rtl8723bs support
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723bs / hal / btc / HalBtc8703b2Ant.c
1 //============================================================\r
2 // Description:\r
3 //\r
4 // This file is for RTL8703B 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 "HalBtc8703b2Ant.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_8703B_2ANT               GLCoexDm8703b2Ant;\r
25 static PCOEX_DM_8703B_2ANT      pCoexDm=&GLCoexDm8703b2Ant;\r
26 static COEX_STA_8703B_2ANT              GLCoexSta8703b2Ant;\r
27 static PCOEX_STA_8703B_2ANT     pCoexSta=&GLCoexSta8703b2Ant;\r
28 \r
29 const char *const GLBtInfoSrc8703b2Ant[]={\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  GLCoexVerDate8703b2Ant=20140903;\r
36 u4Byte  GLCoexVer8703b2Ant=0x43;\r
37 \r
38 //============================================================\r
39 // local function proto type if needed\r
40 //============================================================\r
41 //============================================================\r
42 // local function start with halbtc8703b2ant_\r
43 //============================================================\r
44 u1Byte\r
45 halbtc8703b2ant_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_8703B_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_8703B_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_8703B_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 halbtc8703b2ant_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_8703B_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_8703B_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_8703B_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 halbtc8703b2ant_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 halbtc8703b2ant_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 halbtc8703b2ant_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 halbtc8703b2ant_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 halbtc8703b2ant_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 halbtc8703b2ant_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 = halbtc8703b2ant_WifiRssiState(pBtCoexist,3, 2, BT_8703B_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 halbtc8703b2ant_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_8703B_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 halbtc8703b2ant_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_8703B_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_8703B_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_8703B_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_8703B_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_8703B_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_8703B_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_8703B_2ANT_COEX_ALGO_PANEDR_HID;\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_8703B_2ANT_COEX_ALGO_PANEDR_HID;\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_8703B_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_8703B_2ANT_COEX_ALGO_PANEDR_HID;\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_8703B_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_8703B_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_8703B_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_8703B_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_8703B_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_8703B_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 ==> HID\n"));\r
685                                 algorithm = BT_8703B_2ANT_COEX_ALGO_PANEDR_HID;\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)\n"));\r
693                                         algorithm = BT_8703B_2ANT_COEX_ALGO_PANEDR_HID;\r
694                                 }\r
695                                 else\r
696                                 {\r
697                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + HID + PAN(EDR)\n"));\r
698                                         algorithm = BT_8703B_2ANT_COEX_ALGO_PANEDR_HID;\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_8703B_2ANT_COEX_ALGO_PANEDR_HID;\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_8703B_2ANT_COEX_ALGO_PANEDR_HID;\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_8703B_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_8703B_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_8703B_2ANT_COEX_ALGO_PANEDR_HID;\r
752                                 }\r
753                         }\r
754                 }\r
755         }\r
756 \r
757         return algorithm;\r
758 }\r
759 \r
760 VOID\r
761 halbtc8703b2ant_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 halbtc8703b2ant_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 halbtc8703b2ant_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         halbtc8703b2ant_SetFwDecBtPwr(pBtCoexist, pCoexDm->curBtDecPwrLvl);\r
811 \r
812         pCoexDm->preBtDecPwrLvl = pCoexDm->curBtDecPwrLvl;\r
813 }\r
814 \r
815 VOID\r
816 halbtc8703b2ant_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 halbtc8703b2ant_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         halbtc8703b2ant_SetBtAutoReport(pBtCoexist, pCoexDm->bCurBtAutoReport);\r
853 \r
854         pCoexDm->bPreBtAutoReport = pCoexDm->bCurBtAutoReport;\r
855 }\r
856 \r
857 VOID\r
858 halbtc8703b2ant_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         halbtc8703b2ant_SetFwDacSwingLevel(pBtCoexist, pCoexDm->curFwDacSwingLvl);\r
875 \r
876         pCoexDm->preFwDacSwingLvl = pCoexDm->curFwDacSwingLvl;\r
877 }\r
878 \r
879 VOID\r
880 halbtc8703b2ant_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 halbtc8703b2ant_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         halbtc8703b2ant_SetSwRfRxLpfCorner(pBtCoexist, pCoexDm->bCurRfRxLpfShrink);\r
920 \r
921         pCoexDm->bPreRfRxLpfShrink = pCoexDm->bCurRfRxLpfShrink;\r
922 }\r
923 \r
924 VOID\r
925 halbtc8703b2ant_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 halbtc8703b2ant_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         halbtc8703b2ant_SetSwPenaltyTxRateAdaptive(pBtCoexist, pCoexDm->bCurLowPenaltyRa);\r
967 \r
968         pCoexDm->bPreLowPenaltyRa = pCoexDm->bCurLowPenaltyRa;\r
969 }\r
970 \r
971 VOID\r
972 halbtc8703b2ant_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, 0x883, 0x3e, val);\r
981 }\r
982 \r
983 VOID\r
984 halbtc8703b2ant_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                 halbtc8703b2ant_SetDacSwingReg(pBtCoexist, swDacSwingLvl);\r
993         }\r
994         else\r
995         {\r
996                 halbtc8703b2ant_SetDacSwingReg(pBtCoexist, 0x18);\r
997         }\r
998 }\r
999 \r
1000 \r
1001 VOID\r
1002 halbtc8703b2ant_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         halbtc8703b2ant_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 halbtc8703b2ant_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, 0xc05, 0x30, 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, 0xc05, 0x30, 0x1);\r
1042         }\r
1043 }\r
1044 \r
1045 VOID\r
1046 halbtc8703b2ant_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         halbtc8703b2ant_SetAdcBackOff(pBtCoexist, pCoexDm->bCurAdcBackOff);\r
1062 \r
1063         pCoexDm->bPreAdcBackOff = pCoexDm->bCurAdcBackOff;\r
1064 }\r
1065 \r
1066 VOID\r
1067 halbtc8703b2ant_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 halbtc8703b2ant_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         halbtc8703b2ant_SetAgcTable(pBtCoexist, bAgcTableEn);\r
1155 \r
1156         pCoexDm->bPreAgcTableEn = pCoexDm->bCurAgcTableEn;\r
1157 }\r
1158 \r
1159 VOID\r
1160 halbtc8703b2ant_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 halbtc8703b2ant_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         halbtc8703b2ant_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 halbtc8703b2ant_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                         halbtc8703b2ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x55555555, 0xffffff, 0x3);\r
1227                         break;\r
1228                 case 1:\r
1229                         halbtc8703b2ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x5afa5afa, 0xffffff, 0x3);\r
1230                         break;\r
1231                 case 2:\r
1232                         halbtc8703b2ant_CoexTable(pBtCoexist, bForceExec, 0x5ada5ada, 0x5ada5ada, 0xffffff, 0x3);\r
1233                         break;\r
1234                 case 3:\r
1235                         halbtc8703b2ant_CoexTable(pBtCoexist, bForceExec, 0xaaaaaaaa, 0xaaaaaaaa, 0xffffff, 0x3);\r
1236                         break;\r
1237                 case 4:\r
1238                         halbtc8703b2ant_CoexTable(pBtCoexist, bForceExec, 0xffffffff, 0xffffffff, 0xffffff, 0x3);\r
1239                         break;\r
1240                 case 5:\r
1241                         halbtc8703b2ant_CoexTable(pBtCoexist, bForceExec, 0x5fff5fff, 0x5fff5fff, 0xffffff, 0x3);\r
1242                         break;\r
1243                 case 6:\r
1244                         halbtc8703b2ant_CoexTable(pBtCoexist, bForceExec, 0x55ff55ff, 0x5a5a5a5a, 0xffffff, 0x3);\r
1245                         break;\r
1246                 case 7:\r
1247                         halbtc8703b2ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3);\r
1248                         break;\r
1249                 case 8:\r
1250                         halbtc8703b2ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3);\r
1251                         break;\r
1252                 case 9:\r
1253                         halbtc8703b2ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3);\r
1254                         break;\r
1255                 case 10:\r
1256                         halbtc8703b2ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3);\r
1257                         break;\r
1258                 case 11:\r
1259                         halbtc8703b2ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3);\r
1260                         break;\r
1261                 case 12:\r
1262                         halbtc8703b2ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3);\r
1263                         break;\r
1264                 case 13:\r
1265                         halbtc8703b2ant_CoexTable(pBtCoexist, bForceExec, 0x5fff5fff, 0xaaaaaaaa, 0xffffff, 0x3);\r
1266                         break;\r
1267                 case 14:\r
1268                         halbtc8703b2ant_CoexTable(pBtCoexist, bForceExec, 0x5fff5fff, 0x5ada5ada, 0xffffff, 0x3);\r
1269                         break;\r
1270                 case 15:\r
1271                         halbtc8703b2ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0xaaaaaaaa, 0xffffff, 0x3);\r
1272                         break;\r
1273                 default:\r
1274                         break;\r
1275         }\r
1276 }\r
1277 \r
1278 VOID\r
1279 halbtc8703b2ant_SetFwIgnoreWlanAct(\r
1280         IN      PBTC_COEXIST            pBtCoexist,\r
1281         IN      BOOLEAN                 bEnable\r
1282         )\r
1283 {\r
1284         u1Byte                  H2C_Parameter[1] ={0};\r
1285                 \r
1286         if(bEnable)\r
1287         {\r
1288                 H2C_Parameter[0] |= BIT0;               // function enable\r
1289         }\r
1290         \r
1291         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63=0x%x\n", \r
1292                 H2C_Parameter[0]));\r
1293 \r
1294         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x63, 1, H2C_Parameter);\r
1295 }\r
1296 \r
1297 VOID\r
1298 halbtc8703b2ant_SetLpsRpwm(\r
1299         IN      PBTC_COEXIST            pBtCoexist,\r
1300         IN      u1Byte                  lpsVal,\r
1301         IN      u1Byte                  rpwmVal\r
1302         )\r
1303 {\r
1304         u1Byte  lps=lpsVal;\r
1305         u1Byte  rpwm=rpwmVal;\r
1306         \r
1307         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_LPS_VAL, &lps);\r
1308         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RPWM_VAL, &rpwm);\r
1309 }\r
1310 \r
1311 VOID\r
1312 halbtc8703b2ant_LpsRpwm(\r
1313         IN      PBTC_COEXIST            pBtCoexist,\r
1314         IN      BOOLEAN                 bForceExec,\r
1315         IN      u1Byte                  lpsVal,\r
1316         IN      u1Byte                  rpwmVal\r
1317         )\r
1318 {\r
1319         BOOLEAN bForceExecPwrCmd=FALSE;\r
1320         \r
1321         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s set lps/rpwm=0x%x/0x%x \n", \r
1322                 (bForceExec? "force to":""), lpsVal, rpwmVal));\r
1323         pCoexDm->curLps = lpsVal;\r
1324         pCoexDm->curRpwm = rpwmVal;\r
1325 \r
1326         if(!bForceExec)\r
1327         {\r
1328                 if( (pCoexDm->preLps == pCoexDm->curLps) &&\r
1329                         (pCoexDm->preRpwm == pCoexDm->curRpwm) )\r
1330                 {\r
1331                         return;\r
1332                 }\r
1333         }\r
1334         halbtc8703b2ant_SetLpsRpwm(pBtCoexist, lpsVal, rpwmVal);\r
1335 \r
1336         pCoexDm->preLps = pCoexDm->curLps;\r
1337         pCoexDm->preRpwm = pCoexDm->curRpwm;\r
1338 }\r
1339 \r
1340 VOID\r
1341 halbtc8703b2ant_IgnoreWlanAct(\r
1342         IN      PBTC_COEXIST            pBtCoexist,\r
1343         IN      BOOLEAN                 bForceExec,\r
1344         IN      BOOLEAN                 bEnable\r
1345         )\r
1346 {\r
1347         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn Ignore WlanAct %s\n", \r
1348                 (bForceExec? "force to":""), (bEnable? "ON":"OFF")));\r
1349         pCoexDm->bCurIgnoreWlanAct = bEnable;\r
1350 \r
1351         if(!bForceExec)\r
1352         {\r
1353                 if(pCoexDm->bPreIgnoreWlanAct == pCoexDm->bCurIgnoreWlanAct)\r
1354                         return;\r
1355         }\r
1356         halbtc8703b2ant_SetFwIgnoreWlanAct(pBtCoexist, bEnable);\r
1357 \r
1358         pCoexDm->bPreIgnoreWlanAct = pCoexDm->bCurIgnoreWlanAct;\r
1359 }\r
1360 \r
1361 VOID\r
1362 halbtc8703b2ant_SetFwPstdma(\r
1363         IN      PBTC_COEXIST            pBtCoexist,\r
1364         IN      u1Byte                  byte1,\r
1365         IN      u1Byte                  byte2,\r
1366         IN      u1Byte                  byte3,\r
1367         IN      u1Byte                  byte4,\r
1368         IN      u1Byte                  byte5\r
1369         )\r
1370 {\r
1371         u1Byte                  H2C_Parameter[5] ={0};\r
1372 \r
1373 \r
1374          if ( (pCoexSta->bA2dpExist) && (pCoexSta->bHidExist) )\r
1375          {\r
1376                 byte5 = byte5 | 0x1;\r
1377          }\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 halbtc8703b2ant_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         //halbtc8703b2ant_RfShrink(pBtCoexist, NORMAL_EXEC, bShrinkRxLPF);\r
1420         halbtc8703b2ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, bLowPenaltyRA);\r
1421 }\r
1422 \r
1423 VOID\r
1424 halbtc8703b2ant_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         //halbtc8703b2ant_AgcTable(pBtCoexist, NORMAL_EXEC, bAGCTableShift);\r
1433         //halbtc8703b2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, bADCBackOff);\r
1434         //halbtc8703b2ant_DacSwing(pBtCoexist, NORMAL_EXEC, bSWDACSwing, dacSwingLvl);\r
1435 }\r
1436 \r
1437 VOID\r
1438 halbtc8703b2ant_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                  fwVer=0, u4Tmp=0;\r
1447         BOOLEAN                 bPgExtSwitch=FALSE;\r
1448         BOOLEAN                 bUseExtSwitch=FALSE;\r
1449         u1Byte                  H2C_Parameter[2] ={0};\r
1450 \r
1451         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_EXT_SWITCH, &bPgExtSwitch);\r
1452         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);        // [31:16]=fw ver, [15:0]=fw sub ver\r
1453 \r
1454         if((fwVer>0 && fwVer<0xc0000) || bPgExtSwitch)\r
1455                 bUseExtSwitch = TRUE;\r
1456 \r
1457         if(bInitHwCfg)\r
1458         {\r
1459                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x39, 0x8, 0x1);\r
1460                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x974, 0xff);\r
1461                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x944, 0x3, 0x3);\r
1462                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x930, 0x77);\r
1463                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x1);\r
1464 \r
1465                 if(fwVer >= 0x180000)\r
1466                 {\r
1467                         /* Use H2C to set GNT_BT to High to avoid A2DP click */\r
1468                         H2C_Parameter[0] = 1;\r
1469                 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x6E, 1, H2C_Parameter);\r
1470                 }\r
1471                 else\r
1472                 {\r
1473                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x18);\r
1474                 }\r
1475                 \r
1476                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);\r
1477 \r
1478                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); //WiFi TRx Mask off\r
1479                 //remove due to interrupt is disabled that polling c2h will fail and delay 100ms.\r
1480                 //pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x3c, 0x01); //BT TRx Mask off\r
1481 \r
1482                 if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)\r
1483                 {\r
1484                         //tell firmware "no antenna inverse"\r
1485                         H2C_Parameter[0] = 0;\r
1486                 }\r
1487                 else\r
1488                 {\r
1489                         //tell firmware "antenna inverse"\r
1490                         H2C_Parameter[0] = 1;\r
1491                 }\r
1492 \r
1493                 if (bUseExtSwitch)\r
1494                 {\r
1495                         //ext switch type\r
1496                         H2C_Parameter[1] = 1;\r
1497                 }\r
1498                 else\r
1499                 {\r
1500                         //int switch type\r
1501                         H2C_Parameter[1] = 0;\r
1502                 }\r
1503                 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter);\r
1504         }\r
1505         else\r
1506         {\r
1507                 if(fwVer >= 0x180000)\r
1508                 {\r
1509                         /* Use H2C to set GNT_BT to "Control by PTA"*/\r
1510                         H2C_Parameter[0] = 0;\r
1511                         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x6E, 1, H2C_Parameter);                    \r
1512                 }\r
1513                 else\r
1514                 {\r
1515                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x0);\r
1516                 }\r
1517         }\r
1518 \r
1519         // ext switch setting\r
1520         if(bUseExtSwitch)\r
1521         {\r
1522                 if (bInitHwCfg)\r
1523                 {\r
1524                         // 0x4c[23]=0, 0x4c[24]=1  Antenna control by WL/BT\r
1525                         u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);\r
1526                         u4Tmp &=~BIT23;\r
1527                         u4Tmp |= BIT24;\r
1528                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);\r
1529                 }\r
1530                 \r
1531                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0); // fixed internal switch S1->WiFi, S0->BT\r
1532                 switch(antPosType)\r
1533                 {\r
1534                         case BTC_ANT_WIFI_AT_MAIN:\r
1535                                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x1); // ext switch main at wifi\r
1536                                 break;\r
1537                         case BTC_ANT_WIFI_AT_AUX:\r
1538                                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x2); // ext switch aux at wifi\r
1539                                 break;\r
1540                 }       \r
1541         }\r
1542         else    // internal switch\r
1543         {\r
1544                 if (bInitHwCfg)\r
1545                 {\r
1546                         // 0x4c[23]=0, 0x4c[24]=1  Antenna control by WL/BT\r
1547                         u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);\r
1548                         u4Tmp |= BIT23;\r
1549                         u4Tmp &=~BIT24;\r
1550                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);\r
1551                 }\r
1552                 \r
1553                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x64, 0x1, 0x0); //fixed external switch S1->Main, S0->Aux\r
1554                 switch(antPosType)\r
1555                 {\r
1556                         case BTC_ANT_WIFI_AT_MAIN:\r
1557                                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0); // fixed internal switch S1->WiFi, S0->BT\r
1558                                 break;\r
1559                         case BTC_ANT_WIFI_AT_AUX:\r
1560                                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x280); // fixed internal switch S0->WiFi, S1->BT\r
1561                                 break;\r
1562                 }\r
1563         }\r
1564 }\r
1565 \r
1566 VOID\r
1567 halbtc8703b2ant_PsTdma(\r
1568         IN      PBTC_COEXIST            pBtCoexist,\r
1569         IN      BOOLEAN                 bForceExec,\r
1570         IN      BOOLEAN                 bTurnOn,\r
1571         IN      u1Byte                  type\r
1572         )\r
1573 {\r
1574         BOOLEAN                 bTurnOnByCnt=FALSE;\r
1575         u1Byte                  psTdmaTypeByCnt=0;\r
1576         u1Byte                  wifiRssiState1, btRssiState;\r
1577 \r
1578         \r
1579         wifiRssiState1 = halbtc8703b2ant_WifiRssiState(pBtCoexist, 1, 2, BT_8703B_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);\r
1580         btRssiState = halbtc8703b2ant_BtRssiState(2, BT_8703B_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);\r
1581 \r
1582         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], %s turn %s PS TDMA, type=%d\n", \r
1583                 (bForceExec? "force to":""), (bTurnOn? "ON":"OFF"), type));\r
1584         pCoexDm->bCurPsTdmaOn = bTurnOn;\r
1585         pCoexDm->curPsTdma = type;\r
1586 \r
1587         if (!(BTC_RSSI_HIGH(wifiRssiState1) && BTC_RSSI_HIGH(btRssiState)) && bTurnOn)\r
1588         {\r
1589                 type = type +100;  //for WiFi RSSI low or BT RSSI low\r
1590                 pCoexDm->bIsSwitchTo1dot5Ant = TRUE;\r
1591         }\r
1592         else\r
1593         {\r
1594                 pCoexDm->bIsSwitchTo1dot5Ant = FALSE;\r
1595         }\r
1596 \r
1597 \r
1598         if(!bForceExec)\r
1599         {\r
1600                 if( (pCoexDm->bPrePsTdmaOn == pCoexDm->bCurPsTdmaOn) &&\r
1601                         (pCoexDm->prePsTdma == pCoexDm->curPsTdma) )\r
1602                         return;\r
1603         }       \r
1604         if(bTurnOn)\r
1605         {\r
1606                 switch(type)\r
1607                 {\r
1608                         case 1:\r
1609                         default:\r
1610                                 //halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x90);\r
1611                                 halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x3c, 0x03, 0xf1, 0x90);\r
1612                                 break;\r
1613                         case 2:\r
1614                                 //halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0xe1, 0x90);\r
1615                                 halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x2d, 0x03, 0xf1, 0x90);\r
1616                                 break;\r
1617                         case 3:\r
1618                                 halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1c, 0x3, 0xf1, 0x90);\r
1619                                 break;\r
1620                         case 4:\r
1621                                 halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x10, 0x03, 0xf1, 0x90);\r
1622                                 break;\r
1623                         case 5:\r
1624                                 //halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0x60, 0x90);\r
1625                                 halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x3c, 0x3, 0x70, 0x90);                           \r
1626                                 break;\r
1627                         case 6:\r
1628                                 //halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0x60, 0x90);\r
1629                                 halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x2d, 0x3, 0x70, 0x90);\r
1630                                 break;\r
1631                         case 7:\r
1632                                 halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1c, 0x3, 0x70, 0x90);\r
1633                                 break;\r
1634                         case 8: \r
1635                                 halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xa3, 0x10, 0x3, 0x70, 0x90);\r
1636                                 break;\r
1637                         case 9: \r
1638                                 //halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x90);\r
1639                                 halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x3c, 0x03, 0xf1, 0x90);\r
1640                                 break;\r
1641                         case 10:        \r
1642                                 //halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0xe1, 0x90);\r
1643                                 halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x2d, 0x03, 0xf1, 0x90);\r
1644                                 break;\r
1645                         case 11:        \r
1646                                 //halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0xa, 0xe1, 0x90);\r
1647                                 halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1c, 0x3, 0xf1, 0x90);\r
1648                                 break;\r
1649                         case 12:\r
1650                                 //halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x5, 0x5, 0xe1, 0x90);\r
1651                                 halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x10, 0x3, 0xf1, 0x90);\r
1652                                 break;\r
1653                         case 13:\r
1654                                 //halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0x60, 0x90);\r
1655                                 halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x3c, 0x3, 0x70, 0x90);           \r
1656                                 break;\r
1657                         case 14:\r
1658                                 //halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0x60, 0x90);\r
1659                                 halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x2d, 0x3, 0x70, 0x90);           \r
1660                                 break;\r
1661                         case 15:\r
1662                                 //halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0xa, 0x60, 0x90);\r
1663                                 halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1c, 0x3, 0x70, 0x90);           \r
1664                                 break;\r
1665                         case 16:\r
1666                                 //halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x5, 0x5, 0x60, 0x90);\r
1667                                 halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x10, 0x3, 0x70, 0x90);           \r
1668                                 break;\r
1669                         case 17:\r
1670                                 halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xa3, 0x2f, 0x2f, 0x60, 0x90);\r
1671                                 break;\r
1672                         case 18:\r
1673                                 halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x5, 0x5, 0xe1, 0x90);\r
1674                                 break;                  \r
1675                         case 19:\r
1676                                 halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x25, 0xe1, 0x90);\r
1677                                 break;\r
1678                         case 20:\r
1679                                 halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x25, 0x60, 0x90);\r
1680                                 break;\r
1681                         case 21:\r
1682                                 halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x15, 0x03, 0x70, 0x90);\r
1683                                 break;  \r
1684                         case 71:\r
1685                                 //halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x90);\r
1686 \r
1687                                 halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x3c, 0x03, 0xf1, 0x90);\r
1688                                 break;\r
1689                         case 101:\r
1690                         case 105:\r
1691                         case 171:       \r
1692                                 halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xd3, 0x3a, 0x03, 0x70, 0x50);\r
1693                                 break;\r
1694                         case 102:\r
1695                         case 106:\r
1696                         case 110:\r
1697                         case 114:       \r
1698                                 halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xd3, 0x2d, 0x03, 0x70, 0x50);\r
1699                                 break;  \r
1700                         case 103:\r
1701                         case 107:\r
1702                         case 111:\r
1703                         case 115:       \r
1704                                 halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xd3, 0x1c, 0x03, 0x70, 0x50);\r
1705                                 break;          \r
1706                         case 104:\r
1707                         case 108:\r
1708                         case 112:\r
1709                         case 116:       \r
1710                                 halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xd3, 0x10, 0x03, 0x70, 0x50);\r
1711                                 break;  \r
1712                         case 109:\r
1713                                 halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x3c, 0x03, 0xf1, 0x90);\r
1714                                 break;\r
1715                         case 113:       \r
1716                                 halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x3c, 0x03, 0x70, 0x90);\r
1717                                 break;\r
1718                         case 121:       \r
1719                                 halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x15, 0x03, 0x70, 0x90);\r
1720                                 break;  \r
1721                         case 22:\r
1722                         case 122:\r
1723                                 halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x35, 0x03, 0x71, 0x11);\r
1724                                 break;\r
1725                 }\r
1726         }\r
1727         else\r
1728         {\r
1729                 // disable PS tdma\r
1730                 switch(type)\r
1731                 {\r
1732                         case 0:\r
1733                                 halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x40, 0x0);\r
1734                                 break;\r
1735                         case 1:\r
1736                                 halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x48, 0x0);\r
1737                                 break;\r
1738                         default:\r
1739                                 halbtc8703b2ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x40, 0x0);\r
1740                                 break;\r
1741                 }\r
1742         }\r
1743 \r
1744         // update pre state\r
1745         pCoexDm->bPrePsTdmaOn = pCoexDm->bCurPsTdmaOn;\r
1746         pCoexDm->prePsTdma = pCoexDm->curPsTdma;\r
1747 }\r
1748 \r
1749 VOID\r
1750 halbtc8703b2ant_PsTdmaCheckForPowerSaveState(\r
1751         IN      PBTC_COEXIST            pBtCoexist,\r
1752         IN      BOOLEAN                 bNewPsState\r
1753         )\r
1754 {\r
1755         u1Byte  lpsMode=0x0;\r
1756 \r
1757         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_LPS_MODE, &lpsMode);\r
1758         \r
1759         if(lpsMode)     // already under LPS state\r
1760         {\r
1761                 if(bNewPsState)         \r
1762                 {\r
1763                         // keep state under LPS, do nothing.\r
1764                 }\r
1765                 else\r
1766                 {\r
1767                         // will leave LPS state, turn off psTdma first\r
1768                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);\r
1769                 }\r
1770         }\r
1771         else                                            // NO PS state\r
1772         {\r
1773                 if(bNewPsState)\r
1774                 {\r
1775                         // will enter LPS state, turn off psTdma first\r
1776                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);\r
1777                 }\r
1778                 else\r
1779                 {\r
1780                         // keep state under NO PS state, do nothing.\r
1781                 }\r
1782         }\r
1783 }\r
1784 \r
1785 VOID\r
1786 halbtc8703b2ant_PowerSaveState(\r
1787         IN      PBTC_COEXIST            pBtCoexist,\r
1788         IN      u1Byte                          psType,\r
1789         IN      u1Byte                          lpsVal,\r
1790         IN      u1Byte                          rpwmVal\r
1791         )\r
1792 {\r
1793         BOOLEAN         bLowPwrDisable=FALSE;\r
1794         \r
1795         switch(psType)\r
1796         {\r
1797                 case BTC_PS_WIFI_NATIVE:\r
1798                         // recover to original 32k low power setting\r
1799                         bLowPwrDisable = FALSE;\r
1800                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
1801                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_NORMAL_LPS, NULL);\r
1802                         pCoexSta->bForceLpsOn = FALSE;\r
1803                         break;\r
1804                 case BTC_PS_LPS_ON:\r
1805                         halbtc8703b2ant_PsTdmaCheckForPowerSaveState(pBtCoexist, TRUE);\r
1806                         halbtc8703b2ant_LpsRpwm(pBtCoexist, NORMAL_EXEC, lpsVal, rpwmVal);                      \r
1807                         // when coex force to enter LPS, do not enter 32k low power.\r
1808                         bLowPwrDisable = TRUE;\r
1809                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
1810                         // power save must executed before psTdma.                      \r
1811                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_ENTER_LPS, NULL);\r
1812                         pCoexSta->bForceLpsOn = TRUE;\r
1813                         break;\r
1814                 case BTC_PS_LPS_OFF:\r
1815                         halbtc8703b2ant_PsTdmaCheckForPowerSaveState(pBtCoexist, FALSE);\r
1816                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_LEAVE_LPS, NULL);\r
1817                         pCoexSta->bForceLpsOn = FALSE;\r
1818                         break;\r
1819                 default:\r
1820                         break;\r
1821         }\r
1822 }\r
1823 \r
1824 \r
1825 VOID\r
1826 halbtc8703b2ant_CoexAllOff(\r
1827         IN      PBTC_COEXIST            pBtCoexist\r
1828         )\r
1829 {\r
1830         // fw all off\r
1831         halbtc8703b2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);               \r
1832         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);\r
1833         halbtc8703b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
1834         halbtc8703b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
1835 \r
1836         // sw all off\r
1837         halbtc8703b2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
1838         halbtc8703b2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
1839 \r
1840         // hw all off\r
1841         //pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);\r
1842         halbtc8703b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
1843 }\r
1844 \r
1845 VOID\r
1846 halbtc8703b2ant_InitCoexDm(\r
1847         IN      PBTC_COEXIST            pBtCoexist\r
1848         )\r
1849 {       \r
1850         // force to reset coex mechanism\r
1851         halbtc8703b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
1852         \r
1853         halbtc8703b2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);               \r
1854         halbtc8703b2ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 1);\r
1855         halbtc8703b2ant_FwDacSwingLvl(pBtCoexist, FORCE_EXEC, 6);\r
1856         halbtc8703b2ant_DecBtPwr(pBtCoexist, FORCE_EXEC, 0);\r
1857 \r
1858         halbtc8703b2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
1859         halbtc8703b2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
1860 }\r
1861 \r
1862 VOID\r
1863 halbtc8703b2ant_ActionBtInquiry(\r
1864         IN      PBTC_COEXIST            pBtCoexist\r
1865         )\r
1866 {\r
1867         u1Byte          wifiRssiState, wifiRssiState1, btRssiState;\r
1868         BOOLEAN bWifiConnected=FALSE;\r
1869         BOOLEAN bLowPwrDisable=TRUE;\r
1870         BOOLEAN         bScan=FALSE, bLink=FALSE, bRoam=FALSE;\r
1871 \r
1872 \r
1873         wifiRssiState = halbtc8703b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
1874         wifiRssiState1 = halbtc8703b2ant_WifiRssiState(pBtCoexist, 1, 2, BT_8703B_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);\r
1875         btRssiState = halbtc8703b2ant_BtRssiState(2, BT_8703B_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);\r
1876         \r
1877         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
1878         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
1879 \r
1880         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);\r
1881         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);\r
1882         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);\r
1883                 \r
1884         \r
1885         halbtc8703b2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);               \r
1886 \r
1887         if(bScan || bLink || bRoam)\r
1888         {\r
1889                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi link process + BT Inq/Page!!\n"));\r
1890                 halbtc8703b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 15);         \r
1891                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 22);\r
1892         }\r
1893         else if(bWifiConnected)\r
1894         {\r
1895                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi connected + BT Inq/Page!!\n"));\r
1896                 halbtc8703b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 15);         \r
1897                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 22);\r
1898         }\r
1899         else\r
1900         {\r
1901                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi no-link + BT Inq/Page!!\n"));\r
1902                 halbtc8703b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
1903                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);\r
1904         }       \r
1905         \r
1906         halbtc8703b2ant_FwDacSwingLvl(pBtCoexist, FORCE_EXEC, 6);\r
1907         halbtc8703b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
1908 \r
1909         halbtc8703b2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
1910         halbtc8703b2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
1911 /*\r
1912         pCoexDm->bNeedRecover0x948 = TRUE;\r
1913         pCoexDm->backup0x948 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x948);\r
1914 \r
1915         halbtc8703b2ant_SetAntPath(pBtCoexist, BTC_ANT_WIFI_AT_AUX, FALSE, FALSE);\r
1916 */      \r
1917 }\r
1918 \r
1919 \r
1920 VOID\r
1921 halbtc8703b2ant_ActionWiFiLinkProcess(\r
1922         IN      PBTC_COEXIST            pBtCoexist\r
1923         )\r
1924 {\r
1925         u4Byte  u4Tmp;\r
1926         u1Byte  u1Tmpa, u1Tmpb;\r
1927         \r
1928         halbtc8703b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 15);         \r
1929         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 22);\r
1930 \r
1931         halbtc8703b2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
1932         halbtc8703b2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
1933 \r
1934 \r
1935          u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x948);\r
1936         u1Tmpa = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x765);\r
1937          u1Tmpb = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x76e);\r
1938 \r
1939          RT_TRACE(COMP_COEX, DBG_LOUD, ("############# [BTCoex], 0x948=0x%x, 0x765=0x%x, 0x76e=0x%x\n",\r
1940                       u4Tmp,  u1Tmpa, u1Tmpb));\r
1941 }\r
1942 \r
1943 BOOLEAN\r
1944 halbtc8703b2ant_ActionWifiIdleProcess(\r
1945         IN      PBTC_COEXIST            pBtCoexist\r
1946         )\r
1947 {       \r
1948         u1Byte          wifiRssiState, wifiRssiState1, btRssiState;\r
1949         u4Byte          wifiBw;\r
1950         u1Byte          apNum=0;\r
1951 \r
1952         wifiRssiState = halbtc8703b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
1953         //wifiRssiState1 = halbtc8703b2ant_WifiRssiState(pBtCoexist, 1, 2, BT_8703B_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);\r
1954         wifiRssiState1 = halbtc8703b2ant_WifiRssiState(pBtCoexist, 1, 2, BT_8703B_2ANT_WIFI_RSSI_COEXSWITCH_THRES-20, 0);\r
1955         btRssiState = halbtc8703b2ant_BtRssiState(2, BT_8703B_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);\r
1956 \r
1957         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_AP_NUM, &apNum);\r
1958 \r
1959         // define the office environment\r
1960         if(BTC_RSSI_HIGH(wifiRssiState1) && \r
1961                         (pCoexSta->bHidExist == TRUE) && (pCoexSta->bA2dpExist == TRUE))\r
1962         {\r
1963 \r
1964                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi  idle process for BT HID+A2DP exist!!\n"));\r
1965                 \r
1966                 halbtc8703b2ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0x6);\r
1967                 halbtc8703b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
1968 \r
1969                 // sw all off\r
1970                 halbtc8703b2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
1971                 halbtc8703b2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
1972 \r
1973                 halbtc8703b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
1974 \r
1975                 halbtc8703b2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);               \r
1976                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);\r
1977 \r
1978                 return TRUE;\r
1979         }\r
1980         else\r
1981         {\r
1982                 halbtc8703b2ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0x18);\r
1983                 return FALSE;   \r
1984         }\r
1985         \r
1986         \r
1987 }\r
1988 \r
1989 \r
1990 \r
1991 BOOLEAN\r
1992 halbtc8703b2ant_IsCommonAction(\r
1993         IN      PBTC_COEXIST            pBtCoexist\r
1994         )\r
1995 {\r
1996         u1Byte                  btRssiState=BTC_RSSI_STATE_HIGH;\r
1997         BOOLEAN                 bCommon=FALSE, bWifiConnected=FALSE, bWifiBusy=FALSE;\r
1998         BOOLEAN                 bBtHsOn=FALSE, bLowPwrDisable=FALSE;\r
1999         BOOLEAN                 bAsus8703b=FALSE;\r
2000 \r
2001         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
2002         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
2003         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
2004 \r
2005         if(!bWifiConnected)\r
2006         {\r
2007                 bLowPwrDisable = FALSE;\r
2008                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
2009                 halbtc8703b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
2010 \r
2011                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi non-connected idle!!\n"));\r
2012 \r
2013                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);\r
2014                 halbtc8703b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
2015                 \r
2016                 halbtc8703b2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);                       \r
2017                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);\r
2018                 halbtc8703b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
2019                 halbtc8703b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
2020                 \r
2021                 halbtc8703b2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
2022                 halbtc8703b2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
2023 \r
2024                 bCommon = TRUE;\r
2025         }\r
2026         else\r
2027         {\r
2028                 if(BT_8703B_2ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)\r
2029                 {\r
2030                         bLowPwrDisable = FALSE;\r
2031                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
2032                         halbtc8703b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
2033 \r
2034                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi connected + BT non connected-idle!!\n"));\r
2035 \r
2036                         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);\r
2037                         halbtc8703b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
2038 \r
2039                         halbtc8703b2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);                       \r
2040                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);              \r
2041                         halbtc8703b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 0xb);\r
2042                         halbtc8703b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
2043 \r
2044                 halbtc8703b2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
2045                         halbtc8703b2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
2046 \r
2047                         bCommon = TRUE;\r
2048                 }\r
2049                 else if(BT_8703B_2ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus)\r
2050                 {\r
2051                         bLowPwrDisable = TRUE;\r
2052                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
2053 \r
2054                         if(bBtHsOn)\r
2055                                 return FALSE;\r
2056                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi connected + BT connected-idle!!\n"));\r
2057                         halbtc8703b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
2058 \r
2059                         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);\r
2060                         halbtc8703b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
2061 \r
2062                         halbtc8703b2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);                       \r
2063                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);\r
2064                         halbtc8703b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 0xb);\r
2065                         halbtc8703b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
2066 \r
2067                         halbtc8703b2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
2068                         halbtc8703b2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
2069 \r
2070                         bCommon = TRUE;\r
2071                 }\r
2072                 else\r
2073                 {\r
2074                         bLowPwrDisable = TRUE;\r
2075                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
2076 \r
2077                         if(bWifiBusy)\r
2078                         {\r
2079                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi Connected-Busy + BT Busy!!\n"));\r
2080 #if 0                           \r
2081                                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_IS_ASUS_8703B, &bAsus8703b);\r
2082                                 if(!bAsus8703b)\r
2083                                         bCommon = FALSE;\r
2084                                 else\r
2085                                         bCommon = halbtc8703b2ant_ActionWifiIdleProcess(pBtCoexist);    \r
2086 #else\r
2087                                 bCommon = FALSE;\r
2088 #endif\r
2089                         }\r
2090                         else\r
2091                         {\r
2092                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi Connected-Idle + BT Busy!!\n"));\r
2093                                 //bCommon = FALSE;      \r
2094                                 bCommon = halbtc8703b2ant_ActionWifiIdleProcess(pBtCoexist);                    \r
2095                         }\r
2096                 }       \r
2097         }\r
2098 \r
2099         return bCommon;\r
2100 }\r
2101 VOID\r
2102 halbtc8703b2ant_TdmaDurationAdjust(\r
2103         IN      PBTC_COEXIST            pBtCoexist,\r
2104         IN      BOOLEAN                 bScoHid,\r
2105         IN      BOOLEAN                 bTxPause,\r
2106         IN      u1Byte                  maxInterval\r
2107         )\r
2108 {\r
2109         static s4Byte           up,dn,m,n,WaitCount;\r
2110         s4Byte                  result;   //0: no change, +1: increase WiFi duration, -1: decrease WiFi duration\r
2111         u1Byte                  retryCount=0;\r
2112 \r
2113         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TdmaDurationAdjust()\n"));\r
2114 \r
2115         if(!pCoexDm->bAutoTdmaAdjust)\r
2116         {\r
2117                 pCoexDm->bAutoTdmaAdjust = TRUE;\r
2118                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], first run TdmaDurationAdjust()!!\n"));\r
2119                 {\r
2120                         if(bScoHid)\r
2121                         {\r
2122                                 if(bTxPause)\r
2123                                 {\r
2124                                         if(maxInterval == 1)\r
2125                                         {\r
2126                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);\r
2127                                                 pCoexDm->psTdmaDuAdjType = 13;  \r
2128                                         }\r
2129                                         else if(maxInterval == 2)\r
2130                                         {\r
2131                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2132                                                 pCoexDm->psTdmaDuAdjType = 14;  \r
2133                                         }\r
2134                                         else if(maxInterval == 3)\r
2135                                         {\r
2136                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2137                                                 pCoexDm->psTdmaDuAdjType = 15;  \r
2138                                         }\r
2139                                         else\r
2140                                         {\r
2141                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2142                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2143                                         }\r
2144                                 }\r
2145                                 else\r
2146                                 {\r
2147                                         if(maxInterval == 1)\r
2148                                         {\r
2149                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
2150                                                 pCoexDm->psTdmaDuAdjType = 9;   \r
2151                                         }\r
2152                                         else if(maxInterval == 2)\r
2153                                         {\r
2154                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2155                                                 pCoexDm->psTdmaDuAdjType = 10;  \r
2156                                         }\r
2157                                         else if(maxInterval == 3)\r
2158                                         {\r
2159                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2160                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2161                                         }\r
2162                                         else\r
2163                                         {\r
2164                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2165                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2166                                         }\r
2167                                 }\r
2168                         }\r
2169                         else\r
2170                         {\r
2171                                 if(bTxPause)\r
2172                                 {\r
2173                                         if(maxInterval == 1)\r
2174                                         {\r
2175                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
2176                                                 pCoexDm->psTdmaDuAdjType = 5;   \r
2177                                         }\r
2178                                         else if(maxInterval == 2)\r
2179                                         {\r
2180                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2181                                                 pCoexDm->psTdmaDuAdjType = 6;   \r
2182                                         }\r
2183                                         else if(maxInterval == 3)\r
2184                                         {\r
2185                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2186                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2187                                         }\r
2188                                         else\r
2189                                         {\r
2190                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2191                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2192                                         }\r
2193                                 }\r
2194                                 else\r
2195                                 {\r
2196                                         if(maxInterval == 1)\r
2197                                         {\r
2198                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
2199                                                 pCoexDm->psTdmaDuAdjType = 1;   \r
2200                                         }\r
2201                                         else if(maxInterval == 2)\r
2202                                         {\r
2203                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2204                                                 pCoexDm->psTdmaDuAdjType = 2;   \r
2205                                         }\r
2206                                         else if(maxInterval == 3)\r
2207                                         {\r
2208                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2209                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2210                                         }\r
2211                                         else\r
2212                                         {\r
2213                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2214                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2215                                         }\r
2216                                 }\r
2217                         }\r
2218                 }\r
2219                 //============\r
2220                 up = 0;\r
2221                 dn = 0;\r
2222                 m = 1;\r
2223                 n= 3;\r
2224                 result = 0;\r
2225                 WaitCount = 0;\r
2226         }\r
2227         else\r
2228         {\r
2229                 //accquire the BT TRx retry count from BT_Info byte2\r
2230                 retryCount = pCoexSta->btRetryCnt;\r
2231                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], retryCount = %d\n", retryCount));\r
2232                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], up=%d, dn=%d, m=%d, n=%d, WaitCount=%d\n", \r
2233                         up, dn, m, n, WaitCount));\r
2234                 result = 0;\r
2235                 WaitCount++; \r
2236                   \r
2237                 if(retryCount == 0)  // no retry in the last 2-second duration\r
2238                 {\r
2239                         up++;\r
2240                         dn--;\r
2241 \r
2242                         if (dn <= 0)\r
2243                                 dn = 0;                          \r
2244 \r
2245                         if(up >= n)     // if ³sÄò n ­Ó2¬í retry count¬°0, «h½Õ¼eWiFi duration\r
2246                         {\r
2247                                 WaitCount = 0; \r
2248                                 n = 3;\r
2249                                 up = 0;\r
2250                                 dn = 0;\r
2251                                 result = 1; \r
2252                                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Increase wifi duration!!\n"));\r
2253                         }\r
2254                 }\r
2255                 else if (retryCount <= 3)       // <=3 retry in the last 2-second duration\r
2256                 {\r
2257                         up--; \r
2258                         dn++;\r
2259 \r
2260                         if (up <= 0)\r
2261                                 up = 0;\r
2262 \r
2263                         if (dn == 2)    // if ³sÄò 2 ­Ó2¬í retry count< 3, «h½Õ¯¶WiFi duration\r
2264                         {\r
2265                                 if (WaitCount <= 2)\r
2266                                         m++; // ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^\r
2267                                 else\r
2268                                         m = 1;\r
2269 \r
2270                                 if ( m >= 20) //m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration.\r
2271                                         m = 20;\r
2272 \r
2273                                 n = 3*m;\r
2274                                 up = 0;\r
2275                                 dn = 0;\r
2276                                 WaitCount = 0;\r
2277                                 result = -1; \r
2278                                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter<3!!\n"));\r
2279                         }\r
2280                 }\r
2281                 else  //retry count > 3, ¥u­n1¦¸ retry count > 3, «h½Õ¯¶WiFi duration\r
2282                 {\r
2283                         if (WaitCount == 1)\r
2284                                 m++; // ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^\r
2285                         else\r
2286                                 m = 1;\r
2287 \r
2288                         if ( m >= 20) //m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration.\r
2289                                 m = 20;\r
2290 \r
2291                         n = 3*m;\r
2292                         up = 0;\r
2293                         dn = 0;\r
2294                         WaitCount = 0; \r
2295                         result = -1;\r
2296                         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter>3!!\n"));\r
2297                 }\r
2298 \r
2299                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], max Interval = %d\n", maxInterval));\r
2300                 if(maxInterval == 1)\r
2301                 {\r
2302                         if(bTxPause)\r
2303                         {\r
2304                                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TxPause = 1\n"));\r
2305 \r
2306                                 if(pCoexDm->curPsTdma == 71)\r
2307                                 {\r
2308                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
2309                                         pCoexDm->psTdmaDuAdjType = 5;\r
2310                                 }\r
2311                                 else if(pCoexDm->curPsTdma == 1)\r
2312                                 {\r
2313                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
2314                                         pCoexDm->psTdmaDuAdjType = 5;\r
2315                                 }\r
2316                                 else if(pCoexDm->curPsTdma == 2)\r
2317                                 {\r
2318                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2319                                         pCoexDm->psTdmaDuAdjType = 6;\r
2320                                 }\r
2321                                 else if(pCoexDm->curPsTdma == 3)\r
2322                                 {\r
2323                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2324                                         pCoexDm->psTdmaDuAdjType = 7;\r
2325                                 }\r
2326                                 else if(pCoexDm->curPsTdma == 4)\r
2327                                 {\r
2328                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
2329                                         pCoexDm->psTdmaDuAdjType = 8;\r
2330                                 }\r
2331                                 if(pCoexDm->curPsTdma == 9)\r
2332                                 {\r
2333                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);\r
2334                                         pCoexDm->psTdmaDuAdjType = 13;\r
2335                                 }\r
2336                                 else if(pCoexDm->curPsTdma == 10)\r
2337                                 {\r
2338                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2339                                         pCoexDm->psTdmaDuAdjType = 14;\r
2340                                 }\r
2341                                 else if(pCoexDm->curPsTdma == 11)\r
2342                                 {\r
2343                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2344                                         pCoexDm->psTdmaDuAdjType = 15;\r
2345                                 }\r
2346                                 else if(pCoexDm->curPsTdma == 12)\r
2347                                 {\r
2348                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
2349                                         pCoexDm->psTdmaDuAdjType = 16;\r
2350                                 }\r
2351                                 \r
2352                                 if(result == -1)\r
2353                                 {                                       \r
2354                                         if(pCoexDm->curPsTdma == 5)\r
2355                                         {\r
2356                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2357                                                 pCoexDm->psTdmaDuAdjType = 6;\r
2358                                         }\r
2359                                         else if(pCoexDm->curPsTdma == 6)\r
2360                                         {\r
2361                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2362                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2363                                         }\r
2364                                         else if(pCoexDm->curPsTdma == 7)\r
2365                                         {\r
2366                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
2367                                                 pCoexDm->psTdmaDuAdjType = 8;\r
2368                                         }\r
2369                                         else if(pCoexDm->curPsTdma == 13)\r
2370                                         {\r
2371                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2372                                                 pCoexDm->psTdmaDuAdjType = 14;\r
2373                                         }\r
2374                                         else if(pCoexDm->curPsTdma == 14)\r
2375                                         {\r
2376                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2377                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2378                                         }\r
2379                                         else if(pCoexDm->curPsTdma == 15)\r
2380                                         {\r
2381                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
2382                                                 pCoexDm->psTdmaDuAdjType = 16;\r
2383                                         }\r
2384                                 } \r
2385                                 else if (result == 1)\r
2386                                 {\r
2387                                         if(pCoexDm->curPsTdma == 8)\r
2388                                         {\r
2389                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2390                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2391                                         }\r
2392                                         else if(pCoexDm->curPsTdma == 7)\r
2393                                         {\r
2394                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2395                                                 pCoexDm->psTdmaDuAdjType = 6;\r
2396                                         }\r
2397                                         else if(pCoexDm->curPsTdma == 6)\r
2398                                         {\r
2399                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
2400                                                 pCoexDm->psTdmaDuAdjType = 5;\r
2401                                         }\r
2402                                         else if(pCoexDm->curPsTdma == 16)\r
2403                                         {\r
2404                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2405                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2406                                         }\r
2407                                         else if(pCoexDm->curPsTdma == 15)\r
2408                                         {\r
2409                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2410                                                 pCoexDm->psTdmaDuAdjType = 14;\r
2411                                         }\r
2412                                         else if(pCoexDm->curPsTdma == 14)\r
2413                                         {\r
2414                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);\r
2415                                                 pCoexDm->psTdmaDuAdjType = 13;\r
2416                                         }\r
2417                                 }\r
2418                         }\r
2419                         else\r
2420                         {\r
2421                                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TxPause = 0\n"));\r
2422                                 if(pCoexDm->curPsTdma == 5)\r
2423                                 {\r
2424                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 71);\r
2425                                         pCoexDm->psTdmaDuAdjType = 71;\r
2426                                 }\r
2427                                 else if(pCoexDm->curPsTdma == 6)\r
2428                                 {\r
2429                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2430                                         pCoexDm->psTdmaDuAdjType = 2;\r
2431                                 }\r
2432                                 else if(pCoexDm->curPsTdma == 7)\r
2433                                 {\r
2434                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2435                                         pCoexDm->psTdmaDuAdjType = 3;\r
2436                                 }\r
2437                                 else if(pCoexDm->curPsTdma == 8)\r
2438                                 {\r
2439                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
2440                                         pCoexDm->psTdmaDuAdjType = 4;\r
2441                                 }\r
2442                                 if(pCoexDm->curPsTdma == 13)\r
2443                                 {\r
2444                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
2445                                         pCoexDm->psTdmaDuAdjType = 9;\r
2446                                 }\r
2447                                 else if(pCoexDm->curPsTdma == 14)\r
2448                                 {\r
2449                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2450                                         pCoexDm->psTdmaDuAdjType = 10;\r
2451                                 }\r
2452                                 else if(pCoexDm->curPsTdma == 15)\r
2453                                 {\r
2454                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2455                                         pCoexDm->psTdmaDuAdjType = 11;\r
2456                                 }\r
2457                                 else if(pCoexDm->curPsTdma == 16)\r
2458                                 {\r
2459                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
2460                                         pCoexDm->psTdmaDuAdjType = 12;\r
2461                                 }\r
2462                                 \r
2463                                 if(result == -1)\r
2464                                 {\r
2465                                         if(pCoexDm->curPsTdma == 71)\r
2466                                         {\r
2467                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
2468                                                 pCoexDm->psTdmaDuAdjType = 1;\r
2469                                         }\r
2470                                         else if(pCoexDm->curPsTdma == 1)\r
2471                                         {\r
2472                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2473                                                 pCoexDm->psTdmaDuAdjType = 2;\r
2474                                         }\r
2475                                         else if(pCoexDm->curPsTdma == 2)\r
2476                                         {\r
2477                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2478                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2479                                         }\r
2480                                         else if(pCoexDm->curPsTdma == 3)\r
2481                                         {\r
2482                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
2483                                                 pCoexDm->psTdmaDuAdjType = 4;\r
2484                                         }\r
2485                                         else if(pCoexDm->curPsTdma == 9)\r
2486                                         {\r
2487                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2488                                                 pCoexDm->psTdmaDuAdjType = 10;\r
2489                                         }\r
2490                                         else if(pCoexDm->curPsTdma == 10)\r
2491                                         {\r
2492                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2493                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2494                                         }\r
2495                                         else if(pCoexDm->curPsTdma == 11)\r
2496                                         {\r
2497                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
2498                                                 pCoexDm->psTdmaDuAdjType = 12;\r
2499                                         }\r
2500                                 } \r
2501                                 else if (result == 1)\r
2502                                 {\r
2503                                         if(pCoexDm->curPsTdma == 4)\r
2504                                         {\r
2505                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2506                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2507                                         }\r
2508                                         else if(pCoexDm->curPsTdma == 3)\r
2509                                         {\r
2510                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2511                                                 pCoexDm->psTdmaDuAdjType = 2;\r
2512                                         }\r
2513                                         else if(pCoexDm->curPsTdma == 2)\r
2514                                         {\r
2515                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
2516                                                 pCoexDm->psTdmaDuAdjType = 1;\r
2517                                         }\r
2518                                         else if(pCoexDm->curPsTdma == 1)\r
2519                                         {\r
2520                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 71);\r
2521                                                 pCoexDm->psTdmaDuAdjType = 71;\r
2522                                         }\r
2523                                         else if(pCoexDm->curPsTdma == 12)\r
2524                                         {\r
2525                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2526                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2527                                         }\r
2528                                         else if(pCoexDm->curPsTdma == 11)\r
2529                                         {\r
2530                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2531                                                 pCoexDm->psTdmaDuAdjType = 10;\r
2532                                         }\r
2533                                         else if(pCoexDm->curPsTdma == 10)\r
2534                                         {\r
2535                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
2536                                                 pCoexDm->psTdmaDuAdjType = 9;\r
2537                                         }\r
2538                                 }\r
2539                         }\r
2540                 }\r
2541                 else if(maxInterval == 2)\r
2542                 {\r
2543                         if(bTxPause)\r
2544                         {\r
2545                                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TxPause = 1\n"));\r
2546                                 if(pCoexDm->curPsTdma == 1)\r
2547                                 {\r
2548                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2549                                         pCoexDm->psTdmaDuAdjType = 6;\r
2550                                 }\r
2551                                 else if(pCoexDm->curPsTdma == 2)\r
2552                                 {\r
2553                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2554                                         pCoexDm->psTdmaDuAdjType = 6;\r
2555                                 }\r
2556                                 else if(pCoexDm->curPsTdma == 3)\r
2557                                 {\r
2558                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2559                                         pCoexDm->psTdmaDuAdjType = 7;\r
2560                                 }\r
2561                                 else if(pCoexDm->curPsTdma == 4)\r
2562                                 {\r
2563                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
2564                                         pCoexDm->psTdmaDuAdjType = 8;\r
2565                                 }\r
2566                                 if(pCoexDm->curPsTdma == 9)\r
2567                                 {\r
2568                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2569                                         pCoexDm->psTdmaDuAdjType = 14;\r
2570                                 }\r
2571                                 else if(pCoexDm->curPsTdma == 10)\r
2572                                 {\r
2573                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2574                                         pCoexDm->psTdmaDuAdjType = 14;\r
2575                                 }\r
2576                                 else if(pCoexDm->curPsTdma == 11)\r
2577                                 {\r
2578                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2579                                         pCoexDm->psTdmaDuAdjType = 15;\r
2580                                 }\r
2581                                 else if(pCoexDm->curPsTdma == 12)\r
2582                                 {\r
2583                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
2584                                         pCoexDm->psTdmaDuAdjType = 16;\r
2585                                 }\r
2586                                 if(result == -1)\r
2587                                 {\r
2588                                         if(pCoexDm->curPsTdma == 5) \r
2589                                         {\r
2590                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2591                                                 pCoexDm->psTdmaDuAdjType = 6;\r
2592                                         }\r
2593                                         else if(pCoexDm->curPsTdma == 6)\r
2594                                         {\r
2595                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2596                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2597                                         }\r
2598                                         else if(pCoexDm->curPsTdma == 7)\r
2599                                         {\r
2600                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
2601                                                 pCoexDm->psTdmaDuAdjType = 8;\r
2602                                         }\r
2603                                         else if(pCoexDm->curPsTdma == 13)\r
2604                                         {\r
2605                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2606                                                 pCoexDm->psTdmaDuAdjType = 14;\r
2607                                         }\r
2608                                         else if(pCoexDm->curPsTdma == 14)\r
2609                                         {\r
2610                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2611                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2612                                         }\r
2613                                         else if(pCoexDm->curPsTdma == 15)\r
2614                                         {\r
2615                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
2616                                                 pCoexDm->psTdmaDuAdjType = 16;\r
2617                                         }\r
2618                                 } \r
2619                                 else if (result == 1)\r
2620                                 {\r
2621                                         if(pCoexDm->curPsTdma == 8)\r
2622                                         {\r
2623                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2624                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2625                                         }\r
2626                                         else if(pCoexDm->curPsTdma == 7)\r
2627                                         {\r
2628                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2629                                                 pCoexDm->psTdmaDuAdjType = 6;\r
2630                                         }\r
2631                                         else if(pCoexDm->curPsTdma == 6)\r
2632                                         {\r
2633                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2634                                                 pCoexDm->psTdmaDuAdjType = 6;\r
2635                                         }                                       \r
2636                                         else if(pCoexDm->curPsTdma == 16)\r
2637                                         {\r
2638                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2639                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2640                                         }\r
2641                                         else if(pCoexDm->curPsTdma == 15)\r
2642                                         {\r
2643                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2644                                                 pCoexDm->psTdmaDuAdjType = 14;\r
2645                                         }\r
2646                                         else if(pCoexDm->curPsTdma == 14)\r
2647                                         {\r
2648                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2649                                                 pCoexDm->psTdmaDuAdjType = 14;\r
2650                                         }\r
2651                                 }\r
2652                         }\r
2653                         else\r
2654                         {\r
2655                                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TxPause = 0\n"));\r
2656                                 if(pCoexDm->curPsTdma == 5)\r
2657                                 {\r
2658                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2659                                         pCoexDm->psTdmaDuAdjType = 2;\r
2660                                 }\r
2661                                 else if(pCoexDm->curPsTdma == 6)\r
2662                                 {\r
2663                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2664                                         pCoexDm->psTdmaDuAdjType = 2;\r
2665                                 }\r
2666                                 else if(pCoexDm->curPsTdma == 7)\r
2667                                 {\r
2668                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2669                                         pCoexDm->psTdmaDuAdjType = 3;\r
2670                                 }\r
2671                                 else if(pCoexDm->curPsTdma == 8)\r
2672                                 {\r
2673                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
2674                                         pCoexDm->psTdmaDuAdjType = 4;\r
2675                                 }\r
2676                                 if(pCoexDm->curPsTdma == 13)\r
2677                                 {\r
2678                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2679                                         pCoexDm->psTdmaDuAdjType = 10;\r
2680                                 }\r
2681                                 else if(pCoexDm->curPsTdma == 14)\r
2682                                 {\r
2683                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2684                                         pCoexDm->psTdmaDuAdjType = 10;\r
2685                                 }\r
2686                                 else if(pCoexDm->curPsTdma == 15)\r
2687                                 {\r
2688                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2689                                         pCoexDm->psTdmaDuAdjType = 11;\r
2690                                 }\r
2691                                 else if(pCoexDm->curPsTdma == 16)\r
2692                                 {\r
2693                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
2694                                         pCoexDm->psTdmaDuAdjType = 12;\r
2695                                 }\r
2696                                 if(result == -1)\r
2697                                 {\r
2698                                         if(pCoexDm->curPsTdma == 1)\r
2699                                         {\r
2700                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2701                                                 pCoexDm->psTdmaDuAdjType = 2;\r
2702                                         }\r
2703                                         else if(pCoexDm->curPsTdma == 2)\r
2704                                         {\r
2705                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2706                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2707                                         }\r
2708                                         else if(pCoexDm->curPsTdma == 3)\r
2709                                         {\r
2710                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
2711                                                 pCoexDm->psTdmaDuAdjType = 4;\r
2712                                         }\r
2713                                         else if(pCoexDm->curPsTdma == 9)\r
2714                                         {\r
2715                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2716                                                 pCoexDm->psTdmaDuAdjType = 10;\r
2717                                         }\r
2718                                         else if(pCoexDm->curPsTdma == 10)\r
2719                                         {\r
2720                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2721                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2722                                         }\r
2723                                         else if(pCoexDm->curPsTdma == 11)\r
2724                                         {\r
2725                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
2726                                                 pCoexDm->psTdmaDuAdjType = 12;\r
2727                                         }\r
2728                                 } \r
2729                                 else if (result == 1)\r
2730                                 {\r
2731                                         if(pCoexDm->curPsTdma == 4)\r
2732                                         {\r
2733                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2734                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2735                                         }\r
2736                                         else if(pCoexDm->curPsTdma == 3)\r
2737                                         {\r
2738                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2739                                                 pCoexDm->psTdmaDuAdjType = 2;\r
2740                                         }\r
2741                                         else if(pCoexDm->curPsTdma == 2)\r
2742                                         {\r
2743                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2744                                                 pCoexDm->psTdmaDuAdjType = 2;\r
2745                                         }\r
2746                                         else if(pCoexDm->curPsTdma == 12)\r
2747                                         {\r
2748                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2749                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2750                                         }\r
2751                                         else if(pCoexDm->curPsTdma == 11)\r
2752                                         {\r
2753                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2754                                                 pCoexDm->psTdmaDuAdjType = 10;\r
2755                                         }\r
2756                                         else if(pCoexDm->curPsTdma == 10)\r
2757                                         {\r
2758                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2759                                                 pCoexDm->psTdmaDuAdjType = 10;\r
2760                                         }\r
2761                                 }\r
2762                         }\r
2763                 }\r
2764                 else if(maxInterval == 3)\r
2765                 {\r
2766                         if(bTxPause)\r
2767                         {\r
2768                                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TxPause = 1\n"));\r
2769                                 if(pCoexDm->curPsTdma == 1)\r
2770                                 {\r
2771                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2772                                         pCoexDm->psTdmaDuAdjType = 7;\r
2773                                 }\r
2774                                 else if(pCoexDm->curPsTdma == 2)\r
2775                                 {\r
2776                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2777                                         pCoexDm->psTdmaDuAdjType = 7;\r
2778                                 }\r
2779                                 else if(pCoexDm->curPsTdma == 3)\r
2780                                 {\r
2781                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2782                                         pCoexDm->psTdmaDuAdjType = 7;\r
2783                                 }\r
2784                                 else if(pCoexDm->curPsTdma == 4)\r
2785                                 {\r
2786                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
2787                                         pCoexDm->psTdmaDuAdjType = 8;\r
2788                                 }\r
2789                                 if(pCoexDm->curPsTdma == 9)\r
2790                                 {\r
2791                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2792                                         pCoexDm->psTdmaDuAdjType = 15;\r
2793                                 }\r
2794                                 else if(pCoexDm->curPsTdma == 10)\r
2795                                 {\r
2796                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2797                                         pCoexDm->psTdmaDuAdjType = 15;\r
2798                                 }\r
2799                                 else if(pCoexDm->curPsTdma == 11)\r
2800                                 {\r
2801                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2802                                         pCoexDm->psTdmaDuAdjType = 15;\r
2803                                 }\r
2804                                 else if(pCoexDm->curPsTdma == 12)\r
2805                                 {\r
2806                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
2807                                         pCoexDm->psTdmaDuAdjType = 16;\r
2808                                 }\r
2809                                 if(result == -1)\r
2810                                 {\r
2811                                         if(pCoexDm->curPsTdma == 5) \r
2812                                         {\r
2813                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2814                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2815                                         }\r
2816                                         else if(pCoexDm->curPsTdma == 6)\r
2817                                         {\r
2818                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2819                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2820                                         }\r
2821                                         else if(pCoexDm->curPsTdma == 7)\r
2822                                         {\r
2823                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
2824                                                 pCoexDm->psTdmaDuAdjType = 8;\r
2825                                         }\r
2826                                         else if(pCoexDm->curPsTdma == 13)\r
2827                                         {\r
2828                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2829                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2830                                         }\r
2831                                         else if(pCoexDm->curPsTdma == 14)\r
2832                                         {\r
2833                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2834                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2835                                         }\r
2836                                         else if(pCoexDm->curPsTdma == 15)\r
2837                                         {\r
2838                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
2839                                                 pCoexDm->psTdmaDuAdjType = 16;\r
2840                                         }\r
2841                                 } \r
2842                                 else if (result == 1)\r
2843                                 {\r
2844                                         if(pCoexDm->curPsTdma == 8)\r
2845                                         {\r
2846                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2847                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2848                                         }\r
2849                                         else if(pCoexDm->curPsTdma == 7)\r
2850                                         {\r
2851                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2852                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2853                                         }\r
2854                                         else if(pCoexDm->curPsTdma == 6)\r
2855                                         {\r
2856                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2857                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2858                                         }                                       \r
2859                                         else if(pCoexDm->curPsTdma == 16)\r
2860                                         {\r
2861                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2862                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2863                                         }\r
2864                                         else if(pCoexDm->curPsTdma == 15)\r
2865                                         {\r
2866                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2867                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2868                                         }\r
2869                                         else if(pCoexDm->curPsTdma == 14)\r
2870                                         {\r
2871                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2872                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2873                                         }\r
2874                                 }\r
2875                         }\r
2876                         else\r
2877                         {\r
2878                                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TxPause = 0\n"));\r
2879                                 if(pCoexDm->curPsTdma == 5)\r
2880                                 {\r
2881                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2882                                         pCoexDm->psTdmaDuAdjType = 3;\r
2883                                 }\r
2884                                 else if(pCoexDm->curPsTdma == 6)\r
2885                                 {\r
2886                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2887                                         pCoexDm->psTdmaDuAdjType = 3;\r
2888                                 }\r
2889                                 else if(pCoexDm->curPsTdma == 7)\r
2890                                 {\r
2891                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2892                                         pCoexDm->psTdmaDuAdjType = 3;\r
2893                                 }\r
2894                                 else if(pCoexDm->curPsTdma == 8)\r
2895                                 {\r
2896                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
2897                                         pCoexDm->psTdmaDuAdjType = 4;\r
2898                                 }\r
2899                                 if(pCoexDm->curPsTdma == 13)\r
2900                                 {\r
2901                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2902                                         pCoexDm->psTdmaDuAdjType = 11;\r
2903                                 }\r
2904                                 else if(pCoexDm->curPsTdma == 14)\r
2905                                 {\r
2906                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2907                                         pCoexDm->psTdmaDuAdjType = 11;\r
2908                                 }\r
2909                                 else if(pCoexDm->curPsTdma == 15)\r
2910                                 {\r
2911                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2912                                         pCoexDm->psTdmaDuAdjType = 11;\r
2913                                 }\r
2914                                 else if(pCoexDm->curPsTdma == 16)\r
2915                                 {\r
2916                                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
2917                                         pCoexDm->psTdmaDuAdjType = 12;\r
2918                                 }\r
2919                                 if(result == -1)\r
2920                                 {\r
2921                                         if(pCoexDm->curPsTdma == 1)\r
2922                                         {\r
2923                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2924                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2925                                         }\r
2926                                         else if(pCoexDm->curPsTdma == 2)\r
2927                                         {\r
2928                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2929                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2930                                         }\r
2931                                         else if(pCoexDm->curPsTdma == 3)\r
2932                                         {\r
2933                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
2934                                                 pCoexDm->psTdmaDuAdjType = 4;\r
2935                                         }\r
2936                                         else if(pCoexDm->curPsTdma == 9)\r
2937                                         {\r
2938                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2939                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2940                                         }\r
2941                                         else if(pCoexDm->curPsTdma == 10)\r
2942                                         {\r
2943                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2944                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2945                                         }\r
2946                                         else if(pCoexDm->curPsTdma == 11)\r
2947                                         {\r
2948                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
2949                                                 pCoexDm->psTdmaDuAdjType = 12;\r
2950                                         }\r
2951                                 } \r
2952                                 else if (result == 1)\r
2953                                 {\r
2954                                         if(pCoexDm->curPsTdma == 4)\r
2955                                         {\r
2956                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2957                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2958                                         }\r
2959                                         else if(pCoexDm->curPsTdma == 3)\r
2960                                         {\r
2961                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2962                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2963                                         }\r
2964                                         else if(pCoexDm->curPsTdma == 2)\r
2965                                         {\r
2966                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2967                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2968                                         }\r
2969                                         else if(pCoexDm->curPsTdma == 12)\r
2970                                         {\r
2971                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2972                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2973                                         }\r
2974                                         else if(pCoexDm->curPsTdma == 11)\r
2975                                         {\r
2976                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2977                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2978                                         }\r
2979                                         else if(pCoexDm->curPsTdma == 10)\r
2980                                         {\r
2981                                                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2982                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2983                                         }\r
2984                                 }\r
2985                         }\r
2986                 }\r
2987         }\r
2988 \r
2989         // if current PsTdma not match with the recorded one (when scan, dhcp...), \r
2990         // then we have to adjust it back to the previous record one.\r
2991         if(pCoexDm->curPsTdma != pCoexDm->psTdmaDuAdjType)\r
2992         {\r
2993                 BOOLEAN bScan=FALSE, bLink=FALSE, bRoam=FALSE;\r
2994                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], PsTdma type dismatch!!!, curPsTdma=%d, recordPsTdma=%d\n", \r
2995                         pCoexDm->curPsTdma, pCoexDm->psTdmaDuAdjType));\r
2996 \r
2997                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);\r
2998                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);\r
2999                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);\r
3000                 \r
3001                 if( !bScan && !bLink && !bRoam)\r
3002                 {\r
3003                         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, pCoexDm->psTdmaDuAdjType);\r
3004                 }\r
3005                 else\r
3006                 {\r
3007                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n"));\r
3008                 }\r
3009         }\r
3010 }\r
3011 \r
3012 // SCO only or SCO+PAN(HS)\r
3013 VOID\r
3014 halbtc8703b2ant_ActionSco(\r
3015         IN      PBTC_COEXIST            pBtCoexist\r
3016         )\r
3017 {\r
3018         u1Byte  wifiRssiState, btRssiState;\r
3019         u4Byte  wifiBw;\r
3020 \r
3021         wifiRssiState = halbtc8703b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
3022         btRssiState = halbtc8703b2ant_BtRssiState(2, BT_8703B_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);\r
3023 \r
3024         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);\r
3025 \r
3026         halbtc8703b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
3027         \r
3028         halbtc8703b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 4);\r
3029 \r
3030         if(BTC_RSSI_HIGH(btRssiState))\r
3031                 halbtc8703b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3032         else    \r
3033                 halbtc8703b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3034         \r
3035         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3036 \r
3037         if (BTC_WIFI_BW_LEGACY == wifiBw) //for SCO quality at 11b/g mode\r
3038         {\r
3039                 halbtc8703b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
3040         }\r
3041         else  //for SCO quality & wifi performance balance at 11n mode\r
3042         {\r
3043                 halbtc8703b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 8);\r
3044         }\r
3045 \r
3046         halbtc8703b2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);                       \r
3047         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0); //for voice quality\r
3048 \r
3049         // sw mechanism\r
3050         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3051         {\r
3052                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3053                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3054                 {\r
3055                         halbtc8703b2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
3056                         halbtc8703b2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,TRUE,0x4);                   \r
3057                 }\r
3058                 else\r
3059                 {\r
3060                         halbtc8703b2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
3061                         halbtc8703b2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,TRUE,0x4);  \r
3062                 }               \r
3063         }\r
3064         else\r
3065         {\r
3066                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3067                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3068                 {\r
3069                         halbtc8703b2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
3070                         halbtc8703b2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,TRUE,0x4);\r
3071                 }\r
3072                 else\r
3073                 {\r
3074                         halbtc8703b2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
3075                         halbtc8703b2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,TRUE,0x4);\r
3076                 }               \r
3077         }\r
3078 }\r
3079 \r
3080 \r
3081 VOID\r
3082 halbtc8703b2ant_ActionHid(\r
3083         IN      PBTC_COEXIST            pBtCoexist\r
3084         )\r
3085 {\r
3086         u1Byte  wifiRssiState, btRssiState;     \r
3087         u4Byte  wifiBw;\r
3088 \r
3089         wifiRssiState = halbtc8703b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
3090         btRssiState = halbtc8703b2ant_BtRssiState(2, BT_8703B_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);\r
3091 \r
3092         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);\r
3093 \r
3094         halbtc8703b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
3095         \r
3096         halbtc8703b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
3097 \r
3098         if(BTC_RSSI_HIGH(btRssiState))\r
3099                 halbtc8703b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3100         else    \r
3101                 halbtc8703b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3102 \r
3103         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3104 \r
3105         if (BTC_WIFI_BW_LEGACY == wifiBw) //for HID at 11b/g mode\r
3106         {\r
3107                 halbtc8703b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);\r
3108         }\r
3109         else  //for HID quality & wifi performance balance at 11n mode\r
3110         {\r
3111                 halbtc8703b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 9);\r
3112         }\r
3113 \r
3114         halbtc8703b2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);                       \r
3115         \r
3116         if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
3117                 (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3118         {\r
3119                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
3120         }\r
3121         else\r
3122         {\r
3123                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);\r
3124         }\r
3125 \r
3126         // sw mechanism\r
3127         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3128         {\r
3129                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3130                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3131                 {\r
3132                         halbtc8703b2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
3133                         halbtc8703b2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3134                 }\r
3135                 else\r
3136                 {\r
3137                         halbtc8703b2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
3138                         halbtc8703b2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3139                 }       \r
3140         }\r
3141         else\r
3142         {\r
3143                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3144                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3145                 {\r
3146                         halbtc8703b2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
3147                         halbtc8703b2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3148                 }\r
3149                 else\r
3150                 {\r
3151                         halbtc8703b2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
3152                         halbtc8703b2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3153                 }               \r
3154         }\r
3155 }\r
3156 \r
3157 //A2DP only / PAN(EDR) only/ A2DP+PAN(HS)\r
3158 VOID\r
3159 halbtc8703b2ant_ActionA2dp(\r
3160         IN      PBTC_COEXIST            pBtCoexist\r
3161         )\r
3162 {\r
3163         u1Byte          wifiRssiState, wifiRssiState1, btRssiState;\r
3164         u4Byte          wifiBw;\r
3165         u1Byte          apNum=0;\r
3166 \r
3167         wifiRssiState = halbtc8703b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
3168         wifiRssiState1 = halbtc8703b2ant_WifiRssiState(pBtCoexist, 1, 2, BT_8703B_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);\r
3169         btRssiState = halbtc8703b2ant_BtRssiState(2, BT_8703B_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);\r
3170 \r
3171         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_AP_NUM, &apNum);\r
3172 \r
3173         // define the office environment\r
3174         if( (apNum >= 10) && BTC_RSSI_HIGH(wifiRssiState1) && BTC_RSSI_HIGH(btRssiState))\r
3175         {\r
3176                 //DbgPrint(" AP#>10(%d)\n", apNum);\r
3177                 halbtc8703b2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);                       \r
3178                 \r
3179                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);      \r
3180                 halbtc8703b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
3181                 halbtc8703b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);      \r
3182                 halbtc8703b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);                   \r
3183                                         \r
3184                 halbtc8703b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
3185 \r
3186                 halbtc8703b2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);               \r
3187                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);\r
3188 \r
3189                 // sw mechanism\r
3190                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3191                 if(BTC_WIFI_BW_HT40 == wifiBw)\r
3192                 {\r
3193                         halbtc8703b2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3194                         halbtc8703b2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,TRUE,0x18);\r
3195                 }\r
3196                 else\r
3197                 {\r
3198                         halbtc8703b2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3199                         halbtc8703b2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,TRUE,0x18);          \r
3200                 }\r
3201                 return;\r
3202                 \r
3203         }\r
3204 \r
3205         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);\r
3206         halbtc8703b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
3207 \r
3208         halbtc8703b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
3209 \r
3210         if(BTC_RSSI_HIGH(btRssiState))\r
3211                 halbtc8703b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3212         else    \r
3213                 halbtc8703b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3214 \r
3215                 \r
3216         if (BTC_RSSI_HIGH(wifiRssiState1) && BTC_RSSI_HIGH(btRssiState))\r
3217         {\r
3218         halbtc8703b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);\r
3219                 halbtc8703b2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);               \r
3220         }\r
3221         else\r
3222         {\r
3223                 halbtc8703b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 13);\r
3224                 halbtc8703b2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);           \r
3225         }\r
3226         \r
3227 \r
3228         if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
3229                 (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3230         {\r
3231                 halbtc8703b2ant_TdmaDurationAdjust(pBtCoexist, FALSE, FALSE, 1);\r
3232         }\r
3233         else\r
3234         {\r
3235                 halbtc8703b2ant_TdmaDurationAdjust(pBtCoexist, FALSE, TRUE, 1);\r
3236         }\r
3237 \r
3238         // sw mechanism\r
3239         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3240         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3241         {\r
3242                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3243                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3244                 {\r
3245                         halbtc8703b2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3246                         halbtc8703b2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3247                 }\r
3248                 else\r
3249                 {\r
3250                         halbtc8703b2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3251                         halbtc8703b2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3252                 }\r
3253         }\r
3254         else\r
3255         {\r
3256                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3257                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3258                 {\r
3259                         halbtc8703b2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3260                         halbtc8703b2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3261                 }\r
3262                 else\r
3263                 {\r
3264                         halbtc8703b2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3265                         halbtc8703b2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3266                 }               \r
3267         }\r
3268 }\r
3269 \r
3270 VOID\r
3271 halbtc8703b2ant_ActionA2dpPanHs(\r
3272         IN      PBTC_COEXIST            pBtCoexist\r
3273         )\r
3274 {\r
3275         u1Byte          wifiRssiState, wifiRssiState1, btRssiState;\r
3276         u4Byte          wifiBw;\r
3277 \r
3278         wifiRssiState = halbtc8703b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
3279         wifiRssiState1 = halbtc8703b2ant_WifiRssiState(pBtCoexist, 1, 2, BT_8703B_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);  \r
3280         btRssiState = halbtc8703b2ant_BtRssiState(2, BT_8703B_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);\r
3281 \r
3282         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);\r
3283 \r
3284         halbtc8703b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
3285         \r
3286         halbtc8703b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
3287 \r
3288         if(BTC_RSSI_HIGH(btRssiState))\r
3289                 halbtc8703b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3290         else    \r
3291                 halbtc8703b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3292 \r
3293         if (BTC_RSSI_HIGH(wifiRssiState1) && BTC_RSSI_HIGH(btRssiState))\r
3294         {\r
3295         halbtc8703b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);\r
3296                 halbtc8703b2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);               \r
3297         }\r
3298         else\r
3299         {\r
3300                 halbtc8703b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 13);\r
3301                 halbtc8703b2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);           \r
3302         }\r
3303 \r
3304         halbtc8703b2ant_TdmaDurationAdjust(pBtCoexist, FALSE, TRUE, 2);\r
3305 \r
3306         // sw mechanism\r
3307         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3308         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3309         {\r
3310                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3311                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3312                 {\r
3313                         halbtc8703b2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3314                         halbtc8703b2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3315                 }\r
3316                 else\r
3317                 {\r
3318                         halbtc8703b2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3319                         halbtc8703b2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3320                 }\r
3321         }\r
3322         else\r
3323         {\r
3324                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3325                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3326                 {\r
3327                         halbtc8703b2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3328                         halbtc8703b2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3329                 }\r
3330                 else\r
3331                 {\r
3332                         halbtc8703b2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3333                         halbtc8703b2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3334                 }               \r
3335         }\r
3336 }\r
3337 \r
3338 VOID\r
3339 halbtc8703b2ant_ActionPanEdr(\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 = halbtc8703b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
3347         wifiRssiState1 = halbtc8703b2ant_WifiRssiState(pBtCoexist, 1, 2, BT_8703B_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);  \r
3348         btRssiState = halbtc8703b2ant_BtRssiState(2, BT_8703B_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);\r
3349 \r
3350         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);\r
3351 \r
3352         halbtc8703b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
3353 \r
3354         halbtc8703b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
3355 \r
3356         if(BTC_RSSI_HIGH(btRssiState))\r
3357                 halbtc8703b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3358         else    \r
3359                 halbtc8703b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3360 \r
3361         if (BTC_RSSI_HIGH(wifiRssiState1) && BTC_RSSI_HIGH(btRssiState))\r
3362         {\r
3363         halbtc8703b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 10);\r
3364                 halbtc8703b2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);               \r
3365         }\r
3366         else\r
3367         {\r
3368                 halbtc8703b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 13);\r
3369                 halbtc8703b2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);           \r
3370         }\r
3371 \r
3372         if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
3373                 (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3374         {\r
3375                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
3376         }\r
3377         else\r
3378         {\r
3379                 halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
3380         }\r
3381         \r
3382         // sw mechanism\r
3383         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3384         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3385         {\r
3386                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3387                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3388                 {\r
3389                         halbtc8703b2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3390                         halbtc8703b2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3391                 }\r
3392                 else\r
3393                 {\r
3394                         halbtc8703b2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3395                         halbtc8703b2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3396                 }\r
3397         }\r
3398         else\r
3399         {\r
3400                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3401                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3402                 {\r
3403                         halbtc8703b2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3404                         halbtc8703b2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3405                 }\r
3406                 else\r
3407                 {\r
3408                         halbtc8703b2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3409                         halbtc8703b2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3410                 }\r
3411         }\r
3412 }\r
3413 \r
3414 \r
3415 //PAN(HS) only\r
3416 VOID\r
3417 halbtc8703b2ant_ActionPanHs(\r
3418         IN      PBTC_COEXIST            pBtCoexist\r
3419         )\r
3420 {\r
3421         u1Byte          wifiRssiState, wifiRssiState1, btRssiState;\r
3422         u4Byte          wifiBw;\r
3423 \r
3424         wifiRssiState = halbtc8703b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
3425         wifiRssiState1 = halbtc8703b2ant_WifiRssiState(pBtCoexist, 1, 2, BT_8703B_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);  \r
3426         btRssiState = halbtc8703b2ant_BtRssiState(2, BT_8703B_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);\r
3427 \r
3428         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);\r
3429 \r
3430         halbtc8703b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
3431 \r
3432         halbtc8703b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
3433 \r
3434         if(BTC_RSSI_HIGH(btRssiState))\r
3435                 halbtc8703b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3436         else\r
3437                 halbtc8703b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3438         \r
3439         halbtc8703b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);\r
3440         \r
3441         halbtc8703b2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);               \r
3442         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);\r
3443 \r
3444         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\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                         halbtc8703b2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3451                         halbtc8703b2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3452                 }\r
3453                 else\r
3454                 {\r
3455                         halbtc8703b2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3456                         halbtc8703b2ant_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                         halbtc8703b2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3465                         halbtc8703b2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3466                 }\r
3467                 else\r
3468                 {\r
3469                         halbtc8703b2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3470                         halbtc8703b2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3471                 }\r
3472         }\r
3473 }\r
3474 \r
3475 //PAN(EDR)+A2DP\r
3476 VOID\r
3477 halbtc8703b2ant_ActionPanEdrA2dp(\r
3478         IN      PBTC_COEXIST            pBtCoexist\r
3479         )\r
3480 {\r
3481         u1Byte          wifiRssiState, wifiRssiState1, btRssiState;\r
3482         u4Byte          wifiBw;\r
3483 \r
3484         wifiRssiState = halbtc8703b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
3485         wifiRssiState1 = halbtc8703b2ant_WifiRssiState(pBtCoexist, 1, 2, BT_8703B_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);  \r
3486         btRssiState = halbtc8703b2ant_BtRssiState(2, BT_8703B_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);\r
3487 \r
3488         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);\r
3489 \r
3490         halbtc8703b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
3491 \r
3492         halbtc8703b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
3493 \r
3494         if(BTC_RSSI_HIGH(btRssiState))\r
3495                 halbtc8703b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3496         else    \r
3497                 halbtc8703b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3498 \r
3499         if (BTC_RSSI_HIGH(wifiRssiState1) && BTC_RSSI_HIGH(btRssiState))                \r
3500                 halbtc8703b2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);               \r
3501         else\r
3502                 halbtc8703b2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);\r
3503 \r
3504         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3505 \r
3506         if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
3507                 (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3508         {\r
3509                 halbtc8703b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 12);\r
3510                 \r
3511                 if(BTC_WIFI_BW_HT40 == wifiBw)\r
3512                         halbtc8703b2ant_TdmaDurationAdjust(pBtCoexist, FALSE, TRUE, 3);\r
3513                 else\r
3514                         halbtc8703b2ant_TdmaDurationAdjust(pBtCoexist, FALSE, FALSE, 3);\r
3515         }\r
3516         else\r
3517         {\r
3518                 halbtc8703b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 13);\r
3519                 halbtc8703b2ant_TdmaDurationAdjust(pBtCoexist, FALSE, TRUE, 3);\r
3520         }\r
3521         \r
3522         // sw mechanism \r
3523         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3524         {\r
3525                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3526                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3527                 {\r
3528                         halbtc8703b2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3529                         halbtc8703b2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3530                 }\r
3531                 else\r
3532                 {\r
3533                         halbtc8703b2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3534                         halbtc8703b2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3535                 }\r
3536         }\r
3537         else\r
3538         {\r
3539                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3540                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3541                 {\r
3542                         halbtc8703b2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3543                         halbtc8703b2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3544                 }\r
3545                 else\r
3546                 {\r
3547                         halbtc8703b2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3548                         halbtc8703b2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3549                 }\r
3550         }\r
3551 }\r
3552 \r
3553 VOID\r
3554 halbtc8703b2ant_ActionPanEdrHid(\r
3555         IN      PBTC_COEXIST            pBtCoexist\r
3556         )\r
3557 {\r
3558         u1Byte          wifiRssiState, wifiRssiState1, btRssiState;\r
3559         u4Byte          wifiBw;\r
3560 \r
3561         wifiRssiState = halbtc8703b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
3562         wifiRssiState1 = halbtc8703b2ant_WifiRssiState(pBtCoexist, 1, 2, BT_8703B_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);  \r
3563         btRssiState = halbtc8703b2ant_BtRssiState(2, BT_8703B_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);\r
3564         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3565 \r
3566         halbtc8703b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
3567 \r
3568         if(BTC_RSSI_HIGH(btRssiState))\r
3569                 halbtc8703b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3570         else    \r
3571                 halbtc8703b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3572 \r
3573         if (BTC_RSSI_HIGH(wifiRssiState1) && BTC_RSSI_HIGH(btRssiState))        \r
3574         {\r
3575                 halbtc8703b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);\r
3576                 halbtc8703b2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);               \r
3577         }\r
3578         else\r
3579         {\r
3580                 halbtc8703b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 14);\r
3581                 halbtc8703b2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);\r
3582         }\r
3583 \r
3584         if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
3585                 (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3586         {\r
3587                 if(BTC_WIFI_BW_HT40 == wifiBw)\r
3588                 {\r
3589                         halbtc8703b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 3);\r
3590                         //halbtc8703b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 11);\r
3591                         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x780);\r
3592                 }\r
3593                 else\r
3594                 {\r
3595                         halbtc8703b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
3596                         //halbtc8703b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);\r
3597                         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);\r
3598                 }\r
3599                 halbtc8703b2ant_TdmaDurationAdjust(pBtCoexist, TRUE, FALSE, 2);\r
3600         }\r
3601         else\r
3602         {\r
3603                 halbtc8703b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
3604                 //halbtc8703b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 14);\r
3605                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);\r
3606                 halbtc8703b2ant_TdmaDurationAdjust(pBtCoexist, TRUE, TRUE, 2);\r
3607         }\r
3608         \r
3609         // sw mechanism\r
3610         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3611         {\r
3612                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3613                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3614                 {\r
3615                         halbtc8703b2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
3616                         halbtc8703b2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3617                 }\r
3618                 else\r
3619                 {\r
3620                         halbtc8703b2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
3621                         halbtc8703b2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3622                 }\r
3623         }\r
3624         else\r
3625         {\r
3626                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3627                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3628                 {\r
3629                         halbtc8703b2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
3630                         halbtc8703b2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3631                 }\r
3632                 else\r
3633                 {\r
3634                         halbtc8703b2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
3635                         halbtc8703b2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3636                 }\r
3637         }\r
3638 }\r
3639 \r
3640 // HID+A2DP+PAN(EDR)\r
3641 VOID\r
3642 halbtc8703b2ant_ActionHidA2dpPanEdr(\r
3643         IN      PBTC_COEXIST            pBtCoexist\r
3644         )\r
3645 {\r
3646         u1Byte          wifiRssiState,wifiRssiState1,  btRssiState;\r
3647         u4Byte          wifiBw;\r
3648 \r
3649         wifiRssiState = halbtc8703b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
3650         wifiRssiState1 = halbtc8703b2ant_WifiRssiState(pBtCoexist, 1, 2, BT_8703B_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);  \r
3651         btRssiState = halbtc8703b2ant_BtRssiState(2, BT_8703B_2ANT_BT_RSSI_COEXSWITCH_THRES, 0);\r
3652 \r
3653         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);\r
3654 \r
3655         halbtc8703b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
3656 \r
3657         halbtc8703b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
3658 \r
3659         if(BTC_RSSI_HIGH(btRssiState))\r
3660                 halbtc8703b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3661         else    \r
3662                 halbtc8703b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3663 \r
3664         if (BTC_RSSI_HIGH(wifiRssiState1) && BTC_RSSI_HIGH(btRssiState))\r
3665         {\r
3666                 halbtc8703b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);\r
3667                 halbtc8703b2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);               \r
3668         }\r
3669         else\r
3670         {\r
3671                 halbtc8703b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 14);\r
3672                 halbtc8703b2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);           \r
3673         }\r
3674 \r
3675         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3676 \r
3677         if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
3678                 (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3679         {\r
3680                 if(BTC_WIFI_BW_HT40 == wifiBw)\r
3681                         halbtc8703b2ant_TdmaDurationAdjust(pBtCoexist, TRUE, TRUE, 3);\r
3682                 else\r
3683                         halbtc8703b2ant_TdmaDurationAdjust(pBtCoexist, TRUE, FALSE, 3);\r
3684         }\r
3685         else\r
3686         {\r
3687                 halbtc8703b2ant_TdmaDurationAdjust(pBtCoexist, TRUE, TRUE, 3);\r
3688         }\r
3689 \r
3690         // sw mechanism\r
3691         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3692         {\r
3693                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3694                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3695                 {\r
3696                         halbtc8703b2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
3697                         halbtc8703b2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3698                 }\r
3699                 else\r
3700                 {\r
3701                         halbtc8703b2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
3702                         halbtc8703b2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3703                 }\r
3704         }\r
3705         else\r
3706         {\r
3707                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3708                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3709                 {\r
3710                         halbtc8703b2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
3711                         halbtc8703b2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3712                 }\r
3713                 else\r
3714                 {\r
3715                         halbtc8703b2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
3716                         halbtc8703b2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3717                 }\r
3718         }\r
3719 }\r
3720 \r
3721 VOID\r
3722 halbtc8703b2ant_ActionHidA2dp(\r
3723         IN      PBTC_COEXIST            pBtCoexist\r
3724         )\r
3725 {\r
3726         u1Byte          wifiRssiState, wifiRssiState1, btRssiState;\r
3727         u4Byte          wifiBw;\r
3728         u1Byte          apNum=0;\r
3729 \r
3730         wifiRssiState = halbtc8703b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
3731         //btRssiState = halbtc8703b2ant_BtRssiState(2, 29, 0);\r
3732         wifiRssiState1 = halbtc8703b2ant_WifiRssiState(pBtCoexist, 1, 2, BT_8703B_2ANT_WIFI_RSSI_COEXSWITCH_THRES, 0);  \r
3733         btRssiState = halbtc8703b2ant_BtRssiState(3, BT_8703B_2ANT_BT_RSSI_COEXSWITCH_THRES, 37);\r
3734 \r
3735         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);\r
3736 \r
3737         halbtc8703b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, TRUE, 0x5);\r
3738 \r
3739         halbtc8703b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
3740 \r
3741         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3742         if(BTC_WIFI_BW_LEGACY == wifiBw)\r
3743         {\r
3744                 if(BTC_RSSI_HIGH(btRssiState))\r
3745                         halbtc8703b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3746                 else if(BTC_RSSI_MEDIUM(btRssiState))\r
3747                         halbtc8703b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3748         else    \r
3749                         halbtc8703b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3750         }\r
3751         else    \r
3752         {       // only 802.11N mode we have to dec bt power to 4 degree\r
3753                 if(BTC_RSSI_HIGH(btRssiState))\r
3754                 {\r
3755                         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_AP_NUM, &apNum);\r
3756                         // need to check ap Number of Not\r
3757                         if(apNum < 10)\r
3758                                 halbtc8703b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);\r
3759                         else\r
3760                                 halbtc8703b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3761                 }\r
3762                 else if(BTC_RSSI_MEDIUM(btRssiState))\r
3763                         halbtc8703b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3764                 else    \r
3765                         halbtc8703b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3766         }\r
3767 \r
3768         if (BTC_RSSI_HIGH(wifiRssiState1) && BTC_RSSI_HIGH(btRssiState))\r
3769         {\r
3770         halbtc8703b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);\r
3771                 halbtc8703b2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);               \r
3772         }\r
3773         else\r
3774         {\r
3775                 halbtc8703b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 14);\r
3776                 halbtc8703b2ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);           \r
3777         }\r
3778 \r
3779         if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
3780                 (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3781         {\r
3782                 halbtc8703b2ant_TdmaDurationAdjust(pBtCoexist, TRUE, FALSE, 3);\r
3783         }\r
3784         else\r
3785         {\r
3786                 halbtc8703b2ant_TdmaDurationAdjust(pBtCoexist, TRUE, TRUE, 3);\r
3787         }\r
3788         \r
3789         // sw mechanism\r
3790         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3791         {\r
3792                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3793                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3794                 {\r
3795                         halbtc8703b2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
3796                         halbtc8703b2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3797                 }\r
3798                 else\r
3799                 {\r
3800                         halbtc8703b2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
3801                         halbtc8703b2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3802                 }\r
3803         }\r
3804         else\r
3805         {\r
3806                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3807                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3808                 {\r
3809                         halbtc8703b2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
3810                         halbtc8703b2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3811                 }\r
3812                 else\r
3813                 {\r
3814                         halbtc8703b2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
3815                         halbtc8703b2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3816                 }\r
3817         }\r
3818 }\r
3819 \r
3820 VOID\r
3821 halbtc8703b2ant_ActionBtWhckTest(\r
3822         IN      PBTC_COEXIST            pBtCoexist\r
3823         )\r
3824 {\r
3825         halbtc8703b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3826 \r
3827         // sw all off\r
3828         halbtc8703b2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3829         halbtc8703b2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3830 \r
3831         halbtc8703b2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);\r
3832         \r
3833         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);\r
3834         halbtc8703b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
3835 }\r
3836 \r
3837 VOID\r
3838 halbtc8703b2ant_ActionWifiMultiPort(\r
3839         IN      PBTC_COEXIST            pBtCoexist\r
3840         )\r
3841 {               \r
3842         halbtc8703b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
3843         halbtc8703b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3844 \r
3845         // sw all off\r
3846         halbtc8703b2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3847         halbtc8703b2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3848 \r
3849         // hw all off\r
3850         //pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);\r
3851         halbtc8703b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
3852 \r
3853         halbtc8703b2ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);               \r
3854         halbtc8703b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);\r
3855 }\r
3856 \r
3857 VOID\r
3858 halbtc8703b2ant_RunCoexistMechanism(\r
3859         IN      PBTC_COEXIST            pBtCoexist\r
3860         )\r
3861 {\r
3862         BOOLEAN                         bWifiUnder5G=FALSE, bBtHsOn=FALSE;\r
3863         u1Byte                          btInfoOriginal=0, btRetryCnt=0;\r
3864         u1Byte                          algorithm=0;\r
3865         u4Byte                          numOfWifiLink=0;\r
3866         u4Byte                          wifiLinkStatus=0;\r
3867         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
3868         BOOLEAN                         bMiracastPlusBt=FALSE;\r
3869         BOOLEAN                         bScan=FALSE, bLink=FALSE, bRoam=FALSE;\r
3870 \r
3871         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RunCoexistMechanism()===>\n"));\r
3872 \r
3873         if(pBtCoexist->bManualControl)\r
3874         {\r
3875                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"));\r
3876                 return;\r
3877         }\r
3878 \r
3879         if(pCoexSta->bUnderIps)\r
3880         {\r
3881                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], wifi is under IPS !!!\n"));\r
3882                 return;\r
3883         }\r
3884 \r
3885         if(pCoexSta->bBtWhckTest)\r
3886         {\r
3887                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is under WHCK TEST!!!\n"));\r
3888                 halbtc8703b2ant_ActionBtWhckTest(pBtCoexist);\r
3889                 return;\r
3890         }\r
3891 \r
3892         algorithm = halbtc8703b2ant_ActionAlgorithm(pBtCoexist);\r
3893         if(pCoexSta->bC2hBtInquiryPage && (BT_8703B_2ANT_COEX_ALGO_PANHS!=algorithm))\r
3894         {\r
3895                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is under inquiry/page scan !!\n"));\r
3896                 halbtc8703b2ant_ActionBtInquiry(pBtCoexist);\r
3897                 return;\r
3898         }\r
3899         else\r
3900         {\r
3901                 /*\r
3902                 if(pCoexDm->bNeedRecover0x948)\r
3903                 {\r
3904                         pCoexDm->bNeedRecover0x948 = FALSE;\r
3905                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, pCoexDm->backup0x948);\r
3906                 }\r
3907                 */\r
3908         }\r
3909 \r
3910         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);\r
3911         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);\r
3912         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);\r
3913 \r
3914         if(bScan || bLink || bRoam)\r
3915         {\r
3916                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], WiFi is under Link Process !!\n"));\r
3917                 halbtc8703b2ant_ActionWiFiLinkProcess(pBtCoexist);\r
3918                 return;\r
3919         }\r
3920 \r
3921         //for P2P\r
3922 \r
3923         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);\r
3924         numOfWifiLink = wifiLinkStatus>>16;\r
3925         \r
3926         if((numOfWifiLink>=2) || (wifiLinkStatus&WIFI_P2P_GO_CONNECTED))\r
3927         {\r
3928                 RT_TRACE(COMP_COEX, DBG_LOUD, ("############# [BTCoex],  Multi-Port numOfWifiLink = %d, wifiLinkStatus = 0x%x\n", numOfWifiLink,wifiLinkStatus) );\r
3929 \r
3930                 if(pBtLinkInfo->bBtLinkExist)\r
3931                 {\r
3932                         bMiracastPlusBt = TRUE;\r
3933                 }\r
3934                 else\r
3935                 {\r
3936                         bMiracastPlusBt = FALSE;\r
3937                 }\r
3938                 \r
3939                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_MIRACAST_PLUS_BT, &bMiracastPlusBt);\r
3940                 halbtc8703b2ant_ActionWifiMultiPort(pBtCoexist);\r
3941                 \r
3942                 return;\r
3943         }\r
3944         else\r
3945         {\r
3946                 bMiracastPlusBt = FALSE;\r
3947                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_MIRACAST_PLUS_BT, &bMiracastPlusBt);\r
3948         }\r
3949 \r
3950         pCoexDm->curAlgorithm = algorithm;\r
3951         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Algorithm = %d \n", pCoexDm->curAlgorithm));\r
3952 \r
3953         if(halbtc8703b2ant_IsCommonAction(pBtCoexist))\r
3954         {\r
3955                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant common.\n"));\r
3956                 pCoexDm->bAutoTdmaAdjust = FALSE;\r
3957         }\r
3958         else\r
3959         {\r
3960                 if(pCoexDm->curAlgorithm != pCoexDm->preAlgorithm)\r
3961                 {\r
3962                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], preAlgorithm=%d, curAlgorithm=%d\n", \r
3963                                 pCoexDm->preAlgorithm, pCoexDm->curAlgorithm));\r
3964                         pCoexDm->bAutoTdmaAdjust = FALSE;\r
3965                 }\r
3966                 switch(pCoexDm->curAlgorithm)\r
3967                 {\r
3968                         case BT_8703B_2ANT_COEX_ALGO_SCO:\r
3969                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = SCO.\n"));\r
3970                                 halbtc8703b2ant_ActionSco(pBtCoexist);\r
3971                                 break;\r
3972                         case BT_8703B_2ANT_COEX_ALGO_HID:\r
3973                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = HID.\n"));\r
3974                                 halbtc8703b2ant_ActionHid(pBtCoexist);\r
3975                                 break;\r
3976                         case BT_8703B_2ANT_COEX_ALGO_A2DP:\r
3977                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = A2DP.\n"));\r
3978                                 halbtc8703b2ant_ActionA2dp(pBtCoexist);\r
3979                                 break;\r
3980                         case BT_8703B_2ANT_COEX_ALGO_A2DP_PANHS:\r
3981                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = A2DP+PAN(HS).\n"));\r
3982                                 halbtc8703b2ant_ActionA2dpPanHs(pBtCoexist);\r
3983                                 break;\r
3984                         case BT_8703B_2ANT_COEX_ALGO_PANEDR:\r
3985                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = PAN(EDR).\n"));\r
3986                                 halbtc8703b2ant_ActionPanEdr(pBtCoexist);\r
3987                                 break;\r
3988                         case BT_8703B_2ANT_COEX_ALGO_PANHS:\r
3989                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = HS mode.\n"));\r
3990                                 halbtc8703b2ant_ActionPanHs(pBtCoexist);\r
3991                                 break;\r
3992                         case BT_8703B_2ANT_COEX_ALGO_PANEDR_A2DP:\r
3993                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = PAN+A2DP.\n"));\r
3994                                 halbtc8703b2ant_ActionPanEdrA2dp(pBtCoexist);\r
3995                                 break;\r
3996                         case BT_8703B_2ANT_COEX_ALGO_PANEDR_HID:\r
3997                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = PAN(EDR)+HID.\n"));\r
3998                                 halbtc8703b2ant_ActionPanEdrHid(pBtCoexist);\r
3999                                 break;\r
4000                         case BT_8703B_2ANT_COEX_ALGO_HID_A2DP_PANEDR:\r
4001                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN.\n"));\r
4002                                 halbtc8703b2ant_ActionHidA2dpPanEdr(pBtCoexist);\r
4003                                 break;\r
4004                         case BT_8703B_2ANT_COEX_ALGO_HID_A2DP:\r
4005                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = HID+A2DP.\n"));\r
4006                                 halbtc8703b2ant_ActionHidA2dp(pBtCoexist);\r
4007                                 break;\r
4008                         default:\r
4009                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = coexist All Off!!\n"));\r
4010                                 halbtc8703b2ant_CoexAllOff(pBtCoexist);\r
4011                                 break;\r
4012                 }\r
4013                 pCoexDm->preAlgorithm = pCoexDm->curAlgorithm;\r
4014         }\r
4015 }\r
4016 \r
4017 VOID\r
4018 halbtc8703b2ant_WifiOffHwCfg(\r
4019         IN      PBTC_COEXIST            pBtCoexist\r
4020         )\r
4021 {\r
4022         BOOLEAN bIsInMpMode = FALSE;\r
4023         u1Byte H2C_Parameter[2] ={0};\r
4024         u4Byte fwVer=0;\r
4025 \r
4026         // set wlan_act to low\r
4027         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4);\r
4028 \r
4029         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x780); //WiFi goto standby while GNT_BT 0-->1\r
4030         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);\r
4031         if(fwVer >= 0x180000)\r
4032         {\r
4033         /* Use H2C to set GNT_BT to HIGH */\r
4034         H2C_Parameter[0] = 1;\r
4035         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x6E, 1, H2C_Parameter);\r
4036         }\r
4037         else\r
4038         {\r
4039                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x18);\r
4040         }\r
4041         \r
4042         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_IS_IN_MP_MODE, &bIsInMpMode);\r
4043         if(!bIsInMpMode)\r
4044                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x0); //BT select s0/s1 is controlled by BT\r
4045         else\r
4046                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x1); //BT select s0/s1 is controlled by WiFi\r
4047 }\r
4048 \r
4049 VOID\r
4050 halbtc8703b2ant_InitHwConfig(\r
4051         IN      PBTC_COEXIST            pBtCoexist,\r
4052         IN      BOOLEAN                         bBackUp\r
4053         )\r
4054 {\r
4055         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;\r
4056         u4Byte  u4Tmp=0, fwVer;\r
4057         u2Byte                          u2Tmp=0;\r
4058         u1Byte  u1Tmp=0;\r
4059         u1Byte                          H2C_Parameter[2] ={0};\r
4060                 \r
4061 \r
4062         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], 2Ant Init HW Config!!\n"));\r
4063 \r
4064         // backup rf 0x1e value\r
4065         pCoexDm->btRf0x1eBackup = \r
4066                 pBtCoexist->fBtcGetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff);  \r
4067 \r
4068         // 0x790[5:0]=0x5\r
4069         u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x790);\r
4070         u1Tmp &= 0xc0;\r
4071         u1Tmp |= 0x5;\r
4072         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x790, u1Tmp);\r
4073 \r
4074         //Antenna config        \r
4075         halbtc8703b2ant_SetAntPath(pBtCoexist, BTC_ANT_WIFI_AT_MAIN, TRUE, FALSE);\r
4076         pCoexSta->disVerInfoCnt = 0;\r
4077 \r
4078         // PTA parameter\r
4079         halbtc8703b2ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);\r
4080         \r
4081         // Enable counter statistics\r
4082         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4); //0x76e[3] =1, WLAN_Act control by PTA\r
4083         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x778, 0x3);\r
4084         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x40, 0x20, 0x1);\r
4085 }\r
4086 \r
4087 //============================================================\r
4088 // work around function start with wa_halbtc8703b2ant_\r
4089 //============================================================\r
4090 //============================================================\r
4091 // extern function start with EXhalbtc8703b2ant_\r
4092 //============================================================\r
4093 VOID\r
4094 EXhalbtc8703b2ant_PowerOnSetting(\r
4095         IN      PBTC_COEXIST            pBtCoexist\r
4096         )\r
4097 {\r
4098         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;\r
4099         u2Byte u2Tmp=0x0;\r
4100 \r
4101         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x67, 0x20);\r
4102 \r
4103         // enable BB, REG_SYS_FUNC_EN such that we can write 0x948 correctly.\r
4104         u2Tmp = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x2);\r
4105         pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x2, u2Tmp|BIT0|BIT1);\r
4106 \r
4107         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);\r
4108 \r
4109         if(pBtCoexist->chipInterface == BTC_INTF_USB)\r
4110         {\r
4111                 // fixed at S0 for USB interface\r
4112                 pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_AUX_PORT;\r
4113         }\r
4114         else\r
4115         {\r
4116                 // for PCIE and SDIO interface, we check efuse 0xc3[6]\r
4117                 if(pBoardInfo->singleAntPath == 0)\r
4118                 {\r
4119                         // set to S1\r
4120                         pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;\r
4121                 }\r
4122                 else if(pBoardInfo->singleAntPath == 1)\r
4123                 {\r
4124                         // set to S0\r
4125                         pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_AUX_PORT;\r
4126                 }\r
4127         }\r
4128 }\r
4129 \r
4130 VOID\r
4131 EXhalbtc8703b2ant_PreLoadFirmware(\r
4132         IN      PBTC_COEXIST            pBtCoexist\r
4133         )\r
4134 {\r
4135         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;\r
4136         u1Byte u1Tmp=0x4; /* Set BIT2 by default since it's 2ant case */\r
4137 \r
4138         // \r
4139         // S0 or S1 setting and Local register setting(By the setting fw can get ant number, S0/S1, ... info)\r
4140         // Local setting bit define\r
4141         //      BIT0: "0" for no antenna inverse; "1" for antenna inverse \r
4142         //      BIT1: "0" for internal switch; "1" for external switch\r
4143         //      BIT2: "0" for one antenna; "1" for two antenna\r
4144         // NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and BIT2=0\r
4145         if(pBtCoexist->chipInterface == BTC_INTF_USB)\r
4146         {\r
4147                 // fixed at S0 for USB interface\r
4148                 u1Tmp |= 0x1;   // antenna inverse\r
4149                 pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0xfe08, u1Tmp);\r
4150         }\r
4151         else\r
4152         {\r
4153                 // for PCIE and SDIO interface, we check efuse 0xc3[6]\r
4154                 if(pBoardInfo->singleAntPath == 0)\r
4155                 {\r
4156                 }\r
4157                 else if(pBoardInfo->singleAntPath == 1)\r
4158                 {\r
4159                         // set to S0\r
4160                         u1Tmp |= 0x1;   // antenna inverse\r
4161                 }\r
4162 \r
4163                 if(pBtCoexist->chipInterface == BTC_INTF_PCI)\r
4164                 {       \r
4165                         pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0x384, u1Tmp);\r
4166                 }\r
4167                 else if(pBtCoexist->chipInterface == BTC_INTF_SDIO)\r
4168                 {\r
4169                         pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0x60, u1Tmp);\r
4170                 }                       \r
4171         }\r
4172 }\r
4173 \r
4174 VOID\r
4175 EXhalbtc8703b2ant_InitHwConfig(\r
4176         IN      PBTC_COEXIST            pBtCoexist,\r
4177         IN      BOOLEAN                         bWifiOnly\r
4178         )\r
4179 {\r
4180         halbtc8703b2ant_InitHwConfig(pBtCoexist, TRUE);\r
4181 }\r
4182 \r
4183 VOID\r
4184 EXhalbtc8703b2ant_InitCoexDm(\r
4185         IN      PBTC_COEXIST            pBtCoexist\r
4186         )\r
4187 {\r
4188         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Coex Mechanism Init!!\n"));\r
4189         \r
4190         halbtc8703b2ant_InitCoexDm(pBtCoexist);\r
4191 }\r
4192 \r
4193 VOID\r
4194 EXhalbtc8703b2ant_DisplayCoexInfo(\r
4195         IN      PBTC_COEXIST            pBtCoexist\r
4196         )\r
4197 {\r
4198         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;\r
4199         PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;\r
4200         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
4201         pu1Byte                         cliBuf=pBtCoexist->cliBuf;\r
4202         u1Byte                          u1Tmp[4], i, btInfoExt, psTdmaCase=0;\r
4203         u4Byte                          u4Tmp[4];\r
4204         u4Byte                          faOfdm, faCck;\r
4205         u4Byte                          fwVer=0, btPatchVer=0;\r
4206 \r
4207         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[BT Coexist info]============");\r
4208         CL_PRINTF(cliBuf);\r
4209 \r
4210         if(pBtCoexist->bManualControl)\r
4211         {\r
4212                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[Under Manual Control]============");\r
4213                 CL_PRINTF(cliBuf);\r
4214                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ==========================================");\r
4215                 CL_PRINTF(cliBuf);\r
4216         }\r
4217 \r
4218         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ", "Ant PG number/ Ant mechanism:", \\r
4219                 pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum);\r
4220         CL_PRINTF(cliBuf);\r
4221         \r
4222         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d", "BT stack/ hci ext ver", \\r
4223                 ((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion);\r
4224         CL_PRINTF(cliBuf);\r
4225 \r
4226         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);\r
4227         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);\r
4228         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)", "CoexVer/ FwVer/ PatchVer", \\r
4229                 GLCoexVerDate8703b2Ant, GLCoexVer8703b2Ant, fwVer, btPatchVer, btPatchVer);\r
4230         CL_PRINTF(cliBuf);\r
4231 \r
4232         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", "Wifi channel informed to BT", \\r
4233                 pCoexDm->wifiChnlInfo[0], pCoexDm->wifiChnlInfo[1],\r
4234                 pCoexDm->wifiChnlInfo[2]);\r
4235         CL_PRINTF(cliBuf);\r
4236 \r
4237         // wifi status\r
4238         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Wifi Status]============");\r
4239         CL_PRINTF(cliBuf);\r
4240         pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_WIFI_STATUS);\r
4241 \r
4242         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[BT Status]============");\r
4243         CL_PRINTF(cliBuf);\r
4244 \r
4245         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %ddBm/ %d] ", "BT [status/ rssi/ retryCnt]", \\r
4246                 ((pBtCoexist->btInfo.bBtDisabled)? ("disabled"):        ((pCoexSta->bC2hBtInquiryPage)?("inquiry/page scan"):((BT_8703B_2ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)? "non-connected idle":\r
4247                 (  (BT_8703B_2ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus)? "connected-idle":"busy")))),\r
4248                 pCoexSta->btRssi-100, pCoexSta->btRetryCnt);\r
4249         CL_PRINTF(cliBuf);\r
4250 \r
4251         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP", \\r
4252                 pBtLinkInfo->bScoExist, pBtLinkInfo->bHidExist, pBtLinkInfo->bPanExist, pBtLinkInfo->bA2dpExist);\r
4253         CL_PRINTF(cliBuf);\r
4254 \r
4255         if (pStackInfo->bProfileNotified)\r
4256         {\r
4257         pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_BT_LINK_INFO);\r
4258         }\r
4259         else\r
4260         {\r
4261                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "BT Role", \\r
4262                 (pBtLinkInfo->bSlaveRole )? "Slave":"Master");\r
4263                 CL_PRINTF(cliBuf);      \r
4264         }       \r
4265 \r
4266         btInfoExt = pCoexSta->btInfoExt;\r
4267         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "BT Info A2DP rate", \\r
4268                 (btInfoExt&BIT0)? "Basic rate":"EDR rate");\r
4269         CL_PRINTF(cliBuf);      \r
4270 \r
4271         for(i=0; i<BT_INFO_SRC_8703B_2ANT_MAX; i++)\r
4272         {\r
4273                 if(pCoexSta->btInfoC2hCnt[i])\r
4274                 {                               \r
4275                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", GLBtInfoSrc8703b2Ant[i], \\r
4276                                 pCoexSta->btInfoC2h[i][0], pCoexSta->btInfoC2h[i][1],\r
4277                                 pCoexSta->btInfoC2h[i][2], pCoexSta->btInfoC2h[i][3],\r
4278                                 pCoexSta->btInfoC2h[i][4], pCoexSta->btInfoC2h[i][5],\r
4279                                 pCoexSta->btInfoC2h[i][6], pCoexSta->btInfoC2hCnt[i]);\r
4280                         CL_PRINTF(cliBuf);\r
4281                 }\r
4282         }\r
4283 \r
4284         // Sw mechanism \r
4285         if(pBtCoexist->bManualControl)\r
4286         {                       \r
4287                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw mechanism] (before Manual)============");                    \r
4288         }\r
4289         else\r
4290         {\r
4291                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw mechanism]============");\r
4292         }\r
4293         \r
4294         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d ", "SM1[ShRf/ LpRA/ LimDig]", \\r
4295                 pCoexDm->bCurRfRxLpfShrink, pCoexDm->bCurLowPenaltyRa, pCoexDm->bLimitedDig);\r
4296         CL_PRINTF(cliBuf);\r
4297         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d(0x%x) ", "SM2[AgcT/ AdcB/ SwDacSwing(lvl)]", \\r
4298                 pCoexDm->bCurAgcTableEn, pCoexDm->bCurAdcBackOff, pCoexDm->bCurDacSwingOn, pCoexDm->curDacSwingLvl);\r
4299         CL_PRINTF(cliBuf);\r
4300 \r
4301         // Fw mechanism         \r
4302         if(pBtCoexist->bManualControl)\r
4303         {\r
4304                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw mechanism] (before Manual) ============");                   \r
4305         }\r
4306         else\r
4307         {\r
4308                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw mechanism]============");\r
4309         }\r
4310 \r
4311         psTdmaCase = pCoexDm->curPsTdma;\r
4312 \r
4313         if (pCoexDm->bIsSwitchTo1dot5Ant)\r
4314                 psTdmaCase = psTdmaCase + 100;\r
4315                 \r
4316         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (%s,%s)", "PS TDMA", \\r
4317                 pCoexDm->psTdmaPara[0], pCoexDm->psTdmaPara[1],\r
4318                 pCoexDm->psTdmaPara[2], pCoexDm->psTdmaPara[3],\r
4319                         pCoexDm->psTdmaPara[4], psTdmaCase, \r
4320                         (pCoexDm->bCurPsTdmaOn? "On":"Off"),\r
4321                         (pCoexDm->bAutoTdmaAdjust? "Adj":"Fix") );\r
4322         CL_PRINTF(cliBuf);\r
4323 \r
4324         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "Coex Table Type", \\r
4325                         pCoexSta->nCoexTableType);\r
4326                 CL_PRINTF(cliBuf);\r
4327 \r
4328         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ", "DecBtPwr/ IgnWlanAct", \\r
4329                 pCoexDm->curBtDecPwrLvl, pCoexDm->bCurIgnoreWlanAct);\r
4330         CL_PRINTF(cliBuf);\r
4331 \r
4332         // Hw setting           \r
4333         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Hw setting]============");\r
4334         CL_PRINTF(cliBuf);      \r
4335 \r
4336         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "RF-A, 0x1e initVal", \\r
4337                 pCoexDm->btRf0x1eBackup);\r
4338         CL_PRINTF(cliBuf);\r
4339 \r
4340         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x778);\r
4341         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x880);\r
4342         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0x778/0x880[29:25]", \\r
4343                 u1Tmp[0], (u4Tmp[0]&0x3e000000) >> 25);\r
4344         CL_PRINTF(cliBuf);\r
4345 \r
4346 \r
4347         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x948);\r
4348         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x67);\r
4349         u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x765);\r
4350         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x948/ 0x67[5] / 0x765", \\r
4351                 u4Tmp[0], ((u1Tmp[0]&0x20)>> 5), u1Tmp[1]);\r
4352         CL_PRINTF(cliBuf);\r
4353         \r
4354         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x92c);\r
4355         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x930);\r
4356         u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x944);        \r
4357         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x92c[1:0]/ 0x930[7:0]/0x944[1:0]", \\r
4358                 u4Tmp[0]&0x3, u4Tmp[1]&0xff, u4Tmp[2]&0x3);\r
4359         CL_PRINTF(cliBuf);\r
4360 \r
4361 \r
4362         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x39);\r
4363         u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x40);\r
4364         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);\r
4365         u1Tmp[2] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x64);\r
4366         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0x38[11]/0x40/0x4c[24:23]/0x64[0]", \\r
4367                 ((u1Tmp[0] & 0x8)>>3), u1Tmp[1], ((u4Tmp[0]&0x01800000)>>23), u1Tmp[2]&0x1);\r
4368         CL_PRINTF(cliBuf);\r
4369 \r
4370         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x550);\r
4371         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x522);\r
4372         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0x550(bcn ctrl)/0x522", \\r
4373                 u4Tmp[0], u1Tmp[0]);\r
4374         CL_PRINTF(cliBuf);\r
4375 \r
4376         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xc50);\r
4377         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x49c);\r
4378         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0xc50(dig)/0x49c(null-drop)", \\r
4379                 u4Tmp[0]&0xff, u1Tmp[0]);\r
4380         CL_PRINTF(cliBuf);\r
4381 \r
4382         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda0);\r
4383         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda4);\r
4384         u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda8);\r
4385         u4Tmp[3] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xcf0);\r
4386 \r
4387         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xa5b);\r
4388         u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xa5c);\r
4389 \r
4390         faOfdm = ((u4Tmp[0]&0xffff0000) >> 16) +  ((u4Tmp[1]&0xffff0000) >> 16) + (u4Tmp[1] & 0xffff) +  (u4Tmp[2] & 0xffff) + \\r
4391                              ((u4Tmp[3]&0xffff0000) >> 16) + (u4Tmp[3] & 0xffff) ;\r
4392         faCck = (u1Tmp[0] << 8) + u1Tmp[1];\r
4393         \r
4394         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "OFDM-CCA/OFDM-FA/CCK-FA", \\r
4395                 u4Tmp[0]&0xffff, faOfdm, faCck);\r
4396         CL_PRINTF(cliBuf);\r
4397 \r
4398         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", "CRC_OK CCK/11g/11n/11n-Agg", \\r
4399                 pCoexSta->nCRCOK_CCK, pCoexSta->nCRCOK_11g, pCoexSta->nCRCOK_11n, pCoexSta->nCRCOK_11nAgg);\r
4400         CL_PRINTF(cliBuf);\r
4401 \r
4402         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", "CRC_Err CCK/11g/11n/11n-Agg", \\r
4403                 pCoexSta->nCRCErr_CCK, pCoexSta->nCRCErr_11g, pCoexSta->nCRCErr_11n, pCoexSta->nCRCErr_11nAgg);\r
4404         CL_PRINTF(cliBuf);      \r
4405 \r
4406         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c0);\r
4407         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c4);\r
4408         u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c8);\r
4409         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x6cc);\r
4410         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)", \\r
4411                 u4Tmp[0], u4Tmp[1], u4Tmp[2], u1Tmp[0]);\r
4412         CL_PRINTF(cliBuf);\r
4413 \r
4414         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x770(high-pri rx/tx)", \\r
4415                 pCoexSta->highPriorityRx, pCoexSta->highPriorityTx);\r
4416         CL_PRINTF(cliBuf);\r
4417         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x774(low-pri rx/tx)", \\r
4418                 pCoexSta->lowPriorityRx, pCoexSta->lowPriorityTx);\r
4419         CL_PRINTF(cliBuf);\r
4420 #if(BT_AUTO_REPORT_ONLY_8703B_2ANT == 1)\r
4421         //halbtc8703b2ant_MonitorBtCtr(pBtCoexist);\r
4422 #endif\r
4423         pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_COEX_STATISTICS);\r
4424 }\r
4425 \r
4426 \r
4427 VOID\r
4428 EXhalbtc8703b2ant_IpsNotify(\r
4429         IN      PBTC_COEXIST            pBtCoexist,\r
4430         IN      u1Byte                  type\r
4431         )\r
4432 {\r
4433         if(BTC_IPS_ENTER == type)\r
4434         {\r
4435                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], IPS ENTER notify\n"));\r
4436                 pCoexSta->bUnderIps = TRUE;\r
4437                 halbtc8703b2ant_WifiOffHwCfg(pBtCoexist);\r
4438                 halbtc8703b2ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE);\r
4439                 halbtc8703b2ant_CoexAllOff(pBtCoexist);\r
4440         }\r
4441         else if(BTC_IPS_LEAVE == type)\r
4442         {\r
4443                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], IPS LEAVE notify\n"));\r
4444                 pCoexSta->bUnderIps = FALSE;\r
4445                 halbtc8703b2ant_InitHwConfig(pBtCoexist, FALSE);\r
4446                 halbtc8703b2ant_InitCoexDm(pBtCoexist);\r
4447                 halbtc8703b2ant_QueryBtInfo(pBtCoexist);\r
4448         }\r
4449 }\r
4450 \r
4451 VOID\r
4452 EXhalbtc8703b2ant_LpsNotify(\r
4453         IN      PBTC_COEXIST            pBtCoexist,\r
4454         IN      u1Byte                  type\r
4455         )\r
4456 {\r
4457         if(BTC_LPS_ENABLE == type)\r
4458         {\r
4459                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], LPS ENABLE notify\n"));\r
4460                 pCoexSta->bUnderLps = TRUE;\r
4461         }\r
4462         else if(BTC_LPS_DISABLE == type)\r
4463         {\r
4464                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], LPS DISABLE notify\n"));\r
4465                 pCoexSta->bUnderLps = FALSE;\r
4466         }\r
4467 }\r
4468 \r
4469 VOID\r
4470 EXhalbtc8703b2ant_ScanNotify(\r
4471         IN      PBTC_COEXIST            pBtCoexist,\r
4472         IN      u1Byte                  type\r
4473         )\r
4474 {\r
4475         u4Byte  u4Tmp;\r
4476         u1Byte  u1Tmpa, u1Tmpb; \r
4477         \r
4478 \r
4479 \r
4480         u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x948);\r
4481         u1Tmpa = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x765);\r
4482         u1Tmpb = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x76e);\r
4483         \r
4484         if(BTC_SCAN_START == type)\r
4485         {\r
4486                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN START notify\n"));\r
4487         }\r
4488         else if(BTC_SCAN_FINISH == type)\r
4489         {\r
4490                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN FINISH notify\n"));\r
4491         }\r
4492 \r
4493         RT_TRACE(COMP_COEX, DBG_LOUD, ("############# [BTCoex], 0x948=0x%x, 0x765=0x%x, 0x76e=0x%x\n",\r
4494                 u4Tmp,  u1Tmpa, u1Tmpb));\r
4495 }\r
4496 \r
4497 VOID\r
4498 EXhalbtc8703b2ant_ConnectNotify(\r
4499         IN      PBTC_COEXIST            pBtCoexist,\r
4500         IN      u1Byte                  type\r
4501         )\r
4502 {\r
4503         if(BTC_ASSOCIATE_START == type)\r
4504         {\r
4505                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT START notify\n"));\r
4506         }\r
4507         else if(BTC_ASSOCIATE_FINISH == type)\r
4508         {\r
4509                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT FINISH notify\n"));\r
4510         }\r
4511 }\r
4512 \r
4513 VOID\r
4514 EXhalbtc8703b2ant_MediaStatusNotify(\r
4515         IN      PBTC_COEXIST            pBtCoexist,\r
4516         IN      u1Byte                          type\r
4517         )\r
4518 {\r
4519         u1Byte                  H2C_Parameter[3] ={0};\r
4520         u4Byte                  wifiBw;\r
4521         u1Byte                  wifiCentralChnl;\r
4522         u1Byte                  apNum=0;\r
4523 \r
4524         if(BTC_MEDIA_CONNECT == type)\r
4525         {\r
4526                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], MEDIA connect notify\n"));\r
4527         }\r
4528         else\r
4529         {\r
4530                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], MEDIA disconnect notify\n"));\r
4531         }\r
4532 \r
4533         // only 2.4G we need to inform bt the chnl mask\r
4534         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, &wifiCentralChnl);\r
4535         if( (BTC_MEDIA_CONNECT == type) &&\r
4536                 (wifiCentralChnl <= 14) )\r
4537         {\r
4538                 H2C_Parameter[0] = 0x1;\r
4539                 H2C_Parameter[1] = wifiCentralChnl;\r
4540                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
4541                 if(BTC_WIFI_BW_HT40 == wifiBw)\r
4542                         H2C_Parameter[2] = 0x30;\r
4543                 else\r
4544                 {\r
4545                         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_AP_NUM, &apNum);\r
4546                         if(apNum < 10)\r
4547                                 H2C_Parameter[2] = 0x30;\r
4548                         else\r
4549                                 H2C_Parameter[2] = 0x20;\r
4550         }\r
4551         }\r
4552         \r
4553         pCoexDm->wifiChnlInfo[0] = H2C_Parameter[0];\r
4554         pCoexDm->wifiChnlInfo[1] = H2C_Parameter[1];\r
4555         pCoexDm->wifiChnlInfo[2] = H2C_Parameter[2];\r
4556         \r
4557         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], FW write 0x66=0x%x\n", \r
4558                 H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));\r
4559 \r
4560         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x66, 3, H2C_Parameter);    \r
4561 }\r
4562 \r
4563 VOID\r
4564 EXhalbtc8703b2ant_SpecialPacketNotify(\r
4565         IN      PBTC_COEXIST                    pBtCoexist,\r
4566         IN      u1Byte                          type\r
4567         )\r
4568 {\r
4569         if(type == BTC_PACKET_DHCP)\r
4570         {\r
4571                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], DHCP Packet notify\n"));\r
4572         }\r
4573 }\r
4574 \r
4575 VOID\r
4576 EXhalbtc8703b2ant_BtInfoNotify(\r
4577         IN      PBTC_COEXIST            pBtCoexist,\r
4578         IN      pu1Byte                 tmpBuf,\r
4579         IN      u1Byte                  length\r
4580         )\r
4581 {\r
4582         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
4583         u1Byte                  btInfo=0;\r
4584         u1Byte                  i, rspSource=0;\r
4585         BOOLEAN                 bBtBusy=FALSE, bLimitedDig=FALSE;\r
4586         BOOLEAN                 bWifiConnected=FALSE;\r
4587         static BOOLEAN          bPreScoExist=FALSE;\r
4588         u4Byte                          raMask=0x0;\r
4589 \r
4590         pCoexSta->bC2hBtInfoReqSent = FALSE;\r
4591 \r
4592         rspSource = tmpBuf[0]&0xf;\r
4593         if(rspSource >= BT_INFO_SRC_8703B_2ANT_MAX)\r
4594                 rspSource = BT_INFO_SRC_8703B_2ANT_WIFI_FW;\r
4595         pCoexSta->btInfoC2hCnt[rspSource]++;\r
4596 \r
4597         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Bt info[%d], length=%d, hex data=[", rspSource, length));\r
4598         for(i=0; i<length; i++)\r
4599         {\r
4600                 pCoexSta->btInfoC2h[rspSource][i] = tmpBuf[i];\r
4601                 if(i == 1)\r
4602                         btInfo = tmpBuf[i];\r
4603                 if(i == length-1)\r
4604                 {\r
4605                         RT_TRACE(COMP_COEX, DBG_LOUD, ("0x%02x]\n", tmpBuf[i]));\r
4606                 }\r
4607                 else\r
4608                 {\r
4609                         RT_TRACE(COMP_COEX, DBG_LOUD, ("0x%02x, ", tmpBuf[i]));\r
4610                 }\r
4611         }\r
4612 \r
4613         if(pBtCoexist->bManualControl)\r
4614         {\r
4615                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), return for Manual CTRL<===\n"));\r
4616                 return;\r
4617         }\r
4618 \r
4619         // if 0xff, it means BT is under WHCK test\r
4620         if (btInfo == 0xff)\r
4621                 pCoexSta->bBtWhckTest = TRUE;\r
4622         else\r
4623                 pCoexSta->bBtWhckTest = FALSE;\r
4624 \r
4625         if(BT_INFO_SRC_8703B_2ANT_WIFI_FW != rspSource)\r
4626         {\r
4627                 pCoexSta->btRetryCnt =  // [3:0]\r
4628                         pCoexSta->btInfoC2h[rspSource][2]&0xf;\r
4629 \r
4630                 pCoexSta->btRssi =\r
4631                         pCoexSta->btInfoC2h[rspSource][3]*2+10;\r
4632 \r
4633                 pCoexSta->btInfoExt = \r
4634                         pCoexSta->btInfoC2h[rspSource][4];\r
4635 \r
4636                 pCoexSta->bBtTxRxMask = (pCoexSta->btInfoC2h[rspSource][2]&0x40);\r
4637                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TX_RX_MASK, &pCoexSta->bBtTxRxMask);\r
4638                 if (pCoexSta->bBtTxRxMask)\r
4639                 {\r
4640                         /* BT into is responded by BT FW and BT RF REG 0x3C != 0x01 => Need to switch BT TRx Mask */                            \r
4641                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Switch BT TRx Mask since BT RF REG 0x3C != 0x01\n"));\r
4642                         pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x3c, 0x01);\r
4643                 }\r
4644 \r
4645                 // Here we need to resend some wifi info to BT\r
4646                 // because bt is reset and loss of the info.\r
4647                 if( (pCoexSta->btInfoExt & BIT1) )\r
4648                 {\r
4649                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"));\r
4650                         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
4651                         if(bWifiConnected)\r
4652                         {\r
4653                                 EXhalbtc8703b2ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_CONNECT);\r
4654                         }\r
4655                         else\r
4656                         {\r
4657                                 EXhalbtc8703b2ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);\r
4658                         }\r
4659                 }\r
4660                 \r
4661                 if( (pCoexSta->btInfoExt & BIT3) )\r
4662                 {\r
4663                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n"));\r
4664                         halbtc8703b2ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, FALSE);\r
4665                 }\r
4666                 else\r
4667                 {\r
4668                         // BT already NOT ignore Wlan active, do nothing here.\r
4669                 }\r
4670 #if(BT_AUTO_REPORT_ONLY_8703B_2ANT == 0)\r
4671                 if( (pCoexSta->btInfoExt & BIT4) )\r
4672                 {\r
4673                         // BT auto report already enabled, do nothing\r
4674                 }\r
4675                 else\r
4676                 {\r
4677                         halbtc8703b2ant_BtAutoReport(pBtCoexist, FORCE_EXEC, TRUE);\r
4678                 }\r
4679 #endif\r
4680         }\r
4681 \r
4682         // check BIT2 first ==> check if bt is under inquiry or page scan\r
4683         if(btInfo & BT_INFO_8703B_2ANT_B_INQ_PAGE)\r
4684                 pCoexSta->bC2hBtInquiryPage = TRUE;\r
4685         else\r
4686                 pCoexSta->bC2hBtInquiryPage = FALSE;\r
4687 \r
4688         // set link exist status\r
4689         if(!(btInfo&BT_INFO_8703B_2ANT_B_CONNECTION))\r
4690         {\r
4691                 pCoexSta->bBtLinkExist = FALSE;\r
4692                 pCoexSta->bPanExist = FALSE;\r
4693                 pCoexSta->bA2dpExist = FALSE;\r
4694                 pCoexSta->bHidExist = FALSE;\r
4695                 pCoexSta->bScoExist = FALSE;\r
4696         }\r
4697         else    // connection exists\r
4698         {\r
4699                 pCoexSta->bBtLinkExist = TRUE;\r
4700                 if(btInfo & BT_INFO_8703B_2ANT_B_FTP)\r
4701                         pCoexSta->bPanExist = TRUE;\r
4702                 else\r
4703                         pCoexSta->bPanExist = FALSE;\r
4704                 if(btInfo & BT_INFO_8703B_2ANT_B_A2DP)\r
4705                         pCoexSta->bA2dpExist = TRUE;\r
4706                 else\r
4707                         pCoexSta->bA2dpExist = FALSE;\r
4708                 if(btInfo & BT_INFO_8703B_2ANT_B_HID)\r
4709                         pCoexSta->bHidExist = TRUE;\r
4710                 else\r
4711                         pCoexSta->bHidExist = FALSE;\r
4712                 if(btInfo & BT_INFO_8703B_2ANT_B_SCO_ESCO)\r
4713                         pCoexSta->bScoExist = TRUE;\r
4714                 else\r
4715                         pCoexSta->bScoExist = FALSE;\r
4716 \r
4717                 if ( (pCoexSta->bHidExist == FALSE) && (pCoexSta->bC2hBtInquiryPage == FALSE) && (pCoexSta->bScoExist == FALSE))\r
4718                 {\r
4719                         if (pCoexSta->highPriorityTx  + pCoexSta->highPriorityRx >= 160)                \r
4720                         {\r
4721                                 pCoexSta->bHidExist = TRUE;\r
4722                                 btInfo = btInfo | 0x20;\r
4723                         }\r
4724                 }\r
4725         }\r
4726 \r
4727         halbtc8703b2ant_UpdateBtLinkInfo(pBtCoexist);\r
4728         \r
4729         if(!(btInfo&BT_INFO_8703B_2ANT_B_CONNECTION))\r
4730         {\r
4731                 pCoexDm->btStatus = BT_8703B_2ANT_BT_STATUS_NON_CONNECTED_IDLE;\r
4732                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n"));\r
4733         }\r
4734         else if(btInfo == BT_INFO_8703B_2ANT_B_CONNECTION)      // connection exists but no busy\r
4735         {\r
4736                 pCoexDm->btStatus = BT_8703B_2ANT_BT_STATUS_CONNECTED_IDLE;\r
4737                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n"));\r
4738         }\r
4739         else if((btInfo&BT_INFO_8703B_2ANT_B_SCO_ESCO) ||\r
4740                 (btInfo&BT_INFO_8703B_2ANT_B_SCO_BUSY))\r
4741         {\r
4742                 pCoexDm->btStatus = BT_8703B_2ANT_BT_STATUS_SCO_BUSY;\r
4743                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT SCO busy!!!\n"));\r
4744         }\r
4745         else if(btInfo&BT_INFO_8703B_2ANT_B_ACL_BUSY)\r
4746         {\r
4747                 pCoexDm->btStatus = BT_8703B_2ANT_BT_STATUS_ACL_BUSY;\r
4748                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT ACL busy!!!\n"));\r
4749         }\r
4750         else\r
4751         {\r
4752                 pCoexDm->btStatus = BT_8703B_2ANT_BT_STATUS_MAX;\r
4753                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n"));\r
4754         }\r
4755         \r
4756         if( (BT_8703B_2ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus) ||\r
4757                 (BT_8703B_2ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||\r
4758                 (BT_8703B_2ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )\r
4759         {\r
4760                 bBtBusy = TRUE;\r
4761                 bLimitedDig = TRUE;\r
4762         }\r
4763         else\r
4764         {\r
4765                 bBtBusy = FALSE;\r
4766                 bLimitedDig = FALSE;\r
4767         }\r
4768 \r
4769         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);\r
4770 \r
4771         pCoexDm->bLimitedDig = bLimitedDig;\r
4772         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_LIMITED_DIG, &bLimitedDig);\r
4773 \r
4774         halbtc8703b2ant_RunCoexistMechanism(pBtCoexist);\r
4775 }\r
4776 \r
4777 VOID\r
4778 EXhalbtc8703b2ant_HaltNotify(\r
4779         IN      PBTC_COEXIST                    pBtCoexist\r
4780         )\r
4781 {\r
4782         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Halt notify\n"));\r
4783 \r
4784         halbtc8703b2ant_WifiOffHwCfg(pBtCoexist);\r
4785         //remove due to interrupt is disabled that polling c2h will fail and delay 100ms.\r
4786         //pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x3c, 0x15); //BT goto standby while GNT_BT 1-->0\r
4787         halbtc8703b2ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE);\r
4788         \r
4789         EXhalbtc8703b2ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);\r
4790 }\r
4791 \r
4792 VOID\r
4793 EXhalbtc8703b2ant_PnpNotify(\r
4794         IN      PBTC_COEXIST                    pBtCoexist,\r
4795         IN      u1Byte                          pnpState\r
4796         )\r
4797 {\r
4798         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Pnp notify\n"));\r
4799 \r
4800         if(BTC_WIFI_PNP_SLEEP == pnpState)\r
4801         {\r
4802                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Pnp notify to SLEEP\n"));\r
4803         }\r
4804         else if(BTC_WIFI_PNP_WAKE_UP == pnpState)\r
4805         {\r
4806                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Pnp notify to WAKE UP\n"));\r
4807                 halbtc8703b2ant_InitHwConfig(pBtCoexist, FALSE);\r
4808                 halbtc8703b2ant_InitCoexDm(pBtCoexist);\r
4809                 halbtc8703b2ant_QueryBtInfo(pBtCoexist);\r
4810         }\r
4811 }\r
4812 \r
4813 VOID\r
4814 EXhalbtc8703b2ant_Periodical(\r
4815         IN      PBTC_COEXIST                    pBtCoexist\r
4816         )\r
4817 {\r
4818         //static u1Byte         disVerInfoCnt=0;\r
4819         u4Byte                          fwVer=0, btPatchVer=0;\r
4820         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;\r
4821         PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;\r
4822 \r
4823         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ==========================Periodical===========================\n"));\r
4824 \r
4825         if(pCoexSta->disVerInfoCnt <= 5)\r
4826         {\r
4827                 pCoexSta->disVerInfoCnt += 1;\r
4828                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ****************************************************************\n"));\r
4829                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Ant PG Num/ Ant Mech/ Ant Pos = %d/ %d/ %d\n",\r
4830                         pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum, pBoardInfo->btdmAntPos));\r
4831                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT stack/ hci ext ver = %s / %d\n",\r
4832                         ((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion));\r
4833                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);\r
4834                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);\r
4835                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CoexVer/ FwVer/ PatchVer = %d_%x/ 0x%x/ 0x%x(%d)\n",\r
4836                         GLCoexVerDate8703b2Ant, GLCoexVer8703b2Ant, fwVer, btPatchVer, btPatchVer));\r
4837                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ****************************************************************\n"));\r
4838 \r
4839                 if (pCoexSta->disVerInfoCnt == 3)\r
4840                 {\r
4841                         //Antenna config to set 0x765 = 0x0 (GNT_BT control by PTA) after initial \r
4842                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Set GNT_BT control by PTA\n"));\r
4843                         halbtc8703b2ant_SetAntPath(pBtCoexist, BTC_ANT_WIFI_AT_MAIN, FALSE, FALSE);\r
4844                 }\r
4845         }\r
4846 \r
4847 #if(BT_AUTO_REPORT_ONLY_8703B_2ANT == 0)\r
4848         halbtc8703b2ant_QueryBtInfo(pBtCoexist);\r
4849         halbtc8703b2ant_MonitorBtEnableDisable(pBtCoexist);\r
4850 #else\r
4851         halbtc8703b2ant_MonitorBtCtr(pBtCoexist);\r
4852         halbtc8703b2ant_MonitorWiFiCtr(pBtCoexist);\r
4853         \r
4854         if( halbtc8703b2ant_IsWifiStatusChanged(pBtCoexist) ||\r
4855                 pCoexDm->bAutoTdmaAdjust)\r
4856         {\r
4857                 halbtc8703b2ant_RunCoexistMechanism(pBtCoexist);\r
4858         }\r
4859 #endif\r
4860 }\r
4861 \r
4862 \r
4863 #endif\r
4864 \r