8723BU: Update 8723BU wifi driver to version v4.3.16_14189.20150519_BTCOEX2015119...
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723bu / hal / OUTSRC-BTCoexist / HalBtc8188c2Ant.c
1 //============================================================\r
2 // Description:\r
3 //\r
4 // This file is for 92CE/92CU BT 1 Antenna Co-exist mechanism\r
5 //\r
6 // By cosa 02/11/2011\r
7 //\r
8 //============================================================\r
9 \r
10 //============================================================\r
11 // include files\r
12 //============================================================\r
13 #include "Mp_Precomp.h"\r
14 \r
15 #if WPP_SOFTWARE_TRACE\r
16 #include "HalBtc8188c2Ant.tmh"\r
17 #endif\r
18 \r
19 #if(BT_30_SUPPORT == 1)\r
20 //============================================================\r
21 // Global variables, these are static variables\r
22 //============================================================\r
23 static COEX_DM_8188C_2ANT       GLCoexDm8188c2Ant;\r
24 static PCOEX_DM_8188C_2ANT      pCoexDm=&GLCoexDm8188c2Ant;\r
25 static COEX_STA_8188C_2ANT      GLCoexSta8188c2Ant;\r
26 static PCOEX_STA_8188C_2ANT     pCoexSta=&GLCoexSta8188c2Ant;\r
27 \r
28 //============================================================\r
29 // local function start with btdm_\r
30 //============================================================\r
31 u1Byte\r
32 halbtc8188c2ant_WifiRssiState(\r
33         IN      PBTC_COEXIST            pBtCoexist,\r
34         IN      u1Byte                  index,\r
35         IN      u1Byte                  levelNum,\r
36         IN      u1Byte                  rssiThresh,\r
37         IN      u1Byte                  rssiThresh1\r
38         )\r
39 {\r
40         s4Byte                  wifiRssi=0;\r
41         u1Byte                  wifiRssiState=pCoexSta->preWifiRssiState[index];\r
42 \r
43         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);\r
44         \r
45         if(levelNum == 2)\r
46         {\r
47                 if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||\r
48                         (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW))\r
49                 {\r
50                         if(wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8188C_2ANT))\r
51                         {\r
52                                 wifiRssiState = BTC_RSSI_STATE_HIGH;\r
53                         }\r
54                         else\r
55                         {\r
56                                 wifiRssiState = BTC_RSSI_STATE_STAY_LOW;\r
57                         }\r
58                 }\r
59                 else\r
60                 {\r
61                         if(wifiRssi < rssiThresh)\r
62                         {\r
63                                 wifiRssiState = BTC_RSSI_STATE_LOW;\r
64                         }\r
65                         else\r
66                         {\r
67                                 wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
68                         }\r
69                 }\r
70         }\r
71         else if(levelNum == 3)\r
72         {\r
73                 if(rssiThresh > rssiThresh1)\r
74                 {\r
75                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], wifi RSSI thresh error!!\n"));\r
76                         return pCoexSta->preWifiRssiState[index];\r
77                 }\r
78                 \r
79                 if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||\r
80                         (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW))\r
81                 {\r
82                         if(wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8188C_2ANT))\r
83                         {\r
84                                 wifiRssiState = BTC_RSSI_STATE_MEDIUM;\r
85                         }\r
86                         else\r
87                         {\r
88                                 wifiRssiState = BTC_RSSI_STATE_STAY_LOW;\r
89                         }\r
90                 }\r
91                 else if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_MEDIUM) ||\r
92                         (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_MEDIUM))\r
93                 {\r
94                         if(wifiRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8188C_2ANT))\r
95                         {\r
96                                 wifiRssiState = BTC_RSSI_STATE_HIGH;\r
97                         }\r
98                         else if(wifiRssi < rssiThresh)\r
99                         {\r
100                                 wifiRssiState = BTC_RSSI_STATE_LOW;\r
101                         }\r
102                         else\r
103                         {\r
104                                 wifiRssiState = BTC_RSSI_STATE_STAY_MEDIUM;\r
105                         }\r
106                 }\r
107                 else\r
108                 {\r
109                         if(wifiRssi < rssiThresh1)\r
110                         {\r
111                                 wifiRssiState = BTC_RSSI_STATE_MEDIUM;\r
112                         }\r
113                         else\r
114                         {\r
115                                 wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
116                         }\r
117                 }\r
118         }\r
119                 \r
120         pCoexSta->preWifiRssiState[index] = wifiRssiState;\r
121 \r
122         return wifiRssiState;\r
123 }\r
124 \r
125 u1Byte\r
126 halbtc8188c2ant_ActionAlgorithm(\r
127         IN      PBTC_COEXIST            pBtCoexist\r
128         )\r
129 {\r
130         PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;\r
131         u1Byte                          algorithm=BT_8188C_2ANT_COEX_ALGO_UNDEFINED;\r
132         u1Byte                          numOfDiffProfile=0;\r
133         \r
134         if(!pStackInfo->bBtLinkExist)\r
135         {\r
136                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], No profile exists!!!\n"));\r
137                 return algorithm;\r
138         }\r
139 \r
140         if(pStackInfo->bScoExist)\r
141                 numOfDiffProfile++;\r
142         if(pStackInfo->bHidExist)\r
143                 numOfDiffProfile++;\r
144         if(pStackInfo->bPanExist)\r
145                 numOfDiffProfile++;\r
146         if(pStackInfo->bA2dpExist)\r
147                 numOfDiffProfile++;\r
148 \r
149         if(pStackInfo->bScoExist)\r
150         {\r
151                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO algorithm\n"));\r
152                 algorithm = BT_8188C_2ANT_COEX_ALGO_SCO;\r
153         }\r
154         else\r
155         {\r
156                 if(numOfDiffProfile == 1)\r
157                 {\r
158                         if(pStackInfo->bHidExist)\r
159                         {\r
160                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], HID only\n"));\r
161                                 algorithm = BT_8188C_2ANT_COEX_ALGO_HID;\r
162                         }\r
163                         else if(pStackInfo->bA2dpExist)\r
164                         {\r
165                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], A2DP only\n"));\r
166                                 algorithm = BT_8188C_2ANT_COEX_ALGO_A2DP;\r
167                         }\r
168                         else if(pStackInfo->bPanExist)\r
169                         {\r
170                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], PAN only\n"));\r
171                                 algorithm = BT_8188C_2ANT_COEX_ALGO_PAN;\r
172                         }\r
173                 }\r
174                 else\r
175                 {\r
176                         if( pStackInfo->bHidExist &&\r
177                                 pStackInfo->bA2dpExist )\r
178                         {\r
179                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], HID + A2DP\n"));\r
180                                 algorithm = BT_8188C_2ANT_COEX_ALGO_HID_A2DP;\r
181                         }\r
182                         else if( pStackInfo->bHidExist &&\r
183                                 pStackInfo->bPanExist )\r
184                         {                               \r
185                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], HID + PAN\n"));\r
186                                 algorithm = BT_8188C_2ANT_COEX_ALGO_HID_PAN;\r
187                         }\r
188                         else if( pStackInfo->bPanExist &&\r
189                                 pStackInfo->bA2dpExist )\r
190                         {                               \r
191                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], PAN + A2DP\n"));\r
192                                 algorithm = BT_8188C_2ANT_COEX_ALGO_PAN_A2DP;\r
193                         }\r
194                 }               \r
195         }\r
196         return algorithm;\r
197 }\r
198 \r
199 VOID\r
200 halbtc8188c2ant_SetFwBalance(\r
201         IN      PBTC_COEXIST            pBtCoexist,\r
202         IN      BOOLEAN                 bBalanceOn,\r
203         IN      u1Byte                  ms0,\r
204         IN      u1Byte                  ms1\r
205         )\r
206 {\r
207         u1Byte  H2C_Parameter[3] ={0};\r
208 \r
209         if(bBalanceOn)\r
210         {\r
211                 H2C_Parameter[2] = 1;\r
212                 H2C_Parameter[1] = ms1;\r
213                 H2C_Parameter[0] = ms0;\r
214         }\r
215         else\r
216         {\r
217                 H2C_Parameter[2] = 0;\r
218                 H2C_Parameter[1] = 0;\r
219                 H2C_Parameter[0] = 0;\r
220         }\r
221         \r
222         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Balance=[%s:%dms:%dms], write 0xc=0x%x\n", \r
223                 bBalanceOn?"ON":"OFF", ms0, ms1,\r
224                 H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));\r
225 \r
226         pBtCoexist->fBtcFillH2c(pBtCoexist, 0xc, 3, H2C_Parameter);     \r
227 }\r
228 \r
229 VOID\r
230 halbtc8188c2ant_Balance(\r
231         IN      PBTC_COEXIST            pBtCoexist,\r
232         IN      BOOLEAN                 bForceExec,\r
233         IN      BOOLEAN                 bBalanceOn,\r
234         IN      u1Byte                  ms0,\r
235         IN      u1Byte                  ms1\r
236         )\r
237 {\r
238         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn Balance %s\n", \r
239                 (bForceExec? "force to":""), (bBalanceOn? "ON":"OFF")));\r
240         pCoexDm->bCurBalanceOn = bBalanceOn;\r
241 \r
242         if(!bForceExec)\r
243         {\r
244                 if(pCoexDm->bPreBalanceOn == pCoexDm->bCurBalanceOn)\r
245                         return;\r
246         }\r
247         halbtc8188c2ant_SetFwBalance(pBtCoexist, bBalanceOn, ms0, ms1);\r
248 \r
249         pCoexDm->bPreBalanceOn = pCoexDm->bCurBalanceOn;\r
250 }\r
251 \r
252 VOID\r
253 halbtc8188c2ant_SetFwDiminishWifi(\r
254         IN      PBTC_COEXIST            pBtCoexist,\r
255         IN      BOOLEAN                 bDacOn,\r
256         IN      BOOLEAN                 bInterruptOn,\r
257         IN      u1Byte                  fwDacSwingLvl,\r
258         IN      BOOLEAN                 bNavOn\r
259         )\r
260 {\r
261         u1Byte                  H2C_Parameter[3] ={0};\r
262 \r
263         if((pBtCoexist->stackInfo.minBtRssi <= -5) && (fwDacSwingLvl == 0x20))\r
264         {\r
265                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], DiminishWiFi 0x20 original, but set 0x18 for Low RSSI!\n"));\r
266                 fwDacSwingLvl = 0x18;\r
267         }\r
268 \r
269         H2C_Parameter[2] = 0;\r
270         H2C_Parameter[1] = fwDacSwingLvl;\r
271         H2C_Parameter[0] = 0;\r
272         if(bDacOn)\r
273         {\r
274                 H2C_Parameter[2] |= 0x01;       //BIT0\r
275                 if(bInterruptOn)\r
276                 {\r
277                         H2C_Parameter[2] |= 0x02;       //BIT1\r
278                 }\r
279         }\r
280         if(bNavOn)\r
281         {\r
282                 H2C_Parameter[2] |= 0x08;       //BIT3\r
283         }\r
284 \r
285         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], bDacOn=%s, bInterruptOn=%s, bNavOn=%s, write 0xe=0x%x\n", \r
286                 (bDacOn?"ON":"OFF"), (bInterruptOn?"ON":"OFF"), (bNavOn?"ON":"OFF"),\r
287                 (H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2])));\r
288         pBtCoexist->fBtcFillH2c(pBtCoexist, 0xe, 3, H2C_Parameter);\r
289 }\r
290 \r
291 VOID\r
292 halbtc8188c2ant_DiminishWifi(\r
293         IN      PBTC_COEXIST            pBtCoexist,\r
294         IN      BOOLEAN                 bForceExec,\r
295         IN      BOOLEAN                 bDacOn,\r
296         IN      BOOLEAN                 bInterruptOn,\r
297         IN      u1Byte                  fwDacSwingLvl,\r
298         IN      BOOLEAN                 bNavOn\r
299         )\r
300 {\r
301         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s set Diminish Wifi, bDacOn=%s, bInterruptOn=%s, fwDacSwingLvl=%d, bNavOn=%s\n", \r
302                 (bForceExec? "force to":""), (bDacOn? "ON":"OFF"), (bInterruptOn? "ON":"OFF"), fwDacSwingLvl, (bNavOn? "ON":"OFF")));\r
303 \r
304         pCoexDm->bCurDacOn = bDacOn;\r
305         pCoexDm->bCurInterruptOn = bInterruptOn;\r
306         pCoexDm->curFwDacSwingLvl = fwDacSwingLvl;\r
307         pCoexDm->bCurNavOn = bNavOn;\r
308 \r
309         if(!bForceExec)\r
310         {\r
311                 if( (pCoexDm->bPreDacOn==pCoexDm->bCurDacOn) &&\r
312                         (pCoexDm->bPreInterruptOn==pCoexDm->bCurInterruptOn) &&\r
313                         (pCoexDm->preFwDacSwingLvl==pCoexDm->curFwDacSwingLvl) &&\r
314                         (pCoexDm->bPreNavOn==pCoexDm->bCurNavOn) )\r
315                         return;\r
316         }\r
317         halbtc8188c2ant_SetFwDiminishWifi(pBtCoexist, bDacOn, bInterruptOn, fwDacSwingLvl, bNavOn);\r
318 \r
319         pCoexDm->bPreDacOn = pCoexDm->bCurDacOn;\r
320         pCoexDm->bPreInterruptOn = pCoexDm->bCurInterruptOn;\r
321         pCoexDm->preFwDacSwingLvl = pCoexDm->curFwDacSwingLvl;\r
322         pCoexDm->bPreNavOn = pCoexDm->bCurNavOn;\r
323 }\r
324 \r
325 VOID\r
326 halbtc8188c2ant_SetSwRfRxLpfCorner(\r
327         IN      PBTC_COEXIST            pBtCoexist,\r
328         IN      BOOLEAN                 bRxRfShrinkOn\r
329         )\r
330 {\r
331         if(bRxRfShrinkOn)\r
332         {\r
333                 //Shrink RF Rx LPF corner\r
334                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Shrink RF Rx LPF corner!!\n"));\r
335                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xf0, 0xf);                \r
336         }\r
337         else\r
338         {\r
339                 //Resume RF Rx LPF corner\r
340                 // After initialized, we can use pCoexDm->btRf0x1eBackup\r
341                 if(pBtCoexist->bInitilized)\r
342                 {\r
343                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Resume RF Rx LPF corner!!\n"));\r
344                         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xf0, pCoexDm->btRf0x1eBackup);\r
345                 }\r
346         }\r
347 }\r
348 \r
349 VOID\r
350 halbtc8188c2ant_RfShrink(\r
351         IN      PBTC_COEXIST            pBtCoexist,\r
352         IN      BOOLEAN                 bForceExec,\r
353         IN      BOOLEAN                 bRxRfShrinkOn\r
354         )\r
355 {\r
356         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn Rx RF Shrink = %s\n",  \r
357                 (bForceExec? "force to":""), ((bRxRfShrinkOn)? "ON":"OFF")));\r
358         pCoexDm->bCurRfRxLpfShrink = bRxRfShrinkOn;\r
359 \r
360         if(!bForceExec)\r
361         {\r
362                 if(pCoexDm->bPreRfRxLpfShrink == pCoexDm->bCurRfRxLpfShrink) \r
363                         return;\r
364         }\r
365         halbtc8188c2ant_SetSwRfRxLpfCorner(pBtCoexist, pCoexDm->bCurRfRxLpfShrink);\r
366 \r
367         pCoexDm->bPreRfRxLpfShrink = pCoexDm->bCurRfRxLpfShrink;\r
368 }\r
369 \r
370 VOID\r
371 halbtc8188c2ant_SetSwPenaltyTxRateAdaptive(\r
372         IN      PBTC_COEXIST            pBtCoexist,\r
373         IN      BOOLEAN                 bLowPenaltyRa\r
374         )\r
375 {\r
376         u1Byte  tmpU1;\r
377 \r
378         tmpU1 = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x4fd);\r
379         if(bLowPenaltyRa)\r
380         {\r
381                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Tx rate adaptive, set low penalty!!\n"));\r
382                 tmpU1 &= ~BIT2;\r
383         }\r
384         else\r
385         {\r
386                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Tx rate adaptive, set normal!!\n"));\r
387                 tmpU1 |= BIT2;\r
388         }\r
389         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x4fd, tmpU1);\r
390 }\r
391 \r
392 VOID\r
393 halbtc8188c2ant_LowPenaltyRa(\r
394         IN      PBTC_COEXIST            pBtCoexist,\r
395         IN      BOOLEAN                 bForceExec,\r
396         IN      BOOLEAN                 bLowPenaltyRa\r
397         )\r
398 {\r
399         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn LowPenaltyRA = %s\n",  \r
400                 (bForceExec? "force to":""), ((bLowPenaltyRa)? "ON":"OFF")));\r
401         pCoexDm->bCurLowPenaltyRa = bLowPenaltyRa;\r
402 \r
403         if(!bForceExec)\r
404         {\r
405                 if(pCoexDm->bPreLowPenaltyRa == pCoexDm->bCurLowPenaltyRa) \r
406                         return;\r
407         }\r
408         halbtc8188c2ant_SetSwPenaltyTxRateAdaptive(pBtCoexist, pCoexDm->bCurLowPenaltyRa);\r
409 \r
410         pCoexDm->bPreLowPenaltyRa = pCoexDm->bCurLowPenaltyRa;\r
411 }\r
412 \r
413 VOID\r
414 halbtc8188c2ant_SetSwFullTimeDacSwing(\r
415         IN      PBTC_COEXIST            pBtCoexist,\r
416         IN      BOOLEAN                 bSwDacSwingOn,\r
417         IN      u4Byte                  swDacSwingLvl\r
418         )\r
419 {\r
420         u4Byte  dacSwingLvl;\r
421 \r
422         if(bSwDacSwingOn)\r
423         {               \r
424                 if((pBtCoexist->stackInfo.minBtRssi <= -5) && (swDacSwingLvl == 0x20))\r
425                 {\r
426                         dacSwingLvl = 0x18;\r
427                 }\r
428                 else\r
429                 {\r
430                         dacSwingLvl = swDacSwingLvl;\r
431                 }\r
432                 pBtCoexist->fBtcSetBbReg(pBtCoexist, 0x880, 0xfc000000, dacSwingLvl);\r
433         }\r
434         else\r
435         {\r
436                 pBtCoexist->fBtcSetBbReg(pBtCoexist, 0x880, 0xfc000000, 0x30);\r
437         }\r
438 }\r
439 \r
440 VOID\r
441 halbtc8188c2ant_DacSwing(\r
442         IN      PBTC_COEXIST            pBtCoexist,\r
443         IN      BOOLEAN                 bForceExec,\r
444         IN      BOOLEAN                 bDacSwingOn,\r
445         IN      u4Byte                  dacSwingLvl\r
446         )\r
447 {\r
448         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn DacSwing=%s, dacSwingLvl=0x%x\n",  \r
449                 (bForceExec? "force to":""), ((bDacSwingOn)? "ON":"OFF"), dacSwingLvl));\r
450         pCoexDm->bCurDacSwingOn = bDacSwingOn;\r
451         pCoexDm->curDacSwingLvl = dacSwingLvl;\r
452 \r
453         if(!bForceExec)\r
454         {\r
455                 if( (pCoexDm->bPreDacSwingOn == pCoexDm->bCurDacSwingOn) &&\r
456                         (pCoexDm->preDacSwingLvl == pCoexDm->curDacSwingLvl) )\r
457                         return;\r
458         }\r
459         delay_ms(30);\r
460         halbtc8188c2ant_SetSwFullTimeDacSwing(pBtCoexist, bDacSwingOn, dacSwingLvl);\r
461 \r
462         pCoexDm->bPreDacSwingOn = pCoexDm->bCurDacSwingOn;\r
463         pCoexDm->preDacSwingLvl = pCoexDm->curDacSwingLvl;\r
464 }\r
465 \r
466 VOID\r
467 halbtc8188c2ant_SetAdcBackOff(\r
468         IN      PBTC_COEXIST            pBtCoexist,\r
469         IN      BOOLEAN                 bAdcBackOff\r
470         )\r
471 {\r
472         if(bAdcBackOff)\r
473         {\r
474                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BB BackOff Level On!\n"));\r
475                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc04,0x3a07611);\r
476         }\r
477         else\r
478         {\r
479                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BB BackOff Level Off!\n"));           \r
480                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc04,0x3a05611);\r
481         }\r
482 }\r
483 \r
484 VOID\r
485 halbtc8188c2ant_AdcBackOff(\r
486         IN      PBTC_COEXIST            pBtCoexist,\r
487         IN      BOOLEAN                 bForceExec,\r
488         IN      BOOLEAN                 bAdcBackOff\r
489         )\r
490 {\r
491         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn AdcBackOff = %s\n",  \r
492                 (bForceExec? "force to":""), ((bAdcBackOff)? "ON":"OFF")));\r
493         pCoexDm->bCurAdcBackOff = bAdcBackOff;\r
494 \r
495         if(!bForceExec)\r
496         {\r
497                 if(pCoexDm->bPreAdcBackOff == pCoexDm->bCurAdcBackOff) \r
498                         return;\r
499         }\r
500         halbtc8188c2ant_SetAdcBackOff(pBtCoexist, pCoexDm->bCurAdcBackOff);\r
501 \r
502         pCoexDm->bPreAdcBackOff = pCoexDm->bCurAdcBackOff;\r
503 }\r
504 \r
505 VOID\r
506 halbtc8188c2ant_SetAgcTable(\r
507         IN      PBTC_COEXIST            pBtCoexist,\r
508         IN      BOOLEAN                 bAgcTableEn\r
509         )\r
510 {\r
511         u1Byte          rssiAdjustVal=0;\r
512 \r
513         if(bAgcTableEn)\r
514         {\r
515                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Agc Table On!\n"));\r
516                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x4e1c0001);\r
517                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x4d1d0001);\r
518                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x4c1e0001);\r
519                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x4b1f0001);\r
520                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x4a200001);\r
521 \r
522                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x12, 0xfffff, 0xdc000);\r
523                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x12, 0xfffff, 0x90000);\r
524                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x12, 0xfffff, 0x51000);\r
525                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x12, 0xfffff, 0x12000);\r
526                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1a, 0xfffff, 0x00255);\r
527         }\r
528         else\r
529         {\r
530                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Agc Table Off!\n"));\r
531                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x641c0001);\r
532                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x631d0001);\r
533                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x621e0001);\r
534                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x611f0001);\r
535                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x60200001);\r
536 \r
537                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x12, 0xfffff, 0x32000);\r
538                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x12, 0xfffff, 0x71000);\r
539                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x12, 0xfffff, 0xb0000);\r
540                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x12, 0xfffff, 0xfc000);\r
541                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1a, 0xfffff, 0x10255);\r
542         }\r
543 \r
544         // set rssiAdjustVal for wifi module.\r
545         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON, &rssiAdjustVal);\r
546 }\r
547 \r
548 \r
549 VOID\r
550 halbtc8188c2ant_AgcTable(\r
551         IN      PBTC_COEXIST            pBtCoexist,\r
552         IN      BOOLEAN                 bForceExec,\r
553         IN      BOOLEAN                 bAgcTableEn\r
554         )\r
555 {\r
556         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s %s Agc Table\n",  \r
557                 (bForceExec? "force to":""), ((bAgcTableEn)? "Enable":"Disable")));\r
558         pCoexDm->bCurAgcTableEn = bAgcTableEn;\r
559 \r
560         if(!bForceExec)\r
561         {\r
562                 if(pCoexDm->bPreAgcTableEn == pCoexDm->bCurAgcTableEn) \r
563                         return;\r
564         }\r
565         halbtc8188c2ant_SetAgcTable(pBtCoexist, bAgcTableEn);\r
566 \r
567         pCoexDm->bPreAgcTableEn = pCoexDm->bCurAgcTableEn;\r
568 }\r
569 \r
570 VOID\r
571 halbtc8188c2ant_SetCoexTable(\r
572         IN      PBTC_COEXIST    pBtCoexist,\r
573         IN      u4Byte          val0x6c4,\r
574         IN      u4Byte          val0x6c8,\r
575         IN      u4Byte          val0x6cc\r
576         )\r
577 {\r
578         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], set coex table, set 0x6c4=0x%x\n", val0x6c4));\r
579         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c4, val0x6c4);\r
580 \r
581         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], set coex table, set 0x6c8=0x%x\n", val0x6c8));\r
582         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c8, val0x6c8);\r
583 \r
584         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], set coex table, set 0x6cc=0x%x\n", val0x6cc));\r
585         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6cc, val0x6cc);\r
586 }\r
587 \r
588 VOID\r
589 halbtc8188c2ant_CoexTable(\r
590         IN      PBTC_COEXIST            pBtCoexist,\r
591         IN      BOOLEAN                 bForceExec,\r
592         IN      u4Byte                  val0x6c4,\r
593         IN      u4Byte                  val0x6c8,\r
594         IN      u4Byte                  val0x6cc\r
595         )\r
596 {\r
597         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s write Coex Table 0x6c4=0x%x, 0x6c8=0x%x, 0x6cc=0x%x\n", \r
598                 (bForceExec? "force to":""), val0x6c4, val0x6c8, val0x6cc));\r
599         pCoexDm->curVal0x6c4 = val0x6c4;\r
600         pCoexDm->curVal0x6c8 = val0x6c8;\r
601         pCoexDm->curVal0x6cc = val0x6cc;\r
602 \r
603         if(!bForceExec)\r
604         {       \r
605                 if( (pCoexDm->preVal0x6c4 == pCoexDm->curVal0x6c4) &&\r
606                         (pCoexDm->preVal0x6c8 == pCoexDm->curVal0x6c8) &&\r
607                         (pCoexDm->preVal0x6cc == pCoexDm->curVal0x6cc) )\r
608                         return;\r
609         }\r
610         halbtc8188c2ant_SetCoexTable(pBtCoexist, val0x6c4, val0x6c8, val0x6cc);\r
611 \r
612         pCoexDm->preVal0x6c4 = pCoexDm->curVal0x6c4;\r
613         pCoexDm->preVal0x6c8 = pCoexDm->curVal0x6c8;\r
614         pCoexDm->preVal0x6cc = pCoexDm->curVal0x6cc;\r
615 }\r
616 \r
617 VOID\r
618 halbtc8188c2ant_CoexAllOff(\r
619         IN      PBTC_COEXIST            pBtCoexist\r
620         )\r
621 {\r
622         // fw mechanism\r
623         halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);\r
624         halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0, FALSE);\r
625 \r
626         // sw mechanism\r
627         halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
628         halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
629         halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);\r
630 }\r
631 VOID\r
632 halbtc8188c2ant_InitCoexDm(\r
633         IN      PBTC_COEXIST            pBtCoexist\r
634         )\r
635 {\r
636 }\r
637 \r
638 \r
639 VOID\r
640 halbtc8188c2ant_MonitorBtState(\r
641         IN      PBTC_COEXIST                    pBtCoexist\r
642         )\r
643 {\r
644         BOOLEAN                 stateChange=FALSE;\r
645         u4Byte                  BT_Polling, Ratio_Act, Ratio_STA;\r
646         u4Byte                  BT_Active, BT_State;\r
647         u4Byte                  regBTActive=0, regBTState=0, regBTPolling=0;\r
648         u4Byte                  btBusyThresh=0;\r
649         u4Byte                  fwVer=0;\r
650         static BOOLEAN  bBtBusyTraffic=FALSE;\r
651         BOOLEAN                 bRejApAggPkt=FALSE;\r
652 \r
653         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);\r
654         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], FirmwareVersion = 0x%x(%d)\n", fwVer, fwVer));\r
655         if(fwVer < 62)\r
656         {\r
657                 regBTActive = 0x488;\r
658                 regBTState = 0x48c;\r
659                 regBTPolling = 0x490;\r
660         }\r
661         else\r
662         {\r
663                 regBTActive = 0x444;\r
664                 regBTState = 0x448;\r
665                 if(fwVer >= 74)\r
666                         regBTPolling = 0x44c;\r
667                 else\r
668                         regBTPolling = 0x700;\r
669         }\r
670         btBusyThresh = 60;\r
671         \r
672         BT_Active = pBtCoexist->fBtcRead4Byte(pBtCoexist, regBTActive);\r
673         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT_Active(0x%x)=0x%x\n", regBTActive, BT_Active));\r
674         BT_Active = BT_Active & 0x00ffffff;\r
675 \r
676         BT_State = pBtCoexist->fBtcRead4Byte(pBtCoexist, regBTState);\r
677         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT_State(0x%x)=0x%x\n", regBTState, BT_State));\r
678         BT_State = BT_State & 0x00ffffff;\r
679 \r
680         BT_Polling = pBtCoexist->fBtcRead4Byte(pBtCoexist, regBTPolling);\r
681         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT_Polling(0x%x)=0x%x\n", regBTPolling, BT_Polling));\r
682 \r
683         if(BT_Active==0xffffffff && BT_State==0xffffffff && BT_Polling==0xffffffff )\r
684                 return;\r
685 \r
686         // 2011/05/04 MH For Slim combo test meet a problem. Surprise remove and WLAN is running\r
687         // DHCP process. At the same time, the register read value might be zero. And cause BSOD 0x7f\r
688         // EXCEPTION_DIVIDED_BY_ZERO. In This case, the stack content may always be wrong due to \r
689         // HW divide trap.\r
690         if (BT_Polling==0)\r
691                 return;\r
692         \r
693         Ratio_Act = BT_Active*1000/BT_Polling;\r
694         Ratio_STA = BT_State*1000/BT_Polling;\r
695                 \r
696         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Ratio_Act=%d\n", Ratio_Act));\r
697         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Ratio_STA=%d\n", Ratio_STA));\r
698 \r
699         if(BTC_CHIP_CSR_BC8 == pBtCoexist->boardInfo.btChipType)\r
700         {\r
701                 if(Ratio_STA < 60)      // BT PAN idle\r
702                 {\r
703                 }\r
704                 else\r
705                 {\r
706                         // Check if BT PAN (under BT 2.1) is uplink or downlink\r
707                         if((Ratio_Act/Ratio_STA) < 2)\r
708                         {       // BT PAN Uplink\r
709                                 pCoexSta->bBtUplink = TRUE;\r
710                         }\r
711                         else\r
712                         {       // BT PAN downlink\r
713                                 pCoexSta->bBtUplink = FALSE;\r
714                         }\r
715                 }\r
716         }       \r
717         \r
718         // Check BT is idle or not\r
719         if(!pBtCoexist->stackInfo.bBtLinkExist)\r
720         {\r
721                 pCoexSta->bBtBusy = FALSE;\r
722         }\r
723         else\r
724         {\r
725                 if(BTC_CHIP_CSR_BC4 == pBtCoexist->boardInfo.btChipType)\r
726                 {\r
727                         if(Ratio_Act<20)\r
728                         {\r
729                                 pCoexSta->bBtBusy = FALSE;\r
730                         }\r
731                         else\r
732                         {\r
733                                 pCoexSta->bBtBusy = TRUE;\r
734                         }\r
735                 }\r
736                 else if(BTC_CHIP_CSR_BC8 == pBtCoexist->boardInfo.btChipType)\r
737                 {\r
738                         if(Ratio_STA < btBusyThresh)\r
739                         {\r
740                                 pCoexSta->bBtBusy = FALSE;\r
741                         }\r
742                         else\r
743                         {\r
744                                 pCoexSta->bBtBusy = TRUE;\r
745                         }\r
746 \r
747                         if( (Ratio_STA < btBusyThresh) ||\r
748                                 (Ratio_Act<180 && Ratio_STA<130) )\r
749                         {\r
750                                 pCoexSta->bA2dpBusy = FALSE;\r
751                         }\r
752                         else\r
753                         {\r
754                                 pCoexSta->bA2dpBusy = TRUE;\r
755                         }\r
756                 }\r
757         }\r
758 \r
759         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &pCoexSta->bBtBusy);\r
760         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_LIMITED_DIG, &pCoexSta->bBtBusy);\r
761         \r
762         if(bBtBusyTraffic != pCoexSta->bBtBusy)\r
763         {       // BT idle or BT non-idle\r
764                 bBtBusyTraffic = pCoexSta->bBtBusy;\r
765                 stateChange = TRUE;\r
766         }\r
767 \r
768         if(stateChange)\r
769         {\r
770                 if(!pCoexSta->bBtBusy)\r
771                 {\r
772                         halbtc8188c2ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, FALSE);\r
773                         halbtc8188c2ant_RfShrink(pBtCoexist, NORMAL_EXEC, FALSE);\r
774                         halbtc8188c2ant_CoexAllOff(pBtCoexist);\r
775                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0x0);\r
776                 }\r
777                 else\r
778                 {\r
779                         halbtc8188c2ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, TRUE);\r
780                         halbtc8188c2ant_RfShrink(pBtCoexist, NORMAL_EXEC, TRUE);\r
781                 }\r
782         }\r
783 \r
784         if(stateChange)\r
785         {\r
786                 bRejApAggPkt = pCoexSta->bBtBusy;\r
787                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, &bRejApAggPkt);\r
788                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);\r
789         }\r
790 }\r
791 \r
792 VOID\r
793 halbtc8188c2ant_ActionA2dpBc4(\r
794         IN      PBTC_COEXIST            pBtCoexist\r
795         )\r
796 {\r
797         u1Byte                  wifiRssiState;\r
798         u4Byte                  wifiBw, wifiTrafficDir;\r
799 \r
800         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0x0);\r
801         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
802         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifiTrafficDir);\r
803         \r
804         if(pCoexSta->bBtBusy)\r
805         {\r
806                 if(BTC_WIFI_BW_HT40 == wifiBw)\r
807                 {\r
808                         // fw mechanism first\r
809                         if(BTC_WIFI_TRAFFIC_TX == wifiTrafficDir)\r
810                         {\r
811                                 halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, TRUE, 0xc, 0x18);\r
812                                 halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x20, FALSE);\r
813                         }\r
814                         else if(BTC_WIFI_TRAFFIC_RX == wifiTrafficDir)\r
815                         {\r
816                                 halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);\r
817                                 halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0, FALSE);\r
818                         }\r
819 \r
820                         // sw mechanism \r
821                         halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
822                         halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
823                         halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0x20);\r
824                 }\r
825                 else\r
826                 {\r
827                         wifiRssiState = halbtc8188c2ant_WifiRssiState(pBtCoexist, 0, 2, 47, 0);\r
828 \r
829                         if(BTC_WIFI_TRAFFIC_TX == wifiTrafficDir)\r
830                         {\r
831                                 halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, TRUE, 0xc, 0x18);\r
832                                 halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x20, FALSE);\r
833                         }\r
834                         else if(BTC_WIFI_TRAFFIC_RX == wifiTrafficDir)\r
835                         {\r
836                                 halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);\r
837                                 halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0, FALSE);\r
838                         }\r
839 \r
840                         // sw mechanism \r
841                         if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
842                                 (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
843                         {\r
844                                 halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, TRUE);\r
845                                 halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
846                                 halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0x20);\r
847                         }\r
848                         else\r
849                         {\r
850                                 halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
851                                 halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
852                                 halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0x20);\r
853                         }\r
854                 }\r
855         }\r
856         else\r
857         {\r
858                 halbtc8188c2ant_CoexAllOff(pBtCoexist);\r
859         }\r
860 }\r
861 \r
862 VOID\r
863 halbtc8188c2ant_ActionA2dpBc8(\r
864         IN      PBTC_COEXIST            pBtCoexist\r
865         )\r
866 {\r
867         u1Byte                  wifiRssiState;\r
868         u4Byte                  wifiBw, wifiTrafficDir;\r
869         BOOLEAN                 bWifiBusy=FALSE;\r
870 \r
871         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
872         if(pCoexSta->bA2dpBusy && bWifiBusy)\r
873         {\r
874                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
875                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifiTrafficDir);\r
876                 wifiRssiState = halbtc8188c2ant_WifiRssiState(pBtCoexist, 0, 2, 47, 0);\r
877 \r
878                 // fw mechanism first\r
879                 if(BTC_WIFI_TRAFFIC_TX == wifiTrafficDir)\r
880                 {\r
881                         halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, TRUE, 0xc, 0x18);\r
882                         halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x20, FALSE);\r
883                 }\r
884                 else if(BTC_WIFI_TRAFFIC_RX == wifiTrafficDir)\r
885                 {\r
886                         halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, TRUE, 0x10, 0x18);\r
887                         halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x20, FALSE);\r
888                 }\r
889 \r
890                 // sw mechanism \r
891                 if(BTC_WIFI_BW_HT40 == wifiBw)\r
892                 {\r
893                         halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
894                         halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
895                         halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);\r
896                 }\r
897                 else\r
898                 {\r
899                         if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
900                                 (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
901                         {\r
902                                 halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, TRUE);\r
903                                 halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
904                                 halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);\r
905                         }\r
906                         else\r
907                         {\r
908                                 halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
909                                 halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
910                                 halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);\r
911                         }\r
912                 }\r
913         }\r
914         else if(pCoexSta->bA2dpBusy)\r
915         {\r
916                 // fw mechanism first\r
917                 halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);\r
918                 halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, TRUE, TRUE, 0x18, FALSE);\r
919 \r
920                 // sw mechanism \r
921                 halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
922                 halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
923                 halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);\r
924         }\r
925         else\r
926         {\r
927                 halbtc8188c2ant_CoexAllOff(pBtCoexist);\r
928         }\r
929 }\r
930 \r
931 VOID\r
932 halbtc8188c2ant_ActionA2dp(\r
933         IN      PBTC_COEXIST            pBtCoexist\r
934         )\r
935 {\r
936         if(BTC_CHIP_CSR_BC4 == pBtCoexist->boardInfo.btChipType)\r
937         {\r
938                 halbtc8188c2ant_ActionA2dpBc4(pBtCoexist);\r
939         }\r
940         else if(BTC_CHIP_CSR_BC8 == pBtCoexist->boardInfo.btChipType)\r
941         {\r
942                 halbtc8188c2ant_ActionA2dpBc8(pBtCoexist);\r
943         }\r
944 }\r
945 \r
946 VOID\r
947 halbtc8188c2ant_ActionPanBc4(\r
948         IN      PBTC_COEXIST            pBtCoexist\r
949         )\r
950 {\r
951         BOOLEAN         bBtHsOn=FALSE, bWifiBusy=FALSE;\r
952 \r
953         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
954         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
955         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0x0);\r
956         if(bBtHsOn)\r
957         {\r
958                 halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);\r
959                 halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x0, FALSE);\r
960         }\r
961         else\r
962         {\r
963                 if(pCoexSta->bBtBusy && bWifiBusy)\r
964                 {\r
965                         halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, TRUE, 0x20, 0x10);\r
966                         halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x20, FALSE);\r
967                 }\r
968                 else\r
969                 {\r
970                         halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);\r
971                         halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x0, FALSE);\r
972                 }\r
973         }\r
974         // sw mechanism\r
975         halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
976         halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
977         halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);\r
978 }\r
979 \r
980 VOID\r
981 halbtc8188c2ant_ActionPanBc8(\r
982         IN      PBTC_COEXIST            pBtCoexist\r
983         )\r
984 {\r
985         BOOLEAN         bBtHsOn=FALSE, bWifiBusy=FALSE;\r
986         u1Byte          wifiRssiState;\r
987         u4Byte          wifiBw, wifiTrafficDir;\r
988         s4Byte          wifiRssi;\r
989 \r
990         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
991         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
992         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
993         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifiTrafficDir);\r
994         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);\r
995         \r
996         if(bBtHsOn)\r
997         {\r
998                 halbtc8188c2ant_CoexAllOff(pBtCoexist);\r
999         }\r
1000         else\r
1001         {\r
1002                 wifiRssiState = halbtc8188c2ant_WifiRssiState(pBtCoexist, 0, 3, 25, 50);\r
1003 \r
1004                 if(pCoexSta->bBtBusy && bWifiBusy)\r
1005                 {\r
1006                         if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
1007                                 (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
1008                         {\r
1009                                 // fw mechanism first\r
1010                                 if(pCoexSta->bBtUplink)\r
1011                                 {\r
1012                                         halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, TRUE, 0x20, 0x20);\r
1013                                         halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x20, FALSE);\r
1014                                 }\r
1015                                 else\r
1016                                 {\r
1017                                         halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);\r
1018                                         halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0, FALSE);\r
1019                                 }\r
1020                                 // sw mechanism \r
1021                                 if(BTC_WIFI_BW_HT40 == wifiBw)\r
1022                                 {\r
1023                                         halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
1024                                 }\r
1025                                 else\r
1026                                 {\r
1027                                         halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, TRUE);\r
1028                                 }\r
1029                                 halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
1030                                 if(pCoexSta->bBtUplink)\r
1031                                 {\r
1032                                         halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);\r
1033                                 }\r
1034                                 else\r
1035                                 {\r
1036                                         halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0x20);\r
1037                                 }\r
1038                         }\r
1039                         else if( (wifiRssiState == BTC_RSSI_STATE_MEDIUM) ||\r
1040                                 (wifiRssiState == BTC_RSSI_STATE_STAY_MEDIUM) )\r
1041                         {\r
1042                                 // fw mechanism first\r
1043                                 halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, TRUE, 0x20, 0x20);\r
1044 \r
1045                                 if(BTC_WIFI_TRAFFIC_TX == wifiTrafficDir)\r
1046                                 {\r
1047                                         halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x20, FALSE);\r
1048                                 }\r
1049                                 else if(BTC_WIFI_TRAFFIC_RX == wifiTrafficDir)\r
1050                                 {\r
1051                                         if(BTC_WIFI_BW_HT40 == wifiBw)\r
1052                                                 halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x20, FALSE);//BT_FW_NAV_ON);\r
1053                                         else\r
1054                                                 halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x20, FALSE);\r
1055                                 }\r
1056                                 // sw mechanism \r
1057                                 if(BTC_WIFI_BW_HT40 == wifiBw)\r
1058                                 {\r
1059                                         halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
1060                                 }\r
1061                                 else\r
1062                                 {\r
1063                                         halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, TRUE);\r
1064                                 }\r
1065                                 halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
1066                                 halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);\r
1067                         }\r
1068                         else\r
1069                         {\r
1070                                 // fw mechanism first\r
1071                                 halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, TRUE, 0x20, 0x20);\r
1072                                 \r
1073                                 if(BTC_WIFI_TRAFFIC_TX == wifiTrafficDir)\r
1074                                 {\r
1075                                         halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x20, FALSE);\r
1076                                 }\r
1077                                 else if(BTC_WIFI_TRAFFIC_RX == wifiTrafficDir)\r
1078                                 {\r
1079                                         if(pCoexSta->bBtUplink)\r
1080                                         {\r
1081                                                 if(BTC_WIFI_BW_HT40 == wifiBw)\r
1082                                                 {\r
1083                                                         halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x20, FALSE);//BT_FW_NAV_ON);\r
1084                                                 }\r
1085                                                 else\r
1086                                                 {\r
1087                                                         halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x20, FALSE);\r
1088                                                 }                                               \r
1089                                         }\r
1090                                         else\r
1091                                         {\r
1092                                                 halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x20, FALSE);\r
1093                                         }\r
1094                                 }\r
1095                                 // sw mechanism \r
1096                                 halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
1097                                 halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
1098                                 halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);\r
1099                         }\r
1100                 }\r
1101                 else if(pCoexSta->bBtBusy && !bWifiBusy && (wifiRssi < 30))\r
1102                 {\r
1103                         // fw mechanism first\r
1104                         halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, TRUE, 0x0a, 0x20);\r
1105                         halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x20, FALSE);\r
1106                         // sw mechanism \r
1107                         halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
1108                         halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
1109                         halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);\r
1110                 }\r
1111                 else\r
1112                 {\r
1113                         halbtc8188c2ant_CoexAllOff(pBtCoexist);\r
1114                 }\r
1115         }\r
1116 }\r
1117 \r
1118 VOID\r
1119 halbtc8188c2ant_ActionPan(\r
1120         IN      PBTC_COEXIST            pBtCoexist\r
1121         )\r
1122 {\r
1123         if(BTC_CHIP_CSR_BC4 == pBtCoexist->boardInfo.btChipType)\r
1124         {\r
1125                 halbtc8188c2ant_ActionPanBc4(pBtCoexist);\r
1126         }\r
1127         else if(BTC_CHIP_CSR_BC8 == pBtCoexist->boardInfo.btChipType)\r
1128         {\r
1129                 halbtc8188c2ant_ActionPanBc8(pBtCoexist);\r
1130         }\r
1131 }\r
1132 \r
1133 VOID\r
1134 halbtc8188c2ant_ActionHid(\r
1135         IN      PBTC_COEXIST            pBtCoexist\r
1136         )\r
1137 {\r
1138         u4Byte          wifiBw, wifiTrafficDir;\r
1139         BOOLEAN         bWifiBusy=FALSE;\r
1140 \r
1141         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
1142         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
1143         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifiTrafficDir);\r
1144         if(BTC_WIFI_BW_LEGACY == wifiBw)\r
1145         {\r
1146                 halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);\r
1147                 halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x0, FALSE);\r
1148 \r
1149                 halbtc8188c2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0x000000f0, 0x40000010);\r
1150                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0xa0);\r
1151         }\r
1152         else if(!bWifiBusy)\r
1153         {\r
1154                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0x0);\r
1155                 halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);\r
1156                 halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x0, FALSE);\r
1157         }\r
1158         else if(BTC_WIFI_TRAFFIC_TX == wifiTrafficDir)\r
1159         {\r
1160                 halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);\r
1161                 halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x0, FALSE);\r
1162 \r
1163                 halbtc8188c2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0x000000f0, 0x40000010);\r
1164                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0xa0);\r
1165         }\r
1166         else if(BTC_WIFI_TRAFFIC_RX == wifiTrafficDir)\r
1167         {\r
1168                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0x0);\r
1169                 halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);\r
1170                 halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x0, FALSE);\r
1171         }\r
1172         // sw mechanism\r
1173         halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
1174         halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
1175         halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);\r
1176 }\r
1177 \r
1178 \r
1179 VOID\r
1180 halbtc8188c2ant_ActionSco(\r
1181         IN      PBTC_COEXIST            pBtCoexist\r
1182         )\r
1183 {\r
1184         u1Byte  wifiRssiState;\r
1185         u4Byte  wifiBw;\r
1186 \r
1187         if(BTC_CHIP_CSR_BC4 == pBtCoexist->boardInfo.btChipType)\r
1188         {\r
1189                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0x0);\r
1190                 \r
1191                 // fw mechanism\r
1192                 halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);\r
1193                 halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x0, FALSE);\r
1194 \r
1195                 // sw mechanism\r
1196                 halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
1197                 halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
1198                 halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);\r
1199         }\r
1200         else if(BTC_CHIP_CSR_BC8 == pBtCoexist->boardInfo.btChipType)\r
1201         {\r
1202                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
1203                 if(BTC_WIFI_BW_HT40 == wifiBw)\r
1204                 {\r
1205                         // fw mechanism first\r
1206                         halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);\r
1207                         halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0, FALSE);\r
1208 \r
1209                         // sw mechanism \r
1210                         halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
1211                         halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
1212                         halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);\r
1213                 }\r
1214                 else\r
1215                 {\r
1216                         wifiRssiState = halbtc8188c2ant_WifiRssiState(pBtCoexist, 0, 2, 47, 0);\r
1217                         // fw mechanism first\r
1218                         halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);\r
1219                         halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0, FALSE);\r
1220 \r
1221                         // sw mechanism \r
1222                         if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
1223                                 (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
1224                         {\r
1225                                 halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, TRUE);\r
1226                                 halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
1227                                 halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);\r
1228                         }\r
1229                         else\r
1230                         {                       \r
1231                                 halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
1232                                 halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
1233                                 halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30); \r
1234                         }\r
1235                 }\r
1236         }\r
1237 }\r
1238 \r
1239 VOID\r
1240 halbtc8188c2ant_ActionHidA2dpBc4(\r
1241         IN      PBTC_COEXIST            pBtCoexist\r
1242         )\r
1243 {\r
1244         u1Byte          wifiRssiState;\r
1245         u4Byte          wifiBw, wifiTrafficDir;\r
1246 \r
1247         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
1248         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifiTrafficDir);\r
1249 \r
1250         if(pCoexSta->bBtBusy)\r
1251         {\r
1252                 if(BTC_WIFI_BW_HT40 == wifiBw)\r
1253                 {\r
1254                         // fw mechanism first\r
1255                         if(BTC_WIFI_TRAFFIC_TX == wifiTrafficDir)\r
1256                         {\r
1257                                 halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, TRUE, 0x7, 0x20);\r
1258                                 halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x20, FALSE);\r
1259                         }\r
1260                         else if(BTC_WIFI_TRAFFIC_RX == wifiTrafficDir)\r
1261                         {\r
1262                                 halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);\r
1263                                 halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0, FALSE);\r
1264                         }\r
1265 \r
1266                         // sw mechanism \r
1267                         halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
1268                         halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
1269                         halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0x18);\r
1270                 }\r
1271                 else\r
1272                 {\r
1273                         wifiRssiState = halbtc8188c2ant_WifiRssiState(pBtCoexist, 0, 2, 47, 0);\r
1274                         // fw mechanism first\r
1275                         if(BTC_WIFI_TRAFFIC_TX == wifiTrafficDir)\r
1276                         {\r
1277                                 halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, TRUE, 0x7, 0x20);\r
1278                                 halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x20, FALSE);\r
1279                         }\r
1280                         else if(BTC_WIFI_TRAFFIC_RX == wifiTrafficDir)\r
1281                         {\r
1282                                 halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);\r
1283                                 halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0, FALSE);\r
1284                         }\r
1285 \r
1286                         // sw mechanism \r
1287                         if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
1288                                 (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
1289                         {\r
1290                                 halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, TRUE);\r
1291                                 halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
1292                                 halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0x18);\r
1293                         }\r
1294                         else\r
1295                         {\r
1296                                 halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
1297                                 halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
1298                                 halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0x18);\r
1299                         }\r
1300                 }\r
1301         }\r
1302         else\r
1303         {\r
1304                 halbtc8188c2ant_CoexAllOff(pBtCoexist);\r
1305         }\r
1306 }\r
1307 VOID\r
1308 halbtc8188c2ant_ActionHidA2dpBc8(\r
1309         IN      PBTC_COEXIST            pBtCoexist\r
1310         )\r
1311 {\r
1312         u1Byte          wifiRssiState;\r
1313         u4Byte          wifiBw;\r
1314         \r
1315         if(pCoexSta->bBtBusy)\r
1316         {\r
1317                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
1318                 if(BTC_WIFI_BW_HT40 == wifiBw)\r
1319                 {\r
1320                         // fw mechanism first\r
1321                         halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);\r
1322                         halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0, FALSE);\r
1323 \r
1324                         // sw mechanism \r
1325                         halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
1326                         halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
1327                         halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0x18);\r
1328                 }\r
1329                 else\r
1330                 {\r
1331                         wifiRssiState = halbtc8188c2ant_WifiRssiState(pBtCoexist, 0, 2, 47, 0);\r
1332                         // fw mechanism\r
1333                         halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);\r
1334                         halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0, FALSE);\r
1335 \r
1336                         // sw mechanism \r
1337                         if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
1338                                 (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
1339                         {\r
1340                                 halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, TRUE);\r
1341                                 halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
1342                                 halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0x18);\r
1343                         }\r
1344                         else\r
1345                         {\r
1346                                 halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
1347                                 halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
1348                                 halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0x18);\r
1349                         }\r
1350                 }\r
1351         }\r
1352         else\r
1353         {\r
1354                 halbtc8188c2ant_CoexAllOff(pBtCoexist);\r
1355         }\r
1356 }\r
1357 \r
1358 VOID\r
1359 halbtc8188c2ant_ActionHidA2dp(\r
1360         IN      PBTC_COEXIST            pBtCoexist\r
1361         )\r
1362 {\r
1363         if(BTC_CHIP_CSR_BC4 == pBtCoexist->boardInfo.btChipType)\r
1364         {\r
1365                 halbtc8188c2ant_ActionHidA2dpBc4(pBtCoexist);\r
1366         }\r
1367         else if(BTC_CHIP_CSR_BC8 == pBtCoexist->boardInfo.btChipType)\r
1368         {\r
1369                 halbtc8188c2ant_ActionHidA2dpBc8(pBtCoexist);\r
1370         }\r
1371 }\r
1372 \r
1373 VOID\r
1374 halbtc8188c2ant_ActionHidPanBc4(\r
1375         IN      PBTC_COEXIST            pBtCoexist\r
1376         )\r
1377 {\r
1378         BOOLEAN         bBtHsOn=FALSE, bWifiBusy=FALSE;\r
1379         u4Byte          wifiBw, wifiTrafficDir;\r
1380 \r
1381         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
1382         \r
1383         if(bBtHsOn)\r
1384         {       \r
1385                 halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);\r
1386                 halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x0, FALSE);\r
1387 \r
1388                 halbtc8188c2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0x000000f0, 0x40000010);\r
1389                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0xa0);\r
1390         }\r
1391         else\r
1392         {\r
1393                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
1394                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
1395                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifiTrafficDir);\r
1396                 if(BTC_WIFI_BW_LEGACY == wifiBw)\r
1397                 {\r
1398                         halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);\r
1399                         halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x0, FALSE);\r
1400 \r
1401                         halbtc8188c2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0x000000f0, 0x40000010);\r
1402                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0xa0);\r
1403                 }\r
1404                 else if(BTC_WIFI_TRAFFIC_TX == wifiTrafficDir)\r
1405                 {\r
1406                         halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);\r
1407                         halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x0, FALSE);\r
1408                         \r
1409                         halbtc8188c2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0x000000f0, 0x40000010);\r
1410                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0xa0);\r
1411                 }\r
1412                 else if(BTC_WIFI_TRAFFIC_RX == wifiTrafficDir)\r
1413                 {\r
1414                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0x0);\r
1415                         halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, TRUE, 0x20, 0x10);                                     \r
1416                         halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x20, FALSE);\r
1417                 }\r
1418                 else if(!bWifiBusy)\r
1419                 {\r
1420                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0x0);\r
1421                         halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);\r
1422                         halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x0, FALSE);\r
1423                 }                       \r
1424         }\r
1425         halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
1426         halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
1427         halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);\r
1428 }\r
1429 VOID\r
1430 halbtc8188c2ant_ActionHidPanBc8(        \r
1431         IN      PBTC_COEXIST            pBtCoexist\r
1432         )\r
1433 {\r
1434         BOOLEAN         bBtHsOn=FALSE, bWifiBusy=FALSE;\r
1435         u1Byte          wifiRssiState;\r
1436         u4Byte          wifiBw, wifiTrafficDir;\r
1437 \r
1438         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
1439 \r
1440         if(!bBtHsOn)\r
1441         {\r
1442                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
1443                 wifiRssiState = halbtc8188c2ant_WifiRssiState(pBtCoexist, 0, 2, 25, 0);\r
1444                 if((pCoexSta->bBtBusy && bWifiBusy))\r
1445                 {\r
1446                         // fw mechanism first\r
1447                         if(pCoexSta->bBtUplink)\r
1448                         {\r
1449                                 halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, TRUE, 0x15, 0x20);\r
1450                         }\r
1451                         else\r
1452                         {\r
1453                                 halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, TRUE, 0x10, 0x20);\r
1454                         }\r
1455                         halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x20, FALSE);\r
1456 \r
1457                         // sw mechanism \r
1458                         if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
1459                                 (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
1460                         {\r
1461                                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
1462                                 if(BTC_WIFI_BW_HT40 == wifiBw)\r
1463                                 {\r
1464                                         halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
1465                                         halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
1466                                         halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);\r
1467                                 }\r
1468                                 else\r
1469                                 {\r
1470                                         halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, TRUE);\r
1471                                         halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
1472                                         halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);\r
1473                                 }\r
1474                         }\r
1475                         else\r
1476                         {\r
1477                                 halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
1478                                 halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
1479                                 halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);\r
1480                         }\r
1481                 }\r
1482                 else\r
1483                 {\r
1484                         halbtc8188c2ant_CoexAllOff(pBtCoexist);\r
1485                 }\r
1486         }\r
1487         else\r
1488         {\r
1489                 if(BTC_INTF_USB == pBtCoexist->chipInterface)\r
1490                 {       \r
1491                         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, &wifiTrafficDir);\r
1492                         if(BTC_WIFI_TRAFFIC_TX == wifiTrafficDir)\r
1493                         {\r
1494                                 halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);\r
1495                                 halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x0, FALSE);\r
1496 \r
1497                                 halbtc8188c2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0x000000f0, 0x40000010);\r
1498                                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0xa0);\r
1499                                 halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0x18);\r
1500                         }\r
1501                         else if(BTC_WIFI_TRAFFIC_RX == wifiTrafficDir)\r
1502                         {\r
1503                                 halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0x18);\r
1504                         }\r
1505                 }\r
1506                 else \r
1507                 {\r
1508                         if(pCoexSta->bBtBusy)\r
1509                         {\r
1510                                 // fw mechanism\r
1511                                 halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);\r
1512                                 halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0, FALSE);\r
1513 \r
1514                                 // sw mechanism\r
1515                                 halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
1516                                 halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
1517                                 halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0x20);\r
1518                         }\r
1519                         else\r
1520                         {\r
1521                                 halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);\r
1522                         }\r
1523                 }\r
1524         }\r
1525 }\r
1526 \r
1527 VOID\r
1528 halbtc8188c2ant_ActionHidPan(\r
1529         IN      PBTC_COEXIST            pBtCoexist\r
1530         )\r
1531 {               \r
1532         if(BTC_CHIP_CSR_BC4 == pBtCoexist->boardInfo.btChipType)\r
1533         {\r
1534                 halbtc8188c2ant_ActionHidPanBc4(pBtCoexist);\r
1535         }\r
1536         else if(BTC_CHIP_CSR_BC8 == pBtCoexist->boardInfo.btChipType)\r
1537         {\r
1538                 halbtc8188c2ant_ActionHidPanBc8(pBtCoexist);\r
1539         }\r
1540 }\r
1541 \r
1542 VOID\r
1543 halbtc8188c2ant_ActionPanA2dpBc4(\r
1544         IN      PBTC_COEXIST            pBtCoexist\r
1545         )\r
1546 {\r
1547         BOOLEAN         bBtHsOn=FALSE, bWifiBusy=FALSE;\r
1548         u1Byte          wifiRssiState;\r
1549 \r
1550         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
1551 \r
1552         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0x0);\r
1553         if(bBtHsOn)\r
1554         {\r
1555                 if(pCoexSta->bBtBusy)\r
1556                 {\r
1557                         // fw mechanism\r
1558                         halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);\r
1559                         halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0, FALSE);\r
1560 \r
1561                         // sw mechanism\r
1562                         halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
1563                         halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
1564                         halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0x20);\r
1565                 }\r
1566                 else\r
1567                 {\r
1568                         halbtc8188c2ant_CoexAllOff(pBtCoexist);\r
1569                 }\r
1570         }\r
1571         else\r
1572         {\r
1573                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
1574                 if(pCoexSta->bBtBusy && bWifiBusy)\r
1575                 {\r
1576                         halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, TRUE, 0x20, 0x10);\r
1577                         halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x20, FALSE);\r
1578                 }\r
1579                 else\r
1580                 {\r
1581                         halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);\r
1582                         halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x0, FALSE);\r
1583                 }                       \r
1584                 // sw mechanism\r
1585                 halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
1586                 halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
1587                 halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);\r
1588         }\r
1589 }\r
1590 VOID\r
1591 halbtc8188c2ant_ActionPanA2dpBc8(       \r
1592         IN      PBTC_COEXIST            pBtCoexist\r
1593         )\r
1594 {\r
1595         BOOLEAN         bBtHsOn=FALSE, bWifiBusy=FALSE;\r
1596         u1Byte          wifiRssiState;\r
1597         u4Byte          wifiBw;\r
1598 \r
1599         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
1600 \r
1601         if(!bBtHsOn)\r
1602         {\r
1603                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
1604                 wifiRssiState = halbtc8188c2ant_WifiRssiState(pBtCoexist, 0, 2, 25, 0);\r
1605                 if((pCoexSta->bBtBusy && bWifiBusy))\r
1606                 {\r
1607                         // fw mechanism first\r
1608                         if(pCoexSta->bBtUplink)\r
1609                         {\r
1610                                 halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, TRUE, 0x15, 0x20);\r
1611                         }\r
1612                         else\r
1613                         {\r
1614                                 halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, TRUE, 0x10, 0x20);\r
1615                         }\r
1616                         halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, TRUE, FALSE, 0x20, FALSE);\r
1617 \r
1618                         // sw mechanism \r
1619                         if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
1620                                 (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
1621                         {\r
1622                                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
1623                                 if(BTC_WIFI_BW_HT40 == wifiBw)\r
1624                                 {\r
1625                                         halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
1626                                         halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
1627                                         halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);\r
1628                                 }\r
1629                                 else    \r
1630                                 {\r
1631                                         halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, TRUE);\r
1632                                         halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
1633                                         halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);\r
1634                                 }\r
1635                         }\r
1636                         else\r
1637                         {\r
1638                                 halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
1639                                 halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
1640                                 halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);\r
1641                         }\r
1642                 }\r
1643                 else\r
1644                 {\r
1645                         halbtc8188c2ant_CoexAllOff(pBtCoexist);\r
1646                 }\r
1647         }\r
1648         else\r
1649         {\r
1650                 if(pCoexSta->bBtBusy)\r
1651                 {\r
1652                         // fw mechanism\r
1653                         halbtc8188c2ant_Balance(pBtCoexist, NORMAL_EXEC, FALSE, 0, 0);\r
1654                         halbtc8188c2ant_DiminishWifi(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0, FALSE);\r
1655 \r
1656                         // sw mechanism                 \r
1657                         halbtc8188c2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
1658                         halbtc8188c2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
1659                         halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, TRUE, 0x20);\r
1660                 }\r
1661                 else\r
1662                 {\r
1663                         halbtc8188c2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0x30);\r
1664                 }\r
1665         }\r
1666 }\r
1667 \r
1668 VOID\r
1669 halbtc8188c2ant_ActionPanA2dp(\r
1670         IN      PBTC_COEXIST            pBtCoexist\r
1671         )\r
1672 {\r
1673         if(BTC_CHIP_CSR_BC4 == pBtCoexist->boardInfo.btChipType)\r
1674         {\r
1675                 halbtc8188c2ant_ActionPanA2dpBc4(pBtCoexist);\r
1676         }\r
1677         else if(BTC_CHIP_CSR_BC8 == pBtCoexist->boardInfo.btChipType)\r
1678         {\r
1679                 halbtc8188c2ant_ActionPanA2dpBc8(pBtCoexist);\r
1680         }\r
1681 }\r
1682 \r
1683 //============================================================\r
1684 // extern function start with EXhalbtc8188c2ant_\r
1685 //============================================================\r
1686 VOID\r
1687 EXhalbtc8188c2ant_PowerOnSetting(\r
1688         IN      PBTC_COEXIST            pBtCoexist\r
1689         )\r
1690 {\r
1691 }\r
1692 \r
1693 VOID\r
1694 EXhalbtc8188c2ant_InitHwConfig(\r
1695         IN      PBTC_COEXIST            pBtCoexist,\r
1696         IN      BOOLEAN                         bWifiOnly\r
1697         )\r
1698 {\r
1699         u1Byte  u1Tmp=0;\r
1700 \r
1701         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], 2Ant Init HW Config!!\n"));\r
1702 \r
1703         // backup rf 0x1e value\r
1704         pCoexDm->btRf0x1eBackup = \r
1705                 pBtCoexist->fBtcGetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xf0);\r
1706 \r
1707         if( (BTC_CHIP_CSR_BC4 == pBtCoexist->boardInfo.btChipType) ||\r
1708                 (BTC_CHIP_CSR_BC8 == pBtCoexist->boardInfo.btChipType) )\r
1709         {\r
1710                 u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x4fd) & BIT0;\r
1711                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x4fd, u1Tmp);\r
1712                 \r
1713                 halbtc8188c2ant_CoexTable(pBtCoexist, FORCE_EXEC, 0xaaaa9aaa, 0xffbd0040, 0x40000010);\r
1714         }\r
1715 }\r
1716 \r
1717 VOID\r
1718 EXhalbtc8188c2ant_InitCoexDm(\r
1719         IN      PBTC_COEXIST            pBtCoexist\r
1720         )\r
1721 {\r
1722         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Coex Mechanism Init!!\n"));\r
1723         \r
1724         halbtc8188c2ant_InitCoexDm(pBtCoexist);\r
1725 }\r
1726 \r
1727 VOID\r
1728 EXhalbtc8188c2ant_DisplayCoexInfo(\r
1729         IN      PBTC_COEXIST            pBtCoexist\r
1730         )\r
1731 {\r
1732         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;\r
1733         PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;\r
1734         pu1Byte                         cliBuf=pBtCoexist->cliBuf;\r
1735         u1Byte                          u1Tmp[4], i, btInfoExt, psTdmaCase=0;\r
1736         u4Byte                          u4Tmp[4];\r
1737 \r
1738         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[BT Coexist info]============");\r
1739         CL_PRINTF(cliBuf);\r
1740 \r
1741         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ", "Ant PG number/ Ant mechanism:", \\r
1742                 pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum);\r
1743         CL_PRINTF(cliBuf);      \r
1744         \r
1745         if(pBtCoexist->bManualControl)\r
1746         {\r
1747                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "[Action Manual control]!!");\r
1748                 CL_PRINTF(cliBuf);\r
1749         }\r
1750         \r
1751         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d", "BT stack/ hci ext ver", \\r
1752                 ((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion);\r
1753         CL_PRINTF(cliBuf);\r
1754         \r
1755         // wifi status\r
1756         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Wifi Status]============");\r
1757         CL_PRINTF(cliBuf);\r
1758         pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_WIFI_STATUS);\r
1759 \r
1760         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[BT Status]============");\r
1761         CL_PRINTF(cliBuf);\r
1762         \r
1763         if(pStackInfo->bProfileNotified)\r
1764         {                       \r
1765                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP", \\r
1766                         pStackInfo->bScoExist, pStackInfo->bHidExist, pStackInfo->bPanExist, pStackInfo->bA2dpExist);\r
1767                 CL_PRINTF(cliBuf);      \r
1768 \r
1769                 pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_BT_LINK_INFO);\r
1770         }\r
1771         \r
1772         // Sw mechanism \r
1773         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw mechanism]============");\r
1774         CL_PRINTF(cliBuf);\r
1775         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d(0x%x) ", "SM2[AgcT/ AdcB/ SwDacSwing(lvl)]", \\r
1776                 pCoexDm->bCurAgcTableEn, pCoexDm->bCurAdcBackOff, pCoexDm->bCurDacSwingOn, pCoexDm->curDacSwingLvl);\r
1777         CL_PRINTF(cliBuf);\r
1778 \r
1779         // Fw mechanism         \r
1780         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw mechanism]============");\r
1781         CL_PRINTF(cliBuf);\r
1782 \r
1783         // Hw setting           \r
1784         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Hw setting]============");\r
1785         CL_PRINTF(cliBuf);      \r
1786 \r
1787         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "RF-A, 0x1e initVal", \\r
1788                 pCoexDm->btRf0x1eBackup);\r
1789         CL_PRINTF(cliBuf);\r
1790 \r
1791         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x40);\r
1792         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x40", \\r
1793                 u1Tmp[0]);\r
1794         CL_PRINTF(cliBuf);\r
1795 \r
1796         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xc50);\r
1797         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0xc50(dig)", \\r
1798                 u4Tmp[0]);\r
1799         CL_PRINTF(cliBuf);\r
1800 \r
1801         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c4);\r
1802         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c8);\r
1803         u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6cc);\r
1804         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x6c4/0x6c8/0x6cc(coexTable)", \\r
1805                 u4Tmp[0], u4Tmp[1], u4Tmp[2]);\r
1806         CL_PRINTF(cliBuf);\r
1807 \r
1808         pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_COEX_STATISTICS);\r
1809 }\r
1810 \r
1811 \r
1812 VOID\r
1813 EXhalbtc8188c2ant_IpsNotify(\r
1814         IN      PBTC_COEXIST            pBtCoexist,\r
1815         IN      u1Byte                  type\r
1816         )\r
1817 {\r
1818         if(BTC_IPS_ENTER == type)\r
1819         {\r
1820                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], IPS ENTER notify\n"));\r
1821                 halbtc8188c2ant_CoexAllOff(pBtCoexist);\r
1822         }\r
1823         else if(BTC_IPS_LEAVE == type)\r
1824         {\r
1825                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], IPS LEAVE notify\n"));\r
1826                 //halbtc8188c2ant_InitCoexDm(pBtCoexist);\r
1827         }\r
1828 }\r
1829 \r
1830 VOID\r
1831 EXhalbtc8188c2ant_LpsNotify(\r
1832         IN      PBTC_COEXIST            pBtCoexist,\r
1833         IN      u1Byte                  type\r
1834         )\r
1835 {\r
1836         if(BTC_LPS_ENABLE == type)\r
1837         {\r
1838                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], LPS ENABLE notify\n"));\r
1839                 halbtc8188c2ant_CoexAllOff(pBtCoexist);\r
1840         }\r
1841         else if(BTC_LPS_DISABLE == type)\r
1842         {\r
1843                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], LPS DISABLE notify\n"));\r
1844                 halbtc8188c2ant_InitCoexDm(pBtCoexist);\r
1845         }\r
1846 }\r
1847 \r
1848 VOID\r
1849 EXhalbtc8188c2ant_ScanNotify(\r
1850         IN      PBTC_COEXIST            pBtCoexist,\r
1851         IN      u1Byte                  type\r
1852         )\r
1853 {\r
1854         if(BTC_SCAN_START == type)\r
1855         {\r
1856                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN START notify\n"));\r
1857         }\r
1858         else if(BTC_SCAN_FINISH == type)\r
1859         {\r
1860                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN FINISH notify\n"));\r
1861         }\r
1862 }\r
1863 \r
1864 VOID\r
1865 EXhalbtc8188c2ant_ConnectNotify(\r
1866         IN      PBTC_COEXIST            pBtCoexist,\r
1867         IN      u1Byte                  type\r
1868         )\r
1869 {\r
1870         if(BTC_ASSOCIATE_START == type)\r
1871         {\r
1872                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT START notify\n"));\r
1873         }\r
1874         else if(BTC_ASSOCIATE_FINISH == type)\r
1875         {\r
1876                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT FINISH notify\n"));\r
1877         }\r
1878 }\r
1879 \r
1880 VOID\r
1881 EXhalbtc8188c2ant_MediaStatusNotify(\r
1882         IN      PBTC_COEXIST                    pBtCoexist,\r
1883         IN      u1Byte                          type\r
1884         )\r
1885 {       \r
1886         if(BTC_MEDIA_CONNECT == type)\r
1887         {\r
1888                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], MEDIA connect notify\n"));\r
1889         }\r
1890         else\r
1891         {\r
1892                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], MEDIA disconnect notify\n"));\r
1893         }\r
1894         \r
1895 }\r
1896 \r
1897 VOID\r
1898 EXhalbtc8188c2ant_SpecialPacketNotify(\r
1899         IN      PBTC_COEXIST                    pBtCoexist,\r
1900         IN      u1Byte                          type\r
1901         )\r
1902 {\r
1903         if(type == BTC_PACKET_DHCP)\r
1904         {\r
1905                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], DHCP Packet notify\n"));\r
1906         }\r
1907 }\r
1908 \r
1909 VOID\r
1910 EXhalbtc8188c2ant_BtInfoNotify(\r
1911         IN      PBTC_COEXIST            pBtCoexist,\r
1912         IN      pu1Byte                 tmpBuf,\r
1913         IN      u1Byte                  length\r
1914         )\r
1915 {\r
1916 }\r
1917 \r
1918 VOID\r
1919 EXhalbtc8188c2ant_HaltNotify(\r
1920         IN      PBTC_COEXIST                    pBtCoexist\r
1921         )\r
1922 {\r
1923         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Halt notify\n"));\r
1924 \r
1925         EXhalbtc8188c2ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);\r
1926 }\r
1927 \r
1928 VOID\r
1929 EXhalbtc8188c2ant_Periodical(\r
1930         IN      PBTC_COEXIST                    pBtCoexist\r
1931         )\r
1932 {\r
1933         u1Byte  algorithm;\r
1934 \r
1935         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], 2Ant Periodical!!\n"));\r
1936 \r
1937         // NOTE:\r
1938         // sw mechanism must be done after fw mechanism\r
1939         // \r
1940 \r
1941         if((BTC_CHIP_CSR_BC4 == pBtCoexist->boardInfo.btChipType) ||\r
1942                 (BTC_CHIP_CSR_BC8 == pBtCoexist->boardInfo.btChipType) )\r
1943         {\r
1944                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_GET_BT_RSSI, NULL);\r
1945 \r
1946                 halbtc8188c2ant_MonitorBtState(pBtCoexist);\r
1947                 algorithm = halbtc8188c2ant_ActionAlgorithm(pBtCoexist);        \r
1948                 pCoexDm->curAlgorithm = algorithm;\r
1949                 switch(pCoexDm->curAlgorithm)\r
1950                 {\r
1951                         case BT_8188C_2ANT_COEX_ALGO_SCO:\r
1952                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = SCO\n"));\r
1953                                 halbtc8188c2ant_ActionSco(pBtCoexist);\r
1954                                 break;\r
1955                         case BT_8188C_2ANT_COEX_ALGO_HID:\r
1956                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = HID\n"));\r
1957                                 halbtc8188c2ant_ActionHid(pBtCoexist);\r
1958                                 break;\r
1959                         case BT_8188C_2ANT_COEX_ALGO_A2DP:\r
1960                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = A2DP\n"));\r
1961                                 halbtc8188c2ant_ActionA2dp(pBtCoexist);\r
1962                                 break;\r
1963                         case BT_8188C_2ANT_COEX_ALGO_PAN:\r
1964                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = PAN\n"));\r
1965                                 halbtc8188c2ant_ActionPan(pBtCoexist);\r
1966                                 break;\r
1967                         case BT_8188C_2ANT_COEX_ALGO_HID_A2DP:\r
1968                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = HID+A2DP\n"));\r
1969                                 halbtc8188c2ant_ActionHidA2dp(pBtCoexist);\r
1970                                 break;\r
1971                         case BT_8188C_2ANT_COEX_ALGO_HID_PAN:\r
1972                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = PAN+HID\n"));\r
1973                                 halbtc8188c2ant_ActionHidPan(pBtCoexist);\r
1974                                 break;\r
1975                         case BT_8188C_2ANT_COEX_ALGO_PAN_A2DP:\r
1976                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = PAN+A2DP\n"));\r
1977                                 halbtc8188c2ant_ActionPanA2dp(pBtCoexist);\r
1978                                 break;\r
1979                         default:\r
1980                                 break;\r
1981                 }\r
1982         }\r
1983 }\r
1984 \r
1985 \r
1986 #endif\r
1987 \r