1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
4 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
6 ******************************************************************************/
8 #include "Mp_Precomp.h"
10 /* Global variables, these are static variables */
11 static struct coex_dm_8723b_1ant GLCoexDm8723b1Ant;
12 static struct coex_dm_8723b_1ant *pCoexDm = &GLCoexDm8723b1Ant;
13 static struct coex_sta_8723b_1ant GLCoexSta8723b1Ant;
14 static struct coex_sta_8723b_1ant *pCoexSta = &GLCoexSta8723b1Ant;
16 static const char *const GLBtInfoSrc8723b1Ant[] = {
19 "BT Info[bt auto report]",
22 static u32 GLCoexVerDate8723b1Ant = 20140507;
23 static u32 GLCoexVer8723b1Ant = 0x4e;
25 /* local function proto type if needed */
26 /* local function start with halbtc8723b1ant_ */
27 static u8 halbtc8723b1ant_BtRssiState(
28 u8 levelNum, u8 rssiThresh, u8 rssiThresh1
32 u8 btRssiState = pCoexSta->preBtRssiState;
34 btRssi = pCoexSta->btRssi;
38 (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||
39 (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW)
41 if (btRssi >= (rssiThresh + BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT))
43 btRssiState = BTC_RSSI_STATE_HIGH;
45 btRssiState = BTC_RSSI_STATE_STAY_LOW;
47 if (btRssi < rssiThresh)
48 btRssiState = BTC_RSSI_STATE_LOW;
50 btRssiState = BTC_RSSI_STATE_STAY_HIGH;
52 } else if (levelNum == 3) {
53 if (rssiThresh > rssiThresh1)
54 return pCoexSta->preBtRssiState;
57 (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||
58 (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW)
60 if (btRssi >= (rssiThresh + BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT))
61 btRssiState = BTC_RSSI_STATE_MEDIUM;
63 btRssiState = BTC_RSSI_STATE_STAY_LOW;
65 (pCoexSta->preBtRssiState == BTC_RSSI_STATE_MEDIUM) ||
66 (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_MEDIUM)
68 if (btRssi >= (rssiThresh1 + BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT))
69 btRssiState = BTC_RSSI_STATE_HIGH;
70 else if (btRssi < rssiThresh)
71 btRssiState = BTC_RSSI_STATE_LOW;
73 btRssiState = BTC_RSSI_STATE_STAY_MEDIUM;
75 if (btRssi < rssiThresh1)
76 btRssiState = BTC_RSSI_STATE_MEDIUM;
78 btRssiState = BTC_RSSI_STATE_STAY_HIGH;
82 pCoexSta->preBtRssiState = btRssiState;
87 static void halbtc8723b1ant_UpdateRaMask(
88 struct btc_coexist *pBtCoexist, bool bForceExec, u32 disRateMask
91 pCoexDm->curRaMask = disRateMask;
93 if (bForceExec || (pCoexDm->preRaMask != pCoexDm->curRaMask))
96 BTC_SET_ACT_UPDATE_RAMASK,
99 pCoexDm->preRaMask = pCoexDm->curRaMask;
102 static void halbtc8723b1ant_AutoRateFallbackRetry(
103 struct btc_coexist *pBtCoexist, bool bForceExec, u8 type
106 bool bWifiUnderBMode = false;
108 pCoexDm->curArfrType = type;
110 if (bForceExec || (pCoexDm->preArfrType != pCoexDm->curArfrType)) {
111 switch (pCoexDm->curArfrType) {
112 case 0: /* normal mode */
113 pBtCoexist->fBtcWrite4Byte(
114 pBtCoexist, 0x430, pCoexDm->backupArfrCnt1
116 pBtCoexist->fBtcWrite4Byte(
117 pBtCoexist, 0x434, pCoexDm->backupArfrCnt2
122 pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode
124 if (bWifiUnderBMode) {
125 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x430, 0x0);
126 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x434, 0x01010101);
128 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x430, 0x0);
129 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x434, 0x04030201);
137 pCoexDm->preArfrType = pCoexDm->curArfrType;
140 static void halbtc8723b1ant_RetryLimit(
141 struct btc_coexist *pBtCoexist, bool bForceExec, u8 type
144 pCoexDm->curRetryLimitType = type;
148 (pCoexDm->preRetryLimitType != pCoexDm->curRetryLimitType)
150 switch (pCoexDm->curRetryLimitType) {
151 case 0: /* normal mode */
152 pBtCoexist->fBtcWrite2Byte(
153 pBtCoexist, 0x42a, pCoexDm->backupRetryLimit
156 case 1: /* retry limit =8 */
157 pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x42a, 0x0808);
164 pCoexDm->preRetryLimitType = pCoexDm->curRetryLimitType;
167 static void halbtc8723b1ant_AmpduMaxTime(
168 struct btc_coexist *pBtCoexist, bool bForceExec, u8 type
171 pCoexDm->curAmpduTimeType = type;
174 bForceExec || (pCoexDm->preAmpduTimeType != pCoexDm->curAmpduTimeType)
176 switch (pCoexDm->curAmpduTimeType) {
177 case 0: /* normal mode */
178 pBtCoexist->fBtcWrite1Byte(
179 pBtCoexist, 0x456, pCoexDm->backupAmpduMaxTime
182 case 1: /* AMPDU timw = 0x38 * 32us */
183 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x456, 0x38);
190 pCoexDm->preAmpduTimeType = pCoexDm->curAmpduTimeType;
193 static void halbtc8723b1ant_LimitedTx(
194 struct btc_coexist *pBtCoexist,
202 switch (raMaskType) {
203 case 0: /* normal mode */
204 halbtc8723b1ant_UpdateRaMask(pBtCoexist, bForceExec, 0x0);
206 case 1: /* disable cck 1/2 */
207 halbtc8723b1ant_UpdateRaMask(pBtCoexist, bForceExec, 0x00000003);
209 case 2: /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */
210 halbtc8723b1ant_UpdateRaMask(pBtCoexist, bForceExec, 0x0001f1f7);
216 halbtc8723b1ant_AutoRateFallbackRetry(pBtCoexist, bForceExec, arfrType);
217 halbtc8723b1ant_RetryLimit(pBtCoexist, bForceExec, retryLimitType);
218 halbtc8723b1ant_AmpduMaxTime(pBtCoexist, bForceExec, ampduTimeType);
221 static void halbtc8723b1ant_LimitedRx(
222 struct btc_coexist *pBtCoexist,
225 bool bBtCtrlAggBufSize,
229 bool bRejectRxAgg = bRejApAggPkt;
230 bool bBtCtrlRxAggSize = bBtCtrlAggBufSize;
231 u8 rxAggSize = aggBufSize;
234 /* Rx Aggregation related setting */
237 pBtCoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, &bRejectRxAgg
239 /* decide BT control aggregation buf size or not */
241 pBtCoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, &bBtCtrlRxAggSize
243 /* aggregation buf size, only work when BT control Rx aggregation size. */
244 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_AGG_BUF_SIZE, &rxAggSize);
245 /* real update aggregation setting */
246 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
251 static void halbtc8723b1ant_QueryBtInfo(struct btc_coexist *pBtCoexist)
253 u8 H2C_Parameter[1] = {0};
255 pCoexSta->bC2hBtInfoReqSent = true;
257 H2C_Parameter[0] |= BIT0; /* trigger */
259 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x61, 1, H2C_Parameter);
262 static void halbtc8723b1ant_MonitorBtCtr(struct btc_coexist *pBtCoexist)
264 u32 regHPTxRx, regLPTxRx, u4Tmp;
265 u32 regHPTx = 0, regHPRx = 0, regLPTx = 0, regLPRx = 0;
266 static u8 NumOfBtCounterChk;
268 /* to avoid 0x76e[3] = 1 (WLAN_Act control by PTA) during IPS */
269 /* if (! (pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x76e) & 0x8)) */
271 if (pCoexSta->bUnderIps) {
272 pCoexSta->highPriorityTx = 65535;
273 pCoexSta->highPriorityRx = 65535;
274 pCoexSta->lowPriorityTx = 65535;
275 pCoexSta->lowPriorityRx = 65535;
282 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regHPTxRx);
283 regHPTx = u4Tmp & bMaskLWord;
284 regHPRx = (u4Tmp & bMaskHWord) >> 16;
286 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regLPTxRx);
287 regLPTx = u4Tmp & bMaskLWord;
288 regLPRx = (u4Tmp & bMaskHWord) >> 16;
290 pCoexSta->highPriorityTx = regHPTx;
291 pCoexSta->highPriorityRx = regHPRx;
292 pCoexSta->lowPriorityTx = regLPTx;
293 pCoexSta->lowPriorityRx = regLPRx;
295 if ((pCoexSta->lowPriorityTx >= 1050) && (!pCoexSta->bC2hBtInquiryPage))
296 pCoexSta->popEventCnt++;
299 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc);
301 if ((regHPTx == 0) && (regHPRx == 0) && (regLPTx == 0) && (regLPRx == 0)) {
303 if (NumOfBtCounterChk >= 3) {
304 halbtc8723b1ant_QueryBtInfo(pBtCoexist);
305 NumOfBtCounterChk = 0;
311 static void halbtc8723b1ant_MonitorWiFiCtr(struct btc_coexist *pBtCoexist)
314 bool bWifiBusy = false, bWifiUnderBMode = false;
315 static u8 nCCKLockCounter;
317 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
318 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);
320 pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode
323 if (pCoexSta->bUnderIps) {
324 pCoexSta->nCRCOK_CCK = 0;
325 pCoexSta->nCRCOK_11g = 0;
326 pCoexSta->nCRCOK_11n = 0;
327 pCoexSta->nCRCOK_11nAgg = 0;
329 pCoexSta->nCRCErr_CCK = 0;
330 pCoexSta->nCRCErr_11g = 0;
331 pCoexSta->nCRCErr_11n = 0;
332 pCoexSta->nCRCErr_11nAgg = 0;
334 pCoexSta->nCRCOK_CCK = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xf88);
335 pCoexSta->nCRCOK_11g = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf94);
336 pCoexSta->nCRCOK_11n = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf90);
337 pCoexSta->nCRCOK_11nAgg = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xfb8);
339 pCoexSta->nCRCErr_CCK = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xf84);
340 pCoexSta->nCRCErr_11g = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf96);
341 pCoexSta->nCRCErr_11n = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf92);
342 pCoexSta->nCRCErr_11nAgg = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xfba);
347 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xf16, 0x1, 0x1);
348 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xf16, 0x1, 0x0);
350 if (bWifiBusy && (wifiRssi >= 30) && !bWifiUnderBMode) {
352 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_BUSY) ||
353 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY) ||
354 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_SCO_BUSY)
357 pCoexSta->nCRCOK_CCK > (
358 pCoexSta->nCRCOK_11g +
359 pCoexSta->nCRCOK_11n +
360 pCoexSta->nCRCOK_11nAgg
363 if (nCCKLockCounter < 5)
366 if (nCCKLockCounter > 0)
371 if (nCCKLockCounter > 0)
375 if (nCCKLockCounter > 0)
379 if (!pCoexSta->bPreCCKLock) {
381 if (nCCKLockCounter >= 5)
382 pCoexSta->bCCKLock = true;
384 pCoexSta->bCCKLock = false;
386 if (nCCKLockCounter == 0)
387 pCoexSta->bCCKLock = false;
389 pCoexSta->bCCKLock = true;
392 pCoexSta->bPreCCKLock = pCoexSta->bCCKLock;
397 static bool halbtc8723b1ant_IsWifiStatusChanged(struct btc_coexist *pBtCoexist)
399 static bool bPreWifiBusy, bPreUnder4way, bPreBtHsOn;
400 bool bWifiBusy = false, bUnder4way = false, bBtHsOn = false;
401 bool bWifiConnected = false;
404 pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected
406 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
407 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
409 pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way
412 if (bWifiConnected) {
413 if (bWifiBusy != bPreWifiBusy) {
414 bPreWifiBusy = bWifiBusy;
418 if (bUnder4way != bPreUnder4way) {
419 bPreUnder4way = bUnder4way;
423 if (bBtHsOn != bPreBtHsOn) {
424 bPreBtHsOn = bBtHsOn;
432 static void halbtc8723b1ant_UpdateBtLinkInfo(struct btc_coexist *pBtCoexist)
434 struct btc_bt_link_info *pBtLinkInfo = &pBtCoexist->btLinkInfo;
435 bool bBtHsOn = false;
437 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
439 pBtLinkInfo->bBtLinkExist = pCoexSta->bBtLinkExist;
440 pBtLinkInfo->bScoExist = pCoexSta->bScoExist;
441 pBtLinkInfo->bA2dpExist = pCoexSta->bA2dpExist;
442 pBtLinkInfo->bPanExist = pCoexSta->bPanExist;
443 pBtLinkInfo->bHidExist = pCoexSta->bHidExist;
445 /* work around for HS mode. */
447 pBtLinkInfo->bPanExist = true;
448 pBtLinkInfo->bBtLinkExist = true;
451 /* check if Sco only */
453 pBtLinkInfo->bScoExist &&
454 !pBtLinkInfo->bA2dpExist &&
455 !pBtLinkInfo->bPanExist &&
456 !pBtLinkInfo->bHidExist
458 pBtLinkInfo->bScoOnly = true;
460 pBtLinkInfo->bScoOnly = false;
462 /* check if A2dp only */
464 !pBtLinkInfo->bScoExist &&
465 pBtLinkInfo->bA2dpExist &&
466 !pBtLinkInfo->bPanExist &&
467 !pBtLinkInfo->bHidExist
469 pBtLinkInfo->bA2dpOnly = true;
471 pBtLinkInfo->bA2dpOnly = false;
473 /* check if Pan only */
475 !pBtLinkInfo->bScoExist &&
476 !pBtLinkInfo->bA2dpExist &&
477 pBtLinkInfo->bPanExist &&
478 !pBtLinkInfo->bHidExist
480 pBtLinkInfo->bPanOnly = true;
482 pBtLinkInfo->bPanOnly = false;
484 /* check if Hid only */
486 !pBtLinkInfo->bScoExist &&
487 !pBtLinkInfo->bA2dpExist &&
488 !pBtLinkInfo->bPanExist &&
489 pBtLinkInfo->bHidExist
491 pBtLinkInfo->bHidOnly = true;
493 pBtLinkInfo->bHidOnly = false;
496 static u8 halbtc8723b1ant_ActionAlgorithm(struct btc_coexist *pBtCoexist)
498 struct btc_bt_link_info *pBtLinkInfo = &pBtCoexist->btLinkInfo;
499 bool bBtHsOn = false;
500 u8 algorithm = BT_8723B_1ANT_COEX_ALGO_UNDEFINED;
501 u8 numOfDiffProfile = 0;
503 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
505 if (!pBtLinkInfo->bBtLinkExist)
508 if (pBtLinkInfo->bScoExist)
510 if (pBtLinkInfo->bHidExist)
512 if (pBtLinkInfo->bPanExist)
514 if (pBtLinkInfo->bA2dpExist)
517 if (numOfDiffProfile == 1) {
518 if (pBtLinkInfo->bScoExist) {
519 algorithm = BT_8723B_1ANT_COEX_ALGO_SCO;
521 if (pBtLinkInfo->bHidExist) {
522 algorithm = BT_8723B_1ANT_COEX_ALGO_HID;
523 } else if (pBtLinkInfo->bA2dpExist) {
524 algorithm = BT_8723B_1ANT_COEX_ALGO_A2DP;
525 } else if (pBtLinkInfo->bPanExist) {
527 algorithm = BT_8723B_1ANT_COEX_ALGO_PANHS;
529 algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR;
532 } else if (numOfDiffProfile == 2) {
533 if (pBtLinkInfo->bScoExist) {
534 if (pBtLinkInfo->bHidExist) {
535 algorithm = BT_8723B_1ANT_COEX_ALGO_HID;
536 } else if (pBtLinkInfo->bA2dpExist) {
537 algorithm = BT_8723B_1ANT_COEX_ALGO_SCO;
538 } else if (pBtLinkInfo->bPanExist) {
540 algorithm = BT_8723B_1ANT_COEX_ALGO_SCO;
542 algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_HID;
545 if (pBtLinkInfo->bHidExist && pBtLinkInfo->bA2dpExist) {
546 algorithm = BT_8723B_1ANT_COEX_ALGO_HID_A2DP;
547 } else if (pBtLinkInfo->bHidExist && pBtLinkInfo->bPanExist) {
549 algorithm = BT_8723B_1ANT_COEX_ALGO_HID_A2DP;
551 algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_HID;
552 } else if (pBtLinkInfo->bPanExist && pBtLinkInfo->bA2dpExist) {
554 algorithm = BT_8723B_1ANT_COEX_ALGO_A2DP_PANHS;
556 algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_A2DP;
559 } else if (numOfDiffProfile == 3) {
560 if (pBtLinkInfo->bScoExist) {
561 if (pBtLinkInfo->bHidExist && pBtLinkInfo->bA2dpExist) {
562 algorithm = BT_8723B_1ANT_COEX_ALGO_HID;
564 pBtLinkInfo->bHidExist && pBtLinkInfo->bPanExist
567 algorithm = BT_8723B_1ANT_COEX_ALGO_HID_A2DP;
569 algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_HID;
570 } else if (pBtLinkInfo->bPanExist && pBtLinkInfo->bA2dpExist) {
572 algorithm = BT_8723B_1ANT_COEX_ALGO_SCO;
574 algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_HID;
578 pBtLinkInfo->bHidExist &&
579 pBtLinkInfo->bPanExist &&
580 pBtLinkInfo->bA2dpExist
583 algorithm = BT_8723B_1ANT_COEX_ALGO_HID_A2DP;
585 algorithm = BT_8723B_1ANT_COEX_ALGO_HID_A2DP_PANEDR;
588 } else if (numOfDiffProfile >= 3) {
589 if (pBtLinkInfo->bScoExist) {
591 pBtLinkInfo->bHidExist &&
592 pBtLinkInfo->bPanExist &&
593 pBtLinkInfo->bA2dpExist
596 algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_HID;
605 static void halbtc8723b1ant_SetSwPenaltyTxRateAdaptive(
606 struct btc_coexist *pBtCoexist, bool bLowPenaltyRa
609 u8 H2C_Parameter[6] = {0};
611 H2C_Parameter[0] = 0x6; /* opCode, 0x6 = Retry_Penalty */
614 H2C_Parameter[1] |= BIT0;
615 H2C_Parameter[2] = 0x00; /* normal rate except MCS7/6/5, OFDM54/48/36 */
616 H2C_Parameter[3] = 0xf7; /* MCS7 or OFDM54 */
617 H2C_Parameter[4] = 0xf8; /* MCS6 or OFDM48 */
618 H2C_Parameter[5] = 0xf9; /* MCS5 or OFDM36 */
621 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x69, 6, H2C_Parameter);
624 static void halbtc8723b1ant_LowPenaltyRa(
625 struct btc_coexist *pBtCoexist, bool bForceExec, bool bLowPenaltyRa
628 pCoexDm->bCurLowPenaltyRa = bLowPenaltyRa;
631 if (pCoexDm->bPreLowPenaltyRa == pCoexDm->bCurLowPenaltyRa)
634 halbtc8723b1ant_SetSwPenaltyTxRateAdaptive(
635 pBtCoexist, pCoexDm->bCurLowPenaltyRa
638 pCoexDm->bPreLowPenaltyRa = pCoexDm->bCurLowPenaltyRa;
641 static void halbtc8723b1ant_SetCoexTable(
642 struct btc_coexist *pBtCoexist,
649 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c0, val0x6c0);
651 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c4, val0x6c4);
653 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c8, val0x6c8);
655 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cc, val0x6cc);
658 static void halbtc8723b1ant_CoexTable(
659 struct btc_coexist *pBtCoexist,
667 pCoexDm->curVal0x6c0 = val0x6c0;
668 pCoexDm->curVal0x6c4 = val0x6c4;
669 pCoexDm->curVal0x6c8 = val0x6c8;
670 pCoexDm->curVal0x6cc = val0x6cc;
674 (pCoexDm->preVal0x6c0 == pCoexDm->curVal0x6c0) &&
675 (pCoexDm->preVal0x6c4 == pCoexDm->curVal0x6c4) &&
676 (pCoexDm->preVal0x6c8 == pCoexDm->curVal0x6c8) &&
677 (pCoexDm->preVal0x6cc == pCoexDm->curVal0x6cc)
682 halbtc8723b1ant_SetCoexTable(
683 pBtCoexist, val0x6c0, val0x6c4, val0x6c8, val0x6cc
686 pCoexDm->preVal0x6c0 = pCoexDm->curVal0x6c0;
687 pCoexDm->preVal0x6c4 = pCoexDm->curVal0x6c4;
688 pCoexDm->preVal0x6c8 = pCoexDm->curVal0x6c8;
689 pCoexDm->preVal0x6cc = pCoexDm->curVal0x6cc;
692 static void halbtc8723b1ant_CoexTableWithType(
693 struct btc_coexist *pBtCoexist, bool bForceExec, u8 type
696 pCoexSta->nCoexTableType = type;
700 halbtc8723b1ant_CoexTable(
701 pBtCoexist, bForceExec, 0x55555555, 0x55555555, 0xffffff, 0x3
705 halbtc8723b1ant_CoexTable(
706 pBtCoexist, bForceExec, 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3
710 halbtc8723b1ant_CoexTable(
711 pBtCoexist, bForceExec, 0x5a5a5a5a, 0x5a5a5a5a, 0xffffff, 0x3
715 halbtc8723b1ant_CoexTable(
716 pBtCoexist, bForceExec, 0xaaaa5555, 0xaaaa5a5a, 0xffffff, 0x3
720 halbtc8723b1ant_CoexTable(
721 pBtCoexist, bForceExec, 0x55555555, 0xaaaa5a5a, 0xffffff, 0x3
725 halbtc8723b1ant_CoexTable(
726 pBtCoexist, bForceExec, 0x5a5a5a5a, 0xaaaa5a5a, 0xffffff, 0x3
730 halbtc8723b1ant_CoexTable(
731 pBtCoexist, bForceExec, 0x55555555, 0xaaaaaaaa, 0xffffff, 0x3
735 halbtc8723b1ant_CoexTable(
736 pBtCoexist, bForceExec, 0xaaaaaaaa, 0xaaaaaaaa, 0xffffff, 0x3
744 static void halbtc8723b1ant_SetFwIgnoreWlanAct(
745 struct btc_coexist *pBtCoexist, bool bEnable
748 u8 H2C_Parameter[1] = {0};
751 H2C_Parameter[0] |= BIT0; /* function enable */
753 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x63, 1, H2C_Parameter);
756 static void halbtc8723b1ant_IgnoreWlanAct(
757 struct btc_coexist *pBtCoexist, bool bForceExec, bool bEnable
760 pCoexDm->bCurIgnoreWlanAct = bEnable;
763 if (pCoexDm->bPreIgnoreWlanAct == pCoexDm->bCurIgnoreWlanAct)
766 halbtc8723b1ant_SetFwIgnoreWlanAct(pBtCoexist, bEnable);
768 pCoexDm->bPreIgnoreWlanAct = pCoexDm->bCurIgnoreWlanAct;
771 static void halbtc8723b1ant_SetLpsRpwm(
772 struct btc_coexist *pBtCoexist, u8 lpsVal, u8 rpwmVal
778 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_LPS_VAL, &lps);
779 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
782 static void halbtc8723b1ant_LpsRpwm(
783 struct btc_coexist *pBtCoexist, bool bForceExec, u8 lpsVal, u8 rpwmVal
786 pCoexDm->curLps = lpsVal;
787 pCoexDm->curRpwm = rpwmVal;
791 (pCoexDm->preLps == pCoexDm->curLps) &&
792 (pCoexDm->preRpwm == pCoexDm->curRpwm)
797 halbtc8723b1ant_SetLpsRpwm(pBtCoexist, lpsVal, rpwmVal);
799 pCoexDm->preLps = pCoexDm->curLps;
800 pCoexDm->preRpwm = pCoexDm->curRpwm;
803 static void halbtc8723b1ant_SwMechanism(
804 struct btc_coexist *pBtCoexist, bool bLowPenaltyRA
807 halbtc8723b1ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, bLowPenaltyRA);
810 static void halbtc8723b1ant_SetAntPath(
811 struct btc_coexist *pBtCoexist, u8 antPosType, bool bInitHwCfg, bool bWifiOff
814 struct btc_board_info *pBoardInfo = &pBtCoexist->boardInfo;
815 u32 fwVer = 0, u4Tmp = 0, cntBtCalChk = 0;
816 bool bPgExtSwitch = false;
817 bool bUseExtSwitch = false;
818 bool bIsInMpMode = false;
819 u8 H2C_Parameter[2] = {0}, u1Tmp = 0;
821 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_EXT_SWITCH, &bPgExtSwitch);
822 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer); /* [31:16]=fw ver, [15:0]=fw sub ver */
824 if ((fwVer > 0 && fwVer < 0xc0000) || bPgExtSwitch)
825 bUseExtSwitch = true;
828 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x780); /* WiFi TRx Mask on */
829 pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x3c, 0x15); /* BT TRx Mask on */
831 if (fwVer >= 0x180000) {
832 /* Use H2C to set GNT_BT to HIGH */
833 H2C_Parameter[0] = 1;
834 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x6E, 1, H2C_Parameter);
835 } else /* set grant_bt to high */
836 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x18);
838 /* set wlan_act control by PTA */
839 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4);
841 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x1); /* BT select s0/s1 is controlled by WiFi */
843 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x39, 0x8, 0x1);
844 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x974, 0xff);
845 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x944, 0x3, 0x3);
846 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x930, 0x77);
847 } else if (bWifiOff) {
848 if (fwVer >= 0x180000) {
849 /* Use H2C to set GNT_BT to HIGH */
850 H2C_Parameter[0] = 1;
851 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x6E, 1, H2C_Parameter);
852 } else /* set grant_bt to high */
853 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x18);
855 /* set wlan_act to always low */
856 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4);
858 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_IS_IN_MP_MODE, &bIsInMpMode);
860 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x0); /* BT select s0/s1 is controlled by BT */
862 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x1); /* BT select s0/s1 is controlled by WiFi */
864 /* 0x4c[24:23]= 00, Set Antenna control by BT_RFE_CTRL BT Vendor 0xac = 0xf002 */
865 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);
868 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);
870 /* Use H2C to set GNT_BT to LOW */
871 if (fwVer >= 0x180000) {
872 if (pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x765) != 0) {
873 H2C_Parameter[0] = 0;
874 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x6E, 1, H2C_Parameter);
877 /* BT calibration check */
878 while (cntBtCalChk <= 20) {
879 u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x49d);
888 /* set grant_bt to PTA */
889 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x0);
892 if (pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x76e) != 0xc)
893 /* set wlan_act control by PTA */
894 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc);
899 /* 0x4c[23]= 0, 0x4c[24]= 1 Antenna control by WL/BT */
900 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);
903 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);
905 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0); /* fixed internal switch S1->WiFi, S0->BT */
907 if (pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT) {
908 /* tell firmware "no antenna inverse" */
909 H2C_Parameter[0] = 0;
910 H2C_Parameter[1] = 1; /* ext switch type */
911 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter);
913 /* tell firmware "antenna inverse" */
914 H2C_Parameter[0] = 1;
915 H2C_Parameter[1] = 1; /* ext switch type */
916 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter);
921 /* ext switch setting */
922 switch (antPosType) {
923 case BTC_ANT_PATH_WIFI:
924 if (pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)
925 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x1);
927 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x2);
929 case BTC_ANT_PATH_BT:
930 if (pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)
931 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x2);
933 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x1);
936 case BTC_ANT_PATH_PTA:
937 if (pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)
938 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x1);
940 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x2);
946 /* 0x4c[23]= 1, 0x4c[24]= 0 Antenna control by 0x64 */
947 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);
950 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);
952 /* Fix Ext switch Main->S1, Aux->S0 */
953 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x64, 0x1, 0x0);
955 if (pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT) {
957 /* tell firmware "no antenna inverse" */
958 H2C_Parameter[0] = 0;
959 H2C_Parameter[1] = 0; /* internal switch type */
960 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter);
963 /* tell firmware "antenna inverse" */
964 H2C_Parameter[0] = 1;
965 H2C_Parameter[1] = 0; /* internal switch type */
966 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter);
971 /* internal switch setting */
972 switch (antPosType) {
973 case BTC_ANT_PATH_WIFI:
974 if (pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)
975 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);
977 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x280);
979 case BTC_ANT_PATH_BT:
980 if (pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)
981 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x280);
983 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);
986 case BTC_ANT_PATH_PTA:
987 if (pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)
988 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x200);
990 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x80);
996 static void halbtc8723b1ant_SetFwPstdma(
997 struct btc_coexist *pBtCoexist, u8 byte1, u8 byte2, u8 byte3, u8 byte4, u8 byte5
1000 u8 H2C_Parameter[5] = {0};
1001 u8 realByte1 = byte1, realByte5 = byte5;
1002 bool bApEnable = false;
1004 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);
1007 if (byte1 & BIT4 && !(byte1 & BIT5)) {
1016 H2C_Parameter[0] = realByte1;
1017 H2C_Parameter[1] = byte2;
1018 H2C_Parameter[2] = byte3;
1019 H2C_Parameter[3] = byte4;
1020 H2C_Parameter[4] = realByte5;
1022 pCoexDm->psTdmaPara[0] = realByte1;
1023 pCoexDm->psTdmaPara[1] = byte2;
1024 pCoexDm->psTdmaPara[2] = byte3;
1025 pCoexDm->psTdmaPara[3] = byte4;
1026 pCoexDm->psTdmaPara[4] = realByte5;
1028 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x60, 5, H2C_Parameter);
1032 static void halbtc8723b1ant_PsTdma(
1033 struct btc_coexist *pBtCoexist, bool bForceExec, bool bTurnOn, u8 type
1036 struct btc_bt_link_info *pBtLinkInfo = &pBtCoexist->btLinkInfo;
1037 bool bWifiBusy = false;
1038 u8 rssiAdjustVal = 0;
1039 u8 psTdmaByte4Val = 0x50, psTdmaByte0Val = 0x51, psTdmaByte3Val = 0x10;
1040 s8 nWiFiDurationAdjust = 0x0;
1041 /* u32 fwVer = 0; */
1043 pCoexDm->bCurPsTdmaOn = bTurnOn;
1044 pCoexDm->curPsTdma = type;
1046 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
1050 (pCoexDm->bPrePsTdmaOn == pCoexDm->bCurPsTdmaOn) &&
1051 (pCoexDm->prePsTdma == pCoexDm->curPsTdma)
1056 if (pCoexSta->nScanAPNum <= 5)
1057 nWiFiDurationAdjust = 5;
1058 else if (pCoexSta->nScanAPNum >= 40)
1059 nWiFiDurationAdjust = -15;
1060 else if (pCoexSta->nScanAPNum >= 20)
1061 nWiFiDurationAdjust = -10;
1063 if (!pCoexSta->bForceLpsOn) { /* only for A2DP-only case 1/2/9/11 */
1064 psTdmaByte0Val = 0x61; /* no null-pkt */
1065 psTdmaByte3Val = 0x11; /* no tx-pause at BT-slot */
1066 psTdmaByte4Val = 0x10; /* 0x778 = d/1 toggle */
1071 if (pBtLinkInfo->bSlaveRole)
1072 psTdmaByte4Val = psTdmaByte4Val | 0x1; /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */
1077 halbtc8723b1ant_SetFwPstdma(
1078 pBtCoexist, 0x51, 0x1a, 0x1a, 0x0, psTdmaByte4Val
1082 halbtc8723b1ant_SetFwPstdma(
1085 0x3a + nWiFiDurationAdjust,
1092 halbtc8723b1ant_SetFwPstdma(
1095 0x2d + nWiFiDurationAdjust,
1102 halbtc8723b1ant_SetFwPstdma(
1103 pBtCoexist, 0x51, 0x1d, 0x1d, 0x0, 0x10
1107 halbtc8723b1ant_SetFwPstdma(
1108 pBtCoexist, 0x93, 0x15, 0x3, 0x14, 0x0
1112 halbtc8723b1ant_SetFwPstdma(
1113 pBtCoexist, 0x61, 0x15, 0x3, 0x11, 0x10
1117 halbtc8723b1ant_SetFwPstdma(
1118 pBtCoexist, 0x61, 0x20, 0x3, 0x11, 0x11
1122 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x13, 0xc, 0x5, 0x0, 0x0);
1125 halbtc8723b1ant_SetFwPstdma(
1126 pBtCoexist, 0x93, 0x25, 0x3, 0x10, 0x0
1130 halbtc8723b1ant_SetFwPstdma(
1140 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x13, 0xa, 0xa, 0x0, 0x40);
1143 halbtc8723b1ant_SetFwPstdma(
1153 halbtc8723b1ant_SetFwPstdma(
1154 pBtCoexist, 0x51, 0x0a, 0x0a, 0x0, 0x50
1158 halbtc8723b1ant_SetFwPstdma(
1159 pBtCoexist, 0x51, 0x12, 0x12, 0x0, 0x10
1163 halbtc8723b1ant_SetFwPstdma(
1164 pBtCoexist, 0x51, 0x21, 0x3, 0x10, psTdmaByte4Val
1168 halbtc8723b1ant_SetFwPstdma(
1169 pBtCoexist, 0x13, 0xa, 0x3, 0x8, 0x0
1173 halbtc8723b1ant_SetFwPstdma(
1174 pBtCoexist, 0x93, 0x15, 0x3, 0x10, 0x0
1178 halbtc8723b1ant_SetFwPstdma(
1179 pBtCoexist, 0x93, 0x25, 0x3, 0x10, 0x0
1183 halbtc8723b1ant_SetFwPstdma(
1184 pBtCoexist, 0x61, 0x3f, 0x03, 0x11, 0x10
1189 halbtc8723b1ant_SetFwPstdma(
1190 pBtCoexist, 0x61, 0x25, 0x03, 0x11, 0x11
1194 halbtc8723b1ant_SetFwPstdma(
1195 pBtCoexist, 0x61, 0x25, 0x03, 0x11, 0x10
1199 halbtc8723b1ant_SetFwPstdma(
1200 pBtCoexist, 0xe3, 0x25, 0x3, 0x31, 0x18
1204 halbtc8723b1ant_SetFwPstdma(
1205 pBtCoexist, 0xe3, 0x15, 0x3, 0x31, 0x18
1209 halbtc8723b1ant_SetFwPstdma(
1210 pBtCoexist, 0xe3, 0xa, 0x3, 0x31, 0x18
1214 halbtc8723b1ant_SetFwPstdma(
1215 pBtCoexist, 0xe3, 0xa, 0x3, 0x31, 0x18
1219 halbtc8723b1ant_SetFwPstdma(
1220 pBtCoexist, 0xe3, 0x25, 0x3, 0x31, 0x98
1224 halbtc8723b1ant_SetFwPstdma(
1225 pBtCoexist, 0x69, 0x25, 0x3, 0x31, 0x0
1229 halbtc8723b1ant_SetFwPstdma(
1230 pBtCoexist, 0xab, 0x1a, 0x1a, 0x1, 0x10
1234 halbtc8723b1ant_SetFwPstdma(
1235 pBtCoexist, 0x51, 0x30, 0x3, 0x10, 0x10
1239 halbtc8723b1ant_SetFwPstdma(
1240 pBtCoexist, 0xd3, 0x1a, 0x1a, 0x0, 0x58
1244 halbtc8723b1ant_SetFwPstdma(
1245 pBtCoexist, 0x61, 0x35, 0x3, 0x11, 0x11
1249 halbtc8723b1ant_SetFwPstdma(
1250 pBtCoexist, 0xa3, 0x25, 0x3, 0x30, 0x90
1254 halbtc8723b1ant_SetFwPstdma(
1255 pBtCoexist, 0x53, 0x1a, 0x1a, 0x0, 0x10
1259 halbtc8723b1ant_SetFwPstdma(
1260 pBtCoexist, 0x63, 0x1a, 0x1a, 0x0, 0x10
1264 halbtc8723b1ant_SetFwPstdma(
1265 pBtCoexist, 0xd3, 0x12, 0x3, 0x14, 0x50
1268 case 40: /* SoftAP only with no sta associated, BT disable , TDMA mode for power saving */
1269 /* here softap mode screen off will cost 70-80mA for phone */
1270 halbtc8723b1ant_SetFwPstdma(
1271 pBtCoexist, 0x23, 0x18, 0x00, 0x10, 0x24
1277 /* disable PS tdma */
1279 case 8: /* PTA Control */
1280 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x8, 0x0, 0x0, 0x0, 0x0);
1281 halbtc8723b1ant_SetAntPath(
1282 pBtCoexist, BTC_ANT_PATH_PTA, false, false
1286 default: /* Software control, Antenna at BT side */
1287 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x0, 0x0);
1288 halbtc8723b1ant_SetAntPath(
1289 pBtCoexist, BTC_ANT_PATH_BT, false, false
1292 case 9: /* Software control, Antenna at WiFi side */
1293 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x0, 0x0);
1294 halbtc8723b1ant_SetAntPath(
1295 pBtCoexist, BTC_ANT_PATH_WIFI, false, false
1302 pBtCoexist->fBtcSet(
1303 pBtCoexist, BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE, &rssiAdjustVal
1306 /* update pre state */
1307 pCoexDm->bPrePsTdmaOn = pCoexDm->bCurPsTdmaOn;
1308 pCoexDm->prePsTdma = pCoexDm->curPsTdma;
1311 static bool halbtc8723b1ant_IsCommonAction(struct btc_coexist *pBtCoexist)
1313 bool bCommon = false, bWifiConnected = false, bWifiBusy = false;
1315 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
1316 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
1320 pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE
1322 /* halbtc8723b1ant_SwMechanism(pBtCoexist, false); */
1327 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE)
1329 /* halbtc8723b1ant_SwMechanism(pBtCoexist, false); */
1334 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE)
1336 /* halbtc8723b1ant_SwMechanism(pBtCoexist, false); */
1341 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE)
1343 /* halbtc8723b1ant_SwMechanism(pBtCoexist, false); */
1348 (pCoexDm->btStatus != BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE)
1350 /* halbtc8723b1ant_SwMechanism(pBtCoexist, false); */
1361 static void halbtc8723b1ant_TdmaDurationAdjustForAcl(
1362 struct btc_coexist *pBtCoexist, u8 wifiStatus
1365 static s32 up, dn, m, n, WaitCount;
1366 s32 result; /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */
1367 u8 retryCount = 0, btInfoExt;
1370 (wifiStatus == BT_8723B_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN) ||
1371 (wifiStatus == BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN) ||
1372 (wifiStatus == BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SPECIAL_PKT)
1375 pCoexDm->curPsTdma != 1 &&
1376 pCoexDm->curPsTdma != 2 &&
1377 pCoexDm->curPsTdma != 3 &&
1378 pCoexDm->curPsTdma != 9
1380 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 9);
1381 pCoexDm->psTdmaDuAdjType = 9;
1393 if (!pCoexDm->bAutoTdmaAdjust) {
1394 pCoexDm->bAutoTdmaAdjust = true;
1396 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2);
1397 pCoexDm->psTdmaDuAdjType = 2;
1406 /* acquire the BT TRx retry count from BT_Info byte2 */
1407 retryCount = pCoexSta->btRetryCnt;
1408 btInfoExt = pCoexSta->btInfoExt;
1410 if (pCoexSta->lowPriorityTx > 1050 || pCoexSta->lowPriorityRx > 1250)
1416 if (retryCount == 0) { /* no retry in the last 2-second duration */
1423 if (up >= n) { /* if 連續 n 個2秒 retry count為0, 則調寬WiFi duration */
1430 } else if (retryCount <= 3) { /* <=3 retry in the last 2-second duration */
1437 if (dn == 2) { /* if 連續 2 個2秒 retry count< 3, 則調窄WiFi duration */
1439 m++; /* 避免一直在兩個level中來回 */
1443 if (m >= 20) /* m 最大值 = 20 ' 最大120秒 recheck是否調整 WiFi duration. */
1452 } else { /* retry count > 3, 只要1次 retry count > 3, 則調窄WiFi duration */
1454 m++; /* 避免一直在兩個level中來回 */
1458 if (m >= 20) /* m 最大值 = 20 ' 最大120秒 recheck是否調整 WiFi duration. */
1470 BT_INFO_8723B_1ANT_A2DP_BASIC_RATE(btInfoExt) &&
1471 ((pCoexDm->curPsTdma == 1) || (pCoexDm->curPsTdma == 2))
1473 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 9);
1474 pCoexDm->psTdmaDuAdjType = 9;
1475 } else if (pCoexDm->curPsTdma == 1) {
1476 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2);
1477 pCoexDm->psTdmaDuAdjType = 2;
1478 } else if (pCoexDm->curPsTdma == 2) {
1479 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 9);
1480 pCoexDm->psTdmaDuAdjType = 9;
1481 } else if (pCoexDm->curPsTdma == 9) {
1482 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
1483 pCoexDm->psTdmaDuAdjType = 11;
1485 } else if (result == 1) {
1487 BT_INFO_8723B_1ANT_A2DP_BASIC_RATE(btInfoExt) &&
1488 ((pCoexDm->curPsTdma == 1) || (pCoexDm->curPsTdma == 2))
1490 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 9);
1491 pCoexDm->psTdmaDuAdjType = 9;
1492 } else if (pCoexDm->curPsTdma == 11) {
1493 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 9);
1494 pCoexDm->psTdmaDuAdjType = 9;
1495 } else if (pCoexDm->curPsTdma == 9) {
1496 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2);
1497 pCoexDm->psTdmaDuAdjType = 2;
1498 } else if (pCoexDm->curPsTdma == 2) {
1499 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 1);
1500 pCoexDm->psTdmaDuAdjType = 1;
1505 pCoexDm->curPsTdma != 1 &&
1506 pCoexDm->curPsTdma != 2 &&
1507 pCoexDm->curPsTdma != 9 &&
1508 pCoexDm->curPsTdma != 11
1509 ) /* recover to previous adjust type */
1510 halbtc8723b1ant_PsTdma(
1511 pBtCoexist, NORMAL_EXEC, true, pCoexDm->psTdmaDuAdjType
1516 static void halbtc8723b1ant_PsTdmaCheckForPowerSaveState(
1517 struct btc_coexist *pBtCoexist, bool bNewPsState
1522 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_LPS_MODE, &lpsMode);
1524 if (lpsMode) { /* already under LPS state */
1526 /* keep state under LPS, do nothing. */
1527 } else /* will leave LPS state, turn off psTdma first */
1528 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 0);
1529 } else { /* NO PS state */
1530 if (bNewPsState) /* will enter LPS state, turn off psTdma first */
1531 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 0);
1533 /* keep state under NO PS state, do nothing. */
1538 static void halbtc8723b1ant_PowerSaveState(
1539 struct btc_coexist *pBtCoexist, u8 psType, u8 lpsVal, u8 rpwmVal
1542 bool bLowPwrDisable = false;
1545 case BTC_PS_WIFI_NATIVE:
1546 /* recover to original 32k low power setting */
1547 bLowPwrDisable = false;
1548 pBtCoexist->fBtcSet(
1549 pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable
1551 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_NORMAL_LPS, NULL);
1552 pCoexSta->bForceLpsOn = false;
1555 halbtc8723b1ant_PsTdmaCheckForPowerSaveState(pBtCoexist, true);
1556 halbtc8723b1ant_LpsRpwm(pBtCoexist, NORMAL_EXEC, lpsVal, rpwmVal);
1557 /* when coex force to enter LPS, do not enter 32k low power. */
1558 bLowPwrDisable = true;
1559 pBtCoexist->fBtcSet(
1560 pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable
1562 /* power save must executed before psTdma. */
1563 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_ENTER_LPS, NULL);
1564 pCoexSta->bForceLpsOn = true;
1566 case BTC_PS_LPS_OFF:
1567 halbtc8723b1ant_PsTdmaCheckForPowerSaveState(pBtCoexist, false);
1568 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_LEAVE_LPS, NULL);
1569 pCoexSta->bForceLpsOn = false;
1578 /* Software Coex Mechanism start */
1584 /* Non-Software Coex Mechanism start */
1587 static void halbtc8723b1ant_ActionWifiMultiPort(struct btc_coexist *pBtCoexist)
1589 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1591 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 8);
1592 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
1595 static void halbtc8723b1ant_ActionHs(struct btc_coexist *pBtCoexist)
1597 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 5);
1598 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
1601 static void halbtc8723b1ant_ActionBtInquiry(struct btc_coexist *pBtCoexist)
1603 struct btc_bt_link_info *pBtLinkInfo = &pBtCoexist->btLinkInfo;
1604 bool bWifiConnected = false;
1605 bool bApEnable = false;
1606 bool bWifiBusy = false;
1607 bool bBtBusy = false;
1609 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);
1610 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
1611 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
1612 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);
1614 if (!bWifiConnected && !pCoexSta->bWiFiIsHighPriTask) {
1615 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1616 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 8);
1618 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
1620 pBtLinkInfo->bScoExist ||
1621 pBtLinkInfo->bHidExist ||
1622 pBtLinkInfo->bA2dpExist
1624 /* SCO/HID/A2DP busy */
1625 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1626 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 32);
1628 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1629 } else if (pBtLinkInfo->bPanExist || bWifiBusy) {
1630 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1631 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 20);
1633 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1635 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1636 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 8);
1638 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
1642 static void halbtc8723b1ant_ActionBtScoHidOnlyBusy(
1643 struct btc_coexist *pBtCoexist, u8 wifiStatus
1646 struct btc_bt_link_info *pBtLinkInfo = &pBtCoexist->btLinkInfo;
1647 bool bWifiConnected = false;
1649 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
1651 /* tdma and coex table */
1653 if (pBtLinkInfo->bScoExist) {
1654 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 5);
1655 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 5);
1657 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 6);
1658 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 5);
1662 static void halbtc8723b1ant_ActionWifiConnectedBtAclBusy(
1663 struct btc_coexist *pBtCoexist, u8 wifiStatus
1666 struct btc_bt_link_info *pBtLinkInfo = &pBtCoexist->btLinkInfo;
1668 halbtc8723b1ant_BtRssiState(2, 28, 0);
1670 if ((pCoexSta->lowPriorityRx >= 1000) && (pCoexSta->lowPriorityRx != 65535))
1671 pBtLinkInfo->bSlaveRole = true;
1673 pBtLinkInfo->bSlaveRole = false;
1675 if (pBtLinkInfo->bHidOnly) { /* HID */
1676 halbtc8723b1ant_ActionBtScoHidOnlyBusy(pBtCoexist, wifiStatus);
1677 pCoexDm->bAutoTdmaAdjust = false;
1679 } else if (pBtLinkInfo->bA2dpOnly) { /* A2DP */
1680 if (wifiStatus == BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE) {
1681 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 32);
1682 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1683 pCoexDm->bAutoTdmaAdjust = false;
1685 halbtc8723b1ant_TdmaDurationAdjustForAcl(pBtCoexist, wifiStatus);
1686 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1687 pCoexDm->bAutoTdmaAdjust = true;
1689 } else if (pBtLinkInfo->bHidExist && pBtLinkInfo->bA2dpExist) { /* HID+A2DP */
1690 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 14);
1691 pCoexDm->bAutoTdmaAdjust = false;
1693 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1695 pBtLinkInfo->bPanOnly ||
1696 (pBtLinkInfo->bHidExist && pBtLinkInfo->bPanExist)
1697 ) { /* PAN(OPP, FTP), HID+PAN(OPP, FTP) */
1698 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
1699 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1700 pCoexDm->bAutoTdmaAdjust = false;
1702 (pBtLinkInfo->bA2dpExist && pBtLinkInfo->bPanExist) ||
1703 (pBtLinkInfo->bHidExist && pBtLinkInfo->bA2dpExist && pBtLinkInfo->bPanExist)
1704 ) { /* A2DP+PAN(OPP, FTP), HID+A2DP+PAN(OPP, FTP) */
1705 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 13);
1706 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1707 pCoexDm->bAutoTdmaAdjust = false;
1709 /* BT no-profile busy (0x9) */
1710 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 32);
1711 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1712 pCoexDm->bAutoTdmaAdjust = false;
1716 static void halbtc8723b1ant_ActionWifiNotConnected(struct btc_coexist *pBtCoexist)
1718 /* power save state */
1719 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1721 /* tdma and coex table */
1722 halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, false, 8);
1723 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
1726 static void halbtc8723b1ant_ActionWifiNotConnectedScan(
1727 struct btc_coexist *pBtCoexist
1730 struct btc_bt_link_info *pBtLinkInfo = &pBtCoexist->btLinkInfo;
1732 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1734 /* tdma and coex table */
1735 if (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_BUSY) {
1736 if (pBtLinkInfo->bA2dpExist) {
1737 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 32);
1738 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1739 } else if (pBtLinkInfo->bA2dpExist && pBtLinkInfo->bPanExist) {
1740 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 22);
1741 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1743 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 20);
1744 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1747 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_SCO_BUSY) ||
1748 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY)
1750 halbtc8723b1ant_ActionBtScoHidOnlyBusy(
1751 pBtCoexist, BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN
1755 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 8);
1756 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
1760 static void halbtc8723b1ant_ActionWifiNotConnectedAssoAuth(
1761 struct btc_coexist *pBtCoexist
1764 struct btc_bt_link_info *pBtLinkInfo = &pBtCoexist->btLinkInfo;
1766 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1768 /* tdma and coex table */
1770 (pBtLinkInfo->bScoExist) ||
1771 (pBtLinkInfo->bHidExist) ||
1772 (pBtLinkInfo->bA2dpExist)
1774 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 32);
1775 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1776 } else if (pBtLinkInfo->bPanExist) {
1777 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 20);
1778 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1780 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 8);
1781 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
1785 static void halbtc8723b1ant_ActionWifiConnectedScan(struct btc_coexist *pBtCoexist)
1787 struct btc_bt_link_info *pBtLinkInfo = &pBtCoexist->btLinkInfo;
1789 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1791 /* tdma and coex table */
1792 if (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_BUSY) {
1793 if (pBtLinkInfo->bA2dpExist) {
1794 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 32);
1795 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1796 } else if (pBtLinkInfo->bA2dpExist && pBtLinkInfo->bPanExist) {
1797 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 22);
1798 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1800 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 20);
1801 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1804 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_SCO_BUSY) ||
1805 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY)
1807 halbtc8723b1ant_ActionBtScoHidOnlyBusy(
1808 pBtCoexist, BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN
1812 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 8);
1813 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
1817 static void halbtc8723b1ant_ActionWifiConnectedSpecialPacket(
1818 struct btc_coexist *pBtCoexist
1821 struct btc_bt_link_info *pBtLinkInfo = &pBtCoexist->btLinkInfo;
1823 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1825 /* tdma and coex table */
1827 (pBtLinkInfo->bScoExist) ||
1828 (pBtLinkInfo->bHidExist) ||
1829 (pBtLinkInfo->bA2dpExist)
1831 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 32);
1832 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1833 } else if (pBtLinkInfo->bPanExist) {
1834 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 20);
1835 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1837 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 8);
1838 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
1842 static void halbtc8723b1ant_ActionWifiConnected(struct btc_coexist *pBtCoexist)
1844 bool bWifiBusy = false;
1845 bool bScan = false, bLink = false, bRoam = false;
1846 bool bUnder4way = false, bApEnable = false;
1848 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way);
1850 halbtc8723b1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);
1854 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
1855 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
1856 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
1857 if (bScan || bLink || bRoam) {
1859 halbtc8723b1ant_ActionWifiConnectedScan(pBtCoexist);
1861 halbtc8723b1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);
1865 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);
1866 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
1868 /* power save state */
1871 pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_BUSY &&
1872 !pBtCoexist->btLinkInfo.bHidOnly
1874 if (pBtCoexist->btLinkInfo.bA2dpOnly) { /* A2DP */
1876 halbtc8723b1ant_PowerSaveState(
1877 pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0
1880 if (pCoexSta->nScanAPNum >= BT_8723B_1ANT_WIFI_NOISY_THRESH) /* no force LPS, no PS-TDMA, use pure TDMA */
1881 halbtc8723b1ant_PowerSaveState(
1882 pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0
1885 halbtc8723b1ant_PowerSaveState(
1886 pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4
1890 (!pCoexSta->bPanExist) &&
1891 (!pCoexSta->bA2dpExist) &&
1892 (!pCoexSta->bHidExist)
1894 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1896 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
1898 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1900 /* tdma and coex table */
1902 if (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_BUSY) {
1903 halbtc8723b1ant_ActionWifiConnectedBtAclBusy(
1905 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE
1908 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_SCO_BUSY) ||
1909 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY)
1911 halbtc8723b1ant_ActionBtScoHidOnlyBusy(pBtCoexist,
1912 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE);
1914 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 8);
1916 if ((pCoexSta->highPriorityTx) + (pCoexSta->highPriorityRx) <= 60)
1917 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
1919 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
1922 if (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_BUSY) {
1923 halbtc8723b1ant_ActionWifiConnectedBtAclBusy(
1925 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY
1928 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_SCO_BUSY) ||
1929 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY)
1931 halbtc8723b1ant_ActionBtScoHidOnlyBusy(
1933 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY
1936 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 8);
1938 if ((pCoexSta->highPriorityTx) + (pCoexSta->highPriorityRx) <= 60)
1939 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
1941 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
1946 static void halbtc8723b1ant_RunSwCoexistMechanism(struct btc_coexist *pBtCoexist)
1950 algorithm = halbtc8723b1ant_ActionAlgorithm(pBtCoexist);
1951 pCoexDm->curAlgorithm = algorithm;
1953 if (halbtc8723b1ant_IsCommonAction(pBtCoexist)) {
1956 switch (pCoexDm->curAlgorithm) {
1957 case BT_8723B_1ANT_COEX_ALGO_SCO:
1958 /* halbtc8723b1ant_ActionSco(pBtCoexist); */
1960 case BT_8723B_1ANT_COEX_ALGO_HID:
1961 /* halbtc8723b1ant_ActionHid(pBtCoexist); */
1963 case BT_8723B_1ANT_COEX_ALGO_A2DP:
1964 /* halbtc8723b1ant_ActionA2dp(pBtCoexist); */
1966 case BT_8723B_1ANT_COEX_ALGO_A2DP_PANHS:
1967 /* halbtc8723b1ant_ActionA2dpPanHs(pBtCoexist); */
1969 case BT_8723B_1ANT_COEX_ALGO_PANEDR:
1970 /* halbtc8723b1ant_ActionPanEdr(pBtCoexist); */
1972 case BT_8723B_1ANT_COEX_ALGO_PANHS:
1973 /* halbtc8723b1ant_ActionPanHs(pBtCoexist); */
1975 case BT_8723B_1ANT_COEX_ALGO_PANEDR_A2DP:
1976 /* halbtc8723b1ant_ActionPanEdrA2dp(pBtCoexist); */
1978 case BT_8723B_1ANT_COEX_ALGO_PANEDR_HID:
1979 /* halbtc8723b1ant_ActionPanEdrHid(pBtCoexist); */
1981 case BT_8723B_1ANT_COEX_ALGO_HID_A2DP_PANEDR:
1982 /* halbtc8723b1ant_ActionHidA2dpPanEdr(pBtCoexist); */
1984 case BT_8723B_1ANT_COEX_ALGO_HID_A2DP:
1985 /* halbtc8723b1ant_ActionHidA2dp(pBtCoexist); */
1990 pCoexDm->preAlgorithm = pCoexDm->curAlgorithm;
1994 static void halbtc8723b1ant_RunCoexistMechanism(struct btc_coexist *pBtCoexist)
1996 struct btc_bt_link_info *pBtLinkInfo = &pBtCoexist->btLinkInfo;
1997 bool bWifiConnected = false, bBtHsOn = false;
1998 bool bIncreaseScanDevNum = false;
1999 bool bBtCtrlAggBufSize = false;
2001 u32 wifiLinkStatus = 0;
2002 u32 numOfWifiLink = 0;
2004 if (pBtCoexist->bManualControl)
2007 if (pBtCoexist->bStopCoexDm)
2010 if (pCoexSta->bUnderIps)
2014 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_BUSY) ||
2015 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_SCO_BUSY) ||
2016 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY)
2018 bIncreaseScanDevNum = true;
2021 pBtCoexist->fBtcSet(
2023 BTC_SET_BL_INC_SCAN_DEV_NUM,
2024 &bIncreaseScanDevNum
2026 pBtCoexist->fBtcGet(
2028 BTC_GET_BL_WIFI_CONNECTED,
2032 pBtCoexist->fBtcGet(
2034 BTC_GET_U4_WIFI_LINK_STATUS,
2037 numOfWifiLink = wifiLinkStatus >> 16;
2039 if ((numOfWifiLink >= 2) || (wifiLinkStatus & WIFI_P2P_GO_CONNECTED)) {
2040 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);
2041 halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, bBtCtrlAggBufSize, aggBufSize);
2043 if ((pBtLinkInfo->bA2dpExist) && (pCoexSta->bC2hBtInquiryPage))
2044 halbtc8723b1ant_ActionBtInquiry(pBtCoexist);
2046 halbtc8723b1ant_ActionWifiMultiPort(pBtCoexist);
2051 if ((pBtLinkInfo->bBtLinkExist) && (bWifiConnected)) {
2052 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 1, 1, 0, 1);
2054 if (pBtLinkInfo->bScoExist)
2055 halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, true, 0x5);
2057 halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, true, 0x8);
2059 halbtc8723b1ant_SwMechanism(pBtCoexist, true);
2060 halbtc8723b1ant_RunSwCoexistMechanism(pBtCoexist); /* just print debug message */
2062 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);
2064 halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x5);
2066 halbtc8723b1ant_SwMechanism(pBtCoexist, false);
2067 halbtc8723b1ant_RunSwCoexistMechanism(pBtCoexist); /* just print debug message */
2070 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
2071 if (pCoexSta->bC2hBtInquiryPage) {
2072 halbtc8723b1ant_ActionBtInquiry(pBtCoexist);
2074 } else if (bBtHsOn) {
2075 halbtc8723b1ant_ActionHs(pBtCoexist);
2080 if (!bWifiConnected) {
2081 bool bScan = false, bLink = false, bRoam = false;
2083 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
2084 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
2085 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
2087 if (bScan || bLink || bRoam) {
2089 halbtc8723b1ant_ActionWifiNotConnectedScan(pBtCoexist);
2091 halbtc8723b1ant_ActionWifiNotConnectedAssoAuth(pBtCoexist);
2093 halbtc8723b1ant_ActionWifiNotConnected(pBtCoexist);
2094 } else /* wifi LPS/Busy */
2095 halbtc8723b1ant_ActionWifiConnected(pBtCoexist);
2098 static void halbtc8723b1ant_InitCoexDm(struct btc_coexist *pBtCoexist)
2100 /* force to reset coex mechanism */
2103 halbtc8723b1ant_SwMechanism(pBtCoexist, false);
2105 /* halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, false, 8); */
2106 halbtc8723b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);
2108 pCoexSta->popEventCnt = 0;
2111 static void halbtc8723b1ant_InitHwConfig(
2112 struct btc_coexist *pBtCoexist,
2117 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x550, 0x8, 0x1); /* enable TBTT nterrupt */
2119 /* 0x790[5:0]= 0x5 */
2120 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x790, 0x5);
2122 /* Enable counter statistics */
2123 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x778, 0x1);
2124 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x40, 0x20, 0x1);
2126 /* Antenna config */
2128 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_WIFI, true, false);
2129 halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, false, 9);
2131 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, true, false);
2134 halbtc8723b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);
2136 pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x948);
2137 pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x765);
2138 pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x67);
2142 /* work around function start with wa_halbtc8723b1ant_ */
2145 /* extern function start with EXhalbtc8723b1ant_ */
2147 void EXhalbtc8723b1ant_PowerOnSetting(struct btc_coexist *pBtCoexist)
2149 struct btc_board_info *pBoardInfo = &pBtCoexist->boardInfo;
2153 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x67, 0x20);
2155 /* enable BB, REG_SYS_FUNC_EN such that we can write 0x948 correctly. */
2156 u2Tmp = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x2);
2157 pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x2, u2Tmp | BIT0 | BIT1);
2159 /* set GRAN_BT = 1 */
2160 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x18);
2161 /* set WLAN_ACT = 0 */
2162 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4);
2165 /* S0 or S1 setting and Local register setting(By the setting fw can get ant number, S0/S1, ... info) */
2166 /* Local setting bit define */
2167 /* BIT0: "0" for no antenna inverse; "1" for antenna inverse */
2168 /* BIT1: "0" for internal switch; "1" for external switch */
2169 /* BIT2: "0" for one antenna; "1" for two antenna */
2170 /* NOTE: here default all internal switch and 1-antenna ==> BIT1 = 0 and BIT2 = 0 */
2171 if (pBtCoexist->chipInterface == BTC_INTF_USB) {
2172 /* fixed at S0 for USB interface */
2173 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);
2175 u1Tmp |= 0x1; /* antenna inverse */
2176 pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0xfe08, u1Tmp);
2178 pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_AUX_PORT;
2180 /* for PCIE and SDIO interface, we check efuse 0xc3[6] */
2181 if (pBoardInfo->singleAntPath == 0) {
2183 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x280);
2184 pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
2185 } else if (pBoardInfo->singleAntPath == 1) {
2187 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);
2188 u1Tmp |= 0x1; /* antenna inverse */
2189 pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_AUX_PORT;
2192 if (pBtCoexist->chipInterface == BTC_INTF_PCI)
2193 pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0x384, u1Tmp);
2194 else if (pBtCoexist->chipInterface == BTC_INTF_SDIO)
2195 pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0x60, u1Tmp);
2199 void EXhalbtc8723b1ant_InitHwConfig(struct btc_coexist *pBtCoexist, bool bWifiOnly)
2201 halbtc8723b1ant_InitHwConfig(pBtCoexist, true, bWifiOnly);
2204 void EXhalbtc8723b1ant_InitCoexDm(struct btc_coexist *pBtCoexist)
2206 pBtCoexist->bStopCoexDm = false;
2208 halbtc8723b1ant_InitCoexDm(pBtCoexist);
2210 halbtc8723b1ant_QueryBtInfo(pBtCoexist);
2213 void EXhalbtc8723b1ant_DisplayCoexInfo(struct btc_coexist *pBtCoexist)
2215 struct btc_board_info *pBoardInfo = &pBtCoexist->boardInfo;
2216 struct btc_stack_info *pStackInfo = &pBtCoexist->stackInfo;
2217 struct btc_bt_link_info *pBtLinkInfo = &pBtCoexist->btLinkInfo;
2218 u8 *cliBuf = pBtCoexist->cliBuf;
2219 u8 u1Tmp[4], i, btInfoExt, psTdmaCase = 0;
2225 bool bWifiUnder5G = false;
2226 bool bWifiUnderBMode = false;
2227 bool bBtHsOn = false;
2228 bool bWifiBusy = false;
2229 s32 wifiRssi = 0, btHsRssi = 0;
2230 u32 wifiBw, wifiTrafficDir, faOfdm, faCck, wifiLinkStatus;
2231 u8 wifiDot11Chnl, wifiHsChnl;
2232 u32 fwVer = 0, btPatchVer = 0;
2233 static u8 PopReportIn10s;
2238 "\r\n ============[BT Coexist info]============"
2242 if (pBtCoexist->bManualControl) {
2246 "\r\n ============[Under Manual Control]============"
2251 "\r\n =========================================="
2255 if (pBtCoexist->bStopCoexDm) {
2259 "\r\n ============[Coex is STOPPED]============"
2265 "\r\n =========================================="
2273 "\r\n %-35s = %d/ %d/ %d", "Ant PG Num/ Ant Mech/ Ant Pos:",
2274 pBoardInfo->pgAntNum,
2275 pBoardInfo->btdmAntNum,
2276 pBoardInfo->btdmAntPos
2283 "\r\n %-35s = %s / %d", "BT stack/ hci ext ver",
2284 ((pStackInfo->bProfileNotified) ? "Yes" : "No"),
2285 pStackInfo->hciVersion
2289 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);
2290 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);
2294 "\r\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)", "CoexVer/ FwVer/ PatchVer",
2295 GLCoexVerDate8723b1Ant,
2303 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
2304 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_DOT11_CHNL, &wifiDot11Chnl);
2305 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_HS_CHNL, &wifiHsChnl);
2309 "\r\n %-35s = %d / %d(%d)", "Dot11 channel / HsChnl(HsMode)",
2319 "\r\n %-35s = %02x %02x %02x ", "H2C Wifi inform bt chnl Info",
2320 pCoexDm->wifiChnlInfo[0],
2321 pCoexDm->wifiChnlInfo[1],
2322 pCoexDm->wifiChnlInfo[2]
2326 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);
2327 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_HS_RSSI, &btHsRssi);
2331 "\r\n %-35s = %d/ %d", "Wifi rssi/ HS rssi",
2332 wifiRssi - 100, btHsRssi - 100
2336 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
2337 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
2338 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
2342 "\r\n %-35s = %d/ %d/ %d/ %s", "Wifi bLink/ bRoam/ bScan/ bHi-Pri",
2343 bLink, bRoam, bScan, ((pCoexSta->bWiFiIsHighPriTask) ? "1" : "0")
2347 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_5G, &bWifiUnder5G);
2348 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
2349 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
2350 pBtCoexist->fBtcGet(
2351 pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifiTrafficDir
2353 pBtCoexist->fBtcGet(
2354 pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode
2360 "\r\n %-35s = %s / %s/ %s/ AP =%d/ %s ", "Wifi status",
2361 (bWifiUnder5G ? "5G" : "2.4G"),
2362 ((bWifiUnderBMode) ? "11b" : ((wifiBw == BTC_WIFI_BW_LEGACY) ? "11bg" : (((wifiBw == BTC_WIFI_BW_HT40) ? "HT40" : "HT20")))),
2363 ((!bWifiBusy) ? "idle" : ((wifiTrafficDir == BTC_WIFI_TRAFFIC_TX) ? "uplink" : "downlink")),
2364 pCoexSta->nScanAPNum,
2365 (pCoexSta->bCCKLock) ? "Lock" : "noLock"
2369 pBtCoexist->fBtcGet(
2370 pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus
2375 "\r\n %-35s = %d/ %d/ %d/ %d/ %d", "sta/vwifi/hs/p2pGo/p2pGc",
2376 ((wifiLinkStatus & WIFI_STA_CONNECTED) ? 1 : 0),
2377 ((wifiLinkStatus & WIFI_AP_CONNECTED) ? 1 : 0),
2378 ((wifiLinkStatus & WIFI_HS_CONNECTED) ? 1 : 0),
2379 ((wifiLinkStatus & WIFI_P2P_GO_CONNECTED) ? 1 : 0),
2380 ((wifiLinkStatus & WIFI_P2P_GC_CONNECTED) ? 1 : 0)
2389 "\r\n %-35s = [%s/ %d/ %d/ %d] ", "BT [status/ rssi/ retryCnt/ popCnt]",
2390 ((pBtCoexist->btInfo.bBtDisabled) ? ("disabled") : ((pCoexSta->bC2hBtInquiryPage) ? ("inquiry/page scan") : ((pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE) ? "non-connected idle" :
2391 ((pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE) ? "connected-idle" : "busy")))),
2392 pCoexSta->btRssi, pCoexSta->btRetryCnt, pCoexSta->popEventCnt
2396 if (PopReportIn10s >= 5) {
2397 pCoexSta->popEventCnt = 0;
2405 "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP",
2406 pBtLinkInfo->bScoExist,
2407 pBtLinkInfo->bHidExist,
2408 pBtLinkInfo->bPanExist,
2409 pBtLinkInfo->bA2dpExist
2413 if (pStackInfo->bProfileNotified) {
2414 pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_BT_LINK_INFO);
2416 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "BT Role",
2417 (pBtLinkInfo->bSlaveRole) ? "Slave" : "Master");
2422 btInfoExt = pCoexSta->btInfoExt;
2426 "\r\n %-35s = %s", "BT Info A2DP rate",
2427 (btInfoExt & BIT0) ? "Basic rate" : "EDR rate"
2431 for (i = 0; i < BT_INFO_SRC_8723B_1ANT_MAX; i++) {
2432 if (pCoexSta->btInfoC2hCnt[i]) {
2436 "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", GLBtInfoSrc8723b1Ant[i],
2437 pCoexSta->btInfoC2h[i][0], pCoexSta->btInfoC2h[i][1],
2438 pCoexSta->btInfoC2h[i][2], pCoexSta->btInfoC2h[i][3],
2439 pCoexSta->btInfoC2h[i][4], pCoexSta->btInfoC2h[i][5],
2440 pCoexSta->btInfoC2h[i][6], pCoexSta->btInfoC2hCnt[i]
2448 "\r\n %-35s = %s/%s, (0x%x/0x%x)", "PS state, IPS/LPS, (lps/rpwm)",
2449 (pCoexSta->bUnderIps ? "IPS ON" : "IPS OFF"),
2450 (pCoexSta->bUnderLps ? "LPS ON" : "LPS OFF"),
2451 pBtCoexist->btInfo.lpsVal,
2452 pBtCoexist->btInfo.rpwmVal
2455 pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_FW_PWR_MODE_CMD);
2457 if (!pBtCoexist->bManualControl) {
2462 "\r\n %-35s", "============[Sw mechanism]============"
2469 "\r\n %-35s = %d", "SM[LowPenaltyRA]",
2470 pCoexDm->bCurLowPenaltyRa
2477 "\r\n %-35s = %s/ %s/ %d ", "DelBA/ BtCtrlAgg/ AggSize",
2478 (pBtCoexist->btInfo.bRejectAggPkt ? "Yes" : "No"),
2479 (pBtCoexist->btInfo.bBtCtrlAggBufSize ? "Yes" : "No"),
2480 pBtCoexist->btInfo.aggBufSize
2486 "\r\n %-35s = 0x%x ", "Rate Mask",
2487 pBtCoexist->btInfo.raMask
2492 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw mechanism]============");
2495 psTdmaCase = pCoexDm->curPsTdma;
2496 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (auto:%d)", "PS TDMA",
2497 pCoexDm->psTdmaPara[0], pCoexDm->psTdmaPara[1],
2498 pCoexDm->psTdmaPara[2], pCoexDm->psTdmaPara[3],
2499 pCoexDm->psTdmaPara[4], psTdmaCase, pCoexDm->bAutoTdmaAdjust);
2502 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "Coex Table Type",
2503 pCoexSta->nCoexTableType);
2506 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "IgnWlanAct",
2507 pCoexDm->bCurIgnoreWlanAct);
2512 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Hw setting]============");
2515 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", "backup ARFR1/ARFR2/RL/AMaxTime",
2516 pCoexDm->backupArfrCnt1, pCoexDm->backupArfrCnt2, pCoexDm->backupRetryLimit, pCoexDm->backupAmpduMaxTime);
2519 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x430);
2520 u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x434);
2521 u2Tmp[0] = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x42a);
2522 u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x456);
2523 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", "0x430/0x434/0x42a/0x456",
2524 u4Tmp[0], u4Tmp[1], u2Tmp[0], u1Tmp[0]);
2527 u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x778);
2528 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6cc);
2529 u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x880);
2531 cliBuf, BT_TMP_BUF_SIZE,
2532 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x778/0x6cc/0x880[29:25]",
2533 u1Tmp[0], u4Tmp[0], (u4Tmp[1] & 0x3e000000) >> 25
2537 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x948);
2538 u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x67);
2539 u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x764);
2540 u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x76e);
2544 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0x948/ 0x67[5] / 0x764 / 0x76e",
2545 u4Tmp[0], ((u1Tmp[0] & 0x20) >> 5), (u4Tmp[1] & 0xffff), u1Tmp[1]
2549 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x92c);
2550 u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x930);
2551 u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x944);
2555 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x92c[1:0]/ 0x930[7:0]/0x944[1:0]",
2556 u4Tmp[0] & 0x3, u4Tmp[1] & 0xff, u4Tmp[2] & 0x3
2560 u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x39);
2561 u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x40);
2562 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);
2563 u1Tmp[2] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x64);
2567 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0x38[11]/0x40/0x4c[24:23]/0x64[0]",
2568 ((u1Tmp[0] & 0x8) >> 3),
2570 ((u4Tmp[0] & 0x01800000) >> 23),
2575 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x550);
2576 u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x522);
2580 "\r\n %-35s = 0x%x/ 0x%x", "0x550(bcn ctrl)/0x522",
2585 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xc50);
2586 u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x49c);
2590 "\r\n %-35s = 0x%x/ 0x%x", "0xc50(dig)/0x49c(null-drop)",
2591 u4Tmp[0] & 0xff, u1Tmp[0]
2595 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda0);
2596 u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda4);
2597 u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda8);
2598 u4Tmp[3] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xcf0);
2600 u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xa5b);
2601 u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xa5c);
2604 ((u4Tmp[0] & 0xffff0000) >> 16) +
2605 ((u4Tmp[1] & 0xffff0000) >> 16) +
2606 (u4Tmp[1] & 0xffff) + (u4Tmp[2] & 0xffff) +
2607 ((u4Tmp[3] & 0xffff0000) >> 16) + (u4Tmp[3] & 0xffff);
2608 faCck = (u1Tmp[0] << 8) + u1Tmp[1];
2613 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "OFDM-CCA/OFDM-FA/CCK-FA",
2614 u4Tmp[0] & 0xffff, faOfdm, faCck
2622 "\r\n %-35s = %d/ %d/ %d/ %d", "CRC_OK CCK/11g/11n/11n-Agg",
2623 pCoexSta->nCRCOK_CCK,
2624 pCoexSta->nCRCOK_11g,
2625 pCoexSta->nCRCOK_11n,
2626 pCoexSta->nCRCOK_11nAgg
2633 "\r\n %-35s = %d/ %d/ %d/ %d", "CRC_Err CCK/11g/11n/11n-Agg",
2634 pCoexSta->nCRCErr_CCK,
2635 pCoexSta->nCRCErr_11g,
2636 pCoexSta->nCRCErr_11n,
2637 pCoexSta->nCRCErr_11nAgg
2641 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c0);
2642 u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c4);
2643 u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c8);
2647 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x6c0/0x6c4/0x6c8(coexTable)",
2648 u4Tmp[0], u4Tmp[1], u4Tmp[2]);
2654 "\r\n %-35s = %d/ %d", "0x770(high-pri rx/tx)",
2655 pCoexSta->highPriorityRx, pCoexSta->highPriorityTx
2661 "\r\n %-35s = %d/ %d", "0x774(low-pri rx/tx)",
2662 pCoexSta->lowPriorityRx, pCoexSta->lowPriorityTx
2666 pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_COEX_STATISTICS);
2670 void EXhalbtc8723b1ant_IpsNotify(struct btc_coexist *pBtCoexist, u8 type)
2672 if (pBtCoexist->bManualControl || pBtCoexist->bStopCoexDm)
2675 if (type == BTC_IPS_ENTER) {
2676 pCoexSta->bUnderIps = true;
2678 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 0);
2679 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
2680 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, false, true);
2681 } else if (type == BTC_IPS_LEAVE) {
2682 pCoexSta->bUnderIps = false;
2684 halbtc8723b1ant_InitHwConfig(pBtCoexist, false, false);
2685 halbtc8723b1ant_InitCoexDm(pBtCoexist);
2686 halbtc8723b1ant_QueryBtInfo(pBtCoexist);
2690 void EXhalbtc8723b1ant_LpsNotify(struct btc_coexist *pBtCoexist, u8 type)
2692 if (pBtCoexist->bManualControl || pBtCoexist->bStopCoexDm)
2695 if (type == BTC_LPS_ENABLE)
2696 pCoexSta->bUnderLps = true;
2697 else if (type == BTC_LPS_DISABLE)
2698 pCoexSta->bUnderLps = false;
2701 void EXhalbtc8723b1ant_ScanNotify(struct btc_coexist *pBtCoexist, u8 type)
2703 bool bWifiConnected = false, bBtHsOn = false;
2704 u32 wifiLinkStatus = 0;
2705 u32 numOfWifiLink = 0;
2706 bool bBtCtrlAggBufSize = false;
2712 if (pBtCoexist->bManualControl || pBtCoexist->bStopCoexDm)
2715 if (type == BTC_SCAN_START) {
2716 pCoexSta->bWiFiIsHighPriTask = true;
2718 halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, false, 8); /* Force antenna setup for no scan result issue */
2719 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x948);
2720 u1Tmpa = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x765);
2721 u1Tmpb = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x67);
2723 pCoexSta->bWiFiIsHighPriTask = false;
2725 pBtCoexist->fBtcGet(
2726 pBtCoexist, BTC_GET_U1_AP_NUM, &pCoexSta->nScanAPNum
2730 if (pBtCoexist->btInfo.bBtDisabled)
2733 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
2734 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
2736 halbtc8723b1ant_QueryBtInfo(pBtCoexist);
2738 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);
2739 numOfWifiLink = wifiLinkStatus >> 16;
2741 if (numOfWifiLink >= 2) {
2742 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);
2743 halbtc8723b1ant_LimitedRx(
2744 pBtCoexist, NORMAL_EXEC, false, bBtCtrlAggBufSize, aggBufSize
2746 halbtc8723b1ant_ActionWifiMultiPort(pBtCoexist);
2750 if (pCoexSta->bC2hBtInquiryPage) {
2751 halbtc8723b1ant_ActionBtInquiry(pBtCoexist);
2753 } else if (bBtHsOn) {
2754 halbtc8723b1ant_ActionHs(pBtCoexist);
2758 if (type == BTC_SCAN_START) {
2759 if (!bWifiConnected) /* non-connected scan */
2760 halbtc8723b1ant_ActionWifiNotConnectedScan(pBtCoexist);
2761 else /* wifi is connected */
2762 halbtc8723b1ant_ActionWifiConnectedScan(pBtCoexist);
2763 } else if (type == BTC_SCAN_FINISH) {
2764 if (!bWifiConnected) /* non-connected scan */
2765 halbtc8723b1ant_ActionWifiNotConnected(pBtCoexist);
2767 halbtc8723b1ant_ActionWifiConnected(pBtCoexist);
2771 void EXhalbtc8723b1ant_ConnectNotify(struct btc_coexist *pBtCoexist, u8 type)
2773 bool bWifiConnected = false, bBtHsOn = false;
2774 u32 wifiLinkStatus = 0;
2775 u32 numOfWifiLink = 0;
2776 bool bBtCtrlAggBufSize = false;
2780 pBtCoexist->bManualControl ||
2781 pBtCoexist->bStopCoexDm ||
2782 pBtCoexist->btInfo.bBtDisabled
2786 if (type == BTC_ASSOCIATE_START) {
2787 pCoexSta->bWiFiIsHighPriTask = true;
2788 pCoexDm->nArpCnt = 0;
2790 pCoexSta->bWiFiIsHighPriTask = false;
2791 /* pCoexDm->nArpCnt = 0; */
2794 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);
2795 numOfWifiLink = wifiLinkStatus >> 16;
2796 if (numOfWifiLink >= 2) {
2797 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);
2798 halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, bBtCtrlAggBufSize, aggBufSize);
2799 halbtc8723b1ant_ActionWifiMultiPort(pBtCoexist);
2803 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
2804 if (pCoexSta->bC2hBtInquiryPage) {
2805 halbtc8723b1ant_ActionBtInquiry(pBtCoexist);
2807 } else if (bBtHsOn) {
2808 halbtc8723b1ant_ActionHs(pBtCoexist);
2812 if (type == BTC_ASSOCIATE_START) {
2813 halbtc8723b1ant_ActionWifiNotConnectedAssoAuth(pBtCoexist);
2814 } else if (type == BTC_ASSOCIATE_FINISH) {
2815 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
2816 if (!bWifiConnected) /* non-connected scan */
2817 halbtc8723b1ant_ActionWifiNotConnected(pBtCoexist);
2819 halbtc8723b1ant_ActionWifiConnected(pBtCoexist);
2823 void EXhalbtc8723b1ant_MediaStatusNotify(struct btc_coexist *pBtCoexist, u8 type)
2825 u8 H2C_Parameter[3] = {0};
2828 bool bWifiUnderBMode = false;
2831 pBtCoexist->bManualControl ||
2832 pBtCoexist->bStopCoexDm ||
2833 pBtCoexist->btInfo.bBtDisabled
2837 if (type == BTC_MEDIA_CONNECT) {
2838 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode);
2840 /* Set CCK Tx/Rx high Pri except 11b mode */
2841 if (bWifiUnderBMode) {
2842 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cd, 0x00); /* CCK Tx */
2843 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cf, 0x00); /* CCK Rx */
2845 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cd, 0x10); /* CCK Tx */
2846 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cf, 0x10); /* CCK Rx */
2849 pCoexDm->backupArfrCnt1 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x430);
2850 pCoexDm->backupArfrCnt2 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x434);
2851 pCoexDm->backupRetryLimit = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x42a);
2852 pCoexDm->backupAmpduMaxTime = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x456);
2854 pCoexDm->nArpCnt = 0;
2856 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cd, 0x0); /* CCK Tx */
2857 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cf, 0x0); /* CCK Rx */
2860 /* only 2.4G we need to inform bt the chnl mask */
2861 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, &wifiCentralChnl);
2862 if ((type == BTC_MEDIA_CONNECT) && (wifiCentralChnl <= 14)) {
2863 /* H2C_Parameter[0] = 0x1; */
2864 H2C_Parameter[0] = 0x0;
2865 H2C_Parameter[1] = wifiCentralChnl;
2866 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
2868 if (wifiBw == BTC_WIFI_BW_HT40)
2869 H2C_Parameter[2] = 0x30;
2871 H2C_Parameter[2] = 0x20;
2874 pCoexDm->wifiChnlInfo[0] = H2C_Parameter[0];
2875 pCoexDm->wifiChnlInfo[1] = H2C_Parameter[1];
2876 pCoexDm->wifiChnlInfo[2] = H2C_Parameter[2];
2878 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x66, 3, H2C_Parameter);
2881 void EXhalbtc8723b1ant_SpecialPacketNotify(struct btc_coexist *pBtCoexist, u8 type)
2883 bool bBtHsOn = false;
2884 u32 wifiLinkStatus = 0;
2885 u32 numOfWifiLink = 0;
2886 bool bBtCtrlAggBufSize = false;
2890 pBtCoexist->bManualControl ||
2891 pBtCoexist->bStopCoexDm ||
2892 pBtCoexist->btInfo.bBtDisabled
2897 type == BTC_PACKET_DHCP ||
2898 type == BTC_PACKET_EAPOL ||
2899 type == BTC_PACKET_ARP
2901 if (type == BTC_PACKET_ARP) {
2904 if (pCoexDm->nArpCnt >= 10) /* if APR PKT > 10 after connect, do not go to ActionWifiConnectedSpecialPacket(pBtCoexist) */
2905 pCoexSta->bWiFiIsHighPriTask = false;
2907 pCoexSta->bWiFiIsHighPriTask = true;
2909 pCoexSta->bWiFiIsHighPriTask = true;
2912 pCoexSta->bWiFiIsHighPriTask = false;
2915 pCoexSta->specialPktPeriodCnt = 0;
2917 pBtCoexist->fBtcGet(
2918 pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus
2920 numOfWifiLink = wifiLinkStatus >> 16;
2922 if (numOfWifiLink >= 2) {
2923 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);
2924 halbtc8723b1ant_LimitedRx(
2925 pBtCoexist, NORMAL_EXEC, false, bBtCtrlAggBufSize, aggBufSize
2927 halbtc8723b1ant_ActionWifiMultiPort(pBtCoexist);
2931 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
2932 if (pCoexSta->bC2hBtInquiryPage) {
2933 halbtc8723b1ant_ActionBtInquiry(pBtCoexist);
2935 } else if (bBtHsOn) {
2936 halbtc8723b1ant_ActionHs(pBtCoexist);
2941 type == BTC_PACKET_DHCP ||
2942 type == BTC_PACKET_EAPOL ||
2943 ((type == BTC_PACKET_ARP) && (pCoexSta->bWiFiIsHighPriTask))
2945 halbtc8723b1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);
2948 void EXhalbtc8723b1ant_BtInfoNotify(
2949 struct btc_coexist *pBtCoexist, u8 *tmpBuf, u8 length
2953 u8 i, rspSource = 0;
2954 bool bWifiConnected = false;
2955 bool bBtBusy = false;
2957 pCoexSta->bC2hBtInfoReqSent = false;
2959 rspSource = tmpBuf[0] & 0xf;
2960 if (rspSource >= BT_INFO_SRC_8723B_1ANT_MAX)
2961 rspSource = BT_INFO_SRC_8723B_1ANT_WIFI_FW;
2962 pCoexSta->btInfoC2hCnt[rspSource]++;
2964 for (i = 0; i < length; i++) {
2965 pCoexSta->btInfoC2h[rspSource][i] = tmpBuf[i];
2970 if (rspSource != BT_INFO_SRC_8723B_1ANT_WIFI_FW) {
2971 pCoexSta->btRetryCnt = pCoexSta->btInfoC2h[rspSource][2] & 0xf;
2973 if (pCoexSta->btRetryCnt >= 1)
2974 pCoexSta->popEventCnt++;
2976 if (pCoexSta->btInfoC2h[rspSource][2] & 0x20)
2977 pCoexSta->bC2hBtPage = true;
2979 pCoexSta->bC2hBtPage = false;
2981 pCoexSta->btRssi = pCoexSta->btInfoC2h[rspSource][3] * 2 - 90;
2982 /* pCoexSta->btInfoC2h[rspSource][3]*2+10; */
2984 pCoexSta->btInfoExt = pCoexSta->btInfoC2h[rspSource][4];
2986 pCoexSta->bBtTxRxMask = (pCoexSta->btInfoC2h[rspSource][2] & 0x40);
2987 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TX_RX_MASK, &pCoexSta->bBtTxRxMask);
2989 if (!pCoexSta->bBtTxRxMask) {
2990 /* BT into is responded by BT FW and BT RF REG 0x3C != 0x15 => Need to switch BT TRx Mask */
2991 pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x3c, 0x15);
2994 /* Here we need to resend some wifi info to BT */
2995 /* because bt is reset and loss of the info. */
2996 if (pCoexSta->btInfoExt & BIT1) {
2997 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
2999 EXhalbtc8723b1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_CONNECT);
3001 EXhalbtc8723b1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);
3004 if (pCoexSta->btInfoExt & BIT3) {
3005 if (!pBtCoexist->bManualControl && !pBtCoexist->bStopCoexDm)
3006 halbtc8723b1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, false);
3008 /* BT already NOT ignore Wlan active, do nothing here. */
3012 /* check BIT2 first ==> check if bt is under inquiry or page scan */
3013 if (btInfo & BT_INFO_8723B_1ANT_B_INQ_PAGE)
3014 pCoexSta->bC2hBtInquiryPage = true;
3016 pCoexSta->bC2hBtInquiryPage = false;
3018 /* set link exist status */
3019 if (!(btInfo & BT_INFO_8723B_1ANT_B_CONNECTION)) {
3020 pCoexSta->bBtLinkExist = false;
3021 pCoexSta->bPanExist = false;
3022 pCoexSta->bA2dpExist = false;
3023 pCoexSta->bHidExist = false;
3024 pCoexSta->bScoExist = false;
3025 } else { /* connection exists */
3026 pCoexSta->bBtLinkExist = true;
3027 if (btInfo & BT_INFO_8723B_1ANT_B_FTP)
3028 pCoexSta->bPanExist = true;
3030 pCoexSta->bPanExist = false;
3032 if (btInfo & BT_INFO_8723B_1ANT_B_A2DP)
3033 pCoexSta->bA2dpExist = true;
3035 pCoexSta->bA2dpExist = false;
3037 if (btInfo & BT_INFO_8723B_1ANT_B_HID)
3038 pCoexSta->bHidExist = true;
3040 pCoexSta->bHidExist = false;
3042 if (btInfo & BT_INFO_8723B_1ANT_B_SCO_ESCO)
3043 pCoexSta->bScoExist = true;
3045 pCoexSta->bScoExist = false;
3048 halbtc8723b1ant_UpdateBtLinkInfo(pBtCoexist);
3050 btInfo = btInfo & 0x1f; /* mask profile bit for connect-ilde identification (for CSR case: A2DP idle --> 0x41) */
3052 if (!(btInfo & BT_INFO_8723B_1ANT_B_CONNECTION)) {
3053 pCoexDm->btStatus = BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE;
3054 } else if (btInfo == BT_INFO_8723B_1ANT_B_CONNECTION) {
3055 /* connection exists but no busy */
3056 pCoexDm->btStatus = BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE;
3058 (btInfo & BT_INFO_8723B_1ANT_B_SCO_ESCO) ||
3059 (btInfo & BT_INFO_8723B_1ANT_B_SCO_BUSY)
3061 pCoexDm->btStatus = BT_8723B_1ANT_BT_STATUS_SCO_BUSY;
3062 } else if (btInfo & BT_INFO_8723B_1ANT_B_ACL_BUSY) {
3063 if (pCoexDm->btStatus != BT_8723B_1ANT_BT_STATUS_ACL_BUSY)
3064 pCoexDm->bAutoTdmaAdjust = false;
3066 pCoexDm->btStatus = BT_8723B_1ANT_BT_STATUS_ACL_BUSY;
3068 pCoexDm->btStatus = BT_8723B_1ANT_BT_STATUS_MAX;
3072 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_BUSY) ||
3073 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_SCO_BUSY) ||
3074 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY)
3079 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);
3081 halbtc8723b1ant_RunCoexistMechanism(pBtCoexist);
3084 void EXhalbtc8723b1ant_HaltNotify(struct btc_coexist *pBtCoexist)
3086 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3087 halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, false, 0);
3088 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, false, true);
3090 halbtc8723b1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, true);
3092 EXhalbtc8723b1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);
3094 pBtCoexist->bStopCoexDm = true;
3097 void EXhalbtc8723b1ant_PnpNotify(struct btc_coexist *pBtCoexist, u8 pnpState)
3099 if (pnpState == BTC_WIFI_PNP_SLEEP) {
3100 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
3101 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 0);
3102 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
3103 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, false, true);
3105 pBtCoexist->bStopCoexDm = true;
3106 } else if (pnpState == BTC_WIFI_PNP_WAKE_UP) {
3107 pBtCoexist->bStopCoexDm = false;
3108 halbtc8723b1ant_InitHwConfig(pBtCoexist, false, false);
3109 halbtc8723b1ant_InitCoexDm(pBtCoexist);
3110 halbtc8723b1ant_QueryBtInfo(pBtCoexist);
3114 void EXhalbtc8723b1ant_Periodical(struct btc_coexist *pBtCoexist)
3116 static u8 disVerInfoCnt;
3117 u32 fwVer = 0, btPatchVer = 0;
3119 if (disVerInfoCnt <= 5) {
3121 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);
3122 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);
3125 halbtc8723b1ant_MonitorBtCtr(pBtCoexist);
3126 halbtc8723b1ant_MonitorWiFiCtr(pBtCoexist);
3129 halbtc8723b1ant_IsWifiStatusChanged(pBtCoexist) ||
3130 pCoexDm->bAutoTdmaAdjust
3132 halbtc8723b1ant_RunCoexistMechanism(pBtCoexist);
3134 pCoexSta->specialPktPeriodCnt++;