net: wireless: rockchip_wlan: add rtl8188eu support
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8188eu / hal / btc / HalBtc8703b1Ant.c
1 //============================================================
2 // Description:
3 //
4 // This file is for RTL8703B Co-exist mechanism
5 //
6 // History
7 // 2012/11/15 Cosa first check in.
8 //
9 //============================================================
10
11 //============================================================
12 // include files
13 //============================================================
14 #include "Mp_Precomp.h"
15
16 #if WPP_SOFTWARE_TRACE
17 #include "HalBtc8703b1Ant.tmh"
18 #endif
19
20 #if (RTL8703B_SUPPORT == 1)
21
22 #if(BT_30_SUPPORT == 1)
23 //============================================================
24 // Global variables, these are static variables
25 //============================================================
26 static COEX_DM_8703B_1ANT               GLCoexDm8703b1Ant;
27 static PCOEX_DM_8703B_1ANT      pCoexDm=&GLCoexDm8703b1Ant;
28 static COEX_STA_8703B_1ANT              GLCoexSta8703b1Ant;
29 static PCOEX_STA_8703B_1ANT     pCoexSta=&GLCoexSta8703b1Ant;
30 static PSDSCAN_STA_8703B_1ANT   GLPsdScan8703b1Ant;
31 static PPSDSCAN_STA_8703B_1ANT pPsdScan = &GLPsdScan8703b1Ant;
32
33
34 const char *const GLBtInfoSrc8703b1Ant[]={
35         "BT Info[wifi fw]",
36         "BT Info[bt rsp]",
37         "BT Info[bt auto report]",
38 };
39
40 u4Byte  GLCoexVerDate8703b1Ant=20150904;
41 u4Byte  GLCoexVer8703b1Ant=0x04;
42
43 //============================================================
44 // local function proto type if needed
45 //============================================================
46 //============================================================
47 // local function start with halbtc8703b1ant_
48 //============================================================
49 u1Byte
50 halbtc8703b1ant_BtRssiState(
51         u1Byte                  levelNum,
52         u1Byte                  rssiThresh,
53         u1Byte                  rssiThresh1
54         )
55 {
56         s4Byte                  btRssi=0;
57         u1Byte                  btRssiState=pCoexSta->preBtRssiState;
58
59         btRssi = pCoexSta->btRssi;
60
61         if(levelNum == 2)
62         {                       
63                 if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||
64                         (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW))
65                 {
66                         if(btRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8703B_1ANT))
67                         {
68                                 btRssiState = BTC_RSSI_STATE_HIGH;
69                         }
70                         else
71                         {
72                                 btRssiState = BTC_RSSI_STATE_STAY_LOW;
73                         }
74                 }
75                 else
76                 {
77                         if(btRssi < rssiThresh)
78                         {
79                                 btRssiState = BTC_RSSI_STATE_LOW;
80                         }
81                         else
82                         {
83                                 btRssiState = BTC_RSSI_STATE_STAY_HIGH;
84                         }
85                 }
86         }
87         else if(levelNum == 3)
88         {
89                 if(rssiThresh > rssiThresh1)
90                 {
91                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Rssi thresh error!!\n"));
92                         return pCoexSta->preBtRssiState;
93                 }
94                 
95                 if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||
96                         (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW))
97                 {
98                         if(btRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8703B_1ANT))
99                         {
100                                 btRssiState = BTC_RSSI_STATE_MEDIUM;
101                         }
102                         else
103                         {
104                                 btRssiState = BTC_RSSI_STATE_STAY_LOW;
105                         }
106                 }
107                 else if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_MEDIUM) ||
108                         (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_MEDIUM))
109                 {
110                         if(btRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8703B_1ANT))
111                         {
112                                 btRssiState = BTC_RSSI_STATE_HIGH;
113                         }
114                         else if(btRssi < rssiThresh)
115                         {
116                                 btRssiState = BTC_RSSI_STATE_LOW;
117                         }
118                         else
119                         {
120                                 btRssiState = BTC_RSSI_STATE_STAY_MEDIUM;
121                         }
122                 }
123                 else
124                 {
125                         if(btRssi < rssiThresh1)
126                         {
127                                 btRssiState = BTC_RSSI_STATE_MEDIUM;
128                         }
129                         else
130                         {
131                                 btRssiState = BTC_RSSI_STATE_STAY_HIGH;
132                         }
133                 }
134         }
135                 
136         pCoexSta->preBtRssiState = btRssiState;
137
138         return btRssiState;
139 }
140
141 u1Byte
142 halbtc8703b1ant_WifiRssiState(
143         IN      PBTC_COEXIST            pBtCoexist,
144         IN      u1Byte                  index,
145         IN      u1Byte                  levelNum,
146         IN      u1Byte                  rssiThresh,
147         IN      u1Byte                  rssiThresh1
148         )
149 {
150         s4Byte                  wifiRssi=0;
151         u1Byte                  wifiRssiState=pCoexSta->preWifiRssiState[index];
152
153         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);
154         
155         if(levelNum == 2)
156         {
157                 if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||
158                         (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW))
159                 {
160                         if(wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8703B_1ANT))
161                         {
162                                 wifiRssiState = BTC_RSSI_STATE_HIGH;
163                         }
164                         else
165                         {
166                                 wifiRssiState = BTC_RSSI_STATE_STAY_LOW;
167                         }
168                 }
169                 else
170                 {
171                         if(wifiRssi < rssiThresh)
172                         {
173                                 wifiRssiState = BTC_RSSI_STATE_LOW;
174                         }
175                         else
176                         {
177                                 wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;
178                         }
179                 }
180         }
181         else if(levelNum == 3)
182         {
183                 if(rssiThresh > rssiThresh1)
184                 {
185                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], wifi RSSI thresh error!!\n"));
186                         return pCoexSta->preWifiRssiState[index];
187                 }
188                 
189                 if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||
190                         (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW))
191                 {
192                         if(wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8703B_1ANT))
193                         {
194                                 wifiRssiState = BTC_RSSI_STATE_MEDIUM;
195                         }
196                         else
197                         {
198                                 wifiRssiState = BTC_RSSI_STATE_STAY_LOW;
199                         }
200                 }
201                 else if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_MEDIUM) ||
202                         (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_MEDIUM))
203                 {
204                         if(wifiRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8703B_1ANT))
205                         {
206                                 wifiRssiState = BTC_RSSI_STATE_HIGH;
207                         }
208                         else if(wifiRssi < rssiThresh)
209                         {
210                                 wifiRssiState = BTC_RSSI_STATE_LOW;
211                         }
212                         else
213                         {
214                                 wifiRssiState = BTC_RSSI_STATE_STAY_MEDIUM;
215                         }
216                 }
217                 else
218                 {
219                         if(wifiRssi < rssiThresh1)
220                         {
221                                 wifiRssiState = BTC_RSSI_STATE_MEDIUM;
222                         }
223                         else
224                         {
225                                 wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;
226                         }
227                 }
228         }
229                 
230         pCoexSta->preWifiRssiState[index] = wifiRssiState;
231
232         return wifiRssiState;
233 }
234
235 VOID
236 halbtc8703b1ant_UpdateRaMask(
237         IN      PBTC_COEXIST            pBtCoexist,
238         IN      BOOLEAN                         bForceExec,
239         IN      u4Byte                          disRateMask
240         )
241 {
242         pCoexDm->curRaMask = disRateMask;
243         
244         if( bForceExec || (pCoexDm->preRaMask != pCoexDm->curRaMask))
245         {
246                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_UPDATE_RAMASK, &pCoexDm->curRaMask);
247         }
248         pCoexDm->preRaMask = pCoexDm->curRaMask;
249 }
250
251 VOID
252 halbtc8703b1ant_AutoRateFallbackRetry(
253         IN      PBTC_COEXIST            pBtCoexist,
254         IN      BOOLEAN                         bForceExec,
255         IN      u1Byte                          type
256         )
257 {
258         BOOLEAN bWifiUnderBMode=FALSE;
259         
260         pCoexDm->curArfrType = type;
261
262         if( bForceExec || (pCoexDm->preArfrType != pCoexDm->curArfrType))
263         {
264                 switch(pCoexDm->curArfrType)
265                 {
266                         case 0: // normal mode
267                                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x430, pCoexDm->backupArfrCnt1);
268                                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x434, pCoexDm->backupArfrCnt2);
269                                 break;
270                         case 1: 
271                                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode);
272                                 if(bWifiUnderBMode)
273                                 {
274                                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x430, 0x0);
275                                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x434, 0x01010101);
276                                 }
277                                 else
278                                 {
279                                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x430, 0x0);
280                                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x434, 0x04030201);
281                                 }
282                                 break;
283                         default:
284                                 break;
285                 }
286         }
287
288         pCoexDm->preArfrType = pCoexDm->curArfrType;
289 }
290
291 VOID
292 halbtc8703b1ant_RetryLimit(
293         IN      PBTC_COEXIST            pBtCoexist,
294         IN      BOOLEAN                         bForceExec,
295         IN      u1Byte                          type
296         )
297 {
298         pCoexDm->curRetryLimitType = type;
299
300         if( bForceExec || (pCoexDm->preRetryLimitType != pCoexDm->curRetryLimitType))
301         {
302                 switch(pCoexDm->curRetryLimitType)
303                 {
304                         case 0: // normal mode
305                                 pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x42a, pCoexDm->backupRetryLimit);
306                                 break;
307                         case 1: // retry limit=8
308                                 pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x42a, 0x0808);
309                                 break;
310                         default:
311                                 break;
312                 }
313         }
314
315         pCoexDm->preRetryLimitType = pCoexDm->curRetryLimitType;
316 }
317
318 VOID
319 halbtc8703b1ant_AmpduMaxTime(
320         IN      PBTC_COEXIST            pBtCoexist,
321         IN      BOOLEAN                         bForceExec,
322         IN      u1Byte                          type
323         )
324 {
325         pCoexDm->curAmpduTimeType = type;
326
327         if( bForceExec || (pCoexDm->preAmpduTimeType != pCoexDm->curAmpduTimeType))
328         {
329                 switch(pCoexDm->curAmpduTimeType)
330                 {
331                         case 0: // normal mode
332                                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x456, pCoexDm->backupAmpduMaxTime);
333                                 break;
334                         case 1: // AMPDU timw = 0x38 * 32us
335                                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x456, 0x38);
336                                 break;
337                         default:
338                                 break;
339                 }
340         }
341
342         pCoexDm->preAmpduTimeType = pCoexDm->curAmpduTimeType;
343 }
344
345 VOID
346 halbtc8703b1ant_LimitedTx(
347         IN      PBTC_COEXIST            pBtCoexist,
348         IN      BOOLEAN                         bForceExec,
349         IN      u1Byte                          raMaskType,
350         IN      u1Byte                          arfrType,
351         IN      u1Byte                          retryLimitType,
352         IN      u1Byte                          ampduTimeType
353         )
354 {
355         switch(raMaskType)
356         {
357                 case 0: // normal mode
358                         halbtc8703b1ant_UpdateRaMask(pBtCoexist, bForceExec, 0x0);
359                         break;
360                 case 1: // disable cck 1/2
361                         halbtc8703b1ant_UpdateRaMask(pBtCoexist, bForceExec, 0x00000003);
362                         break;
363                 case 2: // disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4
364                         halbtc8703b1ant_UpdateRaMask(pBtCoexist, bForceExec, 0x0001f1f7);
365                         break;
366                 default:
367                         break;
368         }
369
370         halbtc8703b1ant_AutoRateFallbackRetry(pBtCoexist, bForceExec, arfrType);
371         halbtc8703b1ant_RetryLimit(pBtCoexist, bForceExec, retryLimitType);
372         halbtc8703b1ant_AmpduMaxTime(pBtCoexist, bForceExec, ampduTimeType);
373 }
374
375 VOID
376 halbtc8703b1ant_LimitedRx(
377         IN      PBTC_COEXIST            pBtCoexist,
378         IN      BOOLEAN                         bForceExec,
379         IN      BOOLEAN                         bRejApAggPkt,
380         IN      BOOLEAN                         bBtCtrlAggBufSize,
381         IN      u1Byte                          aggBufSize
382         )
383 {
384         BOOLEAN bRejectRxAgg=bRejApAggPkt;
385         BOOLEAN bBtCtrlRxAggSize=bBtCtrlAggBufSize;
386         u1Byte  rxAggSize=aggBufSize;
387
388         //============================================
389         //      Rx Aggregation related setting
390         //============================================
391         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, &bRejectRxAgg);
392         // decide BT control aggregation buf size or not
393         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, &bBtCtrlRxAggSize);
394         // aggregation buf size, only work when BT control Rx aggregation size.
395         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_AGG_BUF_SIZE, &rxAggSize);
396         // real update aggregation setting
397         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
398
399
400 }
401
402 VOID
403 halbtc8703b1ant_QueryBtInfo(
404         IN      PBTC_COEXIST            pBtCoexist
405         )
406 {
407         u1Byte                  H2C_Parameter[1] ={0};
408
409         pCoexSta->bC2hBtInfoReqSent = TRUE;
410
411         H2C_Parameter[0] |= BIT0;       // trigger
412
413         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Query Bt Info, FW write 0x61=0x%x\n", 
414                 H2C_Parameter[0]));
415
416         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x61, 1, H2C_Parameter);
417 }
418
419 VOID
420 halbtc8703b1ant_MonitorBtCtr(
421         IN      PBTC_COEXIST            pBtCoexist
422         )
423 {
424         u4Byte                  regHPTxRx, regLPTxRx, u4Tmp, u4Tmp1;
425         u4Byte                  regHPTx=0, regHPRx=0, regLPTx=0, regLPRx=0;
426         u1Byte                  u1Tmp, u1Tmp1;
427         s4Byte                  wifiRssi;
428         static u1Byte           NumOfBtCounterChk = 0;
429         
430        //to avoid 0x76e[3] = 1 (WLAN_Act control by PTA) during IPS
431         //if (! (pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x76e) & 0x8) ) 
432
433         if (pCoexSta->bUnderIps)
434         {
435                 //pCoexSta->highPriorityTx = 65535;
436                 //pCoexSta->highPriorityRx = 65535;
437                 //pCoexSta->lowPriorityTx = 65535;
438                 //pCoexSta->lowPriorityRx = 65535;
439                 //return;
440         }
441                 
442         regHPTxRx = 0x770;
443         regLPTxRx = 0x774;
444
445         u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regHPTxRx);
446         regHPTx = u4Tmp & bMaskLWord;
447         regHPRx = (u4Tmp & bMaskHWord)>>16;
448
449         u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regLPTxRx);
450         regLPTx = u4Tmp & bMaskLWord;
451         regLPRx = (u4Tmp & bMaskHWord)>>16;
452                 
453         pCoexSta->highPriorityTx = regHPTx;
454         pCoexSta->highPriorityRx = regHPRx;
455         pCoexSta->lowPriorityTx = regLPTx;
456         pCoexSta->lowPriorityRx = regLPRx;
457
458         if( (pCoexSta->lowPriorityTx > 1150)  && (!pCoexSta->bC2hBtInquiryPage))
459                 pCoexSta->popEventCnt++;
460
461         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Hi-Pri Rx/Tx: %d/%d, Lo-Pri Rx/Tx: %d/%d\n",
462                 regHPRx, regHPTx, regLPRx, regLPTx));
463
464         // reset counter
465         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc);
466
467         if ((regHPTx == 0) && (regHPRx ==0) && (regLPTx == 0) && (regLPRx == 0))
468         {
469                 NumOfBtCounterChk++;
470                 if (NumOfBtCounterChk >= 3)
471                 {
472                         halbtc8703b1ant_QueryBtInfo(pBtCoexist);
473                         NumOfBtCounterChk = 0;
474                 }
475         }
476 }
477
478
479 VOID
480 halbtc8703b1ant_MonitorWiFiCtr(
481         IN      PBTC_COEXIST            pBtCoexist
482         )
483 {
484         u4Byte  u4Tmp;
485         u2Byte  u2Tmp[3];
486         s4Byte  wifiRssi=0;
487         BOOLEAN bWifiBusy = FALSE, bWifiUnderBMode = FALSE;
488         static u1Byte nCCKLockCounter = 0;
489         u4Byte  TotalCnt;
490
491         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
492         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);
493         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode);
494
495         if (pCoexSta->bUnderIps)
496         {
497                 pCoexSta->nCRCOK_CCK = 0;
498                 pCoexSta->nCRCOK_11g = 0;
499                 pCoexSta->nCRCOK_11n = 0;
500                 pCoexSta->nCRCOK_11nAgg = 0;
501
502                 pCoexSta->nCRCErr_CCK = 0;
503                 pCoexSta->nCRCErr_11g = 0;
504                 pCoexSta->nCRCErr_11n = 0;
505                 pCoexSta->nCRCErr_11nAgg = 0;   
506         }
507         else
508         {
509                 pCoexSta->nCRCOK_CCK    = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xf88);
510                 pCoexSta->nCRCOK_11g    = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf94);
511                 pCoexSta->nCRCOK_11n    = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf90);
512                 pCoexSta->nCRCOK_11nAgg= pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xfb8);
513
514                 pCoexSta->nCRCErr_CCK    = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xf84);
515                 pCoexSta->nCRCErr_11g    = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf96);
516                 pCoexSta->nCRCErr_11n    = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf92);
517                 pCoexSta->nCRCErr_11nAgg = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xfba);                
518         }
519
520
521         //reset counter
522         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xf16, 0x1, 0x1);
523         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xf16, 0x1, 0x0);
524
525         if ( (bWifiBusy) && (wifiRssi >= 30) && (!bWifiUnderBMode))
526         {
527                 TotalCnt = pCoexSta->nCRCOK_CCK + pCoexSta->nCRCOK_11g + pCoexSta->nCRCOK_11n + 
528                                 pCoexSta->nCRCOK_11nAgg;
529         
530                 if ( (pCoexDm->btStatus == BT_8703B_1ANT_BT_STATUS_ACL_BUSY) ||
531                         (pCoexDm->btStatus == BT_8703B_1ANT_BT_STATUS_ACL_SCO_BUSY) ||
532                         (pCoexDm->btStatus == BT_8703B_1ANT_BT_STATUS_SCO_BUSY) )
533                 {
534                         if (pCoexSta->nCRCOK_CCK >(TotalCnt -pCoexSta->nCRCOK_CCK)) 
535                         {
536                                 if (nCCKLockCounter < 3)
537                                  nCCKLockCounter++;
538                         }
539                         else
540                         {
541                                 if (nCCKLockCounter > 0)
542                                  nCCKLockCounter--;
543                         }
544
545                 }
546                 else
547                 {
548                         if (nCCKLockCounter > 0)
549                           nCCKLockCounter--;
550                 }
551         }
552         else
553         {
554                 if (nCCKLockCounter > 0)
555                         nCCKLockCounter--;
556         }
557
558         if (!pCoexSta->bPreCCKLock)
559         {
560
561                 if (nCCKLockCounter >= 3)
562                  pCoexSta->bCCKLock = TRUE;
563                 else
564                  pCoexSta->bCCKLock = FALSE;                    
565         }
566         else
567         {
568                 if (nCCKLockCounter == 0)
569                  pCoexSta->bCCKLock = FALSE;
570                 else
571                  pCoexSta->bCCKLock = TRUE;             
572         }
573
574         if  (pCoexSta->bCCKLock)
575                 pCoexSta->bCCKEverLock = TRUE;
576         
577         pCoexSta->bPreCCKLock =  pCoexSta->bCCKLock;    
578                 
579
580 }
581
582 BOOLEAN
583 halbtc8703b1ant_IsWifiStatusChanged(
584         IN      PBTC_COEXIST            pBtCoexist
585         )
586 {
587         static BOOLEAN  bPreWifiBusy=FALSE, bPreUnder4way=FALSE, bPreBtHsOn=FALSE;
588         BOOLEAN bWifiBusy=FALSE, bUnder4way=FALSE, bBtHsOn=FALSE;
589         BOOLEAN bWifiConnected=FALSE;
590
591         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
592         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
593         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
594         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way);
595
596         if(bWifiConnected)
597         {
598                 if(bWifiBusy != bPreWifiBusy)
599                 {
600                         bPreWifiBusy = bWifiBusy;
601                         return TRUE;
602                 }
603                 if(bUnder4way != bPreUnder4way)
604                 {
605                         bPreUnder4way = bUnder4way;
606                         return TRUE;
607                 }
608                 if(bBtHsOn != bPreBtHsOn)
609                 {
610                         bPreBtHsOn = bBtHsOn;
611                         return TRUE;
612                 }
613         }
614
615         return FALSE;
616 }
617
618 VOID
619 halbtc8703b1ant_UpdateBtLinkInfo(
620         IN      PBTC_COEXIST            pBtCoexist
621         )
622 {
623         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;
624         BOOLEAN                         bBtHsOn=FALSE;
625
626         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
627
628         pBtLinkInfo->bBtLinkExist = pCoexSta->bBtLinkExist;
629         pBtLinkInfo->bScoExist = pCoexSta->bScoExist;
630         pBtLinkInfo->bA2dpExist = pCoexSta->bA2dpExist;
631         pBtLinkInfo->bPanExist = pCoexSta->bPanExist;
632         pBtLinkInfo->bHidExist = pCoexSta->bHidExist;
633         pBtLinkInfo->bBtHiPriLinkExist = pCoexSta->bBtHiPriLinkExist;
634
635         // work around for HS mode.
636         if(bBtHsOn)
637         {
638                 pBtLinkInfo->bPanExist = TRUE;
639                 pBtLinkInfo->bBtLinkExist = TRUE;
640         }
641
642         // check if Sco only
643         if( pBtLinkInfo->bScoExist &&
644                 !pBtLinkInfo->bA2dpExist &&
645                 !pBtLinkInfo->bPanExist &&
646                 !pBtLinkInfo->bHidExist )
647                 pBtLinkInfo->bScoOnly = TRUE;
648         else
649                 pBtLinkInfo->bScoOnly = FALSE;
650
651         // check if A2dp only
652         if( !pBtLinkInfo->bScoExist &&
653                 pBtLinkInfo->bA2dpExist &&
654                 !pBtLinkInfo->bPanExist &&
655                 !pBtLinkInfo->bHidExist )
656                 pBtLinkInfo->bA2dpOnly = TRUE;
657         else
658                 pBtLinkInfo->bA2dpOnly = FALSE;
659
660         // check if Pan only
661         if( !pBtLinkInfo->bScoExist &&
662                 !pBtLinkInfo->bA2dpExist &&
663                 pBtLinkInfo->bPanExist &&
664                 !pBtLinkInfo->bHidExist )
665                 pBtLinkInfo->bPanOnly = TRUE;
666         else
667                 pBtLinkInfo->bPanOnly = FALSE;
668         
669         // check if Hid only
670         if( !pBtLinkInfo->bScoExist &&
671                 !pBtLinkInfo->bA2dpExist &&
672                 !pBtLinkInfo->bPanExist &&
673                 pBtLinkInfo->bHidExist )
674                 pBtLinkInfo->bHidOnly = TRUE;
675         else
676                 pBtLinkInfo->bHidOnly = FALSE;
677 }
678
679 VOID
680 halbtc8703b1ant_UpdateWifiChannelInfo(
681         IN      PBTC_COEXIST            pBtCoexist,
682         IN      u1Byte                          type
683         )
684 {
685         u1Byte                  H2C_Parameter[3] ={0};
686         u4Byte                  wifiBw;
687         u1Byte                  wifiCentralChnl;
688         BOOLEAN                 bWifiUnderBMode = FALSE;
689
690         // only 2.4G we need to inform bt the chnl mask
691         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, &wifiCentralChnl);
692         if( (BTC_MEDIA_CONNECT == type) &&
693                 (wifiCentralChnl <= 14) )
694         {
695                 H2C_Parameter[0] = 0x1;  //enable BT AFH skip WL channel for 8703b because BT Rx LO interference
696                 //H2C_Parameter[0] = 0x0;
697                 H2C_Parameter[1] = wifiCentralChnl;
698                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
699                 if(BTC_WIFI_BW_HT40 == wifiBw)
700                         H2C_Parameter[2] = 0x30;
701                 else
702                         H2C_Parameter[2] = 0x20;
703         }
704                 
705         pCoexDm->wifiChnlInfo[0] = H2C_Parameter[0];
706         pCoexDm->wifiChnlInfo[1] = H2C_Parameter[1];
707         pCoexDm->wifiChnlInfo[2] = H2C_Parameter[2];
708         
709         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], FW write 0x66=0x%x\n", 
710                 H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));
711
712         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x66, 3, H2C_Parameter);
713
714 }
715
716 u1Byte
717 halbtc8703b1ant_ActionAlgorithm(
718         IN      PBTC_COEXIST            pBtCoexist
719         )
720 {
721         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;
722         BOOLEAN                         bBtHsOn=FALSE;
723         u1Byte                          algorithm=BT_8703B_1ANT_COEX_ALGO_UNDEFINED;
724         u1Byte                          numOfDiffProfile=0;
725
726         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
727
728         if(!pBtLinkInfo->bBtLinkExist)
729         {
730                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], No BT link exists!!!\n"));
731                 return algorithm;
732         }
733
734         if(pBtLinkInfo->bScoExist)
735                 numOfDiffProfile++;
736         if(pBtLinkInfo->bHidExist)
737                 numOfDiffProfile++;
738         if(pBtLinkInfo->bPanExist)
739                 numOfDiffProfile++;
740         if(pBtLinkInfo->bA2dpExist)
741                 numOfDiffProfile++;
742         
743         if(numOfDiffProfile == 1)
744         {
745                 if(pBtLinkInfo->bScoExist)
746                 {
747                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO only\n"));
748                         algorithm = BT_8703B_1ANT_COEX_ALGO_SCO;
749                 }
750                 else
751                 {
752                         if(pBtLinkInfo->bHidExist)
753                         {
754                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = HID only\n"));
755                                 algorithm = BT_8703B_1ANT_COEX_ALGO_HID;
756                         }
757                         else if(pBtLinkInfo->bA2dpExist)
758                         {
759                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = A2DP only\n"));
760                                 algorithm = BT_8703B_1ANT_COEX_ALGO_A2DP;
761                         }
762                         else if(pBtLinkInfo->bPanExist)
763                         {
764                                 if(bBtHsOn)
765                                 {
766                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = PAN(HS) only\n"));
767                                         algorithm = BT_8703B_1ANT_COEX_ALGO_PANHS;
768                                 }
769                                 else
770                                 {
771                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = PAN(EDR) only\n"));
772                                         algorithm = BT_8703B_1ANT_COEX_ALGO_PANEDR;
773                                 }
774                         }
775                 }
776         }
777         else if(numOfDiffProfile == 2)
778         {
779                 if(pBtLinkInfo->bScoExist)
780                 {
781                         if(pBtLinkInfo->bHidExist)
782                         {
783                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + HID\n"));
784                                 algorithm = BT_8703B_1ANT_COEX_ALGO_HID;
785                         }
786                         else if(pBtLinkInfo->bA2dpExist)
787                         {
788                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + A2DP ==> SCO\n"));
789                                 algorithm = BT_8703B_1ANT_COEX_ALGO_SCO;
790                         }
791                         else if(pBtLinkInfo->bPanExist)
792                         {
793                                 if(bBtHsOn)
794                                 {
795                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + PAN(HS)\n"));
796                                         algorithm = BT_8703B_1ANT_COEX_ALGO_SCO;
797                                 }
798                                 else
799                                 {
800                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + PAN(EDR)\n"));
801                                         algorithm = BT_8703B_1ANT_COEX_ALGO_PANEDR_HID;
802                                 }
803                         }
804                 }
805                 else
806                 {
807                         if( pBtLinkInfo->bHidExist &&
808                                 pBtLinkInfo->bA2dpExist )
809                         {
810                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = HID + A2DP\n"));
811                                 algorithm = BT_8703B_1ANT_COEX_ALGO_HID_A2DP;
812                         }
813                         else if( pBtLinkInfo->bHidExist &&
814                                 pBtLinkInfo->bPanExist )
815                         {
816                                 if(bBtHsOn)
817                                 {
818                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = HID + PAN(HS)\n"));
819                                         algorithm = BT_8703B_1ANT_COEX_ALGO_HID_A2DP;
820                                 }
821                                 else
822                                 {
823                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = HID + PAN(EDR)\n"));
824                                         algorithm = BT_8703B_1ANT_COEX_ALGO_PANEDR_HID;
825                                 }
826                         }
827                         else if( pBtLinkInfo->bPanExist &&
828                                 pBtLinkInfo->bA2dpExist )
829                         {
830                                 if(bBtHsOn)
831                                 {
832                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = A2DP + PAN(HS)\n"));
833                                         algorithm = BT_8703B_1ANT_COEX_ALGO_A2DP_PANHS;
834                                 }
835                                 else
836                                 {
837                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = A2DP + PAN(EDR)\n"));
838                                         algorithm = BT_8703B_1ANT_COEX_ALGO_PANEDR_A2DP;
839                                 }
840                         }
841                 }
842         }
843         else if(numOfDiffProfile == 3)
844         {
845                 if(pBtLinkInfo->bScoExist)
846                 {
847                         if( pBtLinkInfo->bHidExist &&
848                                 pBtLinkInfo->bA2dpExist )
849                         {
850                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n"));
851                                 algorithm = BT_8703B_1ANT_COEX_ALGO_HID;
852                         }
853                         else if( pBtLinkInfo->bHidExist &&
854                                 pBtLinkInfo->bPanExist )
855                         {
856                                 if(bBtHsOn)
857                                 {
858                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + HID + PAN(HS)\n"));
859                                         algorithm = BT_8703B_1ANT_COEX_ALGO_HID_A2DP;
860                                 }
861                                 else
862                                 {
863                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n"));
864                                         algorithm = BT_8703B_1ANT_COEX_ALGO_PANEDR_HID;
865                                 }
866                         }
867                         else if( pBtLinkInfo->bPanExist &&
868                                 pBtLinkInfo->bA2dpExist )
869                         {
870                                 if(bBtHsOn)
871                                 {
872                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n"));
873                                         algorithm = BT_8703B_1ANT_COEX_ALGO_SCO;
874                                 }
875                                 else
876                                 {
877                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n"));
878                                         algorithm = BT_8703B_1ANT_COEX_ALGO_PANEDR_HID;
879                                 }
880                         }
881                 }
882                 else
883                 {
884                         if( pBtLinkInfo->bHidExist &&
885                                 pBtLinkInfo->bPanExist &&
886                                 pBtLinkInfo->bA2dpExist )
887                         {
888                                 if(bBtHsOn)
889                                 {
890                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n"));
891                                         algorithm = BT_8703B_1ANT_COEX_ALGO_HID_A2DP;
892                                 }
893                                 else
894                                 {
895                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n"));
896                                         algorithm = BT_8703B_1ANT_COEX_ALGO_HID_A2DP_PANEDR;
897                                 }
898                         }
899                 }
900         }
901         else if(numOfDiffProfile >= 3)
902         {
903                 if(pBtLinkInfo->bScoExist)
904                 {
905                         if( pBtLinkInfo->bHidExist &&
906                                 pBtLinkInfo->bPanExist &&
907                                 pBtLinkInfo->bA2dpExist )
908                         {
909                                 if(bBtHsOn)
910                                 {
911                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n"));
912
913                                 }
914                                 else
915                                 {
916                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n"));
917                                         algorithm = BT_8703B_1ANT_COEX_ALGO_PANEDR_HID;
918                                 }
919                         }
920                 }
921         }
922
923         return algorithm;
924 }
925
926 VOID
927 halbtc8703b1ant_SetBtAutoReport(
928         IN      PBTC_COEXIST            pBtCoexist,
929         IN      BOOLEAN                 bEnableAutoReport
930         )
931 {
932         u1Byte                  H2C_Parameter[1] ={0};
933         
934         H2C_Parameter[0] = 0;
935
936         if(bEnableAutoReport)
937         {
938                 H2C_Parameter[0] |= BIT0;
939         }
940
941         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], BT FW auto report : %s, FW write 0x68=0x%x\n", 
942                 (bEnableAutoReport? "Enabled!!":"Disabled!!"), H2C_Parameter[0]));
943
944         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x68, 1, H2C_Parameter);    
945 }
946
947 VOID
948 halbtc8703b1ant_BtAutoReport(
949         IN      PBTC_COEXIST            pBtCoexist,
950         IN      BOOLEAN                 bForceExec,
951         IN      BOOLEAN                 bEnableAutoReport
952         )
953 {
954         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s BT Auto report = %s\n",  
955                 (bForceExec? "force to":""), ((bEnableAutoReport)? "Enabled":"Disabled")));
956         pCoexDm->bCurBtAutoReport = bEnableAutoReport;
957
958         if(!bForceExec)
959         {
960                 if(pCoexDm->bPreBtAutoReport == pCoexDm->bCurBtAutoReport) 
961                         return;
962         }
963         halbtc8703b1ant_SetBtAutoReport(pBtCoexist, pCoexDm->bCurBtAutoReport);
964
965         pCoexDm->bPreBtAutoReport = pCoexDm->bCurBtAutoReport;
966 }
967
968 VOID halbtc8703b1ant_WriteScoreBoard(
969         IN      PBTC_COEXIST            pBtCoexist,
970         IN      u2Byte                          scoreboardval                           
971         )
972 {
973         u2Byte  val;
974
975         val = (scoreboardval & 0x7fff) | 0x8000;
976
977         pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0xaa, val);
978
979 #if 0
980         u1Byte                  H2C_Parameter[3] ={0,0,0};
981         
982
983         // write "Set Status"
984         H2C_Parameter[0] = 0x2;   
985
986         // write score board 15-bit value to H2C parameter
987         H2C_Parameter[1] = scoreboardval & 0xff;
988         H2C_Parameter[2] = (scoreboardval & 0x7f00) >> 8;
989
990         // Set Interrupt to BT
991         H2C_Parameter[2] = H2C_Parameter[2] | 0x80; 
992         
993         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Write  BT Scoreboard: H2C 0x71[1:0]= %02x%02x\n", 
994                                      H2C_Parameter[2], H2C_Parameter[1]));
995
996         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x71, 3, H2C_Parameter);
997
998 #endif 
999 }
1000
1001 VOID halbtc8703b1ant_ReadScoreBoard(
1002         IN      PBTC_COEXIST            pBtCoexist,
1003         IN   u2Byte*                            uScoreBoardVal
1004         )
1005 {
1006
1007         *uScoreBoardVal = (pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xaa)) & 0x7fff;
1008
1009
1010
1011 #if 0
1012         u1Byte                  H2C_Parameter[3] ={0,0,0};
1013
1014         // write "Get Status"
1015         H2C_Parameter[0] = 0x1;   
1016
1017         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Read  BT Scoreboard!!\n"));
1018
1019         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x71, 3, H2C_Parameter);
1020
1021         //the BT Scoreboard will be returned by C2H from  EXhalbtc8703b1ant_ScoreBoardStatusNotify()
1022 #endif  
1023 }
1024
1025 VOID halbtc8703b1ant_PostActiveStateToBT(
1026         IN      PBTC_COEXIST            pBtCoexist,
1027         IN      BOOLEAN                         bWifiActive
1028         )
1029 {
1030
1031         if(bWifiActive)
1032         {
1033                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Post WL = Active in Scoreboard!!\n"));
1034                 halbtc8703b1ant_WriteScoreBoard(pBtCoexist, 0x0001);
1035         }
1036         else
1037         {
1038                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Post WL = Non-Active in Scoreboard!!\n"));
1039                 halbtc8703b1ant_WriteScoreBoard(pBtCoexist, 0x0000);
1040         }
1041
1042         // The BT should set "No Shunt-down" mode if WL = Active for BT Synthesizer on/off interference WL Lo issue at 8703b b-cut.
1043
1044 }
1045
1046 VOID
1047 halbtc8703b1ant_SetSwPenaltyTxRateAdaptive(
1048         IN      PBTC_COEXIST            pBtCoexist,
1049         IN      BOOLEAN                 bLowPenaltyRa
1050         )
1051 {
1052         u1Byte                  H2C_Parameter[6] ={0};
1053         
1054         H2C_Parameter[0] = 0x6; // opCode, 0x6= Retry_Penalty
1055
1056         if(bLowPenaltyRa)
1057         {
1058                 H2C_Parameter[1] |= BIT0;
1059                 H2C_Parameter[2] = 0x00;  //normal rate except MCS7/6/5, OFDM54/48/36
1060                 H2C_Parameter[3] = 0xf7;  //MCS7 or OFDM54
1061                 H2C_Parameter[4] = 0xf8;  //MCS6 or OFDM48
1062                 H2C_Parameter[5] = 0xf9;        //MCS5 or OFDM36        
1063         }
1064
1065         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set WiFi Low-Penalty Retry: %s", 
1066                 (bLowPenaltyRa? "ON!!":"OFF!!") ));
1067
1068         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x69, 6, H2C_Parameter);
1069 }
1070
1071 VOID
1072 halbtc8703b1ant_LowPenaltyRa(
1073         IN      PBTC_COEXIST            pBtCoexist,
1074         IN      BOOLEAN                 bForceExec,
1075         IN      BOOLEAN                 bLowPenaltyRa
1076         )
1077 {
1078         pCoexDm->bCurLowPenaltyRa = bLowPenaltyRa;
1079
1080         if(!bForceExec)
1081         {
1082                 if(pCoexDm->bPreLowPenaltyRa == pCoexDm->bCurLowPenaltyRa) 
1083                         return;
1084         }
1085         halbtc8703b1ant_SetSwPenaltyTxRateAdaptive(pBtCoexist, pCoexDm->bCurLowPenaltyRa);
1086
1087         pCoexDm->bPreLowPenaltyRa = pCoexDm->bCurLowPenaltyRa;
1088 }
1089
1090 u4Byte
1091 halbtc8703b1ant_LTECoex_InDirectReadReg(
1092 IN      PBTC_COEXIST            pBtCoexist,
1093 IN      u2Byte                          RegAddr
1094 )       
1095 {
1096         u4Byte j =0;
1097
1098         
1099         //wait for ready bit before access 0x7c0                
1100         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x7c0, 0x800F0000|RegAddr);
1101
1102         do
1103         {
1104                 j++;
1105         }while( ((pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x7c3) & BIT5) ==0) && (j <BT_8703B_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT) );
1106
1107
1108         return(pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x7c8));   //get read data
1109
1110 }
1111
1112 VOID
1113 halbtc8703b1ant_LTECoex_InDirectWriteReg(
1114 IN      PBTC_COEXIST            pBtCoexist,
1115 IN      u2Byte                          RegAddr,
1116 IN      u4Byte                          BitMask,
1117 IN      u4Byte                          RegValue
1118 )
1119 {
1120         u4Byte val, i=0, j=0, bitpos = 0;
1121         
1122
1123         if (BitMask == 0x0)
1124          return;        
1125         if (BitMask == 0xffffffff)
1126         {
1127                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x7c4, RegValue); //put write data
1128
1129                 //wait for ready bit before access 0x7c0
1130                 do
1131                 {
1132                         j++;
1133                 }while( ((pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x7c3) & BIT5) ==0) && (j <BT_8703B_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT) );
1134                 
1135                 
1136                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x7c0, 0xc00F0000|RegAddr);
1137         }
1138         else
1139         {
1140             for(i=0; i<=31; i++)
1141                 {
1142                         if ( ((BitMask >> i) & 0x1) == 0x1)
1143                         {
1144                                 bitpos = i;
1145                                 break;
1146                         }
1147                 }
1148
1149                 //read back register value before write 
1150                 val = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, RegAddr);
1151                 val = (val & (~BitMask)) | (RegValue << bitpos);
1152
1153                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x7c4, val); //put write data
1154
1155                 //wait for ready bit before access 0x7c0                
1156                 do
1157                 {
1158                         j++;
1159                 }while( ((pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x7c3) & BIT5) ==0) && (j <BT_8703B_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT) );
1160                 
1161                 
1162                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x7c0, 0xc00F0000|RegAddr);
1163                 
1164         }
1165
1166 }
1167
1168 void
1169 halbtc8703b1ant_LTECoex_Enable(
1170 IN      PBTC_COEXIST            pBtCoexist,
1171 IN      BOOLEAN                         bEnable
1172 )
1173 {
1174         u1Byte val;
1175         
1176         val =  (bEnable)? 1 : 0; 
1177         halbtc8703b1ant_LTECoex_InDirectWriteReg(pBtCoexist, 0x38, 0x80, val);  //0x38[7]
1178
1179 }
1180
1181 void
1182 halbtc8703b1ant_LTECoex_PathControlOwner(
1183 IN      PBTC_COEXIST            pBtCoexist,
1184 IN      BOOLEAN                         bWiFiControl
1185 )
1186 {
1187         u1Byte val;
1188         
1189         val =  (bWiFiControl)? 1 : 0; 
1190         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x73, 0x4, val); //0x70[26]
1191
1192 }
1193
1194 void
1195 halbtc8703b1ant_LTECoex_Set_GNT_BT(
1196 IN      PBTC_COEXIST            pBtCoexist,
1197 IN      u1Byte                          nControlBlock,
1198 IN      BOOLEAN                         bSWControl,
1199 IN      u1Byte                          nState
1200 )
1201 {
1202         u4Byte val=0, BitMask;
1203         
1204         nState = nState & 0x1;  
1205         val =  (bSWControl)? ((nState<<1) | 0x1) : 0; 
1206
1207         switch(nControlBlock)
1208         {
1209                 case BT_8703B_1ANT_GNT_BLOCK_RFC_BB:    
1210                 default:
1211                         BitMask = 0xc000;
1212                         halbtc8703b1ant_LTECoex_InDirectWriteReg(pBtCoexist, 0x38, BitMask, val); // 0x38[15:14]
1213                         BitMask = 0x0c00;
1214                         halbtc8703b1ant_LTECoex_InDirectWriteReg(pBtCoexist, 0x38, BitMask, val); // 0x38[11:10]                                                
1215                         break;
1216                 case BT_8703B_1ANT_GNT_BLOCK_RFC:
1217                         BitMask = 0xc000;
1218                         halbtc8703b1ant_LTECoex_InDirectWriteReg(pBtCoexist, 0x38, BitMask, val); // 0x38[15:14]
1219                         break;
1220                 case BT_8703B_1ANT_GNT_BLOCK_BB:
1221                         BitMask = 0x0c00;
1222                         halbtc8703b1ant_LTECoex_InDirectWriteReg(pBtCoexist, 0x38, BitMask, val); // 0x38[11:10]
1223                         break;
1224
1225         }
1226         
1227 }
1228
1229 void
1230 halbtc8703b1ant_LTECoex_Set_GNT_WL(
1231 IN      PBTC_COEXIST            pBtCoexist,
1232 IN      u1Byte                          nControlBlock,
1233 IN      BOOLEAN                         bSWControl,
1234 IN      u1Byte                          nState
1235 )
1236 {
1237         u4Byte val=0, BitMask;
1238         
1239         nState = nState & 0x1;  
1240         val =  (bSWControl)? ((nState<<1) | 0x1) : 0; 
1241
1242         switch(nControlBlock)
1243         {
1244                 case BT_8703B_1ANT_GNT_BLOCK_RFC_BB:    
1245                 default:
1246                         BitMask = 0x3000;
1247                         halbtc8703b1ant_LTECoex_InDirectWriteReg(pBtCoexist, 0x38, BitMask, val); // 0x38[13:12]
1248                         BitMask = 0x0300;
1249                         halbtc8703b1ant_LTECoex_InDirectWriteReg(pBtCoexist, 0x38, BitMask, val); // 0x38[9:8]                                          
1250                         break;
1251                 case BT_8703B_1ANT_GNT_BLOCK_RFC:
1252                         BitMask = 0x3000;
1253                         halbtc8703b1ant_LTECoex_InDirectWriteReg(pBtCoexist, 0x38, BitMask, val); // 0x38[13:12]
1254                         break;
1255                 case BT_8703B_1ANT_GNT_BLOCK_BB:
1256                         BitMask = 0x0300;
1257                         halbtc8703b1ant_LTECoex_InDirectWriteReg(pBtCoexist, 0x38, BitMask, val); // 0x38[9:8]
1258                         break;
1259
1260         }
1261
1262 }
1263
1264 void
1265 halbtc8703b1ant_LTECoex_Set_CoexTable(
1266 IN      PBTC_COEXIST            pBtCoexist,
1267 IN      u1Byte                          nTableType,
1268 IN      u2Byte                          nTableContent
1269 )
1270 {
1271         u2Byte RegAddr = 0x0000;
1272
1273         switch(nTableType)
1274         {
1275                 case BT_8703B_1ANT_CTT_WL_VS_LTE:
1276                         RegAddr = 0xa0;
1277                         break;
1278                 case BT_8703B_1ANT_CTT_BT_VS_LTE:
1279                         RegAddr = 0xa4;
1280                         break;
1281         }
1282
1283         if (RegAddr != 0x0000)
1284                 halbtc8703b1ant_LTECoex_InDirectWriteReg(pBtCoexist, RegAddr, 0xffff, nTableContent); // 0xa0[15:0] or 0xa4[15:0]
1285
1286
1287 }
1288
1289
1290 void
1291 halbtc8703b1ant_LTECoex_Set_BreakTable(
1292 IN      PBTC_COEXIST            pBtCoexist,
1293 IN      u1Byte                          nTableType,
1294 IN      u1Byte                          nTableContent
1295 )
1296 {
1297         u2Byte RegAddr = 0x0000;
1298
1299         switch(nTableType)
1300         {
1301                 case BT_8703B_1ANT_LBTT_WL_BREAK_LTE:
1302                         RegAddr = 0xa8;
1303                         break;
1304                 case BT_8703B_1ANT_LBTT_BT_BREAK_LTE:
1305                         RegAddr = 0xac;
1306                         break;
1307                 case BT_8703B_1ANT_LBTT_LTE_BREAK_WL:
1308                         RegAddr = 0xb0;
1309                         break;
1310                 case BT_8703B_1ANT_LBTT_LTE_BREAK_BT:
1311                         RegAddr = 0xb4;
1312                         break;  
1313         }
1314
1315         if (RegAddr != 0x0000)
1316                 halbtc8703b1ant_LTECoex_InDirectWriteReg(pBtCoexist, RegAddr, 0xff, nTableContent); // 0xa8[15:0] or 0xb4[15:0]
1317
1318
1319 }
1320
1321 VOID
1322 halbtc8703b1ant_SetCoexTable(
1323         IN      PBTC_COEXIST    pBtCoexist,
1324         IN      u4Byte          val0x6c0,
1325         IN      u4Byte          val0x6c4,
1326         IN      u4Byte          val0x6c8,
1327         IN      u1Byte          val0x6cc
1328         )
1329 {
1330         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6c0=0x%x\n", val0x6c0));
1331         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c0, val0x6c0);
1332
1333         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6c4=0x%x\n", val0x6c4));
1334         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c4, val0x6c4);
1335
1336         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6c8=0x%x\n", val0x6c8));
1337         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c8, val0x6c8);
1338
1339         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6cc=0x%x\n", val0x6cc));
1340         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cc, val0x6cc);
1341 }
1342
1343 VOID
1344 halbtc8703b1ant_CoexTable(
1345         IN      PBTC_COEXIST            pBtCoexist,
1346         IN      BOOLEAN                 bForceExec,
1347         IN      u4Byte                  val0x6c0,
1348         IN      u4Byte                  val0x6c4,
1349         IN      u4Byte                  val0x6c8,
1350         IN      u1Byte                  val0x6cc
1351         )
1352 {
1353         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s write Coex Table 0x6c0=0x%x, 0x6c4=0x%x, 0x6cc=0x%x\n", 
1354                 (bForceExec? "force to":""), val0x6c0, val0x6c4, val0x6cc));
1355         pCoexDm->curVal0x6c0 = val0x6c0;
1356         pCoexDm->curVal0x6c4 = val0x6c4;
1357         pCoexDm->curVal0x6c8 = val0x6c8;
1358         pCoexDm->curVal0x6cc = val0x6cc;
1359
1360         if(!bForceExec)
1361         {
1362                 if( (pCoexDm->preVal0x6c0 == pCoexDm->curVal0x6c0) &&
1363                         (pCoexDm->preVal0x6c4 == pCoexDm->curVal0x6c4) &&
1364                         (pCoexDm->preVal0x6c8 == pCoexDm->curVal0x6c8) &&
1365                         (pCoexDm->preVal0x6cc == pCoexDm->curVal0x6cc) )
1366                         return;
1367         }
1368         halbtc8703b1ant_SetCoexTable(pBtCoexist, val0x6c0, val0x6c4, val0x6c8, val0x6cc);
1369
1370         pCoexDm->preVal0x6c0 = pCoexDm->curVal0x6c0;
1371         pCoexDm->preVal0x6c4 = pCoexDm->curVal0x6c4;
1372         pCoexDm->preVal0x6c8 = pCoexDm->curVal0x6c8;
1373         pCoexDm->preVal0x6cc = pCoexDm->curVal0x6cc;
1374 }
1375
1376 VOID
1377 halbtc8703b1ant_CoexTableWithType(
1378         IN      PBTC_COEXIST            pBtCoexist,
1379         IN      BOOLEAN                         bForceExec,
1380         IN      u1Byte                          type
1381         )
1382 {
1383         PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;
1384
1385         u4Byte  nBreakTable;
1386         u1Byte  nSelectTable;   
1387
1388
1389         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], ********** CoexTable(%d) **********\n", type));
1390         
1391         pCoexSta->nCoexTableType = type;
1392
1393         if (pCoexSta->bConCurrentRxModeOn == TRUE)
1394         {
1395                 nBreakTable = 0xf0ffffff;  //set WL hi-pri can break BT
1396                 nSelectTable = 0xb;             //set Tx response = Hi-Pri (ex: Transmitting ACK,BA,CTS)
1397         }
1398         else
1399         {
1400                 nBreakTable = 0xffffff;
1401                 nSelectTable = 0x3;
1402         }
1403         
1404         switch(type)
1405         {
1406                 case 0:
1407                         halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x55555555, nBreakTable, nSelectTable);
1408                         break;
1409                 case 1:
1410                         halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x5a5a5a5a, nBreakTable, nSelectTable);
1411                         break;
1412                 case 2:
1413                         halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0xaa5a5a5a, 0xaa5a5a5a, nBreakTable, nSelectTable);
1414                         break;
1415                 case 3:
1416                         halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0xaa555555, 0xaa5a5a5a, nBreakTable, nSelectTable);
1417                         break;
1418                 case 4:
1419                         //if (  (pCoexSta->bCCKEverLock)  &&  (pCoexSta->nScanAPNum <= 5) )
1420                         //      halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0xaa555555, 0xaaaa5a5a, nBreakTable, nSelectTable);
1421                         //else
1422                                 halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0xaa555555, 0xaa5a5a5a, nBreakTable, nSelectTable);
1423                         break;
1424                 case 5:
1425                         //if (  (pCoexSta->bCCKEverLock)  &&  (pCoexSta->nScanAPNum <= 5) )
1426                         //      halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0xaa555555, 0xaaaa5a5a, nBreakTable, nSelectTable);
1427                         //else
1428                                 halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0x5a5a5a5a, 0x5a5a5a5a, nBreakTable, nSelectTable);
1429                         break;
1430                 case 6:
1431                         halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0xaaaaaaaa, nBreakTable, nSelectTable);
1432                         break;
1433                 case 7:
1434                         halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0xaaaaaaaa, 0xaaaaaaaa, nBreakTable, nSelectTable);
1435                         break;
1436                 case 8:
1437                         halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, nBreakTable, nSelectTable);
1438                         break;
1439                 case 9:
1440                         halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, nBreakTable, nSelectTable);
1441                         break;
1442                 case 10:
1443                         halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, nBreakTable, nSelectTable);
1444                         break;
1445                 case 11:
1446                         halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, nBreakTable, nSelectTable);
1447                         break;
1448                 case 12:
1449                         halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, nBreakTable, nSelectTable);
1450                         break;
1451                 case 13:
1452                         halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0x5fff5fff, 0xaaaaaaaa, nBreakTable, nSelectTable);
1453                         break;
1454                 case 14:
1455                         halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0x5fff5fff, 0x5ada5ada, nBreakTable, nSelectTable);
1456                         break;
1457                 case 15:
1458                         halbtc8703b1ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0xaaaaaaaa, nBreakTable, nSelectTable);
1459                         break;  
1460                 default:
1461                         break;
1462         }
1463 }
1464
1465 VOID
1466 halbtc8703b1ant_SetFwIgnoreWlanAct(
1467         IN      PBTC_COEXIST            pBtCoexist,
1468         IN      BOOLEAN                 bEnable
1469         )
1470 {
1471         u1Byte                  H2C_Parameter[1] ={0};
1472                 
1473         if(bEnable)
1474         {
1475                 H2C_Parameter[0] |= BIT0;               // function enable
1476         }
1477         
1478         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63=0x%x\n", 
1479                 H2C_Parameter[0]));
1480
1481         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x63, 1, H2C_Parameter);
1482 }
1483
1484 VOID
1485 halbtc8703b1ant_IgnoreWlanAct(
1486         IN      PBTC_COEXIST            pBtCoexist,
1487         IN      BOOLEAN                 bForceExec,
1488         IN      BOOLEAN                 bEnable
1489         )
1490 {
1491         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn Ignore WlanAct %s\n", 
1492                 (bForceExec? "force to":""), (bEnable? "ON":"OFF")));
1493         pCoexDm->bCurIgnoreWlanAct = bEnable;
1494
1495         if(!bForceExec)
1496         {
1497                 if(pCoexDm->bPreIgnoreWlanAct == pCoexDm->bCurIgnoreWlanAct)
1498                         return;
1499         }
1500         halbtc8703b1ant_SetFwIgnoreWlanAct(pBtCoexist, bEnable);
1501
1502         pCoexDm->bPreIgnoreWlanAct = pCoexDm->bCurIgnoreWlanAct;
1503 }
1504
1505 VOID
1506 halbtc8703b1ant_SetLpsRpwm(
1507         IN      PBTC_COEXIST            pBtCoexist,
1508         IN      u1Byte                  lpsVal,
1509         IN      u1Byte                  rpwmVal
1510         )
1511 {
1512         u1Byte  lps=lpsVal;
1513         u1Byte  rpwm=rpwmVal;
1514         
1515         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_LPS_VAL, &lps);
1516         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
1517 }
1518
1519 VOID
1520 halbtc8703b1ant_LpsRpwm(
1521         IN      PBTC_COEXIST            pBtCoexist,
1522         IN      BOOLEAN                 bForceExec,
1523         IN      u1Byte                  lpsVal,
1524         IN      u1Byte                  rpwmVal
1525         )
1526 {
1527         BOOLEAN bForceExecPwrCmd=FALSE;
1528         
1529         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s set lps/rpwm=0x%x/0x%x \n", 
1530                 (bForceExec? "force to":""), lpsVal, rpwmVal));
1531         pCoexDm->curLps = lpsVal;
1532         pCoexDm->curRpwm = rpwmVal;
1533
1534         if(!bForceExec)
1535         {
1536                 if( (pCoexDm->preLps == pCoexDm->curLps) &&
1537                         (pCoexDm->preRpwm == pCoexDm->curRpwm) )
1538                 {
1539                         return;
1540                 }
1541         }
1542         halbtc8703b1ant_SetLpsRpwm(pBtCoexist, lpsVal, rpwmVal);
1543
1544         pCoexDm->preLps = pCoexDm->curLps;
1545         pCoexDm->preRpwm = pCoexDm->curRpwm;
1546 }
1547
1548 VOID
1549 halbtc8703b1ant_SwMechanism(
1550         IN      PBTC_COEXIST    pBtCoexist,     
1551         IN      BOOLEAN                 bLowPenaltyRA
1552         ) 
1553 {
1554         halbtc8703b1ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, bLowPenaltyRA);
1555 }
1556
1557 VOID
1558 halbtc8703b1ant_SetAntPath(
1559         IN      PBTC_COEXIST            pBtCoexist,
1560         IN      u1Byte                          antPosType,
1561         IN      BOOLEAN                         bForceExec,
1562         IN      BOOLEAN                         bInitHwCfg,
1563         IN      BOOLEAN                         bWifiOff
1564         )
1565 {
1566         PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;
1567         u4Byte                  fwVer=0, u4Tmp=0, cntBtCalChk=0;
1568         BOOLEAN                 bPgExtSwitch=FALSE;
1569         BOOLEAN                 bUseExtSwitch=FALSE;
1570         BOOLEAN                 bIsInMpMode = FALSE;
1571         u1Byte                  H2C_Parameter[2] ={0}, u1Tmp = 0;
1572         u4Byte                  u4Tmp1=0, u4Tmp2=0;
1573
1574         pCoexDm->curAntPosType = antPosType;    
1575
1576 #if 1   
1577                 u4Tmp1 = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0x38);
1578                 u4Tmp2 = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0x54);
1579                 u1Tmp  = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x73);
1580
1581                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ********** (Before Setup) 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x**********\n", u1Tmp, u4Tmp1, u4Tmp2));
1582 #endif
1583
1584         if(bInitHwCfg)
1585         {       
1586                 //Disable LTE Coex Function in WiFi side (this should be on if LTE coex is required)
1587                 halbtc8703b1ant_LTECoex_Enable(pBtCoexist, 0x0);
1588
1589                 //GNT_WL_LTE always = 1 (this should be config if LTE coex is required)
1590                 halbtc8703b1ant_LTECoex_Set_CoexTable(pBtCoexist, BT_8703B_1ANT_CTT_WL_VS_LTE, 0xffff);
1591
1592                 //GNT_BT_LTE always = 1 (this should be config if LTE coex is required)
1593                 halbtc8703b1ant_LTECoex_Set_CoexTable(pBtCoexist, BT_8703B_1ANT_CTT_BT_VS_LTE, 0xffff);
1594
1595                 // Wait If BT IQK running, because Path control owner is at BT during BT IQK (setup by WiFi firmware)  
1596                 while(cntBtCalChk <= 20)
1597                 {
1598                                 u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x49d);
1599                                 cntBtCalChk++;
1600                                 if(u1Tmp & BIT0)
1601                                 {
1602                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ########### BT is calibrating (wait cnt=%d) ###########\n", cntBtCalChk));
1603                                         delay_ms(50);
1604                                 }
1605                                 else
1606                                 {
1607                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ********** BT is NOT calibrating (wait cnt=%d)**********\n", cntBtCalChk));
1608                                         break;
1609                                 }
1610                 }
1611                 
1612                 //set Path control owner to WL at initial step
1613                 halbtc8703b1ant_LTECoex_PathControlOwner(pBtCoexist, BT_8703B_1ANT_PCO_WLSIDE);                 
1614         }
1615         else if(bWifiOff)
1616         {               
1617                 //Disable LTE Coex Function in WiFi side 
1618                 halbtc8703b1ant_LTECoex_Enable(pBtCoexist, 0x0);
1619
1620                 //if MP mode
1621                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_IS_IN_MP_MODE, &bIsInMpMode);
1622                 if(bIsInMpMode) 
1623                         halbtc8703b1ant_LTECoex_PathControlOwner(pBtCoexist, BT_8703B_1ANT_PCO_WLSIDE); //set Path control owner to WiFI
1624                 else
1625                         halbtc8703b1ant_LTECoex_PathControlOwner(pBtCoexist, BT_8703B_1ANT_PCO_BTSIDE);//set Path control owner to BT           
1626         }
1627         else
1628         {                       
1629                         halbtc8703b1ant_LTECoex_PathControlOwner(pBtCoexist, BT_8703B_1ANT_PCO_WLSIDE);         
1630         }
1631         
1632         
1633         if(bForceExec || (pCoexDm->curAntPosType != pCoexDm->preAntPosType) || bInitHwCfg || bWifiOff)
1634         {
1635                 // internal switch setting
1636                 switch(antPosType)
1637                 {
1638                         case BTC_ANT_PATH_WIFI:
1639                                 // set GNT_BT to low
1640                                 halbtc8703b1ant_LTECoex_Set_GNT_BT(pBtCoexist, BT_8703B_1ANT_GNT_BLOCK_RFC_BB, BT_8703B_1ANT_GNT_TYPE_CTRL_BY_SW, BT_8703B_1ANT_SIG_STA_SET_TO_LOW);
1641                                 //Set GNT_WL to high
1642                                 halbtc8703b1ant_LTECoex_Set_GNT_WL(pBtCoexist, BT_8703B_1ANT_GNT_BLOCK_RFC_BB, BT_8703B_1ANT_GNT_TYPE_CTRL_BY_SW, BT_8703B_1ANT_SIG_STA_SET_TO_HIGH);
1643                                 break;
1644                         case BTC_ANT_PATH_BT:
1645                                 // set GNT_BT to high
1646                                 halbtc8703b1ant_LTECoex_Set_GNT_BT(pBtCoexist, BT_8703B_1ANT_GNT_BLOCK_RFC_BB, BT_8703B_1ANT_GNT_TYPE_CTRL_BY_SW, BT_8703B_1ANT_SIG_STA_SET_TO_HIGH);
1647                                 //Set GNT_WL to low
1648                                 halbtc8703b1ant_LTECoex_Set_GNT_WL(pBtCoexist, BT_8703B_1ANT_GNT_BLOCK_RFC_BB, BT_8703B_1ANT_GNT_TYPE_CTRL_BY_SW, BT_8703B_1ANT_SIG_STA_SET_TO_LOW);
1649                                 break;
1650                         default:
1651                         case BTC_ANT_PATH_PTA:
1652                                 // set GNT_BT to PTA
1653                                 halbtc8703b1ant_LTECoex_Set_GNT_BT(pBtCoexist, BT_8703B_1ANT_GNT_BLOCK_RFC_BB, BT_8703B_1ANT_GNT_TYPE_CTRL_BY_PTA, BT_8703B_1ANT_SIG_STA_SET_BY_HW);
1654                                 //Set GNT_WL to PTA
1655                                 halbtc8703b1ant_LTECoex_Set_GNT_WL(pBtCoexist, BT_8703B_1ANT_GNT_BLOCK_RFC_BB, BT_8703B_1ANT_GNT_TYPE_CTRL_BY_PTA, BT_8703B_1ANT_SIG_STA_SET_BY_HW);
1656                                 break;
1657                 }
1658         }
1659         
1660 #if 1
1661         u4Tmp1 = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0x38);
1662         u4Tmp2 = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0x54);
1663         u1Tmp  = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x73);
1664
1665         if(bInitHwCfg)
1666                 {
1667                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ********** (After Init) 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x**********\n", u1Tmp, u4Tmp1, u4Tmp2));
1668                 }
1669         else if (bWifiOff)
1670                 {
1671                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ********** (After WiFi off) 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x**********\n", u1Tmp, u4Tmp1, u4Tmp2));
1672                 }
1673         else
1674         {
1675                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ********** (After Run time) 0x73 = 0x%x, 0x38= 0x%x, 0x54= 0x%x**********\n", u1Tmp, u4Tmp1, u4Tmp2));
1676         }
1677 #endif  
1678         
1679         pCoexDm->preAntPosType = pCoexDm->curAntPosType;
1680 }
1681
1682
1683 VOID
1684 halbtc8703b1ant_SetFwPstdma(
1685         IN      PBTC_COEXIST            pBtCoexist,
1686         IN      u1Byte                  byte1,
1687         IN      u1Byte                  byte2,
1688         IN      u1Byte                  byte3,
1689         IN      u1Byte                  byte4,
1690         IN      u1Byte                  byte5
1691         )
1692 {
1693         u1Byte                  H2C_Parameter[5] ={0};
1694         u1Byte                  realByte1=byte1, realByte5=byte5;
1695         BOOLEAN                 bApEnable=FALSE;
1696
1697         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);
1698
1699         if(bApEnable)
1700         {
1701                 if(byte1&BIT4 && !(byte1&BIT5))
1702                 {                       
1703                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], FW for 1Ant AP mode\n"));
1704                         realByte1 &= ~BIT4;
1705                         realByte1 |= BIT5;
1706
1707                         realByte5 |= BIT5;
1708                         realByte5 &= ~BIT6;
1709                 }
1710         }
1711
1712         H2C_Parameter[0] = realByte1;   
1713         H2C_Parameter[1] = byte2;       
1714         H2C_Parameter[2] = byte3;
1715         H2C_Parameter[3] = byte4;
1716         H2C_Parameter[4] = realByte5;
1717
1718         pCoexDm->psTdmaPara[0] = realByte1;
1719         pCoexDm->psTdmaPara[1] = byte2;
1720         pCoexDm->psTdmaPara[2] = byte3;
1721         pCoexDm->psTdmaPara[3] = byte4;
1722         pCoexDm->psTdmaPara[4] = realByte5;
1723         
1724         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], PS-TDMA H2C cmd =0x%x%08x\n", 
1725                 H2C_Parameter[0], 
1726                 H2C_Parameter[1]<<24|H2C_Parameter[2]<<16|H2C_Parameter[3]<<8|H2C_Parameter[4]));
1727
1728         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x60, 5, H2C_Parameter);
1729 }
1730
1731
1732 VOID
1733 halbtc8703b1ant_PsTdma(
1734         IN      PBTC_COEXIST            pBtCoexist,
1735         IN      BOOLEAN                 bForceExec,
1736         IN      BOOLEAN                 bTurnOn,
1737         IN      u1Byte                  type
1738         )
1739 {
1740         PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;
1741         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
1742         BOOLEAN                 bTurnOnByCnt=FALSE, bWifiBusy=FALSE, bWiFiNoisy=FALSE;
1743         u1Byte                  psTdmaTypeByCnt=0, rssiAdjustVal=0;
1744         u1Byte                  psTdmaByte4Val = 0x50, psTdmaByte0Val = 0x51, psTdmaByte3Val =  0x10;
1745         s1Byte                  nWiFiDurationAdjust = 0x0;
1746         static BOOLEAN   bPreWifiBusy=FALSE;
1747
1748         pCoexDm->bCurPsTdmaOn = bTurnOn;
1749         pCoexDm->curPsTdma = type;
1750
1751         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);      
1752
1753         if (bWifiBusy != bPreWifiBusy)
1754         {
1755                 bForceExec = TRUE;      
1756                 bPreWifiBusy = bWifiBusy;
1757         }
1758
1759         if (pCoexDm->bCurPsTdmaOn)
1760         {
1761                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ********** TDMA(on, %d) **********\n", 
1762                                 pCoexDm->curPsTdma));
1763         }
1764         else
1765         {
1766                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ********** TDMA(off, %d) **********\n", 
1767                                 pCoexDm->curPsTdma));
1768         }
1769                         
1770         if(!bForceExec)
1771         {       
1772                 if( (pCoexDm->bPrePsTdmaOn == pCoexDm->bCurPsTdmaOn) &&
1773                         (pCoexDm->prePsTdma == pCoexDm->curPsTdma) )
1774                         return;
1775         }
1776
1777         // Adjust WiFi slot by AP number
1778         if (pCoexSta->nScanAPNum <= 5)
1779                 nWiFiDurationAdjust = 5;
1780         else if  (pCoexSta->nScanAPNum >= 40)
1781                 nWiFiDurationAdjust = -15;      
1782         else if  (pCoexSta->nScanAPNum >= 20)
1783                 nWiFiDurationAdjust = -10;      
1784         
1785         // for A2DP only case, PS-TDMA/ TDMA
1786         if ((type == 1) || (type == 2) || (type == 9) || (type == 11) || (type == 101)
1787                 || (type == 102) || (type == 109) || (type == 101) || (type == 7) )
1788         {
1789                 if (!pCoexSta->bForceLpsOn)  //Native power save TDMA, only for A2DP-only case 1/2/9/11 while wifi noisy threshold > 30
1790         {
1791                         psTdmaByte0Val = 0x61;  //no null-pkt (TDMA)
1792                 psTdmaByte3Val = 0x11; // no tx-pause at BT-slot
1793
1794                         if (type == 7)
1795                                 psTdmaByte4Val = 0x14;  //BT-Auto-Slot
1796                         else
1797                 psTdmaByte4Val = 0x10; // 0x778 = d/1 toggle, no dynamic slot
1798         }
1799                 else
1800                 {
1801                         psTdmaByte0Val = 0x51;  //null-pkt (PS-TDMA)
1802                         psTdmaByte3Val = 0x10; //tx-pause at BT-slot
1803
1804                         if (type == 7)
1805                                 psTdmaByte4Val = 0x14;  //BT-Auto-Slot
1806                         else
1807                         psTdmaByte4Val = 0x50; // 0x778 = d/1 toggle, dynamic slot
1808                 }
1809         }
1810         else if ((type == 3) ||(type == 4) || (type == 13) || (type == 14) || (type == 103) || (type == 113) || (type == 114))
1811         {
1812                 psTdmaByte0Val = 0x51;  //null-pkt (PS-TDMA)
1813                 psTdmaByte3Val = 0x10; //tx-pause at BT-slot
1814                 psTdmaByte4Val = 0x10; // 0x778 = d/1 toggle, no dynamic slot
1815         }
1816         else  //native power save case
1817         {
1818                 psTdmaByte0Val = 0x61;  //no null-pkt  (TDMA)
1819                 psTdmaByte3Val = 0x11; // no tx-pause at BT-slot
1820                 psTdmaByte4Val = 0x11; // 0x778 = d/1 toggle, no dynamic slot
1821                 //psTdmaByte4Va is not defne for 0x778 = d/1, 1/1 case 
1822                 }
1823                  
1824         //      for A2DP slave 
1825         if ((pBtLinkInfo->bSlaveRole == TRUE)   && (pBtLinkInfo->bA2dpExist))
1826                 psTdmaByte4Val = psTdmaByte4Val | 0x1;  //0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts)
1827                 
1828         //  (for Antenna Detection Mechanism)   
1829         if (type > 100)
1830         {
1831                 psTdmaByte0Val = psTdmaByte0Val | 0x82; //set antenna control by SW     
1832                 psTdmaByte3Val = psTdmaByte3Val | 0x60;  //set antenna no toggle, control by antenna diversity
1833         }
1834
1835                 
1836         if(bTurnOn)
1837         {        
1838                 switch(type)
1839                 {
1840                         default:
1841                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x1a, 0x1a, 0x0, psTdmaByte4Val);
1842                                 break;
1843                         case 1:
1844                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x3a+nWiFiDurationAdjust, 0x03, psTdmaByte3Val, psTdmaByte4Val);                                                                
1845                                 break;
1846                         case 2:
1847                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x2d+nWiFiDurationAdjust, 0x03, psTdmaByte3Val, psTdmaByte4Val);                                                        
1848                                 break;
1849                         case 3:
1850                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x3a, 0x03, psTdmaByte3Val, psTdmaByte4Val);
1851                                 break;
1852                         case 4:
1853                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x03, psTdmaByte3Val, psTdmaByte4Val);
1854                                 break;
1855                         case 5:
1856                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x15, 0x3, psTdmaByte3Val, 0x11);
1857                                 break;
1858                         case 6:
1859                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x20, 0x3, psTdmaByte3Val, 0x11);
1860                                 break;
1861                         case 7:
1862                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x1e, 0x03, psTdmaByte3Val, psTdmaByte4Val);
1863                                 break;
1864                         case 8: 
1865                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x1e, 0x3, 0x10, 0x14);
1866                                 break;
1867                         case 9: 
1868                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x3, psTdmaByte3Val, psTdmaByte4Val);                             
1869                                 break;
1870                         case 10:        
1871                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x13, 0xa, 0xa, 0x0, 0x40);
1872                                 break;
1873                         case 11:        
1874                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x03, psTdmaByte3Val, psTdmaByte4Val);                    
1875                                 break;
1876                         case 12:
1877                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x0a, 0x0a, 0x0, 0x50);
1878                                 break;
1879                         case 13:
1880                                  if (pCoexSta->nScanAPNum <= 3) // for Lenovo CPT test A2DP + OPP
1881                                         halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x3a, 0x3, psTdmaByte3Val, psTdmaByte4Val);
1882                                  else   
1883                                         halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x3, psTdmaByte3Val, psTdmaByte4Val);
1884                                 break;
1885                         case 14:
1886                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x3, psTdmaByte3Val, psTdmaByte4Val);                             
1887                                 break;
1888                         case 15:
1889                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x13, 0xa, 0x3, 0x8, 0x0);
1890                                 break;
1891                         case 16:
1892                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x93, 0x15, 0x3, 0x10, 0x0);
1893                                 break;
1894                         case 18:
1895                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x93, 0x25, 0x3, 0x10, 0x0);
1896                                 break;                  
1897                         case 20:
1898                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x3f, 0x03, psTdmaByte3Val, 0x10);
1899                                 break;
1900                         case 21:
1901                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x61, 0x25, 0x03, 0x11, 0x11);
1902                                 break;
1903                         case 22:
1904                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x25, 0x03, psTdmaByte3Val, 0x10);
1905                                 break;
1906                         case 23:
1907                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x3, 0x31, 0x18);
1908                                 break;
1909                         case 24:
1910                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0xe3, 0x15, 0x3, 0x31, 0x18);
1911                                 break;
1912                         case 25:
1913                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0x3, 0x31, 0x18);
1914                                 break;
1915                         case 26:
1916                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0x3, 0x31, 0x18);
1917                                 break;
1918                         case 27:
1919                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x3, 0x31, 0x98);
1920                                 break;
1921                         case 28:
1922                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x69, 0x25, 0x3, 0x31, 0x0);
1923                                 break;
1924                         case 29:
1925                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0xab, 0x1a, 0x1a, 0x1, 0x10);
1926                                 break;
1927                         case 30:
1928                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x30, 0x3, 0x10, 0x10);
1929                                 break;
1930                         case 31:
1931                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0xd3, 0x1a, 0x1a, 0, 0x58);
1932                                 break;
1933                         case 32:
1934                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x35, 0x3, psTdmaByte3Val, psTdmaByte4Val);
1935                                 break;
1936                         case 33:
1937                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x35, 0x3, psTdmaByte3Val, 0x10);
1938                                 break;
1939                         case 34:
1940                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x53, 0x1a, 0x1a, 0x0, 0x10);
1941                                 break;
1942                         case 35:
1943                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x63, 0x1a, 0x1a, 0x0, 0x10);
1944                                 break;
1945                         case 36:
1946                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0xd3, 0x12, 0x3, 0x14, 0x50);
1947                                 break;
1948                         case 40: // SoftAP only with no sta associated,BT disable ,TDMA mode for power saving
1949                                 /* here softap mode screen off will cost 70-80mA for phone */
1950                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x23, 0x18, 0x00, 0x10, 0x24);
1951                                 break;  
1952                                 
1953                         // 1-Ant translate to 2-Ant (for Antenna Detection Mechanism)
1954                         case 101:
1955                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x3a+nWiFiDurationAdjust, 0x03, psTdmaByte3Val, psTdmaByte4Val);                                                                
1956                                 break;
1957                         case 102:
1958                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x2d+nWiFiDurationAdjust, 0x03, psTdmaByte3Val, psTdmaByte4Val);                                                        
1959                                 break;
1960                         case 103:
1961                                 //halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x1d, 0x1d, 0x0, psTdmaByte4Val);
1962                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x3a, 0x03, psTdmaByte3Val, psTdmaByte4Val);
1963                                 break;
1964                         case 105:
1965                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x15, 0x3, psTdmaByte3Val, 0x11);
1966                                 break;
1967                         case 106:
1968                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x20, 0x3, psTdmaByte3Val, 0x11);
1969                                 break;  
1970                         case 109:       
1971                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x3, psTdmaByte3Val, psTdmaByte4Val);                             
1972                                 break;                  
1973                         case 111:       
1974                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x03, psTdmaByte3Val, psTdmaByte4Val);                    
1975                                 break;  
1976                         case 113:
1977                                 //halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x12, 0x12, 0x0, psTdmaByte4Val);
1978                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x3, psTdmaByte3Val, psTdmaByte4Val);
1979                                 break;
1980                         case 114:
1981                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x3, psTdmaByte3Val, psTdmaByte4Val);                             
1982                                 break;  
1983                         case 120:
1984                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x3f, 0x03, psTdmaByte3Val, 0x10);
1985                                 break;                  
1986                         case 122:
1987                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x25, 0x03, psTdmaByte3Val, 0x10);
1988                                 break;
1989                         case 132:
1990                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x25, 0x03, psTdmaByte3Val, psTdmaByte4Val);
1991                                 break;  
1992                         case 133:
1993                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x25, 0x03, psTdmaByte3Val, 0x11);
1994                                 break;          
1995                                 
1996                 }
1997         }
1998         else
1999         {               
2000
2001                 // disable PS tdma
2002                 switch(type)
2003                 {
2004                         case 8: //PTA Control
2005                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x8, 0x0, 0x0, 0x0, 0x0);
2006                                 break;
2007                         case 0:
2008                         default:  //Software control, Antenna at BT side
2009                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x0, 0x0);
2010                                 break;
2011                         case 1: // 2-Ant, 0x778=3, antenna control by antenna diversity
2012                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x48, 0x0);
2013                                 break;
2014 #if 0
2015                         case 9:   //Software control, Antenna at WiFi side
2016                                 halbtc8703b1ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x0, 0x0);                               
2017                                 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_WIFI, FALSE, FALSE);
2018                                 break;                  
2019 #endif
2020                 }
2021         }
2022         rssiAdjustVal =0;
2023         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE, &rssiAdjustVal);
2024
2025
2026         RT_TRACE(COMP_COEX, DBG_LOUD, ("############# [BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x\n",
2027                 pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x948),   pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x765), pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x67)));
2028
2029         // update pre state
2030         pCoexDm->bPrePsTdmaOn = pCoexDm->bCurPsTdmaOn;
2031         pCoexDm->prePsTdma = pCoexDm->curPsTdma;
2032 }
2033
2034 BOOLEAN
2035 halbtc8703b1ant_IsCommonAction(
2036         IN      PBTC_COEXIST            pBtCoexist
2037         )
2038 {
2039         BOOLEAN                 bCommon=FALSE, bWifiConnected=FALSE, bWifiBusy=FALSE;
2040
2041         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
2042         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
2043
2044         if(!bWifiConnected && 
2045                 BT_8703B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)
2046         {
2047                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n"));
2048                 
2049                 //halbtc8703b1ant_SwMechanism(pBtCoexist, FALSE);
2050
2051                 bCommon = TRUE;
2052         }
2053         else if(bWifiConnected && 
2054                 (BT_8703B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus) )
2055         {
2056                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi connected + BT non connected-idle!!\n"));
2057
2058                 //halbtc8703b1ant_SwMechanism(pBtCoexist, FALSE);
2059
2060                 bCommon = TRUE;
2061         }
2062         else if(!bWifiConnected && 
2063                 (BT_8703B_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus) )
2064         {
2065                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi non connected-idle + BT connected-idle!!\n"));
2066
2067                 //halbtc8703b1ant_SwMechanism(pBtCoexist, FALSE);
2068
2069                 bCommon = TRUE;
2070         }
2071         else if(bWifiConnected && 
2072                 (BT_8703B_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus) )
2073         {
2074                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi connected + BT connected-idle!!\n"));
2075
2076                 //halbtc8703b1ant_SwMechanism(pBtCoexist, FALSE);
2077
2078                 bCommon = TRUE;
2079         }
2080         else if(!bWifiConnected && 
2081                 (BT_8703B_1ANT_BT_STATUS_CONNECTED_IDLE != pCoexDm->btStatus) )
2082         {
2083                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi non connected-idle + BT Busy!!\n"));
2084
2085                 //halbtc8703b1ant_SwMechanism(pBtCoexist, FALSE);
2086                 
2087                 bCommon = TRUE;
2088         }
2089         else
2090         {
2091                 if (bWifiBusy)                  
2092                 {
2093                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi Connected-Busy + BT Busy!!\n"));
2094                 }
2095                 else
2096                 {
2097                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi Connected-Idle + BT Busy!!\n"));
2098                 }
2099                 
2100                 bCommon = FALSE;
2101         }
2102         
2103         return bCommon;
2104 }
2105
2106
2107 VOID
2108 halbtc8703b1ant_TdmaDurationAdjustForAcl(
2109         IN      PBTC_COEXIST            pBtCoexist,
2110         IN      u1Byte                          wifiStatus
2111         )
2112 {
2113         static s4Byte           up,dn,m,n,WaitCount;
2114         s4Byte                  result;   //0: no change, +1: increase WiFi duration, -1: decrease WiFi duration
2115         u1Byte                  retryCount=0, btInfoExt;
2116         static BOOLEAN  bPreWifiBusy=FALSE;
2117         BOOLEAN                 bWifiBusy = FALSE;
2118
2119         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TdmaDurationAdjustForAcl()\n"));
2120
2121         if(BT_8703B_1ANT_WIFI_STATUS_CONNECTED_BUSY == wifiStatus) 
2122                 bWifiBusy = TRUE;
2123         else
2124                 bWifiBusy = FALSE;              
2125
2126         if( (BT_8703B_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN == wifiStatus) ||
2127                 (BT_8703B_1ANT_WIFI_STATUS_CONNECTED_SCAN == wifiStatus) ||
2128                 (BT_8703B_1ANT_WIFI_STATUS_CONNECTED_SPECIAL_PKT == wifiStatus) )
2129         {
2130                 if( pCoexDm->curPsTdma != 1 &&
2131                         pCoexDm->curPsTdma != 2 &&
2132                         pCoexDm->curPsTdma != 3 &&
2133                         pCoexDm->curPsTdma != 9 )
2134                 {
2135                         halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);
2136                         pCoexDm->psTdmaDuAdjType = 9;
2137
2138                         up = 0;
2139                         dn = 0;
2140                         m = 1;
2141                         n= 3;
2142                         result = 0;
2143                         WaitCount = 0;
2144                 }               
2145                 return;
2146         }
2147
2148         if(!pCoexDm->bAutoTdmaAdjust)
2149         {
2150                 pCoexDm->bAutoTdmaAdjust = TRUE;
2151                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], first run TdmaDurationAdjust()!!\n"));
2152
2153                 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);
2154                 pCoexDm->psTdmaDuAdjType = 2;
2155                 //============
2156                 up = 0;
2157                 dn = 0;
2158                 m = 1;
2159                 n= 3;
2160                 result = 0;
2161                 WaitCount = 0;
2162         }
2163         else
2164         {
2165                 //accquire the BT TRx retry count from BT_Info byte2
2166                 retryCount = pCoexSta->btRetryCnt;
2167                 btInfoExt = pCoexSta->btInfoExt;
2168
2169                 if ( (pCoexSta->lowPriorityTx) > 1050 ||  (pCoexSta->lowPriorityRx) > 1250 )
2170                         retryCount++;   
2171                 
2172                 result = 0;
2173                 WaitCount++; 
2174                   
2175                 if(retryCount == 0)  // no retry in the last 2-second duration
2176                 {
2177                         up++;
2178                         dn--;
2179
2180                         if (dn <= 0)
2181                                 dn = 0;                          
2182
2183                         if(up >= n)     // if ³sÄò n ­Ó2¬í retry count¬°0, «h½Õ¼eWiFi duration
2184                         {
2185                                 WaitCount = 0; 
2186                                 n = 3;
2187                                 up = 0;
2188                                 dn = 0;
2189                                 result = 1; 
2190                                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Increase wifi duration!!\n"));
2191                         }
2192                 }
2193                 else if (retryCount <= 3)       // <=3 retry in the last 2-second duration
2194                 {
2195                         up--; 
2196                         dn++;
2197
2198                         if (up <= 0)
2199                                 up = 0;
2200
2201                         if (dn == 2)    // if ³sÄò 2 ­Ó2¬í retry count< 3, «h½Õ¯¶WiFi duration
2202                         {
2203                                 if (WaitCount <= 2)
2204                                         m++; // ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^
2205                                 else
2206                                         m = 1;
2207
2208                                 if ( m >= 20) //m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration.
2209                                         m = 20;
2210
2211                                 n = 3*m;
2212                                 up = 0;
2213                                 dn = 0;
2214                                 WaitCount = 0;
2215                                 result = -1; 
2216                                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter<3!!\n"));
2217                         }
2218                 }
2219                 else  //retry count > 3, ¥u­n1¦¸ retry count > 3, «h½Õ¯¶WiFi duration
2220                 {
2221                         if (WaitCount == 1)
2222                                 m++; // ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^
2223                         else
2224                                 m = 1;
2225
2226                         if ( m >= 20) //m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration.
2227                                 m = 20;
2228
2229                         n = 3*m;
2230                         up = 0;
2231                         dn = 0;
2232                         WaitCount = 0; 
2233                         result = -1;
2234                         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter>3!!\n"));
2235                 }
2236
2237                 if(result == -1)
2238                 {
2239 /*                      if( (BT_INFO_8703B_1ANT_A2DP_BASIC_RATE(btInfoExt)) &&
2240                                 ((pCoexDm->curPsTdma == 1) ||(pCoexDm->curPsTdma == 2)) )
2241                         {
2242                                 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);
2243                                 pCoexDm->psTdmaDuAdjType = 9;
2244                         }
2245                         else */ if(pCoexDm->curPsTdma == 1)
2246                         {
2247                                 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);
2248                                 pCoexDm->psTdmaDuAdjType = 2;
2249                         }
2250                         else if(pCoexDm->curPsTdma == 2)
2251                         {
2252                                 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);
2253                                 pCoexDm->psTdmaDuAdjType = 9;
2254                         }
2255                         else if(pCoexDm->curPsTdma == 9)
2256                         {
2257                                 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
2258                                 pCoexDm->psTdmaDuAdjType = 11;
2259                         }
2260                 }
2261                 else if(result == 1)
2262                 {
2263 /*                      if( (BT_INFO_8703B_1ANT_A2DP_BASIC_RATE(btInfoExt)) &&
2264                                 ((pCoexDm->curPsTdma == 1) ||(pCoexDm->curPsTdma == 2)) )
2265                         {
2266                                 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);
2267                                 pCoexDm->psTdmaDuAdjType = 9;
2268                         }
2269                         else */ if(pCoexDm->curPsTdma == 11)
2270                         {
2271                                 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);
2272                                 pCoexDm->psTdmaDuAdjType = 9;
2273                         }
2274                         else if(pCoexDm->curPsTdma == 9)
2275                         {
2276                                 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);
2277                                 pCoexDm->psTdmaDuAdjType = 2;
2278                         }
2279                         else if(pCoexDm->curPsTdma == 2)
2280                         {
2281                                 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);
2282                                 pCoexDm->psTdmaDuAdjType = 1;
2283                         }
2284                 }
2285                 else      //no change
2286                 {
2287                         /* Bryant Modify        
2288                         if(bWifiBusy != bPreWifiBusy)  //if busy / idle change
2289                         {
2290                                 bPreWifiBusy = bWifiBusy;
2291                                 halbtc8703b1ant_PsTdma(pBtCoexist, FORCE_EXEC, TRUE, pCoexDm->curPsTdma);
2292                         }
2293                         */
2294                 
2295                         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], ********** TDMA(on, %d) **********\n", 
2296                                 pCoexDm->curPsTdma));
2297                 }
2298
2299                 if( pCoexDm->curPsTdma != 1 &&
2300                         pCoexDm->curPsTdma != 2 &&
2301                         pCoexDm->curPsTdma != 9 &&
2302                         pCoexDm->curPsTdma != 11 )
2303                 {
2304                         // recover to previous adjust type
2305                         halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, pCoexDm->psTdmaDuAdjType);
2306                 }
2307         }
2308 }
2309
2310 VOID
2311 halbtc8703b1ant_PsTdmaCheckForPowerSaveState(
2312         IN      PBTC_COEXIST            pBtCoexist,
2313         IN      BOOLEAN                 bNewPsState
2314         )
2315 {
2316         u1Byte  lpsMode=0x0;
2317
2318         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_LPS_MODE, &lpsMode);
2319         
2320         if(lpsMode)     // already under LPS state
2321         {
2322                 if(bNewPsState)         
2323                 {
2324                         // keep state under LPS, do nothing.
2325                 }
2326                 else
2327                 {
2328                         // will leave LPS state, turn off psTdma first
2329                         halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
2330                 }
2331         }
2332         else                                            // NO PS state
2333         {
2334                 if(bNewPsState)
2335                 {
2336                         // will enter LPS state, turn off psTdma first
2337                         halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
2338                 }
2339                 else
2340                 {
2341                         // keep state under NO PS state, do nothing.
2342                 }
2343         }
2344 }
2345
2346 VOID
2347 halbtc8703b1ant_PowerSaveState(
2348         IN      PBTC_COEXIST            pBtCoexist,
2349         IN      u1Byte                          psType,
2350         IN      u1Byte                          lpsVal,
2351         IN      u1Byte                          rpwmVal
2352         )
2353 {
2354         BOOLEAN         bLowPwrDisable=FALSE;
2355         
2356         switch(psType)
2357         {
2358                 case BTC_PS_WIFI_NATIVE:
2359                         // recover to original 32k low power setting
2360                         pCoexSta->bForceLpsOn = FALSE;
2361                         bLowPwrDisable = FALSE;
2362                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);
2363                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_NORMAL_LPS, NULL);
2364                         
2365                         break;
2366                 case BTC_PS_LPS_ON:
2367                         pCoexSta->bForceLpsOn = TRUE;
2368                         halbtc8703b1ant_PsTdmaCheckForPowerSaveState(pBtCoexist, TRUE);
2369                         halbtc8703b1ant_LpsRpwm(pBtCoexist, NORMAL_EXEC, lpsVal, rpwmVal);                      
2370                         // when coex force to enter LPS, do not enter 32k low power.
2371                         bLowPwrDisable = TRUE;
2372                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);
2373                         // power save must executed before psTdma.                      
2374                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_ENTER_LPS, NULL);
2375                         
2376                         break;
2377                 case BTC_PS_LPS_OFF:
2378                         pCoexSta->bForceLpsOn = FALSE;
2379                         halbtc8703b1ant_PsTdmaCheckForPowerSaveState(pBtCoexist, FALSE);
2380                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_LEAVE_LPS, NULL);
2381                         
2382                         break;
2383                 default:
2384                         break;
2385         }
2386 }
2387
2388 VOID
2389 halbtc8703b1ant_ActionWifiOnly(
2390         IN      PBTC_COEXIST            pBtCoexist
2391         )
2392 {
2393         halbtc8703b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);
2394         halbtc8703b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);
2395         halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, FORCE_EXEC, FALSE, FALSE);
2396 }
2397
2398 VOID
2399 halbtc8703b1ant_MonitorBtEnableDisable(
2400         IN      PBTC_COEXIST            pBtCoexist
2401         )
2402 {
2403         static BOOLEAN  bPreBtDisabled=FALSE;
2404         static u4Byte           btDisableCnt=0;
2405         BOOLEAN                 bBtActive=TRUE, bBtDisabled=FALSE;
2406
2407         // This function check if bt is disabled
2408
2409         if(     pCoexSta->highPriorityTx == 0 &&
2410                 pCoexSta->highPriorityRx == 0 &&
2411                 pCoexSta->lowPriorityTx == 0 &&
2412                 pCoexSta->lowPriorityRx == 0)
2413         {
2414                 bBtActive = FALSE;
2415         }
2416         if(     pCoexSta->highPriorityTx == 0xffff &&
2417                 pCoexSta->highPriorityRx == 0xffff &&
2418                 pCoexSta->lowPriorityTx == 0xffff &&
2419                 pCoexSta->lowPriorityRx == 0xffff)
2420         {
2421                 bBtActive = FALSE;
2422         }
2423         if(bBtActive)
2424         {
2425                 btDisableCnt = 0;
2426                 bBtDisabled = FALSE;
2427                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);
2428                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is enabled !!\n"));
2429         }
2430         else
2431         {
2432                 btDisableCnt++;
2433                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], bt all counters=0, %d times!!\n", 
2434                                 btDisableCnt));
2435                 if(btDisableCnt >= 2)
2436                 {
2437                         bBtDisabled = TRUE;
2438                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);
2439                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is disabled !!\n"));
2440                         halbtc8703b1ant_ActionWifiOnly(pBtCoexist);
2441                 }
2442         }
2443         if(bPreBtDisabled != bBtDisabled)
2444         {
2445                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is from %s to %s!!\n", 
2446                         (bPreBtDisabled ? "disabled":"enabled"), 
2447                         (bBtDisabled ? "disabled":"enabled")));
2448                 bPreBtDisabled = bBtDisabled;
2449                 if(!bBtDisabled)
2450                 {
2451                 }
2452                 else
2453                 {
2454                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_LEAVE_LPS, NULL);
2455                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_NORMAL_LPS, NULL);
2456                 }
2457         }
2458 }
2459
2460 //=============================================
2461 //
2462 //      Software Coex Mechanism start
2463 //
2464 //=============================================
2465
2466 // SCO only or SCO+PAN(HS)
2467
2468 /*
2469 VOID
2470 halbtc8703b1ant_ActionSco(
2471         IN      PBTC_COEXIST            pBtCoexist
2472         )
2473 {
2474         halbtc8703b1ant_SwMechanism(pBtCoexist, TRUE);
2475 }
2476
2477
2478 VOID
2479 halbtc8703b1ant_ActionHid(
2480         IN      PBTC_COEXIST            pBtCoexist
2481         )
2482 {
2483         halbtc8703b1ant_SwMechanism(pBtCoexist, TRUE);
2484 }
2485
2486 //A2DP only / PAN(EDR) only/ A2DP+PAN(HS)
2487 VOID
2488 halbtc8703b1ant_ActionA2dp(
2489         IN      PBTC_COEXIST            pBtCoexist
2490         )
2491 {
2492         halbtc8703b1ant_SwMechanism(pBtCoexist, FALSE);
2493 }
2494
2495 VOID
2496 halbtc8703b1ant_ActionA2dpPanHs(
2497         IN      PBTC_COEXIST            pBtCoexist
2498         )
2499 {
2500         halbtc8703b1ant_SwMechanism(pBtCoexist, FALSE);
2501 }
2502
2503 VOID
2504 halbtc8703b1ant_ActionPanEdr(
2505         IN      PBTC_COEXIST            pBtCoexist
2506         )
2507 {
2508         halbtc8703b1ant_SwMechanism(pBtCoexist, FALSE);
2509 }
2510
2511 //PAN(HS) only
2512 VOID
2513 halbtc8703b1ant_ActionPanHs(
2514         IN      PBTC_COEXIST            pBtCoexist
2515         )
2516 {
2517         halbtc8703b1ant_SwMechanism(pBtCoexist, FALSE);
2518 }
2519
2520 //PAN(EDR)+A2DP
2521 VOID
2522 halbtc8703b1ant_ActionPanEdrA2dp(
2523         IN      PBTC_COEXIST            pBtCoexist
2524         )
2525 {
2526         halbtc8703b1ant_SwMechanism(pBtCoexist, FALSE);
2527 }
2528
2529 VOID
2530 halbtc8703b1ant_ActionPanEdrHid(
2531         IN      PBTC_COEXIST            pBtCoexist
2532         )
2533 {
2534         halbtc8703b1ant_SwMechanism(pBtCoexist, TRUE);
2535 }
2536
2537 // HID+A2DP+PAN(EDR)
2538 VOID
2539 halbtc8703b1ant_ActionHidA2dpPanEdr(
2540         IN      PBTC_COEXIST            pBtCoexist
2541         )
2542 {
2543         halbtc8703b1ant_SwMechanism(pBtCoexist, TRUE);
2544 }
2545
2546 VOID
2547 halbtc8703b1ant_ActionHidA2dp(
2548         IN      PBTC_COEXIST            pBtCoexist
2549         )
2550 {
2551         halbtc8703b1ant_SwMechanism(pBtCoexist, TRUE);
2552 }
2553
2554 */
2555
2556 //=============================================
2557 //
2558 //      Non-Software Coex Mechanism start
2559 //
2560 //=============================================
2561 VOID
2562 halbtc8703b1ant_ActionBtWhckTest(
2563         IN      PBTC_COEXIST            pBtCoexist
2564         )
2565 {
2566         halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2567         
2568         halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
2569         halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
2570         halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
2571 }
2572
2573 VOID
2574 halbtc8703b1ant_ActionWifiMultiPort(
2575         IN      PBTC_COEXIST            pBtCoexist
2576         )
2577 {
2578         halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2579         
2580         halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
2581         halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
2582         halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
2583 }
2584
2585 VOID
2586 halbtc8703b1ant_ActionHs(
2587         IN      PBTC_COEXIST            pBtCoexist
2588         )
2589 {
2590         halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);
2591         halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
2592 }
2593
2594 VOID
2595 halbtc8703b1ant_ActionBtInquiry(
2596         IN      PBTC_COEXIST            pBtCoexist
2597         )
2598 {       
2599         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
2600         BOOLEAN                 bWifiConnected=FALSE, bApEnable=FALSE, bWifiBusy=FALSE, bBtBusy=FALSE;
2601
2602         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);
2603         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
2604         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
2605         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);
2606
2607         if ( (!bWifiConnected) && (!pCoexSta->bWiFiIsHighPriTask) )
2608         {
2609                 halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2610                 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
2611                 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
2612                 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);          
2613         }
2614         else if( (pBtLinkInfo->bScoExist) ||    (pBtLinkInfo->bHidExist) ||     (pBtLinkInfo->bA2dpExist)  )
2615         {
2616                 // SCO/HID/A2DP busy
2617                 halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2618                 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
2619                 
2620                 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);          
2621         }
2622         else if ( (pBtLinkInfo->bPanExist) || (bWifiBusy) )
2623         {
2624                 halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);               
2625
2626                 //for BT inquiry/page fail after S4 resume
2627                 //halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);            
2628                 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
2629                 
2630                 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2631         }
2632         else
2633         {
2634                 halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2635                 
2636                 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
2637                 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
2638                 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);          
2639                 
2640
2641                 //halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
2642                 //halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);                                
2643         }
2644 }
2645
2646 VOID
2647 halbtc8703b1ant_ActionBtScoHidOnlyBusy(
2648         IN      PBTC_COEXIST            pBtCoexist,
2649         IN      u1Byte                          wifiStatus
2650         )
2651 {
2652         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
2653         BOOLEAN bWifiConnected=FALSE;
2654         u1Byte  wifiRssiState=BTC_RSSI_STATE_HIGH;
2655
2656         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
2657
2658         // tdma and coex table
2659
2660         if(pBtLinkInfo->bScoExist)
2661         {
2662                 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);
2663                 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 5);
2664         }
2665         else //HID
2666         {
2667                 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);
2668                 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 5);
2669         }
2670 }
2671
2672 VOID
2673 halbtc8703b1ant_ActionWifiConnectedBtAclBusy(
2674         IN      PBTC_COEXIST            pBtCoexist,
2675         IN      u1Byte                          wifiStatus
2676         )
2677 {
2678         u1Byte          btRssiState;
2679         
2680         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
2681         btRssiState = halbtc8703b1ant_BtRssiState(2, 28, 0);    
2682
2683         if ( (pCoexSta->lowPriorityRx >= 950)  && (!pCoexSta->bUnderIps)  
2684                         &&  (pCoexSta->lowPriorityRx >= pCoexSta->lowPriorityTx)  && (!pCoexSta->bC2hBtInquiryPage))
2685         {
2686                 pBtLinkInfo->bSlaveRole = TRUE;
2687         }
2688         else
2689         {
2690                 pBtLinkInfo->bSlaveRole = FALSE;
2691         }
2692
2693         if(pBtLinkInfo->bHidOnly)  //HID
2694         {
2695                 halbtc8703b1ant_ActionBtScoHidOnlyBusy(pBtCoexist, wifiStatus);
2696                 pCoexDm->bAutoTdmaAdjust = FALSE;
2697                 return;
2698         }
2699         else if(pBtLinkInfo->bA2dpOnly)  //A2DP         
2700         {
2701                 if(BT_8703B_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifiStatus)
2702                 {
2703                         halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
2704                         halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2705                         pCoexDm->bAutoTdmaAdjust = FALSE;
2706                 }
2707                 else
2708                 {
2709                         //halbtc8703b1ant_TdmaDurationAdjustForAcl(pBtCoexist, wifiStatus);
2710                         halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);
2711                         halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2712                         pCoexDm->bAutoTdmaAdjust = TRUE;
2713                 }
2714         }
2715         else if ( ((pBtLinkInfo->bA2dpExist) && (pBtLinkInfo->bPanExist)) ||
2716                        (pBtLinkInfo->bHidExist&&pBtLinkInfo->bA2dpExist&&pBtLinkInfo->bPanExist) ) //A2DP+PAN(OPP,FTP), HID+A2DP+PAN(OPP,FTP)
2717         {
2718                 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);
2719                 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2720                 pCoexDm->bAutoTdmaAdjust = FALSE;
2721         }
2722         else if(pBtLinkInfo->bHidExist&&pBtLinkInfo->bA2dpExist)  //HID+A2DP
2723         {
2724                 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);
2725                 pCoexDm->bAutoTdmaAdjust = FALSE;
2726
2727                 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2728         }
2729         else if( (pBtLinkInfo->bPanOnly) || (pBtLinkInfo->bHidExist&&pBtLinkInfo->bPanExist) ) //PAN(OPP,FTP), HID+PAN(OPP,FTP)                 
2730         {
2731                 if(BT_8703B_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifiStatus)
2732                         halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);
2733                 else
2734                 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
2735                         
2736                 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2737                 pCoexDm->bAutoTdmaAdjust = FALSE;
2738         }
2739         else
2740         {               
2741                 //BT no-profile busy (0x9)
2742                 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 33);      
2743                 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2744                 pCoexDm->bAutoTdmaAdjust = FALSE;
2745         }       
2746 }
2747
2748 VOID
2749 halbtc8703b1ant_ActionWifiNotConnected(
2750         IN      PBTC_COEXIST            pBtCoexist
2751         )
2752 {
2753         // power save state
2754         halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2755
2756         // tdma and coex table
2757         halbtc8703b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);
2758         halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
2759         halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
2760 }
2761
2762 VOID
2763 halbtc8703b1ant_ActionWifiNotConnectedScan(
2764         IN      PBTC_COEXIST            pBtCoexist
2765         )
2766 {
2767         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
2768         
2769         halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2770
2771         // tdma and coex table
2772         if(BT_8703B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)
2773         {
2774                 if (pBtLinkInfo->bA2dpExist)
2775                 {
2776                         halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
2777                         halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2778                 }
2779                 else if (pBtLinkInfo->bA2dpExist && pBtLinkInfo->bPanExist)
2780                 {
2781                         halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 22);
2782                         halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2783                 }
2784                 else
2785                 {
2786                 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);
2787                         halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);                  
2788                 }
2789         }
2790         else if( (BT_8703B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||
2791                         (BT_8703B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )
2792         {
2793                 halbtc8703b1ant_ActionBtScoHidOnlyBusy(pBtCoexist,
2794                         BT_8703B_1ANT_WIFI_STATUS_CONNECTED_SCAN);
2795         }
2796         else
2797         {
2798                 //Bryant Add
2799                 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
2800                 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
2801                 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
2802         }
2803 }
2804
2805 VOID
2806 halbtc8703b1ant_ActionWifiNotConnectedAssoAuth(
2807         IN      PBTC_COEXIST            pBtCoexist
2808         )
2809 {
2810         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
2811         
2812         halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2813
2814         // tdma and coex table
2815         if( (pBtLinkInfo->bScoExist)  || (pBtLinkInfo->bHidExist) ||  (pBtLinkInfo->bA2dpExist) )
2816         {
2817                 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
2818                 halbtc8703b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 4);           
2819         }
2820         else if (pBtLinkInfo->bPanExist)                        
2821         {
2822                 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);
2823                 halbtc8703b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 4);           
2824         }
2825         else
2826         {
2827                 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
2828                 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
2829                 halbtc8703b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 2);
2830         }
2831 }
2832
2833 VOID
2834 halbtc8703b1ant_ActionWifiConnectedScan(
2835         IN      PBTC_COEXIST            pBtCoexist
2836         )
2837 {
2838         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
2839         
2840         halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2841
2842         // tdma and coex table
2843         if(BT_8703B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)
2844         {
2845                 if (pBtLinkInfo->bA2dpExist)
2846                 {
2847                         halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
2848                         halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2849                 }
2850                 else if (pBtLinkInfo->bA2dpExist && pBtLinkInfo->bPanExist)
2851                 {
2852                         halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 22);
2853                         halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2854                 }
2855                 else
2856                 {
2857                 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);
2858                         halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2859         }
2860         }
2861         else if( (BT_8703B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||
2862                         (BT_8703B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )
2863         {
2864                 halbtc8703b1ant_ActionBtScoHidOnlyBusy(pBtCoexist,
2865                         BT_8703B_1ANT_WIFI_STATUS_CONNECTED_SCAN);
2866         }
2867         else
2868         {
2869                 //Bryant Add
2870                 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
2871                 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
2872                 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
2873         }
2874 }
2875
2876 VOID
2877 halbtc8703b1ant_ActionWifiConnectedSpecialPacket(
2878         IN      PBTC_COEXIST            pBtCoexist
2879         )
2880 {
2881         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
2882         BOOLEAN bWifiBusy = FALSE;
2883
2884         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
2885
2886         //no special packet process for both WiFi and BT very busy
2887         if ((bWifiBusy) && ((pBtLinkInfo->bPanExist) || (pCoexSta->nNumOfProfile >= 2)))
2888          return;        
2889
2890         halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2891
2892         // tdma and coex table
2893         if((pBtLinkInfo->bScoExist) || (pBtLinkInfo->bHidExist))
2894         {
2895                 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
2896                 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 5);          
2897         }
2898         else if  (pBtLinkInfo->bA2dpExist)
2899         {
2900                 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
2901                 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);          
2902         }
2903         else if(pBtLinkInfo->bPanExist)
2904         {
2905                 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);
2906                 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);          
2907         }
2908         else
2909         {
2910                 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
2911                 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
2912                 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
2913         }
2914 }
2915
2916 VOID
2917 halbtc8703b1ant_ActionWifiConnected(
2918         IN      PBTC_COEXIST            pBtCoexist
2919         )
2920 {
2921         BOOLEAN         bWifiBusy=FALSE;
2922         BOOLEAN         bScan=FALSE, bLink=FALSE, bRoam=FALSE;
2923         BOOLEAN         bUnder4way=FALSE, bApEnable=FALSE;
2924         u4Byte          wifiBw;
2925
2926         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CoexForWifiConnect()===>\n"));
2927
2928         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way);
2929         if(bUnder4way)
2930         {
2931                 halbtc8703b1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);
2932                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n"));
2933                 return;
2934         }
2935         
2936         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
2937         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
2938         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
2939         if(bScan || bLink || bRoam)
2940         {
2941                 if(bScan)       
2942                         halbtc8703b1ant_ActionWifiConnectedScan(pBtCoexist);
2943                 else
2944                         halbtc8703b1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);
2945                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n"));
2946                 return;
2947         }
2948
2949         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);
2950         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
2951         
2952         // power save state
2953         if(!bApEnable && BT_8703B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus && !pBtCoexist->btLinkInfo.bHidOnly)
2954         {
2955                 if(pBtCoexist->btLinkInfo.bA2dpOnly)    //A2DP
2956                         {                       
2957                         if(!bWifiBusy)
2958                                 halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);                               
2959                         else //busy
2960                         {
2961                                 if  (pCoexSta->nScanAPNum >= BT_8703B_1ANT_WIFI_NOISY_THRESH)  //no force LPS, no PS-TDMA, use pure TDMA
2962                                 {
2963                         halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2964                                 }
2965                                 else
2966                                 {
2967                                         halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);                                   
2968                                 }
2969                         }
2970                 }
2971                 else if ((pCoexSta->bPanExist == FALSE) && (pCoexSta->bA2dpExist == FALSE) && (pCoexSta->bHidExist == FALSE))
2972                         halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2973                 else
2974                         halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
2975         }
2976         else
2977                 halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2978
2979         // tdma and coex table
2980         if(!bWifiBusy)
2981         {
2982                 if(BT_8703B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)
2983                 {
2984                         halbtc8703b1ant_ActionWifiConnectedBtAclBusy(pBtCoexist, 
2985                                 BT_8703B_1ANT_WIFI_STATUS_CONNECTED_IDLE);
2986                 }
2987                 else if( (BT_8703B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||
2988                         (BT_8703B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )
2989                 {
2990                         halbtc8703b1ant_ActionBtScoHidOnlyBusy(pBtCoexist,
2991                                 BT_8703B_1ANT_WIFI_STATUS_CONNECTED_IDLE);
2992                 }
2993                 else
2994                 {
2995                         halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
2996                         halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
2997                         halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);           
2998                 }
2999         }
3000         else
3001         {
3002                 if(BT_8703B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)
3003                 {
3004                         halbtc8703b1ant_ActionWifiConnectedBtAclBusy(pBtCoexist,
3005                                 BT_8703B_1ANT_WIFI_STATUS_CONNECTED_BUSY);
3006                 }
3007                 else if( (BT_8703B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||
3008                         (BT_8703B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )
3009                 {
3010                         halbtc8703b1ant_ActionBtScoHidOnlyBusy(pBtCoexist,
3011                                 BT_8703B_1ANT_WIFI_STATUS_CONNECTED_BUSY);
3012                 }
3013                 else 
3014                 {
3015                         //halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
3016                         halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
3017                         halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);    
3018                         //halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);        
3019                         halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);  
3020                 }
3021         }
3022 }
3023
3024 VOID
3025 halbtc8703b1ant_RunSwCoexistMechanism(
3026         IN      PBTC_COEXIST            pBtCoexist
3027         )
3028 {
3029         u1Byte                          algorithm=0;
3030
3031         algorithm = halbtc8703b1ant_ActionAlgorithm(pBtCoexist);
3032         pCoexDm->curAlgorithm = algorithm;
3033
3034         if(halbtc8703b1ant_IsCommonAction(pBtCoexist))
3035         {
3036
3037         }
3038         else
3039         {
3040                 switch(pCoexDm->curAlgorithm)
3041                 {
3042                         case BT_8703B_1ANT_COEX_ALGO_SCO:
3043                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = SCO.\n"));
3044                                 //halbtc8703b1ant_ActionSco(pBtCoexist);
3045                                 break;
3046                         case BT_8703B_1ANT_COEX_ALGO_HID:
3047                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = HID.\n"));
3048                                 //halbtc8703b1ant_ActionHid(pBtCoexist);
3049                                 break;
3050                         case BT_8703B_1ANT_COEX_ALGO_A2DP:
3051                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = A2DP.\n"));
3052                                 //halbtc8703b1ant_ActionA2dp(pBtCoexist);
3053                                 break;
3054                         case BT_8703B_1ANT_COEX_ALGO_A2DP_PANHS:
3055                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = A2DP+PAN(HS).\n"));
3056                                 //halbtc8703b1ant_ActionA2dpPanHs(pBtCoexist);
3057                                 break;
3058                         case BT_8703B_1ANT_COEX_ALGO_PANEDR:
3059                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = PAN(EDR).\n"));
3060                                 //halbtc8703b1ant_ActionPanEdr(pBtCoexist);
3061                                 break;
3062                         case BT_8703B_1ANT_COEX_ALGO_PANHS:
3063                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = HS mode.\n"));
3064                                 //halbtc8703b1ant_ActionPanHs(pBtCoexist);
3065                                 break;
3066                         case BT_8703B_1ANT_COEX_ALGO_PANEDR_A2DP:
3067                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = PAN+A2DP.\n"));
3068                                 //halbtc8703b1ant_ActionPanEdrA2dp(pBtCoexist);
3069                                 break;
3070                         case BT_8703B_1ANT_COEX_ALGO_PANEDR_HID:
3071                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = PAN(EDR)+HID.\n"));
3072                                 //halbtc8703b1ant_ActionPanEdrHid(pBtCoexist);
3073                                 break;
3074                         case BT_8703B_1ANT_COEX_ALGO_HID_A2DP_PANEDR:
3075                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = HID+A2DP+PAN.\n"));
3076                                 //halbtc8703b1ant_ActionHidA2dpPanEdr(pBtCoexist);
3077                                 break;
3078                         case BT_8703B_1ANT_COEX_ALGO_HID_A2DP:
3079                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = HID+A2DP.\n"));
3080                                 //halbtc8703b1ant_ActionHidA2dp(pBtCoexist);
3081                                 break;
3082                         default:
3083                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = coexist All Off!!\n"));
3084                                 //halbtc8703b1ant_CoexAllOff(pBtCoexist);
3085                                 break;
3086                 }
3087                 pCoexDm->preAlgorithm = pCoexDm->curAlgorithm;
3088         }
3089 }
3090
3091 VOID
3092 halbtc8703b1ant_RunCoexistMechanism(
3093         IN      PBTC_COEXIST            pBtCoexist
3094         )
3095 {
3096         PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
3097         BOOLEAN bWifiConnected=FALSE, bBtHsOn=FALSE;
3098         BOOLEAN bIncreaseScanDevNum=FALSE;
3099         BOOLEAN bBtCtrlAggBufSize=FALSE;
3100         BOOLEAN bMiracastPlusBt=FALSE;
3101         u1Byte  aggBufSize=5;
3102         u1Byte  wifiRssiState=BTC_RSSI_STATE_HIGH;
3103         u4Byte  wifiLinkStatus=0;
3104         u4Byte  numOfWifiLink=0, wifiBw;
3105         u1Byte  iotPeer=BTC_IOT_PEER_UNKNOWN;
3106
3107         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RunCoexistMechanism()===>\n"));
3108
3109         if(pBtCoexist->bManualControl)
3110         {
3111                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"));
3112                 return;
3113         }
3114
3115         if(pBtCoexist->bStopCoexDm)
3116         {
3117                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n"));
3118                 return;
3119         }
3120
3121         if(pCoexSta->bUnderIps)
3122         {
3123                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], wifi is under IPS !!!\n"));
3124                 return;
3125         }
3126
3127         if(pCoexSta->bBtWhckTest)
3128         {
3129                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is under WHCK TEST!!!\n"));
3130                 halbtc8703b1ant_ActionBtWhckTest(pBtCoexist);
3131                 return;
3132         }
3133
3134         if( (BT_8703B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus) ||
3135                 (BT_8703B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||
3136                 (BT_8703B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )
3137         {
3138                 bIncreaseScanDevNum = TRUE;
3139         }
3140
3141         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_INC_SCAN_DEV_NUM, &bIncreaseScanDevNum);
3142         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
3143
3144         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);
3145         numOfWifiLink = wifiLinkStatus>>16;
3146         
3147         if((numOfWifiLink>=2) || (wifiLinkStatus&WIFI_P2P_GO_CONNECTED))
3148         {
3149                 RT_TRACE(COMP_COEX, DBG_LOUD, ("############# [BTCoex],  Multi-Port numOfWifiLink = %d, wifiLinkStatus = 0x%x\n", numOfWifiLink,wifiLinkStatus) );
3150
3151                 if(pBtLinkInfo->bBtLinkExist)
3152                 {
3153                         halbtc8703b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 1, 1, 0, 1);
3154                         bMiracastPlusBt = TRUE;
3155                 }
3156                 else
3157                 {
3158                 halbtc8703b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);
3159                         bMiracastPlusBt = FALSE;
3160                 }
3161                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_MIRACAST_PLUS_BT, &bMiracastPlusBt);
3162                 halbtc8703b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, bBtCtrlAggBufSize, aggBufSize);
3163
3164                 if ( (pBtLinkInfo->bA2dpExist) && (pCoexSta->bC2hBtInquiryPage) )
3165                 {
3166                         RT_TRACE(COMP_COEX, DBG_LOUD, ("############# [BTCoex],  BT Is Inquirying \n") );       
3167                         halbtc8703b1ant_ActionBtInquiry(pBtCoexist);
3168                 }
3169                 else
3170                 halbtc8703b1ant_ActionWifiMultiPort(pBtCoexist);
3171                 
3172                 return;
3173         }
3174         else
3175         {
3176                 bMiracastPlusBt = FALSE;
3177                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_MIRACAST_PLUS_BT, &bMiracastPlusBt);
3178         }
3179
3180         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
3181
3182         if ( (pBtLinkInfo->bBtLinkExist) && (bWifiConnected) )
3183         {
3184                 halbtc8703b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 1, 1, 0, 1); 
3185
3186                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_IOT_PEER, &iotPeer);
3187
3188                 if(BTC_IOT_PEER_CISCO != iotPeer)
3189                 {
3190                         if(pBtLinkInfo->bScoExist)//if (pBtLinkInfo->bBtHiPriLinkExist)
3191                                 halbtc8703b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x5);   
3192                         else
3193                                 halbtc8703b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x5);
3194                 }
3195                 else
3196                 {
3197                         if(pBtLinkInfo->bScoExist)
3198                                 halbtc8703b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x5);
3199                         else
3200                         {
3201                                 if (BTC_WIFI_BW_HT40==wifiBw)
3202                                         halbtc8703b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, TRUE, 0x10);  
3203                                 else
3204                                         halbtc8703b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, TRUE, 0x8);
3205                         }
3206                 }
3207
3208                 halbtc8703b1ant_SwMechanism(pBtCoexist, TRUE);
3209                 halbtc8703b1ant_RunSwCoexistMechanism(pBtCoexist);  //just print debug message
3210         }
3211         else
3212         {
3213                 halbtc8703b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);
3214
3215                 halbtc8703b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x5);
3216
3217                 halbtc8703b1ant_SwMechanism(pBtCoexist, FALSE);
3218                 halbtc8703b1ant_RunSwCoexistMechanism(pBtCoexist); ////just print debug message
3219         }
3220         
3221         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
3222         if(pCoexSta->bC2hBtInquiryPage)
3223         {
3224                 RT_TRACE(COMP_COEX, DBG_LOUD, ("############# [BTCoex],  BT Is Inquirying \n") );               
3225                 halbtc8703b1ant_ActionBtInquiry(pBtCoexist);
3226                 return;
3227         }
3228         else if(bBtHsOn)
3229         {
3230                 halbtc8703b1ant_ActionHs(pBtCoexist);
3231                 return;
3232         }
3233
3234         
3235         if(!bWifiConnected)
3236         {
3237                 BOOLEAN bScan=FALSE, bLink=FALSE, bRoam=FALSE;
3238                 
3239                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], wifi is non connected-idle !!!\n"));
3240
3241                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
3242                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
3243                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
3244
3245                 if(bScan || bLink || bRoam)
3246                 {
3247                          if (bScan)     
3248                                 halbtc8703b1ant_ActionWifiNotConnectedScan(pBtCoexist); 
3249                          else
3250                                 halbtc8703b1ant_ActionWifiNotConnectedAssoAuth(pBtCoexist);     
3251                 }
3252                 else
3253                         halbtc8703b1ant_ActionWifiNotConnected(pBtCoexist);
3254         }
3255         else    // wifi LPS/Busy
3256         {
3257                 halbtc8703b1ant_ActionWifiConnected(pBtCoexist);
3258         }
3259 }
3260
3261 u4Byte
3262 halbtc8703b1ant_PSD_Log2Base(
3263         IN      PBTC_COEXIST            pBtCoexist,
3264         IN      u4Byte                          val
3265         
3266         )
3267 {
3268         u1Byte  i,j;
3269         u4Byte  tmp, tmp2, val_integerdB=0, tindex, shiftcount=0;
3270         u4Byte  result,val_fractiondB=0,Table_fraction[21]= {0,432, 332, 274, 232, 200,
3271                                                                    174, 151,132,115,100,86,74,62,51,42,
3272                                                                    32,23,15,7,0};
3273
3274         if (val == 0)
3275          return 0;
3276
3277         tmp = val;
3278
3279         while(1)
3280         {
3281                 if (tmp == 1)
3282                         break;  
3283                 else
3284                 {
3285                         tmp = (tmp >> 1);
3286                         shiftcount++;                           
3287                 }
3288         }
3289         
3290
3291         val_integerdB = shiftcount+1;
3292
3293         tmp2=1;
3294         for (j=1; j<= val_integerdB;j++)
3295           tmp2 = tmp2*2;                
3296         
3297         tmp = (val*100) /tmp2;
3298         tindex = tmp/5;
3299
3300         if (tindex > 20)
3301          tindex = 20;
3302
3303         val_fractiondB = Table_fraction[tindex];
3304
3305         result = val_integerdB*100 - val_fractiondB;                    
3306
3307         return (result);
3308
3309
3310 }
3311
3312 VOID
3313 halbtc8703b1ant_InitCoexDm(
3314         IN      PBTC_COEXIST            pBtCoexist
3315         )
3316 {       
3317         // force to reset coex mechanism
3318
3319         // sw all off
3320         halbtc8703b1ant_SwMechanism(pBtCoexist, FALSE);
3321         
3322         //halbtc8703b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);
3323         //halbtc8703b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);
3324
3325         pCoexSta->popEventCnt = 0;
3326 }
3327
3328 VOID
3329 halbtc8703b1ant_InitHwConfig(
3330         IN      PBTC_COEXIST            pBtCoexist,
3331         IN      BOOLEAN                         bBackUp,
3332         IN      BOOLEAN                         bWifiOnly
3333         )
3334 {
3335         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;
3336         u4Byte                          u4Tmp=0;//, fwVer;
3337         u2Byte                          u2Tmp=0;
3338         u1Byte                          u1Tmp=0, u1Tmpa=0, u1Tmpb=0;
3339         u1Byte                          H2C_Parameter[2] ={0};
3340
3341         u4Byte                          u4Tmp1=0, u4Tmp2=0;
3342
3343                         
3344         u4Tmp1 = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0x38);
3345         u4Tmp2 = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0x54);
3346
3347         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ********** (Before Init HW config) 0x38= 0x%x, 0x54= 0x%x**********\n", u4Tmp1, u4Tmp2));
3348
3349         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], 1Ant Init HW Config!!\n"));
3350
3351
3352         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x550, 0x8, 0x1);  //enable TBTT nterrupt
3353
3354         //BT report packet sample rate  
3355         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x790, 0x5);
3356         
3357         // Enable BT counter statistics
3358         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x778, 0x1);             
3359
3360         //Enable PTA (3-wire function form BT side)
3361         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x40, 0x20, 0x1);
3362         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x41, 0x02, 0x1);
3363
3364         //Enable PTA (tx/rx signal form WiFi side)
3365         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x4c6, 0x10, 0x1);
3366
3367         //enable GNT_WL/GNT_BT debug signal to GPIO14/15
3368         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x73, 0x8, 0x1);
3369
3370         //enable GNT_WL
3371         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x4e, 0x40, 0x0);
3372         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x1, 0x0);
3373
3374         halbtc8703b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);
3375         
3376         //Antenna config
3377         if(bWifiOnly)
3378         {
3379                 pCoexSta->bConCurrentRxModeOn = FALSE;
3380                 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_WIFI, FORCE_EXEC, TRUE, FALSE);
3381                 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_WIFI, FORCE_EXEC, FALSE, FALSE);
3382         }
3383         else
3384         {
3385                 pCoexSta->bConCurrentRxModeOn = TRUE;           
3386                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x953, 0x2, 0x1);
3387                 //RF 0x1[0] = 0 -> Set GNT_WL_RF_Rx always = 1 for con-current Rx
3388                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0x1, 0x0);
3389                 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FORCE_EXEC, TRUE, FALSE);
3390         }
3391
3392         // PTA parameter
3393         halbtc8703b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);
3394
3395 }
3396
3397
3398
3399 VOID
3400 halbtc8703b1ant_PSD_ShowData(
3401         IN      PBTC_COEXIST            pBtCoexist
3402         )
3403 {
3404         pu1Byte         cliBuf=pBtCoexist->cliBuf;
3405         u4Byte          nDeltaFreqPerPoint;
3406         u4Byte          freq,freq1,freq2,n=0,i=0, j=0, m=0, PsdRep1, PsdRep2;
3407         
3408         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n\n============[PSD info]  (%d)============\n",
3409                         pPsdScan->nPSDGenCount);
3410         CL_PRINTF(cliBuf);
3411
3412         if (pPsdScan->nPSDGenCount == 0)
3413         {
3414                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n No Data !!\n");
3415                 CL_PRINTF(cliBuf);
3416                 return;
3417         }
3418
3419         if (pPsdScan->nPSDPoint == 0)
3420                 nDeltaFreqPerPoint = 0;
3421         else                    
3422                 nDeltaFreqPerPoint = pPsdScan->nPSDBandWidth/pPsdScan->nPSDPoint;               
3423
3424         //if (pPsdScan->bIsPSDShowMaxOnly)
3425         if (0)
3426         {       
3427                 PsdRep1 = pPsdScan->nPSDMaxValue/100;
3428                 PsdRep2 = pPsdScan->nPSDMaxValue - PsdRep1 * 100;
3429                                 
3430                 freq = ((pPsdScan->nRealCentFreq-20) * 1000000 + pPsdScan->nPSDMaxValuePoint * nDeltaFreqPerPoint);
3431                 freq1 = freq/1000000;
3432                 freq2 = freq/1000 - freq1 * 1000;
3433
3434                 if (freq2 < 100)        
3435                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n Freq = %d.0%d MHz",  
3436                           freq1, freq2);
3437                 else
3438                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n Freq = %d.%d MHz",  
3439                           freq1, freq2);
3440
3441                 if (PsdRep2 < 10)       
3442                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, ", Value = %d.0%d dB, (%d) \n",  
3443                           PsdRep1, PsdRep2, pPsdScan->nPSDMaxValue);
3444                 else
3445                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, ", Value = %d.%d dB, (%d)\n",  
3446                           PsdRep1, PsdRep2, pPsdScan->nPSDMaxValue);
3447                 
3448                 CL_PRINTF(cliBuf);
3449         }
3450         else
3451         {
3452                 m = pPsdScan->nPSDStartPoint;
3453                 n = pPsdScan->nPSDStartPoint;
3454                 i = 1;
3455                 j = 1;                          
3456
3457          while(1)
3458          {
3459                 do
3460                 {
3461                         freq = ((pPsdScan->nRealCentFreq-20) * 1000000 + m * nDeltaFreqPerPoint);
3462                         freq1 = freq/1000000;
3463                         freq2 = freq/1000 - freq1 * 1000;
3464                         
3465                         if (i ==1)
3466                         {
3467                                 if (freq2 == 0)
3468                                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n Freq%6d.000", freq1);
3469                                 else if (freq2 < 100)   
3470                                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n Freq%6d.0%2d", freq1,freq2);
3471                                 else
3472                                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n Freq%6d.%3d", freq1,freq2);
3473                         }
3474                         else if  ( (i%8 == 0) || (m == pPsdScan->nPSDStopPoint) )
3475                         {
3476                                 if (freq2 == 0)
3477                                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%6d.000\n", freq1);
3478                                 else if (freq2 < 100)   
3479                                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%6d.0%2d\n", freq1,freq2);
3480                                 else
3481                                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%6d.%3d\n", freq1,freq2);
3482                         }                       
3483                         else
3484                         {
3485                                 if (freq2 == 0)
3486                                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%6d.000", freq1);
3487                                 else if (freq2 < 100)   
3488                                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%6d.0%2d", freq1,freq2);
3489                                 else
3490                                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%6d.%3d", freq1,freq2);
3491                         }
3492
3493                         i++;                                    
3494                         m++;
3495                         CL_PRINTF(cliBuf);
3496
3497                 }while(  (i <= 8) && (m <= pPsdScan->nPSDStopPoint));   
3498                 
3499                 
3500                 do
3501                 {
3502                         PsdRep1 = pPsdScan->nPSDReport_MaxHold[n]/100;
3503                         PsdRep2 = pPsdScan->nPSDReport_MaxHold[n] - PsdRep1 * 100;
3504                                 
3505                         if (j ==1)
3506                         {
3507                                 if (PsdRep2 <10)
3508                                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n Val %7d.0%d", PsdRep1,PsdRep2);
3509                                 else
3510                                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n Val %7d.%d", PsdRep1,PsdRep2);
3511                         }
3512                         else if ( (j%8 == 0)  || (n == pPsdScan->nPSDStopPoint) )
3513                         {
3514                                 if (PsdRep2 <10)
3515                                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%7d.0%d\n", PsdRep1,PsdRep2);
3516                                 else
3517                                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%7d.%d\n", PsdRep1,PsdRep2);
3518                         }
3519                         else
3520                         {
3521                                 if (PsdRep2 <10)
3522                                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%7d.0%d", PsdRep1,PsdRep2);
3523                                 else
3524                                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%7d.%d", PsdRep1,PsdRep2);
3525                         }
3526
3527                         j++;
3528                         n++;
3529                         CL_PRINTF(cliBuf);
3530                         
3531                 } while(  (j <= 8) && (n <= pPsdScan->nPSDStopPoint));          
3532
3533                 if  ( (m > pPsdScan->nPSDStopPoint) || (n > pPsdScan->nPSDStopPoint) )
3534                  break;
3535                 else
3536                 {
3537                         i = 1;
3538                         j = 1;
3539                 }
3540                 
3541          }      
3542         }
3543
3544
3545 }
3546
3547 VOID
3548 halbtc8703b1ant_PSD_MaxHoldData(
3549         IN      PBTC_COEXIST            pBtCoexist,
3550         IN      u4Byte                          GenCount
3551         )
3552 {
3553                  u4Byte i=0, i_max=0, val_max=0, j;
3554                  
3555                 if (GenCount== 1)
3556                 {
3557                         memcpy(pPsdScan->nPSDReport_MaxHold, pPsdScan->nPSDReport, BT_8703B_1ANT_ANTDET_PSD_POINTS*sizeof(u4Byte));
3558
3559                         for (i= pPsdScan->nPSDStartPoint; i<=pPsdScan->nPSDStopPoint; i++)
3560                         {
3561                                 //RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), Max_Hold i = %d, PSDReport = %d dB\n", i,  pPsdScan->nPSDReport_MaxHold[i]));
3562                         }
3563
3564                         pPsdScan->nPSDMaxValuePoint = 0;
3565                         pPsdScan->nPSDMaxValue = 0;
3566
3567                 }       
3568                 else
3569                 {
3570                         for (i= pPsdScan->nPSDStartPoint; i<=pPsdScan->nPSDStopPoint; i++)
3571                         {
3572                                 if (pPsdScan->nPSDReport[i] > pPsdScan->nPSDReport_MaxHold[i])
3573                                 pPsdScan->nPSDReport_MaxHold[i] = pPsdScan->nPSDReport[i];      
3574
3575                                 //search Max Value
3576                                 if (i ==pPsdScan->nPSDStartPoint )
3577                                 {
3578                                         i_max = i;
3579                                         val_max = pPsdScan->nPSDReport_MaxHold[i];
3580                                 }
3581                                 else
3582                                 {
3583                                         if (pPsdScan->nPSDReport_MaxHold[i] > val_max)
3584                                         {
3585                                                 i_max = i;
3586                                                 val_max = pPsdScan->nPSDReport_MaxHold[i];
3587                                         }
3588                                 }
3589
3590                                 //RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), Max_Hold i = %d, PSDReport = %d dB\n", i,  pPsdScan->nPSDReport_MaxHold[i]));
3591
3592                         }
3593         
3594                         pPsdScan->nPSDMaxValuePoint = i_max;
3595                         pPsdScan->nPSDMaxValue = val_max;
3596
3597                         //RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), Max_Hold i_Max = %d, PSDReport_Max = %d dB\n", pPsdScan->nPSDMaxValuePoint
3598                         //              ,pPsdScan->nPSDMaxValue));
3599                 }
3600
3601
3602 }
3603
3604 u4Byte
3605 halbtc8703b1ant_PSD_GetData(
3606         IN      PBTC_COEXIST            pBtCoexist,
3607         IN      u4Byte                          nPoint
3608         )
3609 {
3610         //reg 0x808[9:0]: FFT data x
3611         //reg 0x808[22]: 0-->1 to get 1 FFT data y
3612         //reg 0x8b4[15:0]: FFT data y report
3613
3614         u4Byte val = 0, psd_report =0;
3615         
3616         val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x808);
3617
3618         val &= 0xffbffc00;
3619         val |= nPoint;
3620         
3621          pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x808, val);
3622
3623         val |= 0x00400000;
3624          pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x808, val);
3625
3626
3627         val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x8b4);
3628
3629         psd_report = val & 0x0000ffff;
3630          
3631         return psd_report;
3632 }
3633
3634
3635 VOID
3636 halbtc8703b1ant_PSD_SweepPoint(
3637 IN      PBTC_COEXIST                    pBtCoexist,
3638         IN      u4Byte                          centFreq,
3639         IN      s4Byte                          offset,
3640         IN      u4Byte                          span,
3641         IN      u4Byte                          points,
3642         IN      u4Byte                          avgnum
3643         )
3644 {
3645         u4Byte   i,val,n,k=0;
3646         u4Byte  nPoints=0, psd_report=0;
3647         u4Byte  nStartP=0, nStopP=0, nDeltaFreqPerPoint=156250;
3648         u4Byte    nPSDCenterFreq=20*10^6, freq,freq1,freq2;     
3649         BOOLEAN outloop = FALSE;
3650         u1Byte   flag = 0;      
3651         u4Byte  tmp, PsdRep1, PsdRep2;
3652         u4Byte  WiFi_OriginalChannel = 1;
3653
3654         pPsdScan->bIsPSDRunning = TRUE;
3655         
3656         do
3657         {
3658                 switch(flag)
3659                 {
3660                    case 0:  //Get PSD parameters
3661                    default:     
3662                         //RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), centFreq=0x%x, offset=0x%x, span=0x%x\n", 
3663                        //     centFreq, offset, span));
3664
3665                         pPsdScan->nPSDBandWidth = 40*1000000;
3666                         pPsdScan->nPSDPoint = points;
3667                         pPsdScan->nPSDStartBase = points/2; 
3668                         pPsdScan->nPSDAvgNum = avgnum;
3669                         pPsdScan->nRealCentFreq = centFreq;
3670                         pPsdScan->nRealOffset = offset;
3671                         pPsdScan->nRealSpan = span;
3672                 
3673                         
3674                         nPoints = pPsdScan->nPSDPoint;
3675                         nDeltaFreqPerPoint = pPsdScan->nPSDBandWidth/pPsdScan->nPSDPoint;
3676
3677                         //PSD point setup
3678                         val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x808);
3679                         val &= 0xffff0fff;                              
3680                         
3681                         switch(pPsdScan->nPSDPoint)
3682                         {
3683                                 case 128:
3684                                         val |= 0x0;
3685                                         break;
3686                                 case 256:
3687                                 default:        
3688                                         val |=0x00004000;
3689                                         break;
3690                                 case 512:       
3691                                         val |= 0x00008000;
3692                                         break;
3693                                 case 1024:      
3694                                         val |= 0x0000c000;
3695                                         break;
3696                         }                       
3697                                         
3698                         switch(pPsdScan->nPSDAvgNum)
3699                         {
3700                                 case 1:
3701                                         val |= 0x0;
3702                                         break;
3703                                 case 8:                         
3704                                         val |=0x00001000;
3705                                         break;
3706                                 case 16:        
3707                                         val |= 0x00002000;
3708                                         break;
3709                                 case 32:
3710                                 default:        
3711                                         val |= 0x00003000;
3712                                         break;
3713                         }
3714                          pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x808, val);
3715
3716                         //RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), PSD BW= %d, DeltaFreq=%d\n"
3717                         //      , pPsdScan->nPSDBandWidth, nDeltaFreqPerPoint));
3718                         flag = 1;
3719                         break;
3720                   case 1:         //calculate the PSD point index from freq/offset/span
3721                         nPSDCenterFreq = pPsdScan->nPSDBandWidth /2 +offset*(1000000);
3722                         //RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), PSD Center Freq = %d\n", (centFreq + offset)));
3723                         
3724                         nStartP = pPsdScan->nPSDStartBase + (nPSDCenterFreq - span *(1000000)/2) /nDeltaFreqPerPoint;
3725                         pPsdScan->nPSDStartPoint = nStartP - pPsdScan->nPSDStartBase;
3726                         //RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), Start PSD Poin Matrix Index = %d\n", pPsdScan->nPSDStartPoint));
3727
3728                         nStopP = pPsdScan->nPSDStartBase + (nPSDCenterFreq + span *(1000000)/2) /nDeltaFreqPerPoint;
3729                         pPsdScan->nPSDStopPoint = nStopP - pPsdScan->nPSDStartBase-1;
3730                         //RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), Stop PSD Poin Matrix Index = %d\n",pPsdScan->nPSDStopPoint));
3731
3732                         flag = 2;
3733                         break;
3734                   case 2:  //set RF channel/BW/Mode
3735
3736                         //set 3-wire off
3737                         val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x88c);
3738                         val |= 0x00300000;
3739                          pBtCoexist->fBtcWrite4Byte(pBtCoexist,0x88c,val);
3740
3741                         //CCK off
3742                         val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x800);
3743                         val &= 0xfeffffff;
3744                         pBtCoexist->fBtcWrite4Byte(pBtCoexist,0x800,val);               
3745
3746                         //store WiFi original channel
3747                         WiFi_OriginalChannel = pBtCoexist->fBtcGetRfReg(pBtCoexist, BTC_RF_A, 0x18, 0x3ff);
3748
3749                         //Set RF channel
3750                        if (centFreq == 2484)
3751                                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x18, 0x3ff, 0xe); 
3752                         else
3753                                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x18, 0x3ff, (centFreq-2412)/5 + 1); //WiFi TRx Mask on
3754
3755                         //Set  RF mode = Rx, RF Gain = 0x8a0
3756                         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x0, 0xfffff, 0x308a0);
3757
3758                         //Set RF Rx filter corner
3759                         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff, 0x3e4);
3760
3761                         //Set TRx mask off
3762                         //un-lock TRx Mask setup
3763                         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xdd, 0x80, 0x1);
3764                         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xdf, 0x1, 0x1);
3765
3766                         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
3767
3768                         flag = 3;
3769                         break;
3770                   case 3:
3771                         memset(pPsdScan->nPSDReport,0, pPsdScan->nPSDPoint*sizeof(u4Byte));
3772                         nStartP = pPsdScan->nPSDStartPoint + pPsdScan->nPSDStartBase;
3773                         nStopP = pPsdScan->nPSDStopPoint +  pPsdScan->nPSDStartBase + 1;
3774                                 
3775                         i = nStartP;
3776
3777                         while (i < nStopP)
3778                         {
3779                                 if (i >= nPoints)
3780                                 {
3781                                         psd_report = halbtc8703b1ant_PSD_GetData(pBtCoexist,i-nPoints);
3782                                 }
3783                                 else
3784                                 {
3785                                         psd_report = halbtc8703b1ant_PSD_GetData(pBtCoexist,i);
3786                                 }
3787
3788                                 if (psd_report == 0)
3789                                         tmp = 0;
3790                                 else
3791                                         //tmp =  20*log10((double)psd_report);
3792                                         //20*log2(x)/log2(10), log2Base return theresult of the psd_report*100
3793                                         tmp = 6 * halbtc8703b1ant_PSD_Log2Base(pBtCoexist, psd_report);                         
3794
3795                                 n = i-pPsdScan->nPSDStartBase;
3796                                 pPsdScan->nPSDReport[n] =  tmp;
3797                                 PsdRep1 = pPsdScan->nPSDReport[n] /100;
3798                                 PsdRep2 = pPsdScan->nPSDReport[n] - PsdRep1 * 100;
3799                                 
3800                                 freq =  ((centFreq-20) * 1000000 + n * nDeltaFreqPerPoint);
3801                                 freq1 = freq/1000000;
3802                                 freq2 = freq/1000 - freq1 * 1000;
3803 /*
3804                                 if (freq2 < 100)
3805                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), i = %d (%d.0%d MHz)", n, freq1, freq2));
3806                                 else
3807                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), i = %d (%d.%d MHz)", n, freq1, freq2));
3808
3809                                 if (PsdRep2 < 10)
3810                                         RT_TRACE(COMP_COEX, DBG_LOUD, (", PSDReport = %d (%d.0%d dB)\n",psd_report, PsdRep1, PsdRep2));
3811                                 else
3812                                         RT_TRACE(COMP_COEX, DBG_LOUD, (", PSDReport = %d (%d.%d dB)\n",psd_report, PsdRep1,PsdRep2));   
3813 */
3814                                 i++;
3815
3816                                 k=0;
3817
3818                                 //Add Delay between PSD point
3819                                 while(1)
3820                                 {
3821                                         if (k++ > 20000)
3822                                          break;
3823                                 }
3824
3825                                 //RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint()==============\n"));
3826                         }       
3827
3828                         flag = 100;
3829                         break;
3830                   case 99:      //error
3831
3832                         outloop = TRUE;
3833                         break;
3834                   case 100: //recovery 
3835
3836                         //set 3-wire on
3837                         val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x88c);
3838                         val &=0xffcfffff;
3839                         pBtCoexist->fBtcWrite4Byte(pBtCoexist,0x88c,val);
3840
3841                         //CCK on
3842                         val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x800);
3843                         val |= 0x01000000;
3844                         pBtCoexist->fBtcWrite4Byte(pBtCoexist,0x800,val);       
3845
3846                         //PSD off
3847                         val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x808);
3848                         val &=0xffbfffff;
3849                         pBtCoexist->fBtcWrite4Byte(pBtCoexist,0x808,val);
3850                         
3851                         //TRx Mask on
3852                         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x780);
3853
3854                         //lock TRx Mask setup
3855                         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xdd, 0x80, 0x0);
3856                         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xdf, 0x1, 0x0);
3857
3858                         //Set RF Rx filter corner
3859                         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff, 0x0);
3860
3861                         //restore WiFi original channel
3862                         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x18, 0x3ff, WiFi_OriginalChannel); 
3863                         
3864                         outloop = TRUE;
3865                         break;
3866
3867                 }               
3868                         
3869         }while (!outloop);
3870
3871
3872
3873         pPsdScan->bIsPSDRunning = FALSE;
3874
3875
3876 }
3877
3878 //============================================================
3879 // work around function start with wa_halbtc8703b1ant_
3880 //============================================================
3881 //============================================================
3882 // extern function start with EXhalbtc8703b1ant_
3883 //============================================================
3884 VOID
3885 EXhalbtc8703b1ant_PowerOnSetting(
3886         IN      PBTC_COEXIST            pBtCoexist
3887         )
3888 {
3889         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;
3890         u1Byte u1Tmp=0x0;
3891         u2Byte u2Tmp=0x0;
3892
3893         RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx Execute 8703b 1-Ant PowerOn Setting xxxxxxxxxxxxxxxx!!\n"));
3894
3895         RT_TRACE(COMP_COEX, DBG_LOUD, ("Ant Det Finish = %s, Ant Det Number  = %d\n",  
3896                  (pBoardInfo->btdmAntDetFinish? "Yes":"No"), pBoardInfo->btdmAntNumByAntDet));
3897
3898         pBtCoexist->bStopCoexDm = TRUE;
3899
3900         // enable BB, REG_SYS_FUNC_EN such that we can write 0x948 correctly.
3901         u2Tmp = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x2);
3902         pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x2, u2Tmp|BIT0|BIT1);
3903
3904         //set Path control owner to WiFi
3905         halbtc8703b1ant_LTECoex_PathControlOwner(pBtCoexist, BT_8703B_1ANT_PCO_WLSIDE);
3906
3907         // set GNT_BT to high
3908         halbtc8703b1ant_LTECoex_Set_GNT_BT(pBtCoexist, BT_8703B_1ANT_GNT_BLOCK_RFC_BB, BT_8703B_1ANT_GNT_TYPE_CTRL_BY_SW, BT_8703B_1ANT_SIG_STA_SET_TO_HIGH);
3909         //Set GNT_WL to low
3910         halbtc8703b1ant_LTECoex_Set_GNT_WL(pBtCoexist, BT_8703B_1ANT_GNT_BLOCK_RFC_BB, BT_8703B_1ANT_GNT_TYPE_CTRL_BY_SW, BT_8703B_1ANT_SIG_STA_SET_TO_LOW);
3911
3912         // set WLAN_ACT = 0
3913         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4);     
3914
3915         // 
3916         // S0 or S1 setting and Local register setting(By the setting fw can get ant number, S0/S1, ... info)
3917         // Local setting bit define
3918         //      BIT0: "0" for no antenna inverse; "1" for antenna inverse 
3919         //      BIT1: "0" for internal switch; "1" for external switch
3920         //      BIT2: "0" for one antenna; "1" for two antenna
3921         // NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and BIT2=0
3922
3923         u1Tmp = 0;
3924         pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
3925
3926         if(pBtCoexist->chipInterface == BTC_INTF_USB)
3927         {               
3928                 pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0xfe08, u1Tmp);
3929         }
3930         else if(pBtCoexist->chipInterface == BTC_INTF_SDIO)
3931         {
3932                 pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0x60, u1Tmp);
3933         }
3934
3935         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], **********  LTE coex Reg 0x38 (Power-On) = 0x%x**********\n", halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0x38)));
3936                 
3937
3938 #if 0   
3939         if(pBtCoexist->chipInterface == BTC_INTF_USB)
3940         {
3941                 // fixed at S0 for USB interface
3942                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);
3943
3944                 u1Tmp |= 0x1;   // antenna inverse
3945                 pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0xfe08, u1Tmp);
3946
3947                 pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_AUX_PORT;
3948         }
3949         else
3950         {
3951
3952                 // for PCIE and SDIO interface, we check efuse 0xc3[6]
3953                 if(pBoardInfo->singleAntPath == 0)
3954                 {
3955                         // set to S1
3956                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x280);
3957                         pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
3958                 }
3959                 else if(pBoardInfo->singleAntPath == 1)
3960                 {
3961                         // set to S0
3962                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);
3963                         u1Tmp |= 0x1;   // antenna inverse
3964                         pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_AUX_PORT;
3965                 }
3966
3967
3968
3969                 if(pBtCoexist->chipInterface == BTC_INTF_PCI)
3970                 {       
3971                         pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0x384, u1Tmp);
3972                 }
3973                 else if(pBtCoexist->chipInterface == BTC_INTF_SDIO)
3974                 {
3975                         pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0x60, u1Tmp);
3976                 }       
3977         }
3978
3979 #endif  
3980 }
3981
3982 VOID
3983 EXhalbtc8703b1ant_PreLoadFirmware(
3984         IN      PBTC_COEXIST            pBtCoexist
3985         )
3986 {
3987 }
3988
3989 VOID
3990 EXhalbtc8703b1ant_InitHwConfig(
3991         IN      PBTC_COEXIST            pBtCoexist,
3992         IN      BOOLEAN                         bWifiOnly
3993         )
3994 {
3995         halbtc8703b1ant_InitHwConfig(pBtCoexist, TRUE, bWifiOnly);
3996         pBtCoexist->bStopCoexDm = FALSE;
3997 }
3998
3999 VOID
4000 EXhalbtc8703b1ant_InitCoexDm(
4001         IN      PBTC_COEXIST            pBtCoexist
4002         )
4003 {
4004         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Coex Mechanism Init!!\n"));
4005
4006         pBtCoexist->bStopCoexDm = FALSE;
4007         
4008         halbtc8703b1ant_InitCoexDm(pBtCoexist);
4009
4010         halbtc8703b1ant_QueryBtInfo(pBtCoexist);
4011 }
4012
4013 VOID
4014 EXhalbtc8703b1ant_DisplayCoexInfo(
4015         IN      PBTC_COEXIST            pBtCoexist
4016         )
4017 {
4018         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;
4019         PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;
4020         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;
4021         pu1Byte                         cliBuf=pBtCoexist->cliBuf;
4022         u1Byte                          u1Tmp[4], i, btInfoExt, psTdmaCase=0;
4023         u2Byte                          u2Tmp[4];
4024         u4Byte                          u4Tmp[4];
4025         u4Byte                          faOfdm, faCck;
4026         u4Byte                          fwVer=0, btPatchVer=0;
4027         static u1Byte                   PopReportIn10s = 0;     
4028
4029         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[BT Coexist info]============");
4030         CL_PRINTF(cliBuf);
4031
4032         if(pBtCoexist->bManualControl)
4033         {
4034                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[Under Manual Control]============");
4035                 CL_PRINTF(cliBuf);
4036                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ==========================================");
4037                 CL_PRINTF(cliBuf);
4038         }
4039         if(pBtCoexist->bStopCoexDm)
4040         {
4041                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[Coex is STOPPED]============");
4042                 CL_PRINTF(cliBuf);
4043                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ==========================================");
4044                 CL_PRINTF(cliBuf);
4045         }
4046
4047         if (pPsdScan->bAntDet_TryCount == 0)
4048         {
4049                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d", "Ant PG Num/ Mech/ Pos",
4050                 pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum, pBoardInfo->btdmAntPos);
4051         CL_PRINTF(cliBuf);      
4052         }
4053         else
4054         {
4055                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d  (%d/%d/%d)", "Ant PG Num/ Mech(Ant_Det)/ Pos", 
4056                 pBoardInfo->pgAntNum, pBoardInfo->btdmAntNumByAntDet, pBoardInfo->btdmAntPos, 
4057                 pPsdScan->bAntDet_TryCount, pPsdScan->bAntDet_FailCount, pPsdScan->nAntDet_Result);             
4058                 CL_PRINTF(cliBuf);
4059
4060                 if (pBoardInfo->btdmAntDetFinish)
4061                 {
4062                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "Ant Det PSD Value",  pPsdScan->nAntDet_PeakVal);                
4063                         CL_PRINTF(cliBuf);
4064                 }
4065         }
4066         
4067         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d", "BT stack/ hci ext ver", \
4068                 ((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion);
4069         CL_PRINTF(cliBuf);
4070
4071         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);
4072         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);
4073         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)", "CoexVer/ FwVer/ PatchVer", \
4074                 GLCoexVerDate8703b1Ant, GLCoexVer8703b1Ant, fwVer, btPatchVer, btPatchVer);
4075         CL_PRINTF(cliBuf);
4076
4077         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", "Wifi channel informed to BT", \
4078                 pCoexDm->wifiChnlInfo[0], pCoexDm->wifiChnlInfo[1],
4079                 pCoexDm->wifiChnlInfo[2]);
4080         CL_PRINTF(cliBuf);
4081         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s", "WifibHiPri/ Ccklock/ CckEverLock", \
4082                 (pCoexSta->bWiFiIsHighPriTask? "Yes":"No"),
4083                 (pCoexSta->bCCKLock? "Yes":"No"),
4084                 (pCoexSta->bCCKEverLock? "Yes":"No"));
4085         CL_PRINTF(cliBuf);
4086
4087         // wifi status
4088         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Wifi Status]============");
4089         CL_PRINTF(cliBuf);
4090         pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_WIFI_STATUS);
4091
4092         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[BT Status]============");
4093         CL_PRINTF(cliBuf);
4094         
4095         PopReportIn10s++;
4096         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d/ %d] ", "BT [status/ rssi/ retryCnt/ popCnt]", \
4097                 ((pBtCoexist->btInfo.bBtDisabled)? ("disabled"):        ((pCoexSta->bC2hBtInquiryPage)?("inquiry/page scan"):((BT_8703B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)? "non-connected idle":
4098                 (  (BT_8703B_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus)? "connected-idle":"busy")))),
4099                 pCoexSta->btRssi, pCoexSta->btRetryCnt, pCoexSta->popEventCnt);
4100         CL_PRINTF(cliBuf);
4101         
4102         if (PopReportIn10s >= 5)
4103         {
4104                 pCoexSta->popEventCnt = 0;      
4105                 PopReportIn10s = 0;
4106         }
4107         
4108         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d / %d", "SCO/HID/PAN/A2DP/Hi-Pri", \
4109                 pBtLinkInfo->bScoExist, pBtLinkInfo->bHidExist, pBtLinkInfo->bPanExist, pBtLinkInfo->bA2dpExist, pBtLinkInfo->bBtHiPriLinkExist);
4110         CL_PRINTF(cliBuf);
4111
4112         if (pStackInfo->bProfileNotified)
4113         {
4114                 pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_BT_LINK_INFO);      
4115         }
4116         else
4117         {
4118                 btInfoExt = pCoexSta->btInfoExt;
4119                 
4120                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s", "BT Role/A2DP rate", \
4121                 (pBtLinkInfo->bSlaveRole )? "Slave":"Master", (btInfoExt&BIT0)? "BR":"EDR");
4122                 CL_PRINTF(cliBuf);      
4123         }       
4124
4125
4126         for(i=0; i<BT_INFO_SRC_8703B_1ANT_MAX; i++)
4127         {
4128                 if(pCoexSta->btInfoC2hCnt[i])
4129                 {                               
4130                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", GLBtInfoSrc8703b1Ant[i], \
4131                                 pCoexSta->btInfoC2h[i][0], pCoexSta->btInfoC2h[i][1],
4132                                 pCoexSta->btInfoC2h[i][2], pCoexSta->btInfoC2h[i][3],
4133                                 pCoexSta->btInfoC2h[i][4], pCoexSta->btInfoC2h[i][5],
4134                                 pCoexSta->btInfoC2h[i][6], pCoexSta->btInfoC2hCnt[i]);
4135                         CL_PRINTF(cliBuf);
4136                 }
4137         }
4138
4139         
4140         if(pBtCoexist->bManualControl)
4141         {                       
4142                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw mechanism] (before Manual)============");                    
4143         }
4144         else
4145         {
4146                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw mechanism]============");
4147         }       
4148
4149                 CL_PRINTF(cliBuf);
4150         
4151                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ 0x%x", "SM[LowPenaltyRA]/RA Mask", \
4152                         pCoexDm->bCurLowPenaltyRa, pBtCoexist->btInfo.raMask);
4153                 CL_PRINTF(cliBuf);
4154
4155                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %d ", "NoAggr/ CtrlAggr/ AggrSize", \
4156                         (pBtCoexist->btInfo.bRejectAggPkt? "Yes":"No"), (pBtCoexist->btInfo.bBtCtrlAggBufSize? "Yes":"No"),
4157                                 pBtCoexist->btInfo.aggBufSize);
4158                 CL_PRINTF(cliBuf);
4159                 
4160                 // Fw mechanism         
4161                 if(pBtCoexist->bManualControl)
4162                 {
4163                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw mechanism] (before Manual) ============");                   
4164                 }
4165                 else
4166                 {
4167                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw mechanism]============");
4168                 }
4169                 
4170                 CL_PRINTF(cliBuf);      
4171
4172                 psTdmaCase = pCoexDm->curPsTdma;
4173                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (%s,%s)", "PS TDMA", \
4174                         pCoexDm->psTdmaPara[0], pCoexDm->psTdmaPara[1],
4175                         pCoexDm->psTdmaPara[2], pCoexDm->psTdmaPara[3],
4176                         pCoexDm->psTdmaPara[4], psTdmaCase, 
4177                         (pCoexDm->bCurPsTdmaOn? "On":"Off"),
4178                         (pCoexDm->bAutoTdmaAdjust? "Adj":"Fix") );
4179                 
4180                 CL_PRINTF(cliBuf);
4181                 
4182                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "WL/BT Coex Table Type", \
4183                         pCoexSta->nCoexTableType);
4184                 CL_PRINTF(cliBuf);
4185
4186                 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c0);
4187                 u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c4);
4188                 u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c8);
4189                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x6c0/0x6c4/0x6c8(coexTable)", \
4190                                         u4Tmp[0], u4Tmp[1], u4Tmp[2]);
4191                 CL_PRINTF(cliBuf);
4192
4193                 u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x778);
4194                 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6cc);
4195                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x778/0x6cc/IgnWlanAct", \
4196                 u1Tmp[0], u4Tmp[0],  pCoexDm->bCurIgnoreWlanAct);
4197                 CL_PRINTF(cliBuf);
4198
4199                 u4Tmp[0] = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0xa0);
4200                 u4Tmp[1] = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0xa4);
4201
4202                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "LTE Coex Table W_L/B_L", \
4203                         u4Tmp[0]&0xffff, u4Tmp[1]&0xffff);
4204                 CL_PRINTF(cliBuf);
4205
4206                 u4Tmp[0] = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0xa8);
4207                 u4Tmp[1] = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0xac);
4208                 u4Tmp[2] = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0xb0);
4209                 u4Tmp[3] = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0xb4);
4210
4211                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "LTE Break Table W_L/B_L/L_W/L_B", \
4212                         u4Tmp[0]&0xffff, u4Tmp[1]&0xffff, u4Tmp[2]&0xffff, u4Tmp[3]&0xffff);
4213                 CL_PRINTF(cliBuf);
4214                                 
4215                 // Hw setting           
4216                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Hw setting]============");
4217                 CL_PRINTF(cliBuf);
4218         
4219
4220         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x430);
4221         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x434);
4222         u2Tmp[0] = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x42a);
4223         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x456);
4224         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", "0x430/0x434/0x42a/0x456", \
4225                 u4Tmp[0], u4Tmp[1], u2Tmp[0], u1Tmp[0]);
4226         CL_PRINTF(cliBuf);
4227
4228
4229         u4Tmp[0] = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0x38);
4230         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x73);
4231
4232         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %s", "LTE CoexOn/Path Ctrl Owner", \
4233          ((u4Tmp[0]&BIT7)>> 7), ((u1Tmp[0]&BIT2)? "WL":"BT"));
4234         CL_PRINTF(cliBuf);
4235
4236         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", "LTE 3Wire/OPMode/UART/UARTMode", \
4237          ((u4Tmp[0]&BIT6)>> 6), ((u4Tmp[0]&(BIT5|BIT4))>> 4),((u4Tmp[0]&BIT3)>> 3), (u4Tmp[0]&(BIT2|BIT1|BIT0)));
4238         CL_PRINTF(cliBuf);
4239
4240         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %s", "GNT_WL_SWCtrl/GNT_BT_SWCtrl/Dbg", \
4241          ((u4Tmp[0]&BIT12)>> 12), ((u4Tmp[0]&BIT14)>> 14), ((u1Tmp[0]&BIT3)? "On":"Off"));
4242         CL_PRINTF(cliBuf);
4243         
4244         u4Tmp[0] = halbtc8703b1ant_LTECoex_InDirectReadReg(pBtCoexist, 0x54);
4245
4246         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", "GNT_WL/GNT_BT/LTE_Busy/UART_Busy", \
4247                 ((u4Tmp[0]&BIT2)>> 2), ((u4Tmp[0]&BIT3)>> 3),  ((u4Tmp[0]&BIT1)>> 1),  (u4Tmp[0]&BIT0));
4248         CL_PRINTF(cliBuf);
4249
4250
4251         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x4c6);
4252         u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x40);
4253
4254         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0x4c6[4]/0x40[5] (WL/BT PTA)", \
4255                 ((u1Tmp[0] & BIT4)>>4), ((u1Tmp[1] & BIT5)>>5));
4256         CL_PRINTF(cliBuf);
4257
4258         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x550);
4259         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x522);
4260         u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x953);
4261         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ %s", "0x550(bcn ctrl)/0x522/4-RxAGC", \
4262                 u4Tmp[0], u1Tmp[0], (u1Tmp[1]&0x2)? "On": "Off");
4263         CL_PRINTF(cliBuf);
4264
4265         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda0);
4266         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda4);
4267         u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda8);
4268         u4Tmp[3] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xcf0);
4269
4270         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xa5b);
4271         u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xa5c);
4272
4273         faOfdm = ((u4Tmp[0]&0xffff0000) >> 16) +  ((u4Tmp[1]&0xffff0000) >> 16) + (u4Tmp[1] & 0xffff) +  (u4Tmp[2] & 0xffff) + \
4274                              ((u4Tmp[3]&0xffff0000) >> 16) + (u4Tmp[3] & 0xffff) ;
4275         faCck = (u1Tmp[0] << 8) + u1Tmp[1];
4276
4277         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xc50);
4278         
4279         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0xc50/OFDM-CCA/OFDM-FA/CCK-FA", \
4280                 u4Tmp[1]&0xff, u4Tmp[0]&0xffff, faOfdm, faCck);
4281         CL_PRINTF(cliBuf);
4282
4283
4284         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", "CRC_OK CCK/11g/11n/11n-Agg", \
4285                 pCoexSta->nCRCOK_CCK, pCoexSta->nCRCOK_11g, pCoexSta->nCRCOK_11n, pCoexSta->nCRCOK_11nAgg);
4286         CL_PRINTF(cliBuf);
4287
4288         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", "CRC_Err CCK/11g/11n/11n-Agg", \
4289                 pCoexSta->nCRCErr_CCK, pCoexSta->nCRCErr_11g, pCoexSta->nCRCErr_11n, pCoexSta->nCRCErr_11nAgg);
4290         CL_PRINTF(cliBuf);      
4291
4292         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x770(high-pri rx/tx)", \
4293                 pCoexSta->highPriorityRx, pCoexSta->highPriorityTx);
4294         CL_PRINTF(cliBuf);
4295         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x774(low-pri rx/tx)", \
4296                 pCoexSta->lowPriorityRx, pCoexSta->lowPriorityTx);
4297         CL_PRINTF(cliBuf);
4298
4299         halbtc8703b1ant_ReadScoreBoard(pBtCoexist,      &u2Tmp[0]);
4300         
4301         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %04x", "ScoreBoard[14:0] (from BT)", u2Tmp[0]);
4302         CL_PRINTF(cliBuf);
4303
4304 #if(BT_AUTO_REPORT_ONLY_8703B_1ANT == 1)
4305         //halbtc8703b1ant_MonitorBtCtr(pBtCoexist);
4306 #endif
4307         pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_COEX_STATISTICS);
4308 }
4309
4310
4311 VOID
4312 EXhalbtc8703b1ant_IpsNotify(
4313         IN      PBTC_COEXIST            pBtCoexist,
4314         IN      u1Byte                  type
4315         )
4316 {
4317         u4Byte  u4Tmp=0;
4318
4319         if(pBtCoexist->bManualControl ||        pBtCoexist->bStopCoexDm)
4320                 return;
4321
4322         if(BTC_IPS_ENTER == type)
4323         {
4324                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], IPS ENTER notify\n"));
4325                 pCoexSta->bUnderIps = TRUE;
4326                 
4327                 //Write WL "Active" in Score-board for LPS off
4328                 halbtc8703b1ant_PostActiveStateToBT(pBtCoexist, FALSE);
4329                 
4330                 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);
4331                 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FORCE_EXEC, FALSE, TRUE);
4332                 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);  
4333         }
4334         else if(BTC_IPS_LEAVE == type)
4335         {
4336                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], IPS LEAVE notify\n"));
4337                 halbtc8703b1ant_PostActiveStateToBT(pBtCoexist, TRUE);
4338
4339                 halbtc8703b1ant_InitHwConfig(pBtCoexist, FALSE, FALSE);
4340                 halbtc8703b1ant_InitCoexDm(pBtCoexist);
4341                 halbtc8703b1ant_QueryBtInfo(pBtCoexist);
4342
4343                 pCoexSta->bUnderIps = FALSE;
4344         }
4345 }
4346
4347 VOID
4348 EXhalbtc8703b1ant_LpsNotify(
4349         IN      PBTC_COEXIST            pBtCoexist,
4350         IN      u1Byte                  type
4351         )
4352 {
4353         if(pBtCoexist->bManualControl || pBtCoexist->bStopCoexDm)
4354                 return;
4355
4356         if(BTC_LPS_ENABLE == type)
4357         {
4358                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], LPS ENABLE notify\n"));
4359                 pCoexSta->bUnderLps = TRUE;
4360
4361                 if (pCoexSta->bForceLpsOn == TRUE)  // LPS No-32K
4362                 {
4363                         //Write WL "Active" in Score-board for PS-TDMA
4364                         halbtc8703b1ant_PostActiveStateToBT(pBtCoexist, TRUE);
4365         
4366                 }
4367                 else   //  LPS-32K, need check if this h2c 0x71 can work?? (2015/08/28)
4368                 {
4369                         //Write WL "Non-Active" in Score-board for Native-PS
4370                         halbtc8703b1ant_PostActiveStateToBT(pBtCoexist, FALSE);
4371
4372                 }
4373         }
4374         else if(BTC_LPS_DISABLE == type)
4375         {
4376                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], LPS DISABLE notify\n"));
4377                 pCoexSta->bUnderLps = FALSE;
4378
4379                 
4380                 //Write WL "Active" in Score-board for LPS off
4381                 halbtc8703b1ant_PostActiveStateToBT(pBtCoexist, TRUE);
4382                 
4383         }
4384 }
4385
4386 VOID
4387 EXhalbtc8703b1ant_ScanNotify(
4388         IN      PBTC_COEXIST            pBtCoexist,
4389         IN      u1Byte                  type
4390         )
4391 {
4392         BOOLEAN bWifiConnected=FALSE, bBtHsOn=FALSE;    
4393         u4Byte  wifiLinkStatus=0;
4394         u4Byte  numOfWifiLink=0;
4395         BOOLEAN bBtCtrlAggBufSize=FALSE;
4396         u1Byte  aggBufSize=5;
4397
4398         u1Byte u1Tmpa, u1Tmpb;
4399         u4Byte u4Tmp;
4400
4401         if(pBtCoexist->bManualControl ||
4402                 pBtCoexist->bStopCoexDm )
4403                 return;
4404
4405         if(BTC_SCAN_START == type)
4406         {
4407                 pCoexSta->bWiFiIsHighPriTask = TRUE;
4408                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN START notify\n"));
4409                 halbtc8703b1ant_PostActiveStateToBT(pBtCoexist, TRUE);
4410                 halbtc8703b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);  //Force antenna setup for no scan result issue
4411                 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, FORCE_EXEC, FALSE, FALSE);             
4412         }
4413         else
4414         {
4415                 pCoexSta->bWiFiIsHighPriTask = FALSE;   
4416                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN FINISH notify\n"));
4417
4418                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_AP_NUM, &pCoexSta->nScanAPNum);              
4419         }
4420
4421         if(pBtCoexist->btInfo.bBtDisabled)
4422                 return;
4423
4424         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
4425         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
4426
4427         halbtc8703b1ant_QueryBtInfo(pBtCoexist);
4428         
4429         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);
4430         numOfWifiLink = wifiLinkStatus>>16;
4431         if(numOfWifiLink >= 2)
4432         {
4433                 halbtc8703b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);
4434                 halbtc8703b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, bBtCtrlAggBufSize, aggBufSize);
4435                 halbtc8703b1ant_ActionWifiMultiPort(pBtCoexist);
4436                 return;
4437         }
4438         
4439         if(pCoexSta->bC2hBtInquiryPage)
4440         {
4441                 halbtc8703b1ant_ActionBtInquiry(pBtCoexist);
4442                 return;
4443         }
4444         else if(bBtHsOn)
4445         {
4446                 halbtc8703b1ant_ActionHs(pBtCoexist);
4447                 return;
4448         }
4449
4450         if(BTC_SCAN_START == type)
4451         {       
4452                 //RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN START notify\n"));
4453                 if(!bWifiConnected)     // non-connected scan
4454                 {
4455                         halbtc8703b1ant_ActionWifiNotConnectedScan(pBtCoexist);
4456                 }
4457                 else    // wifi is connected
4458                 {
4459                         halbtc8703b1ant_ActionWifiConnectedScan(pBtCoexist);
4460                 }
4461         }
4462         else if(BTC_SCAN_FINISH == type)
4463         {
4464                 //RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN FINISH notify\n"));
4465                 if(!bWifiConnected)     // non-connected scan
4466                 {
4467                         halbtc8703b1ant_ActionWifiNotConnected(pBtCoexist);
4468                 }
4469                 else
4470                 {
4471                         halbtc8703b1ant_ActionWifiConnected(pBtCoexist);
4472                 }
4473         }
4474 }
4475
4476 VOID
4477 EXhalbtc8703b1ant_ConnectNotify(
4478         IN      PBTC_COEXIST            pBtCoexist,
4479         IN      u1Byte                  type
4480         )
4481 {
4482         BOOLEAN bWifiConnected=FALSE, bBtHsOn=FALSE;    
4483         u4Byte  wifiLinkStatus=0;
4484         u4Byte  numOfWifiLink=0;
4485         BOOLEAN bBtCtrlAggBufSize=FALSE;
4486         u1Byte  aggBufSize=5;
4487
4488         if(pBtCoexist->bManualControl ||
4489                 pBtCoexist->bStopCoexDm ||
4490                 pBtCoexist->btInfo.bBtDisabled )
4491                 return;
4492
4493         if(BTC_ASSOCIATE_START == type)
4494         {
4495                 pCoexSta->bWiFiIsHighPriTask = TRUE;
4496                 halbtc8703b1ant_PostActiveStateToBT(pBtCoexist, TRUE);
4497                 halbtc8703b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);  //Force antenna setup for no scan result issue
4498                 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, FORCE_EXEC, FALSE, FALSE);
4499                  RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT START notify\n"));   
4500                  pCoexDm->nArpCnt = 0;
4501         }
4502         else
4503         {
4504                 pCoexSta->bWiFiIsHighPriTask = FALSE;   
4505                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT FINISH notify\n"));   
4506                 //pCoexDm->nArpCnt = 0;
4507         }
4508
4509         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);
4510         numOfWifiLink = wifiLinkStatus>>16;
4511         if(numOfWifiLink >= 2)
4512         {
4513                 halbtc8703b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);
4514                 halbtc8703b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, bBtCtrlAggBufSize, aggBufSize);
4515                 halbtc8703b1ant_ActionWifiMultiPort(pBtCoexist);
4516                 return;
4517         }
4518
4519         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
4520         if(pCoexSta->bC2hBtInquiryPage)
4521         {
4522                 halbtc8703b1ant_ActionBtInquiry(pBtCoexist);
4523                 return;
4524         }
4525         else if(bBtHsOn)
4526         {
4527                 halbtc8703b1ant_ActionHs(pBtCoexist);
4528                 return;
4529         }
4530
4531         if(BTC_ASSOCIATE_START == type)
4532         {
4533                 //RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT START notify\n"));          
4534                 halbtc8703b1ant_ActionWifiNotConnectedAssoAuth(pBtCoexist);
4535         }
4536         else if(BTC_ASSOCIATE_FINISH == type)
4537         {
4538                 //RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT FINISH notify\n"));
4539                 
4540                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
4541                 if(!bWifiConnected) // non-connected scan
4542                 {
4543                         halbtc8703b1ant_ActionWifiNotConnected(pBtCoexist);
4544                 }
4545                 else
4546                 {
4547                         halbtc8703b1ant_ActionWifiConnected(pBtCoexist);
4548                 }
4549         }
4550 }
4551
4552 VOID
4553 EXhalbtc8703b1ant_MediaStatusNotify(
4554         IN      PBTC_COEXIST                    pBtCoexist,
4555         IN      u1Byte                          type
4556         )
4557 {
4558         u1Byte                  H2C_Parameter[3] ={0};
4559         u4Byte                  wifiBw;
4560         u1Byte                  wifiCentralChnl;
4561         BOOLEAN                 bWifiUnderBMode = FALSE;
4562
4563         if(pBtCoexist->bManualControl ||
4564                 pBtCoexist->bStopCoexDm ||
4565                 pBtCoexist->btInfo.bBtDisabled )
4566                 return;
4567
4568         if(BTC_MEDIA_CONNECT == type)
4569         {
4570                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], MEDIA connect notify\n"));
4571                 halbtc8703b1ant_PostActiveStateToBT(pBtCoexist, TRUE);
4572                 halbtc8703b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);  //Force antenna setup for no scan result issue
4573                 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, FORCE_EXEC, FALSE, FALSE);
4574                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode);
4575
4576                 //Set CCK Tx/Rx high Pri except 11b mode
4577                 if (bWifiUnderBMode)
4578                 {
4579                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cd, 0x00); //CCK Tx
4580                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cf, 0x00); //CCK Rx
4581                 }
4582                 else
4583                 {
4584                         //pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cd, 0x10); //CCK Tx
4585                         //pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cf, 0x10); //CCK Rx
4586                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cd, 0x00); //CCK Tx
4587                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cf, 0x10); //CCK Rx
4588                 }
4589                 
4590                 pCoexDm->backupArfrCnt1 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x430);
4591                 pCoexDm->backupArfrCnt2 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x434);
4592                 pCoexDm->backupRetryLimit = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x42a);
4593                 pCoexDm->backupAmpduMaxTime = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x456);
4594         }
4595         else
4596         {
4597                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], MEDIA disconnect notify\n"));
4598                 halbtc8703b1ant_PostActiveStateToBT(pBtCoexist, FALSE);
4599                 pCoexDm->nArpCnt = 0;
4600
4601                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cd, 0x0); //CCK Tx
4602                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cf, 0x0); //CCK Rx
4603
4604                 pCoexSta->bCCKEverLock = FALSE;
4605         }
4606
4607         halbtc8703b1ant_UpdateWifiChannelInfo(pBtCoexist, type);        
4608         
4609 }
4610
4611 VOID
4612 EXhalbtc8703b1ant_SpecialPacketNotify(
4613         IN      PBTC_COEXIST                    pBtCoexist,
4614         IN      u1Byte                          type
4615         )
4616 {
4617         BOOLEAN bBtHsOn=FALSE;
4618         u4Byte  wifiLinkStatus=0;
4619         u4Byte  numOfWifiLink=0;
4620         BOOLEAN bBtCtrlAggBufSize=FALSE, bUnder4way=FALSE;
4621         u1Byte  aggBufSize=5;
4622         
4623         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way);
4624
4625         if(pBtCoexist->bManualControl ||
4626                 pBtCoexist->bStopCoexDm ||
4627                 pBtCoexist->btInfo.bBtDisabled )
4628                 return;
4629
4630         if( BTC_PACKET_DHCP == type || 
4631                 BTC_PACKET_EAPOL == type ||
4632                 BTC_PACKET_ARP == type )
4633         {
4634                 halbtc8703b1ant_PostActiveStateToBT(pBtCoexist, TRUE);
4635                 
4636                 if (BTC_PACKET_ARP == type)
4637                 {
4638                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], special Packet ARP notify\n"));                
4639
4640                         pCoexDm->nArpCnt++;
4641                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ARP Packet Count = %d\n", pCoexDm->nArpCnt));
4642                         
4643                         if((pCoexDm->nArpCnt >= 10) && (!bUnder4way)) // if APR PKT > 10 after connect, do not go to ActionWifiConnectedSpecialPacket(pBtCoexist) 
4644                         {
4645                                 pCoexSta->bWiFiIsHighPriTask = FALSE;                                   
4646                         }                       
4647                         else
4648                         {
4649                                 pCoexSta->bWiFiIsHighPriTask = TRUE;
4650                         }
4651                 }
4652                 else
4653                 {
4654                         pCoexSta->bWiFiIsHighPriTask = TRUE;
4655                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], special Packet DHCP or EAPOL notify\n"));              
4656                 }
4657         } 
4658         else
4659         {
4660                 pCoexSta->bWiFiIsHighPriTask = FALSE;
4661                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], special Packet [Type = %d] notify\n", type));
4662         }
4663
4664         pCoexSta->specialPktPeriodCnt = 0;
4665
4666         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);
4667         numOfWifiLink = wifiLinkStatus>>16;
4668         if(numOfWifiLink >= 2)
4669         {
4670                 halbtc8703b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);
4671                 halbtc8703b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, bBtCtrlAggBufSize, aggBufSize);
4672                 halbtc8703b1ant_ActionWifiMultiPort(pBtCoexist);
4673                 return;
4674         }
4675
4676         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
4677         if(pCoexSta->bC2hBtInquiryPage)
4678         {
4679                 halbtc8703b1ant_ActionBtInquiry(pBtCoexist);
4680                 return;
4681         }
4682         else if(bBtHsOn)
4683         {
4684                 halbtc8703b1ant_ActionHs(pBtCoexist);
4685                 return;
4686         }
4687
4688         if( BTC_PACKET_DHCP == type ||
4689                 BTC_PACKET_EAPOL == type || 
4690                 ( (BTC_PACKET_ARP == type ) && (pCoexSta->bWiFiIsHighPriTask) ) )
4691                 {
4692                 halbtc8703b1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);
4693         }
4694 }
4695
4696 VOID
4697 EXhalbtc8703b1ant_BtInfoNotify(
4698         IN      PBTC_COEXIST            pBtCoexist,
4699         IN      pu1Byte                 tmpBuf,
4700         IN      u1Byte                  length
4701         )
4702 {
4703         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;
4704         u1Byte                          btInfo=0;
4705         u1Byte                          i, rspSource=0;
4706         BOOLEAN                         bWifiConnected=FALSE;
4707         BOOLEAN                         bBtBusy=FALSE;
4708         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;
4709         
4710         pCoexSta->bC2hBtInfoReqSent = FALSE;
4711
4712         rspSource = tmpBuf[0]&0xf;
4713         if(rspSource >= BT_INFO_SRC_8703B_1ANT_MAX)
4714                 rspSource = BT_INFO_SRC_8703B_1ANT_WIFI_FW;
4715         pCoexSta->btInfoC2hCnt[rspSource]++;
4716
4717         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Bt info[%d], length=%d, hex data=[", rspSource, length));
4718         for(i=0; i<length; i++)
4719         {
4720                 pCoexSta->btInfoC2h[rspSource][i] = tmpBuf[i];
4721                 if(i == 1)
4722                         btInfo = tmpBuf[i];
4723                 if(i == length-1)
4724                 {
4725                         RT_TRACE(COMP_COEX, DBG_LOUD, ("0x%02x]\n", tmpBuf[i]));
4726                 }
4727                 else
4728                 {
4729                         RT_TRACE(COMP_COEX, DBG_LOUD, ("0x%02x, ", tmpBuf[i]));
4730                 }
4731         }
4732
4733         // if 0xff, it means BT is under WHCK test
4734         if (btInfo == 0xff)
4735                 pCoexSta->bBtWhckTest = TRUE;
4736         else
4737                 pCoexSta->bBtWhckTest = FALSE;
4738
4739         if(BT_INFO_SRC_8703B_1ANT_WIFI_FW != rspSource)
4740         {
4741                 pCoexSta->btRetryCnt =  // [3:0]
4742                         pCoexSta->btInfoC2h[rspSource][2]&0xf;
4743
4744                 if (pCoexSta->btRetryCnt >= 1)
4745                         pCoexSta->popEventCnt++;
4746
4747                 if (pCoexSta->btInfoC2h[rspSource][2]&0x20)
4748                         pCoexSta->bC2hBtPage = TRUE;
4749                 else
4750                         pCoexSta->bC2hBtPage = FALSE;                   
4751
4752                 pCoexSta->btRssi =
4753                         pCoexSta->btInfoC2h[rspSource][3]*2-90;
4754                         //pCoexSta->btInfoC2h[rspSource][3]*2+10;
4755
4756                 pCoexSta->btInfoExt = 
4757                         pCoexSta->btInfoC2h[rspSource][4];
4758                 
4759                 pCoexSta->bBtTxRxMask = (pCoexSta->btInfoC2h[rspSource][2]&0x40);
4760                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TX_RX_MASK, &pCoexSta->bBtTxRxMask);
4761
4762                                 
4763                 // Here we need to resend some wifi info to BT
4764                 // because bt is reset and loss of the info.
4765                 if(pCoexSta->btInfoExt & BIT1)
4766                 {                       
4767                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"));
4768                         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
4769                         if(bWifiConnected)
4770                         {
4771                                 halbtc8703b1ant_UpdateWifiChannelInfo(pBtCoexist, BTC_MEDIA_CONNECT);                           
4772                         }
4773                         else
4774                         {
4775                                 halbtc8703b1ant_UpdateWifiChannelInfo(pBtCoexist, BTC_MEDIA_DISCONNECT);                                        
4776                         }
4777                 }
4778                                 
4779                 if(pCoexSta->btInfoExt & BIT3)
4780                 {
4781                         if(!pBtCoexist->bManualControl && !pBtCoexist->bStopCoexDm)
4782                         {
4783                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n"));
4784                                 halbtc8703b1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, FALSE);
4785                         }
4786                 }
4787                 else
4788                 {
4789                         // BT already NOT ignore Wlan active, do nothing here.
4790                 }
4791 #if(BT_AUTO_REPORT_ONLY_8703B_1ANT == 0)
4792                 if( (pCoexSta->btInfoExt & BIT4) )
4793                 {
4794                         // BT auto report already enabled, do nothing
4795                 }
4796                 else
4797                 {
4798                         halbtc8703b1ant_BtAutoReport(pBtCoexist, FORCE_EXEC, TRUE);
4799                 }
4800 #endif
4801         }
4802                 
4803         // check BIT2 first ==> check if bt is under inquiry or page scan
4804         if(btInfo & BT_INFO_8703B_1ANT_B_INQ_PAGE)
4805                 pCoexSta->bC2hBtInquiryPage = TRUE;
4806         else
4807                 pCoexSta->bC2hBtInquiryPage = FALSE;
4808
4809         pCoexSta->nNumOfProfile = 0;
4810
4811         // set link exist status
4812         if(!(btInfo&BT_INFO_8703B_1ANT_B_CONNECTION))
4813         {
4814                 pCoexSta->bBtLinkExist = FALSE;
4815                 pCoexSta->bPanExist = FALSE;
4816                 pCoexSta->bA2dpExist = FALSE;
4817                 pCoexSta->bHidExist = FALSE;
4818                 pCoexSta->bScoExist = FALSE;
4819
4820                 pCoexSta->bBtHiPriLinkExist = FALSE;            
4821         }
4822         else    // connection exists
4823         {               
4824                 pCoexSta->bBtLinkExist = TRUE;
4825                 if(btInfo & BT_INFO_8703B_1ANT_B_FTP)
4826                 {
4827                         pCoexSta->bPanExist = TRUE;
4828                         pCoexSta->nNumOfProfile++;
4829                 }
4830                 else
4831                         pCoexSta->bPanExist = FALSE;
4832                 if(btInfo & BT_INFO_8703B_1ANT_B_A2DP)
4833                 {
4834                         pCoexSta->bA2dpExist = TRUE;
4835                         pCoexSta->nNumOfProfile++;
4836                 }
4837                 else
4838                         pCoexSta->bA2dpExist = FALSE;
4839                 if(btInfo & BT_INFO_8703B_1ANT_B_HID)
4840                 {
4841                         pCoexSta->bHidExist = TRUE;
4842                         pCoexSta->nNumOfProfile++;
4843                 }
4844                 else
4845                         pCoexSta->bHidExist = FALSE;
4846                 if(btInfo & BT_INFO_8703B_1ANT_B_SCO_ESCO)
4847                 {
4848                         pCoexSta->bScoExist = TRUE;
4849                         pCoexSta->nNumOfProfile++;
4850                 }
4851                 else
4852                         pCoexSta->bScoExist = FALSE;
4853
4854                 if ((pCoexSta->bHidExist == FALSE) && (pCoexSta->bC2hBtInquiryPage == FALSE) &&( pCoexSta->bScoExist == FALSE))
4855                 {
4856                         if (pCoexSta->highPriorityTx  + pCoexSta->highPriorityRx >= 160)                
4857                         {
4858                                 pCoexSta->bHidExist = TRUE;
4859                                 pCoexSta->wrongProfileNotification++;
4860                                 pCoexSta->nNumOfProfile++;
4861                                 btInfo = btInfo | 0x28;
4862                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT HID = true (Hi-Pri > 160)!\n"));
4863                         }
4864                 }
4865
4866                 //Add Hi-Pri Tx/Rx counter to avoid false detection
4867                 if (((pCoexSta->bHidExist) || (pCoexSta->bScoExist)) && (pCoexSta->highPriorityTx + pCoexSta->highPriorityRx >= 160)
4868                          && (!pCoexSta->bC2hBtInquiryPage))
4869                         pCoexSta->bBtHiPriLinkExist = TRUE;
4870                 else
4871                         pCoexSta->bBtHiPriLinkExist = FALSE;
4872                         
4873                 if((btInfo&BT_INFO_8703B_1ANT_B_ACL_BUSY) && (pCoexSta->nNumOfProfile == 0))
4874                 {
4875                         if (pCoexSta->lowPriorityTx + pCoexSta->lowPriorityRx >= 160)
4876                         {
4877                                 pCoexSta->bPanExist = TRUE;
4878                                 pCoexSta->nNumOfProfile++;
4879                                 pCoexSta->wrongProfileNotification++;
4880                                 btInfo = btInfo | 0x88;                         
4881                         }
4882                 }
4883         }
4884
4885         halbtc8703b1ant_UpdateBtLinkInfo(pBtCoexist);
4886         
4887         btInfo = btInfo & 0x1f;  //mask profile bit for connect-ilde identification ( for CSR case: A2DP idle --> 0x41)
4888         
4889         if(!(btInfo&BT_INFO_8703B_1ANT_B_CONNECTION))
4890         {
4891                 pCoexDm->btStatus = BT_8703B_1ANT_BT_STATUS_NON_CONNECTED_IDLE;
4892                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n"));
4893         }
4894         else if(btInfo == BT_INFO_8703B_1ANT_B_CONNECTION)      // connection exists but no busy
4895         {
4896                 pCoexDm->btStatus = BT_8703B_1ANT_BT_STATUS_CONNECTED_IDLE;
4897                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n"));
4898         }
4899         else if((btInfo&BT_INFO_8703B_1ANT_B_SCO_ESCO) ||
4900                 (btInfo&BT_INFO_8703B_1ANT_B_SCO_BUSY))
4901         {
4902                 pCoexDm->btStatus = BT_8703B_1ANT_BT_STATUS_SCO_BUSY;
4903                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT SCO busy!!!\n"));
4904         }
4905         else if(btInfo&BT_INFO_8703B_1ANT_B_ACL_BUSY)
4906         {
4907                 if(BT_8703B_1ANT_BT_STATUS_ACL_BUSY != pCoexDm->btStatus)
4908                         pCoexDm->bAutoTdmaAdjust = FALSE;
4909                 pCoexDm->btStatus = BT_8703B_1ANT_BT_STATUS_ACL_BUSY;
4910                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT ACL busy!!!\n"));
4911         }
4912         else
4913         {
4914                 pCoexDm->btStatus = BT_8703B_1ANT_BT_STATUS_MAX;
4915                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n"));
4916         }
4917
4918         if( (BT_8703B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus) ||
4919                 (BT_8703B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||
4920                 (BT_8703B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )
4921                 bBtBusy = TRUE;
4922         else
4923                 bBtBusy = FALSE;
4924         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);
4925
4926         halbtc8703b1ant_RunCoexistMechanism(pBtCoexist);
4927 }
4928
4929 VOID
4930 EXhalbtc8703b1ant_RfStatusNotify(
4931         IN      PBTC_COEXIST                    pBtCoexist,
4932         IN      u1Byte                                  type
4933         )
4934 {
4935         u4Byte  u4Tmp;
4936         u1Byte  u1Tmpa,u1Tmpb, u1Tmpc;
4937         
4938         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RF Status notify\n"));
4939
4940         if(BTC_RF_ON == type)
4941         {
4942                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RF is turned ON!!\n"));
4943                 halbtc8703b1ant_PostActiveStateToBT(pBtCoexist, TRUE);
4944                 halbtc8703b1ant_InitHwConfig(pBtCoexist, FALSE, FALSE);
4945                 pBtCoexist->bStopCoexDm = FALSE;
4946         }
4947         else if(BTC_RF_OFF == type)
4948         {
4949                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RF is turned OFF!!\n"));
4950                 halbtc8703b1ant_PostActiveStateToBT(pBtCoexist, FALSE);
4951                 
4952                 halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
4953                 halbtc8703b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 0);
4954                 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FORCE_EXEC, FALSE, TRUE);               
4955                 halbtc8703b1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE);
4956                 pBtCoexist->bStopCoexDm = TRUE;
4957
4958         }
4959 }
4960
4961 VOID
4962 EXhalbtc8703b1ant_HaltNotify(
4963         IN      PBTC_COEXIST                    pBtCoexist
4964         )
4965 {
4966         u4Byte  u4Tmp;
4967         
4968         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Halt notify\n"));
4969
4970         halbtc8703b1ant_PostActiveStateToBT(pBtCoexist, FALSE);
4971
4972         halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
4973         halbtc8703b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 0);
4974         halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FORCE_EXEC, FALSE, TRUE);       
4975
4976         halbtc8703b1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE);
4977
4978         EXhalbtc8703b1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);
4979
4980         pBtCoexist->bStopCoexDm = TRUE; 
4981 }
4982
4983 VOID
4984 EXhalbtc8703b1ant_PnpNotify(
4985         IN      PBTC_COEXIST                    pBtCoexist,
4986         IN      u1Byte                          pnpState
4987         )
4988 {
4989         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Pnp notify\n"));
4990
4991         if(BTC_WIFI_PNP_SLEEP == pnpState)
4992         {
4993                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Pnp notify to SLEEP\n"));
4994
4995                 halbtc8703b1ant_PostActiveStateToBT(pBtCoexist, FALSE);
4996
4997                 halbtc8703b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
4998                 halbtc8703b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);
4999                 halbtc8703b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FORCE_EXEC, FALSE, TRUE);
5000                 halbtc8703b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);          
5001
5002                 pBtCoexist->bStopCoexDm = TRUE;
5003         }
5004         else if(BTC_WIFI_PNP_WAKE_UP == pnpState)
5005         {
5006                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Pnp notify to WAKE UP\n"));
5007                 halbtc8703b1ant_PostActiveStateToBT(pBtCoexist, TRUE);
5008                 
5009                 pBtCoexist->bStopCoexDm = FALSE;
5010                 halbtc8703b1ant_InitHwConfig(pBtCoexist, FALSE, FALSE);
5011                 halbtc8703b1ant_InitCoexDm(pBtCoexist);
5012                 halbtc8703b1ant_QueryBtInfo(pBtCoexist);
5013         }
5014 }
5015
5016
5017 VOID
5018 EXhalbtc8703b1ant_ScoreBoardStatusNotify(
5019         IN      PBTC_COEXIST            pBtCoexist,
5020         IN      pu1Byte                 tmpBuf,
5021         IN      u1Byte                  length
5022         )
5023 {
5024         //
5025
5026
5027 }
5028
5029 VOID
5030 EXhalbtc8703b1ant_CoexDmReset(
5031         IN      PBTC_COEXIST                    pBtCoexist
5032         )
5033 {
5034         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], *****************Coex DM Reset*****************\n"));
5035
5036         halbtc8703b1ant_InitHwConfig(pBtCoexist, FALSE, FALSE);
5037         //pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
5038         //pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x2, 0xfffff, 0x0);
5039         halbtc8703b1ant_InitCoexDm(pBtCoexist);
5040 }
5041
5042 VOID
5043 EXhalbtc8703b1ant_Periodical(
5044         IN      PBTC_COEXIST                    pBtCoexist
5045         )
5046 {
5047         static u1Byte           disVerInfoCnt=0;
5048         u4Byte                          fwVer=0, btPatchVer=0;
5049         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;
5050         PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;
5051
5052         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ==========================Periodical===========================\n"));
5053
5054         if(disVerInfoCnt <= 5)
5055         {
5056                 disVerInfoCnt += 1;
5057                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ****************************************************************\n"));
5058                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Ant PG Num/ Ant Mech/ Ant Pos = %d/ %d/ %d\n", 
5059                         pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum, pBoardInfo->btdmAntPos));
5060                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT stack/ hci ext ver = %s / %d\n", 
5061                         ((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion));
5062                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);
5063                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);
5064                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CoexVer/ FwVer/ PatchVer = %d_%x/ 0x%x/ 0x%x(%d)\n",
5065                         GLCoexVerDate8703b1Ant, GLCoexVer8703b1Ant, fwVer, btPatchVer, btPatchVer));
5066                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ****************************************************************\n"));
5067         }
5068
5069 #if(BT_AUTO_REPORT_ONLY_8703B_1ANT == 0)
5070         halbtc8703b1ant_QueryBtInfo(pBtCoexist);
5071         halbtc8703b1ant_MonitorBtEnableDisable(pBtCoexist);
5072 #else
5073         halbtc8703b1ant_MonitorBtCtr(pBtCoexist);
5074         halbtc8703b1ant_MonitorWiFiCtr(pBtCoexist);
5075 #if BT_8703B_1ANT_ANTDET_ENABLE
5076         halbtc8703b1ant_MonitorBtEnableDisable(pBtCoexist);
5077 #endif
5078
5079         if( halbtc8703b1ant_IsWifiStatusChanged(pBtCoexist) ||
5080                 pCoexDm->bAutoTdmaAdjust )
5081         {
5082
5083                 halbtc8703b1ant_RunCoexistMechanism(pBtCoexist);        
5084         }
5085
5086         pCoexSta->specialPktPeriodCnt++;
5087
5088 #endif
5089 }
5090
5091 VOID
5092 EXhalbtc8703b1ant_AntennaDetection(
5093         IN      PBTC_COEXIST                    pBtCoexist,
5094         IN      u4Byte                                  centFreq,
5095         IN      u4Byte                                  offset,
5096         IN      u4Byte                                  span,
5097         IN      u4Byte                                  seconds
5098         )
5099 {
5100           //No Antenna Detection required because 8730b is only 1-Ant
5101 }
5102
5103 VOID
5104 EXhalbtc8703b1ant_AntennaIsolation(
5105         IN      PBTC_COEXIST                    pBtCoexist,
5106         IN      u4Byte                                  centFreq,
5107         IN      u4Byte                                  offset,
5108         IN      u4Byte                                  span,
5109         IN      u4Byte                                  seconds
5110         )
5111 {
5112
5113
5114 }
5115
5116 VOID
5117 EXhalbtc8703b1ant_PSDScan(
5118         IN      PBTC_COEXIST                    pBtCoexist,
5119         IN      u4Byte                                  centFreq,
5120         IN      u4Byte                                  offset,
5121         IN      u4Byte                                  span,
5122         IN      u4Byte                                  seconds
5123         )
5124 {
5125
5126
5127 }
5128
5129 VOID
5130 EXhalbtc8703b1ant_DisplayAntDetection(
5131         IN      PBTC_COEXIST                    pBtCoexist
5132         )
5133 {
5134
5135 }
5136
5137 #endif
5138
5139 #else   // #if (RTL8723B_SUPPORT == 1)
5140 VOID
5141 EXhalbtc8703b1ant_PowerOnSetting(
5142         IN      PBTC_COEXIST            pBtCoexist
5143         ){}
5144 VOID
5145 EXhalbtc8703b1ant_PreLoadFirmware(
5146         IN      PBTC_COEXIST            pBtCoexist
5147         ){}
5148 VOID
5149 EXhalbtc8703b1ant_InitHwConfig(
5150         IN      PBTC_COEXIST            pBtCoexist,
5151         IN      BOOLEAN                         bWifiOnly
5152         ){}
5153 VOID
5154 EXhalbtc8703b1ant_InitCoexDm(
5155         IN      PBTC_COEXIST            pBtCoexist
5156         ){}
5157 VOID
5158 EXhalbtc8703b1ant_IpsNotify(
5159         IN      PBTC_COEXIST            pBtCoexist,
5160         IN      u1Byte                  type
5161         ){}
5162 VOID
5163 EXhalbtc8703b1ant_LpsNotify(
5164         IN      PBTC_COEXIST            pBtCoexist,
5165         IN      u1Byte                  type
5166         ){}
5167 VOID
5168 EXhalbtc8703b1ant_ScanNotify(
5169         IN      PBTC_COEXIST            pBtCoexist,
5170         IN      u1Byte                  type
5171         ){}
5172 VOID
5173 EXhalbtc8703b1ant_ConnectNotify(
5174         IN      PBTC_COEXIST            pBtCoexist,
5175         IN      u1Byte                  type
5176         ){}
5177 VOID
5178 EXhalbtc8703b1ant_MediaStatusNotify(
5179         IN      PBTC_COEXIST                    pBtCoexist,
5180         IN      u1Byte                          type
5181         ){}
5182 VOID
5183 EXhalbtc8703b1ant_SpecialPacketNotify(
5184         IN      PBTC_COEXIST                    pBtCoexist,
5185         IN      u1Byte                          type
5186         ){}
5187 VOID
5188 EXhalbtc8703b1ant_BtInfoNotify(
5189         IN      PBTC_COEXIST            pBtCoexist,
5190         IN      pu1Byte                 tmpBuf,
5191         IN      u1Byte                  length
5192         ){}
5193 VOID
5194 EXhalbtc8703b1ant_RfStatusNotify(
5195         IN      PBTC_COEXIST                    pBtCoexist,
5196         IN      u1Byte                                  type
5197         ){}
5198 VOID
5199 EXhalbtc8703b1ant_HaltNotify(
5200         IN      PBTC_COEXIST                    pBtCoexist
5201         ){}
5202 VOID
5203 EXhalbtc8703b1ant_PnpNotify(
5204         IN      PBTC_COEXIST                    pBtCoexist,
5205         IN      u1Byte                          pnpState
5206         ){}
5207 VOID
5208 EXhalbtc8703b1ant_ScoreBoardStatusNotify(
5209         IN      PBTC_COEXIST            pBtCoexist,
5210         IN      pu1Byte                 tmpBuf,
5211         IN      u1Byte                  length
5212         ){}
5213 VOID
5214 EXhalbtc8703b1ant_CoexDmReset(
5215         IN      PBTC_COEXIST                    pBtCoexist
5216         ){}
5217 VOID
5218 EXhalbtc8703b1ant_Periodical(
5219         IN      PBTC_COEXIST                    pBtCoexist
5220         ){}
5221 VOID
5222 EXhalbtc8703b1ant_DisplayCoexInfo(
5223         IN      PBTC_COEXIST            pBtCoexist
5224         ){}
5225 VOID
5226 EXhalbtc8703b1ant_AntennaDetection(
5227         IN      PBTC_COEXIST                    pBtCoexist,
5228         IN      u4Byte                                  centFreq,
5229         IN      u4Byte                                  offset,
5230         IN      u4Byte                                  span,
5231         IN      u4Byte                                  seconds
5232         ){}
5233 VOID
5234 EXhalbtc8703b1ant_DisplayAntDetection(
5235         IN      PBTC_COEXIST                    pBtCoexist
5236         ){}
5237
5238 #endif