1 //============================================================
4 // This file is for RTL8723A Co-exist mechanism
7 // 2012/08/22 Cosa first check in.
8 // 2012/11/14 Cosa Revise for 8723A 1Ant out sourcing.
10 //============================================================
12 //============================================================
14 //============================================================
15 #include "Mp_Precomp.h"
16 #if(BT_30_SUPPORT == 1)
17 //============================================================
18 // Global variables, these are static variables
19 //============================================================
20 static COEX_DM_8723A_1ANT GLCoexDm8723a1Ant
;
21 static PCOEX_DM_8723A_1ANT pCoexDm
=&GLCoexDm8723a1Ant
;
22 static COEX_STA_8723A_1ANT GLCoexSta8723a1Ant
;
23 static PCOEX_STA_8723A_1ANT pCoexSta
=&GLCoexSta8723a1Ant
;
25 const char *const GLBtInfoSrc8723a1Ant
[]={
28 "BT Info[bt auto report]",
31 //============================================================
32 // local function proto type if needed
33 //============================================================
34 //============================================================
35 // local function start with halbtc8723a1ant_
36 //============================================================
38 halbtc8723a1ant_Reg0x550Bit3(
39 IN PBTC_COEXIST pBtCoexist
,
45 u1tmp
= pBtCoexist
->btc_read_1byte(pBtCoexist
, 0x550);
54 pBtCoexist
->btc_write_1byte(pBtCoexist
, 0x550, u1tmp
);
55 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
, ("[BTCoex], set 0x550[3]=%d\n", (bSet
? 1:0)));
59 halbtc8723a1ant_NotifyFwScan(
60 IN PBTC_COEXIST pBtCoexist
,
64 u1Byte H2C_Parameter
[1] ={0};
66 if(BTC_SCAN_START
== scanType
)
67 H2C_Parameter
[0] = 0x1;
69 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_FW_EXEC
, ("[BTCoex], Notify FW for wifi scan, write 0x3b=0x%x\n",
72 pBtCoexist
->btc_fill_h2c(pBtCoexist
, 0x3b, 1, H2C_Parameter
);
76 halbtc8723a1ant_QueryBtInfo(
77 IN PBTC_COEXIST pBtCoexist
80 u1Byte H2C_Parameter
[1] ={0};
82 pCoexSta
->bC2hBtInfoReqSent
= true;
84 H2C_Parameter
[0] |= BIT0
; // trigger
86 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_FW_EXEC
, ("[BTCoex], Query Bt Info, FW write 0x38=0x%x\n",
89 pBtCoexist
->btc_fill_h2c(pBtCoexist
, 0x38, 1, H2C_Parameter
);
93 halbtc8723a1ant_SetSwRfRxLpfCorner(
94 IN PBTC_COEXIST pBtCoexist
,
95 IN BOOLEAN bRxRfShrinkOn
100 //Shrink RF Rx LPF corner
101 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_SW_EXEC
, ("[BTCoex], Shrink RF Rx LPF corner!!\n"));
102 pBtCoexist
->btc_set_rf_reg(pBtCoexist
, BTC_RF_A
, 0x1e, 0xfffff, 0xf0ff7);
106 //Resume RF Rx LPF corner
107 // After initialized, we can use pCoexDm->btRf0x1eBackup
108 if(pBtCoexist
->initilized
)
110 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_SW_EXEC
, ("[BTCoex], Resume RF Rx LPF corner!!\n"));
111 pBtCoexist
->btc_set_rf_reg(pBtCoexist
, BTC_RF_A
, 0x1e, 0xfffff, pCoexDm
->btRf0x1eBackup
);
117 halbtc8723a1ant_RfShrink(
118 IN PBTC_COEXIST pBtCoexist
,
119 IN BOOLEAN bForceExec
,
120 IN BOOLEAN bRxRfShrinkOn
123 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_SW
, ("[BTCoex], %s turn Rx RF Shrink = %s\n",
124 (bForceExec
? "force to":""), ((bRxRfShrinkOn
)? "ON":"OFF")));
125 pCoexDm
->bCurRfRxLpfShrink
= bRxRfShrinkOn
;
129 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_SW_DETAIL
, ("[BTCoex], bPreRfRxLpfShrink=%d, bCurRfRxLpfShrink=%d\n",
130 pCoexDm
->bPreRfRxLpfShrink
, pCoexDm
->bCurRfRxLpfShrink
));
132 if(pCoexDm
->bPreRfRxLpfShrink
== pCoexDm
->bCurRfRxLpfShrink
)
135 halbtc8723a1ant_SetSwRfRxLpfCorner(pBtCoexist
, pCoexDm
->bCurRfRxLpfShrink
);
137 pCoexDm
->bPreRfRxLpfShrink
= pCoexDm
->bCurRfRxLpfShrink
;
141 halbtc8723a1ant_SetSwPenaltyTxRateAdaptive(
142 IN PBTC_COEXIST pBtCoexist
,
143 IN BOOLEAN bLowPenaltyRa
148 tmpU1
= pBtCoexist
->btc_read_1byte(pBtCoexist
, 0x4fd);
152 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_SW_EXEC
, ("[BTCoex], Tx rate adaptive, set low penalty!!\n"));
157 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_SW_EXEC
, ("[BTCoex], Tx rate adaptive, set normal!!\n"));
161 pBtCoexist
->btc_write_1byte(pBtCoexist
, 0x4fd, tmpU1
);
165 halbtc8723a1ant_LowPenaltyRa(
166 IN PBTC_COEXIST pBtCoexist
,
167 IN BOOLEAN bForceExec
,
168 IN BOOLEAN bLowPenaltyRa
172 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_SW
, ("[BTCoex], %s turn LowPenaltyRA = %s\n",
173 (bForceExec
? "force to":""), ((bLowPenaltyRa
)? "ON":"OFF")));
174 pCoexDm
->bCurLowPenaltyRa
= bLowPenaltyRa
;
178 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_SW_DETAIL
, ("[BTCoex], bPreLowPenaltyRa=%d, bCurLowPenaltyRa=%d\n",
179 pCoexDm
->bPreLowPenaltyRa
, pCoexDm
->bCurLowPenaltyRa
));
181 if(pCoexDm
->bPreLowPenaltyRa
== pCoexDm
->bCurLowPenaltyRa
)
184 halbtc8723a1ant_SetSwPenaltyTxRateAdaptive(pBtCoexist
, pCoexDm
->bCurLowPenaltyRa
);
186 pCoexDm
->bPreLowPenaltyRa
= pCoexDm
->bCurLowPenaltyRa
;
190 halbtc8723a1ant_SetCoexTable(
191 IN PBTC_COEXIST pBtCoexist
,
197 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_SW_EXEC
, ("[BTCoex], set coex table, set 0x6c0=0x%x\n", val0x6c0
));
198 pBtCoexist
->btc_write_4byte(pBtCoexist
, 0x6c0, val0x6c0
);
200 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_SW_EXEC
, ("[BTCoex], set coex table, set 0x6c8=0x%x\n", val0x6c8
));
201 pBtCoexist
->btc_write_4byte(pBtCoexist
, 0x6c8, val0x6c8
);
203 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_SW_EXEC
, ("[BTCoex], set coex table, set 0x6cc=0x%x\n", val0x6cc
));
204 pBtCoexist
->btc_write_1byte(pBtCoexist
, 0x6cc, val0x6cc
);
208 halbtc8723a1ant_CoexTable(
209 IN PBTC_COEXIST pBtCoexist
,
210 IN BOOLEAN bForceExec
,
216 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_SW
, ("[BTCoex], %s write Coex Table 0x6c0=0x%x, 0x6c8=0x%x, 0x6cc=0x%x\n",
217 (bForceExec
? "force to":""), val0x6c0
, val0x6c8
, val0x6cc
));
218 pCoexDm
->curVal0x6c0
= val0x6c0
;
219 pCoexDm
->curVal0x6c8
= val0x6c8
;
220 pCoexDm
->curVal0x6cc
= val0x6cc
;
224 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_SW_DETAIL
, ("[BTCoex], preVal0x6c0=0x%x, preVal0x6c8=0x%x, preVal0x6cc=0x%x !!\n",
225 pCoexDm
->preVal0x6c0
, pCoexDm
->preVal0x6c8
, pCoexDm
->preVal0x6cc
));
226 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_SW_DETAIL
, ("[BTCoex], curVal0x6c0=0x%x, curVal0x6c8=0x%x, curVal0x6cc=0x%x !!\n",
227 pCoexDm
->curVal0x6c0
, pCoexDm
->curVal0x6c8
, pCoexDm
->curVal0x6cc
));
229 if( (pCoexDm
->preVal0x6c0
== pCoexDm
->curVal0x6c0
) &&
230 (pCoexDm
->preVal0x6c8
== pCoexDm
->curVal0x6c8
) &&
231 (pCoexDm
->preVal0x6cc
== pCoexDm
->curVal0x6cc
) )
234 halbtc8723a1ant_SetCoexTable(pBtCoexist
, val0x6c0
, val0x6c8
, val0x6cc
);
236 pCoexDm
->preVal0x6c0
= pCoexDm
->curVal0x6c0
;
237 pCoexDm
->preVal0x6c8
= pCoexDm
->curVal0x6c8
;
238 pCoexDm
->preVal0x6cc
= pCoexDm
->curVal0x6cc
;
242 halbtc8723a1ant_SetFwIgnoreWlanAct(
243 IN PBTC_COEXIST pBtCoexist
,
247 u1Byte H2C_Parameter
[1] ={0};
251 H2C_Parameter
[0] |= BIT0
; // function enable
254 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_FW_EXEC
, ("[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x25=0x%x\n",
257 pBtCoexist
->btc_fill_h2c(pBtCoexist
, 0x25, 1, H2C_Parameter
);
261 halbtc8723a1ant_IgnoreWlanAct(
262 IN PBTC_COEXIST pBtCoexist
,
263 IN BOOLEAN bForceExec
,
267 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_FW
, ("[BTCoex], %s turn Ignore WlanAct %s\n",
268 (bForceExec
? "force to":""), (bEnable
? "ON":"OFF")));
269 pCoexDm
->bCurIgnoreWlanAct
= bEnable
;
273 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_FW_DETAIL
, ("[BTCoex], bPreIgnoreWlanAct = %d, bCurIgnoreWlanAct = %d!!\n",
274 pCoexDm
->bPreIgnoreWlanAct
, pCoexDm
->bCurIgnoreWlanAct
));
276 if(pCoexDm
->bPreIgnoreWlanAct
== pCoexDm
->bCurIgnoreWlanAct
)
279 halbtc8723a1ant_SetFwIgnoreWlanAct(pBtCoexist
, bEnable
);
281 pCoexDm
->bPreIgnoreWlanAct
= pCoexDm
->bCurIgnoreWlanAct
;
285 halbtc8723a1ant_SetFwPstdma(
286 IN PBTC_COEXIST pBtCoexist
,
295 u1Byte H2C_Parameter
[5] ={0};
296 u1Byte realByte1
=byte1
, realByte5
=byte5
;
297 BOOLEAN bApEnable
=FALSE
;
299 pBtCoexist
->btc_get(pBtCoexist
, BTC_GET_BL_WIFI_AP_MODE_ENABLE
, &bApEnable
);
301 // byte1[1:0] != 0 means enable pstdma
302 // for 2Ant bt coexist, if byte1 != 0 means enable pstdma
307 if(type
!= 5 && type
!= 12)
309 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
, ("[BTCoex], FW for 1Ant AP mode\n"));
318 H2C_Parameter
[0] = realByte1
;
319 H2C_Parameter
[1] = byte2
;
320 H2C_Parameter
[2] = byte3
;
321 H2C_Parameter
[3] = byte4
;
322 H2C_Parameter
[4] = realByte5
;
324 pCoexDm
->psTdmaPara
[0] = realByte1
;
325 pCoexDm
->psTdmaPara
[1] = byte2
;
326 pCoexDm
->psTdmaPara
[2] = byte3
;
327 pCoexDm
->psTdmaPara
[3] = byte4
;
328 pCoexDm
->psTdmaPara
[4] = realByte5
;
330 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_FW_EXEC
, ("[BTCoex], FW write 0x3a(5bytes)=0x%x%08x\n",
332 H2C_Parameter
[1]<<24|H2C_Parameter
[2]<<16|H2C_Parameter
[3]<<8|H2C_Parameter
[4]));
334 pBtCoexist
->btc_fill_h2c(pBtCoexist
, 0x3a, 5, H2C_Parameter
);
338 halbtc8723a1ant_PsTdma(
339 IN PBTC_COEXIST pBtCoexist
,
340 IN BOOLEAN bForceExec
,
345 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_FW
, ("[BTCoex], %s turn %s PS TDMA, type=%d\n",
346 (bForceExec
? "force to":""), (bTurnOn
? "ON":"OFF"), type
));
347 pCoexDm
->bCurPsTdmaOn
= bTurnOn
;
348 pCoexDm
->curPsTdma
= type
;
352 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_FW_DETAIL
, ("[BTCoex], bPrePsTdmaOn = %d, bCurPsTdmaOn = %d!!\n",
353 pCoexDm
->bPrePsTdmaOn
, pCoexDm
->bCurPsTdmaOn
));
354 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE_FW_DETAIL
, ("[BTCoex], prePsTdma = %d, curPsTdma = %d!!\n",
355 pCoexDm
->prePsTdma
, pCoexDm
->curPsTdma
));
357 if( (pCoexDm
->bPrePsTdmaOn
== pCoexDm
->bCurPsTdmaOn
) &&
358 (pCoexDm
->prePsTdma
== pCoexDm
->curPsTdma
) )
361 if(pCoexDm
->bCurPsTdmaOn
)
363 switch(pCoexDm
->curPsTdma
)
367 halbtc8723a1ant_SetFwPstdma(pBtCoexist
, type
, 0x13, 0x1a, 0x1a, 0x0, 0x40);
370 halbtc8723a1ant_SetFwPstdma(pBtCoexist
, type
, 0x13, 0x12, 0x12, 0x0, 0x40);
373 halbtc8723a1ant_SetFwPstdma(pBtCoexist
, type
, 0x93, 0x3f, 0x3, 0x10, 0x40);
376 halbtc8723a1ant_SetFwPstdma(pBtCoexist
, type
, 0x93, 0x15, 0x3, 0x10, 0x0);
379 halbtc8723a1ant_SetFwPstdma(pBtCoexist
, type
, 0xa9, 0x15, 0x3, 0x35, 0xc0);
383 halbtc8723a1ant_SetFwPstdma(pBtCoexist
, type
, 0x93, 0x25, 0x3, 0x10, 0x0);
386 halbtc8723a1ant_SetFwPstdma(pBtCoexist
, type
, 0x13, 0xa, 0xa, 0x0, 0x40);
389 halbtc8723a1ant_SetFwPstdma(pBtCoexist
, type
, 0x13, 0xa, 0xa, 0x0, 0x40);
392 halbtc8723a1ant_SetFwPstdma(pBtCoexist
, type
, 0x13, 0x5, 0x5, 0x0, 0x40);
395 halbtc8723a1ant_SetFwPstdma(pBtCoexist
, type
, 0xa9, 0xa, 0x3, 0x15, 0xc0);
399 halbtc8723a1ant_SetFwPstdma(pBtCoexist
, type
, 0x93, 0x25, 0x3, 0x10, 0x0);
403 halbtc8723a1ant_SetFwPstdma(pBtCoexist
, type
, 0x13, 0x2a, 0x2a, 0x0, 0x0);
406 halbtc8723a1ant_SetFwPstdma(pBtCoexist
, type
, 0x93, 0x20, 0x3, 0x10, 0x40);
409 halbtc8723a1ant_SetFwPstdma(pBtCoexist
, type
, 0x13, 0x1a, 0x1a, 0x2, 0x40);
412 halbtc8723a1ant_SetFwPstdma(pBtCoexist
, type
, 0x13, 0x12, 0x12, 0x2, 0x40);
415 halbtc8723a1ant_SetFwPstdma(pBtCoexist
, type
, 0x13, 0xa, 0xa, 0x2, 0x40);
418 halbtc8723a1ant_SetFwPstdma(pBtCoexist
, type
, 0x13, 0x5, 0x5, 0x2, 0x40);
421 halbtc8723a1ant_SetFwPstdma(pBtCoexist
, type
, 0x93, 0x25, 0x3, 0x10, 0x0);
424 halbtc8723a1ant_SetFwPstdma(pBtCoexist
, type
, 0x13, 0x5, 0x5, 0x2, 0x40);
427 halbtc8723a1ant_SetFwPstdma(pBtCoexist
, type
, 0x3, 0x2f, 0x2f, 0x0, 0x0);
435 switch(pCoexDm
->curPsTdma
)
438 halbtc8723a1ant_SetFwPstdma(pBtCoexist
, type
, 0x8, 0x0, 0x0, 0x0, 0x0);
442 halbtc8723a1ant_SetFwPstdma(pBtCoexist
, type
, 0x0, 0x0, 0x0, 0x0, 0x0);
443 pBtCoexist
->btc_write_2byte(pBtCoexist
, 0x860, 0x210);
446 halbtc8723a1ant_SetFwPstdma(pBtCoexist
, type
, 0x0, 0x0, 0x0, 0x0, 0x0);
447 pBtCoexist
->btc_write_2byte(pBtCoexist
, 0x860, 0x110);
454 pCoexDm
->bPrePsTdmaOn
= pCoexDm
->bCurPsTdmaOn
;
455 pCoexDm
->prePsTdma
= pCoexDm
->curPsTdma
;
460 halbtc8723a1ant_CoexAllOff(
461 IN PBTC_COEXIST pBtCoexist
465 halbtc8723a1ant_IgnoreWlanAct(pBtCoexist
, NORMAL_EXEC
, FALSE
);
466 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, FALSE
, 0);
469 halbtc8723a1ant_LowPenaltyRa(pBtCoexist
, NORMAL_EXEC
, FALSE
);
470 halbtc8723a1ant_RfShrink(pBtCoexist
, NORMAL_EXEC
, FALSE
);
473 halbtc8723a1ant_CoexTable(pBtCoexist
, NORMAL_EXEC
, 0x55555555, 0xffff, 0x3);
477 halbtc8723a1ant_InitCoexDm(
478 IN PBTC_COEXIST pBtCoexist
481 // force to reset coex mechanism
482 halbtc8723a1ant_IgnoreWlanAct(pBtCoexist
, FORCE_EXEC
, FALSE
);
486 halbtc8723a1ant_BtEnableAction(
487 IN PBTC_COEXIST pBtCoexist
490 halbtc8723a1ant_IgnoreWlanAct(pBtCoexist
, FORCE_EXEC
, FALSE
);
494 halbtc8723a1ant_MonitorBtCtr(
495 IN PBTC_COEXIST pBtCoexist
498 u4Byte regHPTxRx
, regLPTxRx
, u4Tmp
;
499 u4Byte regHPTx
=0, regHPRx
=0, regLPTx
=0, regLPRx
=0;
505 u4Tmp
= pBtCoexist
->btc_read_4byte(pBtCoexist
, regHPTxRx
);
506 regHPTx
= u4Tmp
& MASKLWORD
;
507 regHPRx
= (u4Tmp
& MASKHWORD
)>>16;
509 u4Tmp
= pBtCoexist
->btc_read_4byte(pBtCoexist
, regLPTxRx
);
510 regLPTx
= u4Tmp
& MASKLWORD
;
511 regLPRx
= (u4Tmp
& MASKHWORD
)>>16;
513 pCoexSta
->highPriorityTx
= regHPTx
;
514 pCoexSta
->highPriorityRx
= regHPRx
;
515 pCoexSta
->lowPriorityTx
= regLPTx
;
516 pCoexSta
->lowPriorityRx
= regLPRx
;
518 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_BT_MONITOR
, ("[BTCoex], High Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n",
519 regHPTxRx
, regHPTx
, regHPTx
, regHPRx
, regHPRx
));
520 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_BT_MONITOR
, ("[BTCoex], Low Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n",
521 regLPTxRx
, regLPTx
, regLPTx
, regLPRx
, regLPRx
));
524 pBtCoexist
->btc_write_1byte(pBtCoexist
, 0x76e, 0xc);
528 halbtc8723a1ant_MonitorBtEnableDisable(
529 IN PBTC_COEXIST pBtCoexist
532 static BOOLEAN bPreBtDisabled
=FALSE
;
533 static u4Byte btDisableCnt
=0;
534 BOOLEAN bBtActive
=true, bBtDisabled
=FALSE
;
536 // This function check if bt is disabled
538 if( pCoexSta
->highPriorityTx
== 0 &&
539 pCoexSta
->highPriorityRx
== 0 &&
540 pCoexSta
->lowPriorityTx
== 0 &&
541 pCoexSta
->lowPriorityRx
== 0)
545 if( pCoexSta
->highPriorityTx
== 0xffff &&
546 pCoexSta
->highPriorityRx
== 0xffff &&
547 pCoexSta
->lowPriorityTx
== 0xffff &&
548 pCoexSta
->lowPriorityRx
== 0xffff)
556 pBtCoexist
->btc_set(pBtCoexist
, BTC_SET_BL_BT_DISABLE
, &bBtDisabled
);
557 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_BT_MONITOR
, ("[BTCoex], BT is enabled !!\n"));
562 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_BT_MONITOR
, ("[BTCoex], bt all counters=0, %d times!!\n",
564 if(btDisableCnt
>= 2)
567 pBtCoexist
->btc_set(pBtCoexist
, BTC_SET_BL_BT_DISABLE
, &bBtDisabled
);
568 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_BT_MONITOR
, ("[BTCoex], BT is disabled !!\n"));
571 if(bPreBtDisabled
!= bBtDisabled
)
573 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_BT_MONITOR
, ("[BTCoex], BT is from %s to %s!!\n",
574 (bPreBtDisabled
? "disabled":"enabled"),
575 (bBtDisabled
? "disabled":"enabled")));
576 bPreBtDisabled
= bBtDisabled
;
579 halbtc8723a1ant_BtEnableAction(pBtCoexist
);
583 pBtCoexist
->btc_set(pBtCoexist
, BTC_SET_ACT_NORMAL_LPS
, NULL
);
589 halbtc8723a1ant_TdmaDurationAdjust(
590 IN PBTC_COEXIST pBtCoexist
593 static s4Byte up
,dn
,m
,n
,WaitCount
;
594 s4Byte result
; //0: no change, +1: increase WiFi duration, -1: decrease WiFi duration
597 BOOLEAN bScan
=FALSE
, bLink
=FALSE
, bRoam
=FALSE
;
600 pBtCoexist
->btc_get(pBtCoexist
, BTC_GET_U4_WIFI_BW
, &wifiBw
);
601 btState
= pCoexDm
->btStatus
;
603 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
, ("[BTCoex], TdmaDurationAdjust()\n"));
604 if(pCoexDm
->psTdmaGlobalCnt
!= pCoexDm
->psTdmaMonitorCnt
)
606 pCoexDm
->psTdmaMonitorCnt
= 0;
607 pCoexDm
->psTdmaGlobalCnt
= 0;
609 if(pCoexDm
->psTdmaMonitorCnt
== 0)
611 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
, ("[BTCoex], first run BT A2DP + WiFi busy state!!\n"));
612 if(btState
== BT_STATE_8723A_1ANT_ACL_ONLY_BUSY
)
614 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, true, 1);
615 pCoexDm
->psTdmaDuAdjType
= 1;
619 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, true, 22);
620 pCoexDm
->psTdmaDuAdjType
= 22;
632 //acquire the BT TRx retry count from BT_Info byte2
633 retryCount
= pCoexSta
->btRetryCnt
;
634 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
, ("[BTCoex], retryCount = %d\n", retryCount
));
638 if(retryCount
== 0) // no retry in the last 2-second duration
646 if(up
>= n
) // if ³sÄò n Ó2¬í retry count¬°0, «h½Õ¼eWiFi duration
653 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
, ("[BTCoex], Increase wifi duration!!\n"));
656 else if (retryCount
<= 3) // <=3 retry in the last 2-second duration
664 if (dn
== 2) // if ³sÄò 2 Ó2¬í retry count< 3, «h½Õ¯¶WiFi duration
667 m
++; // ÁקK¤@ª½¦b¨âÓlevel¤¤¨Ó¦^
671 if ( m
>= 20) //m ³Ì¤jÈ = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration.
679 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
, ("[BTCoex], Decrease wifi duration for retryCounter<3!!\n"));
682 else //retry count > 3, ¥un1¦¸ retry count > 3, «h½Õ¯¶WiFi duration
685 m
++; // ÁקK¤@ª½¦b¨âÓlevel¤¤¨Ó¦^
689 if ( m
>= 20) //m ³Ì¤jÈ = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration.
697 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
, ("[BTCoex], Decrease wifi duration for retryCounter>3!!\n"));
701 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
, ("[BTCoex], BT TxRx counter H+L <= 1200\n"));
702 if(btState
!= BT_STATE_8723A_1ANT_ACL_ONLY_BUSY
)
704 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
, ("[BTCoex], NOT ACL only busy!\n"));
705 if(BTC_WIFI_BW_HT40
!= wifiBw
)
707 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
, ("[BTCoex], 20MHz\n"));
710 if(pCoexDm
->curPsTdma
== 22)
712 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, true, 23);
713 pCoexDm
->psTdmaDuAdjType
= 23;
715 else if(pCoexDm
->curPsTdma
== 23)
717 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, true, 24);
718 pCoexDm
->psTdmaDuAdjType
= 24;
720 else if(pCoexDm
->curPsTdma
== 24)
722 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, true, 25);
723 pCoexDm
->psTdmaDuAdjType
= 25;
726 else if (result
== 1)
728 if(pCoexDm
->curPsTdma
== 25)
730 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, true, 24);
731 pCoexDm
->psTdmaDuAdjType
= 24;
733 else if(pCoexDm
->curPsTdma
== 24)
735 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, true, 23);
736 pCoexDm
->psTdmaDuAdjType
= 23;
738 else if(pCoexDm
->curPsTdma
== 23)
740 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, true, 22);
741 pCoexDm
->psTdmaDuAdjType
= 22;
744 // error handle, if not in the following state,
746 if( (pCoexDm
->psTdmaDuAdjType
!= 22) &&
747 (pCoexDm
->psTdmaDuAdjType
!= 23) &&
748 (pCoexDm
->psTdmaDuAdjType
!= 24) &&
749 (pCoexDm
->psTdmaDuAdjType
!= 25) )
751 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
, ("[BTCoex], duration case out of handle!!\n"));
752 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, true, 23);
753 pCoexDm
->psTdmaDuAdjType
= 23;
758 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
, ("[BTCoex], 40MHz\n"));
761 if(pCoexDm
->curPsTdma
== 23)
763 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, true, 24);
764 pCoexDm
->psTdmaDuAdjType
= 24;
766 else if(pCoexDm
->curPsTdma
== 24)
768 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, true, 25);
769 pCoexDm
->psTdmaDuAdjType
= 25;
771 else if(pCoexDm
->curPsTdma
== 25)
773 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, true, 27);
774 pCoexDm
->psTdmaDuAdjType
= 27;
777 else if (result
== 1)
779 if(pCoexDm
->curPsTdma
== 27)
781 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, true, 25);
782 pCoexDm
->psTdmaDuAdjType
= 25;
784 else if(pCoexDm
->curPsTdma
== 25)
786 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, true, 24);
787 pCoexDm
->psTdmaDuAdjType
= 24;
789 else if(pCoexDm
->curPsTdma
== 24)
791 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, true, 23);
792 pCoexDm
->psTdmaDuAdjType
= 23;
795 // error handle, if not in the following state,
797 if( (pCoexDm
->psTdmaDuAdjType
!= 23) &&
798 (pCoexDm
->psTdmaDuAdjType
!= 24) &&
799 (pCoexDm
->psTdmaDuAdjType
!= 25) &&
800 (pCoexDm
->psTdmaDuAdjType
!= 27) )
802 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
, ("[BTCoex], duration case out of handle!!\n"));
803 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, true, 24);
804 pCoexDm
->psTdmaDuAdjType
= 24;
810 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
, ("[BTCoex], ACL only busy\n"));
813 if(pCoexDm
->curPsTdma
== 1)
815 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, true, 2);
816 pCoexDm
->psTdmaDuAdjType
= 2;
818 else if(pCoexDm
->curPsTdma
== 2)
820 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, true, 9);
821 pCoexDm
->psTdmaDuAdjType
= 9;
823 else if(pCoexDm
->curPsTdma
== 9)
825 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, true, 11);
826 pCoexDm
->psTdmaDuAdjType
= 11;
829 else if (result
== 1)
831 if(pCoexDm
->curPsTdma
== 11)
833 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, true, 9);
834 pCoexDm
->psTdmaDuAdjType
= 9;
836 else if(pCoexDm
->curPsTdma
== 9)
838 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, true, 2);
839 pCoexDm
->psTdmaDuAdjType
= 2;
841 else if(pCoexDm
->curPsTdma
== 2)
843 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, true, 1);
844 pCoexDm
->psTdmaDuAdjType
= 1;
848 // error handle, if not in the following state,
850 if( (pCoexDm
->psTdmaDuAdjType
!= 1) &&
851 (pCoexDm
->psTdmaDuAdjType
!= 2) &&
852 (pCoexDm
->psTdmaDuAdjType
!= 9) &&
853 (pCoexDm
->psTdmaDuAdjType
!= 11) )
855 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
, ("[BTCoex], duration case out of handle!!\n"));
856 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, true, 2);
857 pCoexDm
->psTdmaDuAdjType
= 2;
863 // if current PsTdma not match with the recorded one (when scan, dhcp...),
864 // then we have to adjust it back to the previous record one.
865 if(pCoexDm
->curPsTdma
!= pCoexDm
->psTdmaDuAdjType
)
867 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
, ("[BTCoex], PsTdma type dismatch!!!, curPsTdma=%d, recordPsTdma=%d\n",
868 pCoexDm
->curPsTdma
, pCoexDm
->psTdmaDuAdjType
));
870 pBtCoexist
->btc_get(pBtCoexist
, BTC_GET_BL_WIFI_SCAN
, &bScan
);
871 pBtCoexist
->btc_get(pBtCoexist
, BTC_GET_BL_WIFI_LINK
, &bLink
);
872 pBtCoexist
->btc_get(pBtCoexist
, BTC_GET_BL_WIFI_ROAM
, &bRoam
);
874 if( !bScan
&& !bLink
&& !bRoam
)
876 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, true, pCoexDm
->psTdmaDuAdjType
);
880 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
, ("[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n"));
883 pCoexDm
->psTdmaMonitorCnt
++;
888 halbtc8723a1ant_CoexForWifiConnect(
889 IN PBTC_COEXIST pBtCoexist
892 BOOLEAN bWifiConnected
=FALSE
, bWifiBusy
=FALSE
;
893 u1Byte btState
, btInfoOriginal
=0;
895 pBtCoexist
->btc_get(pBtCoexist
, BTC_GET_BL_WIFI_CONNECTED
, &bWifiConnected
);
897 btState
= pCoexDm
->btStatus
;
898 btInfoOriginal
= pCoexSta
->btInfoC2h
[BT_INFO_SRC_8723A_1ANT_BT_RSP
][0];
902 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
, ("[BTCoex], wifi connected!!\n"));
903 pBtCoexist
->btc_get(pBtCoexist
, BTC_GET_BL_WIFI_BUSY
, &bWifiBusy
);
906 ((BT_STATE_8723A_1ANT_NO_CONNECTION
== btState
) ||
907 (BT_STATE_8723A_1ANT_CONNECT_IDLE
== btState
)) )
909 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
, ("[BTCoex], [Wifi is idle] or [Bt is non connected idle or Bt is connected idle]!!\n"));
911 if(BT_STATE_8723A_1ANT_NO_CONNECTION
== btState
)
912 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, FALSE
, 9);
913 else if(BT_STATE_8723A_1ANT_CONNECT_IDLE
== btState
)
914 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, FALSE
, 0);
916 pBtCoexist
->btc_setBbReg(pBtCoexist
, 0x880, 0xff000000, 0xc0);
920 if( (BT_STATE_8723A_1ANT_SCO_ONLY_BUSY
== btState
) ||
921 (BT_STATE_8723A_1ANT_ACL_SCO_BUSY
== btState
) ||
922 (BT_STATE_8723A_1ANT_HID_BUSY
== btState
) ||
923 (BT_STATE_8723A_1ANT_HID_SCO_BUSY
== btState
) )
925 pBtCoexist
->btc_setBbReg(pBtCoexist
, 0x880, 0xff000000, 0x60);
929 pBtCoexist
->btc_setBbReg(pBtCoexist
, 0x880, 0xff000000, 0xc0);
933 case BT_STATE_8723A_1ANT_NO_CONNECTION
:
934 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, true, 5);
936 case BT_STATE_8723A_1ANT_CONNECT_IDLE
:
937 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, true, 12);
939 case BT_STATE_8723A_1ANT_INQ_OR_PAG
:
940 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, true, 10);
942 case BT_STATE_8723A_1ANT_SCO_ONLY_BUSY
:
943 case BT_STATE_8723A_1ANT_ACL_SCO_BUSY
:
944 case BT_STATE_8723A_1ANT_HID_BUSY
:
945 case BT_STATE_8723A_1ANT_HID_SCO_BUSY
:
946 halbtc8723a1ant_TdmaDurationAdjust(pBtCoexist
);
948 case BT_STATE_8723A_1ANT_ACL_ONLY_BUSY
:
949 if (btInfoOriginal
&BT_INFO_8723A_1ANT_B_A2DP
)
951 halbtc8723a1ant_TdmaDurationAdjust(pBtCoexist
);
953 else if(btInfoOriginal
&BT_INFO_8723A_1ANT_B_FTP
)
955 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, true, 1);
957 else if( (btInfoOriginal
&BT_INFO_8723A_1ANT_B_A2DP
) &&
958 (btInfoOriginal
&BT_INFO_8723A_1ANT_B_FTP
) )
960 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, true, 6);
964 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, true, 1);
968 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
, ("[BTCoex], error!!!, undefined case in halbtc8723a1ant_CoexForWifiConnect()!!\n"));
975 BTC_PRINT(BTC_MSG_ALGORITHM
, ALGO_TRACE
, ("[BTCoex], wifi is disconnected!!\n"));
978 pCoexDm
->psTdmaGlobalCnt
++;
981 //============================================================
982 // work around function start with wa_halbtc8723a1ant_
983 //============================================================
985 wa_halbtc8723a1ant_MonitorC2h(
986 IN PBTC_COEXIST pBtCoexist
990 u4Byte curC2hTotalCnt
=0x0;
991 static u4Byte preC2hTotalCnt
=0x0, sameCntPollingTime
=0x0;
993 curC2hTotalCnt
+=pCoexSta
->btInfoC2hCnt
[BT_INFO_SRC_8723A_1ANT_BT_RSP
];
995 if(curC2hTotalCnt
== preC2hTotalCnt
)
997 sameCntPollingTime
++;
1001 preC2hTotalCnt
= curC2hTotalCnt
;
1002 sameCntPollingTime
= 0;
1005 if(sameCntPollingTime
>= 2)
1007 tmp1b
= pBtCoexist
->btc_read_1byte(pBtCoexist
, 0x1af);
1010 pCoexSta
->c2hHangDetectCnt
++;
1011 pBtCoexist
->btc_write_1byte(pBtCoexist
, 0x1af, 0x0);
1016 //============================================================
1017 // extern function start with EXhalbtc8723a1ant_
1018 //============================================================
1020 EXhalbtc8723a1ant_InitHwConfig(
1021 IN PBTC_COEXIST pBtCoexist
1024 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_INIT
, ("[BTCoex], 1Ant Init HW Config!!\n"));
1026 // backup rf 0x1e value
1027 pCoexDm
->btRf0x1eBackup
=
1028 pBtCoexist
->btc_get_rf_reg(pBtCoexist
, BTC_RF_A
, 0x1e, 0xfffff);
1030 pBtCoexist
->btc_write_1byte(pBtCoexist
, 0x40, 0x20);
1032 // enable counter statistics
1033 pBtCoexist
->btc_write_1byte(pBtCoexist
, 0x76e, 0x4);
1036 pBtCoexist
->btc_write_1byte(pBtCoexist
, 0x6cc, 0x0); // 1-Ant coex
1037 pBtCoexist
->btc_write_4byte(pBtCoexist
, 0x6c8, 0xffff); // wifi break table
1038 pBtCoexist
->btc_write_4byte(pBtCoexist
, 0x6c4, 0x55555555); //coex table
1040 // antenna switch control parameter
1041 pBtCoexist
->btc_write_4byte(pBtCoexist
, 0x858, 0xaaaaaaaa);
1043 pBtCoexist
->btc_write_2byte(pBtCoexist
, 0x860, 0x210); //set antenna at wifi side if ANTSW is software control
1044 pBtCoexist
->btc_write_4byte(pBtCoexist
, 0x870, 0x300); //SPDT(connected with TRSW) control by hardware PTA
1045 pBtCoexist
->btc_write_4byte(pBtCoexist
, 0x874, 0x22804000); //ANTSW keep by GNT_BT
1047 // coexistence parameters
1048 pBtCoexist
->btc_write_1byte(pBtCoexist
, 0x778, 0x1); // enable RTK mode PTA
1052 EXhalbtc8723a1ant_InitCoexDm(
1053 IN PBTC_COEXIST pBtCoexist
1056 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_INIT
, ("[BTCoex], Coex Mechanism Init!!\n"));
1058 halbtc8723a1ant_InitCoexDm(pBtCoexist
);
1062 EXhalbtc8723a1ant_DisplayCoexInfo(
1063 IN PBTC_COEXIST pBtCoexist
1066 struct btc_board_info
* pBoardInfo
=&pBtCoexist
->board_info
;
1067 PBTC_STACK_INFO pStackInfo
=&pBtCoexist
->stack_info
;
1068 pu1Byte cliBuf
=pBtCoexist
->cli_buf
;
1069 u1Byte u1Tmp
[4], i
, btInfoExt
, psTdmaCase
=0;
1071 BOOLEAN bRoam
=FALSE
, bScan
=FALSE
, bLink
=FALSE
, bWifiUnder5G
=FALSE
;
1072 BOOLEAN bBtHsOn
=FALSE
, bWifiBusy
=FALSE
;
1073 s4Byte wifiRssi
=0, btHsRssi
=0;
1074 u4Byte wifiBw
, wifiTrafficDir
;
1075 u1Byte wifiDot11Chnl
, wifiHsChnl
;
1077 CL_SPRINTF(cliBuf
, BT_TMP_BUF_SIZE
, "\r\n ============[BT Coexist info]============");
1080 if(!pBoardInfo
->bt_exist
)
1082 CL_SPRINTF(cliBuf
, BT_TMP_BUF_SIZE
, "\r\n BT not exists !!!");
1087 CL_SPRINTF(cliBuf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = %d/ %d ", "Ant PG number/ Ant mechanism:", \
1088 pBoardInfo
->pg_ant_num
, pBoardInfo
->btdm_ant_num
);
1091 if(pBtCoexist
->manual_control
)
1093 CL_SPRINTF(cliBuf
, BT_TMP_BUF_SIZE
, "\r\n %-35s", "[Action Manual control]!!");
1097 CL_SPRINTF(cliBuf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = %s / %d", "BT stack/ hci ext ver", \
1098 ((pStackInfo
->bProfileNotified
)? "Yes":"No"), pStackInfo
->hciVersion
);
1101 pBtCoexist
->btc_get(pBtCoexist
, BTC_GET_BL_HS_OPERATION
, &bBtHsOn
);
1102 pBtCoexist
->btc_get(pBtCoexist
, BTC_GET_U1_WIFI_DOT11_CHNL
, &wifiDot11Chnl
);
1103 pBtCoexist
->btc_get(pBtCoexist
, BTC_GET_U1_WIFI_HS_CHNL
, &wifiHsChnl
);
1104 CL_SPRINTF(cliBuf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = %d / %d(%d)", "Dot11 channel / HsChnl(HsMode)", \
1105 wifiDot11Chnl
, wifiHsChnl
, bBtHsOn
);
1108 CL_SPRINTF(cliBuf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = %02x %02x %02x ", "H2C Wifi inform bt chnl Info", \
1109 pCoexDm
->wifiChnlInfo
[0], pCoexDm
->wifiChnlInfo
[1],
1110 pCoexDm
->wifiChnlInfo
[2]);
1113 pBtCoexist
->btc_get(pBtCoexist
, BTC_GET_S4_WIFI_RSSI
, &wifiRssi
);
1114 pBtCoexist
->btc_get(pBtCoexist
, BTC_GET_S4_HS_RSSI
, &btHsRssi
);
1115 CL_SPRINTF(cliBuf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = %d/ %d", "Wifi rssi/ HS rssi", \
1116 wifiRssi
, btHsRssi
);
1119 pBtCoexist
->btc_get(pBtCoexist
, BTC_GET_BL_WIFI_SCAN
, &bScan
);
1120 pBtCoexist
->btc_get(pBtCoexist
, BTC_GET_BL_WIFI_LINK
, &bLink
);
1121 pBtCoexist
->btc_get(pBtCoexist
, BTC_GET_BL_WIFI_ROAM
, &bRoam
);
1122 CL_SPRINTF(cliBuf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = %d/ %d/ %d ", "Wifi bLink/ bRoam/ bScan", \
1123 bLink
, bRoam
, bScan
);
1126 pBtCoexist
->btc_get(pBtCoexist
, BTC_GET_BL_WIFI_UNDER_5G
, &bWifiUnder5G
);
1127 pBtCoexist
->btc_get(pBtCoexist
, BTC_GET_U4_WIFI_BW
, &wifiBw
);
1128 pBtCoexist
->btc_get(pBtCoexist
, BTC_GET_BL_WIFI_BUSY
, &bWifiBusy
);
1129 pBtCoexist
->btc_get(pBtCoexist
, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION
, &wifiTrafficDir
);
1130 CL_SPRINTF(cliBuf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = %s / %s/ %s ", "Wifi status", \
1131 (bWifiUnder5G
? "5G":"2.4G"),
1132 ((BTC_WIFI_BW_LEGACY
==wifiBw
)? "Legacy": (((BTC_WIFI_BW_HT40
==wifiBw
)? "HT40":"HT20"))),
1133 ((!bWifiBusy
)? "idle": ((BTC_WIFI_TRAFFIC_TX
==wifiTrafficDir
)? "uplink":"downlink")));
1136 CL_SPRINTF(cliBuf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = [%s/ %d/ %d] ", "BT [status/ rssi/ retryCnt]", \
1137 ((pCoexSta
->bC2hBtInquiryPage
)?("inquiry/page scan"):((BT_8723A_1ANT_BT_STATUS_IDLE
== pCoexDm
->btStatus
)? "idle":( (BT_8723A_1ANT_BT_STATUS_CONNECTED_IDLE
== pCoexDm
->btStatus
)? "connected-idle":"busy"))),
1138 pCoexSta
->btRssi
, pCoexSta
->btRetryCnt
);
1141 if(pStackInfo
->bProfileNotified
)
1143 CL_SPRINTF(cliBuf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP", \
1144 pStackInfo
->bScoExist
, pStackInfo
->bHidExist
, pStackInfo
->bPanExist
, pStackInfo
->bA2dpExist
);
1147 pBtCoexist
->btc_disp_dbg_msg(pBtCoexist
, BTC_DBG_DISP_BT_LINK_INFO
);
1150 btInfoExt
= pCoexSta
->btInfoExt
;
1151 CL_SPRINTF(cliBuf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = %s", "BT Info A2DP rate", \
1152 (btInfoExt
&BIT0
)? "Basic rate":"EDR rate");
1155 for(i
=0; i
<BT_INFO_SRC_8723A_1ANT_MAX
; i
++)
1157 if(pCoexSta
->btInfoC2hCnt
[i
])
1159 CL_SPRINTF(cliBuf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", GLBtInfoSrc8723a1Ant
[i
], \
1160 pCoexSta
->btInfoC2h
[i
][0], pCoexSta
->btInfoC2h
[i
][1],
1161 pCoexSta
->btInfoC2h
[i
][2], pCoexSta
->btInfoC2h
[i
][3],
1162 pCoexSta
->btInfoC2h
[i
][4], pCoexSta
->btInfoC2h
[i
][5],
1163 pCoexSta
->btInfoC2h
[i
][6], pCoexSta
->btInfoC2hCnt
[i
]);
1168 CL_SPRINTF(cliBuf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = %d", "write 0x1af=0x0 num", \
1169 pCoexSta
->c2hHangDetectCnt
);
1173 CL_SPRINTF(cliBuf
, BT_TMP_BUF_SIZE
, "\r\n %-35s", "============[Sw mechanism]============");
1175 CL_SPRINTF(cliBuf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = %d/ %d/ %d", "SM1[ShRf/ LpRA/ LimDig]", \
1176 pCoexDm
->bCurRfRxLpfShrink
, pCoexDm
->bCurLowPenaltyRa
, pCoexDm
->limited_dig
);
1180 CL_SPRINTF(cliBuf
, BT_TMP_BUF_SIZE
, "\r\n %-35s", "============[Fw mechanism]============");
1183 if(!pBtCoexist
->manual_control
)
1185 psTdmaCase
= pCoexDm
->curPsTdma
;
1186 CL_SPRINTF(cliBuf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = %02x %02x %02x %02x %02x case-%d", "PS TDMA", \
1187 pCoexDm
->psTdmaPara
[0], pCoexDm
->psTdmaPara
[1],
1188 pCoexDm
->psTdmaPara
[2], pCoexDm
->psTdmaPara
[3],
1189 pCoexDm
->psTdmaPara
[4], psTdmaCase
);
1192 CL_SPRINTF(cliBuf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = %d ", "IgnWlanAct", \
1193 pCoexDm
->bCurIgnoreWlanAct
);
1198 CL_SPRINTF(cliBuf
, BT_TMP_BUF_SIZE
, "\r\n %-35s", "============[Hw setting]============");
1201 CL_SPRINTF(cliBuf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = 0x%x", "RF-A, 0x1e initVal", \
1202 pCoexDm
->btRf0x1eBackup
);
1205 u1Tmp
[0] = pBtCoexist
->btc_read_1byte(pBtCoexist
, 0x778);
1206 u1Tmp
[1] = pBtCoexist
->btc_read_1byte(pBtCoexist
, 0x783);
1207 u1Tmp
[2] = pBtCoexist
->btc_read_1byte(pBtCoexist
, 0x796);
1208 CL_SPRINTF(cliBuf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x778/ 0x783/ 0x796", \
1209 u1Tmp
[0], u1Tmp
[1], u1Tmp
[2]);
1212 u4Tmp
[0] = pBtCoexist
->btc_read_4byte(pBtCoexist
, 0x880);
1213 CL_SPRINTF(cliBuf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = 0x%x", "0x880", \
1217 u1Tmp
[0] = pBtCoexist
->btc_read_1byte(pBtCoexist
, 0x40);
1218 CL_SPRINTF(cliBuf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = 0x%x", "0x40", \
1222 u4Tmp
[0] = pBtCoexist
->btc_read_4byte(pBtCoexist
, 0x550);
1223 u1Tmp
[0] = pBtCoexist
->btc_read_1byte(pBtCoexist
, 0x522);
1224 CL_SPRINTF(cliBuf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = 0x%x/ 0x%x", "0x550(bcn ctrl)/0x522", \
1225 u4Tmp
[0], u1Tmp
[0]);
1228 u4Tmp
[0] = pBtCoexist
->btc_read_4byte(pBtCoexist
, 0x484);
1229 CL_SPRINTF(cliBuf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = 0x%x", "0x484(rate adaptive)", \
1233 u4Tmp
[0] = pBtCoexist
->btc_read_4byte(pBtCoexist
, 0xc50);
1234 CL_SPRINTF(cliBuf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = 0x%x", "0xc50(dig)", \
1238 u4Tmp
[0] = pBtCoexist
->btc_read_4byte(pBtCoexist
, 0xda0);
1239 u4Tmp
[1] = pBtCoexist
->btc_read_4byte(pBtCoexist
, 0xda4);
1240 u4Tmp
[2] = pBtCoexist
->btc_read_4byte(pBtCoexist
, 0xda8);
1241 u4Tmp
[3] = pBtCoexist
->btc_read_4byte(pBtCoexist
, 0xdac);
1242 CL_SPRINTF(cliBuf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0xda0/0xda4/0xda8/0xdac(FA cnt)", \
1243 u4Tmp
[0], u4Tmp
[1], u4Tmp
[2], u4Tmp
[3]);
1246 u4Tmp
[0] = pBtCoexist
->btc_read_4byte(pBtCoexist
, 0x6c0);
1247 u4Tmp
[1] = pBtCoexist
->btc_read_4byte(pBtCoexist
, 0x6c4);
1248 u4Tmp
[2] = pBtCoexist
->btc_read_4byte(pBtCoexist
, 0x6c8);
1249 u1Tmp
[0] = pBtCoexist
->btc_read_1byte(pBtCoexist
, 0x6cc);
1250 CL_SPRINTF(cliBuf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)", \
1251 u4Tmp
[0], u4Tmp
[1], u4Tmp
[2], u1Tmp
[0]);
1254 CL_SPRINTF(cliBuf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = %d/ %d", "0x770 (hp rx[31:16]/tx[15:0])", \
1255 pCoexSta
->highPriorityRx
, pCoexSta
->highPriorityTx
);
1257 CL_SPRINTF(cliBuf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = %d/ %d", "0x774(lp rx[31:16]/tx[15:0])", \
1258 pCoexSta
->lowPriorityRx
, pCoexSta
->lowPriorityTx
);
1261 // Tx mgnt queue hang or not, 0x41b should = 0xf, ex: 0xd ==>hang
1262 u1Tmp
[0] = pBtCoexist
->btc_read_1byte(pBtCoexist
, 0x41b);
1263 CL_SPRINTF(cliBuf
, BT_TMP_BUF_SIZE
, "\r\n %-35s = 0x%x", "0x41b (mgntQ hang chk == 0xf)", \
1267 pBtCoexist
->btc_disp_dbg_msg(pBtCoexist
, BTC_DBG_DISP_COEX_STATISTICS
);
1272 EXhalbtc8723a1ant_IpsNotify(
1273 IN PBTC_COEXIST pBtCoexist
,
1277 if(BTC_IPS_ENTER
== type
)
1279 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
, ("[BTCoex], IPS ENTER notify\n"));
1280 halbtc8723a1ant_CoexAllOff(pBtCoexist
);
1282 else if(BTC_IPS_LEAVE
== type
)
1284 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
, ("[BTCoex], IPS LEAVE notify\n"));
1285 //halbtc8723a1ant_InitCoexDm(pBtCoexist);
1290 EXhalbtc8723a1ant_LpsNotify(
1291 IN PBTC_COEXIST pBtCoexist
,
1295 if(BTC_LPS_ENABLE
== type
)
1297 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
, ("[BTCoex], LPS ENABLE notify\n"));
1299 else if(BTC_LPS_DISABLE
== type
)
1301 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
, ("[BTCoex], LPS DISABLE notify\n"));
1302 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, FALSE
, 8);
1307 EXhalbtc8723a1ant_ScanNotify(
1308 IN PBTC_COEXIST pBtCoexist
,
1312 BOOLEAN bWifiConnected
=FALSE
;
1314 halbtc8723a1ant_NotifyFwScan(pBtCoexist
, type
);
1316 if(pBtCoexist
->btInfo
.bBtDisabled
)
1318 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, FALSE
, 9);
1322 pBtCoexist
->btc_get(pBtCoexist
, BTC_GET_BL_WIFI_CONNECTED
, &bWifiConnected
);
1323 if(BTC_SCAN_START
== type
)
1325 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
, ("[BTCoex], SCAN START notify\n"));
1326 if(!bWifiConnected
) // non-connected scan
1328 //set 0x550[3]=1 before PsTdma
1329 halbtc8723a1ant_Reg0x550Bit3(pBtCoexist
, true);
1332 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, true, 4);
1334 else if(BTC_SCAN_FINISH
== type
)
1336 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
, ("[BTCoex], SCAN FINISH notify\n"));
1337 if(!bWifiConnected
) // non-connected scan
1339 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, FALSE
, 0);
1343 halbtc8723a1ant_CoexForWifiConnect(pBtCoexist
);
1350 EXhalbtc8723a1ant_ConnectNotify(
1351 IN PBTC_COEXIST pBtCoexist
,
1355 BOOLEAN bWifiConnected
=FALSE
;
1357 if(pBtCoexist
->btInfo
.bBtDisabled
)
1359 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, FALSE
, 9);
1363 if(BTC_ASSOCIATE_START
== type
)
1365 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
, ("[BTCoex], CONNECT START notify\n"));
1366 //set 0x550[3]=1 before PsTdma
1367 halbtc8723a1ant_Reg0x550Bit3(pBtCoexist
, true);
1368 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, true, 8); // extend wifi slot
1370 else if(BTC_ASSOCIATE_FINISH
== type
)
1372 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
, ("[BTCoex], CONNECT FINISH notify\n"));
1373 pBtCoexist
->btc_get(pBtCoexist
, BTC_GET_BL_WIFI_CONNECTED
, &bWifiConnected
);
1374 if(!bWifiConnected
) // non-connected scan
1376 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, FALSE
, 0);
1380 halbtc8723a1ant_CoexForWifiConnect(pBtCoexist
);
1387 EXhalbtc8723a1ant_MediaStatusNotify(
1388 IN PBTC_COEXIST pBtCoexist
,
1392 if(BTC_MEDIA_CONNECT
== type
)
1394 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
, ("[BTCoex], MEDIA connect notify\n"));
1398 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
, ("[BTCoex], MEDIA disconnect notify\n"));
1403 EXhalbtc8723a1ant_SpecialPacketNotify(
1404 IN PBTC_COEXIST pBtCoexist
,
1408 if(type
== BTC_PACKET_DHCP
)
1410 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
, ("[BTCoex], DHCP Packet notify\n"));
1411 if(pBtCoexist
->btInfo
.bBtDisabled
)
1413 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, FALSE
, 9);
1417 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, true, 18);
1423 EXhalbtc8723a1ant_BtInfoNotify(
1424 IN PBTC_COEXIST pBtCoexist
,
1430 u1Byte i
, rspSource
=0;
1431 BOOLEAN bBtHsOn
=FALSE
, bBtBusy
=FALSE
, bForceLps
=FALSE
;
1433 pCoexSta
->bC2hBtInfoReqSent
= FALSE
;
1435 rspSource
= BT_INFO_SRC_8723A_1ANT_BT_RSP
;
1436 pCoexSta
->btInfoC2hCnt
[rspSource
]++;
1438 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
, ("[BTCoex], Bt info[%d], length=%d, hex data=[", rspSource
, length
));
1439 for(i
=0; i
<length
; i
++)
1441 pCoexSta
->btInfoC2h
[rspSource
][i
] = tmpBuf
[i
];
1446 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
, ("0x%02x]\n", tmpBuf
[i
]));
1450 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
, ("0x%02x, ", tmpBuf
[i
]));
1454 if(BT_INFO_SRC_8723A_1ANT_WIFI_FW
!= rspSource
)
1456 pCoexSta
->btRetryCnt
=
1457 pCoexSta
->btInfoC2h
[rspSource
][1];
1460 pCoexSta
->btInfoC2h
[rspSource
][2]*2+10;
1462 pCoexSta
->btInfoExt
=
1463 pCoexSta
->btInfoC2h
[rspSource
][3];
1466 pBtCoexist
->btc_get(pBtCoexist
, BTC_GET_BL_HS_OPERATION
, &bBtHsOn
);
1467 // check BIT2 first ==> check if bt is under inquiry or page scan
1468 if(btInfo
& BT_INFO_8723A_1ANT_B_INQ_PAGE
)
1470 pCoexSta
->bC2hBtInquiryPage
= true;
1474 pCoexSta
->bC2hBtInquiryPage
= FALSE
;
1477 if(!(btInfo
& BIT0
))
1479 pCoexDm
->btStatus
= BT_STATE_8723A_1ANT_NO_CONNECTION
;
1487 pCoexDm
->btStatus
= BT_STATE_8723A_1ANT_CONNECT_IDLE
;
1489 else if(btInfo
== 0x9)
1491 pCoexDm
->btStatus
= BT_STATE_8723A_1ANT_ACL_ONLY_BUSY
;
1494 else if(btInfo
== 0x13)
1496 pCoexDm
->btStatus
= BT_STATE_8723A_1ANT_SCO_ONLY_BUSY
;
1499 else if(btInfo
== 0x1b)
1501 pCoexDm
->btStatus
= BT_STATE_8723A_1ANT_ACL_SCO_BUSY
;
1504 else if(btInfo
== 0x29)
1506 pCoexDm
->btStatus
= BT_STATE_8723A_1ANT_HID_BUSY
;
1509 else if(btInfo
== 0x3b)
1511 pCoexDm
->btStatus
= BT_STATE_8723A_1ANT_HID_SCO_BUSY
;
1515 pBtCoexist
->btc_set(pBtCoexist
, BTC_SET_BL_BT_TRAFFIC_BUSY
, &bBtBusy
);
1516 pBtCoexist
->btc_set(pBtCoexist
, BTC_SET_BL_BT_LIMITED_DIG
, &bBtBusy
);
1518 pBtCoexist
->btc_set(pBtCoexist
, BTC_SET_ACT_ENTER_LPS
, NULL
);
1520 pBtCoexist
->btc_set(pBtCoexist
, BTC_SET_ACT_NORMAL_LPS
, NULL
);
1522 if( (BT_STATE_8723A_1ANT_NO_CONNECTION
== pCoexDm
->btStatus
) ||
1523 (BT_STATE_8723A_1ANT_CONNECT_IDLE
== pCoexDm
->btStatus
) )
1525 if(pCoexSta
->bC2hBtInquiryPage
)
1526 pCoexDm
->btStatus
= BT_STATE_8723A_1ANT_INQ_OR_PAG
;
1531 EXhalbtc8723a1ant_StackOperationNotify(
1532 IN PBTC_COEXIST pBtCoexist
,
1536 if(BTC_STACK_OP_INQ_PAGE_PAIR_START
== type
)
1538 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
, ("[BTCoex], StackOP Inquiry/page/pair start notify\n"));
1540 else if(BTC_STACK_OP_INQ_PAGE_PAIR_FINISH
== type
)
1542 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
, ("[BTCoex], StackOP Inquiry/page/pair finish notify\n"));
1547 EXhalbtc8723a1ant_HaltNotify(
1548 IN PBTC_COEXIST pBtCoexist
1551 halbtc8723a1ant_PsTdma(pBtCoexist
, FORCE_EXEC
, FALSE
, 0);
1553 halbtc8723a1ant_LowPenaltyRa(pBtCoexist
, FORCE_EXEC
, FALSE
);
1554 halbtc8723a1ant_RfShrink(pBtCoexist
, FORCE_EXEC
, FALSE
);
1556 halbtc8723a1ant_IgnoreWlanAct(pBtCoexist
, FORCE_EXEC
, true);
1557 EXhalbtc8723a1ant_MediaStatusNotify(pBtCoexist
, BTC_MEDIA_DISCONNECT
);
1561 EXhalbtc8723a1ant_Periodical(
1562 IN PBTC_COEXIST pBtCoexist
1565 BOOLEAN bScan
=FALSE
, bLink
=FALSE
, bRoam
=FALSE
, bWifiConnected
=FALSE
;
1567 BTC_PRINT(BTC_MSG_INTERFACE
, INTF_NOTIFY
, ("[BTCoex], 1Ant Periodical!!\n"));
1569 pBtCoexist
->btc_get(pBtCoexist
, BTC_GET_BL_WIFI_SCAN
, &bScan
);
1570 pBtCoexist
->btc_get(pBtCoexist
, BTC_GET_BL_WIFI_LINK
, &bLink
);
1571 pBtCoexist
->btc_get(pBtCoexist
, BTC_GET_BL_WIFI_ROAM
, &bRoam
);
1572 pBtCoexist
->btc_get(pBtCoexist
, BTC_GET_BL_WIFI_CONNECTED
, &bWifiConnected
);
1574 // work around for c2h hang
1575 wa_halbtc8723a1ant_MonitorC2h(pBtCoexist
);
1577 halbtc8723a1ant_QueryBtInfo(pBtCoexist
);
1578 halbtc8723a1ant_MonitorBtCtr(pBtCoexist
);
1579 halbtc8723a1ant_MonitorBtEnableDisable(pBtCoexist
);
1589 if(pBtCoexist
->btInfo
.bBtDisabled
)
1591 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, FALSE
, 9);
1593 halbtc8723a1ant_LowPenaltyRa(pBtCoexist
, NORMAL_EXEC
, FALSE
);
1594 halbtc8723a1ant_RfShrink(pBtCoexist
, NORMAL_EXEC
, FALSE
);
1598 halbtc8723a1ant_LowPenaltyRa(pBtCoexist
, NORMAL_EXEC
, true);
1599 halbtc8723a1ant_RfShrink(pBtCoexist
, NORMAL_EXEC
, FALSE
);
1600 halbtc8723a1ant_CoexForWifiConnect(pBtCoexist
);
1605 halbtc8723a1ant_PsTdma(pBtCoexist
, NORMAL_EXEC
, FALSE
, 0);
1607 halbtc8723a1ant_LowPenaltyRa(pBtCoexist
, NORMAL_EXEC
, FALSE
);
1608 halbtc8723a1ant_RfShrink(pBtCoexist
, NORMAL_EXEC
, FALSE
);