support different wifi bt chip auto compatible
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8189es / hal / OUTSRC-BTCoexist / HalBtc8723a1Ant.c
1 //============================================================\r
2 // Description:\r
3 //\r
4 // This file is for RTL8723A Co-exist mechanism\r
5 //\r
6 // History\r
7 // 2012/08/22 Cosa first check in.\r
8 // 2012/11/14 Cosa Revise for 8723A 1Ant out sourcing.\r
9 //\r
10 //============================================================\r
11 \r
12 //============================================================\r
13 // include files\r
14 //============================================================\r
15 #include "Mp_Precomp.h"\r
16 #if(BT_30_SUPPORT == 1)\r
17 //============================================================\r
18 // Global variables, these are static variables\r
19 //============================================================\r
20 static COEX_DM_8723A_1ANT       GLCoexDm8723a1Ant;\r
21 static PCOEX_DM_8723A_1ANT      pCoexDm=&GLCoexDm8723a1Ant;\r
22 static COEX_STA_8723A_1ANT      GLCoexSta8723a1Ant;\r
23 static PCOEX_STA_8723A_1ANT     pCoexSta=&GLCoexSta8723a1Ant;\r
24 \r
25 const char *const GLBtInfoSrc8723a1Ant[]={\r
26         "BT Info[wifi fw]",\r
27         "BT Info[bt rsp]",\r
28         "BT Info[bt auto report]",\r
29 };\r
30 \r
31 //============================================================\r
32 // local function proto type if needed\r
33 //============================================================\r
34 //============================================================\r
35 // local function start with halbtc8723a1ant_\r
36 //============================================================\r
37 VOID\r
38 halbtc8723a1ant_Reg0x550Bit3(\r
39         IN      PBTC_COEXIST            pBtCoexist,\r
40         IN      BOOLEAN                 bSet\r
41         )\r
42 {\r
43         u1Byte  u1tmp=0;\r
44         \r
45         u1tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x550);\r
46         if(bSet)\r
47         {\r
48                 u1tmp |= BIT3;\r
49         }\r
50         else\r
51         {\r
52                 u1tmp &= ~BIT3;\r
53         }\r
54         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x550, u1tmp);\r
55         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], set 0x550[3]=%d\n", (bSet? 1:0)));\r
56 }\r
57 \r
58 VOID\r
59 halbtc8723a1ant_NotifyFwScan(\r
60         IN      PBTC_COEXIST            pBtCoexist,\r
61         IN      u1Byte                  scanType\r
62         )\r
63 {\r
64         u1Byte                  H2C_Parameter[1] ={0};\r
65         \r
66         if(BTC_SCAN_START == scanType)\r
67                 H2C_Parameter[0] = 0x1;\r
68 \r
69         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], Notify FW for wifi scan, write 0x3b=0x%x\n", \r
70                 H2C_Parameter[0]));\r
71 \r
72         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x3b, 1, H2C_Parameter);\r
73 }\r
74 \r
75 VOID\r
76 halbtc8723a1ant_QueryBtInfo(\r
77         IN      PBTC_COEXIST            pBtCoexist\r
78         )\r
79 {\r
80         u1Byte                  H2C_Parameter[1] ={0};\r
81 \r
82         pCoexSta->bC2hBtInfoReqSent = TRUE;\r
83 \r
84         H2C_Parameter[0] |= BIT0;       // trigger\r
85 \r
86         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], Query Bt Info, FW write 0x38=0x%x\n", \r
87                 H2C_Parameter[0]));\r
88 \r
89         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x38, 1, H2C_Parameter);\r
90 }\r
91 \r
92 VOID\r
93 halbtc8723a1ant_SetSwRfRxLpfCorner(\r
94         IN      PBTC_COEXIST            pBtCoexist,\r
95         IN      BOOLEAN                 bRxRfShrinkOn\r
96         )\r
97 {\r
98         if(bRxRfShrinkOn)\r
99         {\r
100                 //Shrink RF Rx LPF corner\r
101                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Shrink RF Rx LPF corner!!\n"));\r
102                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff, 0xf0ff7);\r
103         }\r
104         else\r
105         {\r
106                 //Resume RF Rx LPF corner\r
107                 // After initialized, we can use pCoexDm->btRf0x1eBackup\r
108                 if(pBtCoexist->bInitilized)\r
109                 {\r
110                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Resume RF Rx LPF corner!!\n"));\r
111                         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff, pCoexDm->btRf0x1eBackup);\r
112                 }\r
113         }\r
114 }\r
115 \r
116 VOID\r
117 halbtc8723a1ant_RfShrink(\r
118         IN      PBTC_COEXIST            pBtCoexist,\r
119         IN      BOOLEAN                 bForceExec,\r
120         IN      BOOLEAN                 bRxRfShrinkOn\r
121         )\r
122 {\r
123         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW, ("[BTCoex], %s turn Rx RF Shrink = %s\n",  \r
124                 (bForceExec? "force to":""), ((bRxRfShrinkOn)? "ON":"OFF")));\r
125         pCoexDm->bCurRfRxLpfShrink = bRxRfShrinkOn;\r
126 \r
127         if(!bForceExec)\r
128         {\r
129                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL, ("[BTCoex], bPreRfRxLpfShrink=%d, bCurRfRxLpfShrink=%d\n", \r
130                         pCoexDm->bPreRfRxLpfShrink, pCoexDm->bCurRfRxLpfShrink));\r
131 \r
132                 if(pCoexDm->bPreRfRxLpfShrink == pCoexDm->bCurRfRxLpfShrink) \r
133                         return;\r
134         }\r
135         halbtc8723a1ant_SetSwRfRxLpfCorner(pBtCoexist, pCoexDm->bCurRfRxLpfShrink);\r
136 \r
137         pCoexDm->bPreRfRxLpfShrink = pCoexDm->bCurRfRxLpfShrink;\r
138 }\r
139 \r
140 VOID\r
141 halbtc8723a1ant_SetSwPenaltyTxRateAdaptive(\r
142         IN      PBTC_COEXIST            pBtCoexist,\r
143         IN      BOOLEAN                 bLowPenaltyRa\r
144         )\r
145 {\r
146         u1Byte  tmpU1;\r
147 \r
148         tmpU1 = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x4fd);\r
149         tmpU1 |= BIT0;\r
150         if(bLowPenaltyRa)\r
151         {\r
152                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Tx rate adaptive, set low penalty!!\n"));\r
153                 tmpU1 &= ~BIT2;\r
154         }\r
155         else\r
156         {\r
157                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Tx rate adaptive, set normal!!\n"));\r
158                 tmpU1 |= BIT2;\r
159         }\r
160 \r
161         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x4fd, tmpU1);\r
162 }\r
163 \r
164 VOID\r
165 halbtc8723a1ant_LowPenaltyRa(\r
166         IN      PBTC_COEXIST            pBtCoexist,\r
167         IN      BOOLEAN                 bForceExec,\r
168         IN      BOOLEAN                 bLowPenaltyRa\r
169         )\r
170 {\r
171         return;\r
172         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW, ("[BTCoex], %s turn LowPenaltyRA = %s\n",  \r
173                 (bForceExec? "force to":""), ((bLowPenaltyRa)? "ON":"OFF")));\r
174         pCoexDm->bCurLowPenaltyRa = bLowPenaltyRa;\r
175 \r
176         if(!bForceExec)\r
177         {\r
178                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL, ("[BTCoex], bPreLowPenaltyRa=%d, bCurLowPenaltyRa=%d\n", \r
179                         pCoexDm->bPreLowPenaltyRa, pCoexDm->bCurLowPenaltyRa));\r
180 \r
181                 if(pCoexDm->bPreLowPenaltyRa == pCoexDm->bCurLowPenaltyRa) \r
182                         return;\r
183         }\r
184         halbtc8723a1ant_SetSwPenaltyTxRateAdaptive(pBtCoexist, pCoexDm->bCurLowPenaltyRa);\r
185 \r
186         pCoexDm->bPreLowPenaltyRa = pCoexDm->bCurLowPenaltyRa;\r
187 }\r
188 \r
189 VOID\r
190 halbtc8723a1ant_SetCoexTable(\r
191         IN      PBTC_COEXIST    pBtCoexist,\r
192         IN      u4Byte          val0x6c0,\r
193         IN      u4Byte          val0x6c8,\r
194         IN      u1Byte          val0x6cc\r
195         )\r
196 {\r
197         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6c0=0x%x\n", val0x6c0));\r
198         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c0, val0x6c0);\r
199 \r
200         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6c8=0x%x\n", val0x6c8));\r
201         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c8, val0x6c8);\r
202 \r
203         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6cc=0x%x\n", val0x6cc));\r
204         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cc, val0x6cc);\r
205 }\r
206 \r
207 VOID\r
208 halbtc8723a1ant_CoexTable(\r
209         IN      PBTC_COEXIST            pBtCoexist,\r
210         IN      BOOLEAN                 bForceExec,\r
211         IN      u4Byte                  val0x6c0,\r
212         IN      u4Byte                  val0x6c8,\r
213         IN      u1Byte                  val0x6cc\r
214         )\r
215 {\r
216         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW, ("[BTCoex], %s write Coex Table 0x6c0=0x%x, 0x6c8=0x%x, 0x6cc=0x%x\n", \r
217                 (bForceExec? "force to":""), val0x6c0, val0x6c8, val0x6cc));\r
218         pCoexDm->curVal0x6c0 = val0x6c0;\r
219         pCoexDm->curVal0x6c8 = val0x6c8;\r
220         pCoexDm->curVal0x6cc = val0x6cc;\r
221 \r
222         if(!bForceExec)\r
223         {\r
224                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL, ("[BTCoex], preVal0x6c0=0x%x, preVal0x6c8=0x%x, preVal0x6cc=0x%x !!\n", \r
225                         pCoexDm->preVal0x6c0, pCoexDm->preVal0x6c8, pCoexDm->preVal0x6cc));\r
226                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL, ("[BTCoex], curVal0x6c0=0x%x, curVal0x6c8=0x%x, curVal0x6cc=0x%x !!\n", \r
227                         pCoexDm->curVal0x6c0, pCoexDm->curVal0x6c8, pCoexDm->curVal0x6cc));\r
228         \r
229                 if( (pCoexDm->preVal0x6c0 == pCoexDm->curVal0x6c0) &&\r
230                         (pCoexDm->preVal0x6c8 == pCoexDm->curVal0x6c8) &&\r
231                         (pCoexDm->preVal0x6cc == pCoexDm->curVal0x6cc) )\r
232                         return;\r
233         }\r
234         halbtc8723a1ant_SetCoexTable(pBtCoexist, val0x6c0, val0x6c8, val0x6cc);\r
235 \r
236         pCoexDm->preVal0x6c0 = pCoexDm->curVal0x6c0;\r
237         pCoexDm->preVal0x6c8 = pCoexDm->curVal0x6c8;\r
238         pCoexDm->preVal0x6cc = pCoexDm->curVal0x6cc;\r
239 }\r
240 \r
241 VOID\r
242 halbtc8723a1ant_SetFwIgnoreWlanAct(\r
243         IN      PBTC_COEXIST            pBtCoexist,\r
244         IN      BOOLEAN                 bEnable\r
245         )\r
246 {\r
247         u1Byte                  H2C_Parameter[1] ={0};\r
248                 \r
249         if(bEnable)\r
250         {\r
251                 H2C_Parameter[0] |= BIT0;               // function enable\r
252         }\r
253         \r
254         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x25=0x%x\n", \r
255                 H2C_Parameter[0]));\r
256 \r
257         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x25, 1, H2C_Parameter);    \r
258 }\r
259 \r
260 VOID\r
261 halbtc8723a1ant_IgnoreWlanAct(\r
262         IN      PBTC_COEXIST            pBtCoexist,\r
263         IN      BOOLEAN                 bForceExec,\r
264         IN      BOOLEAN                 bEnable\r
265         )\r
266 {\r
267         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s turn Ignore WlanAct %s\n", \r
268                 (bForceExec? "force to":""), (bEnable? "ON":"OFF")));\r
269         pCoexDm->bCurIgnoreWlanAct = bEnable;\r
270 \r
271         if(!bForceExec)\r
272         {\r
273                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], bPreIgnoreWlanAct = %d, bCurIgnoreWlanAct = %d!!\n", \r
274                         pCoexDm->bPreIgnoreWlanAct, pCoexDm->bCurIgnoreWlanAct));\r
275 \r
276                 if(pCoexDm->bPreIgnoreWlanAct == pCoexDm->bCurIgnoreWlanAct)\r
277                         return;\r
278         }\r
279         halbtc8723a1ant_SetFwIgnoreWlanAct(pBtCoexist, bEnable);\r
280 \r
281         pCoexDm->bPreIgnoreWlanAct = pCoexDm->bCurIgnoreWlanAct;\r
282 }\r
283 \r
284 VOID\r
285 halbtc8723a1ant_SetFwPstdma(\r
286         IN      PBTC_COEXIST            pBtCoexist,\r
287         IN      u1Byte                  type,\r
288         IN      u1Byte                  byte1,\r
289         IN      u1Byte                  byte2,\r
290         IN      u1Byte                  byte3,\r
291         IN      u1Byte                  byte4,\r
292         IN      u1Byte                  byte5\r
293         )\r
294 {\r
295         u1Byte                  H2C_Parameter[5] ={0};\r
296         u1Byte                  realByte1=byte1, realByte5=byte5;\r
297         BOOLEAN                 bApEnable=FALSE;\r
298 \r
299         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, &bApEnable);\r
300 \r
301         // byte1[1:0] != 0 means enable pstdma\r
302         // for 2Ant bt coexist, if byte1 != 0 means enable pstdma\r
303         if(byte1)\r
304         {\r
305                 if(bApEnable)\r
306                 {\r
307                         if(type != 5 && type != 12)\r
308                         {\r
309                                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], FW for 1Ant AP mode\n"));\r
310                                 realByte1 &= ~BIT4;\r
311                                 realByte1 |= BIT5;\r
312 \r
313                                 realByte5 |= BIT5;\r
314                                 realByte5 &= ~BIT6;\r
315                         }\r
316                 }\r
317         }\r
318         H2C_Parameter[0] = realByte1;   \r
319         H2C_Parameter[1] = byte2;       \r
320         H2C_Parameter[2] = byte3;\r
321         H2C_Parameter[3] = byte4;\r
322         H2C_Parameter[4] = realByte5;\r
323 \r
324         pCoexDm->psTdmaPara[0] = realByte1;\r
325         pCoexDm->psTdmaPara[1] = byte2;\r
326         pCoexDm->psTdmaPara[2] = byte3;\r
327         pCoexDm->psTdmaPara[3] = byte4;\r
328         pCoexDm->psTdmaPara[4] = realByte5;\r
329         \r
330         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], FW write 0x3a(5bytes)=0x%x%08x\n", \r
331                 H2C_Parameter[0], \r
332                 H2C_Parameter[1]<<24|H2C_Parameter[2]<<16|H2C_Parameter[3]<<8|H2C_Parameter[4]));\r
333 \r
334         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x3a, 5, H2C_Parameter);\r
335 }\r
336 \r
337 VOID\r
338 halbtc8723a1ant_PsTdma(\r
339         IN      PBTC_COEXIST            pBtCoexist,\r
340         IN      BOOLEAN                 bForceExec,\r
341         IN      BOOLEAN                 bTurnOn,\r
342         IN      u1Byte                  type\r
343         )\r
344 {\r
345         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s turn %s PS TDMA, type=%d\n", \r
346                 (bForceExec? "force to":""), (bTurnOn? "ON":"OFF"), type));             \r
347         pCoexDm->bCurPsTdmaOn = bTurnOn;\r
348         pCoexDm->curPsTdma = type;\r
349 \r
350         if(!bForceExec)\r
351         {\r
352                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], bPrePsTdmaOn = %d, bCurPsTdmaOn = %d!!\n", \r
353                         pCoexDm->bPrePsTdmaOn, pCoexDm->bCurPsTdmaOn));\r
354                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], prePsTdma = %d, curPsTdma = %d!!\n", \r
355                         pCoexDm->prePsTdma, pCoexDm->curPsTdma));\r
356 \r
357                 if( (pCoexDm->bPrePsTdmaOn == pCoexDm->bCurPsTdmaOn) &&\r
358                         (pCoexDm->prePsTdma == pCoexDm->curPsTdma) )\r
359                         return;\r
360         }       \r
361         if(pCoexDm->bCurPsTdmaOn)\r
362         {\r
363                 switch(pCoexDm->curPsTdma)\r
364                 {\r
365                         case 1:\r
366                         default:\r
367                                 halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x13, 0x1a, 0x1a, 0x0, 0x40);\r
368                                 break;\r
369                         case 2:\r
370                                 halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x13, 0x12, 0x12, 0x0, 0x40);\r
371                                 break;\r
372                         case 3:\r
373                                 halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x93, 0x3f, 0x3, 0x10, 0x40);\r
374                                 break;\r
375                         case 4:\r
376                                 halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x93, 0x15, 0x3, 0x10, 0x0);\r
377                                 break;\r
378                         case 5:\r
379                                 halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0xa9, 0x15, 0x3, 0x35, 0xc0);\r
380                                 break;\r
381                         \r
382                         case 8: \r
383                                 halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x93, 0x25, 0x3, 0x10, 0x0);\r
384                                 break;\r
385                         case 9: \r
386                                 halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x13, 0xa, 0xa, 0x0, 0x40);\r
387                                 break;\r
388                         case 10:        \r
389                                 halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x13, 0xa, 0xa, 0x0, 0x40);\r
390                                 break;\r
391                         case 11:        \r
392                                 halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x13, 0x5, 0x5, 0x0, 0x40);\r
393                                 break;\r
394                         case 12:\r
395                                 halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0xa9, 0xa, 0x3, 0x15, 0xc0);\r
396                                 break;\r
397         \r
398                         case 18:\r
399                                 halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x93, 0x25, 0x3, 0x10, 0x0);\r
400                                 break;                  \r
401 \r
402                         case 20:\r
403                                 halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x13, 0x2a, 0x2a, 0x0, 0x0);\r
404                                 break;\r
405                         case 21:\r
406                                 halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x93, 0x20, 0x3, 0x10, 0x40);\r
407                                 break;\r
408                         case 22:\r
409                                 halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x13, 0x1a, 0x1a, 0x2, 0x40);\r
410                                 break;\r
411                         case 23:\r
412                                 halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x13, 0x12, 0x12, 0x2, 0x40);\r
413                                 break;\r
414                         case 24:\r
415                                 halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x13, 0xa, 0xa, 0x2, 0x40);\r
416                                 break;\r
417                         case 25:\r
418                                 halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x13, 0x5, 0x5, 0x2, 0x40);\r
419                                 break;\r
420                         case 26:\r
421                                 halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x93, 0x25, 0x3, 0x10, 0x0);\r
422                                 break;\r
423                         case 27:\r
424                                 halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x13, 0x5, 0x5, 0x2, 0x40);\r
425                                 break;\r
426                         case 28:\r
427                                 halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x3, 0x2f, 0x2f, 0x0, 0x0);\r
428                                 break;\r
429 \r
430                 }\r
431         }\r
432         else\r
433         {\r
434                 // disable PS tdma\r
435                 switch(pCoexDm->curPsTdma)\r
436                 {\r
437                         case 8:\r
438                                 halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x8, 0x0, 0x0, 0x0, 0x0);         \r
439                                 break;\r
440                         case 0:\r
441                         default:\r
442                                 halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x0, 0x0, 0x0, 0x0, 0x0);\r
443                                 pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x860, 0x210);\r
444                                 break;\r
445                         case 9:\r
446                                 halbtc8723a1ant_SetFwPstdma(pBtCoexist, type, 0x0, 0x0, 0x0, 0x0, 0x0);\r
447                                 pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x860, 0x110);\r
448                                 break;\r
449 \r
450                 }\r
451         }\r
452 \r
453         // update pre state\r
454         pCoexDm->bPrePsTdmaOn = pCoexDm->bCurPsTdmaOn;\r
455         pCoexDm->prePsTdma = pCoexDm->curPsTdma;\r
456 }\r
457 \r
458 \r
459 VOID\r
460 halbtc8723a1ant_CoexAllOff(\r
461         IN      PBTC_COEXIST            pBtCoexist\r
462         )\r
463 {\r
464         // fw all off\r
465         halbtc8723a1ant_IgnoreWlanAct(pBtCoexist, NORMAL_EXEC, FALSE);\r
466         halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
467 \r
468         // sw all off\r
469         halbtc8723a1ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, FALSE);\r
470         halbtc8723a1ant_RfShrink(pBtCoexist, NORMAL_EXEC, FALSE);\r
471 \r
472         // hw all off\r
473         halbtc8723a1ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3);\r
474 }\r
475 \r
476 VOID\r
477 halbtc8723a1ant_InitCoexDm(\r
478         IN      PBTC_COEXIST            pBtCoexist\r
479         )\r
480 {\r
481         // force to reset coex mechanism\r
482         halbtc8723a1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, FALSE);\r
483 }\r
484 \r
485 VOID\r
486 halbtc8723a1ant_BtEnableAction(\r
487         IN      PBTC_COEXIST            pBtCoexist\r
488         )\r
489 {\r
490         halbtc8723a1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, FALSE);\r
491 }\r
492 \r
493 VOID\r
494 halbtc8723a1ant_MonitorBtCtr(\r
495         IN      PBTC_COEXIST            pBtCoexist\r
496         )\r
497 {\r
498         u4Byte                  regHPTxRx, regLPTxRx, u4Tmp;\r
499         u4Byte                  regHPTx=0, regHPRx=0, regLPTx=0, regLPRx=0;\r
500         u1Byte                  u1Tmp;\r
501         \r
502         regHPTxRx = 0x770;\r
503         regLPTxRx = 0x774;\r
504 \r
505         u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regHPTxRx);\r
506         regHPTx = u4Tmp & bMaskLWord;\r
507         regHPRx = (u4Tmp & bMaskHWord)>>16;\r
508 \r
509         u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regLPTxRx);\r
510         regLPTx = u4Tmp & bMaskLWord;\r
511         regLPRx = (u4Tmp & bMaskHWord)>>16;\r
512                 \r
513         pCoexSta->highPriorityTx = regHPTx;\r
514         pCoexSta->highPriorityRx = regHPRx;\r
515         pCoexSta->lowPriorityTx = regLPTx;\r
516         pCoexSta->lowPriorityRx = regLPRx;\r
517 \r
518         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], High Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n", \r
519                 regHPTxRx, regHPTx, regHPTx, regHPRx, regHPRx));\r
520         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], Low Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n", \r
521                 regLPTxRx, regLPTx, regLPTx, regLPRx, regLPRx));\r
522 \r
523         // reset counter\r
524         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc);\r
525 }\r
526 \r
527 VOID\r
528 halbtc8723a1ant_MonitorBtEnableDisable(\r
529         IN      PBTC_COEXIST            pBtCoexist\r
530         )\r
531 {\r
532         static BOOLEAN  bPreBtDisabled=FALSE;\r
533         static u4Byte   btDisableCnt=0;\r
534         BOOLEAN                 bBtActive=TRUE, bBtDisabled=FALSE;\r
535 \r
536         // This function check if bt is disabled\r
537         \r
538         if(     pCoexSta->highPriorityTx == 0 &&\r
539                 pCoexSta->highPriorityRx == 0 &&\r
540                 pCoexSta->lowPriorityTx == 0 &&\r
541                 pCoexSta->lowPriorityRx == 0)\r
542         {\r
543                 bBtActive = FALSE;\r
544         }\r
545         if(     pCoexSta->highPriorityTx == 0xffff &&\r
546                 pCoexSta->highPriorityRx == 0xffff &&\r
547                 pCoexSta->lowPriorityTx == 0xffff &&\r
548                 pCoexSta->lowPriorityRx == 0xffff)\r
549         {\r
550                 bBtActive = FALSE;\r
551         }\r
552         if(bBtActive)\r
553         {\r
554                 btDisableCnt = 0;\r
555                 bBtDisabled = FALSE;\r
556                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);\r
557                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], BT is enabled !!\n"));\r
558         }\r
559         else\r
560         {\r
561                 btDisableCnt++;\r
562                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], bt all counters=0, %d times!!\n", \r
563                                 btDisableCnt));\r
564                 if(btDisableCnt >= 2)\r
565                 {\r
566                         bBtDisabled = TRUE;\r
567                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);\r
568                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], BT is disabled !!\n"));\r
569                 }\r
570         }\r
571         if(bPreBtDisabled != bBtDisabled)\r
572         {\r
573                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], BT is from %s to %s!!\n", \r
574                         (bPreBtDisabled ? "disabled":"enabled"), \r
575                         (bBtDisabled ? "disabled":"enabled")));\r
576                 bPreBtDisabled = bBtDisabled;\r
577                 if(!bBtDisabled)\r
578                 {\r
579                         halbtc8723a1ant_BtEnableAction(pBtCoexist);\r
580                 }\r
581                 else\r
582                 {\r
583                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_NORMAL_LPS, NULL);\r
584                 }\r
585         }\r
586 }\r
587 \r
588 VOID\r
589 halbtc8723a1ant_TdmaDurationAdjust(\r
590         IN      PBTC_COEXIST            pBtCoexist\r
591         )\r
592 {\r
593         static s4Byte           up,dn,m,n,WaitCount;\r
594         s4Byte                  result;   //0: no change, +1: increase WiFi duration, -1: decrease WiFi duration\r
595         u1Byte                  retryCount=0;\r
596         u1Byte                  btState;\r
597         BOOLEAN                 bScan=FALSE, bLink=FALSE, bRoam=FALSE;\r
598         u4Byte                  wifiBw;\r
599         \r
600         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
601         btState = pCoexDm->btStatus;\r
602 \r
603         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], TdmaDurationAdjust()\n"));\r
604         if(pCoexDm->psTdmaGlobalCnt != pCoexDm->psTdmaMonitorCnt)\r
605         {\r
606                 pCoexDm->psTdmaMonitorCnt = 0;\r
607                 pCoexDm->psTdmaGlobalCnt = 0;\r
608         }\r
609         if(pCoexDm->psTdmaMonitorCnt == 0)\r
610         {\r
611                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], first run BT A2DP + WiFi busy state!!\n"));\r
612                 if(btState == BT_STATE_8723A_1ANT_ACL_ONLY_BUSY)\r
613                 {\r
614                         halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
615                         pCoexDm->psTdmaDuAdjType = 1;\r
616                 }\r
617                 else\r
618                 {\r
619                         halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 22);\r
620                         pCoexDm->psTdmaDuAdjType = 22;\r
621                 }\r
622                 //============\r
623                 up = 0;\r
624                 dn = 0;\r
625                 m = 1;\r
626                 n= 3;\r
627                 result = 0;\r
628                 WaitCount = 0;\r
629         }\r
630         else\r
631         {\r
632                 //accquire the BT TRx retry count from BT_Info byte2\r
633                 retryCount = pCoexSta->btRetryCnt;\r
634                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], retryCount = %d\n", retryCount));\r
635                 result = 0;\r
636                 WaitCount++; \r
637                   \r
638                 if(retryCount == 0)  // no retry in the last 2-second duration\r
639                 {\r
640                         up++;\r
641                         dn--;\r
642 \r
643                         if (dn <= 0)\r
644                                 dn = 0;                          \r
645 \r
646                         if(up >= n) // if ³sÄò n ­Ó2¬í retry count¬°0, «h½Õ¼eWiFi duration\r
647                         {\r
648                                 WaitCount = 0; \r
649                                 n = 3;\r
650                                 up = 0;\r
651                                 dn = 0;\r
652                                 result = 1; \r
653                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Increase wifi duration!!\n"));\r
654                         }\r
655                 }\r
656                 else if (retryCount <= 3)       // <=3 retry in the last 2-second duration\r
657                 {\r
658                         up--; \r
659                         dn++;\r
660 \r
661                         if (up <= 0)\r
662                                 up = 0;\r
663 \r
664                         if (dn == 2)    // if ³sÄò 2 ­Ó2¬í retry count< 3, «h½Õ¯¶WiFi duration\r
665                         {\r
666                                 if (WaitCount <= 2)\r
667                                         m++; // ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^\r
668                                 else\r
669                                         m = 1;\r
670 \r
671                                 if ( m >= 20) //m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration.\r
672                                         m = 20;\r
673 \r
674                                 n = 3*m;\r
675                                 up = 0;\r
676                                 dn = 0;\r
677                                 WaitCount = 0;  \r
678                                 result = -1; \r
679                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter<3!!\n"));\r
680                         }\r
681                 }\r
682                 else  //retry count > 3, ¥u­n1¦¸ retry count > 3, «h½Õ¯¶WiFi duration\r
683                 {\r
684                         if (WaitCount == 1)\r
685                                 m++; // ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^\r
686                         else\r
687                                 m = 1;\r
688 \r
689                         if ( m >= 20) //m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration.\r
690                                 m = 20;\r
691 \r
692                         n = 3*m;\r
693                         up = 0;\r
694                         dn = 0;\r
695                         WaitCount = 0; \r
696                         result = -1;\r
697                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter>3!!\n"));\r
698                 }\r
699                 \r
700                 {\r
701                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT TxRx counter H+L <= 1200\n"));\r
702                         if(btState != BT_STATE_8723A_1ANT_ACL_ONLY_BUSY)\r
703                         {\r
704                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], NOT ACL only busy!\n"));\r
705                                 if(BTC_WIFI_BW_HT40 != wifiBw)\r
706                                 {\r
707                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], 20MHz\n"));\r
708                                         if(result == -1)\r
709                                         {\r
710                                                 if(pCoexDm->curPsTdma == 22)\r
711                                                 {\r
712                                                         halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 23);\r
713                                                         pCoexDm->psTdmaDuAdjType = 23;\r
714                                                 }\r
715                                                 else if(pCoexDm->curPsTdma == 23)\r
716                                                 {\r
717                                                         halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 24);\r
718                                                         pCoexDm->psTdmaDuAdjType = 24;\r
719                                                 }\r
720                                                 else if(pCoexDm->curPsTdma == 24)\r
721                                                 {\r
722                                                         halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 25);\r
723                                                         pCoexDm->psTdmaDuAdjType = 25;\r
724                                                 }\r
725                                         } \r
726                                         else if (result == 1)\r
727                                         {\r
728                                                 if(pCoexDm->curPsTdma == 25)\r
729                                                 {\r
730                                                         halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 24);\r
731                                                         pCoexDm->psTdmaDuAdjType = 24;\r
732                                                 }\r
733                                                 else if(pCoexDm->curPsTdma == 24)\r
734                                                 {\r
735                                                         halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 23);\r
736                                                         pCoexDm->psTdmaDuAdjType = 23;\r
737                                                 }\r
738                                                 else if(pCoexDm->curPsTdma == 23)\r
739                                                 {\r
740                                                         halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 22);\r
741                                                         pCoexDm->psTdmaDuAdjType = 22;\r
742                                                 }\r
743                                         }\r
744                                         // error handle, if not in the following state,\r
745                                         // set psTdma again.\r
746                                         if( (pCoexDm->psTdmaDuAdjType != 22) &&\r
747                                                 (pCoexDm->psTdmaDuAdjType != 23) &&\r
748                                                 (pCoexDm->psTdmaDuAdjType != 24) &&\r
749                                                 (pCoexDm->psTdmaDuAdjType != 25) )\r
750                                         {\r
751                                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], duration case out of handle!!\n"));\r
752                                                 halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 23);\r
753                                                 pCoexDm->psTdmaDuAdjType = 23;\r
754                                         }\r
755                                 }\r
756                                 else\r
757                                 {\r
758                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], 40MHz\n"));\r
759                                         if(result == -1)\r
760                                         {\r
761                                                 if(pCoexDm->curPsTdma == 23)\r
762                                                 {\r
763                                                         halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 24);\r
764                                                         pCoexDm->psTdmaDuAdjType = 24;\r
765                                                 }\r
766                                                 else if(pCoexDm->curPsTdma == 24)\r
767                                                 {\r
768                                                         halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 25);\r
769                                                         pCoexDm->psTdmaDuAdjType = 25;\r
770                                                 }\r
771                                                 else if(pCoexDm->curPsTdma == 25)\r
772                                                 {\r
773                                                         halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 27);\r
774                                                         pCoexDm->psTdmaDuAdjType = 27;\r
775                                                 }\r
776                                         } \r
777                                         else if (result == 1)\r
778                                         {\r
779                                                 if(pCoexDm->curPsTdma == 27)\r
780                                                 {\r
781                                                         halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 25);\r
782                                                         pCoexDm->psTdmaDuAdjType = 25;\r
783                                                 }\r
784                                                 else if(pCoexDm->curPsTdma == 25)\r
785                                                 {\r
786                                                         halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 24);\r
787                                                         pCoexDm->psTdmaDuAdjType = 24;\r
788                                                 }\r
789                                                 else if(pCoexDm->curPsTdma == 24)\r
790                                                 {\r
791                                                         halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 23);\r
792                                                         pCoexDm->psTdmaDuAdjType = 23;\r
793                                                 }\r
794                                         }\r
795                                         // error handle, if not in the following state,\r
796                                         // set psTdma again.\r
797                                         if( (pCoexDm->psTdmaDuAdjType != 23) &&\r
798                                                 (pCoexDm->psTdmaDuAdjType != 24) &&\r
799                                                 (pCoexDm->psTdmaDuAdjType != 25) &&\r
800                                                 (pCoexDm->psTdmaDuAdjType != 27) )\r
801                                         {\r
802                                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], duration case out of handle!!\n"));\r
803                                                 halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 24);\r
804                                                 pCoexDm->psTdmaDuAdjType = 24;\r
805                                         }\r
806                                 }\r
807                         }\r
808                         else\r
809                         {\r
810                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], ACL only busy\n"));\r
811                                 if (result == -1)\r
812                                 {\r
813                                         if(pCoexDm->curPsTdma == 1)\r
814                                         {\r
815                                                 halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
816                                                 pCoexDm->psTdmaDuAdjType = 2;\r
817                                         }\r
818                                         else if(pCoexDm->curPsTdma == 2)\r
819                                         {\r
820                                                 halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
821                                                 pCoexDm->psTdmaDuAdjType = 9;\r
822                                         }\r
823                                         else if(pCoexDm->curPsTdma == 9)\r
824                                         {\r
825                                                 halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
826                                                 pCoexDm->psTdmaDuAdjType = 11;\r
827                                         }\r
828                                 }\r
829                                 else if (result == 1)\r
830                                 {\r
831                                         if(pCoexDm->curPsTdma == 11)\r
832                                         {\r
833                                                 halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
834                                                 pCoexDm->psTdmaDuAdjType = 9;\r
835                                         }\r
836                                         else if(pCoexDm->curPsTdma == 9)\r
837                                         {\r
838                                                 halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
839                                                 pCoexDm->psTdmaDuAdjType = 2;\r
840                                         }\r
841                                         else if(pCoexDm->curPsTdma == 2)\r
842                                         {\r
843                                                 halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
844                                                 pCoexDm->psTdmaDuAdjType = 1;\r
845                                         }\r
846                                 }\r
847 \r
848                                 // error handle, if not in the following state,\r
849                                 // set psTdma again.\r
850                                 if( (pCoexDm->psTdmaDuAdjType != 1) &&\r
851                                         (pCoexDm->psTdmaDuAdjType != 2) &&\r
852                                         (pCoexDm->psTdmaDuAdjType != 9) &&\r
853                                         (pCoexDm->psTdmaDuAdjType != 11) )\r
854                                 {\r
855                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], duration case out of handle!!\n"));\r
856                                         halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
857                                         pCoexDm->psTdmaDuAdjType = 2;\r
858                                 }\r
859                         }\r
860                 }\r
861         }\r
862 \r
863         // if current PsTdma not match with the recorded one (when scan, dhcp...), \r
864         // then we have to adjust it back to the previous record one.\r
865         if(pCoexDm->curPsTdma != pCoexDm->psTdmaDuAdjType)\r
866         {\r
867                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], PsTdma type dismatch!!!, curPsTdma=%d, recordPsTdma=%d\n", \r
868                         pCoexDm->curPsTdma, pCoexDm->psTdmaDuAdjType));\r
869 \r
870                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);\r
871                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);\r
872                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);\r
873 \r
874                 if( !bScan && !bLink && !bRoam)\r
875                 {\r
876                         halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, pCoexDm->psTdmaDuAdjType);\r
877                 }\r
878                 else\r
879                 {\r
880                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n"));\r
881                 }\r
882         }\r
883         pCoexDm->psTdmaMonitorCnt++;\r
884 }\r
885 \r
886 \r
887 VOID\r
888 halbtc8723a1ant_CoexForWifiConnect(\r
889         IN      PBTC_COEXIST            pBtCoexist\r
890         )\r
891 {\r
892         BOOLEAN         bWifiConnected=FALSE, bWifiBusy=FALSE;\r
893         u1Byte          btState, btInfoOriginal=0;\r
894 \r
895         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
896 \r
897         btState = pCoexDm->btStatus;\r
898         btInfoOriginal = pCoexSta->btInfoC2h[BT_INFO_SRC_8723A_1ANT_BT_RSP][0];\r
899 \r
900         if(bWifiConnected)\r
901         {\r
902                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], wifi connected!!\n"));\r
903                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
904                 \r
905                 if( !bWifiBusy &&\r
906                         ((BT_STATE_8723A_1ANT_NO_CONNECTION == btState) ||\r
907                         (BT_STATE_8723A_1ANT_CONNECT_IDLE == btState)) )\r
908                 {\r
909                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], [Wifi is idle] or [Bt is non connected idle or Bt is connected idle]!!\n"));\r
910 \r
911                         if(BT_STATE_8723A_1ANT_NO_CONNECTION == btState)\r
912                                 halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 9);\r
913                         else if(BT_STATE_8723A_1ANT_CONNECT_IDLE == btState)\r
914                                 halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
915 \r
916                         pBtCoexist->fBtcSetBbReg(pBtCoexist, 0x880, 0xff000000, 0xc0);\r
917                 }\r
918                 else\r
919                 {\r
920                         if( (BT_STATE_8723A_1ANT_SCO_ONLY_BUSY == btState) ||\r
921                                 (BT_STATE_8723A_1ANT_ACL_SCO_BUSY == btState) ||\r
922                                 (BT_STATE_8723A_1ANT_HID_BUSY == btState) ||\r
923                                 (BT_STATE_8723A_1ANT_HID_SCO_BUSY == btState) )\r
924                         {\r
925                                 pBtCoexist->fBtcSetBbReg(pBtCoexist, 0x880, 0xff000000, 0x60);\r
926                         }\r
927                         else\r
928                         {\r
929                                 pBtCoexist->fBtcSetBbReg(pBtCoexist, 0x880, 0xff000000, 0xc0);\r
930                         }\r
931                         switch(btState)\r
932                         {\r
933                                 case BT_STATE_8723A_1ANT_NO_CONNECTION:\r
934                                         halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
935                                         break;\r
936                                 case BT_STATE_8723A_1ANT_CONNECT_IDLE:\r
937                                         halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
938                                         break;\r
939                                 case BT_STATE_8723A_1ANT_INQ_OR_PAG:\r
940                                         halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
941                                         break;\r
942                                 case BT_STATE_8723A_1ANT_SCO_ONLY_BUSY:\r
943                                 case BT_STATE_8723A_1ANT_ACL_SCO_BUSY:\r
944                                 case BT_STATE_8723A_1ANT_HID_BUSY:\r
945                                 case BT_STATE_8723A_1ANT_HID_SCO_BUSY:\r
946                                         halbtc8723a1ant_TdmaDurationAdjust(pBtCoexist);\r
947                                         break;\r
948                                 case BT_STATE_8723A_1ANT_ACL_ONLY_BUSY:\r
949                                         if (btInfoOriginal&BT_INFO_8723A_1ANT_B_A2DP)\r
950                                         {\r
951                                                 halbtc8723a1ant_TdmaDurationAdjust(pBtCoexist);\r
952                                         }\r
953                                         else if(btInfoOriginal&BT_INFO_8723A_1ANT_B_FTP)\r
954                                         {\r
955                                                 halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
956                                         }\r
957                                         else if( (btInfoOriginal&BT_INFO_8723A_1ANT_B_A2DP) &&\r
958                                                         (btInfoOriginal&BT_INFO_8723A_1ANT_B_FTP) )\r
959                                         {\r
960                                                 halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
961                                         }\r
962                                         else\r
963                                         {\r
964                                                 halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
965                                         }\r
966                                         break;\r
967                                 default:\r
968                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], error!!!, undefined case in halbtc8723a1ant_CoexForWifiConnect()!!\n"));\r
969                                         break;\r
970                         }\r
971                 }\r
972         }\r
973         else\r
974         {\r
975                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], wifi is disconnected!!\n"));\r
976         }\r
977 \r
978         pCoexDm->psTdmaGlobalCnt++;\r
979 }\r
980 \r
981 //============================================================\r
982 // work around function start with wa_halbtc8723a1ant_\r
983 //============================================================\r
984 VOID\r
985 wa_halbtc8723a1ant_MonitorC2h(\r
986         IN      PBTC_COEXIST                    pBtCoexist\r
987         )\r
988 {\r
989         u1Byte  tmp1b=0x0;\r
990         u4Byte  curC2hTotalCnt=0x0;\r
991         static u4Byte   preC2hTotalCnt=0x0, sameCntPollingTime=0x0;\r
992 \r
993         curC2hTotalCnt+=pCoexSta->btInfoC2hCnt[BT_INFO_SRC_8723A_1ANT_BT_RSP];\r
994 \r
995         if(curC2hTotalCnt == preC2hTotalCnt)\r
996         {\r
997                 sameCntPollingTime++;\r
998         }\r
999         else\r
1000         {\r
1001                 preC2hTotalCnt = curC2hTotalCnt;\r
1002                 sameCntPollingTime = 0;\r
1003         }\r
1004 \r
1005         if(sameCntPollingTime >= 2)\r
1006         {\r
1007                 tmp1b = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x1af);\r
1008                 if(tmp1b != 0x0)\r
1009                 {\r
1010                         pCoexSta->c2hHangDetectCnt++;\r
1011                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x1af, 0x0);\r
1012                 }\r
1013         }\r
1014 }\r
1015 \r
1016 //============================================================\r
1017 // extern function start with EXhalbtc8723a1ant_\r
1018 //============================================================\r
1019 VOID\r
1020 EXhalbtc8723a1ant_InitHwConfig(\r
1021         IN      PBTC_COEXIST            pBtCoexist\r
1022         )\r
1023 {\r
1024         BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], 1Ant Init HW Config!!\n"));\r
1025 \r
1026         // backup rf 0x1e value\r
1027         pCoexDm->btRf0x1eBackup = \r
1028                 pBtCoexist->fBtcGetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff);\r
1029 \r
1030         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0x20);\r
1031 \r
1032         // enable counter statistics\r
1033         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4);\r
1034         \r
1035         // coex table\r
1036         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cc, 0x0);                     // 1-Ant coex\r
1037         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c8, 0xffff);          // wifi break table\r
1038         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c4, 0x55555555);      //coex table\r
1039 \r
1040         // antenna switch control parameter\r
1041         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x858, 0xaaaaaaaa);\r
1042         \r
1043         pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x860, 0x210);   //set antenna at wifi side if ANTSW is software control\r
1044         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x870, 0x300);   //SPDT(connected with TRSW) control by hardware PTA\r
1045         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x874, 0x22804000);      //ANTSW keep by GNT_BT\r
1046 \r
1047         // coexistence parameters\r
1048         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x778, 0x1);     // enable RTK mode PTA\r
1049 }\r
1050 \r
1051 VOID\r
1052 EXhalbtc8723a1ant_InitCoexDm(\r
1053         IN      PBTC_COEXIST            pBtCoexist\r
1054         )\r
1055 {\r
1056         BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], Coex Mechanism Init!!\n"));\r
1057         \r
1058         halbtc8723a1ant_InitCoexDm(pBtCoexist);\r
1059 }\r
1060 \r
1061 VOID\r
1062 EXhalbtc8723a1ant_DisplayCoexInfo(\r
1063         IN      PBTC_COEXIST            pBtCoexist\r
1064         )\r
1065 {\r
1066         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;\r
1067         PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;\r
1068         pu1Byte                         cliBuf=pBtCoexist->cliBuf;\r
1069         u1Byte                          u1Tmp[4], i, btInfoExt, psTdmaCase=0;\r
1070         u4Byte                          u4Tmp[4];\r
1071 \r
1072         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[BT Coexist info]============");\r
1073         CL_PRINTF(cliBuf);\r
1074 \r
1075         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ", "Ant PG number/ Ant mechanism:", \\r
1076                 pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum);\r
1077         CL_PRINTF(cliBuf);      \r
1078         \r
1079         if(pBtCoexist->bManualControl)\r
1080         {\r
1081                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "[Action Manual control]!!");\r
1082                 CL_PRINTF(cliBuf);\r
1083         }\r
1084         \r
1085         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d", "BT stack/ hci ext ver", \\r
1086                 ((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion);\r
1087         CL_PRINTF(cliBuf);\r
1088 \r
1089         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", "Wifi channel informed to BT", \\r
1090                 pCoexDm->wifiChnlInfo[0], pCoexDm->wifiChnlInfo[1],\r
1091                 pCoexDm->wifiChnlInfo[2]);\r
1092         CL_PRINTF(cliBuf);\r
1093 \r
1094         // wifi status\r
1095         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Wifi Status]============");\r
1096         CL_PRINTF(cliBuf);\r
1097         pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_WIFI_STATUS);\r
1098 \r
1099         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[BT Status]============");\r
1100         CL_PRINTF(cliBuf);\r
1101 \r
1102         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d] ", "BT [status/ rssi/ retryCnt]", \\r
1103                 ((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"))),\r
1104                 pCoexSta->btRssi, pCoexSta->btRetryCnt);\r
1105         CL_PRINTF(cliBuf);\r
1106         \r
1107         if(pStackInfo->bProfileNotified)\r
1108         {                       \r
1109                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP", \\r
1110                         pStackInfo->bScoExist, pStackInfo->bHidExist, pStackInfo->bPanExist, pStackInfo->bA2dpExist);\r
1111                 CL_PRINTF(cliBuf);      \r
1112 \r
1113                 pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_BT_LINK_INFO);\r
1114         }\r
1115 \r
1116         btInfoExt = pCoexSta->btInfoExt;\r
1117         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "BT Info A2DP rate", \\r
1118                 (btInfoExt&BIT0)? "Basic rate":"EDR rate");\r
1119         CL_PRINTF(cliBuf);      \r
1120 \r
1121         for(i=0; i<BT_INFO_SRC_8723A_1ANT_MAX; i++)\r
1122         {\r
1123                 if(pCoexSta->btInfoC2hCnt[i])\r
1124                 {                               \r
1125                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", GLBtInfoSrc8723a1Ant[i], \\r
1126                                 pCoexSta->btInfoC2h[i][0], pCoexSta->btInfoC2h[i][1],\r
1127                                 pCoexSta->btInfoC2h[i][2], pCoexSta->btInfoC2h[i][3],\r
1128                                 pCoexSta->btInfoC2h[i][4], pCoexSta->btInfoC2h[i][5],\r
1129                                 pCoexSta->btInfoC2h[i][6], pCoexSta->btInfoC2hCnt[i]);\r
1130                         CL_PRINTF(cliBuf);\r
1131                 }\r
1132         }\r
1133 \r
1134         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "write 0x1af=0x0 num", \\r
1135                 pCoexSta->c2hHangDetectCnt);\r
1136         CL_PRINTF(cliBuf);\r
1137         \r
1138         // Sw mechanism \r
1139         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw mechanism]============");\r
1140         CL_PRINTF(cliBuf);\r
1141         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d", "SM1[ShRf/ LpRA/ LimDig]", \\r
1142                 pCoexDm->bCurRfRxLpfShrink, pCoexDm->bCurLowPenaltyRa, pCoexDm->bLimitedDig);\r
1143         CL_PRINTF(cliBuf);\r
1144 \r
1145         // Fw mechanism         \r
1146         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw mechanism]============");\r
1147         CL_PRINTF(cliBuf);      \r
1148         \r
1149         if(!pBtCoexist->bManualControl)\r
1150         {\r
1151                 psTdmaCase = pCoexDm->curPsTdma;\r
1152                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x case-%d", "PS TDMA", \\r
1153                         pCoexDm->psTdmaPara[0], pCoexDm->psTdmaPara[1],\r
1154                         pCoexDm->psTdmaPara[2], pCoexDm->psTdmaPara[3],\r
1155                         pCoexDm->psTdmaPara[4], psTdmaCase);\r
1156                 CL_PRINTF(cliBuf);\r
1157         \r
1158                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d ", "IgnWlanAct", \\r
1159                         pCoexDm->bCurIgnoreWlanAct);\r
1160                 CL_PRINTF(cliBuf);\r
1161         }\r
1162 \r
1163         // Hw setting           \r
1164         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Hw setting]============");\r
1165         CL_PRINTF(cliBuf);      \r
1166 \r
1167         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "RF-A, 0x1e initVal", \\r
1168                 pCoexDm->btRf0x1eBackup);\r
1169         CL_PRINTF(cliBuf);\r
1170 \r
1171         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x778);\r
1172         u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x783);\r
1173         u1Tmp[2] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x796);\r
1174         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x778/ 0x783/ 0x796", \\r
1175                 u1Tmp[0], u1Tmp[1], u1Tmp[2]);\r
1176         CL_PRINTF(cliBuf);\r
1177 \r
1178         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x880);\r
1179         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x880", \\r
1180                 u4Tmp[0]);\r
1181         CL_PRINTF(cliBuf);\r
1182 \r
1183         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x40);\r
1184         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x40", \\r
1185                 u1Tmp[0]);\r
1186         CL_PRINTF(cliBuf);\r
1187 \r
1188         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x550);\r
1189         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x522);\r
1190         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0x550(bcn ctrl)/0x522", \\r
1191                 u4Tmp[0], u1Tmp[0]);\r
1192         CL_PRINTF(cliBuf);\r
1193 \r
1194         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x484);\r
1195         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x484(rate adaptive)", \\r
1196                 u4Tmp[0]);\r
1197         CL_PRINTF(cliBuf);\r
1198 \r
1199         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xc50);\r
1200         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0xc50(dig)", \\r
1201                 u4Tmp[0]);\r
1202         CL_PRINTF(cliBuf);\r
1203 \r
1204         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda0);\r
1205         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda4);\r
1206         u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda8);\r
1207         u4Tmp[3] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xdac);\r
1208         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0xda0/0xda4/0xda8/0xdac(FA cnt)", \\r
1209                 u4Tmp[0], u4Tmp[1], u4Tmp[2], u4Tmp[3]);\r
1210         CL_PRINTF(cliBuf);\r
1211 \r
1212         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c0);\r
1213         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c4);\r
1214         u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c8);\r
1215         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x6cc);\r
1216         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)", \\r
1217                 u4Tmp[0], u4Tmp[1], u4Tmp[2], u1Tmp[0]);\r
1218         CL_PRINTF(cliBuf);\r
1219 \r
1220         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x770 (hp rx[31:16]/tx[15:0])", \\r
1221                 pCoexSta->highPriorityRx, pCoexSta->highPriorityTx);\r
1222         CL_PRINTF(cliBuf);\r
1223         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x774(lp rx[31:16]/tx[15:0])", \\r
1224                 pCoexSta->lowPriorityRx, pCoexSta->lowPriorityTx);\r
1225         CL_PRINTF(cliBuf);\r
1226 \r
1227         pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_COEX_STATISTICS);\r
1228 }\r
1229 \r
1230 \r
1231 VOID\r
1232 EXhalbtc8723a1ant_IpsNotify(\r
1233         IN      PBTC_COEXIST            pBtCoexist,\r
1234         IN      u1Byte                  type\r
1235         )\r
1236 {\r
1237         if(BTC_IPS_ENTER == type)\r
1238         {\r
1239                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], IPS ENTER notify\n"));\r
1240                 halbtc8723a1ant_CoexAllOff(pBtCoexist);\r
1241         }\r
1242         else if(BTC_IPS_LEAVE == type)\r
1243         {\r
1244                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], IPS LEAVE notify\n"));\r
1245                 //halbtc8723a1ant_InitCoexDm(pBtCoexist);\r
1246         }\r
1247 }\r
1248 \r
1249 VOID\r
1250 EXhalbtc8723a1ant_LpsNotify(\r
1251         IN      PBTC_COEXIST            pBtCoexist,\r
1252         IN      u1Byte                  type\r
1253         )\r
1254 {\r
1255         if(BTC_LPS_ENABLE == type)\r
1256         {\r
1257                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], LPS ENABLE notify\n"));\r
1258         }\r
1259         else if(BTC_LPS_DISABLE == type)\r
1260         {\r
1261                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], LPS DISABLE notify\n"));\r
1262                 halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 8);\r
1263         }\r
1264 }\r
1265 \r
1266 VOID\r
1267 EXhalbtc8723a1ant_ScanNotify(\r
1268         IN      PBTC_COEXIST            pBtCoexist,\r
1269         IN      u1Byte                  type\r
1270         )\r
1271 {\r
1272         BOOLEAN         bWifiConnected=FALSE;\r
1273         \r
1274         halbtc8723a1ant_NotifyFwScan(pBtCoexist, type);\r
1275 \r
1276         if(pBtCoexist->btInfo.bBtDisabled)\r
1277         {\r
1278                 halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 9); \r
1279         }\r
1280         else\r
1281         {\r
1282                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
1283                 if(BTC_SCAN_START == type)\r
1284                 {\r
1285                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], SCAN START notify\n"));\r
1286                         if(!bWifiConnected)     // non-connected scan\r
1287                         {\r
1288                                 //set 0x550[3]=1 before PsTdma\r
1289                                 halbtc8723a1ant_Reg0x550Bit3(pBtCoexist, TRUE);\r
1290                         }\r
1291 \r
1292                         halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
1293                 }\r
1294                 else if(BTC_SCAN_FINISH == type)\r
1295                 {\r
1296                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], SCAN FINISH notify\n"));\r
1297                         if(!bWifiConnected)     // non-connected scan\r
1298                         {\r
1299                                 halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0); \r
1300                         }\r
1301                         else\r
1302                         {\r
1303                                 halbtc8723a1ant_CoexForWifiConnect(pBtCoexist);\r
1304                         }\r
1305                 }\r
1306         }\r
1307 }\r
1308 \r
1309 VOID\r
1310 EXhalbtc8723a1ant_ConnectNotify(\r
1311         IN      PBTC_COEXIST            pBtCoexist,\r
1312         IN      u1Byte                  type\r
1313         )\r
1314 {\r
1315         BOOLEAN         bWifiConnected=FALSE;\r
1316                 \r
1317         if(pBtCoexist->btInfo.bBtDisabled)\r
1318         {\r
1319                 halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 9); \r
1320         }\r
1321         else\r
1322         {\r
1323                 if(BTC_ASSOCIATE_START == type)\r
1324                 {\r
1325                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], CONNECT START notify\n"));\r
1326                         //set 0x550[3]=1 before PsTdma\r
1327                         halbtc8723a1ant_Reg0x550Bit3(pBtCoexist, TRUE);\r
1328                         halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);       // extend wifi slot     \r
1329                 }\r
1330                 else if(BTC_ASSOCIATE_FINISH == type)\r
1331                 {\r
1332                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], CONNECT FINISH notify\n"));\r
1333                         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
1334                         if(!bWifiConnected)     // non-connected scan\r
1335                         {\r
1336                                 halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
1337                         }\r
1338                         else\r
1339                         {\r
1340                                 halbtc8723a1ant_CoexForWifiConnect(pBtCoexist);\r
1341                         }\r
1342                 }\r
1343         }\r
1344 }\r
1345 \r
1346 VOID\r
1347 EXhalbtc8723a1ant_MediaStatusNotify(\r
1348         IN      PBTC_COEXIST                    pBtCoexist,\r
1349         IN      u1Byte                          type\r
1350         )\r
1351 {\r
1352         if(BTC_MEDIA_CONNECT == type)\r
1353         {\r
1354                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], MEDIA connect notify\n"));\r
1355         }\r
1356         else\r
1357         {\r
1358                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], MEDIA disconnect notify\n"));\r
1359         }\r
1360 }\r
1361 \r
1362 VOID\r
1363 EXhalbtc8723a1ant_SpecialPacketNotify(\r
1364         IN      PBTC_COEXIST                    pBtCoexist,\r
1365         IN      u1Byte                          type\r
1366         )\r
1367 {\r
1368         if(type == BTC_PACKET_DHCP)\r
1369         {\r
1370                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], DHCP Packet notify\n"));\r
1371                 if(pBtCoexist->btInfo.bBtDisabled)\r
1372                 {\r
1373                         halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 9);      \r
1374                 }\r
1375                 else\r
1376                 {\r
1377                         halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 18);\r
1378                 }               \r
1379         }\r
1380 }\r
1381 \r
1382 VOID\r
1383 EXhalbtc8723a1ant_BtInfoNotify(\r
1384         IN      PBTC_COEXIST            pBtCoexist,\r
1385         IN      pu1Byte                 tmpBuf,\r
1386         IN      u1Byte                  length\r
1387         )\r
1388 {\r
1389         u1Byte                  btInfo=0;\r
1390         u1Byte                  i, rspSource=0;\r
1391         BOOLEAN                 bBtHsOn=FALSE, bBtBusy=FALSE, bForceLps=FALSE;\r
1392 \r
1393         pCoexSta->bC2hBtInfoReqSent = FALSE;\r
1394         \r
1395         rspSource = BT_INFO_SRC_8723A_1ANT_BT_RSP;\r
1396         pCoexSta->btInfoC2hCnt[rspSource]++;\r
1397 \r
1398         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Bt info[%d], length=%d, hex data=[", rspSource, length));\r
1399         for(i=0; i<length; i++)\r
1400         {\r
1401                 pCoexSta->btInfoC2h[rspSource][i] = tmpBuf[i];\r
1402                 if(i == 0)\r
1403                         btInfo = tmpBuf[i];\r
1404                 if(i == length-1)\r
1405                 {\r
1406                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("0x%02x]\n", tmpBuf[i]));\r
1407                 }\r
1408                 else\r
1409                 {\r
1410                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("0x%02x, ", tmpBuf[i]));\r
1411                 }\r
1412         }\r
1413 \r
1414         if(BT_INFO_SRC_8723A_1ANT_WIFI_FW != rspSource)\r
1415         {\r
1416                 pCoexSta->btRetryCnt =\r
1417                         pCoexSta->btInfoC2h[rspSource][1];\r
1418 \r
1419                 pCoexSta->btRssi =\r
1420                         pCoexSta->btInfoC2h[rspSource][2]*2+10;\r
1421 \r
1422                 pCoexSta->btInfoExt = \r
1423                         pCoexSta->btInfoC2h[rspSource][3];\r
1424         }\r
1425                 \r
1426         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
1427         // check BIT2 first ==> check if bt is under inquiry or page scan\r
1428         if(btInfo & BT_INFO_8723A_1ANT_B_INQ_PAGE)\r
1429         {\r
1430                 pCoexSta->bC2hBtInquiryPage = TRUE;\r
1431         }\r
1432         else\r
1433         {\r
1434                 pCoexSta->bC2hBtInquiryPage = FALSE;\r
1435         }\r
1436         btInfo &= ~BIT2;\r
1437         if(!(btInfo & BIT0))\r
1438         {\r
1439                 pCoexDm->btStatus = BT_STATE_8723A_1ANT_NO_CONNECTION;\r
1440                 bForceLps = FALSE;\r
1441         }\r
1442         else\r
1443         {\r
1444                 bForceLps = TRUE;\r
1445                 if(btInfo == 0x1)\r
1446                 {\r
1447                         pCoexDm->btStatus = BT_STATE_8723A_1ANT_CONNECT_IDLE;\r
1448                 }\r
1449                 else if(btInfo == 0x9)\r
1450                 {\r
1451                         pCoexDm->btStatus = BT_STATE_8723A_1ANT_ACL_ONLY_BUSY;\r
1452                         bBtBusy = TRUE;\r
1453                 }\r
1454                 else if(btInfo == 0x13)\r
1455                 {\r
1456                         pCoexDm->btStatus = BT_STATE_8723A_1ANT_SCO_ONLY_BUSY;\r
1457                         bBtBusy = TRUE;\r
1458                 }\r
1459                 else if(btInfo == 0x1b)\r
1460                 {\r
1461                         pCoexDm->btStatus = BT_STATE_8723A_1ANT_ACL_SCO_BUSY;\r
1462                         bBtBusy = TRUE;\r
1463                 }\r
1464                 else if(btInfo == 0x29)\r
1465                 {\r
1466                         pCoexDm->btStatus = BT_STATE_8723A_1ANT_HID_BUSY;\r
1467                         bBtBusy = TRUE;\r
1468                 }\r
1469                 else if(btInfo == 0x3b)\r
1470                 {\r
1471                         pCoexDm->btStatus = BT_STATE_8723A_1ANT_HID_SCO_BUSY;\r
1472                         bBtBusy = TRUE;\r
1473                 }\r
1474         }\r
1475         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);\r
1476         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_LIMITED_DIG, &bBtBusy);\r
1477         if(bForceLps)\r
1478                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_ENTER_LPS, NULL);\r
1479         else\r
1480                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_NORMAL_LPS, NULL);\r
1481 \r
1482         if( (BT_STATE_8723A_1ANT_NO_CONNECTION == pCoexDm->btStatus) ||\r
1483                 (BT_STATE_8723A_1ANT_CONNECT_IDLE == pCoexDm->btStatus) )\r
1484         {\r
1485                 if(pCoexSta->bC2hBtInquiryPage)\r
1486                         pCoexDm->btStatus = BT_STATE_8723A_1ANT_INQ_OR_PAG;\r
1487         }\r
1488 }\r
1489 \r
1490 VOID\r
1491 EXhalbtc8723a1ant_HaltNotify(\r
1492         IN      PBTC_COEXIST                    pBtCoexist\r
1493         )\r
1494 {\r
1495         halbtc8723a1ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 0);\r
1496         \r
1497         halbtc8723a1ant_LowPenaltyRa(pBtCoexist, FORCE_EXEC, FALSE);\r
1498         halbtc8723a1ant_RfShrink(pBtCoexist, FORCE_EXEC, FALSE);\r
1499 \r
1500         halbtc8723a1ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE);\r
1501         EXhalbtc8723a1ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);\r
1502 }\r
1503 \r
1504 VOID\r
1505 EXhalbtc8723a1ant_Periodical(\r
1506         IN      PBTC_COEXIST                    pBtCoexist\r
1507         )\r
1508 {\r
1509         BOOLEAN         bScan=FALSE, bLink=FALSE, bRoam=FALSE, bWifiConnected=FALSE;\r
1510         \r
1511         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], 1Ant Periodical!!\n"));\r
1512         \r
1513         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);\r
1514         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);\r
1515         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);\r
1516         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
1517 \r
1518         // work around for c2h hang\r
1519         wa_halbtc8723a1ant_MonitorC2h(pBtCoexist);      \r
1520 \r
1521         halbtc8723a1ant_QueryBtInfo(pBtCoexist);\r
1522         halbtc8723a1ant_MonitorBtCtr(pBtCoexist);\r
1523         halbtc8723a1ant_MonitorBtEnableDisable(pBtCoexist);\r
1524 \r
1525         \r
1526         if(bScan)\r
1527                 return;\r
1528         if(bLink)\r
1529                 return;\r
1530 \r
1531         if(bWifiConnected)\r
1532         {\r
1533                 if(pBtCoexist->btInfo.bBtDisabled)\r
1534                 {\r
1535                         halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 9);\r
1536                         \r
1537                         halbtc8723a1ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, FALSE);\r
1538                         halbtc8723a1ant_RfShrink(pBtCoexist, NORMAL_EXEC, FALSE);\r
1539                 }\r
1540                 else\r
1541                 {\r
1542                         halbtc8723a1ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, TRUE);\r
1543                         halbtc8723a1ant_RfShrink(pBtCoexist, NORMAL_EXEC, FALSE);\r
1544                         halbtc8723a1ant_CoexForWifiConnect(pBtCoexist);\r
1545                 }\r
1546         }\r
1547         else\r
1548         {\r
1549                 halbtc8723a1ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
1550 \r
1551                 halbtc8723a1ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, FALSE);\r
1552                 halbtc8723a1ant_RfShrink(pBtCoexist, NORMAL_EXEC, FALSE);\r
1553         }\r
1554 }\r
1555 \r
1556 \r
1557 #endif\r
1558 \r