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