1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
4 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
6 ******************************************************************************/
8 #include "Mp_Precomp.h"
11 #define HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(val) \
13 halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, val); \
14 pCoexDm->psTdmaDuAdjType = val; \
17 /* Global variables, these are static variables */
18 static COEX_DM_8723B_2ANT GLCoexDm8723b2Ant;
19 static PCOEX_DM_8723B_2ANT pCoexDm = &GLCoexDm8723b2Ant;
20 static COEX_STA_8723B_2ANT GLCoexSta8723b2Ant;
21 static PCOEX_STA_8723B_2ANT pCoexSta = &GLCoexSta8723b2Ant;
23 static const char *const GLBtInfoSrc8723b2Ant[] = {
26 "BT Info[bt auto report]",
29 static u32 GLCoexVerDate8723b2Ant = 20131211;
30 static u32 GLCoexVer8723b2Ant = 0x40;
32 /* local function start with halbtc8723b2ant_ */
33 static u8 halbtc8723b2ant_BtRssiState(
34 u8 levelNum, u8 rssiThresh, u8 rssiThresh1
38 u8 btRssiState = pCoexSta->preBtRssiState;
40 btRssi = pCoexSta->btRssi;
44 (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||
45 (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW)
47 if (btRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT)) {
48 btRssiState = BTC_RSSI_STATE_HIGH;
49 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to High\n"));
51 btRssiState = BTC_RSSI_STATE_STAY_LOW;
52 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at Low\n"));
55 if (btRssi < rssiThresh) {
56 btRssiState = BTC_RSSI_STATE_LOW;
57 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Low\n"));
59 btRssiState = BTC_RSSI_STATE_STAY_HIGH;
60 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at High\n"));
63 } else if (levelNum == 3) {
64 if (rssiThresh > rssiThresh1) {
65 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi thresh error!!\n"));
66 return pCoexSta->preBtRssiState;
70 (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||
71 (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW)
73 if (btRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT)) {
74 btRssiState = BTC_RSSI_STATE_MEDIUM;
75 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Medium\n"));
77 btRssiState = BTC_RSSI_STATE_STAY_LOW;
78 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at Low\n"));
81 (pCoexSta->preBtRssiState == BTC_RSSI_STATE_MEDIUM) ||
82 (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_MEDIUM)
84 if (btRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT)) {
85 btRssiState = BTC_RSSI_STATE_HIGH;
86 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to High\n"));
87 } else if (btRssi < rssiThresh) {
88 btRssiState = BTC_RSSI_STATE_LOW;
89 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Low\n"));
91 btRssiState = BTC_RSSI_STATE_STAY_MEDIUM;
92 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at Medium\n"));
95 if (btRssi < rssiThresh1) {
96 btRssiState = BTC_RSSI_STATE_MEDIUM;
97 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Medium\n"));
99 btRssiState = BTC_RSSI_STATE_STAY_HIGH;
100 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at High\n"));
105 pCoexSta->preBtRssiState = btRssiState;
110 static u8 halbtc8723b2ant_WifiRssiState(
111 PBTC_COEXIST pBtCoexist,
119 u8 wifiRssiState = pCoexSta->preWifiRssiState[index];
121 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);
125 (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||
126 (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW)
128 if (wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT)) {
129 wifiRssiState = BTC_RSSI_STATE_HIGH;
130 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to High\n"));
132 wifiRssiState = BTC_RSSI_STATE_STAY_LOW;
133 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at Low\n"));
136 if (wifiRssi < rssiThresh) {
137 wifiRssiState = BTC_RSSI_STATE_LOW;
138 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to Low\n"));
140 wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;
141 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at High\n"));
144 } else if (levelNum == 3) {
145 if (rssiThresh > rssiThresh1) {
146 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI thresh error!!\n"));
147 return pCoexSta->preWifiRssiState[index];
151 (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||
152 (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW)
154 if (wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT)) {
155 wifiRssiState = BTC_RSSI_STATE_MEDIUM;
156 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to Medium\n"));
158 wifiRssiState = BTC_RSSI_STATE_STAY_LOW;
159 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at Low\n"));
162 (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_MEDIUM) ||
163 (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_MEDIUM)
165 if (wifiRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT)) {
166 wifiRssiState = BTC_RSSI_STATE_HIGH;
167 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to High\n"));
168 } else if (wifiRssi < rssiThresh) {
169 wifiRssiState = BTC_RSSI_STATE_LOW;
170 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to Low\n"));
172 wifiRssiState = BTC_RSSI_STATE_STAY_MEDIUM;
173 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at Medium\n"));
176 if (wifiRssi < rssiThresh1) {
177 wifiRssiState = BTC_RSSI_STATE_MEDIUM;
178 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to Medium\n"));
180 wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;
181 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at High\n"));
186 pCoexSta->preWifiRssiState[index] = wifiRssiState;
188 return wifiRssiState;
191 static void halbtc8723b2ant_LimitedRx(
192 PBTC_COEXIST pBtCoexist,
195 bool bBtCtrlAggBufSize,
199 bool bRejectRxAgg = bRejApAggPkt;
200 bool bBtCtrlRxAggSize = bBtCtrlAggBufSize;
201 u8 rxAggSize = aggBufSize;
204 /* Rx Aggregation related setting */
206 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, &bRejectRxAgg);
207 /* decide BT control aggregation buf size or not */
208 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, &bBtCtrlRxAggSize);
209 /* aggregation buf size, only work when BT control Rx aggregation size. */
210 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_AGG_BUF_SIZE, &rxAggSize);
211 /* real update aggregation setting */
212 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);
215 static void halbtc8723b2ant_MonitorBtCtr(PBTC_COEXIST pBtCoexist)
217 u32 regHPTxRx, regLPTxRx, u4Tmp;
218 u32 regHPTx = 0, regHPRx = 0, regLPTx = 0, regLPRx = 0;
223 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regHPTxRx);
224 regHPTx = u4Tmp & bMaskLWord;
225 regHPRx = (u4Tmp & bMaskHWord)>>16;
227 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regLPTxRx);
228 regLPTx = u4Tmp & bMaskLWord;
229 regLPRx = (u4Tmp & bMaskHWord)>>16;
231 pCoexSta->highPriorityTx = regHPTx;
232 pCoexSta->highPriorityRx = regHPRx;
233 pCoexSta->lowPriorityTx = regLPTx;
234 pCoexSta->lowPriorityRx = regLPRx;
240 "[BTCoex], High Priority Tx/Rx (reg 0x%x) = 0x%x(%d)/0x%x(%d)\n",
252 "[BTCoex], Low Priority Tx/Rx (reg 0x%x) = 0x%x(%d)/0x%x(%d)\n",
262 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc);
265 static void halbtc8723b2ant_QueryBtInfo(PBTC_COEXIST pBtCoexist)
267 u8 H2C_Parameter[1] = {0};
269 pCoexSta->bC2hBtInfoReqSent = true;
271 H2C_Parameter[0] |= BIT0; /* trigger */
276 ("[BTCoex], Query Bt Info, FW write 0x61 = 0x%x\n", H2C_Parameter[0])
279 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x61, 1, H2C_Parameter);
282 static bool halbtc8723b2ant_IsWifiStatusChanged(PBTC_COEXIST pBtCoexist)
284 static bool bPreWifiBusy, bPreUnder4way, bPreBtHsOn;
285 bool bWifiBusy = false, bUnder4way = false, bBtHsOn = false;
286 bool bWifiConnected = false;
288 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
289 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
290 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
291 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way);
293 if (bWifiConnected) {
294 if (bWifiBusy != bPreWifiBusy) {
295 bPreWifiBusy = bWifiBusy;
299 if (bUnder4way != bPreUnder4way) {
300 bPreUnder4way = bUnder4way;
304 if (bBtHsOn != bPreBtHsOn) {
305 bPreBtHsOn = bBtHsOn;
313 static void halbtc8723b2ant_UpdateBtLinkInfo(PBTC_COEXIST pBtCoexist)
315 PBTC_BT_LINK_INFO pBtLinkInfo = &pBtCoexist->btLinkInfo;
316 bool bBtHsOn = false;
318 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
320 pBtLinkInfo->bBtLinkExist = pCoexSta->bBtLinkExist;
321 pBtLinkInfo->bScoExist = pCoexSta->bScoExist;
322 pBtLinkInfo->bA2dpExist = pCoexSta->bA2dpExist;
323 pBtLinkInfo->bPanExist = pCoexSta->bPanExist;
324 pBtLinkInfo->bHidExist = pCoexSta->bHidExist;
326 /* work around for HS mode. */
328 pBtLinkInfo->bPanExist = true;
329 pBtLinkInfo->bBtLinkExist = true;
332 /* check if Sco only */
334 pBtLinkInfo->bScoExist &&
335 !pBtLinkInfo->bA2dpExist &&
336 !pBtLinkInfo->bPanExist &&
337 !pBtLinkInfo->bHidExist
339 pBtLinkInfo->bScoOnly = true;
341 pBtLinkInfo->bScoOnly = false;
343 /* check if A2dp only */
345 !pBtLinkInfo->bScoExist &&
346 pBtLinkInfo->bA2dpExist &&
347 !pBtLinkInfo->bPanExist &&
348 !pBtLinkInfo->bHidExist
350 pBtLinkInfo->bA2dpOnly = true;
352 pBtLinkInfo->bA2dpOnly = false;
354 /* check if Pan only */
356 !pBtLinkInfo->bScoExist &&
357 !pBtLinkInfo->bA2dpExist &&
358 pBtLinkInfo->bPanExist &&
359 !pBtLinkInfo->bHidExist
361 pBtLinkInfo->bPanOnly = true;
363 pBtLinkInfo->bPanOnly = false;
365 /* check if Hid only */
367 !pBtLinkInfo->bScoExist &&
368 !pBtLinkInfo->bA2dpExist &&
369 !pBtLinkInfo->bPanExist &&
370 pBtLinkInfo->bHidExist
372 pBtLinkInfo->bHidOnly = true;
374 pBtLinkInfo->bHidOnly = false;
377 static u8 halbtc8723b2ant_ActionAlgorithm(PBTC_COEXIST pBtCoexist)
379 PBTC_BT_LINK_INFO pBtLinkInfo = &pBtCoexist->btLinkInfo;
380 bool bBtHsOn = false;
381 u8 algorithm = BT_8723B_2ANT_COEX_ALGO_UNDEFINED;
382 u8 numOfDiffProfile = 0;
384 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
386 if (!pBtLinkInfo->bBtLinkExist) {
387 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], No BT link exists!!!\n"));
391 if (pBtLinkInfo->bScoExist)
394 if (pBtLinkInfo->bHidExist)
397 if (pBtLinkInfo->bPanExist)
400 if (pBtLinkInfo->bA2dpExist)
403 if (numOfDiffProfile == 1) {
404 if (pBtLinkInfo->bScoExist) {
405 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO only\n"));
406 algorithm = BT_8723B_2ANT_COEX_ALGO_SCO;
408 if (pBtLinkInfo->bHidExist) {
409 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID only\n"));
410 algorithm = BT_8723B_2ANT_COEX_ALGO_HID;
411 } else if (pBtLinkInfo->bA2dpExist) {
412 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], A2DP only\n"));
413 algorithm = BT_8723B_2ANT_COEX_ALGO_A2DP;
414 } else if (pBtLinkInfo->bPanExist) {
416 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], PAN(HS) only\n"));
417 algorithm = BT_8723B_2ANT_COEX_ALGO_PANHS;
419 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], PAN(EDR) only\n"));
420 algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR;
424 } else if (numOfDiffProfile == 2) {
425 if (pBtLinkInfo->bScoExist) {
426 if (pBtLinkInfo->bHidExist) {
427 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + HID\n"));
428 algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
429 } else if (pBtLinkInfo->bA2dpExist) {
430 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + A2DP ==> SCO\n"));
431 algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
432 } else if (pBtLinkInfo->bPanExist) {
434 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + PAN(HS)\n"));
435 algorithm = BT_8723B_2ANT_COEX_ALGO_SCO;
437 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + PAN(EDR)\n"));
438 algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
443 pBtLinkInfo->bHidExist &&
444 pBtLinkInfo->bA2dpExist
446 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + A2DP\n"));
447 algorithm = BT_8723B_2ANT_COEX_ALGO_HID_A2DP;
449 pBtLinkInfo->bHidExist &&
450 pBtLinkInfo->bPanExist
453 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + PAN(HS)\n"));
454 algorithm = BT_8723B_2ANT_COEX_ALGO_HID;
456 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + PAN(EDR)\n"));
457 algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
460 pBtLinkInfo->bPanExist &&
461 pBtLinkInfo->bA2dpExist
464 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], A2DP + PAN(HS)\n"));
465 algorithm = BT_8723B_2ANT_COEX_ALGO_A2DP_PANHS;
467 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], A2DP + PAN(EDR)\n"));
468 algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_A2DP;
472 } else if (numOfDiffProfile == 3) {
473 if (pBtLinkInfo->bScoExist) {
475 pBtLinkInfo->bHidExist &&
476 pBtLinkInfo->bA2dpExist
481 ("[BTCoex], SCO + HID + A2DP ==> HID\n")
483 algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
485 pBtLinkInfo->bHidExist &&
486 pBtLinkInfo->bPanExist
492 ("[BTCoex], SCO + HID + PAN(HS)\n")
494 algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
499 ("[BTCoex], SCO + HID + PAN(EDR)\n")
501 algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
504 pBtLinkInfo->bPanExist &&
505 pBtLinkInfo->bA2dpExist
508 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + A2DP + PAN(HS)\n"));
509 algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
511 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + A2DP + PAN(EDR) ==> HID\n"));
512 algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
517 pBtLinkInfo->bHidExist &&
518 pBtLinkInfo->bPanExist &&
519 pBtLinkInfo->bA2dpExist
522 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + A2DP + PAN(HS)\n"));
523 algorithm = BT_8723B_2ANT_COEX_ALGO_HID_A2DP;
525 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + A2DP + PAN(EDR)\n"));
526 algorithm = BT_8723B_2ANT_COEX_ALGO_HID_A2DP_PANEDR;
530 } else if (numOfDiffProfile >= 3) {
531 if (pBtLinkInfo->bScoExist) {
533 pBtLinkInfo->bHidExist &&
534 pBtLinkInfo->bPanExist &&
535 pBtLinkInfo->bA2dpExist
538 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n"));
541 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + HID + A2DP + PAN(EDR) ==>PAN(EDR)+HID\n"));
542 algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID;
551 static void halbtc8723b2ant_SetFwDacSwingLevel(
552 PBTC_COEXIST pBtCoexist, u8 dacSwingLvl
555 u8 H2C_Parameter[1] = {0};
557 /* There are several type of dacswing */
558 /* 0x18/ 0x10/ 0xc/ 0x8/ 0x4/ 0x6 */
559 H2C_Parameter[0] = dacSwingLvl;
564 ("[BTCoex], Set Dac Swing Level = 0x%x\n", dacSwingLvl)
569 ("[BTCoex], FW write 0x64 = 0x%x\n", H2C_Parameter[0])
572 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x64, 1, H2C_Parameter);
575 static void halbtc8723b2ant_SetFwDecBtPwr(
576 PBTC_COEXIST pBtCoexist, u8 decBtPwrLvl
579 u8 H2C_Parameter[1] = {0};
581 H2C_Parameter[0] = decBtPwrLvl;
587 "[BTCoex], decrease Bt Power level = %d, FW write 0x62 = 0x%x\n",
593 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x62, 1, H2C_Parameter);
596 static void halbtc8723b2ant_DecBtPwr(
597 PBTC_COEXIST pBtCoexist, bool bForceExec, u8 decBtPwrLvl
604 "[BTCoex], %s Dec BT power level = %d\n",
605 (bForceExec ? "force to" : ""),
609 pCoexDm->curBtDecPwrLvl = decBtPwrLvl;
614 ALGO_TRACE_FW_DETAIL,
616 "[BTCoex], preBtDecPwrLvl =%d, curBtDecPwrLvl =%d\n",
617 pCoexDm->preBtDecPwrLvl,
618 pCoexDm->curBtDecPwrLvl
622 if (pCoexDm->preBtDecPwrLvl == pCoexDm->curBtDecPwrLvl)
625 halbtc8723b2ant_SetFwDecBtPwr(pBtCoexist, pCoexDm->curBtDecPwrLvl);
627 pCoexDm->preBtDecPwrLvl = pCoexDm->curBtDecPwrLvl;
630 static void halbtc8723b2ant_FwDacSwingLvl(
631 PBTC_COEXIST pBtCoexist, bool bForceExec, u8 fwDacSwingLvl
638 "[BTCoex], %s set FW Dac Swing level = %d\n",
639 (bForceExec ? "force to" : ""),
643 pCoexDm->curFwDacSwingLvl = fwDacSwingLvl;
648 ALGO_TRACE_FW_DETAIL,
650 "[BTCoex], preFwDacSwingLvl =%d, curFwDacSwingLvl =%d\n",
651 pCoexDm->preFwDacSwingLvl,
652 pCoexDm->curFwDacSwingLvl
656 if (pCoexDm->preFwDacSwingLvl == pCoexDm->curFwDacSwingLvl)
660 halbtc8723b2ant_SetFwDacSwingLevel(pBtCoexist, pCoexDm->curFwDacSwingLvl);
662 pCoexDm->preFwDacSwingLvl = pCoexDm->curFwDacSwingLvl;
665 static void halbtc8723b2ant_SetSwRfRxLpfCorner(
666 PBTC_COEXIST pBtCoexist,
671 /* Shrink RF Rx LPF corner */
675 ("[BTCoex], Shrink RF Rx LPF corner!!\n")
677 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff, 0xffffc);
679 /* Resume RF Rx LPF corner */
680 /* After initialized, we can use pCoexDm->btRf0x1eBackup */
681 if (pBtCoexist->bInitilized) {
682 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Resume RF Rx LPF corner!!\n"));
683 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff, pCoexDm->btRf0x1eBackup);
688 static void halbtc8723b2ant_RfShrink(
689 PBTC_COEXIST pBtCoexist, bool bForceExec, bool bRxRfShrinkOn
696 "[BTCoex], %s turn Rx RF Shrink = %s\n",
697 (bForceExec ? "force to" : ""),
698 (bRxRfShrinkOn ? "ON" : "OFF")
701 pCoexDm->bCurRfRxLpfShrink = bRxRfShrinkOn;
706 ALGO_TRACE_SW_DETAIL,
708 "[BTCoex], bPreRfRxLpfShrink =%d, bCurRfRxLpfShrink =%d\n",
709 pCoexDm->bPreRfRxLpfShrink,
710 pCoexDm->bCurRfRxLpfShrink
714 if (pCoexDm->bPreRfRxLpfShrink == pCoexDm->bCurRfRxLpfShrink)
717 halbtc8723b2ant_SetSwRfRxLpfCorner(pBtCoexist, pCoexDm->bCurRfRxLpfShrink);
719 pCoexDm->bPreRfRxLpfShrink = pCoexDm->bCurRfRxLpfShrink;
722 static void halbtc8723b2ant_SetSwPenaltyTxRateAdaptive(
723 PBTC_COEXIST pBtCoexist, bool bLowPenaltyRa
726 u8 H2C_Parameter[6] = {0};
728 H2C_Parameter[0] = 0x6; /* opCode, 0x6 = Retry_Penalty */
731 H2C_Parameter[1] |= BIT0;
732 H2C_Parameter[2] = 0x00; /* normal rate except MCS7/6/5, OFDM54/48/36 */
733 H2C_Parameter[3] = 0xf7; /* MCS7 or OFDM54 */
734 H2C_Parameter[4] = 0xf8; /* MCS6 or OFDM48 */
735 H2C_Parameter[5] = 0xf9; /* MCS5 or OFDM36 */
742 "[BTCoex], set WiFi Low-Penalty Retry: %s",
743 (bLowPenaltyRa ? "ON!!" : "OFF!!")
747 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x69, 6, H2C_Parameter);
750 static void halbtc8723b2ant_LowPenaltyRa(
751 PBTC_COEXIST pBtCoexist, bool bForceExec, bool bLowPenaltyRa
759 "[BTCoex], %s turn LowPenaltyRA = %s\n",
760 (bForceExec ? "force to" : ""),
761 (bLowPenaltyRa ? "ON" : "OFF")
764 pCoexDm->bCurLowPenaltyRa = bLowPenaltyRa;
769 ALGO_TRACE_SW_DETAIL,
771 "[BTCoex], bPreLowPenaltyRa =%d, bCurLowPenaltyRa =%d\n",
772 pCoexDm->bPreLowPenaltyRa,
773 pCoexDm->bCurLowPenaltyRa
777 if (pCoexDm->bPreLowPenaltyRa == pCoexDm->bCurLowPenaltyRa)
780 halbtc8723b2ant_SetSwPenaltyTxRateAdaptive(pBtCoexist, pCoexDm->bCurLowPenaltyRa);
782 pCoexDm->bPreLowPenaltyRa = pCoexDm->bCurLowPenaltyRa;
785 static void halbtc8723b2ant_SetDacSwingReg(PBTC_COEXIST pBtCoexist, u32 level)
792 ("[BTCoex], Write SwDacSwing = 0x%x\n", level)
794 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x883, 0x3e, val);
797 static void halbtc8723b2ant_SetSwFullTimeDacSwing(
798 PBTC_COEXIST pBtCoexist, bool bSwDacSwingOn, u32 swDacSwingLvl
802 halbtc8723b2ant_SetDacSwingReg(pBtCoexist, swDacSwingLvl);
804 halbtc8723b2ant_SetDacSwingReg(pBtCoexist, 0x18);
808 static void halbtc8723b2ant_DacSwing(
809 PBTC_COEXIST pBtCoexist,
819 "[BTCoex], %s turn DacSwing =%s, dacSwingLvl = 0x%x\n",
820 (bForceExec ? "force to" : ""),
821 (bDacSwingOn ? "ON" : "OFF"),
825 pCoexDm->bCurDacSwingOn = bDacSwingOn;
826 pCoexDm->curDacSwingLvl = dacSwingLvl;
831 ALGO_TRACE_SW_DETAIL,
833 "[BTCoex], bPreDacSwingOn =%d, preDacSwingLvl = 0x%x, bCurDacSwingOn =%d, curDacSwingLvl = 0x%x\n",
834 pCoexDm->bPreDacSwingOn,
835 pCoexDm->preDacSwingLvl,
836 pCoexDm->bCurDacSwingOn,
837 pCoexDm->curDacSwingLvl
841 if ((pCoexDm->bPreDacSwingOn == pCoexDm->bCurDacSwingOn) &&
842 (pCoexDm->preDacSwingLvl == pCoexDm->curDacSwingLvl))
846 halbtc8723b2ant_SetSwFullTimeDacSwing(pBtCoexist, bDacSwingOn, dacSwingLvl);
848 pCoexDm->bPreDacSwingOn = pCoexDm->bCurDacSwingOn;
849 pCoexDm->preDacSwingLvl = pCoexDm->curDacSwingLvl;
852 static void halbtc8723b2ant_SetAgcTable(
853 PBTC_COEXIST pBtCoexist, bool bAgcTableEn
856 u8 rssiAdjustVal = 0;
858 /* BB AGC Gain Table */
860 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], BB Agc Table On!\n"));
861 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x6e1A0001);
862 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x6d1B0001);
863 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x6c1C0001);
864 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x6b1D0001);
865 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x6a1E0001);
866 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x691F0001);
867 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x68200001);
869 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], BB Agc Table Off!\n"));
870 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xaa1A0001);
871 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa91B0001);
872 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa81C0001);
873 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa71D0001);
874 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa61E0001);
875 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa51F0001);
876 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa4200001);
881 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xef, 0xfffff, 0x02000);
883 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Agc Table On!\n"));
884 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x3b, 0xfffff, 0x38fff);
885 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x3b, 0xfffff, 0x38ffe);
887 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Agc Table Off!\n"));
888 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x3b, 0xfffff, 0x380c3);
889 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x3b, 0xfffff, 0x28ce6);
891 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xef, 0xfffff, 0x0);
893 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xed, 0xfffff, 0x1);
895 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Agc Table On!\n"));
896 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x40, 0xfffff, 0x38fff);
897 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x40, 0xfffff, 0x38ffe);
899 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Agc Table Off!\n"));
900 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x40, 0xfffff, 0x380c3);
901 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x40, 0xfffff, 0x28ce6);
903 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xed, 0xfffff, 0x0);
905 /* set rssiAdjustVal for wifi module. */
909 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON, &rssiAdjustVal);
912 static void halbtc8723b2ant_AgcTable(
913 PBTC_COEXIST pBtCoexist, bool bForceExec, bool bAgcTableEn
920 "[BTCoex], %s %s Agc Table\n",
921 (bForceExec ? "force to" : ""),
922 (bAgcTableEn ? "Enable" : "Disable")
925 pCoexDm->bCurAgcTableEn = bAgcTableEn;
930 ALGO_TRACE_SW_DETAIL,
932 "[BTCoex], bPreAgcTableEn =%d, bCurAgcTableEn =%d\n",
933 pCoexDm->bPreAgcTableEn,
934 pCoexDm->bCurAgcTableEn
938 if (pCoexDm->bPreAgcTableEn == pCoexDm->bCurAgcTableEn)
941 halbtc8723b2ant_SetAgcTable(pBtCoexist, bAgcTableEn);
943 pCoexDm->bPreAgcTableEn = pCoexDm->bCurAgcTableEn;
946 static void halbtc8723b2ant_SetCoexTable(
947 PBTC_COEXIST pBtCoexist,
957 ("[BTCoex], set coex table, set 0x6c0 = 0x%x\n", val0x6c0)
959 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c0, val0x6c0);
964 ("[BTCoex], set coex table, set 0x6c4 = 0x%x\n", val0x6c4)
966 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c4, val0x6c4);
971 ("[BTCoex], set coex table, set 0x6c8 = 0x%x\n", val0x6c8)
973 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c8, val0x6c8);
978 ("[BTCoex], set coex table, set 0x6cc = 0x%x\n", val0x6cc)
980 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cc, val0x6cc);
983 static void halbtc8723b2ant_CoexTable(
984 PBTC_COEXIST pBtCoexist,
996 "[BTCoex], %s write Coex Table 0x6c0 = 0x%x, 0x6c4 = 0x%x, 0x6c8 = 0x%x, 0x6cc = 0x%x\n",
997 (bForceExec ? "force to" : ""),
1004 pCoexDm->curVal0x6c0 = val0x6c0;
1005 pCoexDm->curVal0x6c4 = val0x6c4;
1006 pCoexDm->curVal0x6c8 = val0x6c8;
1007 pCoexDm->curVal0x6cc = val0x6cc;
1012 ALGO_TRACE_SW_DETAIL,
1014 "[BTCoex], preVal0x6c0 = 0x%x, preVal0x6c4 = 0x%x, preVal0x6c8 = 0x%x, preVal0x6cc = 0x%x !!\n",
1015 pCoexDm->preVal0x6c0,
1016 pCoexDm->preVal0x6c4,
1017 pCoexDm->preVal0x6c8,
1018 pCoexDm->preVal0x6cc
1023 ALGO_TRACE_SW_DETAIL,
1025 "[BTCoex], curVal0x6c0 = 0x%x, curVal0x6c4 = 0x%x, curVal0x6c8 = 0x%x, curVal0x6cc = 0x%x !!\n",
1026 pCoexDm->curVal0x6c0,
1027 pCoexDm->curVal0x6c4,
1028 pCoexDm->curVal0x6c8,
1029 pCoexDm->curVal0x6cc
1034 (pCoexDm->preVal0x6c0 == pCoexDm->curVal0x6c0) &&
1035 (pCoexDm->preVal0x6c4 == pCoexDm->curVal0x6c4) &&
1036 (pCoexDm->preVal0x6c8 == pCoexDm->curVal0x6c8) &&
1037 (pCoexDm->preVal0x6cc == pCoexDm->curVal0x6cc)
1041 halbtc8723b2ant_SetCoexTable(pBtCoexist, val0x6c0, val0x6c4, val0x6c8, val0x6cc);
1043 pCoexDm->preVal0x6c0 = pCoexDm->curVal0x6c0;
1044 pCoexDm->preVal0x6c4 = pCoexDm->curVal0x6c4;
1045 pCoexDm->preVal0x6c8 = pCoexDm->curVal0x6c8;
1046 pCoexDm->preVal0x6cc = pCoexDm->curVal0x6cc;
1049 static void halbtc8723b2ant_CoexTableWithType(
1050 PBTC_COEXIST pBtCoexist, bool bForceExec, u8 type
1055 halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x55555555, 0xffff, 0x3);
1058 halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x5afa5afa, 0xffff, 0x3);
1061 halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x5a5a5a5a, 0x5a5a5a5a, 0xffff, 0x3);
1064 halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0xaaaaaaaa, 0xaaaaaaaa, 0xffff, 0x3);
1067 halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0xffffffff, 0xffffffff, 0xffff, 0x3);
1070 halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x5fff5fff, 0x5fff5fff, 0xffff, 0x3);
1073 halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x55ff55ff, 0x5a5a5a5a, 0xffff, 0x3);
1076 halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x55ff55ff, 0xfafafafa, 0xffff, 0x3);
1079 halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x5aea5aea, 0x5aea5aea, 0xffff, 0x3);
1082 halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x55ff55ff, 0x5aea5aea, 0xffff, 0x3);
1085 halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x55ff55ff, 0x5aff5aff, 0xffff, 0x3);
1088 halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x55ff55ff, 0x5a5f5a5f, 0xffff, 0x3);
1091 halbtc8723b2ant_CoexTable(pBtCoexist, bForceExec, 0x55ff55ff, 0x5f5f5f5f, 0xffff, 0x3);
1098 static void halbtc8723b2ant_SetFwIgnoreWlanAct(
1099 PBTC_COEXIST pBtCoexist, bool bEnable
1102 u8 H2C_Parameter[1] = {0};
1105 H2C_Parameter[0] |= BIT0; /* function enable */
1111 "[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63 = 0x%x\n",
1116 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x63, 1, H2C_Parameter);
1119 static void halbtc8723b2ant_IgnoreWlanAct(
1120 PBTC_COEXIST pBtCoexist, bool bForceExec, bool bEnable
1127 "[BTCoex], %s turn Ignore WlanAct %s\n",
1128 (bForceExec ? "force to" : ""),
1129 (bEnable ? "ON" : "OFF")
1133 pCoexDm->bCurIgnoreWlanAct = bEnable;
1136 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], bPreIgnoreWlanAct = %d, bCurIgnoreWlanAct = %d!!\n",
1137 pCoexDm->bPreIgnoreWlanAct, pCoexDm->bCurIgnoreWlanAct));
1139 if (pCoexDm->bPreIgnoreWlanAct == pCoexDm->bCurIgnoreWlanAct)
1142 halbtc8723b2ant_SetFwIgnoreWlanAct(pBtCoexist, bEnable);
1144 pCoexDm->bPreIgnoreWlanAct = pCoexDm->bCurIgnoreWlanAct;
1147 static void halbtc8723b2ant_SetFwPstdma(
1148 PBTC_COEXIST pBtCoexist,
1156 u8 H2C_Parameter[5] = {0};
1158 H2C_Parameter[0] = byte1;
1159 H2C_Parameter[1] = byte2;
1160 H2C_Parameter[2] = byte3;
1161 H2C_Parameter[3] = byte4;
1162 H2C_Parameter[4] = byte5;
1164 pCoexDm->psTdmaPara[0] = byte1;
1165 pCoexDm->psTdmaPara[1] = byte2;
1166 pCoexDm->psTdmaPara[2] = byte3;
1167 pCoexDm->psTdmaPara[3] = byte4;
1168 pCoexDm->psTdmaPara[4] = byte5;
1174 "[BTCoex], FW write 0x60(5bytes) = 0x%x%08x\n",
1176 H2C_Parameter[1]<<24|
1177 H2C_Parameter[2]<<16|
1178 H2C_Parameter[3]<<8|
1183 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x60, 5, H2C_Parameter);
1186 static void halbtc8723b2ant_SwMechanism1(
1187 PBTC_COEXIST pBtCoexist,
1191 bool bBTLNAConstrain
1194 halbtc8723b2ant_RfShrink(pBtCoexist, NORMAL_EXEC, bShrinkRxLPF);
1195 halbtc8723b2ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, bLowPenaltyRA);
1198 static void halbtc8723b2ant_SwMechanism2(
1199 PBTC_COEXIST pBtCoexist,
1200 bool bAGCTableShift,
1206 halbtc8723b2ant_AgcTable(pBtCoexist, NORMAL_EXEC, bAGCTableShift);
1207 halbtc8723b2ant_DacSwing(pBtCoexist, NORMAL_EXEC, bSWDACSwing, dacSwingLvl);
1210 static void halbtc8723b2ant_SetAntPath(
1211 PBTC_COEXIST pBtCoexist, u8 antPosType, bool bInitHwCfg, bool bWifiOff
1214 PBTC_BOARD_INFO pBoardInfo = &pBtCoexist->boardInfo;
1215 u32 fwVer = 0, u4Tmp = 0;
1216 bool bPgExtSwitch = false;
1217 bool bUseExtSwitch = false;
1218 u8 H2C_Parameter[2] = {0};
1220 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_EXT_SWITCH, &bPgExtSwitch);
1221 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer); /* [31:16]=fw ver, [15:0]=fw sub ver */
1223 if ((fwVer > 0 && fwVer < 0xc0000) || bPgExtSwitch)
1224 bUseExtSwitch = true;
1227 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x39, 0x8, 0x1);
1228 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x974, 0xff);
1229 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x944, 0x3, 0x3);
1230 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x930, 0x77);
1231 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x1);
1233 if (fwVer >= 0x180000) {
1234 /* Use H2C to set GNT_BT to LOW */
1235 H2C_Parameter[0] = 0;
1236 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x6E, 1, H2C_Parameter);
1238 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x0);
1241 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);
1243 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); /* WiFi TRx Mask off */
1244 pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x3c, 0x01); /* BT TRx Mask off */
1246 if (pBoardInfo->btdmAntPos == BTC_ANTENNA_AT_MAIN_PORT) {
1247 /* tell firmware "no antenna inverse" */
1248 H2C_Parameter[0] = 0;
1250 /* tell firmware "antenna inverse" */
1251 H2C_Parameter[0] = 1;
1254 if (bUseExtSwitch) {
1255 /* ext switch type */
1256 H2C_Parameter[1] = 1;
1258 /* int switch type */
1259 H2C_Parameter[1] = 0;
1261 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x65, 2, H2C_Parameter);
1264 /* ext switch setting */
1265 if (bUseExtSwitch) {
1267 /* 0x4c[23]= 0, 0x4c[24]= 1 Antenna control by WL/BT */
1268 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);
1271 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);
1274 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0); /* fixed internal switch S1->WiFi, S0->BT */
1275 switch (antPosType) {
1276 case BTC_ANT_WIFI_AT_MAIN:
1277 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x1); /* ext switch main at wifi */
1279 case BTC_ANT_WIFI_AT_AUX:
1280 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x92c, 0x3, 0x2); /* ext switch aux at wifi */
1283 } else { /* internal switch */
1285 /* 0x4c[23]= 0, 0x4c[24]= 1 Antenna control by WL/BT */
1286 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);
1289 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);
1292 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x64, 0x1, 0x0); /* fixed external switch S1->Main, S0->Aux */
1293 switch (antPosType) {
1294 case BTC_ANT_WIFI_AT_MAIN:
1295 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0); /* fixed internal switch S1->WiFi, S0->BT */
1297 case BTC_ANT_WIFI_AT_AUX:
1298 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x280); /* fixed internal switch S0->WiFi, S1->BT */
1304 static void halbtc8723b2ant_PsTdma(
1305 PBTC_COEXIST pBtCoexist, bool bForceExec, bool bTurnOn, u8 type
1312 "[BTCoex], %s turn %s PS TDMA, type =%d\n",
1313 (bForceExec ? "force to" : ""),
1314 (bTurnOn ? "ON" : "OFF"),
1318 pCoexDm->bCurPsTdmaOn = bTurnOn;
1319 pCoexDm->curPsTdma = type;
1324 ALGO_TRACE_FW_DETAIL,
1326 "[BTCoex], bPrePsTdmaOn = %d, bCurPsTdmaOn = %d!!\n",
1327 pCoexDm->bPrePsTdmaOn,
1328 pCoexDm->bCurPsTdmaOn
1333 ALGO_TRACE_FW_DETAIL,
1335 "[BTCoex], prePsTdma = %d, curPsTdma = %d!!\n",
1336 pCoexDm->prePsTdma, pCoexDm->curPsTdma
1341 (pCoexDm->bPrePsTdmaOn == pCoexDm->bCurPsTdmaOn) &&
1342 (pCoexDm->prePsTdma == pCoexDm->curPsTdma)
1351 halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x90);
1354 halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0xe1, 0x90);
1357 halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1c, 0x3, 0xf1, 0x90);
1360 halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x10, 0x03, 0xf1, 0x90);
1363 halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0x60, 0x90);
1366 halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0x60, 0x90);
1369 halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1c, 0x3, 0x70, 0x90);
1372 halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xa3, 0x10, 0x3, 0x70, 0x90);
1375 halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x90);
1378 halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0xe1, 0x90);
1381 halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0xa, 0xe1, 0x90);
1384 halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x5, 0x5, 0xe1, 0x90);
1387 halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0x60, 0x90);
1390 halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0x60, 0x90);
1393 halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0xa, 0x60, 0x90);
1396 halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x5, 0x5, 0x60, 0x90);
1399 halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xa3, 0x2f, 0x2f, 0x60, 0x90);
1402 halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x5, 0x5, 0xe1, 0x90);
1405 halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x25, 0xe1, 0x90);
1408 halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x25, 0x60, 0x90);
1411 halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x15, 0x03, 0x70, 0x90);
1414 halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x90);
1418 /* disable PS tdma */
1421 halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x40, 0x0);
1424 halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x48, 0x0);
1427 halbtc8723b2ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x40, 0x0);
1432 /* update pre state */
1433 pCoexDm->bPrePsTdmaOn = pCoexDm->bCurPsTdmaOn;
1434 pCoexDm->prePsTdma = pCoexDm->curPsTdma;
1437 static void halbtc8723b2ant_CoexAllOff(PBTC_COEXIST pBtCoexist)
1440 halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 1);
1441 halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
1442 halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
1445 halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
1446 halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
1449 /* pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); */
1450 halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
1453 static void halbtc8723b2ant_InitCoexDm(PBTC_COEXIST pBtCoexist)
1455 /* force to reset coex mechanism */
1457 halbtc8723b2ant_PsTdma(pBtCoexist, FORCE_EXEC, false, 1);
1458 halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, FORCE_EXEC, 6);
1459 halbtc8723b2ant_DecBtPwr(pBtCoexist, FORCE_EXEC, 0);
1461 halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
1462 halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
1465 static void halbtc8723b2ant_ActionBtInquiry(PBTC_COEXIST pBtCoexist)
1467 bool bWifiConnected = false;
1468 bool bLowPwrDisable = true;
1470 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);
1471 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
1473 if (bWifiConnected) {
1474 halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
1475 halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 3);
1477 halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
1478 halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 1);
1481 halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, FORCE_EXEC, 6);
1482 halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
1484 halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
1485 halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
1487 pCoexDm->bNeedRecover0x948 = true;
1488 pCoexDm->backup0x948 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x948);
1490 halbtc8723b2ant_SetAntPath(pBtCoexist, BTC_ANT_WIFI_AT_AUX, false, false);
1493 static bool halbtc8723b2ant_IsCommonAction(PBTC_COEXIST pBtCoexist)
1495 u8 btRssiState = BTC_RSSI_STATE_HIGH;
1496 bool bCommon = false, bWifiConnected = false, bWifiBusy = false;
1497 bool bBtHsOn = false, bLowPwrDisable = false;
1499 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
1500 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
1501 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
1503 if (!bWifiConnected) {
1504 bLowPwrDisable = false;
1505 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);
1506 halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
1508 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi non-connected idle!!\n"));
1510 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
1511 halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
1512 halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 1);
1513 halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
1514 halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
1516 halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
1517 halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
1521 if (BT_8723B_2ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus) {
1522 bLowPwrDisable = false;
1523 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);
1524 halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
1526 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi connected + BT non connected-idle!!\n"));
1528 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
1529 halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
1530 halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 1);
1531 halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 0xb);
1532 halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
1534 halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
1535 halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
1538 } else if (BT_8723B_2ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus) {
1539 bLowPwrDisable = true;
1540 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);
1545 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi connected + BT connected-idle!!\n"));
1546 halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
1548 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
1549 halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
1550 halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 1);
1551 halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 0xb);
1552 halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
1554 halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false);
1555 halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
1559 bLowPwrDisable = true;
1560 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);
1563 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi Connected-Busy + BT Busy!!\n"));
1569 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi Connected-Idle + BT Busy!!\n"));
1570 btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0);
1571 halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
1573 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
1574 halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
1575 halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 21);
1576 halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 0xb);
1578 if (BTC_RSSI_HIGH(btRssiState))
1579 halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
1581 halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
1583 halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
1584 halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
1593 static void halbtc8723b2ant_TdmaDurationAdjust(
1594 PBTC_COEXIST pBtCoexist, bool bScoHid, bool bTxPause, u8 maxInterval
1597 static s32 up, dn, m, n, WaitCount;
1598 s32 result; /* 0: no change, +1: increase WiFi duration, -1: decrease WiFi duration */
1601 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], TdmaDurationAdjust()\n"));
1603 if (!pCoexDm->bAutoTdmaAdjust) {
1604 pCoexDm->bAutoTdmaAdjust = true;
1605 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], first run TdmaDurationAdjust()!!\n"));
1609 if (maxInterval == 1)
1610 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(13);
1611 else if (maxInterval == 2)
1612 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(14);
1614 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15);
1616 if (maxInterval == 1)
1617 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(9);
1618 else if (maxInterval == 2)
1619 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(10);
1621 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11);
1625 if (maxInterval == 1)
1626 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(5);
1627 else if (maxInterval == 2)
1628 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(6);
1630 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7);
1632 if (maxInterval == 1)
1633 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(1);
1634 else if (maxInterval == 2)
1635 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(2);
1637 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3);
1649 /* acquire the BT TRx retry count from BT_Info byte2 */
1650 retryCount = pCoexSta->btRetryCnt;
1651 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], retryCount = %d\n", retryCount));
1654 ALGO_TRACE_FW_DETAIL,
1656 "[BTCoex], up =%d, dn =%d, m =%d, n =%d, WaitCount =%d\n",
1657 up, dn, m, n, WaitCount
1663 if (retryCount == 0) { /* no retry in the last 2-second duration */
1670 if (up >= n) { /* if 連續 n 個2秒 retry count為0, 則調寬WiFi duration */
1676 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], Increase wifi duration!!\n"));
1678 } else if (retryCount <= 3) { /* <=3 retry in the last 2-second duration */
1685 if (dn == 2) { /* if 連續 2 個2秒 retry count< 3, 則調窄WiFi duration */
1687 m++; /* 避免一直在兩個level中來回 */
1691 if (m >= 20) /* m 最大值 = 20 ' 最大120秒 recheck是否調整 WiFi duration. */
1699 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], Decrease wifi duration for retryCounter<3!!\n"));
1701 } else { /* retry count > 3, 只要1次 retry count > 3, 則調窄WiFi duration */
1703 m++; /* 避免一直在兩個level中來回 */
1707 if (m >= 20) /* m 最大值 = 20 ' 最大120秒 recheck是否調整 WiFi duration. */
1715 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], Decrease wifi duration for retryCounter>3!!\n"));
1718 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], max Interval = %d\n", maxInterval));
1719 if (maxInterval == 1) {
1721 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 1\n"));
1723 if (pCoexDm->curPsTdma == 71)
1724 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(5);
1725 else if (pCoexDm->curPsTdma == 1)
1726 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(5);
1727 else if (pCoexDm->curPsTdma == 2)
1728 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(6);
1729 else if (pCoexDm->curPsTdma == 3)
1730 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7);
1731 else if (pCoexDm->curPsTdma == 4)
1732 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(8);
1734 if (pCoexDm->curPsTdma == 9)
1735 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(13);
1736 else if (pCoexDm->curPsTdma == 10)
1737 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(14);
1738 else if (pCoexDm->curPsTdma == 11)
1739 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15);
1740 else if (pCoexDm->curPsTdma == 12)
1741 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(16);
1744 if (pCoexDm->curPsTdma == 5)
1745 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(6);
1746 else if (pCoexDm->curPsTdma == 6)
1747 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7);
1748 else if (pCoexDm->curPsTdma == 7)
1749 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(8);
1750 else if (pCoexDm->curPsTdma == 13)
1751 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(14);
1752 else if (pCoexDm->curPsTdma == 14)
1753 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15);
1754 else if (pCoexDm->curPsTdma == 15)
1755 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(16);
1756 } else if (result == 1) {
1757 if (pCoexDm->curPsTdma == 8)
1758 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7);
1759 else if (pCoexDm->curPsTdma == 7)
1760 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(6);
1761 else if (pCoexDm->curPsTdma == 6)
1762 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(5);
1763 else if (pCoexDm->curPsTdma == 16)
1764 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15);
1765 else if (pCoexDm->curPsTdma == 15)
1766 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(14);
1767 else if (pCoexDm->curPsTdma == 14)
1768 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(13);
1771 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 0\n"));
1772 if (pCoexDm->curPsTdma == 5)
1773 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(71);
1774 else if (pCoexDm->curPsTdma == 6)
1775 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(2);
1776 else if (pCoexDm->curPsTdma == 7)
1777 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3);
1778 else if (pCoexDm->curPsTdma == 8)
1779 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(4);
1781 if (pCoexDm->curPsTdma == 13)
1782 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(9);
1783 else if (pCoexDm->curPsTdma == 14)
1784 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(10);
1785 else if (pCoexDm->curPsTdma == 15)
1786 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11);
1787 else if (pCoexDm->curPsTdma == 16)
1788 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(12);
1791 if (pCoexDm->curPsTdma == 71)
1792 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(1);
1793 else if (pCoexDm->curPsTdma == 1)
1794 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(2);
1795 else if (pCoexDm->curPsTdma == 2)
1796 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3);
1797 else if (pCoexDm->curPsTdma == 3)
1798 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(4);
1799 else if (pCoexDm->curPsTdma == 9)
1800 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(10);
1801 else if (pCoexDm->curPsTdma == 10)
1802 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11);
1803 else if (pCoexDm->curPsTdma == 11)
1804 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(12);
1805 } else if (result == 1) {
1806 if (pCoexDm->curPsTdma == 4)
1807 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3);
1808 else if (pCoexDm->curPsTdma == 3)
1809 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(2);
1810 else if (pCoexDm->curPsTdma == 2)
1811 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(1);
1812 else if (pCoexDm->curPsTdma == 1)
1813 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(71);
1814 else if (pCoexDm->curPsTdma == 12)
1815 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11);
1816 else if (pCoexDm->curPsTdma == 11)
1817 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(10);
1818 else if (pCoexDm->curPsTdma == 10)
1819 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(9);
1822 } else if (maxInterval == 2) {
1824 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 1\n"));
1825 if (pCoexDm->curPsTdma == 1)
1826 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(6);
1827 else if (pCoexDm->curPsTdma == 2)
1828 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(6);
1829 else if (pCoexDm->curPsTdma == 3)
1830 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7);
1831 else if (pCoexDm->curPsTdma == 4)
1832 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(8);
1834 if (pCoexDm->curPsTdma == 9)
1835 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(14);
1836 else if (pCoexDm->curPsTdma == 10)
1837 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(14);
1838 else if (pCoexDm->curPsTdma == 11)
1839 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15);
1840 else if (pCoexDm->curPsTdma == 12)
1841 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(16);
1844 if (pCoexDm->curPsTdma == 5)
1845 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(6);
1846 else if (pCoexDm->curPsTdma == 6)
1847 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7);
1848 else if (pCoexDm->curPsTdma == 7)
1849 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(8);
1850 else if (pCoexDm->curPsTdma == 13)
1851 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(14);
1852 else if (pCoexDm->curPsTdma == 14)
1853 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15);
1854 else if (pCoexDm->curPsTdma == 15)
1855 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(16);
1856 } else if (result == 1) {
1857 if (pCoexDm->curPsTdma == 8)
1858 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7);
1859 else if (pCoexDm->curPsTdma == 7)
1860 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(6);
1861 else if (pCoexDm->curPsTdma == 6)
1862 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(6);
1863 else if (pCoexDm->curPsTdma == 16)
1864 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15);
1865 else if (pCoexDm->curPsTdma == 15)
1866 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(14);
1867 else if (pCoexDm->curPsTdma == 14)
1868 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(14);
1871 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 0\n"));
1872 if (pCoexDm->curPsTdma == 5)
1873 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(2);
1874 else if (pCoexDm->curPsTdma == 6)
1875 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(2);
1876 else if (pCoexDm->curPsTdma == 7)
1877 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3);
1878 else if (pCoexDm->curPsTdma == 8)
1879 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(4);
1881 if (pCoexDm->curPsTdma == 13)
1882 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(10);
1883 else if (pCoexDm->curPsTdma == 14)
1884 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(10);
1885 else if (pCoexDm->curPsTdma == 15)
1886 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11);
1887 else if (pCoexDm->curPsTdma == 16)
1888 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(12);
1891 if (pCoexDm->curPsTdma == 1)
1892 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(2);
1893 else if (pCoexDm->curPsTdma == 2)
1894 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3);
1895 else if (pCoexDm->curPsTdma == 3)
1896 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(4);
1897 else if (pCoexDm->curPsTdma == 9)
1898 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(10);
1899 else if (pCoexDm->curPsTdma == 10)
1900 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11);
1901 else if (pCoexDm->curPsTdma == 11)
1902 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(12);
1903 } else if (result == 1) {
1904 if (pCoexDm->curPsTdma == 4)
1905 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3);
1906 else if (pCoexDm->curPsTdma == 3)
1907 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(2);
1908 else if (pCoexDm->curPsTdma == 2)
1909 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(2);
1910 else if (pCoexDm->curPsTdma == 12)
1911 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11);
1912 else if (pCoexDm->curPsTdma == 11)
1913 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(10);
1914 else if (pCoexDm->curPsTdma == 10)
1915 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(10);
1918 } else if (maxInterval == 3) {
1920 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 1\n"));
1921 if (pCoexDm->curPsTdma == 1)
1922 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7);
1923 else if (pCoexDm->curPsTdma == 2)
1924 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7);
1925 else if (pCoexDm->curPsTdma == 3)
1926 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7);
1927 else if (pCoexDm->curPsTdma == 4)
1928 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(8);
1930 if (pCoexDm->curPsTdma == 9)
1931 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15);
1932 else if (pCoexDm->curPsTdma == 10)
1933 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15);
1934 else if (pCoexDm->curPsTdma == 11)
1935 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15);
1936 else if (pCoexDm->curPsTdma == 12)
1937 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(16);
1940 if (pCoexDm->curPsTdma == 5)
1941 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7);
1942 else if (pCoexDm->curPsTdma == 6)
1943 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7);
1944 else if (pCoexDm->curPsTdma == 7)
1945 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(8);
1946 else if (pCoexDm->curPsTdma == 13)
1947 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15);
1948 else if (pCoexDm->curPsTdma == 14)
1949 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15);
1950 else if (pCoexDm->curPsTdma == 15)
1951 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(16);
1952 } else if (result == 1) {
1953 if (pCoexDm->curPsTdma == 8)
1954 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7);
1955 else if (pCoexDm->curPsTdma == 7)
1956 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7);
1957 else if (pCoexDm->curPsTdma == 6)
1958 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(7);
1959 else if (pCoexDm->curPsTdma == 16)
1960 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15);
1961 else if (pCoexDm->curPsTdma == 15)
1962 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15);
1963 else if (pCoexDm->curPsTdma == 14)
1964 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(15);
1967 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 0\n"));
1968 if (pCoexDm->curPsTdma == 5)
1969 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3);
1970 else if (pCoexDm->curPsTdma == 6)
1971 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3);
1972 else if (pCoexDm->curPsTdma == 7)
1973 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3);
1974 else if (pCoexDm->curPsTdma == 8)
1975 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(4);
1977 if (pCoexDm->curPsTdma == 13)
1978 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11);
1979 else if (pCoexDm->curPsTdma == 14)
1980 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11);
1981 else if (pCoexDm->curPsTdma == 15)
1982 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11);
1983 else if (pCoexDm->curPsTdma == 16)
1984 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(12);
1987 if (pCoexDm->curPsTdma == 1)
1988 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3);
1989 else if (pCoexDm->curPsTdma == 2)
1990 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3);
1991 else if (pCoexDm->curPsTdma == 3)
1992 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(4);
1993 else if (pCoexDm->curPsTdma == 9)
1994 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11);
1995 else if (pCoexDm->curPsTdma == 10)
1996 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11);
1997 else if (pCoexDm->curPsTdma == 11)
1998 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(12);
1999 } else if (result == 1) {
2000 if (pCoexDm->curPsTdma == 4)
2001 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3);
2002 else if (pCoexDm->curPsTdma == 3)
2003 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3);
2004 else if (pCoexDm->curPsTdma == 2)
2005 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(3);
2006 else if (pCoexDm->curPsTdma == 12)
2007 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11);
2008 else if (pCoexDm->curPsTdma == 11)
2009 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11);
2010 else if (pCoexDm->curPsTdma == 10)
2011 HAL_BTC8723B2ANT_DMA_DURATION_ADJUST(11);
2017 /* if current PsTdma not match with the recorded one (when scan, dhcp...), */
2018 /* then we have to adjust it back to the previous record one. */
2019 if (pCoexDm->curPsTdma != pCoexDm->psTdmaDuAdjType) {
2020 bool bScan = false, bLink = false, bRoam = false;
2023 ALGO_TRACE_FW_DETAIL,
2025 "[BTCoex], PsTdma type mismatch!!!, curPsTdma =%d, recordPsTdma =%d\n",
2027 pCoexDm->psTdmaDuAdjType
2031 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
2032 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
2033 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
2035 if (!bScan && !bLink && !bRoam)
2036 halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, pCoexDm->psTdmaDuAdjType);
2038 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n"));
2043 /* SCO only or SCO+PAN(HS) */
2044 static void halbtc8723b2ant_ActionSco(PBTC_COEXIST pBtCoexist)
2046 u8 wifiRssiState, btRssiState;
2049 wifiRssiState = halbtc8723b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
2050 btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0);
2052 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2054 halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
2056 halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 4);
2058 if (BTC_RSSI_HIGH(btRssiState))
2059 halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
2061 halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
2063 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
2065 if (BTC_WIFI_BW_LEGACY == wifiBw) /* for SCO quality at 11b/g mode */
2066 halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);
2067 else /* for SCO quality & wifi performance balance at 11n mode */
2068 halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 8);
2070 halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 0); /* for voice quality */
2073 if (BTC_WIFI_BW_HT40 == wifiBw) {
2075 (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2076 (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2078 halbtc8723b2ant_SwMechanism1(pBtCoexist, true, true, false, false);
2079 halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, true, 0x4);
2081 halbtc8723b2ant_SwMechanism1(pBtCoexist, true, true, false, false);
2082 halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, true, 0x4);
2086 (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2087 (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2089 halbtc8723b2ant_SwMechanism1(pBtCoexist, false, true, false, false);
2090 halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, true, 0x4);
2092 halbtc8723b2ant_SwMechanism1(pBtCoexist, false, true, false, false);
2093 halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, true, 0x4);
2099 static void halbtc8723b2ant_ActionHid(PBTC_COEXIST pBtCoexist)
2101 u8 wifiRssiState, btRssiState;
2104 wifiRssiState = halbtc8723b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
2105 btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0);
2107 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2109 halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
2111 halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
2113 if (BTC_RSSI_HIGH(btRssiState))
2114 halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
2116 halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
2118 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
2120 if (BTC_WIFI_BW_LEGACY == wifiBw) /* for HID at 11b/g mode */
2121 halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
2122 else /* for HID quality & wifi performance balance at 11n mode */
2123 halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 9);
2126 (btRssiState == BTC_RSSI_STATE_HIGH) ||
2127 (btRssiState == BTC_RSSI_STATE_STAY_HIGH)
2129 halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 9);
2131 halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 13);
2134 if (BTC_WIFI_BW_HT40 == wifiBw) {
2136 (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2137 (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2139 halbtc8723b2ant_SwMechanism1(pBtCoexist, true, true, false, false);
2140 halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
2142 halbtc8723b2ant_SwMechanism1(pBtCoexist, true, true, false, false);
2143 halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
2147 (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2148 (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2150 halbtc8723b2ant_SwMechanism1(pBtCoexist, false, true, false, false);
2151 halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
2153 halbtc8723b2ant_SwMechanism1(pBtCoexist, false, true, false, false);
2154 halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
2159 /* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */
2160 static void halbtc8723b2ant_ActionA2dp(PBTC_COEXIST pBtCoexist)
2162 u8 wifiRssiState, wifiRssiState1, btRssiState;
2166 wifiRssiState = halbtc8723b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
2167 wifiRssiState1 = halbtc8723b2ant_WifiRssiState(pBtCoexist, 1, 2, 40, 0);
2168 btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0);
2170 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_AP_NUM, &apNum);
2172 /* define the office environment */
2173 if (apNum >= 10 && BTC_RSSI_HIGH(wifiRssiState1)) {
2174 /* DbgPrint(" AP#>10(%d)\n", apNum); */
2175 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2176 halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
2177 halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
2178 halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
2179 halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);
2180 halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 1);
2183 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
2184 if (BTC_WIFI_BW_HT40 == wifiBw) {
2185 halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false);
2186 halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, true, 0x18);
2188 halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
2189 halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, true, 0x18);
2194 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2195 halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
2197 halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
2199 if (BTC_RSSI_HIGH(btRssiState))
2200 halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
2202 halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
2204 halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
2207 (btRssiState == BTC_RSSI_STATE_HIGH) ||
2208 (btRssiState == BTC_RSSI_STATE_STAY_HIGH)
2210 halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, false, false, 1);
2212 halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, false, true, 1);
2215 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
2216 if (BTC_WIFI_BW_HT40 == wifiBw) {
2218 (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2219 (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2221 halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false);
2222 halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
2224 halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false);
2225 halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
2229 (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2230 (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2232 halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
2233 halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
2235 halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
2236 halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
2241 static void halbtc8723b2ant_ActionA2dpPanHs(PBTC_COEXIST pBtCoexist)
2243 u8 wifiRssiState, btRssiState;
2246 wifiRssiState = halbtc8723b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
2247 btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0);
2249 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2251 halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
2253 halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
2255 if (BTC_RSSI_HIGH(btRssiState))
2256 halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
2258 halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
2260 halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
2262 halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, false, true, 2);
2265 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
2266 if (BTC_WIFI_BW_HT40 == wifiBw) {
2268 (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2269 (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2271 halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false);
2272 halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
2274 halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false);
2275 halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
2279 (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2280 (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2282 halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
2283 halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
2285 halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
2286 halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
2291 static void halbtc8723b2ant_ActionPanEdr(PBTC_COEXIST pBtCoexist)
2293 u8 wifiRssiState, btRssiState;
2296 wifiRssiState = halbtc8723b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
2297 btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0);
2299 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2301 halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
2303 halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
2305 if (BTC_RSSI_HIGH(btRssiState))
2306 halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
2308 halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
2310 halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 10);
2313 (btRssiState == BTC_RSSI_STATE_HIGH) ||
2314 (btRssiState == BTC_RSSI_STATE_STAY_HIGH)
2316 halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 1);
2318 halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, true, 5);
2321 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
2322 if (BTC_WIFI_BW_HT40 == wifiBw) {
2324 (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2325 (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2327 halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false);
2328 halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
2330 halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false);
2331 halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
2335 (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2336 (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2338 halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
2339 halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
2341 halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
2342 halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
2349 static void halbtc8723b2ant_ActionPanHs(PBTC_COEXIST pBtCoexist)
2351 u8 wifiRssiState, btRssiState;
2354 wifiRssiState = halbtc8723b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
2355 btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0);
2357 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2359 halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
2361 halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
2363 if (BTC_RSSI_HIGH(btRssiState))
2364 halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
2366 halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
2368 halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
2370 halbtc8723b2ant_PsTdma(pBtCoexist, NORMAL_EXEC, false, 1);
2372 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
2373 if (BTC_WIFI_BW_HT40 == wifiBw) {
2375 (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2376 (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2378 halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false);
2379 halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
2381 halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false);
2382 halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
2386 (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2387 (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2389 halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
2390 halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
2392 halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
2393 halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
2399 static void halbtc8723b2ant_ActionPanEdrA2dp(PBTC_COEXIST pBtCoexist)
2401 u8 wifiRssiState, btRssiState;
2404 wifiRssiState = halbtc8723b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
2405 btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0);
2407 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2409 halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
2411 halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
2413 if (BTC_RSSI_HIGH(btRssiState))
2414 halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
2416 halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
2418 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
2421 (btRssiState == BTC_RSSI_STATE_HIGH) ||
2422 (btRssiState == BTC_RSSI_STATE_STAY_HIGH)
2424 halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 12);
2425 if (BTC_WIFI_BW_HT40 == wifiBw)
2426 halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, false, true, 3);
2428 halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, false, false, 3);
2430 halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
2431 halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, false, true, 3);
2435 if (BTC_WIFI_BW_HT40 == wifiBw) {
2437 (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2438 (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2440 halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false);
2441 halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
2443 halbtc8723b2ant_SwMechanism1(pBtCoexist, true, false, false, false);
2444 halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
2448 (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2449 (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2451 halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
2452 halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
2454 halbtc8723b2ant_SwMechanism1(pBtCoexist, false, false, false, false);
2455 halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
2460 static void halbtc8723b2ant_ActionPanEdrHid(PBTC_COEXIST pBtCoexist)
2462 u8 wifiRssiState, btRssiState;
2465 wifiRssiState = halbtc8723b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
2466 btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0);
2467 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
2469 halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
2471 if (BTC_RSSI_HIGH(btRssiState))
2472 halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
2474 halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
2477 (btRssiState == BTC_RSSI_STATE_HIGH) ||
2478 (btRssiState == BTC_RSSI_STATE_STAY_HIGH)
2480 if (BTC_WIFI_BW_HT40 == wifiBw) {
2481 halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 3);
2482 halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 11);
2483 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x780);
2485 halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
2486 halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
2487 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2489 halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, true, false, 2);
2491 halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
2492 halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 11);
2493 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2494 halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, true, true, 2);
2498 if (BTC_WIFI_BW_HT40 == wifiBw) {
2500 (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2501 (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2503 halbtc8723b2ant_SwMechanism1(pBtCoexist, true, true, false, false);
2504 halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
2506 halbtc8723b2ant_SwMechanism1(pBtCoexist, true, true, false, false);
2507 halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
2511 (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2512 (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2514 halbtc8723b2ant_SwMechanism1(pBtCoexist, false, true, false, false);
2515 halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
2517 halbtc8723b2ant_SwMechanism1(pBtCoexist, false, true, false, false);
2518 halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
2523 /* HID+A2DP+PAN(EDR) */
2524 static void halbtc8723b2ant_ActionHidA2dpPanEdr(PBTC_COEXIST pBtCoexist)
2526 u8 wifiRssiState, btRssiState;
2529 wifiRssiState = halbtc8723b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
2530 btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0);
2532 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2534 halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, false, 0x8);
2536 halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
2538 if (BTC_RSSI_HIGH(btRssiState))
2539 halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
2541 halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
2543 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
2545 halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
2548 (btRssiState == BTC_RSSI_STATE_HIGH) ||
2549 (btRssiState == BTC_RSSI_STATE_STAY_HIGH)
2551 if (BTC_WIFI_BW_HT40 == wifiBw)
2552 halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, true, true, 2);
2554 halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, true, false, 3);
2556 halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, true, true, 3);
2559 if (BTC_WIFI_BW_HT40 == wifiBw) {
2561 (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2562 (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2564 halbtc8723b2ant_SwMechanism1(pBtCoexist, true, true, false, false);
2565 halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
2567 halbtc8723b2ant_SwMechanism1(pBtCoexist, true, true, false, false);
2568 halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
2572 (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2573 (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2575 halbtc8723b2ant_SwMechanism1(pBtCoexist, false, true, false, false);
2576 halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
2578 halbtc8723b2ant_SwMechanism1(pBtCoexist, false, true, false, false);
2579 halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
2584 static void halbtc8723b2ant_ActionHidA2dp(PBTC_COEXIST pBtCoexist)
2586 u8 wifiRssiState, btRssiState;
2590 wifiRssiState = halbtc8723b2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);
2591 /* btRssiState = halbtc8723b2ant_BtRssiState(2, 29, 0); */
2592 btRssiState = halbtc8723b2ant_BtRssiState(3, 29, 37);
2594 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x0);
2596 halbtc8723b2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, false, true, 0x5);
2598 halbtc8723b2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);
2600 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
2601 if (BTC_WIFI_BW_LEGACY == wifiBw) {
2602 if (BTC_RSSI_HIGH(btRssiState))
2603 halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
2604 else if (BTC_RSSI_MEDIUM(btRssiState))
2605 halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
2607 halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
2609 /* only 802.11N mode we have to dec bt power to 4 degree */
2610 if (BTC_RSSI_HIGH(btRssiState)) {
2611 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_AP_NUM, &apNum);
2612 /* need to check ap Number of Not */
2614 halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);
2616 halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
2617 } else if (BTC_RSSI_MEDIUM(btRssiState))
2618 halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);
2620 halbtc8723b2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);
2623 halbtc8723b2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 7);
2626 (btRssiState == BTC_RSSI_STATE_HIGH) ||
2627 (btRssiState == BTC_RSSI_STATE_STAY_HIGH)
2629 halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, true, false, 2);
2631 halbtc8723b2ant_TdmaDurationAdjust(pBtCoexist, true, true, 2);
2634 if (BTC_WIFI_BW_HT40 == wifiBw) {
2636 (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2637 (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2639 halbtc8723b2ant_SwMechanism1(pBtCoexist, true, true, false, false);
2640 halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
2642 halbtc8723b2ant_SwMechanism1(pBtCoexist, true, true, false, false);
2643 halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
2647 (wifiRssiState == BTC_RSSI_STATE_HIGH) ||
2648 (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH)
2650 halbtc8723b2ant_SwMechanism1(pBtCoexist, false, true, false, false);
2651 halbtc8723b2ant_SwMechanism2(pBtCoexist, true, false, false, 0x18);
2653 halbtc8723b2ant_SwMechanism1(pBtCoexist, false, true, false, false);
2654 halbtc8723b2ant_SwMechanism2(pBtCoexist, false, false, false, 0x18);
2659 static void halbtc8723b2ant_RunCoexistMechanism(PBTC_COEXIST pBtCoexist)
2663 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], RunCoexistMechanism() ===>\n"));
2665 if (pBtCoexist->bManualControl) {
2666 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"));
2670 if (pCoexSta->bUnderIps) {
2671 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], wifi is under IPS !!!\n"));
2675 algorithm = halbtc8723b2ant_ActionAlgorithm(pBtCoexist);
2676 if (pCoexSta->bC2hBtInquiryPage && (BT_8723B_2ANT_COEX_ALGO_PANHS != algorithm)) {
2677 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT is under inquiry/page scan !!\n"));
2678 halbtc8723b2ant_ActionBtInquiry(pBtCoexist);
2681 if (pCoexDm->bNeedRecover0x948) {
2682 pCoexDm->bNeedRecover0x948 = false;
2683 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, pCoexDm->backup0x948);
2687 pCoexDm->curAlgorithm = algorithm;
2688 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Algorithm = %d\n", pCoexDm->curAlgorithm));
2690 if (halbtc8723b2ant_IsCommonAction(pBtCoexist)) {
2691 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant common.\n"));
2692 pCoexDm->bAutoTdmaAdjust = false;
2694 if (pCoexDm->curAlgorithm != pCoexDm->preAlgorithm) {
2699 "[BTCoex], preAlgorithm =%d, curAlgorithm =%d\n",
2700 pCoexDm->preAlgorithm,
2701 pCoexDm->curAlgorithm
2704 pCoexDm->bAutoTdmaAdjust = false;
2708 switch (pCoexDm->curAlgorithm) {
2709 case BT_8723B_2ANT_COEX_ALGO_SCO:
2710 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = SCO.\n"));
2711 halbtc8723b2ant_ActionSco(pBtCoexist);
2713 case BT_8723B_2ANT_COEX_ALGO_HID:
2714 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = HID.\n"));
2715 halbtc8723b2ant_ActionHid(pBtCoexist);
2717 case BT_8723B_2ANT_COEX_ALGO_A2DP:
2718 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = A2DP.\n"));
2719 halbtc8723b2ant_ActionA2dp(pBtCoexist);
2721 case BT_8723B_2ANT_COEX_ALGO_A2DP_PANHS:
2722 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = A2DP+PAN(HS).\n"));
2723 halbtc8723b2ant_ActionA2dpPanHs(pBtCoexist);
2725 case BT_8723B_2ANT_COEX_ALGO_PANEDR:
2726 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = PAN(EDR).\n"));
2727 halbtc8723b2ant_ActionPanEdr(pBtCoexist);
2729 case BT_8723B_2ANT_COEX_ALGO_PANHS:
2730 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = HS mode.\n"));
2731 halbtc8723b2ant_ActionPanHs(pBtCoexist);
2733 case BT_8723B_2ANT_COEX_ALGO_PANEDR_A2DP:
2734 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = PAN+A2DP.\n"));
2735 halbtc8723b2ant_ActionPanEdrA2dp(pBtCoexist);
2737 case BT_8723B_2ANT_COEX_ALGO_PANEDR_HID:
2738 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = PAN(EDR)+HID.\n"));
2739 halbtc8723b2ant_ActionPanEdrHid(pBtCoexist);
2741 case BT_8723B_2ANT_COEX_ALGO_HID_A2DP_PANEDR:
2742 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN.\n"));
2743 halbtc8723b2ant_ActionHidA2dpPanEdr(pBtCoexist);
2745 case BT_8723B_2ANT_COEX_ALGO_HID_A2DP:
2746 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = HID+A2DP.\n"));
2747 halbtc8723b2ant_ActionHidA2dp(pBtCoexist);
2750 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = coexist All Off!!\n"));
2751 halbtc8723b2ant_CoexAllOff(pBtCoexist);
2754 pCoexDm->preAlgorithm = pCoexDm->curAlgorithm;
2758 static void halbtc8723b2ant_WifiOffHwCfg(PBTC_COEXIST pBtCoexist)
2760 bool bIsInMpMode = false;
2761 u8 H2C_Parameter[2] = {0};
2764 /* set wlan_act to low */
2765 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4);
2767 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1, 0xfffff, 0x780); /* WiFi goto standby while GNT_BT 0-->1 */
2768 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);
2769 if (fwVer >= 0x180000) {
2770 /* Use H2C to set GNT_BT to HIGH */
2771 H2C_Parameter[0] = 1;
2772 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x6E, 1, H2C_Parameter);
2774 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x18);
2776 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_IS_IN_MP_MODE, &bIsInMpMode);
2778 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x0); /* BT select s0/s1 is controlled by BT */
2780 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x67, 0x20, 0x1); /* BT select s0/s1 is controlled by WiFi */
2783 static void halbtc8723b2ant_InitHwConfig(PBTC_COEXIST pBtCoexist, bool bBackUp)
2787 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], 2Ant Init HW Config!!\n"));
2789 /* backup rf 0x1e value */
2790 pCoexDm->btRf0x1eBackup =
2791 pBtCoexist->fBtcGetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff);
2793 /* 0x790[5:0]= 0x5 */
2794 u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x790);
2797 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x790, u1Tmp);
2799 /* Antenna config */
2800 halbtc8723b2ant_SetAntPath(pBtCoexist, BTC_ANT_WIFI_AT_MAIN, true, false);
2803 halbtc8723b2ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);
2805 /* Enable counter statistics */
2806 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc); /* 0x76e[3] = 1, WLAN_Act control by PTA */
2807 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x778, 0x3);
2808 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x40, 0x20, 0x1);
2812 /* work around function start with wa_halbtc8723b2ant_ */
2815 /* extern function start with EXhalbtc8723b2ant_ */
2817 void EXhalbtc8723b2ant_PowerOnSetting(PBTC_COEXIST pBtCoexist)
2819 PBTC_BOARD_INFO pBoardInfo = &pBtCoexist->boardInfo;
2820 u8 u1Tmp = 0x4; /* Set BIT2 by default since it's 2ant case */
2823 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x67, 0x20);
2825 /* enable BB, REG_SYS_FUNC_EN such that we can write 0x948 correctly. */
2826 u2Tmp = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x2);
2827 pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x2, u2Tmp|BIT0|BIT1);
2829 /* set GRAN_BT = 1 */
2830 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x765, 0x18);
2831 /* set WLAN_ACT = 0 */
2832 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4);
2835 /* S0 or S1 setting and Local register setting(By the setting fw can get ant number, S0/S1, ... info) */
2836 /* Local setting bit define */
2837 /* BIT0: "0" for no antenna inverse; "1" for antenna inverse */
2838 /* BIT1: "0" for internal switch; "1" for external switch */
2839 /* BIT2: "0" for one antenna; "1" for two antenna */
2840 /* NOTE: here default all internal switch and 1-antenna ==> BIT1 = 0 and BIT2 = 0 */
2841 if (pBtCoexist->chipInterface == BTC_INTF_USB) {
2842 /* fixed at S0 for USB interface */
2843 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);
2845 u1Tmp |= 0x1; /* antenna inverse */
2846 pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0xfe08, u1Tmp);
2848 pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_AUX_PORT;
2850 /* for PCIE and SDIO interface, we check efuse 0xc3[6] */
2851 if (pBoardInfo->singleAntPath == 0) {
2853 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x280);
2854 pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_MAIN_PORT;
2855 } else if (pBoardInfo->singleAntPath == 1) {
2857 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x948, 0x0);
2858 u1Tmp |= 0x1; /* antenna inverse */
2859 pBoardInfo->btdmAntPos = BTC_ANTENNA_AT_AUX_PORT;
2862 if (pBtCoexist->chipInterface == BTC_INTF_PCI)
2863 pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0x384, u1Tmp);
2864 else if (pBtCoexist->chipInterface == BTC_INTF_SDIO)
2865 pBtCoexist->fBtcWriteLocalReg1Byte(pBtCoexist, 0x60, u1Tmp);
2869 void EXhalbtc8723b2ant_InitHwConfig(PBTC_COEXIST pBtCoexist, bool bWifiOnly)
2871 halbtc8723b2ant_InitHwConfig(pBtCoexist, true);
2874 void EXhalbtc8723b2ant_InitCoexDm(PBTC_COEXIST pBtCoexist)
2876 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], Coex Mechanism Init!!\n"));
2878 halbtc8723b2ant_InitCoexDm(pBtCoexist);
2881 void EXhalbtc8723b2ant_DisplayCoexInfo(PBTC_COEXIST pBtCoexist)
2883 PBTC_BOARD_INFO pBoardInfo = &pBtCoexist->boardInfo;
2884 PBTC_STACK_INFO pStackInfo = &pBtCoexist->stackInfo;
2885 PBTC_BT_LINK_INFO pBtLinkInfo = &pBtCoexist->btLinkInfo;
2886 u8 *cliBuf = pBtCoexist->cliBuf;
2887 u8 u1Tmp[4], i, btInfoExt, psTdmaCase = 0;
2889 bool bRoam = false, bScan = false, bLink = false, bWifiUnder5G = false;
2890 bool bBtHsOn = false, bWifiBusy = false;
2891 s32 wifiRssi = 0, btHsRssi = 0;
2892 u32 wifiBw, wifiTrafficDir, faOfdm, faCck;
2893 u8 wifiDot11Chnl, wifiHsChnl;
2894 u32 fwVer = 0, btPatchVer = 0;
2897 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[BT Coexist info]============");
2900 if (pBtCoexist->bManualControl) {
2901 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[Under Manual Control]============");
2903 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ==========================================");
2910 "\r\n %-35s = %d/ %d ", "Ant PG number/ Ant mechanism:", \
2911 pBoardInfo->pgAntNum,
2912 pBoardInfo->btdmAntNum
2919 "\r\n %-35s = %s / %d", "BT stack/ hci ext ver", \
2920 (pStackInfo->bProfileNotified ? "Yes" : "No"),
2921 pStackInfo->hciVersion
2925 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);
2926 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);
2927 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)", "CoexVer/ FwVer/ PatchVer", \
2928 GLCoexVerDate8723b2Ant, GLCoexVer8723b2Ant, fwVer, btPatchVer, btPatchVer);
2931 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);
2932 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_DOT11_CHNL, &wifiDot11Chnl);
2933 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_HS_CHNL, &wifiHsChnl);
2937 "\r\n %-35s = %d / %d(%d)", "Dot11 channel / HsChnl(HsMode)", \
2947 "\r\n %-35s = %02x %02x %02x ", "H2C Wifi inform bt chnl Info", \
2948 pCoexDm->wifiChnlInfo[0],
2949 pCoexDm->wifiChnlInfo[1],
2950 pCoexDm->wifiChnlInfo[2]
2954 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);
2955 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_HS_RSSI, &btHsRssi);
2956 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_AP_NUM, &apNum);
2960 "\r\n %-35s = %d/ %d/ %d", "Wifi rssi/ HS rssi/ AP#", \
2967 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);
2968 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);
2969 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);
2973 "\r\n %-35s = %d/ %d/ %d ", "Wifi bLink/ bRoam/ bScan", \
2980 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_5G, &bWifiUnder5G);
2981 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
2982 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);
2983 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifiTrafficDir);
2987 "\r\n %-35s = %s / %s/ %s ", "Wifi status", \
2988 (bWifiUnder5G ? "5G" : "2.4G"),
2989 ((BTC_WIFI_BW_LEGACY == wifiBw) ? "Legacy" : (((BTC_WIFI_BW_HT40 == wifiBw) ? "HT40" : "HT20"))),
2990 ((!bWifiBusy) ? "idle" : ((BTC_WIFI_TRAFFIC_TX == wifiTrafficDir) ? "uplink" : "downlink"))
2997 "\r\n %-35s = [%s/ %d/ %d] ", "BT [status/ rssi/ retryCnt]", \
2998 ((pBtCoexist->btInfo.bBtDisabled) ? ("disabled") : ((pCoexSta->bC2hBtInquiryPage) ? ("inquiry/page scan") : ((BT_8723B_2ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus) ? "non-connected idle" :
2999 ((BT_8723B_2ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus) ? "connected-idle" : "busy")))),
3001 pCoexSta->btRetryCnt
3008 "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP", \
3009 pBtLinkInfo->bScoExist,
3010 pBtLinkInfo->bHidExist,
3011 pBtLinkInfo->bPanExist,
3012 pBtLinkInfo->bA2dpExist
3015 pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_BT_LINK_INFO);
3017 btInfoExt = pCoexSta->btInfoExt;
3021 "\r\n %-35s = %s", "BT Info A2DP rate", \
3022 (btInfoExt&BIT0) ? "Basic rate" : "EDR rate"
3026 for (i = 0; i < BT_INFO_SRC_8723B_2ANT_MAX; i++) {
3027 if (pCoexSta->btInfoC2hCnt[i]) {
3031 "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", GLBtInfoSrc8723b2Ant[i], \
3032 pCoexSta->btInfoC2h[i][0],
3033 pCoexSta->btInfoC2h[i][1],
3034 pCoexSta->btInfoC2h[i][2],
3035 pCoexSta->btInfoC2h[i][3],
3036 pCoexSta->btInfoC2h[i][4],
3037 pCoexSta->btInfoC2h[i][5],
3038 pCoexSta->btInfoC2h[i][6],
3039 pCoexSta->btInfoC2hCnt[i]
3048 "\r\n %-35s = %s/%s", "PS state, IPS/LPS", \
3049 ((pCoexSta->bUnderIps ? "IPS ON" : "IPS OFF")),
3050 ((pCoexSta->bUnderLps ? "LPS ON" : "LPS OFF"))
3053 pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_FW_PWR_MODE_CMD);
3059 "\r\n %-35s", "============[Sw mechanism]============"
3065 "\r\n %-35s = %d/ %d/ %d ", "SM1[ShRf/ LpRA/ LimDig]", \
3066 pCoexDm->bCurRfRxLpfShrink,
3067 pCoexDm->bCurLowPenaltyRa,
3068 pCoexDm->bLimitedDig
3074 "\r\n %-35s = %d/ %d/ %d(0x%x) ",
3075 "SM2[AgcT/ AdcB/ SwDacSwing(lvl)]", \
3076 pCoexDm->bCurAgcTableEn,
3077 pCoexDm->bCurAdcBackOff,
3078 pCoexDm->bCurDacSwingOn,
3079 pCoexDm->curDacSwingLvl
3084 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw mechanism]============");
3087 psTdmaCase = pCoexDm->curPsTdma;
3091 "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (auto:%d)", "PS TDMA", \
3092 pCoexDm->psTdmaPara[0],
3093 pCoexDm->psTdmaPara[1],
3094 pCoexDm->psTdmaPara[2],
3095 pCoexDm->psTdmaPara[3],
3096 pCoexDm->psTdmaPara[4],
3097 psTdmaCase, pCoexDm->bAutoTdmaAdjust
3104 "\r\n %-35s = %d/ %d ", "DecBtPwr/ IgnWlanAct", \
3105 pCoexDm->curBtDecPwrLvl,
3106 pCoexDm->bCurIgnoreWlanAct
3111 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Hw setting]============");
3117 "\r\n %-35s = 0x%x", "RF-A, 0x1e initVal", \
3118 pCoexDm->btRf0x1eBackup
3122 u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x778);
3123 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x880);
3127 "\r\n %-35s = 0x%x/ 0x%x", "0x778/0x880[29:25]", \
3129 (u4Tmp[0]&0x3e000000) >> 25
3134 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x948);
3135 u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x67);
3136 u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x765);
3140 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x948/ 0x67[5] / 0x765", \
3142 ((u1Tmp[0]&0x20)>>5),
3147 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x92c);
3148 u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x930);
3149 u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x944);
3153 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x92c[1:0]/ 0x930[7:0]/0x944[1:0]", \
3161 u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x39);
3162 u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x40);
3163 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);
3164 u1Tmp[2] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x64);
3168 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0x38[11]/0x40/0x4c[24:23]/0x64[0]", \
3169 ((u1Tmp[0] & 0x8)>>3),
3171 ((u4Tmp[0]&0x01800000)>>23),
3176 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x550);
3177 u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x522);
3181 "\r\n %-35s = 0x%x/ 0x%x", "0x550(bcn ctrl)/0x522", \
3187 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xc50);
3188 u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x49c);
3192 "\r\n %-35s = 0x%x/ 0x%x", "0xc50(dig)/0x49c(null-drop)", \
3198 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda0);
3199 u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda4);
3200 u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda8);
3201 u4Tmp[3] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xcf0);
3203 u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xa5b);
3204 u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0xa5c);
3207 ((u4Tmp[0]&0xffff0000) >> 16) +
3208 ((u4Tmp[1]&0xffff0000) >> 16) +
3209 (u4Tmp[1] & 0xffff) + (u4Tmp[2] & 0xffff) + \
3210 ((u4Tmp[3]&0xffff0000) >> 16) +
3211 (u4Tmp[3] & 0xffff);
3213 faCck = (u1Tmp[0] << 8) + u1Tmp[1];
3218 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "OFDM-CCA/OFDM-FA/CCK-FA", \
3225 u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c0);
3226 u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c4);
3227 u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c8);
3228 u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x6cc);
3232 "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)", \
3243 "\r\n %-35s = %d/ %d", "0x770(high-pri rx/tx)", \
3244 pCoexSta->highPriorityRx,
3245 pCoexSta->highPriorityTx
3251 "\r\n %-35s = %d/ %d", "0x774(low-pri rx/tx)", \
3252 pCoexSta->lowPriorityRx,
3253 pCoexSta->lowPriorityTx
3257 halbtc8723b2ant_MonitorBtCtr(pBtCoexist);
3258 pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_COEX_STATISTICS);
3262 void EXhalbtc8723b2ant_IpsNotify(PBTC_COEXIST pBtCoexist, u8 type)
3264 if (BTC_IPS_ENTER == type) {
3265 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], IPS ENTER notify\n"));
3266 pCoexSta->bUnderIps = true;
3267 halbtc8723b2ant_WifiOffHwCfg(pBtCoexist);
3268 halbtc8723b2ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, true);
3269 halbtc8723b2ant_CoexAllOff(pBtCoexist);
3270 } else if (BTC_IPS_LEAVE == type) {
3271 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], IPS LEAVE notify\n"));
3272 pCoexSta->bUnderIps = false;
3273 halbtc8723b2ant_InitHwConfig(pBtCoexist, false);
3274 halbtc8723b2ant_InitCoexDm(pBtCoexist);
3275 halbtc8723b2ant_QueryBtInfo(pBtCoexist);
3279 void EXhalbtc8723b2ant_LpsNotify(PBTC_COEXIST pBtCoexist, u8 type)
3281 if (BTC_LPS_ENABLE == type) {
3282 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], LPS ENABLE notify\n"));
3283 pCoexSta->bUnderLps = true;
3284 } else if (BTC_LPS_DISABLE == type) {
3285 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], LPS DISABLE notify\n"));
3286 pCoexSta->bUnderLps = false;
3290 void EXhalbtc8723b2ant_ScanNotify(PBTC_COEXIST pBtCoexist, u8 type)
3292 if (BTC_SCAN_START == type) {
3293 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], SCAN START notify\n"));
3294 } else if (BTC_SCAN_FINISH == type) {
3295 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], SCAN FINISH notify\n"));
3299 void EXhalbtc8723b2ant_ConnectNotify(PBTC_COEXIST pBtCoexist, u8 type)
3301 if (BTC_ASSOCIATE_START == type) {
3302 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], CONNECT START notify\n"));
3303 } else if (BTC_ASSOCIATE_FINISH == type) {
3304 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], CONNECT FINISH notify\n"));
3308 void EXhalbtc8723b2ant_MediaStatusNotify(PBTC_COEXIST pBtCoexist, u8 type)
3310 u8 H2C_Parameter[3] = {0};
3315 if (BTC_MEDIA_CONNECT == type) {
3316 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], MEDIA connect notify\n"));
3318 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], MEDIA disconnect notify\n"));
3321 /* only 2.4G we need to inform bt the chnl mask */
3322 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, &wifiCentralChnl);
3323 if ((BTC_MEDIA_CONNECT == type) && (wifiCentralChnl <= 14)) {
3324 H2C_Parameter[0] = 0x1;
3325 H2C_Parameter[1] = wifiCentralChnl;
3326 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);
3327 if (BTC_WIFI_BW_HT40 == wifiBw)
3328 H2C_Parameter[2] = 0x30;
3330 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_AP_NUM, &apNum);
3332 H2C_Parameter[2] = 0x30;
3334 H2C_Parameter[2] = 0x20;
3338 pCoexDm->wifiChnlInfo[0] = H2C_Parameter[0];
3339 pCoexDm->wifiChnlInfo[1] = H2C_Parameter[1];
3340 pCoexDm->wifiChnlInfo[2] = H2C_Parameter[2];
3346 "[BTCoex], FW write 0x66 = 0x%x\n",
3347 H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]
3351 pBtCoexist->fBtcFillH2c(pBtCoexist, 0x66, 3, H2C_Parameter);
3354 void EXhalbtc8723b2ant_SpecialPacketNotify(PBTC_COEXIST pBtCoexist, u8 type)
3356 if (type == BTC_PACKET_DHCP) {
3357 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], DHCP Packet notify\n"));
3361 void EXhalbtc8723b2ant_BtInfoNotify(
3362 PBTC_COEXIST pBtCoexist, u8 *tmpBuf, u8 length
3366 u8 i, rspSource = 0;
3367 bool bBtBusy = false, bLimitedDig = false;
3368 bool bWifiConnected = false;
3370 pCoexSta->bC2hBtInfoReqSent = false;
3372 rspSource = tmpBuf[0]&0xf;
3373 if (rspSource >= BT_INFO_SRC_8723B_2ANT_MAX)
3374 rspSource = BT_INFO_SRC_8723B_2ANT_WIFI_FW;
3376 pCoexSta->btInfoC2hCnt[rspSource]++;
3378 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Bt info[%d], length =%d, hex data =[", rspSource, length));
3379 for (i = 0; i < length; i++) {
3380 pCoexSta->btInfoC2h[rspSource][i] = tmpBuf[i];
3384 if (i == length-1) {
3385 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("0x%02x]\n", tmpBuf[i]));
3387 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("0x%02x, ", tmpBuf[i]));
3391 if (pBtCoexist->bManualControl) {
3392 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), return for Manual CTRL<===\n"));
3396 if (BT_INFO_SRC_8723B_2ANT_WIFI_FW != rspSource) {
3397 pCoexSta->btRetryCnt = pCoexSta->btInfoC2h[rspSource][2]&0xf; /* [3:0] */
3399 pCoexSta->btRssi = pCoexSta->btInfoC2h[rspSource][3]*2+10;
3401 pCoexSta->btInfoExt = pCoexSta->btInfoC2h[rspSource][4];
3403 pCoexSta->bBtTxRxMask = (pCoexSta->btInfoC2h[rspSource][2]&0x40);
3404 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TX_RX_MASK, &pCoexSta->bBtTxRxMask);
3405 if (pCoexSta->bBtTxRxMask) {
3406 /* BT into is responded by BT FW and BT RF REG 0x3C != 0x01 => Need to switch BT TRx Mask */
3407 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Switch BT TRx Mask since BT RF REG 0x3C != 0x01\n"));
3408 pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x3c, 0x01);
3411 /* Here we need to resend some wifi info to BT */
3412 /* because bt is reset and loss of the info. */
3413 if ((pCoexSta->btInfoExt & BIT1)) {
3414 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"));
3415 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);
3418 EXhalbtc8723b2ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_CONNECT);
3420 EXhalbtc8723b2ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);
3423 if ((pCoexSta->btInfoExt & BIT3)) {
3424 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n"));
3425 halbtc8723b2ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, false);
3427 /* BT already NOT ignore Wlan active, do nothing here. */
3431 /* check BIT2 first ==> check if bt is under inquiry or page scan */
3432 if (btInfo & BT_INFO_8723B_2ANT_B_INQ_PAGE)
3433 pCoexSta->bC2hBtInquiryPage = true;
3435 pCoexSta->bC2hBtInquiryPage = false;
3437 /* set link exist status */
3438 if (!(btInfo&BT_INFO_8723B_2ANT_B_CONNECTION)) {
3439 pCoexSta->bBtLinkExist = false;
3440 pCoexSta->bPanExist = false;
3441 pCoexSta->bA2dpExist = false;
3442 pCoexSta->bHidExist = false;
3443 pCoexSta->bScoExist = false;
3444 } else { /* connection exists */
3445 pCoexSta->bBtLinkExist = true;
3446 if (btInfo & BT_INFO_8723B_2ANT_B_FTP)
3447 pCoexSta->bPanExist = true;
3449 pCoexSta->bPanExist = false;
3450 if (btInfo & BT_INFO_8723B_2ANT_B_A2DP)
3451 pCoexSta->bA2dpExist = true;
3453 pCoexSta->bA2dpExist = false;
3454 if (btInfo & BT_INFO_8723B_2ANT_B_HID)
3455 pCoexSta->bHidExist = true;
3457 pCoexSta->bHidExist = false;
3458 if (btInfo & BT_INFO_8723B_2ANT_B_SCO_ESCO)
3459 pCoexSta->bScoExist = true;
3461 pCoexSta->bScoExist = false;
3464 halbtc8723b2ant_UpdateBtLinkInfo(pBtCoexist);
3466 if (!(btInfo&BT_INFO_8723B_2ANT_B_CONNECTION)) {
3467 pCoexDm->btStatus = BT_8723B_2ANT_BT_STATUS_NON_CONNECTED_IDLE;
3468 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n"));
3469 } else if (btInfo == BT_INFO_8723B_2ANT_B_CONNECTION) { /* connection exists but no busy */
3470 pCoexDm->btStatus = BT_8723B_2ANT_BT_STATUS_CONNECTED_IDLE;
3471 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n"));
3473 (btInfo&BT_INFO_8723B_2ANT_B_SCO_ESCO) ||
3474 (btInfo&BT_INFO_8723B_2ANT_B_SCO_BUSY)
3476 pCoexDm->btStatus = BT_8723B_2ANT_BT_STATUS_SCO_BUSY;
3477 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT SCO busy!!!\n"));
3478 } else if (btInfo&BT_INFO_8723B_2ANT_B_ACL_BUSY) {
3479 pCoexDm->btStatus = BT_8723B_2ANT_BT_STATUS_ACL_BUSY;
3480 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT ACL busy!!!\n"));
3482 pCoexDm->btStatus = BT_8723B_2ANT_BT_STATUS_MAX;
3483 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n"));
3487 (BT_8723B_2ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus) ||
3488 (BT_8723B_2ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||
3489 (BT_8723B_2ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus)
3495 bLimitedDig = false;
3498 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);
3500 pCoexDm->bLimitedDig = bLimitedDig;
3501 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_LIMITED_DIG, &bLimitedDig);
3503 halbtc8723b2ant_RunCoexistMechanism(pBtCoexist);
3506 void EXhalbtc8723b2ant_HaltNotify(PBTC_COEXIST pBtCoexist)
3508 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Halt notify\n"));
3510 halbtc8723b2ant_WifiOffHwCfg(pBtCoexist);
3511 pBtCoexist->fBtcSetBtReg(pBtCoexist, BTC_BT_REG_RF, 0x3c, 0x15); /* BT goto standby while GNT_BT 1-->0 */
3512 halbtc8723b2ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, true);
3514 EXhalbtc8723b2ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);
3517 void EXhalbtc8723b2ant_PnpNotify(PBTC_COEXIST pBtCoexist, u8 pnpState)
3519 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Pnp notify\n"));
3521 if (BTC_WIFI_PNP_SLEEP == pnpState) {
3522 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Pnp notify to SLEEP\n"));
3523 } else if (BTC_WIFI_PNP_WAKE_UP == pnpState) {
3524 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Pnp notify to WAKE UP\n"));
3525 halbtc8723b2ant_InitHwConfig(pBtCoexist, false);
3526 halbtc8723b2ant_InitCoexDm(pBtCoexist);
3527 halbtc8723b2ant_QueryBtInfo(pBtCoexist);
3531 void EXhalbtc8723b2ant_Periodical(PBTC_COEXIST pBtCoexist)
3533 static u8 disVerInfoCnt;
3534 u32 fwVer = 0, btPatchVer = 0;
3536 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], ==========================Periodical ===========================\n"));
3538 if (disVerInfoCnt <= 5) {
3540 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], ****************************************************************\n"));
3541 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);
3542 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);
3543 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], CoexVer/ FwVer/ PatchVer = %d_%x/ 0x%x/ 0x%x(%d)\n", \
3544 GLCoexVerDate8723b2Ant, GLCoexVer8723b2Ant, fwVer, btPatchVer, btPatchVer));
3545 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], ****************************************************************\n"));
3549 halbtc8723b2ant_IsWifiStatusChanged(pBtCoexist) ||
3550 pCoexDm->bAutoTdmaAdjust
3552 halbtc8723b2ant_RunCoexistMechanism(pBtCoexist);