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 /* local function proto type if needed */
17 /* local function start with halbtc8723b1ant_ */
18 static u8 halbtc8723b1ant_BtRssiState(
19 u8 levelNum, u8 rssiThresh, u8 rssiThresh1
23 u8 btRssiState = pCoexSta->preBtRssiState;
25 btRssi = pCoexSta->btRssi;
29 (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||
30 (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW)
32 if (btRssi >= (rssiThresh + BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT))
34 btRssiState = BTC_RSSI_STATE_HIGH;
36 btRssiState = BTC_RSSI_STATE_STAY_LOW;
38 if (btRssi < rssiThresh)
39 btRssiState = BTC_RSSI_STATE_LOW;
41 btRssiState = BTC_RSSI_STATE_STAY_HIGH;
43 } else if (levelNum == 3) {
44 if (rssiThresh > rssiThresh1)
45 return pCoexSta->preBtRssiState;
48 (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||
49 (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW)
51 if (btRssi >= (rssiThresh + BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT))
52 btRssiState = BTC_RSSI_STATE_MEDIUM;
54 btRssiState = BTC_RSSI_STATE_STAY_LOW;
56 (pCoexSta->preBtRssiState == BTC_RSSI_STATE_MEDIUM) ||
57 (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_MEDIUM)
59 if (btRssi >= (rssiThresh1 + BTC_RSSI_COEX_THRESH_TOL_8723B_1ANT))
60 btRssiState = BTC_RSSI_STATE_HIGH;
61 else if (btRssi < rssiThresh)
62 btRssiState = BTC_RSSI_STATE_LOW;
64 btRssiState = BTC_RSSI_STATE_STAY_MEDIUM;
66 if (btRssi < rssiThresh1)
67 btRssiState = BTC_RSSI_STATE_MEDIUM;
69 btRssiState = BTC_RSSI_STATE_STAY_HIGH;
73 pCoexSta->preBtRssiState = btRssiState;
78 static void halbtc8723b1ant_UpdateRaMask(
79 struct btc_coexist *pBtCoexist, bool bForceExec, u32 disRateMask
82 pCoexDm->curRaMask = disRateMask;
84 if (bForceExec || (pCoexDm->preRaMask != pCoexDm->curRaMask))
87 BTC_SET_ACT_UPDATE_RAMASK,
90 pCoexDm->preRaMask = pCoexDm->curRaMask;
93 static void halbtc8723b1ant_AutoRateFallbackRetry(
94 struct btc_coexist *pBtCoexist, bool bForceExec, u8 type
97 bool bWifiUnderBMode = false;
99 pCoexDm->curArfrType = type;
101 if (bForceExec || (pCoexDm->preArfrType != pCoexDm->curArfrType)) {
102 switch (pCoexDm->curArfrType) {
103 case 0: /* normal mode */
104 pBtCoexist->fBtcWrite4Byte(
105 pBtCoexist, 0x430, pCoexDm->backupArfrCnt1
107 pBtCoexist->fBtcWrite4Byte(
108 pBtCoexist, 0x434, pCoexDm->backupArfrCnt2
113 pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode
115 if (bWifiUnderBMode) {
116 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x430, 0x0);
117 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x434, 0x01010101);
119 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x430, 0x0);
120 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x434, 0x04030201);
128 pCoexDm->preArfrType = pCoexDm->curArfrType;
131 static void halbtc8723b1ant_RetryLimit(
132 struct btc_coexist *pBtCoexist, bool bForceExec, u8 type
135 pCoexDm->curRetryLimitType = type;
139 (pCoexDm->preRetryLimitType != pCoexDm->curRetryLimitType)
141 switch (pCoexDm->curRetryLimitType) {
142 case 0: /* normal mode */
143 pBtCoexist->fBtcWrite2Byte(
144 pBtCoexist, 0x42a, pCoexDm->backupRetryLimit
147 case 1: /* retry limit =8 */
148 pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x42a, 0x0808);
155 pCoexDm->preRetryLimitType = pCoexDm->curRetryLimitType;
158 static void halbtc8723b1ant_AmpduMaxTime(
159 struct btc_coexist *pBtCoexist, bool bForceExec, u8 type
162 pCoexDm->curAmpduTimeType = type;
165 bForceExec || (pCoexDm->preAmpduTimeType != pCoexDm->curAmpduTimeType)
167 switch (pCoexDm->curAmpduTimeType) {
168 case 0: /* normal mode */
169 pBtCoexist->fBtcWrite1Byte(
170 pBtCoexist, 0x456, pCoexDm->backupAmpduMaxTime
173 case 1: /* AMPDU timw = 0x38 * 32us */
174 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x456, 0x38);
181 pCoexDm->preAmpduTimeType = pCoexDm->curAmpduTimeType;
184 static void halbtc8723b1ant_LimitedTx(
185 struct btc_coexist *pBtCoexist,
193 switch (raMaskType) {
194 case 0: /* normal mode */
195 halbtc8723b1ant_UpdateRaMask(pBtCoexist, bForceExec, 0x0);
197 case 1: /* disable cck 1/2 */
198 halbtc8723b1ant_UpdateRaMask(pBtCoexist, bForceExec, 0x00000003);
200 case 2: /* disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4 */
201 halbtc8723b1ant_UpdateRaMask(pBtCoexist, bForceExec, 0x0001f1f7);
207 halbtc8723b1ant_AutoRateFallbackRetry(pBtCoexist, bForceExec, arfrType);
208 halbtc8723b1ant_RetryLimit(pBtCoexist, bForceExec, retryLimitType);
209 halbtc8723b1ant_AmpduMaxTime(pBtCoexist, bForceExec, ampduTimeType);
212 static void halbtc8723b1ant_LimitedRx(
213 struct btc_coexist *pBtCoexist,
216 bool bBtCtrlAggBufSize,
220 bool bRejectRxAgg = bRejApAggPkt;
221 bool bBtCtrlRxAggSize = bBtCtrlAggBufSize;
222 u8 rxAggSize = aggBufSize;
225 /* Rx Aggregation related setting */
228 pBtCoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, &bRejectRxAgg
230 /* decide BT control aggregation buf size or not */
232 pBtCoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, &bBtCtrlRxAggSize
234 /* aggregation buf size, only work when BT control Rx aggregation size. */
235 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_AGG_BUF_SIZE, &rxAggSize);
236 /* real update aggregation setting */
237 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
242 static void halbtc8723b1ant_QueryBtInfo(struct btc_coexist *pBtCoexist)
244 u8 H2C_Parameter[1] = {0};
246 pCoexSta->bC2hBtInfoReqSent = true;
248 H2C_Parameter[0] |= BIT0; /* trigger */
250 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x61, 1, H2C_Parameter);
253 static void halbtc8723b1ant_MonitorBtCtr(struct btc_coexist *pBtCoexist)
255 u32 regHPTxRx, regLPTxRx, u4Tmp;
256 u32 regHPTx = 0, regHPRx = 0, regLPTx = 0, regLPRx = 0;
257 static u8 NumOfBtCounterChk;
259 /* to avoid 0x76e[3] = 1 (WLAN_Act control by PTA) during IPS */
260 /* if (! (pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x76e) & 0x8)) */
262 if (pCoexSta->bUnderIps) {
263 pCoexSta->highPriorityTx = 65535;
264 pCoexSta->highPriorityRx = 65535;
265 pCoexSta->lowPriorityTx = 65535;
266 pCoexSta->lowPriorityRx = 65535;
273 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regHPTxRx);
274 regHPTx = u4Tmp & bMaskLWord;
275 regHPRx = (u4Tmp & bMaskHWord) >> 16;
277 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regLPTxRx);
278 regLPTx = u4Tmp & bMaskLWord;
279 regLPRx = (u4Tmp & bMaskHWord) >> 16;
281 pCoexSta->highPriorityTx = regHPTx;
282 pCoexSta->highPriorityRx = regHPRx;
283 pCoexSta->lowPriorityTx = regLPTx;
284 pCoexSta->lowPriorityRx = regLPRx;
286 if ((pCoexSta->lowPriorityTx >= 1050) && (!pCoexSta->bC2hBtInquiryPage))
287 pCoexSta->popEventCnt++;
290 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc);
292 if ((regHPTx == 0) && (regHPRx == 0) && (regLPTx == 0) && (regLPRx == 0)) {
294 if (NumOfBtCounterChk >= 3) {
295 halbtc8723b1ant_QueryBtInfo(pBtCoexist);
296 NumOfBtCounterChk = 0;
302 static void halbtc8723b1ant_MonitorWiFiCtr(struct btc_coexist *pBtCoexist)
305 bool bWifiBusy = false, bWifiUnderBMode = false;
306 static u8 nCCKLockCounter;
308 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
309 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);
311 pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode
314 if (pCoexSta->bUnderIps) {
315 pCoexSta->nCRCOK_CCK = 0;
316 pCoexSta->nCRCOK_11g = 0;
317 pCoexSta->nCRCOK_11n = 0;
318 pCoexSta->nCRCOK_11nAgg = 0;
320 pCoexSta->nCRCErr_CCK = 0;
321 pCoexSta->nCRCErr_11g = 0;
322 pCoexSta->nCRCErr_11n = 0;
323 pCoexSta->nCRCErr_11nAgg = 0;
325 pCoexSta->nCRCOK_CCK = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xf88);
326 pCoexSta->nCRCOK_11g = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf94);
327 pCoexSta->nCRCOK_11n = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf90);
328 pCoexSta->nCRCOK_11nAgg = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xfb8);
330 pCoexSta->nCRCErr_CCK = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xf84);
331 pCoexSta->nCRCErr_11g = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf96);
332 pCoexSta->nCRCErr_11n = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xf92);
333 pCoexSta->nCRCErr_11nAgg = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0xfba);
338 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xf16, 0x1, 0x1);
339 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xf16, 0x1, 0x0);
341 if (bWifiBusy && (wifiRssi >= 30) && !bWifiUnderBMode) {
343 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_BUSY) ||
344 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY) ||
345 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_SCO_BUSY)
348 pCoexSta->nCRCOK_CCK > (
349 pCoexSta->nCRCOK_11g +
350 pCoexSta->nCRCOK_11n +
351 pCoexSta->nCRCOK_11nAgg
354 if (nCCKLockCounter < 5)
357 if (nCCKLockCounter > 0)
362 if (nCCKLockCounter > 0)
366 if (nCCKLockCounter > 0)
370 if (!pCoexSta->bPreCCKLock) {
372 if (nCCKLockCounter >= 5)
373 pCoexSta->bCCKLock = true;
375 pCoexSta->bCCKLock = false;
377 if (nCCKLockCounter == 0)
378 pCoexSta->bCCKLock = false;
380 pCoexSta->bCCKLock = true;
383 pCoexSta->bPreCCKLock = pCoexSta->bCCKLock;
388 static bool halbtc8723b1ant_IsWifiStatusChanged(struct btc_coexist *pBtCoexist)
390 static bool bPreWifiBusy, bPreUnder4way, bPreBtHsOn;
391 bool bWifiBusy = false, bUnder4way = false, bBtHsOn = false;
392 bool bWifiConnected = false;
395 pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected
397 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
398 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
400 pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way
403 if (bWifiConnected) {
404 if (bWifiBusy != bPreWifiBusy) {
405 bPreWifiBusy = bWifiBusy;
409 if (bUnder4way != bPreUnder4way) {
410 bPreUnder4way = bUnder4way;
414 if (bBtHsOn != bPreBtHsOn) {
415 bPreBtHsOn = bBtHsOn;
423 static void halbtc8723b1ant_UpdateBtLinkInfo(struct btc_coexist *pBtCoexist)
425 struct btc_bt_link_info *pBtLinkInfo = &pBtCoexist->btLinkInfo;
426 bool bBtHsOn = false;
428 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
430 pBtLinkInfo->bBtLinkExist = pCoexSta->bBtLinkExist;
431 pBtLinkInfo->bScoExist = pCoexSta->bScoExist;
432 pBtLinkInfo->bA2dpExist = pCoexSta->bA2dpExist;
433 pBtLinkInfo->bPanExist = pCoexSta->bPanExist;
434 pBtLinkInfo->bHidExist = pCoexSta->bHidExist;
436 /* work around for HS mode. */
438 pBtLinkInfo->bPanExist = true;
439 pBtLinkInfo->bBtLinkExist = true;
442 /* check if Sco only */
444 pBtLinkInfo->bScoExist &&
445 !pBtLinkInfo->bA2dpExist &&
446 !pBtLinkInfo->bPanExist &&
447 !pBtLinkInfo->bHidExist
449 pBtLinkInfo->bScoOnly = true;
451 pBtLinkInfo->bScoOnly = false;
453 /* check if A2dp only */
455 !pBtLinkInfo->bScoExist &&
456 pBtLinkInfo->bA2dpExist &&
457 !pBtLinkInfo->bPanExist &&
458 !pBtLinkInfo->bHidExist
460 pBtLinkInfo->bA2dpOnly = true;
462 pBtLinkInfo->bA2dpOnly = false;
464 /* check if Pan only */
466 !pBtLinkInfo->bScoExist &&
467 !pBtLinkInfo->bA2dpExist &&
468 pBtLinkInfo->bPanExist &&
469 !pBtLinkInfo->bHidExist
471 pBtLinkInfo->bPanOnly = true;
473 pBtLinkInfo->bPanOnly = false;
475 /* check if Hid only */
477 !pBtLinkInfo->bScoExist &&
478 !pBtLinkInfo->bA2dpExist &&
479 !pBtLinkInfo->bPanExist &&
480 pBtLinkInfo->bHidExist
482 pBtLinkInfo->bHidOnly = true;
484 pBtLinkInfo->bHidOnly = false;
487 static u8 halbtc8723b1ant_ActionAlgorithm(struct btc_coexist *pBtCoexist)
489 struct btc_bt_link_info *pBtLinkInfo = &pBtCoexist->btLinkInfo;
490 bool bBtHsOn = false;
491 u8 algorithm = BT_8723B_1ANT_COEX_ALGO_UNDEFINED;
492 u8 numOfDiffProfile = 0;
494 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
496 if (!pBtLinkInfo->bBtLinkExist)
499 if (pBtLinkInfo->bScoExist)
501 if (pBtLinkInfo->bHidExist)
503 if (pBtLinkInfo->bPanExist)
505 if (pBtLinkInfo->bA2dpExist)
508 if (numOfDiffProfile == 1) {
509 if (pBtLinkInfo->bScoExist) {
510 algorithm = BT_8723B_1ANT_COEX_ALGO_SCO;
512 if (pBtLinkInfo->bHidExist) {
513 algorithm = BT_8723B_1ANT_COEX_ALGO_HID;
514 } else if (pBtLinkInfo->bA2dpExist) {
515 algorithm = BT_8723B_1ANT_COEX_ALGO_A2DP;
516 } else if (pBtLinkInfo->bPanExist) {
518 algorithm = BT_8723B_1ANT_COEX_ALGO_PANHS;
520 algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR;
523 } else if (numOfDiffProfile == 2) {
524 if (pBtLinkInfo->bScoExist) {
525 if (pBtLinkInfo->bHidExist) {
526 algorithm = BT_8723B_1ANT_COEX_ALGO_HID;
527 } else if (pBtLinkInfo->bA2dpExist) {
528 algorithm = BT_8723B_1ANT_COEX_ALGO_SCO;
529 } else if (pBtLinkInfo->bPanExist) {
531 algorithm = BT_8723B_1ANT_COEX_ALGO_SCO;
533 algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_HID;
536 if (pBtLinkInfo->bHidExist && pBtLinkInfo->bA2dpExist) {
537 algorithm = BT_8723B_1ANT_COEX_ALGO_HID_A2DP;
538 } else if (pBtLinkInfo->bHidExist && pBtLinkInfo->bPanExist) {
540 algorithm = BT_8723B_1ANT_COEX_ALGO_HID_A2DP;
542 algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_HID;
543 } else if (pBtLinkInfo->bPanExist && pBtLinkInfo->bA2dpExist) {
545 algorithm = BT_8723B_1ANT_COEX_ALGO_A2DP_PANHS;
547 algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_A2DP;
550 } else if (numOfDiffProfile == 3) {
551 if (pBtLinkInfo->bScoExist) {
552 if (pBtLinkInfo->bHidExist && pBtLinkInfo->bA2dpExist) {
553 algorithm = BT_8723B_1ANT_COEX_ALGO_HID;
555 pBtLinkInfo->bHidExist && pBtLinkInfo->bPanExist
558 algorithm = BT_8723B_1ANT_COEX_ALGO_HID_A2DP;
560 algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_HID;
561 } else if (pBtLinkInfo->bPanExist && pBtLinkInfo->bA2dpExist) {
563 algorithm = BT_8723B_1ANT_COEX_ALGO_SCO;
565 algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_HID;
569 pBtLinkInfo->bHidExist &&
570 pBtLinkInfo->bPanExist &&
571 pBtLinkInfo->bA2dpExist
574 algorithm = BT_8723B_1ANT_COEX_ALGO_HID_A2DP;
576 algorithm = BT_8723B_1ANT_COEX_ALGO_HID_A2DP_PANEDR;
579 } else if (numOfDiffProfile >= 3) {
580 if (pBtLinkInfo->bScoExist) {
582 pBtLinkInfo->bHidExist &&
583 pBtLinkInfo->bPanExist &&
584 pBtLinkInfo->bA2dpExist
587 algorithm = BT_8723B_1ANT_COEX_ALGO_PANEDR_HID;
596 static void halbtc8723b1ant_SetSwPenaltyTxRateAdaptive(
597 struct btc_coexist *pBtCoexist, bool bLowPenaltyRa
600 u8 H2C_Parameter[6] = {0};
602 H2C_Parameter[0] = 0x6; /* opCode, 0x6 = Retry_Penalty */
605 H2C_Parameter[1] |= BIT0;
606 H2C_Parameter[2] = 0x00; /* normal rate except MCS7/6/5, OFDM54/48/36 */
607 H2C_Parameter[3] = 0xf7; /* MCS7 or OFDM54 */
608 H2C_Parameter[4] = 0xf8; /* MCS6 or OFDM48 */
609 H2C_Parameter[5] = 0xf9; /* MCS5 or OFDM36 */
612 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x69, 6, H2C_Parameter);
615 static void halbtc8723b1ant_LowPenaltyRa(
616 struct btc_coexist *pBtCoexist, bool bForceExec, bool bLowPenaltyRa
619 pCoexDm->bCurLowPenaltyRa = bLowPenaltyRa;
622 if (pCoexDm->bPreLowPenaltyRa == pCoexDm->bCurLowPenaltyRa)
625 halbtc8723b1ant_SetSwPenaltyTxRateAdaptive(
626 pBtCoexist, pCoexDm->bCurLowPenaltyRa
629 pCoexDm->bPreLowPenaltyRa = pCoexDm->bCurLowPenaltyRa;
632 static void halbtc8723b1ant_SetCoexTable(
633 struct btc_coexist *pBtCoexist,
640 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c0, val0x6c0);
642 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c4, val0x6c4);
644 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c8, val0x6c8);
646 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cc, val0x6cc);
649 static void halbtc8723b1ant_CoexTable(
650 struct btc_coexist *pBtCoexist,
658 pCoexDm->curVal0x6c0 = val0x6c0;
659 pCoexDm->curVal0x6c4 = val0x6c4;
660 pCoexDm->curVal0x6c8 = val0x6c8;
661 pCoexDm->curVal0x6cc = val0x6cc;
665 (pCoexDm->preVal0x6c0 == pCoexDm->curVal0x6c0) &&
666 (pCoexDm->preVal0x6c4 == pCoexDm->curVal0x6c4) &&
667 (pCoexDm->preVal0x6c8 == pCoexDm->curVal0x6c8) &&
668 (pCoexDm->preVal0x6cc == pCoexDm->curVal0x6cc)
673 halbtc8723b1ant_SetCoexTable(
674 pBtCoexist, val0x6c0, val0x6c4, val0x6c8, val0x6cc
677 pCoexDm->preVal0x6c0 = pCoexDm->curVal0x6c0;
678 pCoexDm->preVal0x6c4 = pCoexDm->curVal0x6c4;
679 pCoexDm->preVal0x6c8 = pCoexDm->curVal0x6c8;
680 pCoexDm->preVal0x6cc = pCoexDm->curVal0x6cc;
683 static void halbtc8723b1ant_CoexTableWithType(
684 struct btc_coexist *pBtCoexist, bool bForceExec, u8 type
687 pCoexSta->nCoexTableType = type;
691 halbtc8723b1ant_CoexTable(
692 pBtCoexist, bForceExec, 0x55555555, 0x55555555, 0xffffff, 0x3
696 halbtc8723b1ant_CoexTable(
697 pBtCoexist, bForceExec, 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3
701 halbtc8723b1ant_CoexTable(
702 pBtCoexist, bForceExec, 0x5a5a5a5a, 0x5a5a5a5a, 0xffffff, 0x3
706 halbtc8723b1ant_CoexTable(
707 pBtCoexist, bForceExec, 0xaaaa5555, 0xaaaa5a5a, 0xffffff, 0x3
711 halbtc8723b1ant_CoexTable(
712 pBtCoexist, bForceExec, 0x55555555, 0xaaaa5a5a, 0xffffff, 0x3
716 halbtc8723b1ant_CoexTable(
717 pBtCoexist, bForceExec, 0x5a5a5a5a, 0xaaaa5a5a, 0xffffff, 0x3
721 halbtc8723b1ant_CoexTable(
722 pBtCoexist, bForceExec, 0x55555555, 0xaaaaaaaa, 0xffffff, 0x3
726 halbtc8723b1ant_CoexTable(
727 pBtCoexist, bForceExec, 0xaaaaaaaa, 0xaaaaaaaa, 0xffffff, 0x3
735 static void halbtc8723b1ant_SetFwIgnoreWlanAct(
736 struct btc_coexist *pBtCoexist, bool bEnable
739 u8 H2C_Parameter[1] = {0};
742 H2C_Parameter[0] |= BIT0; /* function enable */
744 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x63, 1, H2C_Parameter);
747 static void halbtc8723b1ant_IgnoreWlanAct(
748 struct btc_coexist *pBtCoexist, bool bForceExec, bool bEnable
751 pCoexDm->bCurIgnoreWlanAct = bEnable;
754 if (pCoexDm->bPreIgnoreWlanAct == pCoexDm->bCurIgnoreWlanAct)
757 halbtc8723b1ant_SetFwIgnoreWlanAct(pBtCoexist, bEnable);
759 pCoexDm->bPreIgnoreWlanAct = pCoexDm->bCurIgnoreWlanAct;
762 static void halbtc8723b1ant_SetLpsRpwm(
763 struct btc_coexist *pBtCoexist, u8 lpsVal, u8 rpwmVal
769 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_LPS_VAL, &lps);
770 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RPWM_VAL, &rpwm);
773 static void halbtc8723b1ant_LpsRpwm(
774 struct btc_coexist *pBtCoexist, bool bForceExec, u8 lpsVal, u8 rpwmVal
777 pCoexDm->curLps = lpsVal;
778 pCoexDm->curRpwm = rpwmVal;
782 (pCoexDm->preLps == pCoexDm->curLps) &&
783 (pCoexDm->preRpwm == pCoexDm->curRpwm)
788 halbtc8723b1ant_SetLpsRpwm(pBtCoexist, lpsVal, rpwmVal);
790 pCoexDm->preLps = pCoexDm->curLps;
791 pCoexDm->preRpwm = pCoexDm->curRpwm;
794 static void halbtc8723b1ant_SwMechanism(
795 struct btc_coexist *pBtCoexist, bool bLowPenaltyRA
798 halbtc8723b1ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, bLowPenaltyRA);
801 static void halbtc8723b1ant_SetAntPath(
802 struct btc_coexist *pBtCoexist, u8 antPosType, bool bInitHwCfg, bool bWifiOff
805 struct btc_board_info *pBoardInfo = &pBtCoexist->boardInfo;
806 u32 fwVer = 0, u4Tmp = 0, cntBtCalChk = 0;
807 bool bPgExtSwitch = false;
808 bool bUseExtSwitch = false;
809 bool bIsInMpMode = false;
810 u8 H2C_Parameter[2] = {0}, u1Tmp = 0;
812 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_EXT_SWITCH, &bPgExtSwitch);
813 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer); /* [31:16]=fw ver, [15:0]=fw sub ver */
815 if ((fwVer > 0 && fwVer < 0xc0000) || bPgExtSwitch)
816 bUseExtSwitch = true;
819 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x780); /* WiFi TRx Mask on */
820 pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x3c, 0x15); /* BT TRx Mask on */
822 if (fwVer >= 0x180000) {
823 /* Use H2C to set GNT_BT to HIGH */
824 H2C_Parameter[0] = 1;
825 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x6E, 1, H2C_Parameter);
826 } else /* set grant_bt to high */
827 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x18);
829 /* set wlan_act control by PTA */
830 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4);
832 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x1); /* BT select s0/s1 is controlled by WiFi */
834 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x39, 0x8, 0x1);
835 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x974, 0xff);
836 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x944, 0x3, 0x3);
837 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x930, 0x77);
838 } else if (bWifiOff) {
839 if (fwVer >= 0x180000) {
840 /* Use H2C to set GNT_BT to HIGH */
841 H2C_Parameter[0] = 1;
842 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x6E, 1, H2C_Parameter);
843 } else /* set grant_bt to high */
844 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x18);
846 /* set wlan_act to always low */
847 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4);
849 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_IS_IN_MP_MODE, &bIsInMpMode);
851 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x0); /* BT select s0/s1 is controlled by BT */
853 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x1); /* BT select s0/s1 is controlled by WiFi */
855 /* 0x4c[24:23]= 00, Set Antenna control by BT_RFE_CTRL BT Vendor 0xac = 0xf002 */
856 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);
859 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);
861 /* Use H2C to set GNT_BT to LOW */
862 if (fwVer >= 0x180000) {
863 if (pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x765) != 0) {
864 H2C_Parameter[0] = 0;
865 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x6E, 1, H2C_Parameter);
868 /* BT calibration check */
869 while (cntBtCalChk <= 20) {
870 u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x49d);
879 /* set grant_bt to PTA */
880 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x0);
883 if (pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x76e) != 0xc)
884 /* set wlan_act control by PTA */
885 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc);
890 /* 0x4c[23]= 0, 0x4c[24]= 1 Antenna control by WL/BT */
891 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);
894 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);
896 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0); /* fixed internal switch S1->WiFi, S0->BT */
898 if (pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT) {
899 /* tell firmware "no antenna inverse" */
900 H2C_Parameter[0] = 0;
901 H2C_Parameter[1] = 1; /* ext switch type */
902 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter);
904 /* tell firmware "antenna inverse" */
905 H2C_Parameter[0] = 1;
906 H2C_Parameter[1] = 1; /* ext switch type */
907 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter);
912 /* ext switch setting */
913 switch (antPosType) {
914 case BTC_ANT_PATH_WIFI:
915 if (pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)
916 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x1);
918 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x2);
920 case BTC_ANT_PATH_BT:
921 if (pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)
922 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x2);
924 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x1);
927 case BTC_ANT_PATH_PTA:
928 if (pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)
929 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x1);
931 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x2);
937 /* 0x4c[23]= 1, 0x4c[24]= 0 Antenna control by 0x64 */
938 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);
941 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);
943 /* Fix Ext switch Main->S1, Aux->S0 */
944 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x64, 0x1, 0x0);
946 if (pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT) {
948 /* tell firmware "no antenna inverse" */
949 H2C_Parameter[0] = 0;
950 H2C_Parameter[1] = 0; /* internal switch type */
951 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter);
954 /* tell firmware "antenna inverse" */
955 H2C_Parameter[0] = 1;
956 H2C_Parameter[1] = 0; /* internal switch type */
957 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter);
962 /* internal switch setting */
963 switch (antPosType) {
964 case BTC_ANT_PATH_WIFI:
965 if (pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)
966 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);
968 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x280);
970 case BTC_ANT_PATH_BT:
971 if (pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)
972 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x280);
974 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);
977 case BTC_ANT_PATH_PTA:
978 if (pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT)
979 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x200);
981 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x80);
987 static void halbtc8723b1ant_SetFwPstdma(
988 struct btc_coexist *pBtCoexist, u8 byte1, u8 byte2, u8 byte3, u8 byte4, u8 byte5
991 u8 H2C_Parameter[5] = {0};
992 u8 realByte1 = byte1, realByte5 = byte5;
993 bool bApEnable = false;
995 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);
998 if (byte1 & BIT4 && !(byte1 & BIT5)) {
1007 H2C_Parameter[0] = realByte1;
1008 H2C_Parameter[1] = byte2;
1009 H2C_Parameter[2] = byte3;
1010 H2C_Parameter[3] = byte4;
1011 H2C_Parameter[4] = realByte5;
1013 pCoexDm->psTdmaPara[0] = realByte1;
1014 pCoexDm->psTdmaPara[1] = byte2;
1015 pCoexDm->psTdmaPara[2] = byte3;
1016 pCoexDm->psTdmaPara[3] = byte4;
1017 pCoexDm->psTdmaPara[4] = realByte5;
1019 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x60, 5, H2C_Parameter);
1023 static void halbtc8723b1ant_PsTdma(
1024 struct btc_coexist *pBtCoexist, bool bForceExec, bool bTurnOn, u8 type
1027 struct btc_bt_link_info *pBtLinkInfo = &pBtCoexist->btLinkInfo;
1028 bool bWifiBusy = false;
1029 u8 rssiAdjustVal = 0;
1030 u8 psTdmaByte4Val = 0x50, psTdmaByte0Val = 0x51, psTdmaByte3Val = 0x10;
1031 s8 nWiFiDurationAdjust = 0x0;
1032 /* u32 fwVer = 0; */
1034 pCoexDm->bCurPsTdmaOn = bTurnOn;
1035 pCoexDm->curPsTdma = type;
1037 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
1041 (pCoexDm->bPrePsTdmaOn == pCoexDm->bCurPsTdmaOn) &&
1042 (pCoexDm->prePsTdma == pCoexDm->curPsTdma)
1047 if (pCoexSta->nScanAPNum <= 5)
1048 nWiFiDurationAdjust = 5;
1049 else if (pCoexSta->nScanAPNum >= 40)
1050 nWiFiDurationAdjust = -15;
1051 else if (pCoexSta->nScanAPNum >= 20)
1052 nWiFiDurationAdjust = -10;
1054 if (!pCoexSta->bForceLpsOn) { /* only for A2DP-only case 1/2/9/11 */
1055 psTdmaByte0Val = 0x61; /* no null-pkt */
1056 psTdmaByte3Val = 0x11; /* no tx-pause at BT-slot */
1057 psTdmaByte4Val = 0x10; /* 0x778 = d/1 toggle */
1062 if (pBtLinkInfo->bSlaveRole)
1063 psTdmaByte4Val = psTdmaByte4Val | 0x1; /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */
1068 halbtc8723b1ant_SetFwPstdma(
1069 pBtCoexist, 0x51, 0x1a, 0x1a, 0x0, psTdmaByte4Val
1073 halbtc8723b1ant_SetFwPstdma(
1076 0x3a + nWiFiDurationAdjust,
1083 halbtc8723b1ant_SetFwPstdma(
1086 0x2d + nWiFiDurationAdjust,
1093 halbtc8723b1ant_SetFwPstdma(
1094 pBtCoexist, 0x51, 0x1d, 0x1d, 0x0, 0x10
1098 halbtc8723b1ant_SetFwPstdma(
1099 pBtCoexist, 0x93, 0x15, 0x3, 0x14, 0x0
1103 halbtc8723b1ant_SetFwPstdma(
1104 pBtCoexist, 0x61, 0x15, 0x3, 0x11, 0x10
1108 halbtc8723b1ant_SetFwPstdma(
1109 pBtCoexist, 0x61, 0x20, 0x3, 0x11, 0x11
1113 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x13, 0xc, 0x5, 0x0, 0x0);
1116 halbtc8723b1ant_SetFwPstdma(
1117 pBtCoexist, 0x93, 0x25, 0x3, 0x10, 0x0
1121 halbtc8723b1ant_SetFwPstdma(
1131 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x13, 0xa, 0xa, 0x0, 0x40);
1134 halbtc8723b1ant_SetFwPstdma(
1144 halbtc8723b1ant_SetFwPstdma(
1145 pBtCoexist, 0x51, 0x0a, 0x0a, 0x0, 0x50
1149 halbtc8723b1ant_SetFwPstdma(
1150 pBtCoexist, 0x51, 0x12, 0x12, 0x0, 0x10
1154 halbtc8723b1ant_SetFwPstdma(
1155 pBtCoexist, 0x51, 0x21, 0x3, 0x10, psTdmaByte4Val
1159 halbtc8723b1ant_SetFwPstdma(
1160 pBtCoexist, 0x13, 0xa, 0x3, 0x8, 0x0
1164 halbtc8723b1ant_SetFwPstdma(
1165 pBtCoexist, 0x93, 0x15, 0x3, 0x10, 0x0
1169 halbtc8723b1ant_SetFwPstdma(
1170 pBtCoexist, 0x93, 0x25, 0x3, 0x10, 0x0
1174 halbtc8723b1ant_SetFwPstdma(
1175 pBtCoexist, 0x61, 0x3f, 0x03, 0x11, 0x10
1180 halbtc8723b1ant_SetFwPstdma(
1181 pBtCoexist, 0x61, 0x25, 0x03, 0x11, 0x11
1185 halbtc8723b1ant_SetFwPstdma(
1186 pBtCoexist, 0x61, 0x25, 0x03, 0x11, 0x10
1190 halbtc8723b1ant_SetFwPstdma(
1191 pBtCoexist, 0xe3, 0x25, 0x3, 0x31, 0x18
1195 halbtc8723b1ant_SetFwPstdma(
1196 pBtCoexist, 0xe3, 0x15, 0x3, 0x31, 0x18
1200 halbtc8723b1ant_SetFwPstdma(
1201 pBtCoexist, 0xe3, 0xa, 0x3, 0x31, 0x18
1205 halbtc8723b1ant_SetFwPstdma(
1206 pBtCoexist, 0xe3, 0xa, 0x3, 0x31, 0x18
1210 halbtc8723b1ant_SetFwPstdma(
1211 pBtCoexist, 0xe3, 0x25, 0x3, 0x31, 0x98
1215 halbtc8723b1ant_SetFwPstdma(
1216 pBtCoexist, 0x69, 0x25, 0x3, 0x31, 0x0
1220 halbtc8723b1ant_SetFwPstdma(
1221 pBtCoexist, 0xab, 0x1a, 0x1a, 0x1, 0x10
1225 halbtc8723b1ant_SetFwPstdma(
1226 pBtCoexist, 0x51, 0x30, 0x3, 0x10, 0x10
1230 halbtc8723b1ant_SetFwPstdma(
1231 pBtCoexist, 0xd3, 0x1a, 0x1a, 0x0, 0x58
1235 halbtc8723b1ant_SetFwPstdma(
1236 pBtCoexist, 0x61, 0x35, 0x3, 0x11, 0x11
1240 halbtc8723b1ant_SetFwPstdma(
1241 pBtCoexist, 0xa3, 0x25, 0x3, 0x30, 0x90
1245 halbtc8723b1ant_SetFwPstdma(
1246 pBtCoexist, 0x53, 0x1a, 0x1a, 0x0, 0x10
1250 halbtc8723b1ant_SetFwPstdma(
1251 pBtCoexist, 0x63, 0x1a, 0x1a, 0x0, 0x10
1255 halbtc8723b1ant_SetFwPstdma(
1256 pBtCoexist, 0xd3, 0x12, 0x3, 0x14, 0x50
1259 case 40: /* SoftAP only with no sta associated, BT disable , TDMA mode for power saving */
1260 /* here softap mode screen off will cost 70-80mA for phone */
1261 halbtc8723b1ant_SetFwPstdma(
1262 pBtCoexist, 0x23, 0x18, 0x00, 0x10, 0x24
1268 /* disable PS tdma */
1270 case 8: /* PTA Control */
1271 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x8, 0x0, 0x0, 0x0, 0x0);
1272 halbtc8723b1ant_SetAntPath(
1273 pBtCoexist, BTC_ANT_PATH_PTA, false, false
1277 default: /* Software control, Antenna at BT side */
1278 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x0, 0x0);
1279 halbtc8723b1ant_SetAntPath(
1280 pBtCoexist, BTC_ANT_PATH_BT, false, false
1283 case 9: /* Software control, Antenna at WiFi side */
1284 halbtc8723b1ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x0, 0x0);
1285 halbtc8723b1ant_SetAntPath(
1286 pBtCoexist, BTC_ANT_PATH_WIFI, false, false
1293 pBtCoexist->fBtcSet(
1294 pBtCoexist, BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE, &rssiAdjustVal
1297 /* update pre state */
1298 pCoexDm->bPrePsTdmaOn = pCoexDm->bCurPsTdmaOn;
1299 pCoexDm->prePsTdma = pCoexDm->curPsTdma;
1302 static bool halbtc8723b1ant_IsCommonAction(struct btc_coexist *pBtCoexist)
1304 bool bCommon = false, bWifiConnected = false, bWifiBusy = false;
1306 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
1307 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
1311 pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE
1313 /* halbtc8723b1ant_SwMechanism(pBtCoexist, false); */
1318 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE)
1320 /* halbtc8723b1ant_SwMechanism(pBtCoexist, false); */
1325 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE)
1327 /* halbtc8723b1ant_SwMechanism(pBtCoexist, false); */
1332 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE)
1334 /* halbtc8723b1ant_SwMechanism(pBtCoexist, false); */
1339 (pCoexDm->btStatus != BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE)
1341 /* halbtc8723b1ant_SwMechanism(pBtCoexist, false); */
1352 static void halbtc8723b1ant_TdmaDurationAdjustForAcl(
1353 struct btc_coexist *pBtCoexist, u8 wifiStatus
1356 static s32 up, dn, m, n, WaitCount;
1357 s32 result; /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */
1358 u8 retryCount = 0, btInfoExt;
1361 (wifiStatus == BT_8723B_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN) ||
1362 (wifiStatus == BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN) ||
1363 (wifiStatus == BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SPECIAL_PKT)
1366 pCoexDm->curPsTdma != 1 &&
1367 pCoexDm->curPsTdma != 2 &&
1368 pCoexDm->curPsTdma != 3 &&
1369 pCoexDm->curPsTdma != 9
1371 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 9);
1372 pCoexDm->psTdmaDuAdjType = 9;
1384 if (!pCoexDm->bAutoTdmaAdjust) {
1385 pCoexDm->bAutoTdmaAdjust = true;
1387 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2);
1388 pCoexDm->psTdmaDuAdjType = 2;
1397 /* acquire the BT TRx retry count from BT_Info byte2 */
1398 retryCount = pCoexSta->btRetryCnt;
1399 btInfoExt = pCoexSta->btInfoExt;
1401 if (pCoexSta->lowPriorityTx > 1050 || pCoexSta->lowPriorityRx > 1250)
1407 if (retryCount == 0) { /* no retry in the last 2-second duration */
1414 if (up >= n) { /* if 連續 n 個2秒 retry count為0, 則調寬WiFi duration */
1421 } else if (retryCount <= 3) { /* <=3 retry in the last 2-second duration */
1428 if (dn == 2) { /* if 連續 2 個2秒 retry count< 3, 則調窄WiFi duration */
1430 m++; /* 避免一直在兩個level中來回 */
1434 if (m >= 20) /* m 最大值 = 20 ' 最大120秒 recheck是否調整 WiFi duration. */
1443 } else { /* retry count > 3, 只要1次 retry count > 3, 則調窄WiFi duration */
1445 m++; /* 避免一直在兩個level中來回 */
1449 if (m >= 20) /* m 最大值 = 20 ' 最大120秒 recheck是否調整 WiFi duration. */
1461 BT_INFO_8723B_1ANT_A2DP_BASIC_RATE(btInfoExt) &&
1462 ((pCoexDm->curPsTdma == 1) || (pCoexDm->curPsTdma == 2))
1464 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 9);
1465 pCoexDm->psTdmaDuAdjType = 9;
1466 } else if (pCoexDm->curPsTdma == 1) {
1467 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2);
1468 pCoexDm->psTdmaDuAdjType = 2;
1469 } else if (pCoexDm->curPsTdma == 2) {
1470 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 9);
1471 pCoexDm->psTdmaDuAdjType = 9;
1472 } else if (pCoexDm->curPsTdma == 9) {
1473 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 11);
1474 pCoexDm->psTdmaDuAdjType = 11;
1476 } else if (result == 1) {
1478 BT_INFO_8723B_1ANT_A2DP_BASIC_RATE(btInfoExt) &&
1479 ((pCoexDm->curPsTdma == 1) || (pCoexDm->curPsTdma == 2))
1481 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 9);
1482 pCoexDm->psTdmaDuAdjType = 9;
1483 } else if (pCoexDm->curPsTdma == 11) {
1484 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 9);
1485 pCoexDm->psTdmaDuAdjType = 9;
1486 } else if (pCoexDm->curPsTdma == 9) {
1487 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 2);
1488 pCoexDm->psTdmaDuAdjType = 2;
1489 } else if (pCoexDm->curPsTdma == 2) {
1490 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 1);
1491 pCoexDm->psTdmaDuAdjType = 1;
1496 pCoexDm->curPsTdma != 1 &&
1497 pCoexDm->curPsTdma != 2 &&
1498 pCoexDm->curPsTdma != 9 &&
1499 pCoexDm->curPsTdma != 11
1500 ) /* recover to previous adjust type */
1501 halbtc8723b1ant_PsTdma(
1502 pBtCoexist, NORMAL_EXEC, true, pCoexDm->psTdmaDuAdjType
1507 static void halbtc8723b1ant_PsTdmaCheckForPowerSaveState(
1508 struct btc_coexist *pBtCoexist, bool bNewPsState
1513 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_LPS_MODE, &lpsMode);
1515 if (lpsMode) { /* already under LPS state */
1517 /* keep state under LPS, do nothing. */
1518 } else /* will leave LPS state, turn off psTdma first */
1519 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 0);
1520 } else { /* NO PS state */
1521 if (bNewPsState) /* will enter LPS state, turn off psTdma first */
1522 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 0);
1524 /* keep state under NO PS state, do nothing. */
1529 static void halbtc8723b1ant_PowerSaveState(
1530 struct btc_coexist *pBtCoexist, u8 psType, u8 lpsVal, u8 rpwmVal
1533 bool bLowPwrDisable = false;
1536 case BTC_PS_WIFI_NATIVE:
1537 /* recover to original 32k low power setting */
1538 bLowPwrDisable = false;
1539 pBtCoexist->fBtcSet(
1540 pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable
1542 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_NORMAL_LPS, NULL);
1543 pCoexSta->bForceLpsOn = false;
1546 halbtc8723b1ant_PsTdmaCheckForPowerSaveState(pBtCoexist, true);
1547 halbtc8723b1ant_LpsRpwm(pBtCoexist, NORMAL_EXEC, lpsVal, rpwmVal);
1548 /* when coex force to enter LPS, do not enter 32k low power. */
1549 bLowPwrDisable = true;
1550 pBtCoexist->fBtcSet(
1551 pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable
1553 /* power save must executed before psTdma. */
1554 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_ENTER_LPS, NULL);
1555 pCoexSta->bForceLpsOn = true;
1557 case BTC_PS_LPS_OFF:
1558 halbtc8723b1ant_PsTdmaCheckForPowerSaveState(pBtCoexist, false);
1559 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_LEAVE_LPS, NULL);
1560 pCoexSta->bForceLpsOn = false;
1569 /* Software Coex Mechanism start */
1575 /* Non-Software Coex Mechanism start */
1578 static void halbtc8723b1ant_ActionWifiMultiPort(struct btc_coexist *pBtCoexist)
1580 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1582 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 8);
1583 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
1586 static void halbtc8723b1ant_ActionHs(struct btc_coexist *pBtCoexist)
1588 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 5);
1589 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
1592 static void halbtc8723b1ant_ActionBtInquiry(struct btc_coexist *pBtCoexist)
1594 struct btc_bt_link_info *pBtLinkInfo = &pBtCoexist->btLinkInfo;
1595 bool bWifiConnected = false;
1596 bool bApEnable = false;
1597 bool bWifiBusy = false;
1598 bool bBtBusy = false;
1600 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);
1601 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
1602 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
1603 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);
1605 if (!bWifiConnected && !pCoexSta->bWiFiIsHighPriTask) {
1606 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1607 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 8);
1609 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
1611 pBtLinkInfo->bScoExist ||
1612 pBtLinkInfo->bHidExist ||
1613 pBtLinkInfo->bA2dpExist
1615 /* SCO/HID/A2DP busy */
1616 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1617 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 32);
1619 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1620 } else if (pBtLinkInfo->bPanExist || bWifiBusy) {
1621 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1622 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 20);
1624 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1626 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1627 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 8);
1629 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
1633 static void halbtc8723b1ant_ActionBtScoHidOnlyBusy(
1634 struct btc_coexist *pBtCoexist, u8 wifiStatus
1637 struct btc_bt_link_info *pBtLinkInfo = &pBtCoexist->btLinkInfo;
1638 bool bWifiConnected = false;
1640 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
1642 /* tdma and coex table */
1644 if (pBtLinkInfo->bScoExist) {
1645 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 5);
1646 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 5);
1648 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 6);
1649 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 5);
1653 static void halbtc8723b1ant_ActionWifiConnectedBtAclBusy(
1654 struct btc_coexist *pBtCoexist, u8 wifiStatus
1657 struct btc_bt_link_info *pBtLinkInfo = &pBtCoexist->btLinkInfo;
1659 halbtc8723b1ant_BtRssiState(2, 28, 0);
1661 if ((pCoexSta->lowPriorityRx >= 1000) && (pCoexSta->lowPriorityRx != 65535))
1662 pBtLinkInfo->bSlaveRole = true;
1664 pBtLinkInfo->bSlaveRole = false;
1666 if (pBtLinkInfo->bHidOnly) { /* HID */
1667 halbtc8723b1ant_ActionBtScoHidOnlyBusy(pBtCoexist, wifiStatus);
1668 pCoexDm->bAutoTdmaAdjust = false;
1670 } else if (pBtLinkInfo->bA2dpOnly) { /* A2DP */
1671 if (wifiStatus == BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE) {
1672 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 32);
1673 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1674 pCoexDm->bAutoTdmaAdjust = false;
1676 halbtc8723b1ant_TdmaDurationAdjustForAcl(pBtCoexist, wifiStatus);
1677 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1678 pCoexDm->bAutoTdmaAdjust = true;
1680 } else if (pBtLinkInfo->bHidExist && pBtLinkInfo->bA2dpExist) { /* HID+A2DP */
1681 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 14);
1682 pCoexDm->bAutoTdmaAdjust = false;
1684 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1686 pBtLinkInfo->bPanOnly ||
1687 (pBtLinkInfo->bHidExist && pBtLinkInfo->bPanExist)
1688 ) { /* PAN(OPP, FTP), HID+PAN(OPP, FTP) */
1689 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
1690 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1691 pCoexDm->bAutoTdmaAdjust = false;
1693 (pBtLinkInfo->bA2dpExist && pBtLinkInfo->bPanExist) ||
1694 (pBtLinkInfo->bHidExist && pBtLinkInfo->bA2dpExist && pBtLinkInfo->bPanExist)
1695 ) { /* A2DP+PAN(OPP, FTP), HID+A2DP+PAN(OPP, FTP) */
1696 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 13);
1697 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1698 pCoexDm->bAutoTdmaAdjust = false;
1700 /* BT no-profile busy (0x9) */
1701 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 32);
1702 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1703 pCoexDm->bAutoTdmaAdjust = false;
1707 static void halbtc8723b1ant_ActionWifiNotConnected(struct btc_coexist *pBtCoexist)
1709 /* power save state */
1710 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1712 /* tdma and coex table */
1713 halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, false, 8);
1714 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
1717 static void halbtc8723b1ant_ActionWifiNotConnectedScan(
1718 struct btc_coexist *pBtCoexist
1721 struct btc_bt_link_info *pBtLinkInfo = &pBtCoexist->btLinkInfo;
1723 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1725 /* tdma and coex table */
1726 if (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_BUSY) {
1727 if (pBtLinkInfo->bA2dpExist) {
1728 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 32);
1729 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1730 } else if (pBtLinkInfo->bA2dpExist && pBtLinkInfo->bPanExist) {
1731 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 22);
1732 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1734 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 20);
1735 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1738 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_SCO_BUSY) ||
1739 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY)
1741 halbtc8723b1ant_ActionBtScoHidOnlyBusy(
1742 pBtCoexist, BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN
1746 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 8);
1747 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
1751 static void halbtc8723b1ant_ActionWifiNotConnectedAssoAuth(
1752 struct btc_coexist *pBtCoexist
1755 struct btc_bt_link_info *pBtLinkInfo = &pBtCoexist->btLinkInfo;
1757 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1759 /* tdma and coex table */
1761 (pBtLinkInfo->bScoExist) ||
1762 (pBtLinkInfo->bHidExist) ||
1763 (pBtLinkInfo->bA2dpExist)
1765 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 32);
1766 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1767 } else if (pBtLinkInfo->bPanExist) {
1768 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 20);
1769 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1771 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 8);
1772 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
1776 static void halbtc8723b1ant_ActionWifiConnectedScan(struct btc_coexist *pBtCoexist)
1778 struct btc_bt_link_info *pBtLinkInfo = &pBtCoexist->btLinkInfo;
1780 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1782 /* tdma and coex table */
1783 if (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_BUSY) {
1784 if (pBtLinkInfo->bA2dpExist) {
1785 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 32);
1786 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1787 } else if (pBtLinkInfo->bA2dpExist && pBtLinkInfo->bPanExist) {
1788 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 22);
1789 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1791 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 20);
1792 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1795 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_SCO_BUSY) ||
1796 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY)
1798 halbtc8723b1ant_ActionBtScoHidOnlyBusy(
1799 pBtCoexist, BT_8723B_1ANT_WIFI_STATUS_CONNECTED_SCAN
1803 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 8);
1804 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
1808 static void halbtc8723b1ant_ActionWifiConnectedSpecialPacket(
1809 struct btc_coexist *pBtCoexist
1812 struct btc_bt_link_info *pBtLinkInfo = &pBtCoexist->btLinkInfo;
1814 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1816 /* tdma and coex table */
1818 (pBtLinkInfo->bScoExist) ||
1819 (pBtLinkInfo->bHidExist) ||
1820 (pBtLinkInfo->bA2dpExist)
1822 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 32);
1823 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1824 } else if (pBtLinkInfo->bPanExist) {
1825 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 20);
1826 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);
1828 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 8);
1829 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
1833 static void halbtc8723b1ant_ActionWifiConnected(struct btc_coexist *pBtCoexist)
1835 bool bWifiBusy = false;
1836 bool bScan = false, bLink = false, bRoam = false;
1837 bool bUnder4way = false, bApEnable = false;
1839 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way);
1841 halbtc8723b1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);
1845 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
1846 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
1847 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
1848 if (bScan || bLink || bRoam) {
1850 halbtc8723b1ant_ActionWifiConnectedScan(pBtCoexist);
1852 halbtc8723b1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);
1856 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);
1857 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
1859 /* power save state */
1862 pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_BUSY &&
1863 !pBtCoexist->btLinkInfo.bHidOnly
1865 if (pBtCoexist->btLinkInfo.bA2dpOnly) { /* A2DP */
1867 halbtc8723b1ant_PowerSaveState(
1868 pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0
1871 if (pCoexSta->nScanAPNum >= BT_8723B_1ANT_WIFI_NOISY_THRESH) /* no force LPS, no PS-TDMA, use pure TDMA */
1872 halbtc8723b1ant_PowerSaveState(
1873 pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0
1876 halbtc8723b1ant_PowerSaveState(
1877 pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4
1881 (!pCoexSta->bPanExist) &&
1882 (!pCoexSta->bA2dpExist) &&
1883 (!pCoexSta->bHidExist)
1885 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1887 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_LPS_ON, 0x50, 0x4);
1889 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
1891 /* tdma and coex table */
1893 if (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_BUSY) {
1894 halbtc8723b1ant_ActionWifiConnectedBtAclBusy(
1896 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE
1899 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_SCO_BUSY) ||
1900 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY)
1902 halbtc8723b1ant_ActionBtScoHidOnlyBusy(pBtCoexist,
1903 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_IDLE);
1905 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 8);
1907 if ((pCoexSta->highPriorityTx) + (pCoexSta->highPriorityRx) <= 60)
1908 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
1910 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
1913 if (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_BUSY) {
1914 halbtc8723b1ant_ActionWifiConnectedBtAclBusy(
1916 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY
1919 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_SCO_BUSY) ||
1920 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY)
1922 halbtc8723b1ant_ActionBtScoHidOnlyBusy(
1924 BT_8723B_1ANT_WIFI_STATUS_CONNECTED_BUSY
1927 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 8);
1929 if ((pCoexSta->highPriorityTx) + (pCoexSta->highPriorityRx) <= 60)
1930 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
1932 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
1937 static void halbtc8723b1ant_RunSwCoexistMechanism(struct btc_coexist *pBtCoexist)
1941 algorithm = halbtc8723b1ant_ActionAlgorithm(pBtCoexist);
1942 pCoexDm->curAlgorithm = algorithm;
1944 if (halbtc8723b1ant_IsCommonAction(pBtCoexist)) {
1947 switch (pCoexDm->curAlgorithm) {
1948 case BT_8723B_1ANT_COEX_ALGO_SCO:
1949 /* halbtc8723b1ant_ActionSco(pBtCoexist); */
1951 case BT_8723B_1ANT_COEX_ALGO_HID:
1952 /* halbtc8723b1ant_ActionHid(pBtCoexist); */
1954 case BT_8723B_1ANT_COEX_ALGO_A2DP:
1955 /* halbtc8723b1ant_ActionA2dp(pBtCoexist); */
1957 case BT_8723B_1ANT_COEX_ALGO_A2DP_PANHS:
1958 /* halbtc8723b1ant_ActionA2dpPanHs(pBtCoexist); */
1960 case BT_8723B_1ANT_COEX_ALGO_PANEDR:
1961 /* halbtc8723b1ant_ActionPanEdr(pBtCoexist); */
1963 case BT_8723B_1ANT_COEX_ALGO_PANHS:
1964 /* halbtc8723b1ant_ActionPanHs(pBtCoexist); */
1966 case BT_8723B_1ANT_COEX_ALGO_PANEDR_A2DP:
1967 /* halbtc8723b1ant_ActionPanEdrA2dp(pBtCoexist); */
1969 case BT_8723B_1ANT_COEX_ALGO_PANEDR_HID:
1970 /* halbtc8723b1ant_ActionPanEdrHid(pBtCoexist); */
1972 case BT_8723B_1ANT_COEX_ALGO_HID_A2DP_PANEDR:
1973 /* halbtc8723b1ant_ActionHidA2dpPanEdr(pBtCoexist); */
1975 case BT_8723B_1ANT_COEX_ALGO_HID_A2DP:
1976 /* halbtc8723b1ant_ActionHidA2dp(pBtCoexist); */
1981 pCoexDm->preAlgorithm = pCoexDm->curAlgorithm;
1985 static void halbtc8723b1ant_RunCoexistMechanism(struct btc_coexist *pBtCoexist)
1987 struct btc_bt_link_info *pBtLinkInfo = &pBtCoexist->btLinkInfo;
1988 bool bWifiConnected = false, bBtHsOn = false;
1989 bool bIncreaseScanDevNum = false;
1990 bool bBtCtrlAggBufSize = false;
1992 u32 wifiLinkStatus = 0;
1993 u32 numOfWifiLink = 0;
1995 if (pBtCoexist->bManualControl)
1998 if (pBtCoexist->bStopCoexDm)
2001 if (pCoexSta->bUnderIps)
2005 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_BUSY) ||
2006 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_SCO_BUSY) ||
2007 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY)
2009 bIncreaseScanDevNum = true;
2012 pBtCoexist->fBtcSet(
2014 BTC_SET_BL_INC_SCAN_DEV_NUM,
2015 &bIncreaseScanDevNum
2017 pBtCoexist->fBtcGet(
2019 BTC_GET_BL_WIFI_CONNECTED,
2023 pBtCoexist->fBtcGet(
2025 BTC_GET_U4_WIFI_LINK_STATUS,
2028 numOfWifiLink = wifiLinkStatus >> 16;
2030 if ((numOfWifiLink >= 2) || (wifiLinkStatus & WIFI_P2P_GO_CONNECTED)) {
2031 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);
2032 halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, bBtCtrlAggBufSize, aggBufSize);
2034 if ((pBtLinkInfo->bA2dpExist) && (pCoexSta->bC2hBtInquiryPage))
2035 halbtc8723b1ant_ActionBtInquiry(pBtCoexist);
2037 halbtc8723b1ant_ActionWifiMultiPort(pBtCoexist);
2042 if ((pBtLinkInfo->bBtLinkExist) && (bWifiConnected)) {
2043 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 1, 1, 0, 1);
2045 if (pBtLinkInfo->bScoExist)
2046 halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, true, 0x5);
2048 halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, true, 0x8);
2050 halbtc8723b1ant_SwMechanism(pBtCoexist, true);
2051 halbtc8723b1ant_RunSwCoexistMechanism(pBtCoexist); /* just print debug message */
2053 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);
2055 halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x5);
2057 halbtc8723b1ant_SwMechanism(pBtCoexist, false);
2058 halbtc8723b1ant_RunSwCoexistMechanism(pBtCoexist); /* just print debug message */
2061 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
2062 if (pCoexSta->bC2hBtInquiryPage) {
2063 halbtc8723b1ant_ActionBtInquiry(pBtCoexist);
2065 } else if (bBtHsOn) {
2066 halbtc8723b1ant_ActionHs(pBtCoexist);
2071 if (!bWifiConnected) {
2072 bool bScan = false, bLink = false, bRoam = false;
2074 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
2075 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
2076 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
2078 if (bScan || bLink || bRoam) {
2080 halbtc8723b1ant_ActionWifiNotConnectedScan(pBtCoexist);
2082 halbtc8723b1ant_ActionWifiNotConnectedAssoAuth(pBtCoexist);
2084 halbtc8723b1ant_ActionWifiNotConnected(pBtCoexist);
2085 } else /* wifi LPS/Busy */
2086 halbtc8723b1ant_ActionWifiConnected(pBtCoexist);
2089 static void halbtc8723b1ant_InitCoexDm(struct btc_coexist *pBtCoexist)
2091 /* force to reset coex mechanism */
2094 halbtc8723b1ant_SwMechanism(pBtCoexist, false);
2096 /* halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, false, 8); */
2097 halbtc8723b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);
2099 pCoexSta->popEventCnt = 0;
2102 static void halbtc8723b1ant_InitHwConfig(
2103 struct btc_coexist *pBtCoexist,
2108 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x550, 0x8, 0x1); /* enable TBTT nterrupt */
2110 /* 0x790[5:0]= 0x5 */
2111 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x790, 0x5);
2113 /* Enable counter statistics */
2114 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x778, 0x1);
2115 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x40, 0x20, 0x1);
2117 /* Antenna config */
2119 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_WIFI, true, false);
2120 halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, false, 9);
2122 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, true, false);
2125 halbtc8723b1ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);
2127 pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x948);
2128 pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x765);
2129 pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x67);
2133 /* work around function start with wa_halbtc8723b1ant_ */
2136 /* extern function start with EXhalbtc8723b1ant_ */
2138 void EXhalbtc8723b1ant_PowerOnSetting(struct btc_coexist *pBtCoexist)
2140 struct btc_board_info *pBoardInfo = &pBtCoexist->boardInfo;
2144 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x67, 0x20);
2146 /* enable BB, REG_SYS_FUNC_EN such that we can write 0x948 correctly. */
2147 u2Tmp = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x2);
2148 pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x2, u2Tmp | BIT0 | BIT1);
2150 /* set GRAN_BT = 1 */
2151 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x18);
2152 /* set WLAN_ACT = 0 */
2153 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4);
2156 /* S0 or S1 setting and Local register setting(By the setting fw can get ant number, S0/S1, ... info) */
2157 /* Local setting bit define */
2158 /* BIT0: "0" for no antenna inverse; "1" for antenna inverse */
2159 /* BIT1: "0" for internal switch; "1" for external switch */
2160 /* BIT2: "0" for one antenna; "1" for two antenna */
2161 /* NOTE: here default all internal switch and 1-antenna ==> BIT1 = 0 and BIT2 = 0 */
2162 if (pBtCoexist->chipInterface == BTC_INTF_USB) {
2163 /* fixed at S0 for USB interface */
2164 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);
2166 u1Tmp |= 0x1; /* antenna inverse */
2167 pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0xfe08, u1Tmp);
2169 pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_AUX_PORT;
2171 /* for PCIE and SDIO interface, we check efuse 0xc3[6] */
2172 if (pBoardInfo->singleAntPath == 0) {
2174 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x280);
2175 pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
2176 } else if (pBoardInfo->singleAntPath == 1) {
2178 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);
2179 u1Tmp |= 0x1; /* antenna inverse */
2180 pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_AUX_PORT;
2183 if (pBtCoexist->chipInterface == BTC_INTF_PCI)
2184 pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0x384, u1Tmp);
2185 else if (pBtCoexist->chipInterface == BTC_INTF_SDIO)
2186 pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0x60, u1Tmp);
2190 void EXhalbtc8723b1ant_InitHwConfig(struct btc_coexist *pBtCoexist, bool bWifiOnly)
2192 halbtc8723b1ant_InitHwConfig(pBtCoexist, true, bWifiOnly);
2195 void EXhalbtc8723b1ant_InitCoexDm(struct btc_coexist *pBtCoexist)
2197 pBtCoexist->bStopCoexDm = false;
2199 halbtc8723b1ant_InitCoexDm(pBtCoexist);
2201 halbtc8723b1ant_QueryBtInfo(pBtCoexist);
2204 void EXhalbtc8723b1ant_IpsNotify(struct btc_coexist *pBtCoexist, u8 type)
2206 if (pBtCoexist->bManualControl || pBtCoexist->bStopCoexDm)
2209 if (type == BTC_IPS_ENTER) {
2210 pCoexSta->bUnderIps = true;
2212 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 0);
2213 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
2214 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, false, true);
2215 } else if (type == BTC_IPS_LEAVE) {
2216 pCoexSta->bUnderIps = false;
2218 halbtc8723b1ant_InitHwConfig(pBtCoexist, false, false);
2219 halbtc8723b1ant_InitCoexDm(pBtCoexist);
2220 halbtc8723b1ant_QueryBtInfo(pBtCoexist);
2224 void EXhalbtc8723b1ant_LpsNotify(struct btc_coexist *pBtCoexist, u8 type)
2226 if (pBtCoexist->bManualControl || pBtCoexist->bStopCoexDm)
2229 if (type == BTC_LPS_ENABLE)
2230 pCoexSta->bUnderLps = true;
2231 else if (type == BTC_LPS_DISABLE)
2232 pCoexSta->bUnderLps = false;
2235 void EXhalbtc8723b1ant_ScanNotify(struct btc_coexist *pBtCoexist, u8 type)
2237 bool bWifiConnected = false, bBtHsOn = false;
2238 u32 wifiLinkStatus = 0;
2239 u32 numOfWifiLink = 0;
2240 bool bBtCtrlAggBufSize = false;
2243 if (pBtCoexist->bManualControl || pBtCoexist->bStopCoexDm)
2246 if (type == BTC_SCAN_START) {
2247 pCoexSta->bWiFiIsHighPriTask = true;
2249 halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, false, 8); /* Force antenna setup for no scan result issue */
2250 pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x948);
2251 pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x765);
2252 pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x67);
2254 pCoexSta->bWiFiIsHighPriTask = false;
2256 pBtCoexist->fBtcGet(
2257 pBtCoexist, BTC_GET_U1_AP_NUM, &pCoexSta->nScanAPNum
2261 if (pBtCoexist->btInfo.bBtDisabled)
2264 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
2265 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
2267 halbtc8723b1ant_QueryBtInfo(pBtCoexist);
2269 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);
2270 numOfWifiLink = wifiLinkStatus >> 16;
2272 if (numOfWifiLink >= 2) {
2273 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);
2274 halbtc8723b1ant_LimitedRx(
2275 pBtCoexist, NORMAL_EXEC, false, bBtCtrlAggBufSize, aggBufSize
2277 halbtc8723b1ant_ActionWifiMultiPort(pBtCoexist);
2281 if (pCoexSta->bC2hBtInquiryPage) {
2282 halbtc8723b1ant_ActionBtInquiry(pBtCoexist);
2284 } else if (bBtHsOn) {
2285 halbtc8723b1ant_ActionHs(pBtCoexist);
2289 if (type == BTC_SCAN_START) {
2290 if (!bWifiConnected) /* non-connected scan */
2291 halbtc8723b1ant_ActionWifiNotConnectedScan(pBtCoexist);
2292 else /* wifi is connected */
2293 halbtc8723b1ant_ActionWifiConnectedScan(pBtCoexist);
2294 } else if (type == BTC_SCAN_FINISH) {
2295 if (!bWifiConnected) /* non-connected scan */
2296 halbtc8723b1ant_ActionWifiNotConnected(pBtCoexist);
2298 halbtc8723b1ant_ActionWifiConnected(pBtCoexist);
2302 void EXhalbtc8723b1ant_ConnectNotify(struct btc_coexist *pBtCoexist, u8 type)
2304 bool bWifiConnected = false, bBtHsOn = false;
2305 u32 wifiLinkStatus = 0;
2306 u32 numOfWifiLink = 0;
2307 bool bBtCtrlAggBufSize = false;
2311 pBtCoexist->bManualControl ||
2312 pBtCoexist->bStopCoexDm ||
2313 pBtCoexist->btInfo.bBtDisabled
2317 if (type == BTC_ASSOCIATE_START) {
2318 pCoexSta->bWiFiIsHighPriTask = true;
2319 pCoexDm->nArpCnt = 0;
2321 pCoexSta->bWiFiIsHighPriTask = false;
2322 /* pCoexDm->nArpCnt = 0; */
2325 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus);
2326 numOfWifiLink = wifiLinkStatus >> 16;
2327 if (numOfWifiLink >= 2) {
2328 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);
2329 halbtc8723b1ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, bBtCtrlAggBufSize, aggBufSize);
2330 halbtc8723b1ant_ActionWifiMultiPort(pBtCoexist);
2334 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
2335 if (pCoexSta->bC2hBtInquiryPage) {
2336 halbtc8723b1ant_ActionBtInquiry(pBtCoexist);
2338 } else if (bBtHsOn) {
2339 halbtc8723b1ant_ActionHs(pBtCoexist);
2343 if (type == BTC_ASSOCIATE_START) {
2344 halbtc8723b1ant_ActionWifiNotConnectedAssoAuth(pBtCoexist);
2345 } else if (type == BTC_ASSOCIATE_FINISH) {
2346 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
2347 if (!bWifiConnected) /* non-connected scan */
2348 halbtc8723b1ant_ActionWifiNotConnected(pBtCoexist);
2350 halbtc8723b1ant_ActionWifiConnected(pBtCoexist);
2354 void EXhalbtc8723b1ant_MediaStatusNotify(struct btc_coexist *pBtCoexist, u8 type)
2356 u8 H2C_Parameter[3] = {0};
2359 bool bWifiUnderBMode = false;
2362 pBtCoexist->bManualControl ||
2363 pBtCoexist->bStopCoexDm ||
2364 pBtCoexist->btInfo.bBtDisabled
2368 if (type == BTC_MEDIA_CONNECT) {
2369 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode);
2371 /* Set CCK Tx/Rx high Pri except 11b mode */
2372 if (bWifiUnderBMode) {
2373 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cd, 0x00); /* CCK Tx */
2374 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cf, 0x00); /* CCK Rx */
2376 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cd, 0x10); /* CCK Tx */
2377 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cf, 0x10); /* CCK Rx */
2380 pCoexDm->backupArfrCnt1 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x430);
2381 pCoexDm->backupArfrCnt2 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x434);
2382 pCoexDm->backupRetryLimit = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x42a);
2383 pCoexDm->backupAmpduMaxTime = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x456);
2385 pCoexDm->nArpCnt = 0;
2387 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cd, 0x0); /* CCK Tx */
2388 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cf, 0x0); /* CCK Rx */
2391 /* only 2.4G we need to inform bt the chnl mask */
2392 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, &wifiCentralChnl);
2393 if ((type == BTC_MEDIA_CONNECT) && (wifiCentralChnl <= 14)) {
2394 /* H2C_Parameter[0] = 0x1; */
2395 H2C_Parameter[0] = 0x0;
2396 H2C_Parameter[1] = wifiCentralChnl;
2397 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
2399 if (wifiBw == BTC_WIFI_BW_HT40)
2400 H2C_Parameter[2] = 0x30;
2402 H2C_Parameter[2] = 0x20;
2405 pCoexDm->wifiChnlInfo[0] = H2C_Parameter[0];
2406 pCoexDm->wifiChnlInfo[1] = H2C_Parameter[1];
2407 pCoexDm->wifiChnlInfo[2] = H2C_Parameter[2];
2409 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x66, 3, H2C_Parameter);
2412 void EXhalbtc8723b1ant_SpecialPacketNotify(struct btc_coexist *pBtCoexist, u8 type)
2414 bool bBtHsOn = false;
2415 u32 wifiLinkStatus = 0;
2416 u32 numOfWifiLink = 0;
2417 bool bBtCtrlAggBufSize = false;
2421 pBtCoexist->bManualControl ||
2422 pBtCoexist->bStopCoexDm ||
2423 pBtCoexist->btInfo.bBtDisabled
2428 type == BTC_PACKET_DHCP ||
2429 type == BTC_PACKET_EAPOL ||
2430 type == BTC_PACKET_ARP
2432 if (type == BTC_PACKET_ARP) {
2435 if (pCoexDm->nArpCnt >= 10) /* if APR PKT > 10 after connect, do not go to ActionWifiConnectedSpecialPacket(pBtCoexist) */
2436 pCoexSta->bWiFiIsHighPriTask = false;
2438 pCoexSta->bWiFiIsHighPriTask = true;
2440 pCoexSta->bWiFiIsHighPriTask = true;
2443 pCoexSta->bWiFiIsHighPriTask = false;
2446 pCoexSta->specialPktPeriodCnt = 0;
2448 pBtCoexist->fBtcGet(
2449 pBtCoexist, BTC_GET_U4_WIFI_LINK_STATUS, &wifiLinkStatus
2451 numOfWifiLink = wifiLinkStatus >> 16;
2453 if (numOfWifiLink >= 2) {
2454 halbtc8723b1ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);
2455 halbtc8723b1ant_LimitedRx(
2456 pBtCoexist, NORMAL_EXEC, false, bBtCtrlAggBufSize, aggBufSize
2458 halbtc8723b1ant_ActionWifiMultiPort(pBtCoexist);
2462 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
2463 if (pCoexSta->bC2hBtInquiryPage) {
2464 halbtc8723b1ant_ActionBtInquiry(pBtCoexist);
2466 } else if (bBtHsOn) {
2467 halbtc8723b1ant_ActionHs(pBtCoexist);
2472 type == BTC_PACKET_DHCP ||
2473 type == BTC_PACKET_EAPOL ||
2474 ((type == BTC_PACKET_ARP) && (pCoexSta->bWiFiIsHighPriTask))
2476 halbtc8723b1ant_ActionWifiConnectedSpecialPacket(pBtCoexist);
2479 void EXhalbtc8723b1ant_BtInfoNotify(
2480 struct btc_coexist *pBtCoexist, u8 *tmpBuf, u8 length
2484 u8 i, rspSource = 0;
2485 bool bWifiConnected = false;
2486 bool bBtBusy = false;
2488 pCoexSta->bC2hBtInfoReqSent = false;
2490 rspSource = tmpBuf[0] & 0xf;
2491 if (rspSource >= BT_INFO_SRC_8723B_1ANT_MAX)
2492 rspSource = BT_INFO_SRC_8723B_1ANT_WIFI_FW;
2493 pCoexSta->btInfoC2hCnt[rspSource]++;
2495 for (i = 0; i < length; i++) {
2496 pCoexSta->btInfoC2h[rspSource][i] = tmpBuf[i];
2501 if (rspSource != BT_INFO_SRC_8723B_1ANT_WIFI_FW) {
2502 pCoexSta->btRetryCnt = pCoexSta->btInfoC2h[rspSource][2] & 0xf;
2504 if (pCoexSta->btRetryCnt >= 1)
2505 pCoexSta->popEventCnt++;
2507 if (pCoexSta->btInfoC2h[rspSource][2] & 0x20)
2508 pCoexSta->bC2hBtPage = true;
2510 pCoexSta->bC2hBtPage = false;
2512 pCoexSta->btRssi = pCoexSta->btInfoC2h[rspSource][3] * 2 - 90;
2513 /* pCoexSta->btInfoC2h[rspSource][3]*2+10; */
2515 pCoexSta->btInfoExt = pCoexSta->btInfoC2h[rspSource][4];
2517 pCoexSta->bBtTxRxMask = (pCoexSta->btInfoC2h[rspSource][2] & 0x40);
2518 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TX_RX_MASK, &pCoexSta->bBtTxRxMask);
2520 if (!pCoexSta->bBtTxRxMask) {
2521 /* BT into is responded by BT FW and BT RF REG 0x3C != 0x15 => Need to switch BT TRx Mask */
2522 pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x3c, 0x15);
2525 /* Here we need to resend some wifi info to BT */
2526 /* because bt is reset and loss of the info. */
2527 if (pCoexSta->btInfoExt & BIT1) {
2528 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
2530 EXhalbtc8723b1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_CONNECT);
2532 EXhalbtc8723b1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);
2535 if (pCoexSta->btInfoExt & BIT3) {
2536 if (!pBtCoexist->bManualControl && !pBtCoexist->bStopCoexDm)
2537 halbtc8723b1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, false);
2539 /* BT already NOT ignore Wlan active, do nothing here. */
2543 /* check BIT2 first ==> check if bt is under inquiry or page scan */
2544 if (btInfo & BT_INFO_8723B_1ANT_B_INQ_PAGE)
2545 pCoexSta->bC2hBtInquiryPage = true;
2547 pCoexSta->bC2hBtInquiryPage = false;
2549 /* set link exist status */
2550 if (!(btInfo & BT_INFO_8723B_1ANT_B_CONNECTION)) {
2551 pCoexSta->bBtLinkExist = false;
2552 pCoexSta->bPanExist = false;
2553 pCoexSta->bA2dpExist = false;
2554 pCoexSta->bHidExist = false;
2555 pCoexSta->bScoExist = false;
2556 } else { /* connection exists */
2557 pCoexSta->bBtLinkExist = true;
2558 if (btInfo & BT_INFO_8723B_1ANT_B_FTP)
2559 pCoexSta->bPanExist = true;
2561 pCoexSta->bPanExist = false;
2563 if (btInfo & BT_INFO_8723B_1ANT_B_A2DP)
2564 pCoexSta->bA2dpExist = true;
2566 pCoexSta->bA2dpExist = false;
2568 if (btInfo & BT_INFO_8723B_1ANT_B_HID)
2569 pCoexSta->bHidExist = true;
2571 pCoexSta->bHidExist = false;
2573 if (btInfo & BT_INFO_8723B_1ANT_B_SCO_ESCO)
2574 pCoexSta->bScoExist = true;
2576 pCoexSta->bScoExist = false;
2579 halbtc8723b1ant_UpdateBtLinkInfo(pBtCoexist);
2581 btInfo = btInfo & 0x1f; /* mask profile bit for connect-ilde identification (for CSR case: A2DP idle --> 0x41) */
2583 if (!(btInfo & BT_INFO_8723B_1ANT_B_CONNECTION)) {
2584 pCoexDm->btStatus = BT_8723B_1ANT_BT_STATUS_NON_CONNECTED_IDLE;
2585 } else if (btInfo == BT_INFO_8723B_1ANT_B_CONNECTION) {
2586 /* connection exists but no busy */
2587 pCoexDm->btStatus = BT_8723B_1ANT_BT_STATUS_CONNECTED_IDLE;
2589 (btInfo & BT_INFO_8723B_1ANT_B_SCO_ESCO) ||
2590 (btInfo & BT_INFO_8723B_1ANT_B_SCO_BUSY)
2592 pCoexDm->btStatus = BT_8723B_1ANT_BT_STATUS_SCO_BUSY;
2593 } else if (btInfo & BT_INFO_8723B_1ANT_B_ACL_BUSY) {
2594 if (pCoexDm->btStatus != BT_8723B_1ANT_BT_STATUS_ACL_BUSY)
2595 pCoexDm->bAutoTdmaAdjust = false;
2597 pCoexDm->btStatus = BT_8723B_1ANT_BT_STATUS_ACL_BUSY;
2599 pCoexDm->btStatus = BT_8723B_1ANT_BT_STATUS_MAX;
2603 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_BUSY) ||
2604 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_SCO_BUSY) ||
2605 (pCoexDm->btStatus == BT_8723B_1ANT_BT_STATUS_ACL_SCO_BUSY)
2610 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);
2612 halbtc8723b1ant_RunCoexistMechanism(pBtCoexist);
2615 void EXhalbtc8723b1ant_HaltNotify(struct btc_coexist *pBtCoexist)
2617 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2618 halbtc8723b1ant_PsTdma(pBtCoexist, FORCE_EXEC, false, 0);
2619 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, false, true);
2621 halbtc8723b1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, true);
2623 EXhalbtc8723b1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);
2625 pBtCoexist->bStopCoexDm = true;
2628 void EXhalbtc8723b1ant_PnpNotify(struct btc_coexist *pBtCoexist, u8 pnpState)
2630 if (pnpState == BTC_WIFI_PNP_SLEEP) {
2631 halbtc8723b1ant_PowerSaveState(pBtCoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0);
2632 halbtc8723b1ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 0);
2633 halbtc8723b1ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
2634 halbtc8723b1ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, false, true);
2636 pBtCoexist->bStopCoexDm = true;
2637 } else if (pnpState == BTC_WIFI_PNP_WAKE_UP) {
2638 pBtCoexist->bStopCoexDm = false;
2639 halbtc8723b1ant_InitHwConfig(pBtCoexist, false, false);
2640 halbtc8723b1ant_InitCoexDm(pBtCoexist);
2641 halbtc8723b1ant_QueryBtInfo(pBtCoexist);
2645 void EXhalbtc8723b1ant_Periodical(struct btc_coexist *pBtCoexist)
2647 static u8 disVerInfoCnt;
2648 u32 fwVer = 0, btPatchVer = 0;
2650 if (disVerInfoCnt <= 5) {
2652 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);
2653 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);
2656 halbtc8723b1ant_MonitorBtCtr(pBtCoexist);
2657 halbtc8723b1ant_MonitorWiFiCtr(pBtCoexist);
2660 halbtc8723b1ant_IsWifiStatusChanged(pBtCoexist) ||
2661 pCoexDm->bAutoTdmaAdjust
2663 halbtc8723b1ant_RunCoexistMechanism(pBtCoexist);
2665 pCoexSta->specialPktPeriodCnt++;