1 /* SPDX-License-Identifier: GPL-2.0 */
2 //============================================================
3 // Description:
4 //
5 // This file is for RTL8723B Co-exist mechanism
6 //
7 // History
8 // 2012/11/15 Cosa first check in.
9 //
10 //============================================================
11
12 //============================================================
13 // include files
14 //============================================================
15 #include "Mp_Precomp.h"
16
17 #if WPP_SOFTWARE_TRACE
18 #include "HalBtc8723b1Ant.tmh"
19 #endif
20
21 //#include <Math.h>
22 #if(BT_30_SUPPORT == 1)
23 //============================================================
24 // Global variables, these are static variables
25 //============================================================
26 static COEX_DM_8723B_1ANT GLCoexDm8723b1Ant;
27 static PCOEX_DM_8723B_1ANT pCoexDm=&GLCoexDm8723b1Ant;
28 static COEX_STA_8723B_1ANT GLCoexSta8723b1Ant;
29 static PCOEX_STA_8723B_1ANT pCoexSta=&GLCoexSta8723b1Ant;
30 static PSDSCAN_STA_8723B_1ANT GLPsdScan8723b1Ant;
31 static PPSDSCAN_STA_8723B_1ANT pPsdScan = &GLPsdScan8723b1Ant;
32
33
34 const char *const GLBtInfoSrc8723b1Ant[]={
35 "BT Info[wifi fw]",
36 "BT Info[bt rsp]",
37 "BT Info[bt auto report]",
38 };
39
40 u4Byte GLCoexVerDate8723b1Ant=20150119;
41 u4Byte GLCoexVer8723b1Ant=0x58;
42
43 //============================================================
44 // local function proto type if needed
45 //============================================================
46 //============================================================
47 // local function start with halbtc8723b1ant_
48 //============================================================
49 u1Byte
halbtc8723b1ant_BtRssiState(u1Byte levelNum,u1Byte rssiThresh,u1Byte rssiThresh1)50 halbtc8723b1ant_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_8723B_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_8723B_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_8723B_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
halbtc8723b1ant_WifiRssiState(IN PBTC_COEXIST pBtCoexist,IN u1Byte index,IN u1Byte levelNum,IN u1Byte rssiThresh,IN u1Byte rssiThresh1)142 halbtc8723b1ant_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_8723B_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_8723B_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_8723B_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
halbtc8723b1ant_UpdateRaMask(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN u4Byte disRateMask)236 halbtc8723b1ant_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
halbtc8723b1ant_AutoRateFallbackRetry(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN u1Byte type)252 halbtc8723b1ant_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
halbtc8723b1ant_RetryLimit(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN u1Byte type)292 halbtc8723b1ant_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
halbtc8723b1ant_AmpduMaxTime(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN u1Byte type)319 halbtc8723b1ant_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
halbtc8723b1ant_LimitedTx(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN u1Byte raMaskType,IN u1Byte arfrType,IN u1Byte retryLimitType,IN u1Byte ampduTimeType)346 halbtc8723b1ant_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 halbtc8723b1ant_UpdateRaMask(pBtCoexist, bForceExec, 0x0);
359 break;
360 case 1: // disable cck 1/2
361 halbtc8723b1ant_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 halbtc8723b1ant_UpdateRaMask(pBtCoexist, bForceExec, 0x0001f1f7);
365 break;
366 default:
367 break;
368 }
369
370 halbtc8723b1ant_AutoRateFallbackRetry(pBtCoexist, bForceExec, arfrType);
371 halbtc8723b1ant_RetryLimit(pBtCoexist, bForceExec, retryLimitType);
372 halbtc8723b1ant_AmpduMaxTime(pBtCoexist, bForceExec, ampduTimeType);
373 }
374
375 VOID
halbtc8723b1ant_LimitedRx(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN BOOLEAN bRejApAggPkt,IN BOOLEAN bBtCtrlAggBufSize,IN u1Byte aggBufSize)376 halbtc8723b1ant_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
halbtc8723b1ant_QueryBtInfo(IN PBTC_COEXIST pBtCoexist)403 halbtc8723b1ant_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
halbtc8723b1ant_MonitorBtCtr(IN PBTC_COEXIST pBtCoexist)420 halbtc8723b1ant_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 u4Byte 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 > 1050) && (!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 // This part is for wifi FW and driver to update BT's status as disabled.
468 // The flow is as the following
469 // 1. disable BT
470 // 2. if all BT Tx/Rx counter=0, after 6 sec we query bt info
471 // 3. Because BT will not rsp from mailbox, so wifi fw will know BT is disabled
472 // 4. FW will rsp c2h for BT that driver will know BT is disabled.
473 if ((regHPTx == 0) && (regHPRx ==0) && (regLPTx == 0) && (regLPRx == 0))
474 {
475 NumOfBtCounterChk++;
476 if (NumOfBtCounterChk == 3)
477 {
478 halbtc8723b1ant_QueryBtInfo(pBtCoexist);
479 }
480 }
481 else
482 {
483 NumOfBtCounterChk = 0;
484 }
485 }
486
487
488 VOID
halbtc8723b1ant_MonitorWiFiCtr(IN PBTC_COEXIST pBtCoexist)489 halbtc8723b1ant_MonitorWiFiCtr(
490 IN PBTC_COEXIST pBtCoexist
491 )
492 {
493 u4Byte u4Tmp;
494 u2Byte u2Tmp[3];
495 s4Byte wifiRssi=0;
496 BOOLEAN bWifiBusy = FALSE, bWifiUnderBMode = FALSE;
497 static u1Byte nCCKLockCounter = 0;
498 u4Byte TotalCnt;
499
500 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
501 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);
502 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode);
503
504 if (pCoexSta->bUnderIps)
505 {
506 pCoexSta->nCRCOK_CCK = 0;
507 pCoexSta->nCRCOK_11g = 0;
508 pCoexSta->nCRCOK_11n = 0;
509 pCoexSta->nCRCOK_11nAgg = 0;
510
511 pCoexSta->nCRCErr_CCK = 0;
512 pCoexSta->nCRCErr_11g = 0;
513 pCoexSta->nCRCErr_11n = 0;
514 pCoexSta->nCRCErr_11nAgg = 0;
515 }
516 else
517 {
518 pCoexSta->nCRCOK_CCK = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xf88);
519 pCoexSta->nCRCOK_11g = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf94);
520 pCoexSta->nCRCOK_11n = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf90);
521 pCoexSta->nCRCOK_11nAgg= pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xfb8);
522
523 pCoexSta->nCRCErr_CCK = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xf84);
524 pCoexSta->nCRCErr_11g = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf96);
525 pCoexSta->nCRCErr_11n = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf92);
526 pCoexSta->nCRCErr_11nAgg = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xfba);
527 }
528
529
530 //reset counter
531 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xf16, 0x1, 0x1);
532 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xf16, 0x1, 0x0);
533
534 if ( (bWifiBusy) && (wifiRssi >= 30) && (!bWifiUnderBMode))
535 {
536 TotalCnt = pCoexSta->nCRCOK_CCK + pCoexSta->nCRCOK_11g + pCoexSta->nCRCOK_11n +
537 pCoexSta->nCRCOK_11nAgg;
538
539 if ( (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_BUSY) ||
540 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY) ||
541 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_SCO_BUSY) )
542 {
543 if (pCoexSta->nCRCOK_CCK >(TotalCnt -pCoexSta->nCRCOK_CCK))
544 {
545 if (nCCKLockCounter < 3)
546 nCCKLockCounter++;
547 }
548 else
549 {
550 if (nCCKLockCounter > 0)
551 nCCKLockCounter--;
552 }
553
554 }
555 else
556 {
557 if (nCCKLockCounter > 0)
558 nCCKLockCounter--;
559 }
560 }
561 else
562 {
563 if (nCCKLockCounter > 0)
564 nCCKLockCounter--;
565 }
566
567 if (!pCoexSta->bPreCCKLock)
568 {
569
570 if (nCCKLockCounter >= 3)
571 pCoexSta->bCCKLock = TRUE;
572 else
573 pCoexSta->bCCKLock = FALSE;
574 }
575 else
576 {
577 if (nCCKLockCounter == 0)
578 pCoexSta->bCCKLock = FALSE;
579 else
580 pCoexSta->bCCKLock = TRUE;
581 }
582
583 if (pCoexSta->bCCKLock)
584 pCoexSta->bCCKEverLock = TRUE;
585
586 pCoexSta->bPreCCKLock = pCoexSta->bCCKLock;
587
588
589 }
590
591 BOOLEAN
halbtc8723b1ant_IsWifiStatusChanged(IN PBTC_COEXIST pBtCoexist)592 halbtc8723b1ant_IsWifiStatusChanged(
593 IN PBTC_COEXIST pBtCoexist
594 )
595 {
596 static BOOLEAN bPreWifiBusy=FALSE, bPreUnder4way=FALSE, bPreBtHsOn=FALSE;
597 BOOLEAN bWifiBusy=FALSE, bUnder4way=FALSE, bBtHsOn=FALSE;
598 BOOLEAN bWifiConnected=FALSE;
599 u1Byte wifiRssiState=BTC_RSSI_STATE_HIGH;
600
601 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
602 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
603 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
604 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way);
605
606 if(bWifiConnected)
607 {
608 if(bWifiBusy != bPreWifiBusy)
609 {
610 bPreWifiBusy = bWifiBusy;
611 return TRUE;
612 }
613 if(bUnder4way != bPreUnder4way)
614 {
615 bPreUnder4way = bUnder4way;
616 return TRUE;
617 }
618 if(bBtHsOn != bPreBtHsOn)
619 {
620 bPreBtHsOn = bBtHsOn;
621 return TRUE;
622 }
623
624
625 }
626
627 return FALSE;
628 }
629
630 VOID
halbtc8723b1ant_UpdateBtLinkInfo(IN PBTC_COEXIST pBtCoexist)631 halbtc8723b1ant_UpdateBtLinkInfo(
632 IN PBTC_COEXIST pBtCoexist
633 )
634 {
635 PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
636 BOOLEAN bBtHsOn=FALSE;
637
638 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
639
640 pBtLinkInfo->bBtLinkExist = pCoexSta->bBtLinkExist;
641 pBtLinkInfo->bScoExist = pCoexSta->bScoExist;
642 pBtLinkInfo->bA2dpExist = pCoexSta->bA2dpExist;
643 pBtLinkInfo->bPanExist = pCoexSta->bPanExist;
644 pBtLinkInfo->bHidExist = pCoexSta->bHidExist;
645 pBtLinkInfo->bBtHiPriLinkExist = pCoexSta->bBtHiPriLinkExist;
646
647 // work around for HS mode.
648 if(bBtHsOn)
649 {
650 pBtLinkInfo->bPanExist = TRUE;
651 pBtLinkInfo->bBtLinkExist = TRUE;
652 }
653
654 // check if Sco only
655 if( pBtLinkInfo->bScoExist &&
656 !pBtLinkInfo->bA2dpExist &&
657 !pBtLinkInfo->bPanExist &&
658 !pBtLinkInfo->bHidExist )
659 pBtLinkInfo->bScoOnly = TRUE;
660 else
661 pBtLinkInfo->bScoOnly = FALSE;
662
663 // check if A2dp only
664 if( !pBtLinkInfo->bScoExist &&
665 pBtLinkInfo->bA2dpExist &&
666 !pBtLinkInfo->bPanExist &&
667 !pBtLinkInfo->bHidExist )
668 pBtLinkInfo->bA2dpOnly = TRUE;
669 else
670 pBtLinkInfo->bA2dpOnly = FALSE;
671
672 // check if Pan only
673 if( !pBtLinkInfo->bScoExist &&
674 !pBtLinkInfo->bA2dpExist &&
675 pBtLinkInfo->bPanExist &&
676 !pBtLinkInfo->bHidExist )
677 pBtLinkInfo->bPanOnly = TRUE;
678 else
679 pBtLinkInfo->bPanOnly = FALSE;
680
681 // check if Hid only
682 if( !pBtLinkInfo->bScoExist &&
683 !pBtLinkInfo->bA2dpExist &&
684 !pBtLinkInfo->bPanExist &&
685 pBtLinkInfo->bHidExist )
686 pBtLinkInfo->bHidOnly = TRUE;
687 else
688 pBtLinkInfo->bHidOnly = FALSE;
689 }
690
691 u1Byte
halbtc8723b1ant_ActionAlgorithm(IN PBTC_COEXIST pBtCoexist)692 halbtc8723b1ant_ActionAlgorithm(
693 IN PBTC_COEXIST pBtCoexist
694 )
695 {
696 PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
697 BOOLEAN bBtHsOn=FALSE;
698 u1Byte algorithm=BT_8723B_1ANT_COEX_ALGO_UNDEFINED;
699 u1Byte numOfDiffProfile=0;
700
701 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
702
703 if(!pBtLinkInfo->bBtLinkExist)
704 {
705 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], No BT link exists!!!\n"));
706 return algorithm;
707 }
708
709 if(pBtLinkInfo->bScoExist)
710 numOfDiffProfile++;
711 if(pBtLinkInfo->bHidExist)
712 numOfDiffProfile++;
713 if(pBtLinkInfo->bPanExist)
714 numOfDiffProfile++;
715 if(pBtLinkInfo->bA2dpExist)
716 numOfDiffProfile++;
717
718 if(numOfDiffProfile == 1)
719 {
720 if(pBtLinkInfo->bScoExist)
721 {
722 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO only\n"));
723 algorithm = BT_8723B_1ANT_COEX_ALGO_SCO;
724 }
725 else
726 {
727 if(pBtLinkInfo->bHidExist)
728 {
729 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = HID only\n"));
730 algorithm = BT_8723B_1ANT_COEX_ALGO_HID;
731 }
732 else if(pBtLinkInfo->bA2dpExist)
733 {
734 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = A2DP only\n"));
735 algorithm = BT_8723B_1ANT_COEX_ALGO_A2DP;
736 }
737 else if(pBtLinkInfo->bPanExist)
738 {
739 if(bBtHsOn)
740 {
741 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = PAN(HS) only\n"));
742 algorithm = BT_8723B_1ANT_COEX_ALGO_PANHS;
743 }
744 else
745 {
746 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = PAN(EDR) only\n"));
747 algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR;
748 }
749 }
750 }
751 }
752 else if(numOfDiffProfile == 2)
753 {
754 if(pBtLinkInfo->bScoExist)
755 {
756 if(pBtLinkInfo->bHidExist)
757 {
758 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + HID\n"));
759 algorithm = BT_8723B_1ANT_COEX_ALGO_HID;
760 }
761 else if(pBtLinkInfo->bA2dpExist)
762 {
763 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + A2DP ==> SCO\n"));
764 algorithm = BT_8723B_1ANT_COEX_ALGO_SCO;
765 }
766 else if(pBtLinkInfo->bPanExist)
767 {
768 if(bBtHsOn)
769 {
770 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + PAN(HS)\n"));
771 algorithm = BT_8723B_1ANT_COEX_ALGO_SCO;
772 }
773 else
774 {
775 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + PAN(EDR)\n"));
776 algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_HID;
777 }
778 }
779 }
780 else
781 {
782 if( pBtLinkInfo->bHidExist &&
783 pBtLinkInfo->bA2dpExist )
784 {
785 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = HID + A2DP\n"));
786 algorithm = BT_8723B_1ANT_COEX_ALGO_HID_A2DP;
787 }
788 else if( pBtLinkInfo->bHidExist &&
789 pBtLinkInfo->bPanExist )
790 {
791 if(bBtHsOn)
792 {
793 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = HID + PAN(HS)\n"));
794 algorithm = BT_8723B_1ANT_COEX_ALGO_HID_A2DP;
795 }
796 else
797 {
798 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = HID + PAN(EDR)\n"));
799 algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_HID;
800 }
801 }
802 else if( pBtLinkInfo->bPanExist &&
803 pBtLinkInfo->bA2dpExist )
804 {
805 if(bBtHsOn)
806 {
807 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = A2DP + PAN(HS)\n"));
808 algorithm = BT_8723B_1ANT_COEX_ALGO_A2DP_PANHS;
809 }
810 else
811 {
812 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = A2DP + PAN(EDR)\n"));
813 algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_A2DP;
814 }
815 }
816 }
817 }
818 else if(numOfDiffProfile == 3)
819 {
820 if(pBtLinkInfo->bScoExist)
821 {
822 if( pBtLinkInfo->bHidExist &&
823 pBtLinkInfo->bA2dpExist )
824 {
825 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + HID + A2DP ==> HID\n"));
826 algorithm = BT_8723B_1ANT_COEX_ALGO_HID;
827 }
828 else if( pBtLinkInfo->bHidExist &&
829 pBtLinkInfo->bPanExist )
830 {
831 if(bBtHsOn)
832 {
833 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + HID + PAN(HS)\n"));
834 algorithm = BT_8723B_1ANT_COEX_ALGO_HID_A2DP;
835 }
836 else
837 {
838 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + HID + PAN(EDR)\n"));
839 algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_HID;
840 }
841 }
842 else if( pBtLinkInfo->bPanExist &&
843 pBtLinkInfo->bA2dpExist )
844 {
845 if(bBtHsOn)
846 {
847 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + A2DP + PAN(HS)\n"));
848 algorithm = BT_8723B_1ANT_COEX_ALGO_SCO;
849 }
850 else
851 {
852 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + A2DP + PAN(EDR) ==> HID\n"));
853 algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_HID;
854 }
855 }
856 }
857 else
858 {
859 if( pBtLinkInfo->bHidExist &&
860 pBtLinkInfo->bPanExist &&
861 pBtLinkInfo->bA2dpExist )
862 {
863 if(bBtHsOn)
864 {
865 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = HID + A2DP + PAN(HS)\n"));
866 algorithm = BT_8723B_1ANT_COEX_ALGO_HID_A2DP;
867 }
868 else
869 {
870 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = HID + A2DP + PAN(EDR)\n"));
871 algorithm = BT_8723B_1ANT_COEX_ALGO_HID_A2DP_PANEDR;
872 }
873 }
874 }
875 }
876 else if(numOfDiffProfile >= 3)
877 {
878 if(pBtLinkInfo->bScoExist)
879 {
880 if( pBtLinkInfo->bHidExist &&
881 pBtLinkInfo->bPanExist &&
882 pBtLinkInfo->bA2dpExist )
883 {
884 if(bBtHsOn)
885 {
886 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Error!!! BT Profile = SCO + HID + A2DP + PAN(HS)\n"));
887
888 }
889 else
890 {
891 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Profile = SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n"));
892 algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_HID;
893 }
894 }
895 }
896 }
897
898 return algorithm;
899 }
900
901 VOID
halbtc8723b1ant_SetBtAutoReport(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bEnableAutoReport)902 halbtc8723b1ant_SetBtAutoReport(
903 IN PBTC_COEXIST pBtCoexist,
904 IN BOOLEAN bEnableAutoReport
905 )
906 {
907 u1Byte H2C_Parameter[1] ={0};
908
909 H2C_Parameter[0] = 0;
910
911 if(bEnableAutoReport)
912 {
913 H2C_Parameter[0] |= BIT0;
914 }
915
916 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], BT FW auto report : %s, FW write 0x68=0x%x\n",
917 (bEnableAutoReport? "Enabled!!":"Disabled!!"), H2C_Parameter[0]));
918
919 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x68, 1, H2C_Parameter);
920 }
921
922 VOID
halbtc8723b1ant_BtAutoReport(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN BOOLEAN bEnableAutoReport)923 halbtc8723b1ant_BtAutoReport(
924 IN PBTC_COEXIST pBtCoexist,
925 IN BOOLEAN bForceExec,
926 IN BOOLEAN bEnableAutoReport
927 )
928 {
929 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s BT Auto report = %s\n",
930 (bForceExec? "force to":""), ((bEnableAutoReport)? "Enabled":"Disabled")));
931 pCoexDm->bCurBtAutoReport = bEnableAutoReport;
932
933 if(!bForceExec)
934 {
935 if(pCoexDm->bPreBtAutoReport == pCoexDm->bCurBtAutoReport)
936 return;
937 }
938 halbtc8723b1ant_SetBtAutoReport(pBtCoexist, pCoexDm->bCurBtAutoReport);
939
940 pCoexDm->bPreBtAutoReport = pCoexDm->bCurBtAutoReport;
941 }
942
943 VOID
halbtc8723b1ant_SetSwPenaltyTxRateAdaptive(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bLowPenaltyRa)944 halbtc8723b1ant_SetSwPenaltyTxRateAdaptive(
945 IN PBTC_COEXIST pBtCoexist,
946 IN BOOLEAN bLowPenaltyRa
947 )
948 {
949 u1Byte H2C_Parameter[6] ={0};
950
951 H2C_Parameter[0] = 0x6; // opCode, 0x6= Retry_Penalty
952
953 if(bLowPenaltyRa)
954 {
955 H2C_Parameter[1] |= BIT0;
956 H2C_Parameter[2] = 0x00; //normal rate except MCS7/6/5, OFDM54/48/36
957 H2C_Parameter[3] = 0xf7; //MCS7 or OFDM54
958 H2C_Parameter[4] = 0xf8; //MCS6 or OFDM48
959 H2C_Parameter[5] = 0xf9; //MCS5 or OFDM36
960 }
961
962 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set WiFi Low-Penalty Retry: %s",
963 (bLowPenaltyRa? "ON!!":"OFF!!") ));
964
965 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x69, 6, H2C_Parameter);
966 }
967
968 VOID
halbtc8723b1ant_LowPenaltyRa(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN BOOLEAN bLowPenaltyRa)969 halbtc8723b1ant_LowPenaltyRa(
970 IN PBTC_COEXIST pBtCoexist,
971 IN BOOLEAN bForceExec,
972 IN BOOLEAN bLowPenaltyRa
973 )
974 {
975 pCoexDm->bCurLowPenaltyRa = bLowPenaltyRa;
976
977 if(!bForceExec)
978 {
979 if(pCoexDm->bPreLowPenaltyRa == pCoexDm->bCurLowPenaltyRa)
980 return;
981 }
982 halbtc8723b1ant_SetSwPenaltyTxRateAdaptive(pBtCoexist, pCoexDm->bCurLowPenaltyRa);
983
984 pCoexDm->bPreLowPenaltyRa = pCoexDm->bCurLowPenaltyRa;
985 }
986
987 VOID
halbtc8723b1ant_SetCoexTable(IN PBTC_COEXIST pBtCoexist,IN u4Byte val0x6c0,IN u4Byte val0x6c4,IN u4Byte val0x6c8,IN u1Byte val0x6cc)988 halbtc8723b1ant_SetCoexTable(
989 IN PBTC_COEXIST pBtCoexist,
990 IN u4Byte val0x6c0,
991 IN u4Byte val0x6c4,
992 IN u4Byte val0x6c8,
993 IN u1Byte val0x6cc
994 )
995 {
996 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6c0=0x%x\n", val0x6c0));
997 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c0, val0x6c0);
998
999 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6c4=0x%x\n", val0x6c4));
1000 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c4, val0x6c4);
1001
1002 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6c8=0x%x\n", val0x6c8));
1003 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c8, val0x6c8);
1004
1005 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6cc=0x%x\n", val0x6cc));
1006 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cc, val0x6cc);
1007 }
1008
1009 VOID
halbtc8723b1ant_CoexTable(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN u4Byte val0x6c0,IN u4Byte val0x6c4,IN u4Byte val0x6c8,IN u1Byte val0x6cc)1010 halbtc8723b1ant_CoexTable(
1011 IN PBTC_COEXIST pBtCoexist,
1012 IN BOOLEAN bForceExec,
1013 IN u4Byte val0x6c0,
1014 IN u4Byte val0x6c4,
1015 IN u4Byte val0x6c8,
1016 IN u1Byte val0x6cc
1017 )
1018 {
1019 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s write Coex Table 0x6c0=0x%x, 0x6c4=0x%x, 0x6cc=0x%x\n",
1020 (bForceExec? "force to":""), val0x6c0, val0x6c4, val0x6cc));
1021 pCoexDm->curVal0x6c0 = val0x6c0;
1022 pCoexDm->curVal0x6c4 = val0x6c4;
1023 pCoexDm->curVal0x6c8 = val0x6c8;
1024 pCoexDm->curVal0x6cc = val0x6cc;
1025
1026 if(!bForceExec)
1027 {
1028 if( (pCoexDm->preVal0x6c0 == pCoexDm->curVal0x6c0) &&
1029 (pCoexDm->preVal0x6c4 == pCoexDm->curVal0x6c4) &&
1030 (pCoexDm->preVal0x6c8 == pCoexDm->curVal0x6c8) &&
1031 (pCoexDm->preVal0x6cc == pCoexDm->curVal0x6cc) )
1032 return;
1033 }
1034 halbtc8723b1ant_SetCoexTable(pBtCoexist, val0x6c0, val0x6c4, val0x6c8, val0x6cc);
1035
1036 pCoexDm->preVal0x6c0 = pCoexDm->curVal0x6c0;
1037 pCoexDm->preVal0x6c4 = pCoexDm->curVal0x6c4;
1038 pCoexDm->preVal0x6c8 = pCoexDm->curVal0x6c8;
1039 pCoexDm->preVal0x6cc = pCoexDm->curVal0x6cc;
1040 }
1041
1042 VOID
halbtc8723b1ant_CoexTableWithType(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN u1Byte type)1043 halbtc8723b1ant_CoexTableWithType(
1044 IN PBTC_COEXIST pBtCoexist,
1045 IN BOOLEAN bForceExec,
1046 IN u1Byte type
1047 )
1048 {
1049 PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;
1050
1051 #if BT_8723B_1ANT_ANTDET_ENABLE
1052 #if BT_8723B_1ANT_ANTDET_COEXMECHANISMSWITCH_ENABLE
1053 if (pBoardInfo->btdmAntNumByAntDet == 2)
1054 {
1055 if (type == 3)
1056 type = 14;
1057 else if (type == 4)
1058 type = 13;
1059 else if (type == 5)
1060 type = 8;
1061 }
1062 #endif
1063 #endif
1064
1065 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], ********** CoexTable(%d) **********\n", type));
1066
1067 pCoexSta->nCoexTableType = type;
1068
1069 switch(type)
1070 {
1071 case 0:
1072 halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x55555555, 0xffffff, 0x3);
1073 break;
1074 case 1:
1075 halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3);
1076 break;
1077 case 2:
1078 halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x5a5a5a5a, 0x5a5a5a5a, 0xffffff, 0x3);
1079 break;
1080 case 3:
1081 halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3);
1082 break;
1083 case 4:
1084 if ( pCoexSta->bCCKEverLock)
1085 halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0xaaaaaaaa, 0xffffff, 0x3);
1086 else
1087 halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0xaaaa5a5a, 0xffffff, 0x3);
1088 break;
1089 case 5:
1090 if ( pCoexSta->bCCKEverLock)
1091 halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0xaaaa5a5a, 0xaaaa5a5a, 0xffffff, 0x3);
1092 else
1093 halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x5a5a5a5a, 0x5a5a5a5a, 0xffffff, 0x3);
1094 break;
1095 case 6:
1096 halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0xaaaaaaaa, 0xffffff, 0x3);
1097 break;
1098 case 7:
1099 halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0xaaaaaaaa, 0xaaaaaaaa, 0xffffff, 0x3);
1100 break;
1101 case 8:
1102 halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3);
1103 break;
1104 case 9:
1105 halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3);
1106 break;
1107 case 10:
1108 halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3);
1109 break;
1110 case 11:
1111 halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3);
1112 break;
1113 case 12:
1114 halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0x5ada5ada, 0xffffff, 0x3);
1115 break;
1116 case 13:
1117 halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x5fff5fff, 0xaaaaaaaa, 0xffffff, 0x3);
1118 break;
1119 case 14:
1120 halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x5fff5fff, 0x5ada5ada, 0xffffff, 0x3);
1121 break;
1122 case 15:
1123 halbtc8723b1ant_CoexTable(pBtCoexist, bForceExec, 0x55dd55dd, 0xaaaaaaaa, 0xffffff, 0x3);
1124 break;
1125 default:
1126 break;
1127 }
1128 }
1129
1130 VOID
halbtc8723b1ant_SetFwIgnoreWlanAct(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bEnable)1131 halbtc8723b1ant_SetFwIgnoreWlanAct(
1132 IN PBTC_COEXIST pBtCoexist,
1133 IN BOOLEAN bEnable
1134 )
1135 {
1136 u1Byte H2C_Parameter[1] ={0};
1137
1138 if(bEnable)
1139 {
1140 H2C_Parameter[0] |= BIT0; // function enable
1141 }
1142
1143 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63=0x%x\n",
1144 H2C_Parameter[0]));
1145
1146 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x63, 1, H2C_Parameter);
1147 }
1148
1149 VOID
halbtc8723b1ant_IgnoreWlanAct(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN BOOLEAN bEnable)1150 halbtc8723b1ant_IgnoreWlanAct(
1151 IN PBTC_COEXIST pBtCoexist,
1152 IN BOOLEAN bForceExec,
1153 IN BOOLEAN bEnable
1154 )
1155 {
1156 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn Ignore WlanAct %s\n",
1157 (bForceExec? "force to":""), (bEnable? "ON":"OFF")));
1158 pCoexDm->bCurIgnoreWlanAct = bEnable;
1159
1160 if(!bForceExec)
1161 {
1162 if(pCoexDm->bPreIgnoreWlanAct == pCoexDm->bCurIgnoreWlanAct)
1163 return;
1164 }
1165 halbtc8723b1ant_SetFwIgnoreWlanAct(pBtCoexist, bEnable);
1166
1167 pCoexDm->bPreIgnoreWlanAct = pCoexDm->bCurIgnoreWlanAct;
1168 }
1169
1170 VOID
halbtc8723b1ant_SetLpsRpwm(IN PBTC_COEXIST pBtCoexist,IN u1Byte lpsVal,IN u1Byte rpwmVal)1171 halbtc8723b1ant_SetLpsRpwm(
1172 IN PBTC_COEXIST pBtCoexist,
1173 IN u1Byte lpsVal,
1174 IN u1Byte rpwmVal
1175 )
1176 {
1177 u1Byte lps=lpsVal;
1178 u1Byte rpwm=rpwmVal;
1179
1180 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_LPS_VAL, &lps);
1181 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
1182 }
1183
1184 VOID
halbtc8723b1ant_LpsRpwm(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN u1Byte lpsVal,IN u1Byte rpwmVal)1185 halbtc8723b1ant_LpsRpwm(
1186 IN PBTC_COEXIST pBtCoexist,
1187 IN BOOLEAN bForceExec,
1188 IN u1Byte lpsVal,
1189 IN u1Byte rpwmVal
1190 )
1191 {
1192 BOOLEAN bForceExecPwrCmd=FALSE;
1193
1194 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s set lps/rpwm=0x%x/0x%x \n",
1195 (bForceExec? "force to":""), lpsVal, rpwmVal));
1196 pCoexDm->curLps = lpsVal;
1197 pCoexDm->curRpwm = rpwmVal;
1198
1199 if(!bForceExec)
1200 {
1201 if( (pCoexDm->preLps == pCoexDm->curLps) &&
1202 (pCoexDm->preRpwm == pCoexDm->curRpwm) )
1203 {
1204 return;
1205 }
1206 }
1207 halbtc8723b1ant_SetLpsRpwm(pBtCoexist, lpsVal, rpwmVal);
1208
1209 pCoexDm->preLps = pCoexDm->curLps;
1210 pCoexDm->preRpwm = pCoexDm->curRpwm;
1211 }
1212
1213 VOID
halbtc8723b1ant_SwMechanism(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bLowPenaltyRA)1214 halbtc8723b1ant_SwMechanism(
1215 IN PBTC_COEXIST pBtCoexist,
1216 IN BOOLEAN bLowPenaltyRA
1217 )
1218 {
1219 halbtc8723b1ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, bLowPenaltyRA);
1220 }
1221
1222 VOID
halbtc8723b1ant_SetAntPath(IN PBTC_COEXIST pBtCoexist,IN u1Byte antPosType,IN BOOLEAN bForceExec,IN BOOLEAN bInitHwCfg,IN BOOLEAN bWifiOff)1223 halbtc8723b1ant_SetAntPath(
1224 IN PBTC_COEXIST pBtCoexist,
1225 IN u1Byte antPosType,
1226 IN BOOLEAN bForceExec,
1227 IN BOOLEAN bInitHwCfg,
1228 IN BOOLEAN bWifiOff
1229 )
1230 {
1231 PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;
1232 u4Byte fwVer=0, u4Tmp=0, cntBtCalChk=0;
1233 BOOLEAN bPgExtSwitch=FALSE;
1234 BOOLEAN bUseExtSwitch=FALSE;
1235 BOOLEAN bIsInMpMode = FALSE;
1236 u1Byte H2C_Parameter[2] ={0}, u1Tmp = 0;
1237
1238 pCoexDm->curAntPosType = antPosType;
1239
1240 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_EXT_SWITCH, &bPgExtSwitch);
1241 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer); // [31:16]=fw ver, [15:0]=fw sub ver
1242
1243 if((fwVer>0 && fwVer<0xc0000) || bPgExtSwitch)
1244 bUseExtSwitch = TRUE;
1245
1246 #if BT_8723B_1ANT_ANTDET_ENABLE
1247 #if BT_8723B_1ANT_ANTDET_COEXMECHANISMSWITCH_ENABLE
1248 if (antPosType == BTC_ANT_PATH_PTA)
1249 {
1250 if ((pBoardInfo->btdmAntDetFinish) && (pBoardInfo->btdmAntNumByAntDet == 2))
1251 {
1252 if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)
1253 antPosType = BTC_ANT_PATH_WIFI;
1254 else
1255 antPosType = BTC_ANT_PATH_BT;
1256 }
1257 }
1258 #endif
1259 #endif
1260
1261 if(bInitHwCfg)
1262 {
1263 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x780); //WiFi TRx Mask on
1264 //remove due to interrupt is disabled that polling c2h will fail and delay 100ms.
1265 //pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x3c, 0x15); //BT TRx Mask on
1266
1267 if(fwVer >= 0x180000)
1268 {
1269 /* Use H2C to set GNT_BT to HIGH */
1270 H2C_Parameter[0] = 1;
1271 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x6E, 1, H2C_Parameter);
1272 }
1273 else
1274 {
1275 // set grant_bt to high
1276 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x18);
1277 }
1278 //set wlan_act control by PTA
1279 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4);
1280
1281 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x0); //BT select s0/s1 is controlled by BT
1282
1283 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x39, 0x8, 0x1);
1284 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x974, 0xff);
1285 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x944, 0x3, 0x3);
1286 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x930, 0x77);
1287 }
1288 else if(bWifiOff)
1289 {
1290 if(fwVer >= 0x180000)
1291 {
1292 /* Use H2C to set GNT_BT to HIGH */
1293 H2C_Parameter[0] = 1;
1294 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x6E, 1, H2C_Parameter);
1295 }
1296 else
1297 {
1298 // set grant_bt to high
1299 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x18);
1300 }
1301 //set wlan_act to always low
1302 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4);
1303
1304 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_IS_IN_MP_MODE, &bIsInMpMode);
1305 if(!bIsInMpMode)
1306 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x0); //BT select s0/s1 is controlled by BT
1307 else
1308 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x1); //BT select s0/s1 is controlled by WiFi
1309
1310 // 0x4c[24:23]=00, Set Antenna control by BT_RFE_CTRL BT Vendor 0xac=0xf002
1311 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);
1312 u4Tmp &= ~BIT23;
1313 u4Tmp &= ~BIT24;
1314 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);
1315 }
1316 else
1317 {
1318 /* Use H2C to set GNT_BT to LOW */
1319 if(fwVer >= 0x180000)
1320 {
1321 if (pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x765) != 0)
1322 {
1323 H2C_Parameter[0] = 0;
1324 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x6E, 1, H2C_Parameter);
1325 }
1326 }
1327 else
1328 {
1329 // BT calibration check
1330 while(cntBtCalChk <= 20)
1331 {
1332 u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x49d);
1333 cntBtCalChk++;
1334 if(u1Tmp & BIT0)
1335 {
1336 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ########### BT is calibrating (wait cnt=%d) ###########\n", cntBtCalChk));
1337 delay_ms(50);
1338 }
1339 else
1340 {
1341 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ********** BT is NOT calibrating (wait cnt=%d)**********\n", cntBtCalChk));
1342 break;
1343 }
1344 }
1345
1346 // set grant_bt to PTA
1347 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x0);
1348 }
1349
1350 if (pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x76e) != 0xc)
1351 {
1352 //set wlan_act control by PTA
1353 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc);
1354 }
1355
1356 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x1); //BT select s0/s1 is controlled by WiFi
1357 }
1358
1359 if(bUseExtSwitch)
1360 {
1361 if(bInitHwCfg)
1362 {
1363 // 0x4c[23]=0, 0x4c[24]=1 Antenna control by WL/BT
1364 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);
1365 u4Tmp &=~BIT23;
1366 u4Tmp |= BIT24;
1367 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);
1368
1369 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0); // fixed internal switch S1->WiFi, S0->BT
1370
1371 if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)
1372 {
1373 //tell firmware "no antenna inverse"
1374 H2C_Parameter[0] = 0;
1375 H2C_Parameter[1] = 1; //ext switch type
1376 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter);
1377 }
1378 else
1379 {
1380 //tell firmware "antenna inverse"
1381 H2C_Parameter[0] = 1;
1382 H2C_Parameter[1] = 1; //ext switch type
1383 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter);
1384 }
1385 }
1386
1387 if(bForceExec || (pCoexDm->curAntPosType != pCoexDm->preAntPosType))
1388 {
1389 // ext switch setting
1390 switch(antPosType)
1391 {
1392 case BTC_ANT_PATH_WIFI:
1393 if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)
1394 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x1);
1395 else
1396 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x2);
1397 break;
1398 case BTC_ANT_PATH_BT:
1399 if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)
1400 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x2);
1401 else
1402 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x1);
1403 break;
1404 default:
1405 case BTC_ANT_PATH_PTA:
1406 if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)
1407 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x1);
1408 else
1409 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x2);
1410 break;
1411 }
1412 }
1413 }
1414 else
1415 {
1416 if(bInitHwCfg)
1417 {
1418 // 0x4c[23]=1, 0x4c[24]=0 Antenna control by 0x64
1419 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);
1420 u4Tmp |= BIT23;
1421 u4Tmp &=~BIT24;
1422 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);
1423
1424 //Fix Ext switch Main->S1, Aux->S0
1425 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x64, 0x1, 0x0);
1426
1427 if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)
1428 {
1429
1430 //tell firmware "no antenna inverse"
1431 H2C_Parameter[0] = 0;
1432 H2C_Parameter[1] = 0; //internal switch type
1433 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter);
1434 }
1435 else
1436 {
1437
1438 //tell firmware "antenna inverse"
1439 H2C_Parameter[0] = 1;
1440 H2C_Parameter[1] = 0; //internal switch type
1441 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter);
1442 }
1443 }
1444
1445 if(bForceExec || (pCoexDm->curAntPosType != pCoexDm->preAntPosType))
1446 {
1447 // internal switch setting
1448 switch(antPosType)
1449 {
1450 case BTC_ANT_PATH_WIFI:
1451 if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)
1452 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);
1453 else
1454 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x280);
1455 break;
1456 case BTC_ANT_PATH_BT:
1457 if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)
1458 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x280);
1459 else
1460 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);
1461 break;
1462 default:
1463 case BTC_ANT_PATH_PTA:
1464 if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)
1465 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x200);
1466 else
1467 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x80);
1468 break;
1469 }
1470 }
1471 }
1472
1473 pCoexDm->preAntPosType = pCoexDm->curAntPosType;
1474 }
1475
1476 VOID
halbtc8723b1ant_SetAntPathDCut(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bAntennaAux,IN BOOLEAN bExtSwitch,IN BOOLEAN bTwoAntenna,IN u1Byte antennaPos,IN u1Byte wifiState)1477 halbtc8723b1ant_SetAntPathDCut(
1478 IN PBTC_COEXIST pBtCoexist,
1479 IN BOOLEAN bAntennaAux, //For 1-Ant--> 1: Antenna at S0, 0: Antenna at S1. Set 0 for 2-Ant
1480 IN BOOLEAN bExtSwitch, // 1: Ext Switch (SPDT) exist on module, 0: no Ext Switch (SPDT) exist on module
1481 IN BOOLEAN bTwoAntenna, // 1: 2-Antenna, 0:1-Antenna
1482 IN u1Byte antennaPos, //Set Antenna Pos, For 1-Ant: BTC_ANT_PATH_WIFI, BTC_ANT_PATH_BT, BTC_ANT_PATH_PTA, For 2-Ant:BTC_ANT_WIFI_AT_MAIN, BTC_ANT_WIFI_AT_Aux
1483 IN u1Byte wifiState //BTC_WIFI_STAT_INIT, BTC_WIFI_STAT_IQK, BTC_WIFI_STAT_NORMAL_OFF, BTC_WIFI_STAT_MP_OFF, BTC_WIFI_STAT_NORMAL, BTC_WIFI_STAT_ANT_DIV
1484 )
1485 {
1486 u1Byte dataLen=5;
1487 u1Byte buf[6] = {0};
1488
1489 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set BT Ant, bAntennaAux/bExtSwitch/bTwoAntenna/antennaPos/wifiState=%d/%d/%d/%d/%d\n",
1490 bAntennaAux, bExtSwitch, bTwoAntenna, antennaPos, wifiState));
1491
1492 buf[0] = dataLen;
1493
1494 if(bAntennaAux)
1495 buf[1] = 0x1;
1496
1497 if(bExtSwitch)
1498 buf[2] = 0x1;
1499
1500 if(bTwoAntenna)
1501 buf[3] = 0x1;
1502
1503 buf[4] = antennaPos;
1504
1505 buf[5] = wifiState;
1506
1507 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_CTRL_8723B_ANT, (PVOID)&buf[0]);
1508 }
1509
1510 VOID
halbtc8723b1ant_SetFwPstdma(IN PBTC_COEXIST pBtCoexist,IN u1Byte byte1,IN u1Byte byte2,IN u1Byte byte3,IN u1Byte byte4,IN u1Byte byte5)1511 halbtc8723b1ant_SetFwPstdma(
1512 IN PBTC_COEXIST pBtCoexist,
1513 IN u1Byte byte1,
1514 IN u1Byte byte2,
1515 IN u1Byte byte3,
1516 IN u1Byte byte4,
1517 IN u1Byte byte5
1518 )
1519 {
1520 u1Byte H2C_Parameter[5] ={0};
1521 u1Byte realByte1=byte1, realByte5=byte5;
1522 BOOLEAN bApEnable=FALSE;
1523
1524 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);
1525
1526 if(bApEnable)
1527 {
1528 if(byte1&BIT4 && !(byte1&BIT5))
1529 {
1530 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], FW for 1Ant AP mode\n"));
1531 realByte1 &= ~BIT4;
1532 realByte1 |= BIT5;
1533
1534 realByte5 |= BIT5;
1535 realByte5 &= ~BIT6;
1536 }
1537 }
1538
1539 H2C_Parameter[0] = realByte1;
1540 H2C_Parameter[1] = byte2;
1541 H2C_Parameter[2] = byte3;
1542 H2C_Parameter[3] = byte4;
1543 H2C_Parameter[4] = realByte5;
1544
1545 pCoexDm->psTdmaPara[0] = realByte1;
1546 pCoexDm->psTdmaPara[1] = byte2;
1547 pCoexDm->psTdmaPara[2] = byte3;
1548 pCoexDm->psTdmaPara[3] = byte4;
1549 pCoexDm->psTdmaPara[4] = realByte5;
1550
1551 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], PS-TDMA H2C cmd =0x%x%08x\n",
1552 H2C_Parameter[0],
1553 H2C_Parameter[1]<<24|H2C_Parameter[2]<<16|H2C_Parameter[3]<<8|H2C_Parameter[4]));
1554
1555 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x60, 5, H2C_Parameter);
1556 }
1557
1558
1559 VOID
halbtc8723b1ant_PsTdma(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bForceExec,IN BOOLEAN bTurnOn,IN u1Byte type)1560 halbtc8723b1ant_PsTdma(
1561 IN PBTC_COEXIST pBtCoexist,
1562 IN BOOLEAN bForceExec,
1563 IN BOOLEAN bTurnOn,
1564 IN u1Byte type
1565 )
1566 {
1567 PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;
1568 PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
1569 BOOLEAN bTurnOnByCnt=FALSE, bWifiBusy=FALSE, bWiFiNoisy=FALSE;
1570 u1Byte psTdmaTypeByCnt=0, rssiAdjustVal=0;
1571 u1Byte psTdmaByte4Val = 0x50, psTdmaByte0Val = 0x51, psTdmaByte3Val = 0x10;
1572 s1Byte nWiFiDurationAdjust = 0x0;
1573 static BOOLEAN bPreWifiBusy=FALSE;
1574
1575 pCoexDm->bCurPsTdmaOn = bTurnOn;
1576 pCoexDm->curPsTdma = type;
1577
1578 #if BT_8723B_1ANT_ANTDET_ENABLE
1579 #if BT_8723B_1ANT_ANTDET_COEXMECHANISMSWITCH_ENABLE
1580 if (pBoardInfo->btdmAntNumByAntDet == 2)
1581 {
1582 if (bTurnOn)
1583 type = type +100; //for WiFi RSSI low or BT RSSI low
1584 else
1585 type = 1; //always translate to TDMA(off,1) for TDMA-off case
1586 }
1587
1588 #endif
1589 #endif
1590
1591 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
1592
1593 if (bWifiBusy != bPreWifiBusy)
1594 {
1595 bForceExec = TRUE;
1596 bPreWifiBusy = bWifiBusy;
1597 }
1598
1599 if (pCoexDm->bCurPsTdmaOn)
1600 {
1601 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ********** TDMA(on, %d) **********\n",
1602 pCoexDm->curPsTdma));
1603 }
1604 else
1605 {
1606 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ********** TDMA(off, %d) **********\n",
1607 pCoexDm->curPsTdma));
1608 }
1609
1610 if(!bForceExec)
1611 {
1612 if( (pCoexDm->bPrePsTdmaOn == pCoexDm->bCurPsTdmaOn) &&
1613 (pCoexDm->prePsTdma == pCoexDm->curPsTdma) )
1614 return;
1615 }
1616
1617 if (pCoexSta->nScanAPNum <= 5)
1618 {
1619 nWiFiDurationAdjust = 5;
1620
1621 if (pCoexSta->nA2DPBitPool >= 35)
1622 nWiFiDurationAdjust = -10;
1623 else if (pCoexSta->nA2DPBitPool >= 45)
1624 nWiFiDurationAdjust = -15;
1625 }
1626 else if (pCoexSta->nScanAPNum >= 40)
1627 {
1628 nWiFiDurationAdjust = -15;
1629
1630 if (pCoexSta->nA2DPBitPool < 35)
1631 nWiFiDurationAdjust = -5;
1632 else if (pCoexSta->nA2DPBitPool < 45)
1633 nWiFiDurationAdjust = -10;
1634 }
1635 else if (pCoexSta->nScanAPNum >= 20)
1636 {
1637 nWiFiDurationAdjust = -10;
1638
1639 if (pCoexSta->nA2DPBitPool >= 45)
1640 nWiFiDurationAdjust = -15;
1641 }
1642 else
1643 {
1644 nWiFiDurationAdjust = 0;
1645
1646 if (pCoexSta->nA2DPBitPool >= 35)
1647 nWiFiDurationAdjust = -10;
1648 else if (pCoexSta->nA2DPBitPool >= 45)
1649 nWiFiDurationAdjust = -15;
1650 }
1651
1652 if ((type == 1) || (type == 2) || (type == 9) || (type == 11) || (type == 101)
1653 || (type == 102) || (type == 109) || (type == 101))
1654 {
1655 if (!pCoexSta->bForceLpsOn) //Native power save TDMA, only for A2DP-only case 1/2/9/11 while wifi noisy threshold > 30
1656 {
1657 psTdmaByte0Val = 0x61; //no null-pkt
1658 psTdmaByte3Val = 0x11; // no tx-pause at BT-slot
1659 psTdmaByte4Val = 0x10; // 0x778 = d/1 toggle, no dynamic slot
1660 }
1661 else
1662 {
1663 psTdmaByte0Val = 0x51; //null-pkt
1664 psTdmaByte3Val = 0x10; //tx-pause at BT-slot
1665 psTdmaByte4Val = 0x50; // 0x778 = d/1 toggle, dynamic slot
1666 }
1667 }
1668 else if ((type == 3) || (type == 13) || (type == 14) || (type == 103) || (type == 113) || (type == 114))
1669 {
1670 psTdmaByte0Val = 0x51; //null-pkt
1671 psTdmaByte3Val = 0x10; //tx-pause at BT-slot
1672 psTdmaByte4Val = 0x10; // 0x778 = d/1 toggle, no dynamic slot
1673 #if 0
1674 if (!bWifiBusy)
1675 psTdmaByte4Val = psTdmaByte4Val | 0x1; //0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts)
1676 #endif
1677 }
1678 else //native power save case
1679 {
1680 psTdmaByte0Val = 0x61; //no null-pkt
1681 psTdmaByte3Val = 0x11; // no tx-pause at BT-slot
1682 psTdmaByte4Val = 0x11; // 0x778 = d/1 toggle, no dynamic slot
1683 //psTdmaByte4Va is not defne for 0x778 = d/1, 1/1 case
1684 }
1685
1686 //if (pBtLinkInfo->bSlaveRole == TRUE)
1687 if ((pBtLinkInfo->bSlaveRole == TRUE) && (pBtLinkInfo->bA2dpExist))
1688 psTdmaByte4Val = psTdmaByte4Val | 0x1; //0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts)
1689
1690 if (type > 100)
1691 {
1692 psTdmaByte0Val = psTdmaByte0Val | 0x82; //set antenna control by SW
1693 psTdmaByte3Val = psTdmaByte3Val | 0x60; //set antenna no toggle, control by antenna diversity
1694 }
1695
1696
1697 if(bTurnOn)
1698 {
1699 switch(type)
1700 {
1701 default:
1702 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x1a, 0x1a, 0x0, psTdmaByte4Val);
1703 break;
1704 case 1:
1705 halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x3a+nWiFiDurationAdjust, 0x03, psTdmaByte3Val, psTdmaByte4Val);
1706 break;
1707 case 2:
1708 halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x2d+nWiFiDurationAdjust, 0x03, psTdmaByte3Val, psTdmaByte4Val);
1709 break;
1710 case 3:
1711 halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x3a, 0x03, psTdmaByte3Val, psTdmaByte4Val);
1712 break;
1713 case 4:
1714 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x93, 0x15, 0x3, 0x14, 0x0);
1715 break;
1716 case 5:
1717 halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x15, 0x3, psTdmaByte3Val, 0x11);
1718 break;
1719 case 6:
1720 halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x20, 0x3, psTdmaByte3Val, 0x11);
1721 break;
1722 case 7:
1723 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x13, 0xc, 0x5, 0x0, 0x0);
1724 break;
1725 case 8:
1726 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x93, 0x25, 0x3, 0x10, 0x0);
1727 break;
1728 case 9:
1729 halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x3, psTdmaByte3Val, psTdmaByte4Val);
1730 break;
1731 case 10:
1732 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x13, 0xa, 0xa, 0x0, 0x40);
1733 break;
1734 case 11:
1735 halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x03, psTdmaByte3Val, psTdmaByte4Val);
1736 break;
1737 case 12:
1738 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x0a, 0x0a, 0x0, 0x50);
1739 break;
1740 case 13:
1741 halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x3, psTdmaByte3Val, psTdmaByte4Val);
1742 break;
1743 case 14:
1744 halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x3, psTdmaByte3Val, psTdmaByte4Val);
1745 break;
1746 case 15:
1747 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x13, 0xa, 0x3, 0x8, 0x0);
1748 break;
1749 case 16:
1750 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x93, 0x15, 0x3, 0x10, 0x0);
1751 break;
1752 case 18:
1753 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x93, 0x25, 0x3, 0x10, 0x0);
1754 break;
1755 case 20:
1756 halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x3f, 0x03, psTdmaByte3Val, 0x10);
1757 break;
1758 case 21:
1759 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x61, 0x25, 0x03, 0x11, 0x11);
1760 break;
1761 case 22:
1762 halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x25, 0x03, psTdmaByte3Val, 0x10);
1763 break;
1764 case 23:
1765 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x3, 0x31, 0x18);
1766 break;
1767 case 24:
1768 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0xe3, 0x15, 0x3, 0x31, 0x18);
1769 break;
1770 case 25:
1771 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0x3, 0x31, 0x18);
1772 break;
1773 case 26:
1774 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0x3, 0x31, 0x18);
1775 break;
1776 case 27:
1777 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x3, 0x31, 0x98);
1778 break;
1779 case 28:
1780 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x69, 0x25, 0x3, 0x31, 0x0);
1781 break;
1782 case 29:
1783 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0xab, 0x1a, 0x1a, 0x1, 0x10);
1784 break;
1785 case 30:
1786 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x30, 0x3, 0x10, 0x10);
1787 break;
1788 case 31:
1789 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0xd3, 0x1a, 0x1a, 0, 0x58);
1790 break;
1791 case 32:
1792 halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x35, 0x3, psTdmaByte3Val, psTdmaByte4Val);
1793 break;
1794 case 33:
1795 halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x35, 0x3, psTdmaByte3Val, 0x10);
1796 break;
1797 case 34:
1798 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x53, 0x1a, 0x1a, 0x0, 0x10);
1799 break;
1800 case 35:
1801 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x63, 0x1a, 0x1a, 0x0, 0x10);
1802 break;
1803 case 36:
1804 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0xd3, 0x12, 0x3, 0x14, 0x50);
1805 break;
1806 case 40: // SoftAP only with no sta associated,BT disable ,TDMA mode for power saving
1807 /* here softap mode screen off will cost 70-80mA for phone */
1808 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x23, 0x18, 0x00, 0x10, 0x24);
1809 break;
1810
1811 //for 1-Ant translate to 2-Ant
1812 case 101:
1813 halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x3a+nWiFiDurationAdjust, 0x03, psTdmaByte3Val, psTdmaByte4Val);
1814 break;
1815 case 102:
1816 halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x2d+nWiFiDurationAdjust, 0x03, psTdmaByte3Val, psTdmaByte4Val);
1817 break;
1818 case 103:
1819 //halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x1d, 0x1d, 0x0, psTdmaByte4Val);
1820 halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x3a, 0x03, psTdmaByte3Val, psTdmaByte4Val);
1821 break;
1822 case 105:
1823 halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x15, 0x3, psTdmaByte3Val, 0x11);
1824 break;
1825 case 106:
1826 halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x20, 0x3, psTdmaByte3Val, 0x11);
1827 break;
1828 case 109:
1829 halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x3, psTdmaByte3Val, psTdmaByte4Val);
1830 break;
1831 case 111:
1832 halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x03, psTdmaByte3Val, psTdmaByte4Val);
1833 break;
1834 case 113:
1835 //halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x51, 0x12, 0x12, 0x0, psTdmaByte4Val);
1836 halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x3, psTdmaByte3Val, psTdmaByte4Val);
1837 break;
1838 case 114:
1839 halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x21, 0x3, psTdmaByte3Val, psTdmaByte4Val);
1840 break;
1841 case 120:
1842 halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x3f, 0x03, psTdmaByte3Val, 0x10);
1843 break;
1844 case 122:
1845 halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x25, 0x03, psTdmaByte3Val, 0x10);
1846 break;
1847 case 132:
1848 halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x25, 0x03, psTdmaByte3Val, psTdmaByte4Val);
1849 break;
1850 case 133:
1851 halbtc8723b1ant_SetFwPstdma(pBtCoexist, psTdmaByte0Val, 0x25, 0x03, psTdmaByte3Val, 0x11);
1852 break;
1853
1854 }
1855 }
1856 else
1857 {
1858
1859 // disable PS tdma
1860 switch(type)
1861 {
1862 case 8: //PTA Control
1863 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x8, 0x0, 0x0, 0x0, 0x0);
1864 break;
1865 case 0:
1866 default: //Software control, Antenna at BT side
1867 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x0, 0x0);
1868 break;
1869 case 1: // 2-Ant, 0x778=3, antenna control by antenna diversity
1870 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x48, 0x0);
1871 break;
1872 #if 0
1873 case 9: //Software control, Antenna at WiFi side
1874 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x0, 0x0);
1875 //halbtc8723b1ant_SetAntPathDCut(pBtCoexist, FALSE, FALSE, FALSE, BTC_ANT_PATH_WIFI, BTC_WIFI_STAT_NORMAL);
1876 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_WIFI, FALSE, FALSE);
1877 break;
1878 #endif
1879 }
1880 }
1881 rssiAdjustVal =0;
1882 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE, &rssiAdjustVal);
1883
1884
1885 RT_TRACE(COMP_COEX, DBG_LOUD, ("############# [BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x\n",
1886 pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x948), pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x765), pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x67)));
1887
1888 // update pre state
1889 pCoexDm->bPrePsTdmaOn = pCoexDm->bCurPsTdmaOn;
1890 pCoexDm->prePsTdma = pCoexDm->curPsTdma;
1891 }
1892
1893 BOOLEAN
halbtc8723b1ant_IsCommonAction(IN PBTC_COEXIST pBtCoexist)1894 halbtc8723b1ant_IsCommonAction(
1895 IN PBTC_COEXIST pBtCoexist
1896 )
1897 {
1898 BOOLEAN bCommon=FALSE, bWifiConnected=FALSE, bWifiBusy=FALSE;
1899
1900 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
1901 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
1902
1903 if(!bWifiConnected &&
1904 BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)
1905 {
1906 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi non connected-idle + BT non connected-idle!!\n"));
1907
1908 //halbtc8723b1ant_SwMechanism(pBtCoexist, FALSE);
1909
1910 bCommon = TRUE;
1911 }
1912 else if(bWifiConnected &&
1913 (BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus) )
1914 {
1915 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi connected + BT non connected-idle!!\n"));
1916
1917 //halbtc8723b1ant_SwMechanism(pBtCoexist, FALSE);
1918
1919 bCommon = TRUE;
1920 }
1921 else if(!bWifiConnected &&
1922 (BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus) )
1923 {
1924 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi non connected-idle + BT connected-idle!!\n"));
1925
1926 //halbtc8723b1ant_SwMechanism(pBtCoexist, FALSE);
1927
1928 bCommon = TRUE;
1929 }
1930 else if(bWifiConnected &&
1931 (BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus) )
1932 {
1933 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi connected + BT connected-idle!!\n"));
1934
1935 //halbtc8723b1ant_SwMechanism(pBtCoexist, FALSE);
1936
1937 bCommon = TRUE;
1938 }
1939 else if(!bWifiConnected &&
1940 (BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE != pCoexDm->btStatus) )
1941 {
1942 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi non connected-idle + BT Busy!!\n"));
1943
1944 //halbtc8723b1ant_SwMechanism(pBtCoexist, FALSE);
1945
1946 bCommon = TRUE;
1947 }
1948 else
1949 {
1950 if (bWifiBusy)
1951 {
1952 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi Connected-Busy + BT Busy!!\n"));
1953 }
1954 else
1955 {
1956 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi Connected-Idle + BT Busy!!\n"));
1957 }
1958
1959 bCommon = FALSE;
1960 }
1961
1962 return bCommon;
1963 }
1964
1965
1966 VOID
halbtc8723b1ant_TdmaDurationAdjustForAcl(IN PBTC_COEXIST pBtCoexist,IN u1Byte wifiStatus)1967 halbtc8723b1ant_TdmaDurationAdjustForAcl(
1968 IN PBTC_COEXIST pBtCoexist,
1969 IN u1Byte wifiStatus
1970 )
1971 {
1972 static s4Byte up,dn,m,n,WaitCount;
1973 s4Byte result; //0: no change, +1: increase WiFi duration, -1: decrease WiFi duration
1974 u1Byte retryCount=0, btInfoExt;
1975 static BOOLEAN bPreWifiBusy=FALSE;
1976 BOOLEAN bWifiBusy = FALSE;
1977
1978 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TdmaDurationAdjustForAcl()\n"));
1979
1980 if(BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY == wifiStatus)
1981 bWifiBusy = TRUE;
1982 else
1983 bWifiBusy = FALSE;
1984
1985 if( (BT_8723B_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN == wifiStatus) ||
1986 (BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN == wifiStatus) ||
1987 (BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SPECIAL_PKT == wifiStatus) )
1988 {
1989 if( pCoexDm->curPsTdma != 1 &&
1990 pCoexDm->curPsTdma != 2 &&
1991 pCoexDm->curPsTdma != 3 &&
1992 pCoexDm->curPsTdma != 9 )
1993 {
1994 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);
1995 pCoexDm->psTdmaDuAdjType = 9;
1996
1997 up = 0;
1998 dn = 0;
1999 m = 1;
2000 n= 3;
2001 result = 0;
2002 WaitCount = 0;
2003 }
2004 return;
2005 }
2006
2007 if(!pCoexDm->bAutoTdmaAdjust)
2008 {
2009 pCoexDm->bAutoTdmaAdjust = TRUE;
2010 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], first run TdmaDurationAdjust()!!\n"));
2011
2012 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);
2013 pCoexDm->psTdmaDuAdjType = 2;
2014 //============
2015 up = 0;
2016 dn = 0;
2017 m = 1;
2018 n= 3;
2019 result = 0;
2020 WaitCount = 0;
2021 }
2022 else
2023 {
2024 //accquire the BT TRx retry count from BT_Info byte2
2025 retryCount = pCoexSta->btRetryCnt;
2026 btInfoExt = pCoexSta->btInfoExt;
2027
2028 if ( (pCoexSta->lowPriorityTx) > 1050 || (pCoexSta->lowPriorityRx) > 1250 )
2029 retryCount++;
2030
2031 result = 0;
2032 WaitCount++;
2033
2034 if(retryCount == 0) // no retry in the last 2-second duration
2035 {
2036 up++;
2037 dn--;
2038
2039 if (dn <= 0)
2040 dn = 0;
2041
2042 if(up >= n) // if �s�� n ��2�� retry count��0, �h�ռeWiFi duration
2043 {
2044 WaitCount = 0;
2045 n = 3;
2046 up = 0;
2047 dn = 0;
2048 result = 1;
2049 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Increase wifi duration!!\n"));
2050 }
2051 }
2052 else if (retryCount <= 3) // <=3 retry in the last 2-second duration
2053 {
2054 up--;
2055 dn++;
2056
2057 if (up <= 0)
2058 up = 0;
2059
2060 if (dn == 2) // if �s�� 2 ��2�� retry count< 3, �h�կ�WiFi duration
2061 {
2062 if (WaitCount <= 2)
2063 m++; // �קK�@���b���level���Ӧ^
2064 else
2065 m = 1;
2066
2067 if ( m >= 20) //m �̤j�� = 20 ' �̤j120�� recheck�O�_�վ� WiFi duration.
2068 m = 20;
2069
2070 n = 3*m;
2071 up = 0;
2072 dn = 0;
2073 WaitCount = 0;
2074 result = -1;
2075 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter<3!!\n"));
2076 }
2077 }
2078 else //retry count > 3, �u�n1�� retry count > 3, �h�կ�WiFi duration
2079 {
2080 if (WaitCount == 1)
2081 m++; // �קK�@���b���level���Ӧ^
2082 else
2083 m = 1;
2084
2085 if ( m >= 20) //m �̤j�� = 20 ' �̤j120�� recheck�O�_�վ� WiFi duration.
2086 m = 20;
2087
2088 n = 3*m;
2089 up = 0;
2090 dn = 0;
2091 WaitCount = 0;
2092 result = -1;
2093 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter>3!!\n"));
2094 }
2095
2096 if(result == -1)
2097 {
2098 /* if( (BT_INFO_8723B_1ANT_A2DP_BASIC_RATE(btInfoExt)) &&
2099 ((pCoexDm->curPsTdma == 1) ||(pCoexDm->curPsTdma == 2)) )
2100 {
2101 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);
2102 pCoexDm->psTdmaDuAdjType = 9;
2103 }
2104 else */ if(pCoexDm->curPsTdma == 1)
2105 {
2106 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);
2107 pCoexDm->psTdmaDuAdjType = 2;
2108 }
2109 else if(pCoexDm->curPsTdma == 2)
2110 {
2111 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);
2112 pCoexDm->psTdmaDuAdjType = 9;
2113 }
2114 else if(pCoexDm->curPsTdma == 9)
2115 {
2116 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);
2117 pCoexDm->psTdmaDuAdjType = 11;
2118 }
2119 }
2120 else if(result == 1)
2121 {
2122 /* if( (BT_INFO_8723B_1ANT_A2DP_BASIC_RATE(btInfoExt)) &&
2123 ((pCoexDm->curPsTdma == 1) ||(pCoexDm->curPsTdma == 2)) )
2124 {
2125 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);
2126 pCoexDm->psTdmaDuAdjType = 9;
2127 }
2128 else */ if(pCoexDm->curPsTdma == 11)
2129 {
2130 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);
2131 pCoexDm->psTdmaDuAdjType = 9;
2132 }
2133 else if(pCoexDm->curPsTdma == 9)
2134 {
2135 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);
2136 pCoexDm->psTdmaDuAdjType = 2;
2137 }
2138 else if(pCoexDm->curPsTdma == 2)
2139 {
2140 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);
2141 pCoexDm->psTdmaDuAdjType = 1;
2142 }
2143 }
2144 else //no change
2145 {
2146 /* Bryant Modify
2147 if(bWifiBusy != bPreWifiBusy) //if busy / idle change
2148 {
2149 bPreWifiBusy = bWifiBusy;
2150 halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, TRUE, pCoexDm->curPsTdma);
2151 }
2152 */
2153
2154 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], ********** TDMA(on, %d) **********\n",
2155 pCoexDm->curPsTdma));
2156 }
2157
2158 if( pCoexDm->curPsTdma != 1 &&
2159 pCoexDm->curPsTdma != 2 &&
2160 pCoexDm->curPsTdma != 9 &&
2161 pCoexDm->curPsTdma != 11 )
2162 {
2163 // recover to previous adjust type
2164 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, pCoexDm->psTdmaDuAdjType);
2165 }
2166 }
2167 }
2168
2169 VOID
halbtc8723b1ant_PsTdmaCheckForPowerSaveState(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bNewPsState)2170 halbtc8723b1ant_PsTdmaCheckForPowerSaveState(
2171 IN PBTC_COEXIST pBtCoexist,
2172 IN BOOLEAN bNewPsState
2173 )
2174 {
2175 u1Byte lpsMode=0x0;
2176
2177 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_LPS_MODE, &lpsMode);
2178
2179 if(lpsMode) // already under LPS state
2180 {
2181 if(bNewPsState)
2182 {
2183 // keep state under LPS, do nothing.
2184 }
2185 else
2186 {
2187 // will leave LPS state, turn off psTdma first
2188 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
2189 }
2190 }
2191 else // NO PS state
2192 {
2193 if(bNewPsState)
2194 {
2195 // will enter LPS state, turn off psTdma first
2196 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
2197 }
2198 else
2199 {
2200 // keep state under NO PS state, do nothing.
2201 }
2202 }
2203 }
2204
2205 VOID
halbtc8723b1ant_PowerSaveState(IN PBTC_COEXIST pBtCoexist,IN u1Byte psType,IN u1Byte lpsVal,IN u1Byte rpwmVal)2206 halbtc8723b1ant_PowerSaveState(
2207 IN PBTC_COEXIST pBtCoexist,
2208 IN u1Byte psType,
2209 IN u1Byte lpsVal,
2210 IN u1Byte rpwmVal
2211 )
2212 {
2213 BOOLEAN bLowPwrDisable=FALSE;
2214
2215 switch(psType)
2216 {
2217 case BTC_PS_WIFI_NATIVE:
2218 // recover to original 32k low power setting
2219 bLowPwrDisable = FALSE;
2220 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);
2221 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_NORMAL_LPS, NULL);
2222 pCoexSta->bForceLpsOn = FALSE;
2223 break;
2224 case BTC_PS_LPS_ON:
2225 halbtc8723b1ant_PsTdmaCheckForPowerSaveState(pBtCoexist, TRUE);
2226 halbtc8723b1ant_LpsRpwm(pBtCoexist, NORMAL_EXEC, lpsVal, rpwmVal);
2227 // when coex force to enter LPS, do not enter 32k low power.
2228 bLowPwrDisable = TRUE;
2229 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);
2230 // power save must executed before psTdma.
2231 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_ENTER_LPS, NULL);
2232 pCoexSta->bForceLpsOn = TRUE;
2233 break;
2234 case BTC_PS_LPS_OFF:
2235 halbtc8723b1ant_PsTdmaCheckForPowerSaveState(pBtCoexist, FALSE);
2236 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_LEAVE_LPS, NULL);
2237 pCoexSta->bForceLpsOn = FALSE;
2238 break;
2239 default:
2240 break;
2241 }
2242 }
2243
2244 VOID
halbtc8723b1ant_ActionWifiOnly(IN PBTC_COEXIST pBtCoexist)2245 halbtc8723b1ant_ActionWifiOnly(
2246 IN PBTC_COEXIST pBtCoexist
2247 )
2248 {
2249 halbtc8723b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);
2250 halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);
2251 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, FORCE_EXEC, FALSE, FALSE);
2252 }
2253
2254 VOID
halbtc8723b1ant_MonitorBtEnableDisable(IN PBTC_COEXIST pBtCoexist)2255 halbtc8723b1ant_MonitorBtEnableDisable(
2256 IN PBTC_COEXIST pBtCoexist
2257 )
2258 {
2259 static BOOLEAN bPreBtDisabled=FALSE;
2260 static u4Byte btDisableCnt=0;
2261 BOOLEAN bBtActive=TRUE, bBtDisabled=FALSE;
2262
2263 // This function check if bt is disabled
2264
2265 if( pCoexSta->highPriorityTx == 0 &&
2266 pCoexSta->highPriorityRx == 0 &&
2267 pCoexSta->lowPriorityTx == 0 &&
2268 pCoexSta->lowPriorityRx == 0)
2269 {
2270 bBtActive = FALSE;
2271 }
2272 if( pCoexSta->highPriorityTx == 0xffff &&
2273 pCoexSta->highPriorityRx == 0xffff &&
2274 pCoexSta->lowPriorityTx == 0xffff &&
2275 pCoexSta->lowPriorityRx == 0xffff)
2276 {
2277 bBtActive = FALSE;
2278 }
2279 if(bBtActive)
2280 {
2281 btDisableCnt = 0;
2282 bBtDisabled = FALSE;
2283 }
2284 else
2285 {
2286 btDisableCnt++;
2287 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], bt all counters=0, %d times!!\n", btDisableCnt));
2288 if(btDisableCnt >= 2)
2289 {
2290 bBtDisabled = TRUE;
2291 }
2292 }
2293 if(bPreBtDisabled != bBtDisabled)
2294 {
2295 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is from %s to %s!!\n", (bPreBtDisabled ? "disabled":"enabled"),
2296 (bBtDisabled ? "disabled":"enabled")));
2297
2298 bPreBtDisabled = bBtDisabled;
2299 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);
2300 if(bBtDisabled)
2301 {
2302 halbtc8723b1ant_ActionWifiOnly(pBtCoexist);
2303 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_LEAVE_LPS, NULL);
2304 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_NORMAL_LPS, NULL);
2305 }
2306 }
2307 }
2308
2309 //=============================================
2310 //
2311 // Software Coex Mechanism start
2312 //
2313 //=============================================
2314
2315 // SCO only or SCO+PAN(HS)
2316
2317 /*
2318 VOID
2319 halbtc8723b1ant_ActionSco(
2320 IN PBTC_COEXIST pBtCoexist
2321 )
2322 {
2323 halbtc8723b1ant_SwMechanism(pBtCoexist, TRUE);
2324 }
2325
2326
2327 VOID
2328 halbtc8723b1ant_ActionHid(
2329 IN PBTC_COEXIST pBtCoexist
2330 )
2331 {
2332 halbtc8723b1ant_SwMechanism(pBtCoexist, TRUE);
2333 }
2334
2335 //A2DP only / PAN(EDR) only/ A2DP+PAN(HS)
2336 VOID
2337 halbtc8723b1ant_ActionA2dp(
2338 IN PBTC_COEXIST pBtCoexist
2339 )
2340 {
2341 halbtc8723b1ant_SwMechanism(pBtCoexist, FALSE);
2342 }
2343
2344 VOID
2345 halbtc8723b1ant_ActionA2dpPanHs(
2346 IN PBTC_COEXIST pBtCoexist
2347 )
2348 {
2349 halbtc8723b1ant_SwMechanism(pBtCoexist, FALSE);
2350 }
2351
2352 VOID
2353 halbtc8723b1ant_ActionPanEdr(
2354 IN PBTC_COEXIST pBtCoexist
2355 )
2356 {
2357 halbtc8723b1ant_SwMechanism(pBtCoexist, FALSE);
2358 }
2359
2360 //PAN(HS) only
2361 VOID
2362 halbtc8723b1ant_ActionPanHs(
2363 IN PBTC_COEXIST pBtCoexist
2364 )
2365 {
2366 halbtc8723b1ant_SwMechanism(pBtCoexist, FALSE);
2367 }
2368
2369 //PAN(EDR)+A2DP
2370 VOID
2371 halbtc8723b1ant_ActionPanEdrA2dp(
2372 IN PBTC_COEXIST pBtCoexist
2373 )
2374 {
2375 halbtc8723b1ant_SwMechanism(pBtCoexist, FALSE);
2376 }
2377
2378 VOID
2379 halbtc8723b1ant_ActionPanEdrHid(
2380 IN PBTC_COEXIST pBtCoexist
2381 )
2382 {
2383 halbtc8723b1ant_SwMechanism(pBtCoexist, TRUE);
2384 }
2385
2386 // HID+A2DP+PAN(EDR)
2387 VOID
2388 halbtc8723b1ant_ActionHidA2dpPanEdr(
2389 IN PBTC_COEXIST pBtCoexist
2390 )
2391 {
2392 halbtc8723b1ant_SwMechanism(pBtCoexist, TRUE);
2393 }
2394
2395 VOID
2396 halbtc8723b1ant_ActionHidA2dp(
2397 IN PBTC_COEXIST pBtCoexist
2398 )
2399 {
2400 halbtc8723b1ant_SwMechanism(pBtCoexist, TRUE);
2401 }
2402
2403 */
2404
2405 //=============================================
2406 //
2407 // Non-Software Coex Mechanism start
2408 //
2409 //=============================================
2410 VOID
halbtc8723b1ant_ActionBtWhckTest(IN PBTC_COEXIST pBtCoexist)2411 halbtc8723b1ant_ActionBtWhckTest(
2412 IN PBTC_COEXIST pBtCoexist
2413 )
2414 {
2415 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2416
2417 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
2418 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
2419 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
2420 }
2421
2422 VOID
halbtc8723b1ant_ActionWifiMultiPort(IN PBTC_COEXIST pBtCoexist)2423 halbtc8723b1ant_ActionWifiMultiPort(
2424 IN PBTC_COEXIST pBtCoexist
2425 )
2426 {
2427 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2428
2429 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
2430 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
2431 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
2432 }
2433
2434 VOID
halbtc8723b1ant_ActionHs(IN PBTC_COEXIST pBtCoexist)2435 halbtc8723b1ant_ActionHs(
2436 IN PBTC_COEXIST pBtCoexist
2437 )
2438 {
2439 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);
2440 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
2441 }
2442
2443 VOID
halbtc8723b1ant_ActionBtInquiry(IN PBTC_COEXIST pBtCoexist)2444 halbtc8723b1ant_ActionBtInquiry(
2445 IN PBTC_COEXIST pBtCoexist
2446 )
2447 {
2448 PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
2449 BOOLEAN bWifiConnected=FALSE, bApEnable=FALSE, bWifiBusy=FALSE, bBtBusy=FALSE;
2450
2451 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);
2452 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
2453 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
2454 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);
2455
2456 if ( (!bWifiConnected) && (!pCoexSta->bWiFiIsHighPriTask) )
2457 {
2458 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2459 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
2460 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
2461 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
2462 }
2463 else if( (pBtLinkInfo->bScoExist) || (pBtLinkInfo->bHidExist) || (pBtLinkInfo->bA2dpExist) )
2464 {
2465 // SCO/HID/A2DP busy
2466 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2467
2468 if (pCoexSta->bC2hBtRemoteNameReq)
2469 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 33);
2470 else
2471 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
2472
2473 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2474 }
2475 else if ( (pBtLinkInfo->bPanExist) || (bWifiBusy) )
2476 {
2477 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2478
2479 if (pCoexSta->bC2hBtRemoteNameReq)
2480 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 33);
2481 else
2482 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
2483
2484 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2485 }
2486 else
2487 {
2488 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2489
2490 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
2491 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
2492 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
2493
2494 }
2495 }
2496
2497 VOID
halbtc8723b1ant_ActionBtScoHidOnlyBusy(IN PBTC_COEXIST pBtCoexist,IN u1Byte wifiStatus)2498 halbtc8723b1ant_ActionBtScoHidOnlyBusy(
2499 IN PBTC_COEXIST pBtCoexist,
2500 IN u1Byte wifiStatus
2501 )
2502 {
2503 PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
2504 BOOLEAN bWifiConnected=FALSE;
2505 u1Byte wifiRssiState=BTC_RSSI_STATE_HIGH;
2506
2507 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
2508
2509 // tdma and coex table
2510
2511 if(pBtLinkInfo->bScoExist)
2512 {
2513 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);
2514 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 5);
2515 }
2516 else //HID
2517 {
2518 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);
2519 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 5);
2520 }
2521 }
2522
2523 VOID
halbtc8723b1ant_ActionWifiConnectedBtAclBusy(IN PBTC_COEXIST pBtCoexist,IN u1Byte wifiStatus)2524 halbtc8723b1ant_ActionWifiConnectedBtAclBusy(
2525 IN PBTC_COEXIST pBtCoexist,
2526 IN u1Byte wifiStatus
2527 )
2528 {
2529 u1Byte btRssiState;
2530
2531 PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
2532 btRssiState = halbtc8723b1ant_BtRssiState(2, 28, 0);
2533
2534 if ( (pCoexSta->lowPriorityRx >= 950) && (!pCoexSta->bUnderIps) )
2535 {
2536 pBtLinkInfo->bSlaveRole = TRUE;
2537 }
2538 else
2539 {
2540 pBtLinkInfo->bSlaveRole = FALSE;
2541 }
2542
2543 if(pBtLinkInfo->bHidOnly) //HID
2544 {
2545 halbtc8723b1ant_ActionBtScoHidOnlyBusy(pBtCoexist, wifiStatus);
2546 pCoexDm->bAutoTdmaAdjust = FALSE;
2547 return;
2548 }
2549 else if(pBtLinkInfo->bA2dpOnly) //A2DP
2550 {
2551 if(BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE == wifiStatus)
2552 {
2553 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
2554 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2555 pCoexDm->bAutoTdmaAdjust = FALSE;
2556 }
2557 else
2558 {
2559 halbtc8723b1ant_TdmaDurationAdjustForAcl(pBtCoexist, wifiStatus);
2560 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2561 pCoexDm->bAutoTdmaAdjust = TRUE;
2562 }
2563 }
2564 else if ( ((pBtLinkInfo->bA2dpExist) && (pBtLinkInfo->bPanExist)) ||
2565 (pBtLinkInfo->bHidExist&&pBtLinkInfo->bA2dpExist&&pBtLinkInfo->bPanExist) ) //A2DP+PAN(OPP,FTP), HID+A2DP+PAN(OPP,FTP)
2566 {
2567 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);
2568 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2569 pCoexDm->bAutoTdmaAdjust = FALSE;
2570 }
2571 else if(pBtLinkInfo->bHidExist&&pBtLinkInfo->bA2dpExist) //HID+A2DP
2572 {
2573 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);
2574 pCoexDm->bAutoTdmaAdjust = FALSE;
2575
2576 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 3);
2577 }
2578 else if( (pBtLinkInfo->bPanOnly) || (pBtLinkInfo->bHidExist&&pBtLinkInfo->bPanExist) ) //PAN(OPP,FTP), HID+PAN(OPP,FTP)
2579 {
2580 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);
2581 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2582 pCoexDm->bAutoTdmaAdjust = FALSE;
2583 }
2584 else
2585 {
2586 //BT no-profile busy (0x9)
2587 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 33);
2588 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2589 pCoexDm->bAutoTdmaAdjust = FALSE;
2590 }
2591 }
2592
2593 VOID
halbtc8723b1ant_ActionWifiNotConnected(IN PBTC_COEXIST pBtCoexist)2594 halbtc8723b1ant_ActionWifiNotConnected(
2595 IN PBTC_COEXIST pBtCoexist
2596 )
2597 {
2598 // power save state
2599 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2600
2601 // tdma and coex table
2602 halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);
2603 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
2604 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
2605 }
2606
2607 VOID
halbtc8723b1ant_ActionWifiNotConnectedScan(IN PBTC_COEXIST pBtCoexist)2608 halbtc8723b1ant_ActionWifiNotConnectedScan(
2609 IN PBTC_COEXIST pBtCoexist
2610 )
2611 {
2612 PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
2613
2614 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2615
2616 // tdma and coex table
2617 if(BT_8723B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)
2618 {
2619 if (pBtLinkInfo->bA2dpExist)
2620 {
2621 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
2622 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2623 }
2624 else if (pBtLinkInfo->bA2dpExist && pBtLinkInfo->bPanExist)
2625 {
2626 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 22);
2627 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2628 }
2629 else
2630 {
2631 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);
2632 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2633 }
2634 }
2635 else if( (BT_8723B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||
2636 (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )
2637 {
2638 halbtc8723b1ant_ActionBtScoHidOnlyBusy(pBtCoexist,
2639 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN);
2640 }
2641 else
2642 {
2643 //Bryant Add
2644 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
2645 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
2646 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
2647 }
2648 }
2649
2650 VOID
halbtc8723b1ant_ActionWifiNotConnectedAssoAuth(IN PBTC_COEXIST pBtCoexist)2651 halbtc8723b1ant_ActionWifiNotConnectedAssoAuth(
2652 IN PBTC_COEXIST pBtCoexist
2653 )
2654 {
2655 PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
2656
2657 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2658
2659 // tdma and coex table
2660 if( (pBtLinkInfo->bScoExist) || (pBtLinkInfo->bHidExist) || (pBtLinkInfo->bA2dpExist) )
2661 {
2662 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
2663 halbtc8723b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 4);
2664 }
2665 else if (pBtLinkInfo->bPanExist)
2666 {
2667 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);
2668 halbtc8723b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 4);
2669 }
2670 else
2671 {
2672 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
2673 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
2674 halbtc8723b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 2);
2675 }
2676 }
2677
2678 VOID
halbtc8723b1ant_ActionWifiConnectedScan(IN PBTC_COEXIST pBtCoexist)2679 halbtc8723b1ant_ActionWifiConnectedScan(
2680 IN PBTC_COEXIST pBtCoexist
2681 )
2682 {
2683 PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
2684
2685 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2686
2687 // tdma and coex table
2688 if(BT_8723B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)
2689 {
2690 if (pBtLinkInfo->bA2dpExist)
2691 {
2692 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
2693 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2694 }
2695 else if (pBtLinkInfo->bA2dpExist && pBtLinkInfo->bPanExist)
2696 {
2697 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 22);
2698 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2699 }
2700 else
2701 {
2702 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);
2703 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2704 }
2705 }
2706 else if( (BT_8723B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||
2707 (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )
2708 {
2709 halbtc8723b1ant_ActionBtScoHidOnlyBusy(pBtCoexist,
2710 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN);
2711 }
2712 else
2713 {
2714 //Bryant Add
2715 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
2716 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
2717 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
2718 }
2719 }
2720
2721 VOID
halbtc8723b1ant_ActionWifiConnectedSpecialPacket(IN PBTC_COEXIST pBtCoexist)2722 halbtc8723b1ant_ActionWifiConnectedSpecialPacket(
2723 IN PBTC_COEXIST pBtCoexist
2724 )
2725 {
2726 PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
2727 BOOLEAN bWifiBusy = FALSE;
2728
2729 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
2730
2731 //no special packet process for both WiFi and BT very busy
2732 if ((bWifiBusy) && ((pBtLinkInfo->bPanExist) || (pCoexSta->nNumOfProfile >= 2)))
2733 return;
2734
2735 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2736
2737 // tdma and coex table
2738 if((pBtLinkInfo->bScoExist) || (pBtLinkInfo->bHidExist))
2739 {
2740 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
2741 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 5);
2742 }
2743 else if (pBtLinkInfo->bA2dpExist)
2744 {
2745 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 32);
2746 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2747 }
2748 else if(pBtLinkInfo->bPanExist)
2749 {
2750 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 20);
2751 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
2752 }
2753 else
2754 {
2755 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
2756 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
2757 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
2758 }
2759 }
2760
2761 VOID
halbtc8723b1ant_ActionWifiConnected(IN PBTC_COEXIST pBtCoexist)2762 halbtc8723b1ant_ActionWifiConnected(
2763 IN PBTC_COEXIST pBtCoexist
2764 )
2765 {
2766 BOOLEAN bWifiBusy=FALSE;
2767 BOOLEAN bScan=FALSE, bLink=FALSE, bRoam=FALSE;
2768 BOOLEAN bUnder4way=FALSE, bApEnable=FALSE;
2769 u4Byte wifiBw;
2770
2771 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CoexForWifiConnect()===>\n"));
2772
2773 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way);
2774 if(bUnder4way)
2775 {
2776 halbtc8723b1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);
2777 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CoexForWifiConnect(), return for wifi is under 4way<===\n"));
2778 return;
2779 }
2780
2781 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
2782 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
2783 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
2784 if(bScan || bLink || bRoam)
2785 {
2786 if(bScan)
2787 halbtc8723b1ant_ActionWifiConnectedScan(pBtCoexist);
2788 else
2789 halbtc8723b1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);
2790 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CoexForWifiConnect(), return for wifi is under scan<===\n"));
2791 return;
2792 }
2793
2794 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);
2795 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
2796
2797 // power save state
2798 if(!bApEnable && BT_8723B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus && !pBtCoexist->btLinkInfo.bHidOnly)
2799 {
2800 if(pBtCoexist->btLinkInfo.bA2dpOnly) //A2DP
2801 {
2802 if(!bWifiBusy)
2803 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2804 else //busy
2805 {
2806 if (pCoexSta->nScanAPNum >= BT_8723B_1ANT_WIFI_NOISY_THRESH) //no force LPS, no PS-TDMA, use pure TDMA
2807 {
2808 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2809 }
2810 else
2811 {
2812 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
2813 }
2814 }
2815 }
2816 else if ((pCoexSta->bPanExist == FALSE) && (pCoexSta->bA2dpExist == FALSE) && (pCoexSta->bHidExist == FALSE))
2817 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2818 else
2819 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
2820 }
2821 else
2822 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2823
2824 // tdma and coex table
2825 if(!bWifiBusy)
2826 {
2827 if(BT_8723B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)
2828 {
2829 halbtc8723b1ant_ActionWifiConnectedBtAclBusy(pBtCoexist,
2830 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE);
2831 }
2832 else if( (BT_8723B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||
2833 (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )
2834 {
2835 halbtc8723b1ant_ActionBtScoHidOnlyBusy(pBtCoexist,
2836 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE);
2837 }
2838 else
2839 {
2840 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
2841 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
2842 if ( (pCoexSta->highPriorityTx) + (pCoexSta->highPriorityRx) <= 60 )
2843 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
2844 else
2845 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
2846 }
2847 }
2848 else
2849 {
2850 if(BT_8723B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus)
2851 {
2852 halbtc8723b1ant_ActionWifiConnectedBtAclBusy(pBtCoexist,
2853 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY);
2854 }
2855 else if( (BT_8723B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||
2856 (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )
2857 {
2858 halbtc8723b1ant_ActionBtScoHidOnlyBusy(pBtCoexist,
2859 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY);
2860 }
2861 else
2862 {
2863 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);
2864 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, NORMAL_EXEC, FALSE, FALSE);
2865 if ( (pCoexSta->highPriorityTx) + (pCoexSta->highPriorityRx) <= 60 )
2866 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
2867 else
2868 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
2869 }
2870 }
2871 }
2872
2873 VOID
halbtc8723b1ant_RunSwCoexistMechanism(IN PBTC_COEXIST pBtCoexist)2874 halbtc8723b1ant_RunSwCoexistMechanism(
2875 IN PBTC_COEXIST pBtCoexist
2876 )
2877 {
2878 u1Byte algorithm=0;
2879
2880 algorithm = halbtc8723b1ant_ActionAlgorithm(pBtCoexist);
2881 pCoexDm->curAlgorithm = algorithm;
2882
2883 if(halbtc8723b1ant_IsCommonAction(pBtCoexist))
2884 {
2885
2886 }
2887 else
2888 {
2889 switch(pCoexDm->curAlgorithm)
2890 {
2891 case BT_8723B_1ANT_COEX_ALGO_SCO:
2892 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = SCO.\n"));
2893 //halbtc8723b1ant_ActionSco(pBtCoexist);
2894 break;
2895 case BT_8723B_1ANT_COEX_ALGO_HID:
2896 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = HID.\n"));
2897 //halbtc8723b1ant_ActionHid(pBtCoexist);
2898 break;
2899 case BT_8723B_1ANT_COEX_ALGO_A2DP:
2900 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = A2DP.\n"));
2901 //halbtc8723b1ant_ActionA2dp(pBtCoexist);
2902 break;
2903 case BT_8723B_1ANT_COEX_ALGO_A2DP_PANHS:
2904 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = A2DP+PAN(HS).\n"));
2905 //halbtc8723b1ant_ActionA2dpPanHs(pBtCoexist);
2906 break;
2907 case BT_8723B_1ANT_COEX_ALGO_PANEDR:
2908 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = PAN(EDR).\n"));
2909 //halbtc8723b1ant_ActionPanEdr(pBtCoexist);
2910 break;
2911 case BT_8723B_1ANT_COEX_ALGO_PANHS:
2912 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = HS mode.\n"));
2913 //halbtc8723b1ant_ActionPanHs(pBtCoexist);
2914 break;
2915 case BT_8723B_1ANT_COEX_ALGO_PANEDR_A2DP:
2916 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = PAN+A2DP.\n"));
2917 //halbtc8723b1ant_ActionPanEdrA2dp(pBtCoexist);
2918 break;
2919 case BT_8723B_1ANT_COEX_ALGO_PANEDR_HID:
2920 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = PAN(EDR)+HID.\n"));
2921 //halbtc8723b1ant_ActionPanEdrHid(pBtCoexist);
2922 break;
2923 case BT_8723B_1ANT_COEX_ALGO_HID_A2DP_PANEDR:
2924 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = HID+A2DP+PAN.\n"));
2925 //halbtc8723b1ant_ActionHidA2dpPanEdr(pBtCoexist);
2926 break;
2927 case BT_8723B_1ANT_COEX_ALGO_HID_A2DP:
2928 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = HID+A2DP.\n"));
2929 //halbtc8723b1ant_ActionHidA2dp(pBtCoexist);
2930 break;
2931 default:
2932 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action algorithm = coexist All Off!!\n"));
2933 //halbtc8723b1ant_CoexAllOff(pBtCoexist);
2934 break;
2935 }
2936 pCoexDm->preAlgorithm = pCoexDm->curAlgorithm;
2937 }
2938 }
2939
2940 VOID
halbtc8723b1ant_RunCoexistMechanism(IN PBTC_COEXIST pBtCoexist)2941 halbtc8723b1ant_RunCoexistMechanism(
2942 IN PBTC_COEXIST pBtCoexist
2943 )
2944 {
2945 PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
2946 BOOLEAN bWifiConnected=FALSE, bBtHsOn=FALSE, bWifiBusy = FALSE;
2947 BOOLEAN bIncreaseScanDevNum=FALSE;
2948 BOOLEAN bBtCtrlAggBufSize=FALSE;
2949 BOOLEAN bMiracastPlusBt=FALSE;
2950 u1Byte aggBufSize=5;
2951 u1Byte wifiRssiState=BTC_RSSI_STATE_HIGH;
2952 u4Byte wifiLinkStatus=0;
2953 u4Byte numOfWifiLink=0, wifiBw;
2954 u1Byte iotPeer=BTC_IOT_PEER_UNKNOWN;
2955
2956 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RunCoexistMechanism()===>\n"));
2957
2958 if(pBtCoexist->bManualControl)
2959 {
2960 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"));
2961 return;
2962 }
2963
2964 if(pBtCoexist->bStopCoexDm)
2965 {
2966 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RunCoexistMechanism(), return for Stop Coex DM <===\n"));
2967 return;
2968 }
2969
2970 if(pCoexSta->bUnderIps)
2971 {
2972 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], wifi is under IPS !!!\n"));
2973 return;
2974 }
2975
2976 if(pCoexSta->bBtWhckTest)
2977 {
2978 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is under WHCK TEST!!!\n"));
2979 halbtc8723b1ant_ActionBtWhckTest(pBtCoexist);
2980 return;
2981 }
2982
2983 if( (BT_8723B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus) ||
2984 (BT_8723B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||
2985 (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )
2986 {
2987 bIncreaseScanDevNum = TRUE;
2988 }
2989
2990 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_INC_SCAN_DEV_NUM, &bIncreaseScanDevNum);
2991 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
2992 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
2993
2994 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);
2995 numOfWifiLink = wifiLinkStatus>>16;
2996
2997 if((numOfWifiLink>=2) || (wifiLinkStatus&WIFI_P2P_GO_CONNECTED))
2998 {
2999 RT_TRACE(COMP_COEX, DBG_LOUD, ("############# [BTCoex], Multi-Port numOfWifiLink = %d, wifiLinkStatus = 0x%x\n", numOfWifiLink,wifiLinkStatus) );
3000
3001 if(pBtLinkInfo->bBtLinkExist)
3002 {
3003 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 1, 1, 0, 1);
3004 bMiracastPlusBt = TRUE;
3005 }
3006 else
3007 {
3008 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);
3009 bMiracastPlusBt = FALSE;
3010 }
3011 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_MIRACAST_PLUS_BT, &bMiracastPlusBt);
3012 halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, bBtCtrlAggBufSize, aggBufSize);
3013
3014 if (( (pBtLinkInfo->bA2dpExist) || (bWifiBusy) ) && (pCoexSta->bC2hBtInquiryPage) )
3015 {
3016 RT_TRACE(COMP_COEX, DBG_LOUD, ("############# [BTCoex], BT Is Inquirying \n") );
3017 halbtc8723b1ant_ActionBtInquiry(pBtCoexist);
3018 }
3019 else
3020 halbtc8723b1ant_ActionWifiMultiPort(pBtCoexist);
3021
3022 return;
3023 }
3024 else
3025 {
3026 bMiracastPlusBt = FALSE;
3027 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_MIRACAST_PLUS_BT, &bMiracastPlusBt);
3028 }
3029
3030 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
3031
3032 if ( (pBtLinkInfo->bBtLinkExist) && (bWifiConnected) )
3033 {
3034 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 1, 1, 0, 1);
3035
3036 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_IOT_PEER, &iotPeer);
3037
3038 if(BTC_IOT_PEER_CISCO != iotPeer)
3039 {
3040 if(pBtLinkInfo->bScoExist)//if (pBtLinkInfo->bBtHiPriLinkExist)
3041 //halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x5);
3042 halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x5);
3043 else
3044 halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x5);
3045 //halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, TRUE, 0x8);
3046 }
3047 else
3048 {
3049 if(pBtLinkInfo->bScoExist)
3050 halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x5);
3051 else
3052 {
3053 if (BTC_WIFI_BW_HT40==wifiBw)
3054 halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, TRUE, 0x10);
3055 else
3056 halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, TRUE, 0x8);
3057 }
3058 }
3059
3060 halbtc8723b1ant_SwMechanism(pBtCoexist, TRUE);
3061 halbtc8723b1ant_RunSwCoexistMechanism(pBtCoexist); //just print debug message
3062 }
3063 else
3064 {
3065 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);
3066
3067 halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x5);
3068
3069 halbtc8723b1ant_SwMechanism(pBtCoexist, FALSE);
3070 halbtc8723b1ant_RunSwCoexistMechanism(pBtCoexist); ////just print debug message
3071 }
3072
3073 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
3074 if(pCoexSta->bC2hBtInquiryPage)
3075 {
3076 RT_TRACE(COMP_COEX, DBG_LOUD, ("############# [BTCoex], BT Is Inquirying \n") );
3077 halbtc8723b1ant_ActionBtInquiry(pBtCoexist);
3078 return;
3079 }
3080 else if(bBtHsOn)
3081 {
3082 halbtc8723b1ant_ActionHs(pBtCoexist);
3083 return;
3084 }
3085
3086
3087 if(!bWifiConnected)
3088 {
3089 BOOLEAN bScan=FALSE, bLink=FALSE, bRoam=FALSE;
3090
3091 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], wifi is non connected-idle !!!\n"));
3092
3093 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
3094 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
3095 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
3096
3097 if(bScan || bLink || bRoam)
3098 {
3099 if (bScan)
3100 halbtc8723b1ant_ActionWifiNotConnectedScan(pBtCoexist);
3101 else
3102 halbtc8723b1ant_ActionWifiNotConnectedAssoAuth(pBtCoexist);
3103 }
3104 else
3105 halbtc8723b1ant_ActionWifiNotConnected(pBtCoexist);
3106 }
3107 else // wifi LPS/Busy
3108 {
3109 halbtc8723b1ant_ActionWifiConnected(pBtCoexist);
3110 }
3111 }
3112
3113 u4Byte
halbtc8723b1ant_PSD_Log2Base(IN PBTC_COEXIST pBtCoexist,IN u4Byte val)3114 halbtc8723b1ant_PSD_Log2Base(
3115 IN PBTC_COEXIST pBtCoexist,
3116 IN u4Byte val
3117
3118 )
3119 {
3120 u1Byte i,j;
3121 u4Byte tmp, tmp2, val_integerdB=0, tindex, shiftcount=0;
3122 u4Byte result,val_fractiondB=0,Table_fraction[21]= {0,432, 332, 274, 232, 200,
3123 174, 151,132,115,100,86,74,62,51,42,
3124 32,23,15,7,0};
3125
3126 if (val == 0)
3127 return 0;
3128
3129 tmp = val;
3130
3131 while(1)
3132 {
3133 if (tmp == 1)
3134 break;
3135 else
3136 {
3137 tmp = (tmp >> 1);
3138 shiftcount++;
3139 }
3140 }
3141
3142
3143 val_integerdB = shiftcount+1;
3144
3145 tmp2=1;
3146 for (j=1; j<= val_integerdB;j++)
3147 tmp2 = tmp2*2;
3148
3149 tmp = (val*100) /tmp2;
3150 tindex = tmp/5;
3151
3152 if (tindex > 20)
3153 tindex = 20;
3154
3155 val_fractiondB = Table_fraction[tindex];
3156
3157 result = val_integerdB*100 - val_fractiondB;
3158
3159 return (result);
3160
3161
3162 }
3163
3164 VOID
halbtc8723b1ant_InitCoexDm(IN PBTC_COEXIST pBtCoexist)3165 halbtc8723b1ant_InitCoexDm(
3166 IN PBTC_COEXIST pBtCoexist
3167 )
3168 {
3169 // force to reset coex mechanism
3170
3171 // sw all off
3172 halbtc8723b1ant_SwMechanism(pBtCoexist, FALSE);
3173
3174 //halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);
3175 //halbtc8723b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);
3176
3177 pCoexSta->popEventCnt = 0;
3178 }
3179
3180 VOID
halbtc8723b1ant_InitHwConfig(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bBackUp,IN BOOLEAN bWifiOnly)3181 halbtc8723b1ant_InitHwConfig(
3182 IN PBTC_COEXIST pBtCoexist,
3183 IN BOOLEAN bBackUp,
3184 IN BOOLEAN bWifiOnly
3185 )
3186 {
3187 PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;
3188 u4Byte u4Tmp=0;//, fwVer;
3189 u2Byte u2Tmp=0;
3190 u1Byte u1Tmp=0, u1Tmpa=0, u1Tmpb=0;
3191 u1Byte H2C_Parameter[2] ={0};
3192
3193 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], 1Ant Init HW Config!!\n"));
3194
3195 pPsdScan->nAntDet_IsAntDetAvailable = FALSE;
3196
3197 //0xf0[15:12] --> Chip Cut information
3198 pCoexSta->nCutVersion = (pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xf1) & 0xf0) >> 4;
3199
3200 #if 0//move to BTC_MEDIA_CONNECT
3201 if(bBackUp)
3202 {
3203 pCoexDm->backupArfrCnt1 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x430);
3204 pCoexDm->backupArfrCnt2 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x434);
3205 pCoexDm->backupRetryLimit = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x42a);
3206 pCoexDm->backupAmpduMaxTime = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x456);
3207 }
3208 #endif
3209 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x550, 0x8, 0x1); //enable TBTT nterrupt
3210
3211 // 0x790[5:0]=0x5
3212 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x790, 0x5);
3213
3214 // Enable counter statistics
3215 //pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc); //0x76e[3] =1, WLAN_Act control by PTA
3216 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x778, 0x1);
3217 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x40, 0x20, 0x1);
3218
3219
3220 //pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x1); //BT select s0/s1 is controlled by WiFi
3221
3222 halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);
3223
3224 //Antenna config
3225 if(bWifiOnly)
3226 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_WIFI, FORCE_EXEC, TRUE, FALSE);
3227 else
3228 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FORCE_EXEC, TRUE, FALSE);
3229
3230 #if 0
3231 if(bWifiOnly)
3232 {
3233 halbtc8723b1ant_SetAntPathDCut(pBtCoexist, FALSE, FALSE, FALSE, BTC_ANT_PATH_WIFI, BTC_WIFI_STAT_INIT);
3234 halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8);
3235 }
3236 else
3237 halbtc8723b1ant_SetAntPathDCut(pBtCoexist, FALSE, FALSE, FALSE, BTC_ANT_PATH_BT, BTC_WIFI_STAT_INIT);
3238 #endif
3239
3240
3241
3242 // PTA parameter
3243 halbtc8723b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);
3244
3245 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x948);
3246 u1Tmpa = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x765);
3247 u1Tmpb = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x67);
3248
3249 RT_TRACE(COMP_COEX, DBG_LOUD, ("############# [BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x\n",
3250 u4Tmp, u1Tmpa, u1Tmpb));
3251 }
3252
3253
3254
3255
3256
3257 VOID
halbtc8723b1ant_MechanismSwitch(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bSwitchTo2Antenna)3258 halbtc8723b1ant_MechanismSwitch(
3259 IN PBTC_COEXIST pBtCoexist,
3260 IN BOOLEAN bSwitchTo2Antenna
3261 )
3262 {
3263
3264 if (bSwitchTo2Antenna) // 1-Ant -> 2-Ant
3265 {
3266 //un-lock TRx Mask setup for 8723b f-cut
3267 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xdd, 0x80, 0x1);
3268 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xdf, 0x1, 0x1);
3269 //WiFi TRx Mask on
3270 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
3271
3272 //BT TRx Mask un-lock 0x2c[0], 0x30[0] = 1
3273 pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x2c, 0x7c45);
3274 pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x30, 0x7c45);
3275
3276 //BT TRx Mask on
3277 pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x3c, 0x1);
3278
3279 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FORCE_EXEC, FALSE, FALSE);
3280 }
3281 else
3282 {
3283 //WiFi TRx Mask on
3284 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x780);
3285
3286 //lock TRx Mask setup for 8723b f-cut
3287 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xdd, 0x80, 0x0);
3288 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xdf, 0x1, 0x0);
3289
3290 //BT TRx Mask on
3291 pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x3c, 0x15);
3292
3293 //BT TRx Mask ock 0x2c[0], 0x30[0] = 0
3294 pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x2c, 0x7c44);
3295 pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x30, 0x7c44);
3296
3297
3298 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, FORCE_EXEC, FALSE, FALSE);
3299 }
3300
3301 }
3302
3303
3304
3305
3306 VOID
halbtc8723b1ant_PSD_ShowAntennaDetectResult(IN PBTC_COEXIST pBtCoexist)3307 halbtc8723b1ant_PSD_ShowAntennaDetectResult(
3308 IN PBTC_COEXIST pBtCoexist
3309 )
3310 {
3311 pu1Byte cliBuf=pBtCoexist->cliBuf;
3312 PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;
3313
3314 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n============[Antenna Detection info] ============\n");
3315 CL_PRINTF(cliBuf);
3316
3317 if (pPsdScan->nAntDet_Result == 1)
3318 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s (>%d)", "Ant Det Result", "2-Antenna (Bad-Isolation)",
3319 BT_8723B_1ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION);
3320 else if (pPsdScan->nAntDet_Result == 2)
3321 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s (%d~%d)", "Ant Det Result", "2-Antenna (Good-Isolation)",
3322 BT_8723B_1ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION+pPsdScan->nAntDet_ThresOffset, BT_8723B_1ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION);
3323 else
3324 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s (%d~%d)", "Ant Det Result", "1-Antenna",
3325 BT_8723B_1ANT_ANTDET_PSDTHRES_1ANT, BT_8723B_1ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION+pPsdScan->nAntDet_ThresOffset);
3326
3327 CL_PRINTF(cliBuf);
3328
3329 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s ", "Antenna Detection Finish",
3330 (pBoardInfo->btdmAntDetFinish? "Yes":"No"));
3331 CL_PRINTF(cliBuf);
3332
3333 switch(pPsdScan->nAntDet_Result)
3334 {
3335 case 0:
3336 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "(BT is not available)");
3337 break;
3338 case 1: // 2-Ant bad-isolation
3339 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "(BT is available)");
3340 break;
3341 case 2: // 2-Ant good-isolation
3342 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "(BT is available)");
3343 break;
3344 case 3: // 1-Ant
3345 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "(BT is available)");
3346 break;
3347 case 4:
3348 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "(Uncertainty result)");
3349 break;
3350 case 5:
3351 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "(Pre-Scan fai)");
3352 break;
3353 case 6:
3354 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "(WiFi is Scanning)");
3355 break;
3356 case 7:
3357 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "(BT is not idle)");
3358 break;
3359 case 8:
3360 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "(Abort by WiFi Scanning)");
3361 break;
3362 case 9:
3363 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "(Antenna Init is not ready)");
3364 break;
3365 case 10:
3366 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "(BT is Inquiry or page)");
3367 break;
3368 case 11:
3369 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "(BT is Disabled)");
3370 break;
3371 }
3372 CL_PRINTF(cliBuf);
3373
3374
3375 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "Ant Detect Total Count",pPsdScan->bAntDet_TryCount);
3376 CL_PRINTF(cliBuf);
3377
3378 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "Ant Detect Fail Count",pPsdScan->bAntDet_FailCount);
3379 CL_PRINTF(cliBuf);
3380
3381 if ( (!pBoardInfo->btdmAntDetFinish) && (pPsdScan->nAntDet_Result != 5) )
3382 return;
3383
3384 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "BT Response",(pPsdScan->nAntDet_Result? "ok":"fail"));
3385 CL_PRINTF(cliBuf);
3386
3387 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ms", "BT Tx Time", pPsdScan->nAntDet_BTTxTime);
3388 CL_PRINTF(cliBuf);
3389
3390 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "BT Tx Ch", pPsdScan->nAntDet_BTLEChannel);
3391 CL_PRINTF(cliBuf);
3392
3393 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d", "WiFi PSD Cent-Ch/Offset/Span",
3394 pPsdScan->nRealCentFreq, pPsdScan->nRealOffset, pPsdScan->nRealSpan);
3395 CL_PRINTF(cliBuf);
3396
3397 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d dB", "PSD Pre-Scan Peak Value", pPsdScan->nAntDet_PrePSDScanPeakVal/100);
3398 CL_PRINTF(cliBuf);
3399
3400 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s (<= %d)", "PSD Pre-Scan result",
3401 (pPsdScan->nAntDet_Result != 5? "ok":"fail"), BT_8723B_1ANT_ANTDET_PSDTHRES_BACKGROUND+pPsdScan->nAntDet_ThresOffset);
3402 CL_PRINTF(cliBuf);
3403
3404 if (pPsdScan->nAntDet_Result == 5)
3405 return;
3406
3407 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s dB", "PSD Scan Peak Value", pPsdScan->nAntDet_PeakVal);
3408 CL_PRINTF(cliBuf);
3409
3410 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s MHz", "PSD Scan Peak Freq", pPsdScan->nAntDet_PeakFreq);
3411 CL_PRINTF(cliBuf);
3412
3413
3414 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "TFBGA Package",
3415 (pBoardInfo->bTfbgaPackage)? "Yes":"No");
3416 CL_PRINTF(cliBuf);
3417
3418 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "PSD Threshold Offset", pPsdScan->nAntDet_ThresOffset);
3419 CL_PRINTF(cliBuf);
3420
3421 }
3422
3423 VOID
halbtc8723b1ant_PSD_ShowData(IN PBTC_COEXIST pBtCoexist)3424 halbtc8723b1ant_PSD_ShowData(
3425 IN PBTC_COEXIST pBtCoexist
3426 )
3427 {
3428 pu1Byte cliBuf=pBtCoexist->cliBuf;
3429 u4Byte nDeltaFreqPerPoint;
3430 u4Byte freq,freq1,freq2,n=0,i=0, j=0, m=0, PsdRep1, PsdRep2;
3431
3432 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n\n============[PSD info] (%d)============\n",
3433 pPsdScan->nPSDGenCount);
3434 CL_PRINTF(cliBuf);
3435
3436 if (pPsdScan->nPSDGenCount == 0)
3437 {
3438 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n No Data !!\n");
3439 CL_PRINTF(cliBuf);
3440 return;
3441 }
3442
3443 if (pPsdScan->nPSDPoint == 0)
3444 nDeltaFreqPerPoint = 0;
3445 else
3446 nDeltaFreqPerPoint = pPsdScan->nPSDBandWidth/pPsdScan->nPSDPoint;
3447
3448 //if (pPsdScan->bIsPSDShowMaxOnly)
3449 if (0)
3450 {
3451 PsdRep1 = pPsdScan->nPSDMaxValue/100;
3452 PsdRep2 = pPsdScan->nPSDMaxValue - PsdRep1 * 100;
3453
3454 freq = ((pPsdScan->nRealCentFreq-20) * 1000000 + pPsdScan->nPSDMaxValuePoint * nDeltaFreqPerPoint);
3455 freq1 = freq/1000000;
3456 freq2 = freq/1000 - freq1 * 1000;
3457
3458 if (freq2 < 100)
3459 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n Freq = %d.0%d MHz",
3460 freq1, freq2);
3461 else
3462 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n Freq = %d.%d MHz",
3463 freq1, freq2);
3464
3465 if (PsdRep2 < 10)
3466 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, ", Value = %d.0%d dB, (%d) \n",
3467 PsdRep1, PsdRep2, pPsdScan->nPSDMaxValue);
3468 else
3469 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, ", Value = %d.%d dB, (%d)\n",
3470 PsdRep1, PsdRep2, pPsdScan->nPSDMaxValue);
3471
3472 CL_PRINTF(cliBuf);
3473 }
3474 else
3475 {
3476 m = pPsdScan->nPSDStartPoint;
3477 n = pPsdScan->nPSDStartPoint;
3478 i = 1;
3479 j = 1;
3480
3481 while(1)
3482 {
3483 do
3484 {
3485 freq = ((pPsdScan->nRealCentFreq-20) * 1000000 + m * nDeltaFreqPerPoint);
3486 freq1 = freq/1000000;
3487 freq2 = freq/1000 - freq1 * 1000;
3488
3489 if (i ==1)
3490 {
3491 if (freq2 == 0)
3492 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n Freq%6d.000", freq1);
3493 else if (freq2 < 100)
3494 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n Freq%6d.0%2d", freq1,freq2);
3495 else
3496 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n Freq%6d.%3d", freq1,freq2);
3497 }
3498 else if ( (i%8 == 0) || (m == pPsdScan->nPSDStopPoint) )
3499 {
3500 if (freq2 == 0)
3501 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%6d.000\n", freq1);
3502 else if (freq2 < 100)
3503 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%6d.0%2d\n", freq1,freq2);
3504 else
3505 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%6d.%3d\n", freq1,freq2);
3506 }
3507 else
3508 {
3509 if (freq2 == 0)
3510 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%6d.000", freq1);
3511 else if (freq2 < 100)
3512 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%6d.0%2d", freq1,freq2);
3513 else
3514 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%6d.%3d", freq1,freq2);
3515 }
3516
3517 i++;
3518 m++;
3519 CL_PRINTF(cliBuf);
3520
3521 }while( (i <= 8) && (m <= pPsdScan->nPSDStopPoint));
3522
3523
3524 do
3525 {
3526 PsdRep1 = pPsdScan->nPSDReport_MaxHold[n]/100;
3527 PsdRep2 = pPsdScan->nPSDReport_MaxHold[n] - PsdRep1 * 100;
3528
3529 if (j ==1)
3530 {
3531 if (PsdRep2 <10)
3532 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n Val %7d.0%d", PsdRep1,PsdRep2);
3533 else
3534 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n Val %7d.%d", PsdRep1,PsdRep2);
3535 }
3536 else if ( (j%8 == 0) || (n == pPsdScan->nPSDStopPoint) )
3537 {
3538 if (PsdRep2 <10)
3539 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%7d.0%d\n", PsdRep1,PsdRep2);
3540 else
3541 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%7d.%d\n", PsdRep1,PsdRep2);
3542 }
3543 else
3544 {
3545 if (PsdRep2 <10)
3546 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%7d.0%d", PsdRep1,PsdRep2);
3547 else
3548 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "%7d.%d", PsdRep1,PsdRep2);
3549 }
3550
3551 j++;
3552 n++;
3553 CL_PRINTF(cliBuf);
3554
3555 } while( (j <= 8) && (n <= pPsdScan->nPSDStopPoint));
3556
3557 if ( (m > pPsdScan->nPSDStopPoint) || (n > pPsdScan->nPSDStopPoint) )
3558 break;
3559 else
3560 {
3561 i = 1;
3562 j = 1;
3563 }
3564
3565 }
3566 }
3567
3568
3569 }
3570
3571 VOID
halbtc8723b1ant_PSD_MaxHoldData(IN PBTC_COEXIST pBtCoexist,IN u4Byte GenCount)3572 halbtc8723b1ant_PSD_MaxHoldData(
3573 IN PBTC_COEXIST pBtCoexist,
3574 IN u4Byte GenCount
3575 )
3576 {
3577 u4Byte i=0, i_max=0, val_max=0, j;
3578
3579 if (GenCount== 1)
3580 {
3581 memcpy(pPsdScan->nPSDReport_MaxHold, pPsdScan->nPSDReport, BT_8723B_1ANT_ANTDET_PSD_POINTS*sizeof(u4Byte));
3582
3583 for (i= pPsdScan->nPSDStartPoint; i<=pPsdScan->nPSDStopPoint; i++)
3584 {
3585 //RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), Max_Hold i = %d, PSDReport = %d dB\n", i, pPsdScan->nPSDReport_MaxHold[i]));
3586 }
3587
3588 pPsdScan->nPSDMaxValuePoint = 0;
3589 pPsdScan->nPSDMaxValue = 0;
3590
3591 }
3592 else
3593 {
3594 for (i= pPsdScan->nPSDStartPoint; i<=pPsdScan->nPSDStopPoint; i++)
3595 {
3596 if (pPsdScan->nPSDReport[i] > pPsdScan->nPSDReport_MaxHold[i])
3597 pPsdScan->nPSDReport_MaxHold[i] = pPsdScan->nPSDReport[i];
3598
3599 //search Max Value
3600 if (i ==pPsdScan->nPSDStartPoint )
3601 {
3602 i_max = i;
3603 val_max = pPsdScan->nPSDReport_MaxHold[i];
3604 }
3605 else
3606 {
3607 if (pPsdScan->nPSDReport_MaxHold[i] > val_max)
3608 {
3609 i_max = i;
3610 val_max = pPsdScan->nPSDReport_MaxHold[i];
3611 }
3612 }
3613
3614 //RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), Max_Hold i = %d, PSDReport = %d dB\n", i, pPsdScan->nPSDReport_MaxHold[i]));
3615
3616 }
3617
3618 pPsdScan->nPSDMaxValuePoint = i_max;
3619 pPsdScan->nPSDMaxValue = val_max;
3620
3621 //RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), Max_Hold i_Max = %d, PSDReport_Max = %d dB\n", pPsdScan->nPSDMaxValuePoint
3622 // ,pPsdScan->nPSDMaxValue));
3623 }
3624
3625
3626 }
3627
3628 u4Byte
halbtc8723b1ant_PSD_GetData(IN PBTC_COEXIST pBtCoexist,IN u4Byte nPoint)3629 halbtc8723b1ant_PSD_GetData(
3630 IN PBTC_COEXIST pBtCoexist,
3631 IN u4Byte nPoint
3632 )
3633 {
3634 //reg 0x808[9:0]: FFT data x
3635 //reg 0x808[22]: 0-->1 to get 1 FFT data y
3636 //reg 0x8b4[15:0]: FFT data y report
3637
3638 u4Byte val = 0, psd_report =0;
3639
3640 val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x808);
3641
3642 val &= 0xffbffc00;
3643 val |= nPoint;
3644
3645 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x808, val);
3646
3647 val |= 0x00400000;
3648 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x808, val);
3649
3650
3651 val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x8b4);
3652
3653 psd_report = val & 0x0000ffff;
3654
3655 return psd_report;
3656 }
3657
3658
3659 VOID
halbtc8723b1ant_PSD_SweepPoint(IN PBTC_COEXIST pBtCoexist,IN u4Byte centFreq,IN s4Byte offset,IN u4Byte span,IN u4Byte points,IN u4Byte avgnum)3660 halbtc8723b1ant_PSD_SweepPoint(
3661 IN PBTC_COEXIST pBtCoexist,
3662 IN u4Byte centFreq,
3663 IN s4Byte offset,
3664 IN u4Byte span,
3665 IN u4Byte points,
3666 IN u4Byte avgnum
3667 )
3668 {
3669 u4Byte i,val,n,k=0;
3670 u4Byte nPoints=0, psd_report=0;
3671 u4Byte nStartP=0, nStopP=0, nDeltaFreqPerPoint=156250;
3672 u4Byte nPSDCenterFreq=20*10^6, freq,freq1,freq2;
3673 BOOLEAN outloop = FALSE;
3674 u1Byte flag = 0;
3675 u4Byte tmp, PsdRep1, PsdRep2;
3676 u4Byte WiFi_OriginalChannel = 1;
3677
3678 pPsdScan->bIsPSDRunning = TRUE;
3679
3680 do
3681 {
3682 switch(flag)
3683 {
3684 case 0: //Get PSD parameters
3685 default:
3686 //RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), centFreq=0x%x, offset=0x%x, span=0x%x\n",
3687 // centFreq, offset, span));
3688
3689 pPsdScan->nPSDBandWidth = 40*1000000;
3690 pPsdScan->nPSDPoint = points;
3691 pPsdScan->nPSDStartBase = points/2;
3692 pPsdScan->nPSDAvgNum = avgnum;
3693 pPsdScan->nRealCentFreq = centFreq;
3694 pPsdScan->nRealOffset = offset;
3695 pPsdScan->nRealSpan = span;
3696
3697
3698 nPoints = pPsdScan->nPSDPoint;
3699 nDeltaFreqPerPoint = pPsdScan->nPSDBandWidth/pPsdScan->nPSDPoint;
3700
3701 //PSD point setup
3702 val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x808);
3703 val &= 0xffff0fff;
3704
3705 switch(pPsdScan->nPSDPoint)
3706 {
3707 case 128:
3708 val |= 0x0;
3709 break;
3710 case 256:
3711 default:
3712 val |=0x00004000;
3713 break;
3714 case 512:
3715 val |= 0x00008000;
3716 break;
3717 case 1024:
3718 val |= 0x0000c000;
3719 break;
3720 }
3721
3722 switch(pPsdScan->nPSDAvgNum)
3723 {
3724 case 1:
3725 val |= 0x0;
3726 break;
3727 case 8:
3728 val |=0x00001000;
3729 break;
3730 case 16:
3731 val |= 0x00002000;
3732 break;
3733 case 32:
3734 default:
3735 val |= 0x00003000;
3736 break;
3737 }
3738 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x808, val);
3739
3740 //RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), PSD BW= %d, DeltaFreq=%d\n"
3741 // , pPsdScan->nPSDBandWidth, nDeltaFreqPerPoint));
3742 flag = 1;
3743 break;
3744 case 1: //calculate the PSD point index from freq/offset/span
3745 nPSDCenterFreq = pPsdScan->nPSDBandWidth /2 +offset*(1000000);
3746 //RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), PSD Center Freq = %d\n", (centFreq + offset)));
3747
3748 nStartP = pPsdScan->nPSDStartBase + (nPSDCenterFreq - span *(1000000)/2) /nDeltaFreqPerPoint;
3749 pPsdScan->nPSDStartPoint = nStartP - pPsdScan->nPSDStartBase;
3750 //RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), Start PSD Poin Matrix Index = %d\n", pPsdScan->nPSDStartPoint));
3751
3752 nStopP = pPsdScan->nPSDStartBase + (nPSDCenterFreq + span *(1000000)/2) /nDeltaFreqPerPoint;
3753 pPsdScan->nPSDStopPoint = nStopP - pPsdScan->nPSDStartBase-1;
3754 //RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), Stop PSD Poin Matrix Index = %d\n",pPsdScan->nPSDStopPoint));
3755
3756 flag = 2;
3757 break;
3758 case 2: //set RF channel/BW/Mode
3759
3760 //set 3-wire off
3761 val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x88c);
3762 val |= 0x00300000;
3763 pBtCoexist->fBtcWrite4Byte(pBtCoexist,0x88c,val);
3764
3765 //CCK off
3766 val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x800);
3767 val &= 0xfeffffff;
3768 pBtCoexist->fBtcWrite4Byte(pBtCoexist,0x800,val);
3769
3770 //store WiFi original channel
3771 WiFi_OriginalChannel = pBtCoexist->fBtcGetRfReg(pBtCoexist, BTC_RF_A, 0x18, 0x3ff);
3772
3773 //Set RF channel
3774 if (centFreq == 2484)
3775 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x18, 0x3ff, 0xe);
3776 else
3777 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x18, 0x3ff, (centFreq-2412)/5 + 1); //WiFi TRx Mask on
3778
3779 //Set RF mode = Rx, RF Gain = 0x8a0
3780 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x0, 0xfffff, 0x308a0);
3781
3782 //Set RF Rx filter corner
3783 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff, 0x3e4);
3784
3785 //Set TRx mask off
3786 //un-lock TRx Mask setup
3787 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xdd, 0x80, 0x1);
3788 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xdf, 0x1, 0x1);
3789
3790 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
3791
3792 flag = 3;
3793 break;
3794 case 3:
3795 memset(pPsdScan->nPSDReport,0, pPsdScan->nPSDPoint*sizeof(u4Byte));
3796 nStartP = pPsdScan->nPSDStartPoint + pPsdScan->nPSDStartBase;
3797 nStopP = pPsdScan->nPSDStopPoint + pPsdScan->nPSDStartBase + 1;
3798
3799 i = nStartP;
3800
3801 while (i < nStopP)
3802 {
3803 if (i >= nPoints)
3804 {
3805 psd_report = halbtc8723b1ant_PSD_GetData(pBtCoexist,i-nPoints);
3806 }
3807 else
3808 {
3809 psd_report = halbtc8723b1ant_PSD_GetData(pBtCoexist,i);
3810 }
3811
3812 if (psd_report == 0)
3813 tmp = 0;
3814 else
3815 //tmp = 20*log10((double)psd_report);
3816 //20*log2(x)/log2(10), log2Base return theresult of the psd_report*100
3817 tmp = 6 * halbtc8723b1ant_PSD_Log2Base(pBtCoexist, psd_report);
3818
3819 n = i-pPsdScan->nPSDStartBase;
3820 pPsdScan->nPSDReport[n] = tmp;
3821 PsdRep1 = pPsdScan->nPSDReport[n] /100;
3822 PsdRep2 = pPsdScan->nPSDReport[n] - PsdRep1 * 100;
3823
3824 freq = ((centFreq-20) * 1000000 + n * nDeltaFreqPerPoint);
3825 freq1 = freq/1000000;
3826 freq2 = freq/1000 - freq1 * 1000;
3827 /*
3828 if (freq2 < 100)
3829 RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), i = %d (%d.0%d MHz)", n, freq1, freq2));
3830 else
3831 RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint(), i = %d (%d.%d MHz)", n, freq1, freq2));
3832
3833 if (PsdRep2 < 10)
3834 RT_TRACE(COMP_COEX, DBG_LOUD, (", PSDReport = %d (%d.0%d dB)\n",psd_report, PsdRep1, PsdRep2));
3835 else
3836 RT_TRACE(COMP_COEX, DBG_LOUD, (", PSDReport = %d (%d.%d dB)\n",psd_report, PsdRep1,PsdRep2));
3837 */
3838 i++;
3839
3840 k=0;
3841
3842 //Add Delay between PSD point
3843 while(1)
3844 {
3845 if (k++ > 20000)
3846 break;
3847 }
3848
3849 //RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx SweepPSDPoint()==============\n"));
3850 }
3851
3852 flag = 100;
3853 break;
3854 case 99: //error
3855
3856 outloop = TRUE;
3857 break;
3858 case 100: //recovery
3859
3860 //set 3-wire on
3861 val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x88c);
3862 val &=0xffcfffff;
3863 pBtCoexist->fBtcWrite4Byte(pBtCoexist,0x88c,val);
3864
3865 //CCK on
3866 val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x800);
3867 val |= 0x01000000;
3868 pBtCoexist->fBtcWrite4Byte(pBtCoexist,0x800,val);
3869
3870 //PSD off
3871 val = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x808);
3872 val &=0xffbfffff;
3873 pBtCoexist->fBtcWrite4Byte(pBtCoexist,0x808,val);
3874
3875 //TRx Mask on
3876 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x780);
3877
3878 //lock TRx Mask setup
3879 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xdd, 0x80, 0x0);
3880 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xdf, 0x1, 0x0);
3881
3882 //Set RF Rx filter corner
3883 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff, 0x0);
3884
3885 //restore WiFi original channel
3886 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x18, 0x3ff, WiFi_OriginalChannel);
3887
3888 outloop = TRUE;
3889 break;
3890
3891 }
3892
3893 }while (!outloop);
3894
3895
3896
3897 pPsdScan->bIsPSDRunning = FALSE;
3898
3899
3900 }
3901
3902 VOID
halbtc8723b1ant_PSD_AntennaDetection(IN PBTC_COEXIST pBtCoexist,IN u4Byte BTTxTime,IN u4Byte BTLEChannel)3903 halbtc8723b1ant_PSD_AntennaDetection(
3904 IN PBTC_COEXIST pBtCoexist,
3905 IN u4Byte BTTxTime,
3906 IN u4Byte BTLEChannel
3907 )
3908 {
3909 u4Byte realseconds = 0, i=0, j=0;
3910 u4Byte WLPSD_CentFreq = 2484, WLPSD_Span = 2, WLPSD_SweepCount = 50;
3911 s4Byte WLPSD_Offset = -4;
3912 u1Byte BTLECh[13] = {3,6,8,11,13,16,18,21,23,26,28,31,33};
3913
3914 u1Byte H2C_Parameter[3] ={0},u1Tmpa,u1Tmpb;
3915
3916 u1Byte state=0;
3917 BOOLEAN outloop = FALSE, BTResp = FALSE, bScan ,bRoam;
3918 u4Byte freq,freq1,freq2,PsdRep1, PsdRep2, nDeltaFreqPerPoint,u4Tmp;
3919 PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;
3920
3921 pBoardInfo->btdmAntDetFinish = FALSE;
3922 memset(pPsdScan->nAntDet_PeakVal, 0, 16*sizeof(UCHAR));
3923 memset(pPsdScan->nAntDet_PeakFreq, 0, 16*sizeof(UCHAR));
3924
3925 if (pBoardInfo->bTfbgaPackage) //for TFBGA
3926 pPsdScan->nAntDet_ThresOffset = 5;
3927 else
3928 pPsdScan->nAntDet_ThresOffset = 0;
3929
3930 do
3931 {
3932 switch(state)
3933 {
3934 case 0:
3935 if (BTLEChannel == 39)
3936 WLPSD_CentFreq = 2484;
3937 else
3938 {
3939 for (i=1; i<=13; i++)
3940 {
3941 if (BTLECh[i-1] == BTLEChannel)
3942 {
3943 WLPSD_CentFreq = 2412 + (i-1) * 5;
3944 break;
3945 }
3946 }
3947
3948 if (i == 14)
3949 {
3950
3951 RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx AntennaDetect(), Abort!!, Invalid LE channel = %d\n ", BTLEChannel));
3952 outloop = TRUE;
3953 break;
3954 }
3955 }
3956
3957 WLPSD_SweepCount = BTTxTime * 238 /100; //BTTxTime/0.42
3958
3959 if (WLPSD_SweepCount % 5 != 0)
3960 WLPSD_SweepCount = (WLPSD_SweepCount/5 + 1) * 5;
3961
3962 RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx AntennaDetect(), BT_LETxTime=%d, BT_LECh = %d\n", BTTxTime, BTLEChannel));
3963 RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx AntennaDetect(), WLPSD_CentFreq=%d, WLPSD_Offset = %d, WLPSD_Span = %d, WLPSD_SweepCount = %d\n",
3964 WLPSD_CentFreq, WLPSD_Offset, WLPSD_Span,WLPSD_SweepCount));
3965
3966 state = 1;
3967 break;
3968 case 1: //stop coex DM & set antenna path
3969 //Stop Coex DM
3970 pBtCoexist->bStopCoexDm = TRUE;
3971
3972 RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx AntennaDetect(), Stop Coex DM!!\n"));
3973
3974 //set native power save
3975 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3976
3977 //Set TDMA off,
3978 halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 0);
3979
3980 //Set coex table
3981 halbtc8723b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);
3982
3983 if(pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)
3984 {
3985 RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx AntennaDetect(), Antenna at Main Port\n"));
3986 }
3987 else
3988 {
3989 RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx AntennaDetect(), Antenna at Aux Port\n"));
3990 }
3991
3992 //Set Antenna path, switch WiFi to un-certain antenna port
3993 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FORCE_EXEC, FALSE, FALSE);
3994
3995 RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx AntennaDetect(), Set Antenna to BT!!\n"));
3996
3997 //Set AFH mask on at WiFi channel 2472MHz +/- 10MHz
3998 H2C_Parameter[0] = 0x1;
3999 H2C_Parameter[1] = 0xd;
4000 H2C_Parameter[2] = 0x14;
4001
4002 RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx AntennaDetect(), Set AFH on, Cent-Ch= %d, Mask=%d\n",
4003 H2C_Parameter[1],H2C_Parameter[2]));
4004
4005 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x66, 3, H2C_Parameter);
4006
4007 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x948);
4008 u1Tmpa = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x765);
4009 u1Tmpb = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x778);
4010
4011 RT_TRACE(COMP_COEX, DBG_LOUD, ("############# [BTCoex], 0x948=0x%x, 0x765=0x%x, 0x778=0x%x\n",
4012 u4Tmp, u1Tmpa, u1Tmpb));
4013
4014 state =2;
4015 break;
4016 case 2: //Pre-sweep background psd
4017 for (pPsdScan->nPSDGenCount=1; pPsdScan->nPSDGenCount<=3; pPsdScan->nPSDGenCount++)
4018 {
4019 RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx AntennaDetect(), PSDGenCount = %d\n ", pPsdScan->nPSDGenCount));
4020 halbtc8723b1ant_PSD_SweepPoint(pBtCoexist, WLPSD_CentFreq, WLPSD_Offset, WLPSD_Span, BT_8723B_1ANT_ANTDET_PSD_POINTS, BT_8723B_1ANT_ANTDET_PSD_AVGNUM);
4021 halbtc8723b1ant_PSD_MaxHoldData(pBtCoexist, pPsdScan->nPSDGenCount);
4022 }
4023
4024 pPsdScan->nAntDet_PrePSDScanPeakVal = pPsdScan->nPSDMaxValue;
4025
4026 if (pPsdScan->nPSDMaxValue > (BT_8723B_1ANT_ANTDET_PSDTHRES_BACKGROUND+pPsdScan->nAntDet_ThresOffset)*100)
4027 {
4028 RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx AntennaDetect(), Abort Antenna Detection!! becaus background = %d > thres (%d)\n",
4029 pPsdScan->nPSDMaxValue/100, BT_8723B_1ANT_ANTDET_PSDTHRES_BACKGROUND+pPsdScan->nAntDet_ThresOffset));
4030 pBoardInfo->btdmAntDetFinish = FALSE;
4031 pBoardInfo->btdmAntNumByAntDet = 1;
4032 pPsdScan->nAntDet_Result = 5;
4033 state = 99;
4034 }
4035 else
4036 {
4037 RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx AntennaDetect(), Start Antenna Detection!! becaus background = %d <= thres (%d)\n",
4038 pPsdScan->nPSDMaxValue/100, BT_8723B_1ANT_ANTDET_PSDTHRES_BACKGROUND+pPsdScan->nAntDet_ThresOffset));
4039 state = 3;
4040 }
4041 break;
4042 case 3:
4043 BTResp = pBtCoexist->fBtcSetBtAntDetection(pBtCoexist, (u1Byte)(BTTxTime&0xff), (u1Byte)(BTLEChannel&0xff));
4044
4045 for (pPsdScan->nPSDGenCount=1; pPsdScan->nPSDGenCount<=WLPSD_SweepCount; pPsdScan->nPSDGenCount++)
4046 {
4047 RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx AntennaDetect(), PSDGenCount = %d\n ", pPsdScan->nPSDGenCount));
4048 halbtc8723b1ant_PSD_SweepPoint(pBtCoexist, WLPSD_CentFreq, WLPSD_Offset, WLPSD_Span, BT_8723B_1ANT_ANTDET_PSD_POINTS, BT_8723B_1ANT_ANTDET_PSD_AVGNUM);
4049 halbtc8723b1ant_PSD_MaxHoldData(pBtCoexist, pPsdScan->nPSDGenCount);
4050
4051 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
4052 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
4053
4054 if (bScan ||bRoam)
4055 {
4056 pBoardInfo->btdmAntDetFinish = FALSE;
4057 pBoardInfo->btdmAntNumByAntDet = 1;
4058 pPsdScan->nAntDet_Result = 8;
4059 state = 99;
4060 break;
4061 }
4062 }
4063
4064 pPsdScan->nAntDet_PSDScanPeakVal = pPsdScan->nPSDMaxValue;
4065 pPsdScan->nAntDet_PSDScanPeakFreq = pPsdScan->nPSDMaxValuePoint;
4066 state = 4;
4067 break;
4068 case 4:
4069
4070 if (pPsdScan->nPSDPoint == 0)
4071 nDeltaFreqPerPoint = 0;
4072 else
4073 nDeltaFreqPerPoint = pPsdScan->nPSDBandWidth/pPsdScan->nPSDPoint;
4074
4075 PsdRep1 = pPsdScan->nPSDMaxValue/100;
4076 PsdRep2 = pPsdScan->nPSDMaxValue - PsdRep1 * 100;
4077
4078 freq = ((pPsdScan->nRealCentFreq-20) * 1000000 + pPsdScan->nPSDMaxValuePoint * nDeltaFreqPerPoint);
4079 freq1 = freq/1000000;
4080 freq2 = freq/1000 - freq1 * 1000;
4081
4082 if (freq2 < 100)
4083 {
4084 RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx AntennaDetect(), Max Value: Freq = %d.0%d MHz", freq1, freq2));
4085 CL_SPRINTF(pPsdScan->nAntDet_PeakFreq, BT_8723B_1ANT_ANTDET_BUF_LEN, "%d.0%d", freq1,freq2);
4086 }
4087 else
4088 {
4089 RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx AntennaDetect(), Max Value: Freq = %d.%d MHz", freq1, freq2));
4090 CL_SPRINTF(pPsdScan->nAntDet_PeakFreq, BT_8723B_1ANT_ANTDET_BUF_LEN, "%d.%d", freq1,freq2);
4091 }
4092
4093 if (PsdRep2 < 10)
4094 {
4095 RT_TRACE(COMP_COEX, DBG_LOUD, (", Value = %d.0%d dB\n", PsdRep1, PsdRep2));
4096 CL_SPRINTF(pPsdScan->nAntDet_PeakVal, BT_8723B_1ANT_ANTDET_BUF_LEN, "%d.0%d", PsdRep1,PsdRep2);
4097 }
4098 else
4099 {
4100 RT_TRACE(COMP_COEX, DBG_LOUD, (", Value = %d.%d dB\n",PsdRep1, PsdRep2));
4101 CL_SPRINTF(pPsdScan->nAntDet_PeakVal, BT_8723B_1ANT_ANTDET_BUF_LEN, "%d.%d", PsdRep1,PsdRep2);
4102 }
4103
4104 pPsdScan->nAntDet_IsBTReplyAvailable = TRUE;
4105
4106 if (BTResp == FALSE)
4107 {
4108 pPsdScan->nAntDet_IsBTReplyAvailable = FALSE;
4109 pPsdScan->nAntDet_Result = 0;
4110 pBoardInfo->btdmAntDetFinish = FALSE;
4111 pBoardInfo->btdmAntNumByAntDet = 1;
4112 RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx AntennaDetect(), BT Response = Fail \n "));
4113 }
4114 else if (pPsdScan->nPSDMaxValue > (BT_8723B_1ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION)*100)
4115 {
4116 pPsdScan->nAntDet_Result = 1;
4117 pBoardInfo->btdmAntDetFinish = TRUE;
4118 pBoardInfo->btdmAntNumByAntDet = 2;
4119 RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx AntennaDetect(), Detect Result = 2-Ant, Bad-Isolation!! \n"));
4120 }
4121 else if (pPsdScan->nPSDMaxValue > (BT_8723B_1ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION+pPsdScan->nAntDet_ThresOffset)*100)
4122 {
4123 pPsdScan->nAntDet_Result = 2;
4124 pBoardInfo->btdmAntDetFinish = TRUE;
4125 pBoardInfo->btdmAntNumByAntDet = 2;
4126 RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx AntennaDetect(), Detect Result = 2-Ant, Good-Isolation!! \n"));
4127 }
4128 else if (pPsdScan->nPSDMaxValue > (BT_8723B_1ANT_ANTDET_PSDTHRES_1ANT)*100)
4129 {
4130 pPsdScan->nAntDet_Result = 3;
4131 pBoardInfo->btdmAntDetFinish = TRUE;
4132 pBoardInfo->btdmAntNumByAntDet = 1;
4133 RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx AntennaDetect(), Detect Result = 1-Ant!!\n"));
4134 }
4135 else
4136 {
4137 pPsdScan->nAntDet_Result = 4;
4138 pBoardInfo->btdmAntDetFinish = FALSE;
4139 pBoardInfo->btdmAntNumByAntDet = 1;
4140 RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx AntennaDetect(), Detect Result = 1-Ant, un-certainity!!\n"));
4141 }
4142
4143 state = 99;
4144 break;
4145 case 99: //restore setup
4146
4147 //Set AFH mask off at WiFi channel 2472MHz +/- 10MHz
4148 H2C_Parameter[0] = 0x0;
4149 H2C_Parameter[1] = 0x0;
4150 H2C_Parameter[2] = 0x0;
4151
4152 RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx AntennaDetect(), Set AFH on, Cent-Ch= %d, Mask=%d\n",
4153 H2C_Parameter[1],H2C_Parameter[2]));
4154
4155 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x66, 3, H2C_Parameter);
4156
4157 //Set Antenna Path
4158 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, FORCE_EXEC, FALSE, FALSE);
4159 RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx AntennaDetect(), Set Antenna to PTA\n!!"));
4160
4161 //Resume Coex DM
4162 pBtCoexist->bStopCoexDm = FALSE;
4163 RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx AntennaDetect(), Resume Coex DM\n!!"));
4164
4165 //stimulate coex running
4166 halbtc8723b1ant_RunCoexistMechanism(pBtCoexist);
4167 RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx AntennaDetect(), Stimulate Coex running\n!!"));
4168
4169 outloop = TRUE;
4170 break;
4171 }
4172
4173 }while(!outloop);
4174
4175
4176
4177 }
4178
4179 VOID
halbtc8723b1ant_PSD_AntennaDetectionCheck(IN PBTC_COEXIST pBtCoexist)4180 halbtc8723b1ant_PSD_AntennaDetectionCheck(
4181 IN PBTC_COEXIST pBtCoexist
4182 )
4183 {
4184 static u4Byte AntDetCount = 0, AntDetFailCount = 0;
4185 PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;
4186
4187 BOOLEAN bScan, bRoam;
4188
4189 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
4190 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
4191
4192
4193 pPsdScan->nAntDet_BTTxTime = 20; //0.42ms*50 = 20ms
4194 pPsdScan->nAntDet_BTLEChannel = 39;
4195
4196 AntDetCount++;
4197
4198 pPsdScan->bAntDet_TryCount = AntDetCount;
4199
4200 if (bScan ||bRoam)
4201 {
4202 pBoardInfo->btdmAntDetFinish = FALSE;
4203 pPsdScan->nAntDet_Result = 6;
4204 }
4205 else if(pBtCoexist->btInfo.bBtDisabled)
4206 {
4207 pBoardInfo->btdmAntDetFinish = FALSE;
4208 pPsdScan->nAntDet_Result = 11;
4209 }
4210 else if (pCoexSta->nNumOfProfile >= 1)
4211 {
4212 pBoardInfo->btdmAntDetFinish = FALSE;
4213 pPsdScan->nAntDet_Result = 7;
4214 }
4215 else if (!pPsdScan->nAntDet_IsAntDetAvailable) //Antenna initial setup is not ready
4216 {
4217 pBoardInfo->btdmAntDetFinish = FALSE;
4218 pPsdScan->nAntDet_Result = 9;
4219 }
4220 else if (pCoexSta->bC2hBtInquiryPage)
4221 {
4222 pBoardInfo->btdmAntDetFinish = FALSE;
4223 pPsdScan->nAntDet_Result = 10;
4224 }
4225 else
4226 {
4227 halbtc8723b1ant_PSD_AntennaDetection(pBtCoexist, pPsdScan->nAntDet_BTTxTime, pPsdScan->nAntDet_BTLEChannel);
4228 }
4229
4230 if (!pBoardInfo->btdmAntDetFinish)
4231 AntDetFailCount++;
4232
4233 pPsdScan->bAntDet_FailCount = AntDetFailCount;
4234
4235 }
4236
4237
4238 //============================================================
4239 // work around function start with wa_halbtc8723b1ant_
4240 //============================================================
4241 //============================================================
4242 // extern function start with EXhalbtc8723b1ant_
4243 //============================================================
4244 VOID
EXhalbtc8723b1ant_PowerOnSetting(IN PBTC_COEXIST pBtCoexist)4245 EXhalbtc8723b1ant_PowerOnSetting(
4246 IN PBTC_COEXIST pBtCoexist
4247 )
4248 {
4249 PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;
4250 u1Byte u1Tmp=0x0;
4251 u2Byte u2Tmp=0x0;
4252
4253 RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx Execute 8723b 1-Ant PowerOn Setting xxxxxxxxxxxxxxxx!!\n"));
4254
4255 RT_TRACE(COMP_COEX, DBG_LOUD, ("Ant Det Finish = %s, Ant Det Number = %d\n",
4256 (pBoardInfo->btdmAntDetFinish? "Yes":"No"), pBoardInfo->btdmAntNumByAntDet));
4257
4258 pBtCoexist->bStopCoexDm = TRUE;
4259
4260 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x67, 0x20);
4261
4262 // enable BB, REG_SYS_FUNC_EN such that we can write 0x948 correctly.
4263 u2Tmp = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x2);
4264 pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x2, u2Tmp|BIT0|BIT1);
4265
4266 // set GRAN_BT = 1
4267 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x18);
4268 // set WLAN_ACT = 0
4269 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4);
4270
4271 //
4272 // S0 or S1 setting and Local register setting(By the setting fw can get ant number, S0/S1, ... info)
4273 // Local setting bit define
4274 // BIT0: "0" for no antenna inverse; "1" for antenna inverse
4275 // BIT1: "0" for internal switch; "1" for external switch
4276 // BIT2: "0" for one antenna; "1" for two antenna
4277 // NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and BIT2=0
4278 if(pBtCoexist->chipInterface == BTC_INTF_USB)
4279 {
4280 // fixed at S0 for USB interface
4281 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);
4282
4283 u1Tmp |= 0x1; // antenna inverse
4284 pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0xfe08, u1Tmp);
4285
4286 pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_AUX_PORT;
4287 }
4288 else
4289 {
4290 // for PCIE and SDIO interface, we check efuse 0xc3[6]
4291 if(pBoardInfo->singleAntPath == 0)
4292 {
4293 // set to S1
4294 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x280);
4295 pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
4296 }
4297 else if(pBoardInfo->singleAntPath == 1)
4298 {
4299 // set to S0
4300 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);
4301 u1Tmp |= 0x1; // antenna inverse
4302 pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_AUX_PORT;
4303 }
4304
4305 if(pBtCoexist->chipInterface == BTC_INTF_PCI)
4306 {
4307 pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0x384, u1Tmp);
4308 }
4309 else if(pBtCoexist->chipInterface == BTC_INTF_SDIO)
4310 {
4311 pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0x60, u1Tmp);
4312 }
4313 }
4314 }
4315
4316 VOID
EXhalbtc8723b1ant_PreLoadFirmware(IN PBTC_COEXIST pBtCoexist)4317 EXhalbtc8723b1ant_PreLoadFirmware(
4318 IN PBTC_COEXIST pBtCoexist
4319 )
4320 {
4321 }
4322
4323 VOID
EXhalbtc8723b1ant_InitHwConfig(IN PBTC_COEXIST pBtCoexist,IN BOOLEAN bWifiOnly)4324 EXhalbtc8723b1ant_InitHwConfig(
4325 IN PBTC_COEXIST pBtCoexist,
4326 IN BOOLEAN bWifiOnly
4327 )
4328 {
4329 halbtc8723b1ant_InitHwConfig(pBtCoexist, TRUE, bWifiOnly);
4330 pBtCoexist->bStopCoexDm = FALSE;
4331 }
4332
4333 VOID
EXhalbtc8723b1ant_InitCoexDm(IN PBTC_COEXIST pBtCoexist)4334 EXhalbtc8723b1ant_InitCoexDm(
4335 IN PBTC_COEXIST pBtCoexist
4336 )
4337 {
4338 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Coex Mechanism Init!!\n"));
4339
4340 pBtCoexist->bStopCoexDm = FALSE;
4341
4342 halbtc8723b1ant_InitCoexDm(pBtCoexist);
4343
4344 halbtc8723b1ant_QueryBtInfo(pBtCoexist);
4345 }
4346
4347 VOID
EXhalbtc8723b1ant_DisplayCoexInfo(IN PBTC_COEXIST pBtCoexist)4348 EXhalbtc8723b1ant_DisplayCoexInfo(
4349 IN PBTC_COEXIST pBtCoexist
4350 )
4351 {
4352 PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;
4353 PBTC_STACK_INFO pStackInfo=&pBtCoexist->stackInfo;
4354 PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
4355 pu1Byte cliBuf=pBtCoexist->cliBuf;
4356 u1Byte u1Tmp[4], i, btInfoExt, psTdmaCase=0;
4357 u2Byte u2Tmp[4];
4358 u4Byte u4Tmp[4];
4359 u4Byte faOfdm, faCck;
4360 u4Byte fwVer=0, btPatchVer=0;
4361 static u1Byte PopReportIn10s = 0;
4362
4363 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[BT Coexist info]============");
4364 CL_PRINTF(cliBuf);
4365
4366 if(pBtCoexist->bManualControl)
4367 {
4368 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[Under Manual Control]============");
4369 CL_PRINTF(cliBuf);
4370 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ==========================================");
4371 CL_PRINTF(cliBuf);
4372 }
4373 if(pBtCoexist->bStopCoexDm)
4374 {
4375 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[Coex is STOPPED]============");
4376 CL_PRINTF(cliBuf);
4377 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ==========================================");
4378 CL_PRINTF(cliBuf);
4379 }
4380
4381 if (pPsdScan->bAntDet_TryCount == 0)
4382 {
4383 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d", "Ant PG Num/ Mech/ Pos",
4384 pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum, pBoardInfo->btdmAntPos);
4385 CL_PRINTF(cliBuf);
4386 }
4387 else
4388 {
4389 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d (%d/%d/%d)", "Ant PG Num/ Mech(Ant_Det)/ Pos",
4390 pBoardInfo->pgAntNum, pBoardInfo->btdmAntNumByAntDet, pBoardInfo->btdmAntPos,
4391 pPsdScan->bAntDet_TryCount, pPsdScan->bAntDet_FailCount, pPsdScan->nAntDet_Result);
4392 CL_PRINTF(cliBuf);
4393
4394 if (pBoardInfo->btdmAntDetFinish)
4395 {
4396 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "Ant Det PSD Value", pPsdScan->nAntDet_PeakVal);
4397 CL_PRINTF(cliBuf);
4398 }
4399 }
4400
4401 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d", "BT stack/ hci ext ver", \
4402 ((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion);
4403 CL_PRINTF(cliBuf);
4404
4405 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);
4406 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);
4407 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)/ %c", "Version Coex/ Fw/ Patch/ Cut", \
4408 GLCoexVerDate8723b1Ant, GLCoexVer8723b1Ant, fwVer, btPatchVer, btPatchVer, pCoexSta->nCutVersion+65);
4409 CL_PRINTF(cliBuf);
4410
4411 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", "Wifi channel informed to BT", \
4412 pCoexDm->wifiChnlInfo[0], pCoexDm->wifiChnlInfo[1],
4413 pCoexDm->wifiChnlInfo[2]);
4414 CL_PRINTF(cliBuf);
4415 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %s", "WifibHiPri/ Ccklock/ CckEverLock", \
4416 (pCoexSta->bWiFiIsHighPriTask? "Yes":"No"),
4417 (pCoexSta->bCCKLock? "Yes":"No"),
4418 (pCoexSta->bCCKEverLock? "Yes":"No"));
4419 CL_PRINTF(cliBuf);
4420
4421 // wifi status
4422 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Wifi Status]============");
4423 CL_PRINTF(cliBuf);
4424 pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_WIFI_STATUS);
4425
4426 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[BT Status]============");
4427 CL_PRINTF(cliBuf);
4428
4429 PopReportIn10s++;
4430 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d/ %d] ", "BT [status/ rssi/ retryCnt/ popCnt]", \
4431 ((pBtCoexist->btInfo.bBtDisabled)? ("disabled"): ((pCoexSta->bC2hBtInquiryPage)?("inquiry/page scan"):((BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)? "non-connected idle":
4432 ( (BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus)? "connected-idle":"busy")))),
4433 pCoexSta->btRssi, pCoexSta->btRetryCnt, pCoexSta->popEventCnt);
4434 CL_PRINTF(cliBuf);
4435
4436 if (PopReportIn10s >= 5)
4437 {
4438 pCoexSta->popEventCnt = 0;
4439 PopReportIn10s = 0;
4440 }
4441
4442 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d / %d / %d", "SCO/HID/PAN/A2DP/NameReq/WHQL", \
4443 pBtLinkInfo->bScoExist, pBtLinkInfo->bHidExist, pBtLinkInfo->bPanExist, pBtLinkInfo->bA2dpExist, pCoexSta->bC2hBtRemoteNameReq, pCoexSta->bBtWhckTest );
4444 CL_PRINTF(cliBuf);
4445
4446 if (pStackInfo->bProfileNotified)
4447 {
4448 pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_BT_LINK_INFO);
4449 }
4450 else
4451 {
4452 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "BT Role", \
4453 (pBtLinkInfo->bSlaveRole )? "Slave":"Master");
4454 CL_PRINTF(cliBuf);
4455 }
4456
4457 btInfoExt = pCoexSta->btInfoExt;
4458 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %d", "A2DP Rate/Bitpool", \
4459 (btInfoExt&BIT0)? "BR":"EDR", pCoexSta->nA2DPBitPool);
4460 CL_PRINTF(cliBuf);
4461
4462 for(i=0; i<BT_INFO_SRC_8723B_1ANT_MAX; i++)
4463 {
4464 if(pCoexSta->btInfoC2hCnt[i])
4465 {
4466 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", GLBtInfoSrc8723b1Ant[i], \
4467 pCoexSta->btInfoC2h[i][0], pCoexSta->btInfoC2h[i][1],
4468 pCoexSta->btInfoC2h[i][2], pCoexSta->btInfoC2h[i][3],
4469 pCoexSta->btInfoC2h[i][4], pCoexSta->btInfoC2h[i][5],
4470 pCoexSta->btInfoC2h[i][6], pCoexSta->btInfoC2hCnt[i]);
4471 CL_PRINTF(cliBuf);
4472 }
4473 }
4474
4475
4476 if(pBtCoexist->bManualControl)
4477 {
4478 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw mechanism] (before Manual)============");
4479 }
4480 else
4481 {
4482 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw mechanism]============");
4483 }
4484
4485 CL_PRINTF(cliBuf);
4486
4487 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "SM[LowPenaltyRA]", \
4488 pCoexDm->bCurLowPenaltyRa);
4489 CL_PRINTF(cliBuf);
4490
4491 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s/ %s/ %d ", "DelBA/ BtCtrlAgg/ AggSize", \
4492 (pBtCoexist->btInfo.bRejectAggPkt? "Yes":"No"), (pBtCoexist->btInfo.bBtCtrlAggBufSize? "Yes":"No"),
4493 pBtCoexist->btInfo.aggBufSize);
4494 CL_PRINTF(cliBuf);
4495 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ", "Rate Mask", \
4496 pBtCoexist->btInfo.raMask);
4497 CL_PRINTF(cliBuf);
4498
4499 // Fw mechanism
4500 if(pBtCoexist->bManualControl)
4501 {
4502 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw mechanism] (before Manual) ============");
4503 }
4504 else
4505 {
4506 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw mechanism]============");
4507 }
4508
4509 CL_PRINTF(cliBuf);
4510
4511 psTdmaCase = pCoexDm->curPsTdma;
4512 if (pBoardInfo->btdmAntNumByAntDet == 2)
4513 {
4514 if (pCoexDm->bCurPsTdmaOn)
4515 psTdmaCase = psTdmaCase +100; //for WiFi RSSI low or BT RSSI low
4516 else
4517 psTdmaCase = 1; //always translate to TDMA(off,1) for TDMA-off case
4518 }
4519
4520 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (%s,%s)", "PS TDMA", \
4521 pCoexDm->psTdmaPara[0], pCoexDm->psTdmaPara[1],
4522 pCoexDm->psTdmaPara[2], pCoexDm->psTdmaPara[3],
4523 pCoexDm->psTdmaPara[4], psTdmaCase,
4524 (pCoexDm->bCurPsTdmaOn? "On":"Off"),
4525 (pCoexDm->bAutoTdmaAdjust? "Adj":"Fix") );
4526
4527 CL_PRINTF(cliBuf);
4528
4529 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "Coex Table Type", \
4530 pCoexSta->nCoexTableType);
4531 CL_PRINTF(cliBuf);
4532
4533 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "IgnWlanAct", \
4534 pCoexDm->bCurIgnoreWlanAct);
4535 CL_PRINTF(cliBuf);
4536
4537 /*
4538 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ", "Latest error condition(should be 0)", \
4539 pCoexDm->errorCondition);
4540 CL_PRINTF(cliBuf);
4541 */
4542
4543 // Hw setting
4544 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Hw setting]============");
4545 CL_PRINTF(cliBuf);
4546
4547 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", "backup ARFR1/ARFR2/RL/AMaxTime", \
4548 pCoexDm->backupArfrCnt1, pCoexDm->backupArfrCnt2, pCoexDm->backupRetryLimit, pCoexDm->backupAmpduMaxTime);
4549 CL_PRINTF(cliBuf);
4550
4551 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x430);
4552 u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x434);
4553 u2Tmp[0] = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x42a);
4554 u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x456);
4555 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", "0x430/0x434/0x42a/0x456", \
4556 u4Tmp[0], u4Tmp[1], u2Tmp[0], u1Tmp[0]);
4557 CL_PRINTF(cliBuf);
4558
4559 u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x778);
4560 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6cc);
4561 u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x880);
4562 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x778/0x6cc/0x880[29:25]", \
4563 u1Tmp[0], u4Tmp[0], (u4Tmp[1]&0x3e000000) >> 25);
4564 CL_PRINTF(cliBuf);
4565
4566 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x948);
4567 u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x67);
4568 u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x764);
4569 u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x76e);
4570 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0x948/ 0x67[5] / 0x764 / 0x76e", \
4571 u4Tmp[0], ((u1Tmp[0]&0x20)>> 5), (u4Tmp[1] & 0xffff), u1Tmp[1]);
4572 CL_PRINTF(cliBuf);
4573
4574 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x92c);
4575 u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x930);
4576 u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x944);
4577 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x92c[1:0]/ 0x930[7:0]/0x944[1:0]", \
4578 u4Tmp[0]&0x3, u4Tmp[1]&0xff, u4Tmp[2]&0x3);
4579 CL_PRINTF(cliBuf);
4580
4581 u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x39);
4582 u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x40);
4583 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);
4584 u1Tmp[2] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x64);
4585 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0x38[11]/0x40/0x4c[24:23]/0x64[0]", \
4586 ((u1Tmp[0] & 0x8)>>3), u1Tmp[1], ((u4Tmp[0]&0x01800000)>>23), u1Tmp[2]&0x1);
4587 CL_PRINTF(cliBuf);
4588
4589 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x550);
4590 u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x522);
4591 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0x550(bcn ctrl)/0x522", \
4592 u4Tmp[0], u1Tmp[0]);
4593 CL_PRINTF(cliBuf);
4594
4595 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xc50);
4596 u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x49c);
4597 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0xc50(dig)/0x49c(null-drop)", \
4598 u4Tmp[0]&0xff, u1Tmp[0]);
4599 CL_PRINTF(cliBuf);
4600
4601 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda0);
4602 u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda4);
4603 u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda8);
4604 u4Tmp[3] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xcf0);
4605
4606 u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xa5b);
4607 u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xa5c);
4608
4609 faOfdm = ((u4Tmp[0]&0xffff0000) >> 16) + ((u4Tmp[1]&0xffff0000) >> 16) + (u4Tmp[1] & 0xffff) + (u4Tmp[2] & 0xffff) + \
4610 ((u4Tmp[3]&0xffff0000) >> 16) + (u4Tmp[3] & 0xffff) ;
4611 faCck = (u1Tmp[0] << 8) + u1Tmp[1];
4612
4613 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "OFDM-CCA/OFDM-FA/CCK-FA", \
4614 u4Tmp[0]&0xffff, faOfdm, faCck);
4615 CL_PRINTF(cliBuf);
4616
4617
4618 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", "CRC_OK CCK/11g/11n/11n-Agg", \
4619 pCoexSta->nCRCOK_CCK, pCoexSta->nCRCOK_11g, pCoexSta->nCRCOK_11n, pCoexSta->nCRCOK_11nAgg);
4620 CL_PRINTF(cliBuf);
4621
4622 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d/ %d", "CRC_Err CCK/11g/11n/11n-Agg", \
4623 pCoexSta->nCRCErr_CCK, pCoexSta->nCRCErr_11g, pCoexSta->nCRCErr_11n, pCoexSta->nCRCErr_11nAgg);
4624 CL_PRINTF(cliBuf);
4625
4626 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c0);
4627 u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c4);
4628 u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c8);
4629 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x6c0/0x6c4/0x6c8(coexTable)", \
4630 u4Tmp[0], u4Tmp[1], u4Tmp[2]);
4631 CL_PRINTF(cliBuf);
4632
4633 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x770(high-pri rx/tx)", \
4634 pCoexSta->highPriorityRx, pCoexSta->highPriorityTx);
4635 CL_PRINTF(cliBuf);
4636 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x774(low-pri rx/tx)", \
4637 pCoexSta->lowPriorityRx, pCoexSta->lowPriorityTx);
4638 CL_PRINTF(cliBuf);
4639 #if(BT_AUTO_REPORT_ONLY_8723B_1ANT == 1)
4640 //halbtc8723b1ant_MonitorBtCtr(pBtCoexist);
4641 #endif
4642 pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_COEX_STATISTICS);
4643 }
4644
4645
4646 VOID
EXhalbtc8723b1ant_IpsNotify(IN PBTC_COEXIST pBtCoexist,IN u1Byte type)4647 EXhalbtc8723b1ant_IpsNotify(
4648 IN PBTC_COEXIST pBtCoexist,
4649 IN u1Byte type
4650 )
4651 {
4652 u4Byte u4Tmp=0;
4653
4654 if(pBtCoexist->bManualControl || pBtCoexist->bStopCoexDm)
4655 return;
4656
4657 if(BTC_IPS_ENTER == type)
4658 {
4659 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], IPS ENTER notify\n"));
4660 pCoexSta->bUnderIps = TRUE;
4661
4662 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);
4663 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FORCE_EXEC, FALSE, TRUE);
4664 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
4665 //halbtc8723b1ant_SetAntPathDCut(pBtCoexist, FALSE, FALSE, FALSE, BTC_ANT_PATH_BT, BTC_WIFI_STAT_NORMAL_OFF);
4666 }
4667 else if(BTC_IPS_LEAVE == type)
4668 {
4669 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], IPS LEAVE notify\n"));
4670
4671 halbtc8723b1ant_InitHwConfig(pBtCoexist, FALSE, FALSE);
4672 halbtc8723b1ant_InitCoexDm(pBtCoexist);
4673 halbtc8723b1ant_QueryBtInfo(pBtCoexist);
4674
4675 pCoexSta->bUnderIps = FALSE;
4676 }
4677 }
4678
4679 VOID
EXhalbtc8723b1ant_LpsNotify(IN PBTC_COEXIST pBtCoexist,IN u1Byte type)4680 EXhalbtc8723b1ant_LpsNotify(
4681 IN PBTC_COEXIST pBtCoexist,
4682 IN u1Byte type
4683 )
4684 {
4685 if(pBtCoexist->bManualControl || pBtCoexist->bStopCoexDm)
4686 return;
4687
4688 if(BTC_LPS_ENABLE == type)
4689 {
4690 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], LPS ENABLE notify\n"));
4691 pCoexSta->bUnderLps = TRUE;
4692 }
4693 else if(BTC_LPS_DISABLE == type)
4694 {
4695 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], LPS DISABLE notify\n"));
4696 pCoexSta->bUnderLps = FALSE;
4697 }
4698 }
4699
4700 VOID
EXhalbtc8723b1ant_ScanNotify(IN PBTC_COEXIST pBtCoexist,IN u1Byte type)4701 EXhalbtc8723b1ant_ScanNotify(
4702 IN PBTC_COEXIST pBtCoexist,
4703 IN u1Byte type
4704 )
4705 {
4706 BOOLEAN bWifiConnected=FALSE, bBtHsOn=FALSE;
4707 u4Byte wifiLinkStatus=0;
4708 u4Byte numOfWifiLink=0;
4709 BOOLEAN bBtCtrlAggBufSize=FALSE;
4710 u1Byte aggBufSize=5;
4711
4712 u1Byte u1Tmpa, u1Tmpb;
4713 u4Byte u4Tmp;
4714
4715 if(pBtCoexist->bManualControl ||
4716 pBtCoexist->bStopCoexDm )
4717 return;
4718
4719 if(BTC_SCAN_START == type)
4720 {
4721 pCoexSta->bWiFiIsHighPriTask = TRUE;
4722 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN START notify\n"));
4723 pPsdScan->nAntDet_IsAntDetAvailable = TRUE;
4724 halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8); //Force antenna setup for no scan result issue
4725 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, FORCE_EXEC, FALSE, FALSE);
4726 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x948);
4727 u1Tmpa = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x765);
4728 u1Tmpb = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x67);
4729
4730
4731 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x\n",
4732 u4Tmp, u1Tmpa, u1Tmpb));
4733 }
4734 else
4735 {
4736 pCoexSta->bWiFiIsHighPriTask = FALSE;
4737 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN FINISH notify\n"));
4738
4739 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_AP_NUM, &pCoexSta->nScanAPNum);
4740 }
4741
4742 if(pBtCoexist->btInfo.bBtDisabled)
4743 return;
4744
4745 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
4746 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
4747
4748 halbtc8723b1ant_QueryBtInfo(pBtCoexist);
4749
4750 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);
4751 numOfWifiLink = wifiLinkStatus>>16;
4752 if(numOfWifiLink >= 2)
4753 {
4754 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);
4755 halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, bBtCtrlAggBufSize, aggBufSize);
4756 halbtc8723b1ant_ActionWifiMultiPort(pBtCoexist);
4757 return;
4758 }
4759
4760 if(pCoexSta->bC2hBtInquiryPage)
4761 {
4762 halbtc8723b1ant_ActionBtInquiry(pBtCoexist);
4763 return;
4764 }
4765 else if(bBtHsOn)
4766 {
4767 halbtc8723b1ant_ActionHs(pBtCoexist);
4768 return;
4769 }
4770
4771 if(BTC_SCAN_START == type)
4772 {
4773 //RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN START notify\n"));
4774 if(!bWifiConnected) // non-connected scan
4775 {
4776 halbtc8723b1ant_ActionWifiNotConnectedScan(pBtCoexist);
4777 }
4778 else // wifi is connected
4779 {
4780 halbtc8723b1ant_ActionWifiConnectedScan(pBtCoexist);
4781 }
4782 }
4783 else if(BTC_SCAN_FINISH == type)
4784 {
4785 //RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN FINISH notify\n"));
4786 if(!bWifiConnected) // non-connected scan
4787 {
4788 halbtc8723b1ant_ActionWifiNotConnected(pBtCoexist);
4789 }
4790 else
4791 {
4792 halbtc8723b1ant_ActionWifiConnected(pBtCoexist);
4793 }
4794 }
4795 }
4796
4797 VOID
EXhalbtc8723b1ant_ConnectNotify(IN PBTC_COEXIST pBtCoexist,IN u1Byte type)4798 EXhalbtc8723b1ant_ConnectNotify(
4799 IN PBTC_COEXIST pBtCoexist,
4800 IN u1Byte type
4801 )
4802 {
4803 BOOLEAN bWifiConnected=FALSE, bBtHsOn=FALSE;
4804 u4Byte wifiLinkStatus=0;
4805 u4Byte numOfWifiLink=0;
4806 BOOLEAN bBtCtrlAggBufSize=FALSE;
4807 u1Byte aggBufSize=5;
4808
4809 if(pBtCoexist->bManualControl ||
4810 pBtCoexist->bStopCoexDm ||
4811 pBtCoexist->btInfo.bBtDisabled )
4812 return;
4813
4814 if(BTC_ASSOCIATE_START == type)
4815 {
4816 pCoexSta->bWiFiIsHighPriTask = TRUE;
4817 pPsdScan->nAntDet_IsAntDetAvailable = TRUE;
4818 halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8); //Force antenna setup for no scan result issue
4819 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, FORCE_EXEC, FALSE, FALSE);
4820 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT START notify\n"));
4821 pCoexDm->nArpCnt = 0;
4822 }
4823 else
4824 {
4825 pCoexSta->bWiFiIsHighPriTask = FALSE;
4826 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT FINISH notify\n"));
4827 //pCoexDm->nArpCnt = 0;
4828 }
4829
4830 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);
4831 numOfWifiLink = wifiLinkStatus>>16;
4832 if(numOfWifiLink >= 2)
4833 {
4834 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);
4835 halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, bBtCtrlAggBufSize, aggBufSize);
4836 halbtc8723b1ant_ActionWifiMultiPort(pBtCoexist);
4837 return;
4838 }
4839
4840 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
4841 if(pCoexSta->bC2hBtInquiryPage)
4842 {
4843 halbtc8723b1ant_ActionBtInquiry(pBtCoexist);
4844 return;
4845 }
4846 else if(bBtHsOn)
4847 {
4848 halbtc8723b1ant_ActionHs(pBtCoexist);
4849 return;
4850 }
4851
4852 if(BTC_ASSOCIATE_START == type)
4853 {
4854 //RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT START notify\n"));
4855 halbtc8723b1ant_ActionWifiNotConnectedAssoAuth(pBtCoexist);
4856 }
4857 else if(BTC_ASSOCIATE_FINISH == type)
4858 {
4859 //RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT FINISH notify\n"));
4860
4861 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
4862 if(!bWifiConnected) // non-connected scan
4863 {
4864 halbtc8723b1ant_ActionWifiNotConnected(pBtCoexist);
4865 }
4866 else
4867 {
4868 halbtc8723b1ant_ActionWifiConnected(pBtCoexist);
4869 }
4870 }
4871 }
4872
4873 VOID
EXhalbtc8723b1ant_MediaStatusNotify(IN PBTC_COEXIST pBtCoexist,IN u1Byte type)4874 EXhalbtc8723b1ant_MediaStatusNotify(
4875 IN PBTC_COEXIST pBtCoexist,
4876 IN u1Byte type
4877 )
4878 {
4879 u1Byte H2C_Parameter[3] ={0};
4880 u4Byte wifiBw;
4881 u1Byte wifiCentralChnl;
4882 BOOLEAN bWifiUnderBMode = FALSE;
4883
4884 if(pBtCoexist->bManualControl ||
4885 pBtCoexist->bStopCoexDm ||
4886 pBtCoexist->btInfo.bBtDisabled )
4887 return;
4888
4889 if(BTC_MEDIA_CONNECT == type)
4890 {
4891 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], MEDIA connect notify\n"));
4892 halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 8); //Force antenna setup for no scan result issue
4893 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, FORCE_EXEC, FALSE, FALSE);
4894 pPsdScan->nAntDet_IsAntDetAvailable = TRUE;
4895 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode);
4896
4897 //Set CCK Tx/Rx high Pri except 11b mode
4898 if (bWifiUnderBMode)
4899 {
4900 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cd, 0x00); //CCK Tx
4901 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cf, 0x00); //CCK Rx
4902 }
4903 else
4904 {
4905 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cd, 0x10); //CCK Tx
4906 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cf, 0x10); //CCK Rx
4907 }
4908
4909 pCoexDm->backupArfrCnt1 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x430);
4910 pCoexDm->backupArfrCnt2 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x434);
4911 pCoexDm->backupRetryLimit = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x42a);
4912 pCoexDm->backupAmpduMaxTime = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x456);
4913 }
4914 else
4915 {
4916 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], MEDIA disconnect notify\n"));
4917 pCoexDm->nArpCnt = 0;
4918
4919 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cd, 0x0); //CCK Tx
4920 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cf, 0x0); //CCK Rx
4921
4922 pCoexSta->bCCKEverLock = FALSE;
4923 }
4924
4925 // only 2.4G we need to inform bt the chnl mask
4926 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, &wifiCentralChnl);
4927 if( (BTC_MEDIA_CONNECT == type) &&
4928 (wifiCentralChnl <= 14) )
4929 {
4930 //H2C_Parameter[0] = 0x1;
4931 H2C_Parameter[0] = 0x0;
4932 H2C_Parameter[1] = wifiCentralChnl;
4933 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
4934 if(BTC_WIFI_BW_HT40 == wifiBw)
4935 H2C_Parameter[2] = 0x30;
4936 else
4937 H2C_Parameter[2] = 0x20;
4938 }
4939
4940 pCoexDm->wifiChnlInfo[0] = H2C_Parameter[0];
4941 pCoexDm->wifiChnlInfo[1] = H2C_Parameter[1];
4942 pCoexDm->wifiChnlInfo[2] = H2C_Parameter[2];
4943
4944 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], FW write 0x66=0x%x\n",
4945 H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));
4946
4947 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x66, 3, H2C_Parameter);
4948 }
4949
4950 VOID
EXhalbtc8723b1ant_SpecialPacketNotify(IN PBTC_COEXIST pBtCoexist,IN u1Byte type)4951 EXhalbtc8723b1ant_SpecialPacketNotify(
4952 IN PBTC_COEXIST pBtCoexist,
4953 IN u1Byte type
4954 )
4955 {
4956 BOOLEAN bBtHsOn=FALSE;
4957 u4Byte wifiLinkStatus=0;
4958 u4Byte numOfWifiLink=0;
4959 BOOLEAN bBtCtrlAggBufSize=FALSE, bUnder4way=FALSE;
4960 u1Byte aggBufSize=5;
4961
4962 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way);
4963
4964 if(pBtCoexist->bManualControl ||
4965 pBtCoexist->bStopCoexDm ||
4966 pBtCoexist->btInfo.bBtDisabled )
4967 return;
4968
4969 if( BTC_PACKET_DHCP == type ||
4970 BTC_PACKET_EAPOL == type ||
4971 BTC_PACKET_ARP == type )
4972 {
4973 if (BTC_PACKET_ARP == type)
4974 {
4975 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], special Packet ARP notify\n"));
4976
4977 pCoexDm->nArpCnt++;
4978 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ARP Packet Count = %d\n", pCoexDm->nArpCnt));
4979
4980 if((pCoexDm->nArpCnt >= 10) && (!bUnder4way)) // if APR PKT > 10 after connect, do not go to ActionWifiConnectedSpecialPacket(pBtCoexist)
4981 {
4982 pCoexSta->bWiFiIsHighPriTask = FALSE;
4983 }
4984 else
4985 {
4986 pCoexSta->bWiFiIsHighPriTask = TRUE;
4987 }
4988 }
4989 else
4990 {
4991 pCoexSta->bWiFiIsHighPriTask = TRUE;
4992 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], special Packet DHCP or EAPOL notify\n"));
4993 }
4994 }
4995 else
4996 {
4997 pCoexSta->bWiFiIsHighPriTask = FALSE;
4998 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], special Packet [Type = %d] notify\n", type));
4999 }
5000
5001 pCoexSta->specialPktPeriodCnt = 0;
5002
5003 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);
5004 numOfWifiLink = wifiLinkStatus>>16;
5005 if(numOfWifiLink >= 2)
5006 {
5007 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);
5008 halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, bBtCtrlAggBufSize, aggBufSize);
5009 halbtc8723b1ant_ActionWifiMultiPort(pBtCoexist);
5010 return;
5011 }
5012
5013 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
5014 if(pCoexSta->bC2hBtInquiryPage)
5015 {
5016 halbtc8723b1ant_ActionBtInquiry(pBtCoexist);
5017 return;
5018 }
5019 else if(bBtHsOn)
5020 {
5021 halbtc8723b1ant_ActionHs(pBtCoexist);
5022 return;
5023 }
5024
5025 if( BTC_PACKET_DHCP == type ||
5026 BTC_PACKET_EAPOL == type ||
5027 ( (BTC_PACKET_ARP == type ) && (pCoexSta->bWiFiIsHighPriTask) ) )
5028 {
5029 halbtc8723b1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);
5030 }
5031 }
5032
5033 VOID
EXhalbtc8723b1ant_BtInfoNotify(IN PBTC_COEXIST pBtCoexist,IN pu1Byte tmpBuf,IN u1Byte length)5034 EXhalbtc8723b1ant_BtInfoNotify(
5035 IN PBTC_COEXIST pBtCoexist,
5036 IN pu1Byte tmpBuf,
5037 IN u1Byte length
5038 )
5039 {
5040 PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
5041 u1Byte btInfo=0;
5042 u1Byte i, rspSource=0;
5043 BOOLEAN bWifiConnected=FALSE;
5044 BOOLEAN bBtBusy=FALSE;
5045 PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;
5046
5047 pCoexSta->bC2hBtInfoReqSent = FALSE;
5048
5049 rspSource = tmpBuf[0]&0xf;
5050 if(rspSource >= BT_INFO_SRC_8723B_1ANT_MAX)
5051 rspSource = BT_INFO_SRC_8723B_1ANT_WIFI_FW;
5052 pCoexSta->btInfoC2hCnt[rspSource]++;
5053
5054 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Bt info[%d], length=%d, hex data=[", rspSource, length));
5055 for(i=0; i<length; i++)
5056 {
5057 pCoexSta->btInfoC2h[rspSource][i] = tmpBuf[i];
5058 if(i == 1)
5059 btInfo = tmpBuf[i];
5060 if(i == length-1)
5061 {
5062 RT_TRACE(COMP_COEX, DBG_LOUD, ("0x%02x]\n", tmpBuf[i]));
5063 }
5064 else
5065 {
5066 RT_TRACE(COMP_COEX, DBG_LOUD, ("0x%02x, ", tmpBuf[i]));
5067 }
5068 }
5069
5070 // if 0xff, it means BT is under WHCK test
5071 if (btInfo == 0xff)
5072 pCoexSta->bBtWhckTest = TRUE;
5073 else
5074 pCoexSta->bBtWhckTest = FALSE;
5075
5076 if(BT_INFO_SRC_8723B_1ANT_WIFI_FW != rspSource)
5077 {
5078 pCoexSta->btRetryCnt = // [3:0]
5079 pCoexSta->btInfoC2h[rspSource][2]&0xf;
5080
5081 if (pCoexSta->btRetryCnt >= 1)
5082 pCoexSta->popEventCnt++;
5083
5084 if (pCoexSta->btInfoC2h[rspSource][2]&0x20)
5085 pCoexSta->bC2hBtRemoteNameReq = TRUE;
5086 else
5087 pCoexSta->bC2hBtRemoteNameReq = FALSE;
5088
5089 pCoexSta->btRssi =
5090 pCoexSta->btInfoC2h[rspSource][3]*2-90;
5091 //pCoexSta->btInfoC2h[rspSource][3]*2+10;
5092
5093 pCoexSta->btInfoExt =
5094 pCoexSta->btInfoC2h[rspSource][4];
5095
5096 if (pCoexSta->btInfoC2h[rspSource][1] == 0x49)
5097 {
5098 pCoexSta->nA2DPBitPool =
5099 pCoexSta->btInfoC2h[rspSource][6];
5100 }
5101 else
5102 pCoexSta->nA2DPBitPool = 0;
5103
5104 pCoexSta->bBtTxRxMask = (pCoexSta->btInfoC2h[rspSource][2]&0x40);
5105 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TX_RX_MASK, &pCoexSta->bBtTxRxMask);
5106
5107 #if BT_8723B_1ANT_ANTDET_ENABLE
5108 #if BT_8723B_1ANT_ANTDET_COEXMECHANISMSWITCH_ENABLE
5109 if ((pBoardInfo->btdmAntDetFinish) && (pBoardInfo->btdmAntNumByAntDet == 2))
5110 {
5111 if(pCoexSta->bBtTxRxMask)
5112 {
5113 /* BT into is responded by BT FW and BT RF REG 0x3C != 0x15 => Need to switch BT TRx Mask */
5114 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Switch BT TRx Mask since BT RF REG 0x3C != 0x1\n"));
5115
5116 //BT TRx Mask un-lock 0x2c[0], 0x30[0] = 1
5117 pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x2c, 0x7c45);
5118 pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x30, 0x7c45);
5119
5120 pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x3c, 0x1);
5121 }
5122 }
5123 else
5124 #endif
5125 #endif
5126
5127 {
5128 if(!pCoexSta->bBtTxRxMask)
5129 {
5130 /* BT into is responded by BT FW and BT RF REG 0x3C != 0x15 => Need to switch BT TRx Mask */
5131 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Switch BT TRx Mask since BT RF REG 0x3C != 0x15\n"));
5132 pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x3c, 0x15);
5133
5134 //BT TRx Mask lock 0x2c[0], 0x30[0] = 0
5135 pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x2c, 0x7c44);
5136 pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x30, 0x7c44);
5137 }
5138 }
5139
5140 // Here we need to resend some wifi info to BT
5141 // because bt is reset and loss of the info.
5142 if(pCoexSta->btInfoExt & BIT1)
5143 {
5144 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"));
5145 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
5146 if(bWifiConnected)
5147 {
5148 EXhalbtc8723b1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_CONNECT);
5149 }
5150 else
5151 {
5152 EXhalbtc8723b1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);
5153 }
5154 }
5155
5156 if(pCoexSta->btInfoExt & BIT3)
5157 {
5158 if(!pBtCoexist->bManualControl && !pBtCoexist->bStopCoexDm)
5159 {
5160 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n"));
5161 halbtc8723b1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, FALSE);
5162 }
5163 }
5164 else
5165 {
5166 // BT already NOT ignore Wlan active, do nothing here.
5167 }
5168 #if(BT_AUTO_REPORT_ONLY_8723B_1ANT == 0)
5169 if( (pCoexSta->btInfoExt & BIT4) )
5170 {
5171 // BT auto report already enabled, do nothing
5172 }
5173 else
5174 {
5175 halbtc8723b1ant_BtAutoReport(pBtCoexist, FORCE_EXEC, TRUE);
5176 }
5177 #endif
5178 }
5179
5180 // check BIT2 first ==> check if bt is under inquiry or page scan
5181 if(btInfo & BT_INFO_8723B_1ANT_B_INQ_PAGE)
5182 pCoexSta->bC2hBtInquiryPage = TRUE;
5183 else
5184 pCoexSta->bC2hBtInquiryPage = FALSE;
5185
5186 pCoexSta->nNumOfProfile = 0;
5187
5188 // set link exist status
5189 if(!(btInfo&BT_INFO_8723B_1ANT_B_CONNECTION))
5190 {
5191 pCoexSta->bBtLinkExist = FALSE;
5192 pCoexSta->bPanExist = FALSE;
5193 pCoexSta->bA2dpExist = FALSE;
5194 pCoexSta->bHidExist = FALSE;
5195 pCoexSta->bScoExist = FALSE;
5196
5197 pCoexSta->bBtHiPriLinkExist = FALSE;
5198 }
5199 else // connection exists
5200 {
5201 pCoexSta->bBtLinkExist = TRUE;
5202 if(btInfo & BT_INFO_8723B_1ANT_B_FTP)
5203 {
5204 pCoexSta->bPanExist = TRUE;
5205 pCoexSta->nNumOfProfile++;
5206 }
5207 else
5208 pCoexSta->bPanExist = FALSE;
5209 if(btInfo & BT_INFO_8723B_1ANT_B_A2DP)
5210 {
5211 pCoexSta->bA2dpExist = TRUE;
5212 pCoexSta->nNumOfProfile++;
5213 }
5214 else
5215 pCoexSta->bA2dpExist = FALSE;
5216 if(btInfo & BT_INFO_8723B_1ANT_B_HID)
5217 {
5218 pCoexSta->bHidExist = TRUE;
5219 pCoexSta->nNumOfProfile++;
5220 }
5221 else
5222 pCoexSta->bHidExist = FALSE;
5223 if(btInfo & BT_INFO_8723B_1ANT_B_SCO_ESCO)
5224 {
5225 pCoexSta->bScoExist = TRUE;
5226 pCoexSta->nNumOfProfile++;
5227 }
5228 else
5229 pCoexSta->bScoExist = FALSE;
5230
5231 if ((pCoexSta->bHidExist == FALSE) && (pCoexSta->bC2hBtInquiryPage == FALSE) &&( pCoexSta->bScoExist == FALSE))
5232 {
5233 if (pCoexSta->highPriorityTx + pCoexSta->highPriorityRx >= 160)
5234 {
5235 pCoexSta->bHidExist = TRUE;
5236 pCoexSta->wrongProfileNotification++;
5237 pCoexSta->nNumOfProfile++;
5238 btInfo = btInfo | 0x28;
5239 }
5240 }
5241
5242 //Add Hi-Pri Tx/Rx counter to avoid false detection
5243 if (((pCoexSta->bHidExist) || (pCoexSta->bScoExist)) && (pCoexSta->highPriorityTx + pCoexSta->highPriorityRx >= 160)
5244 && (!pCoexSta->bC2hBtInquiryPage))
5245 pCoexSta->bBtHiPriLinkExist = TRUE;
5246
5247 if((btInfo&BT_INFO_8723B_1ANT_B_ACL_BUSY) && (pCoexSta->nNumOfProfile == 0))
5248 {
5249 if (pCoexSta->lowPriorityTx + pCoexSta->lowPriorityRx >= 160)
5250 {
5251 pCoexSta->bPanExist = TRUE;
5252 pCoexSta->nNumOfProfile++;
5253 pCoexSta->wrongProfileNotification++;
5254 btInfo = btInfo | 0x88;
5255 }
5256 }
5257 }
5258
5259 halbtc8723b1ant_UpdateBtLinkInfo(pBtCoexist);
5260
5261 btInfo = btInfo & 0x1f; //mask profile bit for connect-ilde identification ( for CSR case: A2DP idle --> 0x41)
5262
5263 if(!(btInfo&BT_INFO_8723B_1ANT_B_CONNECTION))
5264 {
5265 pCoexDm->btStatus = BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE;
5266 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n"));
5267 }
5268 else if(btInfo == BT_INFO_8723B_1ANT_B_CONNECTION) // connection exists but no busy
5269 {
5270 pCoexDm->btStatus = BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE;
5271 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n"));
5272 }
5273 else if((btInfo&BT_INFO_8723B_1ANT_B_SCO_ESCO) ||
5274 (btInfo&BT_INFO_8723B_1ANT_B_SCO_BUSY))
5275 {
5276 pCoexDm->btStatus = BT_8723B_1ANT_BT_STATUS_SCO_BUSY;
5277 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT SCO busy!!!\n"));
5278 }
5279 else if(btInfo&BT_INFO_8723B_1ANT_B_ACL_BUSY)
5280 {
5281 if(BT_8723B_1ANT_BT_STATUS_ACL_BUSY != pCoexDm->btStatus)
5282 pCoexDm->bAutoTdmaAdjust = FALSE;
5283 pCoexDm->btStatus = BT_8723B_1ANT_BT_STATUS_ACL_BUSY;
5284 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT ACL busy!!!\n"));
5285 }
5286 else
5287 {
5288 pCoexDm->btStatus = BT_8723B_1ANT_BT_STATUS_MAX;
5289 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n"));
5290 }
5291
5292 if( (BT_8723B_1ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus) ||
5293 (BT_8723B_1ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||
5294 (BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )
5295 bBtBusy = TRUE;
5296 else
5297 bBtBusy = FALSE;
5298 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);
5299
5300 halbtc8723b1ant_RunCoexistMechanism(pBtCoexist);
5301 }
5302
5303 VOID
EXhalbtc8723b1ant_RfStatusNotify(IN PBTC_COEXIST pBtCoexist,IN u1Byte type)5304 EXhalbtc8723b1ant_RfStatusNotify(
5305 IN PBTC_COEXIST pBtCoexist,
5306 IN u1Byte type
5307 )
5308 {
5309 u4Byte u4Tmp;
5310 u1Byte u1Tmpa,u1Tmpb, u1Tmpc;
5311
5312 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RF Status notify\n"));
5313
5314 if(BTC_RF_ON == type)
5315 {
5316 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RF is turned ON!!\n"));
5317 pBtCoexist->bStopCoexDm = FALSE;
5318 }
5319 else if(BTC_RF_OFF == type)
5320 {
5321 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], RF is turned OFF!!\n"));
5322
5323 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
5324 halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 0);
5325 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FORCE_EXEC, FALSE, TRUE);
5326 //halbtc8723b1ant_SetAntPathDCut(pBtCoexist, FALSE, FALSE, FALSE, BTC_ANT_PATH_BT, BTC_WIFI_STAT_NORMAL_OFF);
5327
5328 halbtc8723b1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE);
5329 pBtCoexist->bStopCoexDm = TRUE;
5330
5331 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x948);
5332 u1Tmpa = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x765);
5333 u1Tmpb = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x67);
5334 u1Tmpc = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x76e);
5335
5336
5337 RT_TRACE(COMP_COEX, DBG_LOUD, ("############# [BTCoex], 0x948=0x%x, 0x765=0x%x, 0x67=0x%x, 0x76e=0x%x\n",
5338 u4Tmp, u1Tmpa, u1Tmpb, u1Tmpc));
5339
5340 }
5341 }
5342
5343 VOID
EXhalbtc8723b1ant_HaltNotify(IN PBTC_COEXIST pBtCoexist)5344 EXhalbtc8723b1ant_HaltNotify(
5345 IN PBTC_COEXIST pBtCoexist
5346 )
5347 {
5348 u4Byte u4Tmp;
5349
5350 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Halt notify\n"));
5351
5352 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
5353 halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 0);
5354 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FORCE_EXEC, FALSE, TRUE);
5355 //halbtc8723b1ant_SetAntPathDCut(pBtCoexist, FALSE, FALSE, FALSE, BTC_ANT_PATH_BT, BTC_WIFI_STAT_NORMAL_OFF);
5356
5357 halbtc8723b1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE);
5358
5359 EXhalbtc8723b1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);
5360
5361 pBtCoexist->bStopCoexDm = TRUE;
5362 }
5363
5364 VOID
EXhalbtc8723b1ant_PnpNotify(IN PBTC_COEXIST pBtCoexist,IN u1Byte pnpState)5365 EXhalbtc8723b1ant_PnpNotify(
5366 IN PBTC_COEXIST pBtCoexist,
5367 IN u1Byte pnpState
5368 )
5369 {
5370 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Pnp notify\n"));
5371
5372 if(BTC_WIFI_PNP_SLEEP == pnpState)
5373 {
5374 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Pnp notify to SLEEP\n"));
5375
5376 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
5377 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);
5378 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FORCE_EXEC, FALSE, TRUE);
5379 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
5380 //halbtc8723b1ant_SetAntPathDCut(pBtCoexist, FALSE, FALSE, FALSE, BTC_ANT_PATH_BT, BTC_WIFI_STAT_NORMAL_OFF);
5381
5382 pBtCoexist->bStopCoexDm = TRUE;
5383 }
5384 else if(BTC_WIFI_PNP_WAKE_UP == pnpState)
5385 {
5386 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Pnp notify to WAKE UP\n"));
5387 pBtCoexist->bStopCoexDm = FALSE;
5388 halbtc8723b1ant_InitHwConfig(pBtCoexist, FALSE, FALSE);
5389 halbtc8723b1ant_InitCoexDm(pBtCoexist);
5390 halbtc8723b1ant_QueryBtInfo(pBtCoexist);
5391 }
5392 }
5393
5394 VOID
EXhalbtc8723b1ant_CoexDmReset(IN PBTC_COEXIST pBtCoexist)5395 EXhalbtc8723b1ant_CoexDmReset(
5396 IN PBTC_COEXIST pBtCoexist
5397 )
5398 {
5399 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], *****************Coex DM Reset*****************\n"));
5400
5401 halbtc8723b1ant_InitHwConfig(pBtCoexist, FALSE, FALSE);
5402 //pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
5403 //pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x2, 0xfffff, 0x0);
5404 halbtc8723b1ant_InitCoexDm(pBtCoexist);
5405 }
5406
5407 VOID
EXhalbtc8723b1ant_Periodical(IN PBTC_COEXIST pBtCoexist)5408 EXhalbtc8723b1ant_Periodical(
5409 IN PBTC_COEXIST pBtCoexist
5410 )
5411 {
5412 static u1Byte disVerInfoCnt=0;
5413 u4Byte fwVer=0, btPatchVer=0;
5414 PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;
5415 PBTC_STACK_INFO pStackInfo=&pBtCoexist->stackInfo;
5416 PBTC_BT_LINK_INFO pBtLinkInfo=&pBtCoexist->btLinkInfo;
5417
5418 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ==========================Periodical===========================\n"));
5419
5420 if(disVerInfoCnt <= 5)
5421 {
5422 disVerInfoCnt += 1;
5423 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ****************************************************************\n"));
5424 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Ant PG Num/ Ant Mech/ Ant Pos = %d/ %d/ %d\n",
5425 pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum, pBoardInfo->btdmAntPos));
5426 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT stack/ hci ext ver = %s / %d\n",
5427 ((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion));
5428 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);
5429 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);
5430 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CoexVer/ FwVer/ PatchVer = %d_%x/ 0x%x/ 0x%x(%d)\n",
5431 GLCoexVerDate8723b1Ant, GLCoexVer8723b1Ant, fwVer, btPatchVer, btPatchVer));
5432 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], ****************************************************************\n"));
5433 }
5434
5435 #if(BT_AUTO_REPORT_ONLY_8723B_1ANT == 0)
5436 halbtc8723b1ant_QueryBtInfo(pBtCoexist);
5437 halbtc8723b1ant_MonitorBtEnableDisable(pBtCoexist);
5438 #else
5439 halbtc8723b1ant_MonitorBtCtr(pBtCoexist);
5440 halbtc8723b1ant_MonitorWiFiCtr(pBtCoexist);
5441 #if BT_8723B_1ANT_ANTDET_ENABLE
5442 halbtc8723b1ant_MonitorBtEnableDisable(pBtCoexist);
5443 #endif
5444
5445 if ( (pCoexSta->highPriorityTx + pCoexSta->highPriorityRx < 50) && (pBtLinkInfo->bHidExist == TRUE))
5446 {
5447 pBtLinkInfo->bHidExist = FALSE;
5448 }
5449
5450 if( halbtc8723b1ant_IsWifiStatusChanged(pBtCoexist) ||
5451 pCoexDm->bAutoTdmaAdjust )
5452 {
5453 halbtc8723b1ant_RunCoexistMechanism(pBtCoexist);
5454 }
5455
5456 pCoexSta->specialPktPeriodCnt++;
5457
5458 // sample to set bt to execute Ant detection
5459 //pBtCoexist->fBtcSetBtAntDetection(pBtCoexist, 20, 14);
5460 /*
5461 if (pPsdScan->bIsAntDetEnable)
5462 {
5463 if (pPsdScan->nPSDGenCount > pPsdScan->realseconds)
5464 pPsdScan->nPSDGenCount = 0;
5465
5466 halbtc8723b1ant_AntennaDetection(pBtCoexist, pPsdScan->realcentFreq, pPsdScan->realoffset, pPsdScan->realspan, pPsdScan->realseconds);
5467 pPsdScan->nPSDGenTotalCount +=2;
5468 pPsdScan->nPSDGenCount += 2;
5469 }
5470 */
5471 #endif
5472 }
5473
5474 VOID
EXhalbtc8723b1ant_AntennaDetection(IN PBTC_COEXIST pBtCoexist,IN u4Byte centFreq,IN u4Byte offset,IN u4Byte span,IN u4Byte seconds)5475 EXhalbtc8723b1ant_AntennaDetection(
5476 IN PBTC_COEXIST pBtCoexist,
5477 IN u4Byte centFreq,
5478 IN u4Byte offset,
5479 IN u4Byte span,
5480 IN u4Byte seconds
5481 )
5482 {
5483 static u4Byte AntDetCount = 0, AntDetFailCount = 0;
5484 PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;
5485 BOOLEAN bScan, bRoam;
5486
5487 #if BT_8723B_1ANT_ANTDET_ENABLE
5488
5489 if (seconds == 0)
5490 {
5491 pPsdScan->bAntDet_TryCount = 0;
5492 pPsdScan->bAntDet_FailCount = 0;
5493 AntDetCount = 0;
5494 AntDetFailCount = 0;
5495 pBoardInfo->btdmAntDetFinish = FALSE;
5496 pBoardInfo->btdmAntNumByAntDet = 1;
5497 return;
5498 }
5499
5500 if (!pBoardInfo->btdmAntDetFinish)
5501 {
5502 pPsdScan->nAntDet_IntevalCount = pPsdScan->nAntDet_IntevalCount+2;
5503
5504 if (pPsdScan->nAntDet_IntevalCount >= BT_8723B_1ANT_ANTDET_RETRY_INTERVAL)
5505 {
5506 RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Timer is up, Try Detect!!\n"));
5507 halbtc8723b1ant_PSD_AntennaDetectionCheck(pBtCoexist);
5508
5509 if (pBoardInfo->btdmAntDetFinish)
5510 {
5511 RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Success!!\n"));
5512 #if 1
5513 if (pBoardInfo->btdmAntNumByAntDet == 2)
5514 halbtc8723b1ant_MechanismSwitch(pBtCoexist, TRUE);
5515 else
5516 halbtc8723b1ant_MechanismSwitch(pBtCoexist, FALSE);
5517 #endif
5518 }
5519 else
5520 RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Fail!!\n"));
5521
5522 pPsdScan->nAntDet_IntevalCount = 0;
5523 }
5524 else
5525 {
5526 RT_TRACE(COMP_COEX, DBG_LOUD, ("xxxxxxxxxxxxxxxx AntennaDetect(), Antenna Det Timer is not up! (%d)\n", pPsdScan->nAntDet_IntevalCount));
5527 }
5528
5529 }
5530 #endif
5531
5532
5533 /*
5534 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
5535 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
5536
5537
5538 pPsdScan->nAntDet_BTTxTime = seconds; //0.42ms*50 = 20ms
5539 pPsdScan->nAntDet_BTLEChannel = centFreq;
5540
5541 if (seconds == 0)
5542 {
5543 pPsdScan->bAntDet_TryCount = 0;
5544 pPsdScan->bAntDet_FailCount = 0;
5545 AntDetCount = 0;
5546 AntDetFailCount = 0;
5547 pBoardInfo->btdmAntDetFinish = FALSE;
5548 pBoardInfo->btdmAntNumByAntDet = 1;
5549 return;
5550 }
5551 else
5552 {
5553 AntDetCount++;
5554
5555 pPsdScan->bAntDet_TryCount = AntDetCount;
5556
5557 if (bScan ||bRoam)
5558 {
5559 pBoardInfo->btdmAntDetFinish = FALSE;
5560 pPsdScan->nAntDet_Result = 6;
5561 }
5562 else if (pCoexSta->nNumOfProfile >= 1)
5563 {
5564 pBoardInfo->btdmAntDetFinish = FALSE;
5565 pPsdScan->nAntDet_Result = 7;
5566 }
5567 else if (!pPsdScan->nAntDet_IsAntDetAvailable) //Antenna initial setup is not ready
5568 {
5569 pBoardInfo->btdmAntDetFinish = FALSE;
5570 pPsdScan->nAntDet_Result = 9;
5571 }
5572 else if (pCoexSta->bC2hBtInquiryPage)
5573 {
5574 pBoardInfo->btdmAntDetFinish = FALSE;
5575 pPsdScan->nAntDet_Result = 10;
5576 }
5577 else
5578 {
5579 //halbtc8723b1ant_PSD_AntennaDetection(pBtCoexist, pPsdScan->nAntDet_BTTxTime, pPsdScan->nAntDet_BTLEChannel);
5580 }
5581
5582 if (!pBoardInfo->btdmAntDetFinish)
5583 AntDetFailCount++;
5584
5585 pPsdScan->bAntDet_FailCount = AntDetFailCount;
5586 }
5587 */
5588 }
5589
5590 VOID
EXhalbtc8723b1ant_AntennaIsolation(IN PBTC_COEXIST pBtCoexist,IN u4Byte centFreq,IN u4Byte offset,IN u4Byte span,IN u4Byte seconds)5591 EXhalbtc8723b1ant_AntennaIsolation(
5592 IN PBTC_COEXIST pBtCoexist,
5593 IN u4Byte centFreq,
5594 IN u4Byte offset,
5595 IN u4Byte span,
5596 IN u4Byte seconds
5597 )
5598 {
5599
5600
5601 }
5602
5603 VOID
EXhalbtc8723b1ant_PSDScan(IN PBTC_COEXIST pBtCoexist,IN u4Byte centFreq,IN u4Byte offset,IN u4Byte span,IN u4Byte seconds)5604 EXhalbtc8723b1ant_PSDScan(
5605 IN PBTC_COEXIST pBtCoexist,
5606 IN u4Byte centFreq,
5607 IN u4Byte offset,
5608 IN u4Byte span,
5609 IN u4Byte seconds
5610 )
5611 {
5612
5613
5614 }
5615
5616 VOID
EXhalbtc8723b1ant_DisplayAntDetection(IN PBTC_COEXIST pBtCoexist)5617 EXhalbtc8723b1ant_DisplayAntDetection(
5618 IN PBTC_COEXIST pBtCoexist
5619 )
5620 {
5621 PBTC_BOARD_INFO pBoardInfo=&pBtCoexist->boardInfo;
5622
5623 #if BT_8723B_1ANT_ANTDET_ENABLE
5624 if (pPsdScan->bAntDet_TryCount != 0)
5625 {
5626 halbtc8723b1ant_PSD_ShowAntennaDetectResult(pBtCoexist);
5627
5628 if (pBoardInfo->btdmAntDetFinish)
5629 halbtc8723b1ant_PSD_ShowData(pBtCoexist);
5630 return;
5631 }
5632 #endif
5633
5634 //halbtc8723b1ant_ShowPSDData(pBtCoexist);
5635 }
5636
5637
5638 #endif
5639
5640