dt-bindings: Document the Rockchip RGA bindings
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723bs / hal / OUTSRC-BTCoexist / HalBtc8192e2Ant.c
1 //============================================================\r
2 // Description:\r
3 //\r
4 // This file is for RTL8192E Co-exist mechanism\r
5 //\r
6 // History\r
7 // 2012/11/15 Cosa first check in.\r
8 //\r
9 //============================================================\r
10 \r
11 //============================================================\r
12 // include files\r
13 //============================================================\r
14 #include "Mp_Precomp.h"\r
15 #if(BT_30_SUPPORT == 1)\r
16 //============================================================\r
17 // Global variables, these are static variables\r
18 //============================================================\r
19 static COEX_DM_8192E_2ANT               GLCoexDm8192e2Ant;\r
20 static PCOEX_DM_8192E_2ANT      pCoexDm=&GLCoexDm8192e2Ant;\r
21 static COEX_STA_8192E_2ANT              GLCoexSta8192e2Ant;\r
22 static PCOEX_STA_8192E_2ANT     pCoexSta=&GLCoexSta8192e2Ant;\r
23 \r
24 const char *const GLBtInfoSrc8192e2Ant[]={\r
25         "BT Info[wifi fw]",\r
26         "BT Info[bt rsp]",\r
27         "BT Info[bt auto report]",\r
28 };\r
29 \r
30 u4Byte  GLCoexVerDate8192e2Ant=20130912;\r
31 u4Byte  GLCoexVer8192e2Ant=0x35;\r
32 \r
33 //============================================================\r
34 // local function proto type if needed\r
35 //============================================================\r
36 //============================================================\r
37 // local function start with halbtc8192e2ant_\r
38 //============================================================\r
39 u1Byte\r
40 halbtc8192e2ant_BtRssiState(\r
41         u1Byte                  levelNum,\r
42         u1Byte                  rssiThresh,\r
43         u1Byte                  rssiThresh1\r
44         )\r
45 {\r
46         s4Byte                  btRssi=0;\r
47         u1Byte                  btRssiState=pCoexSta->preBtRssiState;\r
48 \r
49         btRssi = pCoexSta->btRssi;\r
50 \r
51         if(levelNum == 2)\r
52         {                       \r
53                 if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||\r
54                         (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW))\r
55                 {\r
56                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi pre state=LOW\n"));\r
57                         if(btRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8192E_2ANT))\r
58                         {\r
59                                 btRssiState = BTC_RSSI_STATE_HIGH;\r
60                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to High\n"));\r
61                         }\r
62                         else\r
63                         {\r
64                                 btRssiState = BTC_RSSI_STATE_STAY_LOW;\r
65                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at Low\n"));\r
66                         }\r
67                 }\r
68                 else\r
69                 {\r
70                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi pre state=HIGH\n"));\r
71                         if(btRssi < rssiThresh)\r
72                         {\r
73                                 btRssiState = BTC_RSSI_STATE_LOW;\r
74                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Low\n"));\r
75                         }\r
76                         else\r
77                         {\r
78                                 btRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
79                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at High\n"));\r
80                         }\r
81                 }\r
82         }\r
83         else if(levelNum == 3)\r
84         {\r
85                 if(rssiThresh > rssiThresh1)\r
86                 {\r
87                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi thresh error!!\n"));\r
88                         return pCoexSta->preBtRssiState;\r
89                 }\r
90                 \r
91                 if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||\r
92                         (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW))\r
93                 {\r
94                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi pre state=LOW\n"));\r
95                         if(btRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8192E_2ANT))\r
96                         {\r
97                                 btRssiState = BTC_RSSI_STATE_MEDIUM;\r
98                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Medium\n"));\r
99                         }\r
100                         else\r
101                         {\r
102                                 btRssiState = BTC_RSSI_STATE_STAY_LOW;\r
103                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at Low\n"));\r
104                         }\r
105                 }\r
106                 else if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_MEDIUM) ||\r
107                         (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_MEDIUM))\r
108                 {\r
109                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi pre state=MEDIUM\n"));\r
110                         if(btRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8192E_2ANT))\r
111                         {\r
112                                 btRssiState = BTC_RSSI_STATE_HIGH;\r
113                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to High\n"));\r
114                         }\r
115                         else if(btRssi < rssiThresh)\r
116                         {\r
117                                 btRssiState = BTC_RSSI_STATE_LOW;\r
118                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Low\n"));\r
119                         }\r
120                         else\r
121                         {\r
122                                 btRssiState = BTC_RSSI_STATE_STAY_MEDIUM;\r
123                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at Medium\n"));\r
124                         }\r
125                 }\r
126                 else\r
127                 {\r
128                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi pre state=HIGH\n"));\r
129                         if(btRssi < rssiThresh1)\r
130                         {\r
131                                 btRssiState = BTC_RSSI_STATE_MEDIUM;\r
132                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state switch to Medium\n"));\r
133                         }\r
134                         else\r
135                         {\r
136                                 btRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
137                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_RSSI_STATE, ("[BTCoex], BT Rssi state stay at High\n"));\r
138                         }\r
139                 }\r
140         }\r
141                 \r
142         pCoexSta->preBtRssiState = btRssiState;\r
143 \r
144         return btRssiState;\r
145 }\r
146 \r
147 u1Byte\r
148 halbtc8192e2ant_WifiRssiState(\r
149         IN      PBTC_COEXIST            pBtCoexist,\r
150         IN      u1Byte                  index,\r
151         IN      u1Byte                  levelNum,\r
152         IN      u1Byte                  rssiThresh,\r
153         IN      u1Byte                  rssiThresh1\r
154         )\r
155 {\r
156         s4Byte                  wifiRssi=0;\r
157         u1Byte                  wifiRssiState=pCoexSta->preWifiRssiState[index];\r
158 \r
159         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);\r
160         \r
161         if(levelNum == 2)\r
162         {\r
163                 if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||\r
164                         (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW))\r
165                 {\r
166                         if(wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8192E_2ANT))\r
167                         {\r
168                                 wifiRssiState = BTC_RSSI_STATE_HIGH;\r
169                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to High\n"));\r
170                         }\r
171                         else\r
172                         {\r
173                                 wifiRssiState = BTC_RSSI_STATE_STAY_LOW;\r
174                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at Low\n"));\r
175                         }\r
176                 }\r
177                 else\r
178                 {\r
179                         if(wifiRssi < rssiThresh)\r
180                         {\r
181                                 wifiRssiState = BTC_RSSI_STATE_LOW;\r
182                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to Low\n"));\r
183                         }\r
184                         else\r
185                         {\r
186                                 wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
187                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at High\n"));\r
188                         }\r
189                 }\r
190         }\r
191         else if(levelNum == 3)\r
192         {\r
193                 if(rssiThresh > rssiThresh1)\r
194                 {\r
195                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI thresh error!!\n"));\r
196                         return pCoexSta->preWifiRssiState[index];\r
197                 }\r
198                 \r
199                 if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||\r
200                         (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW))\r
201                 {\r
202                         if(wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8192E_2ANT))\r
203                         {\r
204                                 wifiRssiState = BTC_RSSI_STATE_MEDIUM;\r
205                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to Medium\n"));\r
206                         }\r
207                         else\r
208                         {\r
209                                 wifiRssiState = BTC_RSSI_STATE_STAY_LOW;\r
210                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at Low\n"));\r
211                         }\r
212                 }\r
213                 else if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_MEDIUM) ||\r
214                         (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_MEDIUM))\r
215                 {\r
216                         if(wifiRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8192E_2ANT))\r
217                         {\r
218                                 wifiRssiState = BTC_RSSI_STATE_HIGH;\r
219                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to High\n"));\r
220                         }\r
221                         else if(wifiRssi < rssiThresh)\r
222                         {\r
223                                 wifiRssiState = BTC_RSSI_STATE_LOW;\r
224                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to Low\n"));\r
225                         }\r
226                         else\r
227                         {\r
228                                 wifiRssiState = BTC_RSSI_STATE_STAY_MEDIUM;\r
229                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at Medium\n"));\r
230                         }\r
231                 }\r
232                 else\r
233                 {\r
234                         if(wifiRssi < rssiThresh1)\r
235                         {\r
236                                 wifiRssiState = BTC_RSSI_STATE_MEDIUM;\r
237                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state switch to Medium\n"));\r
238                         }\r
239                         else\r
240                         {\r
241                                 wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
242                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_WIFI_RSSI_STATE, ("[BTCoex], wifi RSSI state stay at High\n"));\r
243                         }\r
244                 }\r
245         }\r
246                 \r
247         pCoexSta->preWifiRssiState[index] = wifiRssiState;\r
248 \r
249         return wifiRssiState;\r
250 }\r
251 \r
252 VOID\r
253 halbtc8192e2ant_MonitorBtEnableDisable(\r
254         IN      PBTC_COEXIST            pBtCoexist\r
255         )\r
256 {\r
257         static BOOLEAN  bPreBtDisabled=FALSE;\r
258         static u4Byte   btDisableCnt=0;\r
259         BOOLEAN                 bBtActive=TRUE, bBtDisabled=FALSE;\r
260 \r
261         // This function check if bt is disabled\r
262 \r
263         if(     pCoexSta->highPriorityTx == 0 &&\r
264                 pCoexSta->highPriorityRx == 0 &&\r
265                 pCoexSta->lowPriorityTx == 0 &&\r
266                 pCoexSta->lowPriorityRx == 0)\r
267         {\r
268                 bBtActive = FALSE;\r
269         }\r
270         if(     pCoexSta->highPriorityTx == 0xffff &&\r
271                 pCoexSta->highPriorityRx == 0xffff &&\r
272                 pCoexSta->lowPriorityTx == 0xffff &&\r
273                 pCoexSta->lowPriorityRx == 0xffff)\r
274         {\r
275                 bBtActive = FALSE;\r
276         }\r
277         if(bBtActive)\r
278         {\r
279                 btDisableCnt = 0;\r
280                 bBtDisabled = FALSE;\r
281                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);\r
282                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], BT is enabled !!\n"));\r
283         }\r
284         else\r
285         {\r
286                 btDisableCnt++;\r
287                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], bt all counters=0, %d times!!\n", \r
288                                 btDisableCnt));\r
289                 if(btDisableCnt >= 2)\r
290                 {\r
291                         bBtDisabled = TRUE;\r
292                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);\r
293                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], BT is disabled !!\n"));\r
294                 }\r
295         }\r
296         if(bPreBtDisabled != bBtDisabled)\r
297         {\r
298                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], BT is from %s to %s!!\n", \r
299                         (bPreBtDisabled ? "disabled":"enabled"), \r
300                         (bBtDisabled ? "disabled":"enabled")));\r
301                 bPreBtDisabled = bBtDisabled;\r
302                 if(!bBtDisabled)\r
303                 {\r
304                 }\r
305                 else\r
306                 {\r
307                 }\r
308         }\r
309 }\r
310 \r
311 u4Byte\r
312 halbtc8192e2ant_DecideRaMask(\r
313         IN      PBTC_COEXIST            pBtCoexist,\r
314         IN      u1Byte                          ssType,\r
315         IN      u4Byte                          raMaskType\r
316         )\r
317 {\r
318         u4Byte  disRaMask=0x0;\r
319         \r
320         switch(raMaskType)\r
321         {\r
322                 case 0: // normal mode\r
323                         if(ssType == 2)\r
324                                 disRaMask = 0x0;                        // enable 2ss\r
325                         else\r
326                                 disRaMask = 0xfff00000;         // disable 2ss\r
327                         break;\r
328                 case 1: // disable cck 1/2\r
329                         if(ssType == 2)\r
330                                 disRaMask = 0x00000003;         // enable 2ss\r
331                         else\r
332                                 disRaMask = 0xfff00003;         // disable 2ss\r
333                         break;\r
334                 case 2: // disable cck 1/2/5.5, ofdm 6/9/12/18/24, mcs 0/1/2/3/4\r
335                         if(ssType == 2)\r
336                                 disRaMask = 0x0001f1f7;         // enable 2ss\r
337                         else\r
338                                 disRaMask = 0xfff1f1f7;         // disable 2ss\r
339                         break;\r
340                 default:\r
341                         break;\r
342         }\r
343 \r
344         return disRaMask;\r
345 }\r
346 \r
347 VOID\r
348 halbtc8192e2ant_UpdateRaMask(\r
349         IN      PBTC_COEXIST            pBtCoexist,\r
350         IN      BOOLEAN                         bForceExec,\r
351         IN      u4Byte                          disRateMask\r
352         )\r
353 {\r
354         pCoexDm->curRaMask = disRateMask;\r
355         \r
356         if( bForceExec || (pCoexDm->preRaMask != pCoexDm->curRaMask))\r
357         {\r
358                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_UPDATE_RAMASK, &pCoexDm->curRaMask);\r
359         }\r
360         pCoexDm->preRaMask = pCoexDm->curRaMask;\r
361 }\r
362 \r
363 VOID\r
364 halbtc8192e2ant_AutoRateFallbackRetry(\r
365         IN      PBTC_COEXIST            pBtCoexist,\r
366         IN      BOOLEAN                         bForceExec,\r
367         IN      u1Byte                          type\r
368         )\r
369 {\r
370         BOOLEAN bWifiUnderBMode=FALSE;\r
371         \r
372         pCoexDm->curArfrType = type;\r
373 \r
374         if( bForceExec || (pCoexDm->preArfrType != pCoexDm->curArfrType))\r
375         {\r
376                 switch(pCoexDm->curArfrType)\r
377                 {\r
378                         case 0: // normal mode\r
379                                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x430, pCoexDm->backupArfrCnt1);\r
380                                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x434, pCoexDm->backupArfrCnt2);\r
381                                 break;\r
382                         case 1: \r
383                                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_UNDER_B_MODE, &bWifiUnderBMode);\r
384                                 if(bWifiUnderBMode)\r
385                                 {\r
386                                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x430, 0x0);\r
387                                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x434, 0x01010101);\r
388                                 }\r
389                                 else\r
390                                 {\r
391                                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x430, 0x0);\r
392                                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x434, 0x04030201);\r
393                                 }\r
394                                 break;\r
395                         default:\r
396                                 break;\r
397                 }\r
398         }\r
399 \r
400         pCoexDm->preArfrType = pCoexDm->curArfrType;\r
401 }\r
402 \r
403 VOID\r
404 halbtc8192e2ant_RetryLimit(\r
405         IN      PBTC_COEXIST            pBtCoexist,\r
406         IN      BOOLEAN                         bForceExec,\r
407         IN      u1Byte                          type\r
408         )\r
409 {\r
410         pCoexDm->curRetryLimitType = type;\r
411 \r
412         if( bForceExec || (pCoexDm->preRetryLimitType != pCoexDm->curRetryLimitType))\r
413         {\r
414                 switch(pCoexDm->curRetryLimitType)\r
415                 {\r
416                         case 0: // normal mode\r
417                                 pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x42a, pCoexDm->backupRetryLimit);\r
418                                 break;\r
419                         case 1: // retry limit=8\r
420                                 pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x42a, 0x0808);\r
421                                 break;\r
422                         default:\r
423                                 break;\r
424                 }\r
425         }\r
426 \r
427         pCoexDm->preRetryLimitType = pCoexDm->curRetryLimitType;\r
428 }\r
429 \r
430 VOID\r
431 halbtc8192e2ant_AmpduMaxTime(\r
432         IN      PBTC_COEXIST            pBtCoexist,\r
433         IN      BOOLEAN                         bForceExec,\r
434         IN      u1Byte                          type\r
435         )\r
436 {\r
437         pCoexDm->curAmpduTimeType = type;\r
438 \r
439         if( bForceExec || (pCoexDm->preAmpduTimeType != pCoexDm->curAmpduTimeType))\r
440         {\r
441                 switch(pCoexDm->curAmpduTimeType)\r
442                 {\r
443                         case 0: // normal mode\r
444                                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x456, pCoexDm->backupAmpduMaxTime);\r
445                                 break;\r
446                         case 1: // AMPDU timw = 0x38 * 32us\r
447                                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x456, 0x38);\r
448                                 break;\r
449                         default:\r
450                                 break;\r
451                 }\r
452         }\r
453 \r
454         pCoexDm->preAmpduTimeType = pCoexDm->curAmpduTimeType;\r
455 }\r
456 \r
457 VOID\r
458 halbtc8192e2ant_LimitedTx(\r
459         IN      PBTC_COEXIST            pBtCoexist,\r
460         IN      BOOLEAN                         bForceExec,\r
461         IN      u1Byte                          raMaskType,\r
462         IN      u1Byte                          arfrType,\r
463         IN      u1Byte                          retryLimitType,\r
464         IN      u1Byte                          ampduTimeType\r
465         )\r
466 {\r
467         u4Byte  disRaMask=0x0;\r
468 \r
469         pCoexDm->curRaMaskType = raMaskType;\r
470         disRaMask = halbtc8192e2ant_DecideRaMask(pBtCoexist, pCoexDm->curSsType, raMaskType);\r
471         halbtc8192e2ant_UpdateRaMask(pBtCoexist, bForceExec, disRaMask);\r
472 \r
473         halbtc8192e2ant_AutoRateFallbackRetry(pBtCoexist, bForceExec, arfrType);\r
474         halbtc8192e2ant_RetryLimit(pBtCoexist, bForceExec, retryLimitType);\r
475         halbtc8192e2ant_AmpduMaxTime(pBtCoexist, bForceExec, ampduTimeType);\r
476 }\r
477 \r
478 VOID\r
479 halbtc8192e2ant_LimitedRx(\r
480         IN      PBTC_COEXIST            pBtCoexist,\r
481         IN      BOOLEAN                         bForceExec,\r
482         IN      BOOLEAN                         bRejApAggPkt,\r
483         IN      BOOLEAN                         bBtCtrlAggBufSize,\r
484         IN      u1Byte                          aggBufSize\r
485         )\r
486 {\r
487         BOOLEAN bRejectRxAgg=bRejApAggPkt;\r
488         BOOLEAN bBtCtrlRxAggSize=bBtCtrlAggBufSize;\r
489         u1Byte  rxAggSize=aggBufSize;\r
490 \r
491         //============================================\r
492         //      Rx Aggregation related setting\r
493         //============================================\r
494         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, &bRejectRxAgg);\r
495         // decide BT control aggregation buf size or not\r
496         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, &bBtCtrlRxAggSize);\r
497         // aggregation buf size, only work when BT control Rx aggregation size.\r
498         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_AGG_BUF_SIZE, &rxAggSize);\r
499         // real update aggregation setting\r
500         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL);\r
501 \r
502 \r
503 }\r
504 \r
505 VOID\r
506 halbtc8192e2ant_MonitorBtCtr(\r
507         IN      PBTC_COEXIST            pBtCoexist\r
508         )\r
509 {\r
510         u4Byte                  regHPTxRx, regLPTxRx, u4Tmp;\r
511         u4Byte                  regHPTx=0, regHPRx=0, regLPTx=0, regLPRx=0;\r
512         u1Byte                  u1Tmp;\r
513         \r
514         regHPTxRx = 0x770;\r
515         regLPTxRx = 0x774;\r
516 \r
517         u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regHPTxRx);\r
518         regHPTx = u4Tmp & bMaskLWord;\r
519         regHPRx = (u4Tmp & bMaskHWord)>>16;\r
520 \r
521         u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regLPTxRx);\r
522         regLPTx = u4Tmp & bMaskLWord;\r
523         regLPRx = (u4Tmp & bMaskHWord)>>16;\r
524                 \r
525         pCoexSta->highPriorityTx = regHPTx;\r
526         pCoexSta->highPriorityRx = regHPRx;\r
527         pCoexSta->lowPriorityTx = regLPTx;\r
528         pCoexSta->lowPriorityRx = regLPRx;\r
529 \r
530         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], High Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n", \r
531                 regHPTxRx, regHPTx, regHPTx, regHPRx, regHPRx));\r
532         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_BT_MONITOR, ("[BTCoex], Low Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n", \r
533                 regLPTxRx, regLPTx, regLPTx, regLPRx, regLPRx));\r
534 \r
535         // reset counter\r
536         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc);\r
537 }\r
538 \r
539 VOID\r
540 halbtc8192e2ant_QueryBtInfo(\r
541         IN      PBTC_COEXIST            pBtCoexist\r
542         )\r
543 {\r
544         u1Byte                  H2C_Parameter[1] ={0};\r
545 \r
546         pCoexSta->bC2hBtInfoReqSent = TRUE;\r
547 \r
548         H2C_Parameter[0] |= BIT0;       // trigger\r
549 \r
550         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], Query Bt Info, FW write 0x61=0x%x\n", \r
551                 H2C_Parameter[0]));\r
552 \r
553         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x61, 1, H2C_Parameter);\r
554 }\r
555 \r
556 BOOLEAN\r
557 halbtc8192e2ant_IsWifiStatusChanged(\r
558         IN      PBTC_COEXIST            pBtCoexist\r
559         )\r
560 {\r
561         static BOOLEAN  bPreWifiBusy=FALSE, bPreUnder4way=FALSE, bPreBtHsOn=FALSE;\r
562         BOOLEAN bWifiBusy=FALSE, bUnder4way=FALSE, bBtHsOn=FALSE;\r
563         BOOLEAN bWifiConnected=FALSE;\r
564 \r
565         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
566         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
567         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
568         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, &bUnder4way);\r
569 \r
570         if(bWifiConnected)\r
571         {\r
572                 if(bWifiBusy != bPreWifiBusy)\r
573                 {\r
574                         bPreWifiBusy = bWifiBusy;\r
575                         return TRUE;\r
576                 }\r
577                 if(bUnder4way != bPreUnder4way)\r
578                 {\r
579                         bPreUnder4way = bUnder4way;\r
580                         return TRUE;\r
581                 }\r
582                 if(bBtHsOn != bPreBtHsOn)\r
583                 {\r
584                         bPreBtHsOn = bBtHsOn;\r
585                         return TRUE;\r
586                 }\r
587         }\r
588 \r
589         return FALSE;\r
590 }\r
591 \r
592 VOID\r
593 halbtc8192e2ant_UpdateBtLinkInfo(\r
594         IN      PBTC_COEXIST            pBtCoexist\r
595         )\r
596 {\r
597         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
598         BOOLEAN                         bBtHsOn=FALSE;\r
599 \r
600         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
601 \r
602         pBtLinkInfo->bBtLinkExist = pCoexSta->bBtLinkExist;\r
603         pBtLinkInfo->bScoExist = pCoexSta->bScoExist;\r
604         pBtLinkInfo->bA2dpExist = pCoexSta->bA2dpExist;\r
605         pBtLinkInfo->bPanExist = pCoexSta->bPanExist;\r
606         pBtLinkInfo->bHidExist = pCoexSta->bHidExist;\r
607 \r
608         // work around for HS mode.\r
609         if(bBtHsOn)\r
610         {\r
611                 pBtLinkInfo->bPanExist = TRUE;\r
612                 pBtLinkInfo->bBtLinkExist = TRUE;\r
613         }\r
614 \r
615         // check if Sco only\r
616         if( pBtLinkInfo->bScoExist &&\r
617                 !pBtLinkInfo->bA2dpExist &&\r
618                 !pBtLinkInfo->bPanExist &&\r
619                 !pBtLinkInfo->bHidExist )\r
620                 pBtLinkInfo->bScoOnly = TRUE;\r
621         else\r
622                 pBtLinkInfo->bScoOnly = FALSE;\r
623 \r
624         // check if A2dp only\r
625         if( !pBtLinkInfo->bScoExist &&\r
626                 pBtLinkInfo->bA2dpExist &&\r
627                 !pBtLinkInfo->bPanExist &&\r
628                 !pBtLinkInfo->bHidExist )\r
629                 pBtLinkInfo->bA2dpOnly = TRUE;\r
630         else\r
631                 pBtLinkInfo->bA2dpOnly = FALSE;\r
632 \r
633         // check if Pan only\r
634         if( !pBtLinkInfo->bScoExist &&\r
635                 !pBtLinkInfo->bA2dpExist &&\r
636                 pBtLinkInfo->bPanExist &&\r
637                 !pBtLinkInfo->bHidExist )\r
638                 pBtLinkInfo->bPanOnly = TRUE;\r
639         else\r
640                 pBtLinkInfo->bPanOnly = FALSE;\r
641         \r
642         // check if Hid only\r
643         if( !pBtLinkInfo->bScoExist &&\r
644                 !pBtLinkInfo->bA2dpExist &&\r
645                 !pBtLinkInfo->bPanExist &&\r
646                 pBtLinkInfo->bHidExist )\r
647                 pBtLinkInfo->bHidOnly = TRUE;\r
648         else\r
649                 pBtLinkInfo->bHidOnly = FALSE;\r
650 }\r
651 \r
652 u1Byte\r
653 halbtc8192e2ant_ActionAlgorithm(\r
654         IN      PBTC_COEXIST            pBtCoexist\r
655         )\r
656 {\r
657         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
658         PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;\r
659         BOOLEAN                         bBtHsOn=FALSE;\r
660         u1Byte                          algorithm=BT_8192E_2ANT_COEX_ALGO_UNDEFINED;\r
661         u1Byte                          numOfDiffProfile=0;\r
662 \r
663         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
664                 \r
665         if(!pBtLinkInfo->bBtLinkExist)\r
666         {\r
667                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], No BT link exists!!!\n"));\r
668                 return algorithm;\r
669         }\r
670 \r
671         if(pBtLinkInfo->bScoExist)\r
672                 numOfDiffProfile++;\r
673         if(pBtLinkInfo->bHidExist)\r
674                 numOfDiffProfile++;\r
675         if(pBtLinkInfo->bPanExist)\r
676                 numOfDiffProfile++;\r
677         if(pBtLinkInfo->bA2dpExist)\r
678                 numOfDiffProfile++;\r
679         \r
680         if(numOfDiffProfile == 1)\r
681         {\r
682                 if(pBtLinkInfo->bScoExist)\r
683                 {\r
684                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO only\n"));\r
685                         algorithm = BT_8192E_2ANT_COEX_ALGO_SCO;\r
686                 }\r
687                 else\r
688                 {\r
689                         if(pBtLinkInfo->bHidExist)\r
690                         {\r
691                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID only\n"));\r
692                                 algorithm = BT_8192E_2ANT_COEX_ALGO_HID;\r
693                         }\r
694                         else if(pBtLinkInfo->bA2dpExist)\r
695                         {\r
696                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], A2DP only\n"));\r
697                                 algorithm = BT_8192E_2ANT_COEX_ALGO_A2DP;\r
698                         }\r
699                         else if(pBtLinkInfo->bPanExist)\r
700                         {\r
701                                 if(bBtHsOn)\r
702                                 {\r
703                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], PAN(HS) only\n"));\r
704                                         algorithm = BT_8192E_2ANT_COEX_ALGO_PANHS;\r
705                                 }\r
706                                 else\r
707                                 {\r
708                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], PAN(EDR) only\n"));\r
709                                         algorithm = BT_8192E_2ANT_COEX_ALGO_PANEDR;\r
710                                 }\r
711                         }\r
712                 }\r
713         }\r
714         else if(numOfDiffProfile == 2)\r
715         {\r
716                 if(pBtLinkInfo->bScoExist)\r
717                 {\r
718                         if(pBtLinkInfo->bHidExist)\r
719                         {\r
720                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + HID\n"));\r
721                                 algorithm = BT_8192E_2ANT_COEX_ALGO_SCO;\r
722                         }\r
723                         else if(pBtLinkInfo->bA2dpExist)\r
724                         {\r
725                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + A2DP ==> SCO\n"));\r
726                                 algorithm = BT_8192E_2ANT_COEX_ALGO_PANEDR_HID;\r
727                         }\r
728                         else if(pBtLinkInfo->bPanExist)\r
729                         {\r
730                                 if(bBtHsOn)\r
731                                 {\r
732                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + PAN(HS)\n"));\r
733                                         algorithm = BT_8192E_2ANT_COEX_ALGO_SCO;\r
734                                 }\r
735                                 else\r
736                                 {\r
737                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + PAN(EDR)\n"));\r
738                                         algorithm = BT_8192E_2ANT_COEX_ALGO_SCO_PAN;\r
739                                 }\r
740                         }\r
741                 }\r
742                 else\r
743                 {\r
744                         if( pBtLinkInfo->bHidExist &&\r
745                                 pBtLinkInfo->bA2dpExist )\r
746                         {\r
747                                 if(pStackInfo->numOfHid >= 2)\r
748                                 {\r
749                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID*2 + A2DP\n"));\r
750                                         algorithm = BT_8192E_2ANT_COEX_ALGO_HID_A2DP_PANEDR;\r
751                                 }\r
752                                 else\r
753                                 {                       \r
754                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + A2DP\n"));\r
755                                         algorithm = BT_8192E_2ANT_COEX_ALGO_HID_A2DP;\r
756                                 }\r
757                         }\r
758                         else if( pBtLinkInfo->bHidExist &&\r
759                                 pBtLinkInfo->bPanExist )\r
760                         {\r
761                                 if(bBtHsOn)\r
762                                 {\r
763                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + PAN(HS)\n"));\r
764                                         algorithm = BT_8192E_2ANT_COEX_ALGO_HID;\r
765                                 }\r
766                                 else\r
767                                 {\r
768                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + PAN(EDR)\n"));\r
769                                         algorithm = BT_8192E_2ANT_COEX_ALGO_PANEDR_HID;\r
770                                 }\r
771                         }\r
772                         else if( pBtLinkInfo->bPanExist &&\r
773                                 pBtLinkInfo->bA2dpExist )\r
774                         {\r
775                                 if(bBtHsOn)\r
776                                 {\r
777                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], A2DP + PAN(HS)\n"));\r
778                                         algorithm = BT_8192E_2ANT_COEX_ALGO_A2DP_PANHS;\r
779                                 }\r
780                                 else\r
781                                 {\r
782                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], A2DP + PAN(EDR)\n"));\r
783                                         algorithm = BT_8192E_2ANT_COEX_ALGO_PANEDR_A2DP;\r
784                                 }\r
785                         }\r
786                 }\r
787         }\r
788         else if(numOfDiffProfile == 3)\r
789         {\r
790                 if(pBtLinkInfo->bScoExist)\r
791                 {\r
792                         if( pBtLinkInfo->bHidExist &&\r
793                                 pBtLinkInfo->bA2dpExist )\r
794                         {\r
795                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + HID + A2DP ==> HID\n"));\r
796                                 algorithm = BT_8192E_2ANT_COEX_ALGO_PANEDR_HID;\r
797                         }\r
798                         else if( pBtLinkInfo->bHidExist &&\r
799                                 pBtLinkInfo->bPanExist )\r
800                         {\r
801                                 if(bBtHsOn)\r
802                                 {\r
803                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + HID + PAN(HS)\n"));\r
804                                         algorithm = BT_8192E_2ANT_COEX_ALGO_SCO;\r
805                                 }\r
806                                 else\r
807                                 {\r
808                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + HID + PAN(EDR)\n"));\r
809                                         algorithm = BT_8192E_2ANT_COEX_ALGO_SCO_PAN;\r
810                                 }\r
811                         }\r
812                         else if( pBtLinkInfo->bPanExist &&\r
813                                 pBtLinkInfo->bA2dpExist )\r
814                         {\r
815                                 if(bBtHsOn)\r
816                                 {\r
817                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + A2DP + PAN(HS)\n"));\r
818                                         algorithm = BT_8192E_2ANT_COEX_ALGO_SCO;\r
819                                 }\r
820                                 else\r
821                                 {\r
822                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + A2DP + PAN(EDR) ==> HID\n"));\r
823                                         algorithm = BT_8192E_2ANT_COEX_ALGO_PANEDR_HID;\r
824                                 }\r
825                         }\r
826                 }\r
827                 else\r
828                 {\r
829                         if( pBtLinkInfo->bHidExist &&\r
830                                 pBtLinkInfo->bPanExist &&\r
831                                 pBtLinkInfo->bA2dpExist )\r
832                         {\r
833                                 if(bBtHsOn)\r
834                                 {\r
835                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + A2DP + PAN(HS)\n"));\r
836                                         algorithm = BT_8192E_2ANT_COEX_ALGO_HID_A2DP;\r
837                                 }\r
838                                 else\r
839                                 {\r
840                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], HID + A2DP + PAN(EDR)\n"));\r
841                                         algorithm = BT_8192E_2ANT_COEX_ALGO_HID_A2DP_PANEDR;\r
842                                 }\r
843                         }\r
844                 }\r
845         }\r
846         else if(numOfDiffProfile >= 3)\r
847         {\r
848                 if(pBtLinkInfo->bScoExist)\r
849                 {\r
850                         if( pBtLinkInfo->bHidExist &&\r
851                                 pBtLinkInfo->bPanExist &&\r
852                                 pBtLinkInfo->bA2dpExist )\r
853                         {\r
854                                 if(bBtHsOn)\r
855                                 {\r
856                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n"));\r
857 \r
858                                 }\r
859                                 else\r
860                                 {\r
861                                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n"));\r
862                                         algorithm = BT_8192E_2ANT_COEX_ALGO_PANEDR_HID;\r
863                                 }\r
864                         }\r
865                 }\r
866         }\r
867 \r
868         return algorithm;\r
869 }\r
870 \r
871 VOID\r
872 halbtc8192e2ant_SetFwDacSwingLevel(\r
873         IN      PBTC_COEXIST            pBtCoexist,\r
874         IN      u1Byte                  dacSwingLvl\r
875         )\r
876 {\r
877         u1Byte                  H2C_Parameter[1] ={0};\r
878 \r
879         // There are several type of dacswing\r
880         // 0x18/ 0x10/ 0xc/ 0x8/ 0x4/ 0x6\r
881         H2C_Parameter[0] = dacSwingLvl;\r
882 \r
883         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], Set Dac Swing Level=0x%x\n", dacSwingLvl));\r
884         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], FW write 0x64=0x%x\n", H2C_Parameter[0]));\r
885 \r
886         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x64, 1, H2C_Parameter);\r
887 }\r
888 \r
889 VOID\r
890 halbtc8192e2ant_SetFwDecBtPwr(\r
891         IN      PBTC_COEXIST            pBtCoexist,\r
892         IN      u1Byte                          decBtPwrLvl\r
893         )\r
894 {\r
895         u1Byte                  H2C_Parameter[1] ={0};\r
896         \r
897         H2C_Parameter[0] = decBtPwrLvl;\r
898 \r
899         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], decrease Bt Power level = %d, FW write 0x62=0x%x\n", \r
900                 decBtPwrLvl, H2C_Parameter[0]));\r
901 \r
902         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x62, 1, H2C_Parameter);    \r
903 }\r
904 \r
905 VOID\r
906 halbtc8192e2ant_DecBtPwr(\r
907         IN      PBTC_COEXIST            pBtCoexist,\r
908         IN      BOOLEAN                         bForceExec,\r
909         IN      u1Byte                          decBtPwrLvl\r
910         )\r
911 {\r
912         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s Dec BT power level = %d\n",  \r
913                 (bForceExec? "force to":""), decBtPwrLvl));\r
914         pCoexDm->curBtDecPwrLvl = decBtPwrLvl;\r
915 \r
916         if(!bForceExec)\r
917         {\r
918                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], preBtDecPwrLvl=%d, curBtDecPwrLvl=%d\n", \r
919                         pCoexDm->preBtDecPwrLvl, pCoexDm->curBtDecPwrLvl));\r
920 #if 0   // work around, avoid h2c command fail.\r
921                 if(pCoexDm->preBtDecPwrLvl == pCoexDm->curBtDecPwrLvl) \r
922                         return;\r
923 #endif\r
924         }\r
925         halbtc8192e2ant_SetFwDecBtPwr(pBtCoexist, pCoexDm->curBtDecPwrLvl);\r
926 \r
927         pCoexDm->preBtDecPwrLvl = pCoexDm->curBtDecPwrLvl;\r
928 }\r
929 \r
930 VOID\r
931 halbtc8192e2ant_SetBtAutoReport(\r
932         IN      PBTC_COEXIST            pBtCoexist,\r
933         IN      BOOLEAN                 bEnableAutoReport\r
934         )\r
935 {\r
936         u1Byte                  H2C_Parameter[1] ={0};\r
937         \r
938         H2C_Parameter[0] = 0;\r
939 \r
940         if(bEnableAutoReport)\r
941         {\r
942                 H2C_Parameter[0] |= BIT0;\r
943         }\r
944 \r
945         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], BT FW auto report : %s, FW write 0x68=0x%x\n", \r
946                 (bEnableAutoReport? "Enabled!!":"Disabled!!"), H2C_Parameter[0]));\r
947 \r
948         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x68, 1, H2C_Parameter);    \r
949 }\r
950 \r
951 VOID\r
952 halbtc8192e2ant_BtAutoReport(\r
953         IN      PBTC_COEXIST            pBtCoexist,\r
954         IN      BOOLEAN                 bForceExec,\r
955         IN      BOOLEAN                 bEnableAutoReport\r
956         )\r
957 {\r
958         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s BT Auto report = %s\n",  \r
959                 (bForceExec? "force to":""), ((bEnableAutoReport)? "Enabled":"Disabled")));\r
960         pCoexDm->bCurBtAutoReport = bEnableAutoReport;\r
961 \r
962         if(!bForceExec)\r
963         {\r
964                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], bPreBtAutoReport=%d, bCurBtAutoReport=%d\n", \r
965                         pCoexDm->bPreBtAutoReport, pCoexDm->bCurBtAutoReport));\r
966 \r
967                 if(pCoexDm->bPreBtAutoReport == pCoexDm->bCurBtAutoReport) \r
968                         return;\r
969         }\r
970         halbtc8192e2ant_SetBtAutoReport(pBtCoexist, pCoexDm->bCurBtAutoReport);\r
971 \r
972         pCoexDm->bPreBtAutoReport = pCoexDm->bCurBtAutoReport;\r
973 }\r
974 \r
975 VOID\r
976 halbtc8192e2ant_FwDacSwingLvl(\r
977         IN      PBTC_COEXIST            pBtCoexist,\r
978         IN      BOOLEAN                 bForceExec,\r
979         IN      u1Byte                  fwDacSwingLvl\r
980         )\r
981 {\r
982         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s set FW Dac Swing level = %d\n",  \r
983                 (bForceExec? "force to":""), fwDacSwingLvl));\r
984         pCoexDm->curFwDacSwingLvl = fwDacSwingLvl;\r
985 \r
986         if(!bForceExec)\r
987         {\r
988                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], preFwDacSwingLvl=%d, curFwDacSwingLvl=%d\n", \r
989                         pCoexDm->preFwDacSwingLvl, pCoexDm->curFwDacSwingLvl));\r
990 \r
991                 if(pCoexDm->preFwDacSwingLvl == pCoexDm->curFwDacSwingLvl) \r
992                         return;\r
993         }\r
994 \r
995         halbtc8192e2ant_SetFwDacSwingLevel(pBtCoexist, pCoexDm->curFwDacSwingLvl);\r
996 \r
997         pCoexDm->preFwDacSwingLvl = pCoexDm->curFwDacSwingLvl;\r
998 }\r
999 \r
1000 VOID\r
1001 halbtc8192e2ant_SetSwRfRxLpfCorner(\r
1002         IN      PBTC_COEXIST            pBtCoexist,\r
1003         IN      BOOLEAN                 bRxRfShrinkOn\r
1004         )\r
1005 {\r
1006         if(bRxRfShrinkOn)\r
1007         {\r
1008                 //Shrink RF Rx LPF corner\r
1009                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Shrink RF Rx LPF corner!!\n"));\r
1010                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff, 0xffffc);\r
1011         }\r
1012         else\r
1013         {\r
1014                 //Resume RF Rx LPF corner\r
1015                 // After initialized, we can use pCoexDm->btRf0x1eBackup\r
1016                 if(pBtCoexist->bInitilized)\r
1017                 {\r
1018                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Resume RF Rx LPF corner!!\n"));\r
1019                         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff, pCoexDm->btRf0x1eBackup);\r
1020                 }\r
1021         }\r
1022 }\r
1023 \r
1024 VOID\r
1025 halbtc8192e2ant_RfShrink(\r
1026         IN      PBTC_COEXIST            pBtCoexist,\r
1027         IN      BOOLEAN                 bForceExec,\r
1028         IN      BOOLEAN                 bRxRfShrinkOn\r
1029         )\r
1030 {\r
1031         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW, ("[BTCoex], %s turn Rx RF Shrink = %s\n",  \r
1032                 (bForceExec? "force to":""), ((bRxRfShrinkOn)? "ON":"OFF")));\r
1033         pCoexDm->bCurRfRxLpfShrink = bRxRfShrinkOn;\r
1034 \r
1035         if(!bForceExec)\r
1036         {\r
1037                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL, ("[BTCoex], bPreRfRxLpfShrink=%d, bCurRfRxLpfShrink=%d\n", \r
1038                         pCoexDm->bPreRfRxLpfShrink, pCoexDm->bCurRfRxLpfShrink));\r
1039 \r
1040                 if(pCoexDm->bPreRfRxLpfShrink == pCoexDm->bCurRfRxLpfShrink) \r
1041                         return;\r
1042         }\r
1043         halbtc8192e2ant_SetSwRfRxLpfCorner(pBtCoexist, pCoexDm->bCurRfRxLpfShrink);\r
1044 \r
1045         pCoexDm->bPreRfRxLpfShrink = pCoexDm->bCurRfRxLpfShrink;\r
1046 }\r
1047 \r
1048 VOID\r
1049 halbtc8192e2ant_SetSwPenaltyTxRateAdaptive(\r
1050         IN      PBTC_COEXIST            pBtCoexist,\r
1051         IN      BOOLEAN                 bLowPenaltyRa\r
1052         )\r
1053 {\r
1054         u1Byte                  H2C_Parameter[6] ={0};\r
1055         \r
1056         H2C_Parameter[0] = 0x6; // opCode, 0x6= Retry_Penalty\r
1057 \r
1058         if(bLowPenaltyRa)\r
1059         {\r
1060                 H2C_Parameter[1] |= BIT0;\r
1061                 H2C_Parameter[2] = 0x00;  //normal rate except MCS7/6/5, OFDM54/48/36\r
1062                 H2C_Parameter[3] = 0xf7;  //MCS7 or OFDM54\r
1063                 H2C_Parameter[4] = 0xf8;  //MCS6 or OFDM48\r
1064                 H2C_Parameter[5] = 0xf9;        //MCS5 or OFDM36        \r
1065         }\r
1066 \r
1067         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], set WiFi Low-Penalty Retry: %s", \r
1068                 (bLowPenaltyRa? "ON!!":"OFF!!")) );\r
1069 \r
1070         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x69, 6, H2C_Parameter);\r
1071 }\r
1072 \r
1073 VOID\r
1074 halbtc8192e2ant_LowPenaltyRa(\r
1075         IN      PBTC_COEXIST            pBtCoexist,\r
1076         IN      BOOLEAN                 bForceExec,\r
1077         IN      BOOLEAN                 bLowPenaltyRa\r
1078         )\r
1079 {\r
1080         //return;\r
1081         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW, ("[BTCoex], %s turn LowPenaltyRA = %s\n",  \r
1082                 (bForceExec? "force to":""), ((bLowPenaltyRa)? "ON":"OFF")));\r
1083         pCoexDm->bCurLowPenaltyRa = bLowPenaltyRa;\r
1084 \r
1085         if(!bForceExec)\r
1086         {\r
1087                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL, ("[BTCoex], bPreLowPenaltyRa=%d, bCurLowPenaltyRa=%d\n", \r
1088                         pCoexDm->bPreLowPenaltyRa, pCoexDm->bCurLowPenaltyRa));\r
1089 \r
1090                 if(pCoexDm->bPreLowPenaltyRa == pCoexDm->bCurLowPenaltyRa) \r
1091                         return;\r
1092         }\r
1093         halbtc8192e2ant_SetSwPenaltyTxRateAdaptive(pBtCoexist, pCoexDm->bCurLowPenaltyRa);\r
1094 \r
1095         pCoexDm->bPreLowPenaltyRa = pCoexDm->bCurLowPenaltyRa;\r
1096 }\r
1097 \r
1098 VOID\r
1099 halbtc8192e2ant_SetDacSwingReg(\r
1100         IN      PBTC_COEXIST            pBtCoexist,\r
1101         IN      u4Byte                  level\r
1102         )\r
1103 {\r
1104         u1Byte  val=(u1Byte)level;\r
1105 \r
1106         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Write SwDacSwing = 0x%x\n", level));\r
1107         pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0x883, 0x3e, val);\r
1108 }\r
1109 \r
1110 VOID\r
1111 halbtc8192e2ant_SetSwFullTimeDacSwing(\r
1112         IN      PBTC_COEXIST            pBtCoexist,\r
1113         IN      BOOLEAN                 bSwDacSwingOn,\r
1114         IN      u4Byte                  swDacSwingLvl\r
1115         )\r
1116 {\r
1117         if(bSwDacSwingOn)\r
1118         {\r
1119                 halbtc8192e2ant_SetDacSwingReg(pBtCoexist, swDacSwingLvl);\r
1120         }\r
1121         else\r
1122         {\r
1123                 halbtc8192e2ant_SetDacSwingReg(pBtCoexist, 0x18);\r
1124         }\r
1125 }\r
1126 \r
1127 \r
1128 VOID\r
1129 halbtc8192e2ant_DacSwing(\r
1130         IN      PBTC_COEXIST            pBtCoexist,\r
1131         IN      BOOLEAN                 bForceExec,\r
1132         IN      BOOLEAN                 bDacSwingOn,\r
1133         IN      u4Byte                  dacSwingLvl\r
1134         )\r
1135 {\r
1136         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW, ("[BTCoex], %s turn DacSwing=%s, dacSwingLvl=0x%x\n",  \r
1137                 (bForceExec? "force to":""), ((bDacSwingOn)? "ON":"OFF"), dacSwingLvl));\r
1138         pCoexDm->bCurDacSwingOn = bDacSwingOn;\r
1139         pCoexDm->curDacSwingLvl = dacSwingLvl;\r
1140 \r
1141         if(!bForceExec)\r
1142         {\r
1143                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL, ("[BTCoex], bPreDacSwingOn=%d, preDacSwingLvl=0x%x, bCurDacSwingOn=%d, curDacSwingLvl=0x%x\n", \r
1144                         pCoexDm->bPreDacSwingOn, pCoexDm->preDacSwingLvl,\r
1145                         pCoexDm->bCurDacSwingOn, pCoexDm->curDacSwingLvl));\r
1146 \r
1147                 if( (pCoexDm->bPreDacSwingOn == pCoexDm->bCurDacSwingOn) &&\r
1148                         (pCoexDm->preDacSwingLvl == pCoexDm->curDacSwingLvl) )\r
1149                         return;\r
1150         }\r
1151         delay_ms(30);\r
1152         halbtc8192e2ant_SetSwFullTimeDacSwing(pBtCoexist, bDacSwingOn, dacSwingLvl);\r
1153 \r
1154         pCoexDm->bPreDacSwingOn = pCoexDm->bCurDacSwingOn;\r
1155         pCoexDm->preDacSwingLvl = pCoexDm->curDacSwingLvl;\r
1156 }\r
1157 \r
1158 VOID\r
1159 halbtc8192e2ant_SetAdcBackOff(\r
1160         IN      PBTC_COEXIST            pBtCoexist,\r
1161         IN      BOOLEAN                 bAdcBackOff\r
1162         )\r
1163 {\r
1164         if(bAdcBackOff)\r
1165         {\r
1166                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], BB BackOff Level On!\n"));\r
1167                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xc05, 0x30, 0x3);\r
1168         }\r
1169         else\r
1170         {\r
1171                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], BB BackOff Level Off!\n"));\r
1172                 pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xc05, 0x30, 0x1);\r
1173         }\r
1174 }\r
1175 \r
1176 VOID\r
1177 halbtc8192e2ant_AdcBackOff(\r
1178         IN      PBTC_COEXIST            pBtCoexist,\r
1179         IN      BOOLEAN                 bForceExec,\r
1180         IN      BOOLEAN                 bAdcBackOff\r
1181         )\r
1182 {\r
1183         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW, ("[BTCoex], %s turn AdcBackOff = %s\n",  \r
1184                 (bForceExec? "force to":""), ((bAdcBackOff)? "ON":"OFF")));\r
1185         pCoexDm->bCurAdcBackOff = bAdcBackOff;\r
1186 \r
1187         if(!bForceExec)\r
1188         {\r
1189                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL, ("[BTCoex], bPreAdcBackOff=%d, bCurAdcBackOff=%d\n", \r
1190                         pCoexDm->bPreAdcBackOff, pCoexDm->bCurAdcBackOff));\r
1191 \r
1192                 if(pCoexDm->bPreAdcBackOff == pCoexDm->bCurAdcBackOff) \r
1193                         return;\r
1194         }\r
1195         halbtc8192e2ant_SetAdcBackOff(pBtCoexist, pCoexDm->bCurAdcBackOff);\r
1196 \r
1197         pCoexDm->bPreAdcBackOff = pCoexDm->bCurAdcBackOff;\r
1198 }\r
1199 \r
1200 VOID\r
1201 halbtc8192e2ant_SetAgcTable(\r
1202         IN      PBTC_COEXIST            pBtCoexist,\r
1203         IN      BOOLEAN                 bAgcTableEn\r
1204         )\r
1205 {\r
1206         u1Byte          rssiAdjustVal=0;\r
1207 \r
1208         //=================BB AGC Gain Table\r
1209         if(bAgcTableEn)\r
1210         {\r
1211                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], BB Agc Table On!\n"));\r
1212                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x0a1A0001);\r
1213                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x091B0001);\r
1214                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x081C0001);\r
1215                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x071D0001);\r
1216                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x061E0001);\r
1217                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0x051F0001);\r
1218         }\r
1219         else\r
1220         {\r
1221                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], BB Agc Table Off!\n"));\r
1222                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xaa1A0001);\r
1223                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa91B0001);\r
1224                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa81C0001);\r
1225                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa71D0001);\r
1226                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa61E0001);\r
1227                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78, 0xa51F0001);\r
1228         }\r
1229         \r
1230 #if 0   \r
1231         //=================RF Gain\r
1232         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xef, 0xfffff, 0x02000);\r
1233         if(bAgcTableEn)\r
1234         {\r
1235                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Agc Table On!\n"));\r
1236                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x3b, 0xfffff, 0x38fff);\r
1237                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x3b, 0xfffff, 0x38ffe);\r
1238         }\r
1239         else\r
1240         {\r
1241                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Agc Table Off!\n"));\r
1242                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x3b, 0xfffff, 0x380c3);\r
1243                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x3b, 0xfffff, 0x28ce6);\r
1244         }\r
1245         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xef, 0xfffff, 0x0);\r
1246 \r
1247         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xed, 0xfffff, 0x1);\r
1248         if(bAgcTableEn)\r
1249         {\r
1250                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Agc Table On!\n"));\r
1251                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x40, 0xfffff, 0x38fff);\r
1252                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x40, 0xfffff, 0x38ffe);\r
1253         }\r
1254         else\r
1255         {\r
1256                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], Agc Table Off!\n"));\r
1257                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x40, 0xfffff, 0x380c3);\r
1258                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x40, 0xfffff, 0x28ce6);\r
1259         }\r
1260         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0xed, 0xfffff, 0x0);\r
1261 \r
1262         // set rssiAdjustVal for wifi module.\r
1263         if(bAgcTableEn)\r
1264         {\r
1265                 rssiAdjustVal = 8;\r
1266         }\r
1267         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON, &rssiAdjustVal);\r
1268 #endif\r
1269 \r
1270 }\r
1271 \r
1272 VOID\r
1273 halbtc8192e2ant_AgcTable(\r
1274         IN      PBTC_COEXIST            pBtCoexist,\r
1275         IN      BOOLEAN                 bForceExec,\r
1276         IN      BOOLEAN                 bAgcTableEn\r
1277         )\r
1278 {\r
1279         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW, ("[BTCoex], %s %s Agc Table\n",  \r
1280                 (bForceExec? "force to":""), ((bAgcTableEn)? "Enable":"Disable")));\r
1281         pCoexDm->bCurAgcTableEn = bAgcTableEn;\r
1282 \r
1283         if(!bForceExec)\r
1284         {\r
1285                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL, ("[BTCoex], bPreAgcTableEn=%d, bCurAgcTableEn=%d\n", \r
1286                         pCoexDm->bPreAgcTableEn, pCoexDm->bCurAgcTableEn));\r
1287 \r
1288                 if(pCoexDm->bPreAgcTableEn == pCoexDm->bCurAgcTableEn) \r
1289                         return;\r
1290         }\r
1291         halbtc8192e2ant_SetAgcTable(pBtCoexist, bAgcTableEn);\r
1292 \r
1293         pCoexDm->bPreAgcTableEn = pCoexDm->bCurAgcTableEn;\r
1294 }\r
1295 \r
1296 VOID\r
1297 halbtc8192e2ant_SetCoexTable(\r
1298         IN      PBTC_COEXIST    pBtCoexist,\r
1299         IN      u4Byte          val0x6c0,\r
1300         IN      u4Byte          val0x6c4,\r
1301         IN      u4Byte          val0x6c8,\r
1302         IN      u1Byte          val0x6cc\r
1303         )\r
1304 {\r
1305         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6c0=0x%x\n", val0x6c0));\r
1306         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c0, val0x6c0);\r
1307 \r
1308         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6c4=0x%x\n", val0x6c4));\r
1309         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c4, val0x6c4);\r
1310 \r
1311         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6c8=0x%x\n", val0x6c8));\r
1312         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c8, val0x6c8);\r
1313 \r
1314         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_EXEC, ("[BTCoex], set coex table, set 0x6cc=0x%x\n", val0x6cc));\r
1315         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cc, val0x6cc);\r
1316 }\r
1317 \r
1318 VOID\r
1319 halbtc8192e2ant_CoexTable(\r
1320         IN      PBTC_COEXIST            pBtCoexist,\r
1321         IN      BOOLEAN                 bForceExec,\r
1322         IN      u4Byte                  val0x6c0,\r
1323         IN      u4Byte                  val0x6c4,\r
1324         IN      u4Byte                  val0x6c8,\r
1325         IN      u1Byte                  val0x6cc\r
1326         )\r
1327 {\r
1328         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW, ("[BTCoex], %s write Coex Table 0x6c0=0x%x, 0x6c4=0x%x, 0x6c8=0x%x, 0x6cc=0x%x\n", \r
1329                 (bForceExec? "force to":""), val0x6c0, val0x6c4, val0x6c8, val0x6cc));\r
1330         pCoexDm->curVal0x6c0 = val0x6c0;\r
1331         pCoexDm->curVal0x6c4 = val0x6c4;\r
1332         pCoexDm->curVal0x6c8 = val0x6c8;\r
1333         pCoexDm->curVal0x6cc = val0x6cc;\r
1334 \r
1335         if(!bForceExec)\r
1336         {\r
1337                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL, ("[BTCoex], preVal0x6c0=0x%x, preVal0x6c4=0x%x, preVal0x6c8=0x%x, preVal0x6cc=0x%x !!\n", \r
1338                         pCoexDm->preVal0x6c0, pCoexDm->preVal0x6c4, pCoexDm->preVal0x6c8, pCoexDm->preVal0x6cc));\r
1339                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_SW_DETAIL, ("[BTCoex], curVal0x6c0=0x%x, curVal0x6c4=0x%x, curVal0x6c8=0x%x, curVal0x6cc=0x%x !!\n", \r
1340                         pCoexDm->curVal0x6c0, pCoexDm->curVal0x6c4, pCoexDm->curVal0x6c8, pCoexDm->curVal0x6cc));\r
1341         \r
1342                 if( (pCoexDm->preVal0x6c0 == pCoexDm->curVal0x6c0) &&\r
1343                         (pCoexDm->preVal0x6c4 == pCoexDm->curVal0x6c4) &&\r
1344                         (pCoexDm->preVal0x6c8 == pCoexDm->curVal0x6c8) &&\r
1345                         (pCoexDm->preVal0x6cc == pCoexDm->curVal0x6cc) )\r
1346                         return;\r
1347         }\r
1348         halbtc8192e2ant_SetCoexTable(pBtCoexist, val0x6c0, val0x6c4, val0x6c8, val0x6cc);\r
1349 \r
1350         pCoexDm->preVal0x6c0 = pCoexDm->curVal0x6c0;\r
1351         pCoexDm->preVal0x6c4 = pCoexDm->curVal0x6c4;\r
1352         pCoexDm->preVal0x6c8 = pCoexDm->curVal0x6c8;\r
1353         pCoexDm->preVal0x6cc = pCoexDm->curVal0x6cc;\r
1354 }\r
1355 \r
1356 VOID\r
1357 halbtc8192e2ant_CoexTableWithType(\r
1358         IN      PBTC_COEXIST            pBtCoexist,\r
1359         IN      BOOLEAN                         bForceExec,\r
1360         IN      u1Byte                          type\r
1361         )\r
1362 {\r
1363         switch(type)\r
1364         {\r
1365                 case 0:\r
1366                         halbtc8192e2ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x5a5a5a5a, 0xffffff, 0x3);\r
1367                         break;\r
1368                 case 1:\r
1369                         halbtc8192e2ant_CoexTable(pBtCoexist, bForceExec, 0x5a5a5a5a, 0x5a5a5a5a, 0xffffff, 0x3);\r
1370                         break;\r
1371                 case 2:\r
1372                         halbtc8192e2ant_CoexTable(pBtCoexist, bForceExec, 0x55555555, 0x5ffb5ffb, 0xffffff, 0x3);\r
1373                         break;\r
1374                 case 3:\r
1375                         halbtc8192e2ant_CoexTable(pBtCoexist, bForceExec, 0x5fdf5fdf, 0x5fdb5fdb, 0xffffff, 0x3);\r
1376                         break;\r
1377                 case 4:\r
1378                         halbtc8192e2ant_CoexTable(pBtCoexist, bForceExec, 0xdfffdfff, 0x5ffb5ffb, 0xffffff, 0x3);\r
1379                         break;\r
1380 \r
1381                 default:\r
1382                         break;\r
1383         }\r
1384 }\r
1385 \r
1386 VOID\r
1387 halbtc8192e2ant_SetFwIgnoreWlanAct(\r
1388         IN      PBTC_COEXIST            pBtCoexist,\r
1389         IN      BOOLEAN                 bEnable\r
1390         )\r
1391 {\r
1392         u1Byte                  H2C_Parameter[1] ={0};\r
1393                 \r
1394         if(bEnable)\r
1395         {\r
1396                 H2C_Parameter[0] |= BIT0;               // function enable\r
1397         }\r
1398         \r
1399         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63=0x%x\n", \r
1400                 H2C_Parameter[0]));\r
1401 \r
1402         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x63, 1, H2C_Parameter);\r
1403 }\r
1404 \r
1405 VOID\r
1406 halbtc8192e2ant_IgnoreWlanAct(\r
1407         IN      PBTC_COEXIST            pBtCoexist,\r
1408         IN      BOOLEAN                 bForceExec,\r
1409         IN      BOOLEAN                 bEnable\r
1410         )\r
1411 {\r
1412         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s turn Ignore WlanAct %s\n", \r
1413                 (bForceExec? "force to":""), (bEnable? "ON":"OFF")));\r
1414         pCoexDm->bCurIgnoreWlanAct = bEnable;\r
1415 \r
1416         if(!bForceExec)\r
1417         {\r
1418                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], bPreIgnoreWlanAct = %d, bCurIgnoreWlanAct = %d!!\n", \r
1419                         pCoexDm->bPreIgnoreWlanAct, pCoexDm->bCurIgnoreWlanAct));\r
1420 \r
1421                 if(pCoexDm->bPreIgnoreWlanAct == pCoexDm->bCurIgnoreWlanAct)\r
1422                         return;\r
1423         }\r
1424         halbtc8192e2ant_SetFwIgnoreWlanAct(pBtCoexist, bEnable);\r
1425 \r
1426         pCoexDm->bPreIgnoreWlanAct = pCoexDm->bCurIgnoreWlanAct;\r
1427 }\r
1428 \r
1429 VOID\r
1430 halbtc8192e2ant_SetFwPstdma(\r
1431         IN      PBTC_COEXIST            pBtCoexist,\r
1432         IN      u1Byte                  byte1,\r
1433         IN      u1Byte                  byte2,\r
1434         IN      u1Byte                  byte3,\r
1435         IN      u1Byte                  byte4,\r
1436         IN      u1Byte                  byte5\r
1437         )\r
1438 {\r
1439         u1Byte                  H2C_Parameter[5] ={0};\r
1440 \r
1441         H2C_Parameter[0] = byte1;       \r
1442         H2C_Parameter[1] = byte2;       \r
1443         H2C_Parameter[2] = byte3;\r
1444         H2C_Parameter[3] = byte4;\r
1445         H2C_Parameter[4] = byte5;\r
1446 \r
1447         pCoexDm->psTdmaPara[0] = byte1;\r
1448         pCoexDm->psTdmaPara[1] = byte2;\r
1449         pCoexDm->psTdmaPara[2] = byte3;\r
1450         pCoexDm->psTdmaPara[3] = byte4;\r
1451         pCoexDm->psTdmaPara[4] = byte5;\r
1452         \r
1453         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], FW write 0x60(5bytes)=0x%x%08x\n", \r
1454                 H2C_Parameter[0], \r
1455                 H2C_Parameter[1]<<24|H2C_Parameter[2]<<16|H2C_Parameter[3]<<8|H2C_Parameter[4]));\r
1456 \r
1457         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x60, 5, H2C_Parameter);\r
1458 }\r
1459 \r
1460 VOID\r
1461 halbtc8192e2ant_SwMechanism1(\r
1462         IN      PBTC_COEXIST    pBtCoexist,     \r
1463         IN      BOOLEAN         bShrinkRxLPF,\r
1464         IN      BOOLEAN         bLowPenaltyRA,\r
1465         IN      BOOLEAN         bLimitedDIG, \r
1466         IN      BOOLEAN         bBTLNAConstrain\r
1467         ) \r
1468 {\r
1469         /*\r
1470         u4Byte  wifiBw;\r
1471         \r
1472         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
1473         \r
1474         if(BTC_WIFI_BW_HT40 != wifiBw)  //only shrink RF Rx LPF for HT40\r
1475         {\r
1476                 if (bShrinkRxLPF)\r
1477                         bShrinkRxLPF = FALSE;\r
1478         }\r
1479         */\r
1480         \r
1481         halbtc8192e2ant_RfShrink(pBtCoexist, NORMAL_EXEC, bShrinkRxLPF);\r
1482         //halbtc8192e2ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, bLowPenaltyRA);\r
1483 }\r
1484 \r
1485 VOID\r
1486 halbtc8192e2ant_SwMechanism2(\r
1487         IN      PBTC_COEXIST    pBtCoexist,     \r
1488         IN      BOOLEAN         bAGCTableShift,\r
1489         IN      BOOLEAN         bADCBackOff,\r
1490         IN      BOOLEAN         bSWDACSwing,\r
1491         IN      u4Byte          dacSwingLvl\r
1492         ) \r
1493 {\r
1494         halbtc8192e2ant_AgcTable(pBtCoexist, NORMAL_EXEC, bAGCTableShift);\r
1495         //halbtc8192e2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, bADCBackOff);\r
1496         halbtc8192e2ant_DacSwing(pBtCoexist, NORMAL_EXEC, bSWDACSwing, dacSwingLvl);\r
1497 }\r
1498 \r
1499 VOID\r
1500 halbtc8192e2ant_SetAntPath(\r
1501         IN      PBTC_COEXIST            pBtCoexist,\r
1502         IN      u1Byte                          antPosType,\r
1503         IN      BOOLEAN                         bInitHwCfg,\r
1504         IN      BOOLEAN                         bWifiOff\r
1505         )\r
1506 {\r
1507         u4Byte                  u4Tmp=0;\r
1508         \r
1509         if(bInitHwCfg)\r
1510         {\r
1511                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x944, 0x24);\r
1512                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x930, 0x700700);                \r
1513                 if(pBtCoexist->chipInterface == BTC_INTF_USB)\r
1514                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x64, 0x30430004);\r
1515                 else\r
1516                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x64, 0x30030004);\r
1517 \r
1518                 // 0x4c[27][24]='00', Set Antenna to BB\r
1519                 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);\r
1520                 u4Tmp &= ~BIT24;\r
1521                 u4Tmp &= ~BIT27;\r
1522                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);\r
1523         }\r
1524         else if(bWifiOff)\r
1525         {\r
1526                 if(pBtCoexist->chipInterface == BTC_INTF_USB)\r
1527                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x64, 0x30430004);\r
1528                 else\r
1529                         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x64, 0x30030004);\r
1530 \r
1531                 // 0x4c[27][24]='11', Set Antenna to BT, 0x64[8:7]=0, 0x64[2]=1\r
1532                 u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x4c);\r
1533                 u4Tmp |= BIT24;\r
1534                 u4Tmp |= BIT27;\r
1535                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x4c, u4Tmp);\r
1536         }\r
1537         \r
1538         // ext switch setting\r
1539         switch(antPosType)\r
1540         {\r
1541                 case BTC_ANT_PATH_WIFI:\r
1542                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x92c, 0x4);\r
1543                         break;\r
1544                 case BTC_ANT_PATH_BT:\r
1545                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x92c, 0x20);\r
1546                         break;\r
1547                 default:\r
1548                 case BTC_ANT_PATH_PTA:\r
1549                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x92c, 0x4);\r
1550                         break;\r
1551         }\r
1552 }\r
1553 \r
1554 VOID\r
1555 halbtc8192e2ant_PsTdma(\r
1556         IN      PBTC_COEXIST            pBtCoexist,\r
1557         IN      BOOLEAN                 bForceExec,\r
1558         IN      BOOLEAN                 bTurnOn,\r
1559         IN      u1Byte                  type\r
1560         )\r
1561 {\r
1562         BOOLEAN                 bTurnOnByCnt=FALSE;\r
1563         u1Byte                  psTdmaTypeByCnt=0;\r
1564 \r
1565         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], %s turn %s PS TDMA, type=%d\n", \r
1566                 (bForceExec? "force to":""), (bTurnOn? "ON":"OFF"), type));\r
1567         pCoexDm->bCurPsTdmaOn = bTurnOn;\r
1568         pCoexDm->curPsTdma = type;\r
1569 \r
1570         if(!bForceExec)\r
1571         {\r
1572                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], bPrePsTdmaOn = %d, bCurPsTdmaOn = %d!!\n", \r
1573                         pCoexDm->bPrePsTdmaOn, pCoexDm->bCurPsTdmaOn));\r
1574                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], prePsTdma = %d, curPsTdma = %d!!\n", \r
1575                         pCoexDm->prePsTdma, pCoexDm->curPsTdma));\r
1576 \r
1577                 if( (pCoexDm->bPrePsTdmaOn == pCoexDm->bCurPsTdmaOn) &&\r
1578                         (pCoexDm->prePsTdma == pCoexDm->curPsTdma) )\r
1579                         return;\r
1580         }       \r
1581         if(bTurnOn)\r
1582         {\r
1583                 switch(type)\r
1584                 {\r
1585                         case 1:\r
1586                         default:\r
1587                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x90);\r
1588                                 break;\r
1589                         case 2:\r
1590                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0xe1, 0x90);\r
1591                                 break;\r
1592                         case 3:\r
1593                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1c, 0x3, 0xf1, 0x90);\r
1594                                 break;\r
1595                         case 4:\r
1596                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x10, 0x3, 0xf1, 0x90);\r
1597                                 break;\r
1598                         case 5:\r
1599                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0x60, 0x90);\r
1600                                 break;\r
1601                         case 6:\r
1602                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0x60, 0x90);\r
1603                                 break;\r
1604                         case 7:\r
1605                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1c, 0x3, 0x70, 0x90);\r
1606                                 break;\r
1607                         case 8: \r
1608                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xa3, 0x10, 0x3, 0x70, 0x90);\r
1609                                 break;\r
1610                         case 9: \r
1611                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x10);\r
1612                                 break;\r
1613                         case 10:        \r
1614                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0xe1, 0x10);\r
1615                                 break;\r
1616                         case 11:        \r
1617                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1c, 0x3, 0xf1, 0x10);\r
1618                                 break;\r
1619                         case 12:\r
1620                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x10, 0x3, 0xf1, 0x10);\r
1621                                 break;\r
1622                         case 13:\r
1623                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0xe0, 0x10);\r
1624                                 break;\r
1625                         case 14:\r
1626                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0xe0, 0x10);\r
1627                                 break;\r
1628                         case 15:\r
1629                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1c, 0x3, 0xf0, 0x10);\r
1630                                 break;\r
1631                         case 16:\r
1632                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x3, 0xf0, 0x10);\r
1633                                 break;\r
1634                         case 17:\r
1635                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0x61, 0x20, 0x03, 0x10, 0x10);\r
1636                                 break;\r
1637                         case 18:\r
1638                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x5, 0x5, 0xe1, 0x90);\r
1639                                 break;                  \r
1640                         case 19:\r
1641                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x25, 0xe1, 0x90);\r
1642                                 break;\r
1643                         case 20:\r
1644                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x25, 0x60, 0x90);\r
1645                                 break;\r
1646                         case 21:\r
1647                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x15, 0x03, 0x70, 0x90);\r
1648                                 break;  \r
1649                         case 71:\r
1650                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x90);\r
1651                                 break;\r
1652                 }\r
1653         }\r
1654         else\r
1655         {\r
1656                 // disable PS tdma\r
1657                 switch(type)\r
1658                 {\r
1659                         default:\r
1660                         case 0:  //ANT2PTA, 0x778=1\r
1661                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0x8, 0x0, 0x0, 0x0, 0x0);\r
1662                                 halbtc8192e2ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_PTA, FALSE, FALSE);\r
1663                                 break;\r
1664                         case 1:  //ANT2BT, 0x778=3\r
1665                                 halbtc8192e2ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x8, 0x0);\r
1666                                 delay_ms(5);\r
1667                                 halbtc8192e2ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FALSE, FALSE);\r
1668                                 break;\r
1669 \r
1670                 }\r
1671         }\r
1672 \r
1673         // update pre state\r
1674         pCoexDm->bPrePsTdmaOn = pCoexDm->bCurPsTdmaOn;\r
1675         pCoexDm->prePsTdma = pCoexDm->curPsTdma;\r
1676 }\r
1677 \r
1678 VOID\r
1679 halbtc8192e2ant_SetSwitchSsType(\r
1680         IN      PBTC_COEXIST            pBtCoexist,\r
1681         IN      u1Byte                          ssType\r
1682         )\r
1683 {\r
1684         u1Byte  mimoPs=BTC_MIMO_PS_DYNAMIC;\r
1685         u4Byte  disRaMask=0x0;\r
1686 \r
1687         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], REAL set SS Type = %d\n", ssType));\r
1688         \r
1689         disRaMask = halbtc8192e2ant_DecideRaMask(pBtCoexist, ssType, pCoexDm->curRaMaskType);\r
1690         halbtc8192e2ant_UpdateRaMask(pBtCoexist, FORCE_EXEC, disRaMask);\r
1691         \r
1692         if(ssType == 1)\r
1693         {               \r
1694                 halbtc8192e2ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 1);\r
1695                 // switch ofdm path\r
1696                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0xc04, 0x11);\r
1697                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0xd04, 0x1);\r
1698                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x90c, 0x81111111);\r
1699                 // switch cck patch\r
1700                 //Jenyu suggest to remove 0xe77 this line for tx issue\r
1701                 //pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xe77, 0x4, 0x1);\r
1702                 //pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0xa07, 0x81);\r
1703                 mimoPs=BTC_MIMO_PS_STATIC;\r
1704         }\r
1705         else if(ssType == 2)\r
1706         {\r
1707                 halbtc8192e2ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 0);\r
1708                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0xc04, 0x33);\r
1709                 pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0xd04, 0x3);\r
1710                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x90c, 0x81121313);\r
1711                 //Jenyu suggest to remove 0xe77 this line for tx issue\r
1712                 //pBtCoexist->fBtcWrite1ByteBitMask(pBtCoexist, 0xe77, 0x4, 0x0);\r
1713                 //pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0xa07, 0x41);\r
1714                 mimoPs=BTC_MIMO_PS_DYNAMIC;\r
1715         }\r
1716         \r
1717         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_SEND_MIMO_PS, &mimoPs);     // set rx 1ss or 2ss\r
1718 }\r
1719 \r
1720 VOID\r
1721 halbtc8192e2ant_SwitchSsType(\r
1722         IN      PBTC_COEXIST            pBtCoexist,\r
1723         IN      BOOLEAN                         bForceExec,\r
1724         IN      u1Byte                          newSsType\r
1725         )\r
1726 {\r
1727         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], %s Switch SS Type = %d\n",  \r
1728                 (bForceExec? "force to":""), newSsType));\r
1729         pCoexDm->curSsType = newSsType;\r
1730 \r
1731         if(!bForceExec)\r
1732         {\r
1733                 if(pCoexDm->preSsType == pCoexDm->curSsType) \r
1734                         return;\r
1735         }\r
1736         halbtc8192e2ant_SetSwitchSsType(pBtCoexist, pCoexDm->curSsType);\r
1737 \r
1738         pCoexDm->preSsType = pCoexDm->curSsType;\r
1739 }\r
1740 \r
1741 VOID\r
1742 halbtc8192e2ant_CoexAllOff(\r
1743         IN      PBTC_COEXIST            pBtCoexist\r
1744         )\r
1745 {\r
1746         // fw all off\r
1747         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);\r
1748         halbtc8192e2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
1749         halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
1750 \r
1751         // sw all off\r
1752         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
1753         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
1754 \r
1755         // hw all off\r
1756         halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
1757 }\r
1758 \r
1759 VOID\r
1760 halbtc8192e2ant_InitCoexDm(\r
1761         IN      PBTC_COEXIST            pBtCoexist\r
1762         )\r
1763 {       \r
1764         // force to reset coex mechanism\r
1765         \r
1766         halbtc8192e2ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 1);\r
1767         halbtc8192e2ant_FwDacSwingLvl(pBtCoexist, FORCE_EXEC, 6);\r
1768         halbtc8192e2ant_DecBtPwr(pBtCoexist, FORCE_EXEC, 0);\r
1769 \r
1770         halbtc8192e2ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);\r
1771         halbtc8192e2ant_SwitchSsType(pBtCoexist, FORCE_EXEC, 2);\r
1772         \r
1773         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
1774         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
1775 }\r
1776 \r
1777 VOID\r
1778 halbtc8192e2ant_ActionBtInquiry(\r
1779         IN      PBTC_COEXIST            pBtCoexist\r
1780         )\r
1781 {\r
1782         BOOLEAN bLowPwrDisable=TRUE;\r
1783         \r
1784         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
1785 \r
1786         halbtc8192e2ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 1);\r
1787 \r
1788         halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
1789         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
1790         halbtc8192e2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
1791         halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
1792 \r
1793         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
1794         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
1795 }\r
1796 \r
1797 BOOLEAN\r
1798 halbtc8192e2ant_IsCommonAction(\r
1799         IN      PBTC_COEXIST            pBtCoexist\r
1800         )\r
1801 {\r
1802         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
1803         BOOLEAN                 bCommon=FALSE, bWifiConnected=FALSE, bWifiBusy=FALSE;\r
1804         BOOLEAN                 bBtHsOn=FALSE, bLowPwrDisable=FALSE;\r
1805 \r
1806         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
1807         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
1808         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
1809 \r
1810         if(pBtLinkInfo->bScoExist || pBtLinkInfo->bHidExist)\r
1811         {\r
1812                 halbtc8192e2ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 1, 0, 0, 0);\r
1813         }\r
1814         else\r
1815         {\r
1816                 halbtc8192e2ant_LimitedTx(pBtCoexist, NORMAL_EXEC, 0, 0, 0, 0);\r
1817         }\r
1818 \r
1819         if(!bWifiConnected)\r
1820         {\r
1821                 bLowPwrDisable = FALSE;\r
1822                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
1823                 \r
1824                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi non-connected idle!!\n"));\r
1825 \r
1826                 if( (BT_8192E_2ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus) ||\r
1827                         (BT_8192E_2ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus) )\r
1828                 {\r
1829                         halbtc8192e2ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 2);\r
1830                         halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 1);\r
1831                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
1832                 }\r
1833                 else\r
1834                 {                       \r
1835                         halbtc8192e2ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 1);\r
1836                         halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
1837                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);\r
1838                 }\r
1839                 \r
1840                 halbtc8192e2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
1841                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
1842                 \r
1843                 halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
1844                 halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
1845 \r
1846                 bCommon = TRUE;\r
1847         }\r
1848         else\r
1849         {\r
1850                 if(BT_8192E_2ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)\r
1851                 {\r
1852                         bLowPwrDisable = FALSE;\r
1853                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
1854 \r
1855                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi connected + BT non connected-idle!!\n"));\r
1856 \r
1857                         halbtc8192e2ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 2);\r
1858                         halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 1);\r
1859                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);              \r
1860                         halbtc8192e2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
1861                         halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
1862 \r
1863                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
1864                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
1865 \r
1866                         bCommon = TRUE;\r
1867                 }\r
1868                 else if(BT_8192E_2ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus)\r
1869                 {\r
1870                         bLowPwrDisable = TRUE;\r
1871                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
1872 \r
1873                         if(bBtHsOn)\r
1874                                 return FALSE;\r
1875                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi connected + BT connected-idle!!\n"));\r
1876 \r
1877                         halbtc8192e2ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 2);\r
1878                         halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 1);\r
1879                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
1880                         halbtc8192e2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
1881                         halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
1882 \r
1883                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
1884                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
1885 \r
1886                         bCommon = TRUE;\r
1887                 }\r
1888                 else\r
1889                 {\r
1890                         bLowPwrDisable = TRUE;\r
1891                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
1892 \r
1893                         if(bWifiBusy)\r
1894                         {\r
1895                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi Connected-Busy + BT Busy!!\n"));\r
1896                                 bCommon = FALSE;\r
1897                         }\r
1898                         else\r
1899                         {\r
1900                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Wifi Connected-Idle + BT Busy!!\n"));\r
1901 \r
1902                                 halbtc8192e2ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 1);\r
1903                                 halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
1904                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 21);\r
1905                                 halbtc8192e2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);      \r
1906                                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
1907                                 halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
1908                                 halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
1909                                 bCommon = TRUE;\r
1910                         }\r
1911                 }       \r
1912         }\r
1913 \r
1914         return bCommon;\r
1915 }\r
1916 VOID\r
1917 halbtc8192e2ant_TdmaDurationAdjust(\r
1918         IN      PBTC_COEXIST            pBtCoexist,\r
1919         IN      BOOLEAN                 bScoHid,\r
1920         IN      BOOLEAN                 bTxPause,\r
1921         IN      u1Byte                  maxInterval\r
1922         )\r
1923 {\r
1924         static s4Byte           up,dn,m,n,WaitCount;\r
1925         s4Byte                  result;   //0: no change, +1: increase WiFi duration, -1: decrease WiFi duration\r
1926         u1Byte                  retryCount=0;\r
1927 \r
1928         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW, ("[BTCoex], TdmaDurationAdjust()\n"));\r
1929 \r
1930         if(!pCoexDm->bAutoTdmaAdjust)\r
1931         {\r
1932                 pCoexDm->bAutoTdmaAdjust = TRUE;\r
1933                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], first run TdmaDurationAdjust()!!\n"));\r
1934                 {\r
1935                         if(bScoHid)\r
1936                         {\r
1937                                 if(bTxPause)\r
1938                                 {\r
1939                                         if(maxInterval == 1)\r
1940                                         {\r
1941                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);\r
1942                                                 pCoexDm->psTdmaDuAdjType = 13;  \r
1943                                         }\r
1944                                         else if(maxInterval == 2)\r
1945                                         {\r
1946                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
1947                                                 pCoexDm->psTdmaDuAdjType = 14;  \r
1948                                         }\r
1949                                         else if(maxInterval == 3)\r
1950                                         {\r
1951                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
1952                                                 pCoexDm->psTdmaDuAdjType = 15;  \r
1953                                         }\r
1954                                         else\r
1955                                         {\r
1956                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
1957                                                 pCoexDm->psTdmaDuAdjType = 15;\r
1958                                         }\r
1959                                 }\r
1960                                 else\r
1961                                 {\r
1962                                         if(maxInterval == 1)\r
1963                                         {\r
1964                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
1965                                                 pCoexDm->psTdmaDuAdjType = 9;   \r
1966                                         }\r
1967                                         else if(maxInterval == 2)\r
1968                                         {\r
1969                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
1970                                                 pCoexDm->psTdmaDuAdjType = 10;  \r
1971                                         }\r
1972                                         else if(maxInterval == 3)\r
1973                                         {\r
1974                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
1975                                                 pCoexDm->psTdmaDuAdjType = 11;\r
1976                                         }\r
1977                                         else\r
1978                                         {\r
1979                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
1980                                                 pCoexDm->psTdmaDuAdjType = 11;\r
1981                                         }\r
1982                                 }\r
1983                         }\r
1984                         else\r
1985                         {\r
1986                                 if(bTxPause)\r
1987                                 {\r
1988                                         if(maxInterval == 1)\r
1989                                         {\r
1990                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
1991                                                 pCoexDm->psTdmaDuAdjType = 5;   \r
1992                                         }\r
1993                                         else if(maxInterval == 2)\r
1994                                         {\r
1995                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
1996                                                 pCoexDm->psTdmaDuAdjType = 6;   \r
1997                                         }\r
1998                                         else if(maxInterval == 3)\r
1999                                         {\r
2000                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2001                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2002                                         }\r
2003                                         else\r
2004                                         {\r
2005                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2006                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2007                                         }\r
2008                                 }\r
2009                                 else\r
2010                                 {\r
2011                                         if(maxInterval == 1)\r
2012                                         {\r
2013                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
2014                                                 pCoexDm->psTdmaDuAdjType = 1;   \r
2015                                         }\r
2016                                         else if(maxInterval == 2)\r
2017                                         {\r
2018                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2019                                                 pCoexDm->psTdmaDuAdjType = 2;   \r
2020                                         }\r
2021                                         else if(maxInterval == 3)\r
2022                                         {\r
2023                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2024                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2025                                         }\r
2026                                         else\r
2027                                         {\r
2028                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2029                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2030                                         }\r
2031                                 }\r
2032                         }\r
2033                 }\r
2034                 //============\r
2035                 up = 0;\r
2036                 dn = 0;\r
2037                 m = 1;\r
2038                 n= 3;\r
2039                 result = 0;\r
2040                 WaitCount = 0;\r
2041         }\r
2042         else\r
2043         {\r
2044                 //accquire the BT TRx retry count from BT_Info byte2\r
2045                 retryCount = pCoexSta->btRetryCnt;\r
2046                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], retryCount = %d\n", retryCount));\r
2047                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], up=%d, dn=%d, m=%d, n=%d, WaitCount=%d\n", \r
2048                         up, dn, m, n, WaitCount));\r
2049                 result = 0;\r
2050                 WaitCount++; \r
2051                   \r
2052                 if(retryCount == 0)  // no retry in the last 2-second duration\r
2053                 {\r
2054                         up++;\r
2055                         dn--;\r
2056 \r
2057                         if (dn <= 0)\r
2058                                 dn = 0;                          \r
2059 \r
2060                         if(up >= n)     // if ³sÄò n ­Ó2¬í retry count¬°0, «h½Õ¼eWiFi duration\r
2061                         {\r
2062                                 WaitCount = 0; \r
2063                                 n = 3;\r
2064                                 up = 0;\r
2065                                 dn = 0;\r
2066                                 result = 1; \r
2067                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], Increase wifi duration!!\n"));\r
2068                         }\r
2069                 }\r
2070                 else if (retryCount <= 3)       // <=3 retry in the last 2-second duration\r
2071                 {\r
2072                         up--; \r
2073                         dn++;\r
2074 \r
2075                         if (up <= 0)\r
2076                                 up = 0;\r
2077 \r
2078                         if (dn == 2)    // if ³sÄò 2 ­Ó2¬í retry count< 3, «h½Õ¯¶WiFi duration\r
2079                         {\r
2080                                 if (WaitCount <= 2)\r
2081                                         m++; // ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^\r
2082                                 else\r
2083                                         m = 1;\r
2084 \r
2085                                 if ( m >= 20) //m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration.\r
2086                                         m = 20;\r
2087 \r
2088                                 n = 3*m;\r
2089                                 up = 0;\r
2090                                 dn = 0;\r
2091                                 WaitCount = 0;\r
2092                                 result = -1; \r
2093                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], Decrease wifi duration for retryCounter<3!!\n"));\r
2094                         }\r
2095                 }\r
2096                 else  //retry count > 3, ¥u­n1¦¸ retry count > 3, «h½Õ¯¶WiFi duration\r
2097                 {\r
2098                         if (WaitCount == 1)\r
2099                                 m++; // ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^\r
2100                         else\r
2101                                 m = 1;\r
2102 \r
2103                         if ( m >= 20) //m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration.\r
2104                                 m = 20;\r
2105 \r
2106                         n = 3*m;\r
2107                         up = 0;\r
2108                         dn = 0;\r
2109                         WaitCount = 0; \r
2110                         result = -1;\r
2111                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], Decrease wifi duration for retryCounter>3!!\n"));\r
2112                 }\r
2113 \r
2114                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], max Interval = %d\n", maxInterval));\r
2115                 if(maxInterval == 1)\r
2116                 {\r
2117                         if(bTxPause)\r
2118                         {\r
2119                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 1\n"));\r
2120 \r
2121                                 if(pCoexDm->curPsTdma == 71)\r
2122                                 {\r
2123                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
2124                                         pCoexDm->psTdmaDuAdjType = 5;\r
2125                                 }\r
2126                                 else if(pCoexDm->curPsTdma == 1)\r
2127                                 {\r
2128                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
2129                                         pCoexDm->psTdmaDuAdjType = 5;\r
2130                                 }\r
2131                                 else if(pCoexDm->curPsTdma == 2)\r
2132                                 {\r
2133                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2134                                         pCoexDm->psTdmaDuAdjType = 6;\r
2135                                 }\r
2136                                 else if(pCoexDm->curPsTdma == 3)\r
2137                                 {\r
2138                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2139                                         pCoexDm->psTdmaDuAdjType = 7;\r
2140                                 }\r
2141                                 else if(pCoexDm->curPsTdma == 4)\r
2142                                 {\r
2143                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
2144                                         pCoexDm->psTdmaDuAdjType = 8;\r
2145                                 }\r
2146                                 if(pCoexDm->curPsTdma == 9)\r
2147                                 {\r
2148                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);\r
2149                                         pCoexDm->psTdmaDuAdjType = 13;\r
2150                                 }\r
2151                                 else if(pCoexDm->curPsTdma == 10)\r
2152                                 {\r
2153                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2154                                         pCoexDm->psTdmaDuAdjType = 14;\r
2155                                 }\r
2156                                 else if(pCoexDm->curPsTdma == 11)\r
2157                                 {\r
2158                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2159                                         pCoexDm->psTdmaDuAdjType = 15;\r
2160                                 }\r
2161                                 else if(pCoexDm->curPsTdma == 12)\r
2162                                 {\r
2163                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
2164                                         pCoexDm->psTdmaDuAdjType = 16;\r
2165                                 }\r
2166                                 \r
2167                                 if(result == -1)\r
2168                                 {                                       \r
2169                                         if(pCoexDm->curPsTdma == 5)\r
2170                                         {\r
2171                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2172                                                 pCoexDm->psTdmaDuAdjType = 6;\r
2173                                         }\r
2174                                         else if(pCoexDm->curPsTdma == 6)\r
2175                                         {\r
2176                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2177                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2178                                         }\r
2179                                         else if(pCoexDm->curPsTdma == 7)\r
2180                                         {\r
2181                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
2182                                                 pCoexDm->psTdmaDuAdjType = 8;\r
2183                                         }\r
2184                                         else if(pCoexDm->curPsTdma == 13)\r
2185                                         {\r
2186                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2187                                                 pCoexDm->psTdmaDuAdjType = 14;\r
2188                                         }\r
2189                                         else if(pCoexDm->curPsTdma == 14)\r
2190                                         {\r
2191                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2192                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2193                                         }\r
2194                                         else if(pCoexDm->curPsTdma == 15)\r
2195                                         {\r
2196                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
2197                                                 pCoexDm->psTdmaDuAdjType = 16;\r
2198                                         }\r
2199                                 } \r
2200                                 else if (result == 1)\r
2201                                 {\r
2202                                         if(pCoexDm->curPsTdma == 8)\r
2203                                         {\r
2204                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2205                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2206                                         }\r
2207                                         else if(pCoexDm->curPsTdma == 7)\r
2208                                         {\r
2209                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2210                                                 pCoexDm->psTdmaDuAdjType = 6;\r
2211                                         }\r
2212                                         else if(pCoexDm->curPsTdma == 6)\r
2213                                         {\r
2214                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
2215                                                 pCoexDm->psTdmaDuAdjType = 5;\r
2216                                         }\r
2217                                         else if(pCoexDm->curPsTdma == 16)\r
2218                                         {\r
2219                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2220                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2221                                         }\r
2222                                         else if(pCoexDm->curPsTdma == 15)\r
2223                                         {\r
2224                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2225                                                 pCoexDm->psTdmaDuAdjType = 14;\r
2226                                         }\r
2227                                         else if(pCoexDm->curPsTdma == 14)\r
2228                                         {\r
2229                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);\r
2230                                                 pCoexDm->psTdmaDuAdjType = 13;\r
2231                                         }\r
2232                                 }\r
2233                         }\r
2234                         else\r
2235                         {\r
2236                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 0\n"));\r
2237                                 if(pCoexDm->curPsTdma == 5)\r
2238                                 {\r
2239                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 71);\r
2240                                         pCoexDm->psTdmaDuAdjType = 71;\r
2241                                 }\r
2242                                 else if(pCoexDm->curPsTdma == 6)\r
2243                                 {\r
2244                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2245                                         pCoexDm->psTdmaDuAdjType = 2;\r
2246                                 }\r
2247                                 else if(pCoexDm->curPsTdma == 7)\r
2248                                 {\r
2249                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2250                                         pCoexDm->psTdmaDuAdjType = 3;\r
2251                                 }\r
2252                                 else if(pCoexDm->curPsTdma == 8)\r
2253                                 {\r
2254                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
2255                                         pCoexDm->psTdmaDuAdjType = 4;\r
2256                                 }\r
2257                                 if(pCoexDm->curPsTdma == 13)\r
2258                                 {\r
2259                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
2260                                         pCoexDm->psTdmaDuAdjType = 9;\r
2261                                 }\r
2262                                 else if(pCoexDm->curPsTdma == 14)\r
2263                                 {\r
2264                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2265                                         pCoexDm->psTdmaDuAdjType = 10;\r
2266                                 }\r
2267                                 else if(pCoexDm->curPsTdma == 15)\r
2268                                 {\r
2269                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2270                                         pCoexDm->psTdmaDuAdjType = 11;\r
2271                                 }\r
2272                                 else if(pCoexDm->curPsTdma == 16)\r
2273                                 {\r
2274                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
2275                                         pCoexDm->psTdmaDuAdjType = 12;\r
2276                                 }\r
2277                                 \r
2278                                 if(result == -1)\r
2279                                 {\r
2280                                         if(pCoexDm->curPsTdma == 71)\r
2281                                         {\r
2282                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
2283                                                 pCoexDm->psTdmaDuAdjType = 1;\r
2284                                         }\r
2285                                         else if(pCoexDm->curPsTdma == 1)\r
2286                                         {\r
2287                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2288                                                 pCoexDm->psTdmaDuAdjType = 2;\r
2289                                         }\r
2290                                         else if(pCoexDm->curPsTdma == 2)\r
2291                                         {\r
2292                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2293                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2294                                         }\r
2295                                         else if(pCoexDm->curPsTdma == 3)\r
2296                                         {\r
2297                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
2298                                                 pCoexDm->psTdmaDuAdjType = 4;\r
2299                                         }\r
2300                                         else if(pCoexDm->curPsTdma == 9)\r
2301                                         {\r
2302                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2303                                                 pCoexDm->psTdmaDuAdjType = 10;\r
2304                                         }\r
2305                                         else if(pCoexDm->curPsTdma == 10)\r
2306                                         {\r
2307                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2308                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2309                                         }\r
2310                                         else if(pCoexDm->curPsTdma == 11)\r
2311                                         {\r
2312                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
2313                                                 pCoexDm->psTdmaDuAdjType = 12;\r
2314                                         }\r
2315                                 } \r
2316                                 else if (result == 1)\r
2317                                 {\r
2318                                         if(pCoexDm->curPsTdma == 4)\r
2319                                         {\r
2320                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2321                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2322                                         }\r
2323                                         else if(pCoexDm->curPsTdma == 3)\r
2324                                         {\r
2325                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2326                                                 pCoexDm->psTdmaDuAdjType = 2;\r
2327                                         }\r
2328                                         else if(pCoexDm->curPsTdma == 2)\r
2329                                         {\r
2330                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
2331                                                 pCoexDm->psTdmaDuAdjType = 1;\r
2332                                         }\r
2333                                         else if(pCoexDm->curPsTdma == 1)\r
2334                                         {\r
2335                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 71);\r
2336                                                 pCoexDm->psTdmaDuAdjType = 71;\r
2337                                         }\r
2338                                         else if(pCoexDm->curPsTdma == 12)\r
2339                                         {\r
2340                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2341                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2342                                         }\r
2343                                         else if(pCoexDm->curPsTdma == 11)\r
2344                                         {\r
2345                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2346                                                 pCoexDm->psTdmaDuAdjType = 10;\r
2347                                         }\r
2348                                         else if(pCoexDm->curPsTdma == 10)\r
2349                                         {\r
2350                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
2351                                                 pCoexDm->psTdmaDuAdjType = 9;\r
2352                                         }\r
2353                                 }\r
2354                         }\r
2355                 }\r
2356                 else if(maxInterval == 2)\r
2357                 {\r
2358                         if(bTxPause)\r
2359                         {\r
2360                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 1\n"));\r
2361                                 if(pCoexDm->curPsTdma == 1)\r
2362                                 {\r
2363                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2364                                         pCoexDm->psTdmaDuAdjType = 6;\r
2365                                 }\r
2366                                 else if(pCoexDm->curPsTdma == 2)\r
2367                                 {\r
2368                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2369                                         pCoexDm->psTdmaDuAdjType = 6;\r
2370                                 }\r
2371                                 else if(pCoexDm->curPsTdma == 3)\r
2372                                 {\r
2373                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2374                                         pCoexDm->psTdmaDuAdjType = 7;\r
2375                                 }\r
2376                                 else if(pCoexDm->curPsTdma == 4)\r
2377                                 {\r
2378                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
2379                                         pCoexDm->psTdmaDuAdjType = 8;\r
2380                                 }\r
2381                                 if(pCoexDm->curPsTdma == 9)\r
2382                                 {\r
2383                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2384                                         pCoexDm->psTdmaDuAdjType = 14;\r
2385                                 }\r
2386                                 else if(pCoexDm->curPsTdma == 10)\r
2387                                 {\r
2388                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2389                                         pCoexDm->psTdmaDuAdjType = 14;\r
2390                                 }\r
2391                                 else if(pCoexDm->curPsTdma == 11)\r
2392                                 {\r
2393                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2394                                         pCoexDm->psTdmaDuAdjType = 15;\r
2395                                 }\r
2396                                 else if(pCoexDm->curPsTdma == 12)\r
2397                                 {\r
2398                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
2399                                         pCoexDm->psTdmaDuAdjType = 16;\r
2400                                 }\r
2401                                 if(result == -1)\r
2402                                 {\r
2403                                         if(pCoexDm->curPsTdma == 5) \r
2404                                         {\r
2405                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2406                                                 pCoexDm->psTdmaDuAdjType = 6;\r
2407                                         }\r
2408                                         else if(pCoexDm->curPsTdma == 6)\r
2409                                         {\r
2410                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2411                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2412                                         }\r
2413                                         else if(pCoexDm->curPsTdma == 7)\r
2414                                         {\r
2415                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
2416                                                 pCoexDm->psTdmaDuAdjType = 8;\r
2417                                         }\r
2418                                         else if(pCoexDm->curPsTdma == 13)\r
2419                                         {\r
2420                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2421                                                 pCoexDm->psTdmaDuAdjType = 14;\r
2422                                         }\r
2423                                         else if(pCoexDm->curPsTdma == 14)\r
2424                                         {\r
2425                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2426                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2427                                         }\r
2428                                         else if(pCoexDm->curPsTdma == 15)\r
2429                                         {\r
2430                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
2431                                                 pCoexDm->psTdmaDuAdjType = 16;\r
2432                                         }\r
2433                                 } \r
2434                                 else if (result == 1)\r
2435                                 {\r
2436                                         if(pCoexDm->curPsTdma == 8)\r
2437                                         {\r
2438                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2439                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2440                                         }\r
2441                                         else if(pCoexDm->curPsTdma == 7)\r
2442                                         {\r
2443                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2444                                                 pCoexDm->psTdmaDuAdjType = 6;\r
2445                                         }\r
2446                                         else if(pCoexDm->curPsTdma == 6)\r
2447                                         {\r
2448                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2449                                                 pCoexDm->psTdmaDuAdjType = 6;\r
2450                                         }                                       \r
2451                                         else if(pCoexDm->curPsTdma == 16)\r
2452                                         {\r
2453                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2454                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2455                                         }\r
2456                                         else if(pCoexDm->curPsTdma == 15)\r
2457                                         {\r
2458                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2459                                                 pCoexDm->psTdmaDuAdjType = 14;\r
2460                                         }\r
2461                                         else if(pCoexDm->curPsTdma == 14)\r
2462                                         {\r
2463                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2464                                                 pCoexDm->psTdmaDuAdjType = 14;\r
2465                                         }\r
2466                                 }\r
2467                         }\r
2468                         else\r
2469                         {\r
2470                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 0\n"));\r
2471                                 if(pCoexDm->curPsTdma == 5)\r
2472                                 {\r
2473                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2474                                         pCoexDm->psTdmaDuAdjType = 2;\r
2475                                 }\r
2476                                 else if(pCoexDm->curPsTdma == 6)\r
2477                                 {\r
2478                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2479                                         pCoexDm->psTdmaDuAdjType = 2;\r
2480                                 }\r
2481                                 else if(pCoexDm->curPsTdma == 7)\r
2482                                 {\r
2483                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2484                                         pCoexDm->psTdmaDuAdjType = 3;\r
2485                                 }\r
2486                                 else if(pCoexDm->curPsTdma == 8)\r
2487                                 {\r
2488                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
2489                                         pCoexDm->psTdmaDuAdjType = 4;\r
2490                                 }\r
2491                                 if(pCoexDm->curPsTdma == 13)\r
2492                                 {\r
2493                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2494                                         pCoexDm->psTdmaDuAdjType = 10;\r
2495                                 }\r
2496                                 else if(pCoexDm->curPsTdma == 14)\r
2497                                 {\r
2498                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2499                                         pCoexDm->psTdmaDuAdjType = 10;\r
2500                                 }\r
2501                                 else if(pCoexDm->curPsTdma == 15)\r
2502                                 {\r
2503                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2504                                         pCoexDm->psTdmaDuAdjType = 11;\r
2505                                 }\r
2506                                 else if(pCoexDm->curPsTdma == 16)\r
2507                                 {\r
2508                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
2509                                         pCoexDm->psTdmaDuAdjType = 12;\r
2510                                 }\r
2511                                 if(result == -1)\r
2512                                 {\r
2513                                         if(pCoexDm->curPsTdma == 1)\r
2514                                         {\r
2515                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2516                                                 pCoexDm->psTdmaDuAdjType = 2;\r
2517                                         }\r
2518                                         else if(pCoexDm->curPsTdma == 2)\r
2519                                         {\r
2520                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2521                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2522                                         }\r
2523                                         else if(pCoexDm->curPsTdma == 3)\r
2524                                         {\r
2525                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
2526                                                 pCoexDm->psTdmaDuAdjType = 4;\r
2527                                         }\r
2528                                         else if(pCoexDm->curPsTdma == 9)\r
2529                                         {\r
2530                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2531                                                 pCoexDm->psTdmaDuAdjType = 10;\r
2532                                         }\r
2533                                         else if(pCoexDm->curPsTdma == 10)\r
2534                                         {\r
2535                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2536                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2537                                         }\r
2538                                         else if(pCoexDm->curPsTdma == 11)\r
2539                                         {\r
2540                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
2541                                                 pCoexDm->psTdmaDuAdjType = 12;\r
2542                                         }\r
2543                                 } \r
2544                                 else if (result == 1)\r
2545                                 {\r
2546                                         if(pCoexDm->curPsTdma == 4)\r
2547                                         {\r
2548                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2549                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2550                                         }\r
2551                                         else if(pCoexDm->curPsTdma == 3)\r
2552                                         {\r
2553                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2554                                                 pCoexDm->psTdmaDuAdjType = 2;\r
2555                                         }\r
2556                                         else if(pCoexDm->curPsTdma == 2)\r
2557                                         {\r
2558                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2559                                                 pCoexDm->psTdmaDuAdjType = 2;\r
2560                                         }\r
2561                                         else if(pCoexDm->curPsTdma == 12)\r
2562                                         {\r
2563                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2564                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2565                                         }\r
2566                                         else if(pCoexDm->curPsTdma == 11)\r
2567                                         {\r
2568                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2569                                                 pCoexDm->psTdmaDuAdjType = 10;\r
2570                                         }\r
2571                                         else if(pCoexDm->curPsTdma == 10)\r
2572                                         {\r
2573                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2574                                                 pCoexDm->psTdmaDuAdjType = 10;\r
2575                                         }\r
2576                                 }\r
2577                         }\r
2578                 }\r
2579                 else if(maxInterval == 3)\r
2580                 {\r
2581                         if(bTxPause)\r
2582                         {\r
2583                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 1\n"));\r
2584                                 if(pCoexDm->curPsTdma == 1)\r
2585                                 {\r
2586                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2587                                         pCoexDm->psTdmaDuAdjType = 7;\r
2588                                 }\r
2589                                 else if(pCoexDm->curPsTdma == 2)\r
2590                                 {\r
2591                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2592                                         pCoexDm->psTdmaDuAdjType = 7;\r
2593                                 }\r
2594                                 else if(pCoexDm->curPsTdma == 3)\r
2595                                 {\r
2596                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2597                                         pCoexDm->psTdmaDuAdjType = 7;\r
2598                                 }\r
2599                                 else if(pCoexDm->curPsTdma == 4)\r
2600                                 {\r
2601                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
2602                                         pCoexDm->psTdmaDuAdjType = 8;\r
2603                                 }\r
2604                                 if(pCoexDm->curPsTdma == 9)\r
2605                                 {\r
2606                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2607                                         pCoexDm->psTdmaDuAdjType = 15;\r
2608                                 }\r
2609                                 else if(pCoexDm->curPsTdma == 10)\r
2610                                 {\r
2611                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2612                                         pCoexDm->psTdmaDuAdjType = 15;\r
2613                                 }\r
2614                                 else if(pCoexDm->curPsTdma == 11)\r
2615                                 {\r
2616                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2617                                         pCoexDm->psTdmaDuAdjType = 15;\r
2618                                 }\r
2619                                 else if(pCoexDm->curPsTdma == 12)\r
2620                                 {\r
2621                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
2622                                         pCoexDm->psTdmaDuAdjType = 16;\r
2623                                 }\r
2624                                 if(result == -1)\r
2625                                 {\r
2626                                         if(pCoexDm->curPsTdma == 5) \r
2627                                         {\r
2628                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2629                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2630                                         }\r
2631                                         else if(pCoexDm->curPsTdma == 6)\r
2632                                         {\r
2633                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2634                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2635                                         }\r
2636                                         else if(pCoexDm->curPsTdma == 7)\r
2637                                         {\r
2638                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
2639                                                 pCoexDm->psTdmaDuAdjType = 8;\r
2640                                         }\r
2641                                         else if(pCoexDm->curPsTdma == 13)\r
2642                                         {\r
2643                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2644                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2645                                         }\r
2646                                         else if(pCoexDm->curPsTdma == 14)\r
2647                                         {\r
2648                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2649                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2650                                         }\r
2651                                         else if(pCoexDm->curPsTdma == 15)\r
2652                                         {\r
2653                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
2654                                                 pCoexDm->psTdmaDuAdjType = 16;\r
2655                                         }\r
2656                                 } \r
2657                                 else if (result == 1)\r
2658                                 {\r
2659                                         if(pCoexDm->curPsTdma == 8)\r
2660                                         {\r
2661                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2662                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2663                                         }\r
2664                                         else if(pCoexDm->curPsTdma == 7)\r
2665                                         {\r
2666                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2667                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2668                                         }\r
2669                                         else if(pCoexDm->curPsTdma == 6)\r
2670                                         {\r
2671                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2672                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2673                                         }                                       \r
2674                                         else if(pCoexDm->curPsTdma == 16)\r
2675                                         {\r
2676                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2677                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2678                                         }\r
2679                                         else if(pCoexDm->curPsTdma == 15)\r
2680                                         {\r
2681                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2682                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2683                                         }\r
2684                                         else if(pCoexDm->curPsTdma == 14)\r
2685                                         {\r
2686                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2687                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2688                                         }\r
2689                                 }\r
2690                         }\r
2691                         else\r
2692                         {\r
2693                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], TxPause = 0\n"));\r
2694                                 if(pCoexDm->curPsTdma == 5)\r
2695                                 {\r
2696                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2697                                         pCoexDm->psTdmaDuAdjType = 3;\r
2698                                 }\r
2699                                 else if(pCoexDm->curPsTdma == 6)\r
2700                                 {\r
2701                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2702                                         pCoexDm->psTdmaDuAdjType = 3;\r
2703                                 }\r
2704                                 else if(pCoexDm->curPsTdma == 7)\r
2705                                 {\r
2706                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2707                                         pCoexDm->psTdmaDuAdjType = 3;\r
2708                                 }\r
2709                                 else if(pCoexDm->curPsTdma == 8)\r
2710                                 {\r
2711                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
2712                                         pCoexDm->psTdmaDuAdjType = 4;\r
2713                                 }\r
2714                                 if(pCoexDm->curPsTdma == 13)\r
2715                                 {\r
2716                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2717                                         pCoexDm->psTdmaDuAdjType = 11;\r
2718                                 }\r
2719                                 else if(pCoexDm->curPsTdma == 14)\r
2720                                 {\r
2721                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2722                                         pCoexDm->psTdmaDuAdjType = 11;\r
2723                                 }\r
2724                                 else if(pCoexDm->curPsTdma == 15)\r
2725                                 {\r
2726                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2727                                         pCoexDm->psTdmaDuAdjType = 11;\r
2728                                 }\r
2729                                 else if(pCoexDm->curPsTdma == 16)\r
2730                                 {\r
2731                                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
2732                                         pCoexDm->psTdmaDuAdjType = 12;\r
2733                                 }\r
2734                                 if(result == -1)\r
2735                                 {\r
2736                                         if(pCoexDm->curPsTdma == 1)\r
2737                                         {\r
2738                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2739                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2740                                         }\r
2741                                         else if(pCoexDm->curPsTdma == 2)\r
2742                                         {\r
2743                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2744                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2745                                         }\r
2746                                         else if(pCoexDm->curPsTdma == 3)\r
2747                                         {\r
2748                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
2749                                                 pCoexDm->psTdmaDuAdjType = 4;\r
2750                                         }\r
2751                                         else if(pCoexDm->curPsTdma == 9)\r
2752                                         {\r
2753                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2754                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2755                                         }\r
2756                                         else if(pCoexDm->curPsTdma == 10)\r
2757                                         {\r
2758                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2759                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2760                                         }\r
2761                                         else if(pCoexDm->curPsTdma == 11)\r
2762                                         {\r
2763                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
2764                                                 pCoexDm->psTdmaDuAdjType = 12;\r
2765                                         }\r
2766                                 } \r
2767                                 else if (result == 1)\r
2768                                 {\r
2769                                         if(pCoexDm->curPsTdma == 4)\r
2770                                         {\r
2771                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2772                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2773                                         }\r
2774                                         else if(pCoexDm->curPsTdma == 3)\r
2775                                         {\r
2776                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2777                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2778                                         }\r
2779                                         else if(pCoexDm->curPsTdma == 2)\r
2780                                         {\r
2781                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2782                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2783                                         }\r
2784                                         else if(pCoexDm->curPsTdma == 12)\r
2785                                         {\r
2786                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2787                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2788                                         }\r
2789                                         else if(pCoexDm->curPsTdma == 11)\r
2790                                         {\r
2791                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2792                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2793                                         }\r
2794                                         else if(pCoexDm->curPsTdma == 10)\r
2795                                         {\r
2796                                                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2797                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2798                                         }\r
2799                                 }\r
2800                         }\r
2801                 }\r
2802         }\r
2803 \r
2804         // if current PsTdma not match with the recorded one (when scan, dhcp...), \r
2805         // then we have to adjust it back to the previous record one.\r
2806         if(pCoexDm->curPsTdma != pCoexDm->psTdmaDuAdjType)\r
2807         {\r
2808                 BOOLEAN bScan=FALSE, bLink=FALSE, bRoam=FALSE;\r
2809                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], PsTdma type dismatch!!!, curPsTdma=%d, recordPsTdma=%d\n", \r
2810                         pCoexDm->curPsTdma, pCoexDm->psTdmaDuAdjType));\r
2811 \r
2812                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);\r
2813                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);\r
2814                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);\r
2815                 \r
2816                 if( !bScan && !bLink && !bRoam)\r
2817                 {\r
2818                         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, pCoexDm->psTdmaDuAdjType);\r
2819                 }\r
2820                 else\r
2821                 {\r
2822                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_DETAIL, ("[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n"));\r
2823                 }\r
2824         }\r
2825 }\r
2826 \r
2827 // SCO only or SCO+PAN(HS)\r
2828 VOID\r
2829 halbtc8192e2ant_ActionSco(\r
2830         IN      PBTC_COEXIST            pBtCoexist\r
2831         )\r
2832 {\r
2833         u1Byte  wifiRssiState, btRssiState=BTC_RSSI_STATE_STAY_LOW;\r
2834         u4Byte  wifiBw;\r
2835 \r
2836         wifiRssiState = halbtc8192e2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
2837 \r
2838         halbtc8192e2ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 1);\r
2839         halbtc8192e2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
2840 \r
2841         halbtc8192e2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
2842 \r
2843         halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);\r
2844 \r
2845         btRssiState = halbtc8192e2ant_BtRssiState(3, 34, 42);\r
2846 \r
2847         if( (btRssiState == BTC_RSSI_STATE_LOW) ||\r
2848                 (btRssiState == BTC_RSSI_STATE_STAY_LOW) )\r
2849         {\r
2850                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
2851                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);\r
2852         }\r
2853         else if( (btRssiState == BTC_RSSI_STATE_MEDIUM) ||\r
2854                         (btRssiState == BTC_RSSI_STATE_STAY_MEDIUM) )\r
2855         {\r
2856                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
2857                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
2858         }\r
2859         else if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
2860                         (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2861         {\r
2862                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);\r
2863                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
2864         }\r
2865         \r
2866         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
2867 \r
2868         // sw mechanism\r
2869         if(BTC_WIFI_BW_HT40 == wifiBw)\r
2870         {\r
2871                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2872                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2873                 {\r
2874                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
2875                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x6);                  \r
2876                 }\r
2877                 else\r
2878                 {\r
2879                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
2880                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x6); \r
2881                 }               \r
2882         }\r
2883         else\r
2884         {\r
2885                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2886                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2887                 {\r
2888                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
2889                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x6);\r
2890                 }\r
2891                 else\r
2892                 {\r
2893                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
2894                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x6);\r
2895                 }               \r
2896         }\r
2897 }\r
2898 \r
2899 VOID\r
2900 halbtc8192e2ant_ActionScoPan(\r
2901         IN      PBTC_COEXIST            pBtCoexist\r
2902         )\r
2903 {\r
2904         u1Byte  wifiRssiState, btRssiState=BTC_RSSI_STATE_STAY_LOW;\r
2905         u4Byte  wifiBw;\r
2906 \r
2907         wifiRssiState = halbtc8192e2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
2908 \r
2909         halbtc8192e2ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 1);\r
2910         halbtc8192e2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
2911 \r
2912         halbtc8192e2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
2913 \r
2914         halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 4);\r
2915 \r
2916         btRssiState = halbtc8192e2ant_BtRssiState(3, 34, 42);\r
2917 \r
2918         if( (btRssiState == BTC_RSSI_STATE_LOW) ||\r
2919                 (btRssiState == BTC_RSSI_STATE_STAY_LOW) )\r
2920         {\r
2921                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
2922                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2923         }\r
2924         else if( (btRssiState == BTC_RSSI_STATE_MEDIUM) ||\r
2925                         (btRssiState == BTC_RSSI_STATE_STAY_MEDIUM) )\r
2926         {\r
2927                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
2928                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2929         }\r
2930         else if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
2931                         (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2932         {\r
2933                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);\r
2934                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2935         }\r
2936         \r
2937         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
2938 \r
2939         // sw mechanism\r
2940         if(BTC_WIFI_BW_HT40 == wifiBw)\r
2941         {\r
2942                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2943                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2944                 {\r
2945                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
2946                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x6);                  \r
2947                 }\r
2948                 else\r
2949                 {\r
2950                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
2951                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x6); \r
2952                 }               \r
2953         }\r
2954         else\r
2955         {\r
2956                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2957                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2958                 {\r
2959                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
2960                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x6);\r
2961                 }\r
2962                 else\r
2963                 {\r
2964                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
2965                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x6);\r
2966                 }               \r
2967         }\r
2968 }\r
2969 \r
2970 VOID\r
2971 halbtc8192e2ant_ActionHid(\r
2972         IN      PBTC_COEXIST            pBtCoexist\r
2973         )\r
2974 {\r
2975         u1Byte  wifiRssiState, btRssiState=BTC_RSSI_STATE_HIGH; \r
2976         u4Byte  wifiBw;\r
2977 \r
2978         wifiRssiState = halbtc8192e2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
2979         btRssiState = halbtc8192e2ant_BtRssiState(3, 34, 42);\r
2980 \r
2981         halbtc8192e2ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 1);\r
2982         halbtc8192e2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
2983 \r
2984         halbtc8192e2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
2985 \r
2986         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
2987 \r
2988         halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 3);\r
2989 \r
2990         if( (btRssiState == BTC_RSSI_STATE_LOW) ||\r
2991                 (btRssiState == BTC_RSSI_STATE_STAY_LOW) )\r
2992         {\r
2993                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
2994                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);\r
2995         }\r
2996         else if( (btRssiState == BTC_RSSI_STATE_MEDIUM) ||\r
2997                         (btRssiState == BTC_RSSI_STATE_STAY_MEDIUM) )\r
2998         {\r
2999                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3000                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
3001         }\r
3002         else if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
3003                         (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3004         {\r
3005                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);\r
3006                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
3007         }\r
3008 \r
3009         // sw mechanism\r
3010         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3011         {\r
3012                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3013                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3014                 {\r
3015                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
3016                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3017                 }\r
3018                 else\r
3019                 {\r
3020                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
3021                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3022                 }       \r
3023         }\r
3024         else\r
3025         {\r
3026                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3027                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3028                 {\r
3029                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
3030                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3031                 }\r
3032                 else\r
3033                 {\r
3034                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
3035                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3036                 }               \r
3037         }\r
3038 }\r
3039 \r
3040 //A2DP only / PAN(EDR) only/ A2DP+PAN(HS)\r
3041 VOID\r
3042 halbtc8192e2ant_ActionA2dp(\r
3043         IN      PBTC_COEXIST            pBtCoexist\r
3044         )\r
3045 {\r
3046         u1Byte          wifiRssiState, btRssiState=BTC_RSSI_STATE_HIGH;\r
3047         u4Byte          wifiBw;\r
3048         BOOLEAN         bLongDist=FALSE;\r
3049 \r
3050         wifiRssiState = halbtc8192e2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
3051         btRssiState = halbtc8192e2ant_BtRssiState(3, 34, 42);\r
3052 \r
3053         if( (btRssiState == BTC_RSSI_STATE_LOW||btRssiState == BTC_RSSI_STATE_STAY_LOW) &&\r
3054                 (wifiRssiState == BTC_RSSI_STATE_LOW||wifiRssiState == BTC_RSSI_STATE_STAY_LOW) )\r
3055         {\r
3056                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], A2dp, wifi/bt rssi both LOW!!\n"));\r
3057                 bLongDist = TRUE;\r
3058         }\r
3059         if(bLongDist)\r
3060         {\r
3061                 halbtc8192e2ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 2);\r
3062                 halbtc8192e2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, TRUE, 0x4);\r
3063         }\r
3064         else\r
3065         {\r
3066                 halbtc8192e2ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 1);\r
3067                 halbtc8192e2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
3068         }\r
3069 \r
3070         halbtc8192e2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
3071 \r
3072         if(bLongDist)\r
3073                 halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 0);\r
3074         else\r
3075                 halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
3076 \r
3077 \r
3078         if(bLongDist)\r
3079         {\r
3080                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 17);\r
3081                 pCoexDm->bAutoTdmaAdjust = FALSE;\r
3082                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3083         }\r
3084         else\r
3085         {\r
3086                 if( (btRssiState == BTC_RSSI_STATE_LOW) ||\r
3087                         (btRssiState == BTC_RSSI_STATE_STAY_LOW) )\r
3088                 {\r
3089                         halbtc8192e2ant_TdmaDurationAdjust(pBtCoexist, FALSE, TRUE, 1);\r
3090                         halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3091                 }\r
3092                 else if( (btRssiState == BTC_RSSI_STATE_MEDIUM) ||\r
3093                                 (btRssiState == BTC_RSSI_STATE_STAY_MEDIUM) )\r
3094                 {\r
3095                         halbtc8192e2ant_TdmaDurationAdjust(pBtCoexist, FALSE, FALSE, 1);\r
3096                         halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3097                 }\r
3098                 else if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
3099                                 (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3100                 {\r
3101                         halbtc8192e2ant_TdmaDurationAdjust(pBtCoexist, FALSE, FALSE, 1);\r
3102                         halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);\r
3103                 }\r
3104         }\r
3105         \r
3106         // sw mechanism\r
3107         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3108         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3109         {\r
3110                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3111                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3112                 {\r
3113                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3114                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3115                 }\r
3116                 else\r
3117                 {\r
3118                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3119                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3120                 }\r
3121         }\r
3122         else\r
3123         {\r
3124                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3125                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3126                 {\r
3127                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3128                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3129                 }\r
3130                 else\r
3131                 {\r
3132                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3133                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3134                 }               \r
3135         }\r
3136 }\r
3137 \r
3138 VOID\r
3139 halbtc8192e2ant_ActionA2dpPanHs(\r
3140         IN      PBTC_COEXIST            pBtCoexist\r
3141         )\r
3142 {\r
3143         u1Byte          wifiRssiState, btRssiState=BTC_RSSI_STATE_HIGH;\r
3144         u4Byte          wifiBw;\r
3145 \r
3146         wifiRssiState = halbtc8192e2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
3147         btRssiState = halbtc8192e2ant_BtRssiState(3, 34, 42);\r
3148 \r
3149         halbtc8192e2ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 1);\r
3150         halbtc8192e2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
3151 \r
3152         halbtc8192e2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
3153         halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
3154 \r
3155         if( (btRssiState == BTC_RSSI_STATE_LOW) ||\r
3156                 (btRssiState == BTC_RSSI_STATE_STAY_LOW) )\r
3157         {\r
3158                 halbtc8192e2ant_TdmaDurationAdjust(pBtCoexist, FALSE, TRUE, 2);\r
3159                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3160         }\r
3161         else if( (btRssiState == BTC_RSSI_STATE_MEDIUM) ||\r
3162                         (btRssiState == BTC_RSSI_STATE_STAY_MEDIUM) )\r
3163         {\r
3164                 halbtc8192e2ant_TdmaDurationAdjust(pBtCoexist, FALSE, FALSE, 2);\r
3165                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3166         }\r
3167         else if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
3168                         (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3169         {\r
3170                 halbtc8192e2ant_TdmaDurationAdjust(pBtCoexist, FALSE, FALSE, 2);\r
3171                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);\r
3172         }\r
3173 \r
3174         // sw mechanism\r
3175         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3176         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3177         {\r
3178                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3179                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3180                 {\r
3181                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3182                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,TRUE,0x6);\r
3183                 }\r
3184                 else\r
3185                 {\r
3186                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3187                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,TRUE,0x6);\r
3188                 }\r
3189         }\r
3190         else\r
3191         {\r
3192                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3193                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3194                 {\r
3195                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3196                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,TRUE,0x6);\r
3197                 }\r
3198                 else\r
3199                 {\r
3200                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3201                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,TRUE,0x6);\r
3202                 }               \r
3203         }\r
3204 }\r
3205 \r
3206 VOID\r
3207 halbtc8192e2ant_ActionPanEdr(\r
3208         IN      PBTC_COEXIST            pBtCoexist\r
3209         )\r
3210 {\r
3211         u1Byte          wifiRssiState, btRssiState=BTC_RSSI_STATE_HIGH;\r
3212         u4Byte          wifiBw;\r
3213 \r
3214         wifiRssiState = halbtc8192e2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
3215         btRssiState = halbtc8192e2ant_BtRssiState(3, 34, 42);\r
3216 \r
3217         halbtc8192e2ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 1);\r
3218         halbtc8192e2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
3219 \r
3220         halbtc8192e2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
3221 \r
3222         halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
3223 \r
3224         if( (btRssiState == BTC_RSSI_STATE_LOW) ||\r
3225                 (btRssiState == BTC_RSSI_STATE_STAY_LOW) )\r
3226         {\r
3227                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3228                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
3229         }\r
3230         else if( (btRssiState == BTC_RSSI_STATE_MEDIUM) ||\r
3231                         (btRssiState == BTC_RSSI_STATE_STAY_MEDIUM) )\r
3232         {\r
3233                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3234                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
3235         }\r
3236         else if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
3237                         (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3238         {\r
3239                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);\r
3240                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
3241         }\r
3242         \r
3243         // sw mechanism\r
3244         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3245         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3246         {\r
3247                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3248                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3249                 {\r
3250                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3251                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3252                 }\r
3253                 else\r
3254                 {\r
3255                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3256                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3257                 }\r
3258         }\r
3259         else\r
3260         {\r
3261                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3262                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3263                 {\r
3264                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3265                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3266                 }\r
3267                 else\r
3268                 {\r
3269                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3270                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3271                 }\r
3272         }\r
3273 }\r
3274 \r
3275 //PAN(HS) only\r
3276 VOID\r
3277 halbtc8192e2ant_ActionPanHs(\r
3278         IN      PBTC_COEXIST            pBtCoexist\r
3279         )\r
3280 {\r
3281         u1Byte          wifiRssiState, btRssiState=BTC_RSSI_STATE_HIGH;\r
3282         u4Byte          wifiBw;\r
3283 \r
3284         wifiRssiState = halbtc8192e2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
3285         btRssiState = halbtc8192e2ant_BtRssiState(3, 34, 42);\r
3286 \r
3287         halbtc8192e2ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 1);\r
3288         halbtc8192e2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
3289 \r
3290         halbtc8192e2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
3291 \r
3292         halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
3293 \r
3294         if( (btRssiState == BTC_RSSI_STATE_LOW) ||\r
3295                 (btRssiState == BTC_RSSI_STATE_STAY_LOW) )\r
3296         {\r
3297                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3298         }\r
3299         else if( (btRssiState == BTC_RSSI_STATE_MEDIUM) ||\r
3300                         (btRssiState == BTC_RSSI_STATE_STAY_MEDIUM) )\r
3301         {\r
3302                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3303         }\r
3304         else if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
3305                         (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3306         {\r
3307                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);\r
3308         }\r
3309         halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 1);\r
3310 \r
3311         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3312         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3313         {\r
3314                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3315                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3316                 {\r
3317                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3318                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3319                 }\r
3320                 else\r
3321                 {\r
3322                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3323                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3324                 }\r
3325         }\r
3326         else\r
3327         {\r
3328                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3329                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3330                 {\r
3331                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3332                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3333                 }\r
3334                 else\r
3335                 {\r
3336                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3337                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3338                 }\r
3339         }\r
3340 }\r
3341 \r
3342 //PAN(EDR)+A2DP\r
3343 VOID\r
3344 halbtc8192e2ant_ActionPanEdrA2dp(\r
3345         IN      PBTC_COEXIST            pBtCoexist\r
3346         )\r
3347 {\r
3348         u1Byte          wifiRssiState, btRssiState=BTC_RSSI_STATE_HIGH;\r
3349         u4Byte          wifiBw;\r
3350 \r
3351         wifiRssiState = halbtc8192e2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
3352         btRssiState = halbtc8192e2ant_BtRssiState(3, 34, 42);\r
3353 \r
3354         halbtc8192e2ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 1);\r
3355         halbtc8192e2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
3356 \r
3357         halbtc8192e2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
3358 \r
3359         halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 2);\r
3360 \r
3361         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3362 \r
3363         if( (btRssiState == BTC_RSSI_STATE_LOW) ||\r
3364                 (btRssiState == BTC_RSSI_STATE_STAY_LOW) )\r
3365         {\r
3366                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3367                 halbtc8192e2ant_TdmaDurationAdjust(pBtCoexist, FALSE, TRUE, 3);\r
3368         }\r
3369         else if( (btRssiState == BTC_RSSI_STATE_MEDIUM) ||\r
3370                         (btRssiState == BTC_RSSI_STATE_STAY_MEDIUM) )\r
3371         {\r
3372                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3373                 halbtc8192e2ant_TdmaDurationAdjust(pBtCoexist, FALSE, FALSE, 3);\r
3374         }\r
3375         else if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
3376                         (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3377         {\r
3378                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);\r
3379                 halbtc8192e2ant_TdmaDurationAdjust(pBtCoexist, FALSE, FALSE, 3);\r
3380         }\r
3381         \r
3382         // sw mechanism \r
3383         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3384         {\r
3385                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3386                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3387                 {\r
3388                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3389                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3390                 }\r
3391                 else\r
3392                 {\r
3393                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,FALSE,FALSE,FALSE);\r
3394                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3395                 }\r
3396         }\r
3397         else\r
3398         {\r
3399                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3400                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3401                 {\r
3402                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3403                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3404                 }\r
3405                 else\r
3406                 {\r
3407                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,FALSE,FALSE,FALSE);\r
3408                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3409                 }\r
3410         }\r
3411 }\r
3412 \r
3413 VOID\r
3414 halbtc8192e2ant_ActionPanEdrHid(\r
3415         IN      PBTC_COEXIST            pBtCoexist\r
3416         )\r
3417 {\r
3418         u1Byte          wifiRssiState, btRssiState=BTC_RSSI_STATE_HIGH;\r
3419         u4Byte          wifiBw;\r
3420 \r
3421         wifiRssiState = halbtc8192e2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
3422         btRssiState = halbtc8192e2ant_BtRssiState(3, 34, 42);\r
3423 \r
3424         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3425 \r
3426         halbtc8192e2ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 1);\r
3427         halbtc8192e2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
3428 \r
3429         halbtc8192e2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
3430 \r
3431         halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 3);\r
3432 \r
3433         if( (btRssiState == BTC_RSSI_STATE_LOW) ||\r
3434                 (btRssiState == BTC_RSSI_STATE_STAY_LOW) )\r
3435         {\r
3436                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3437                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
3438         }\r
3439         else if( (btRssiState == BTC_RSSI_STATE_MEDIUM) ||\r
3440                         (btRssiState == BTC_RSSI_STATE_STAY_MEDIUM) )\r
3441         {\r
3442                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3443                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
3444         }\r
3445         else if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
3446                         (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3447         {\r
3448                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);\r
3449                 halbtc8192e2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
3450         }\r
3451         \r
3452         // sw mechanism\r
3453         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3454         {\r
3455                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3456                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3457                 {\r
3458                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
3459                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3460                 }\r
3461                 else\r
3462                 {\r
3463                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
3464                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3465                 }\r
3466         }\r
3467         else\r
3468         {\r
3469                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3470                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3471                 {\r
3472                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
3473                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3474                 }\r
3475                 else\r
3476                 {\r
3477                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
3478                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3479                 }\r
3480         }\r
3481 }\r
3482 \r
3483 // HID+A2DP+PAN(EDR)\r
3484 VOID\r
3485 halbtc8192e2ant_ActionHidA2dpPanEdr(\r
3486         IN      PBTC_COEXIST            pBtCoexist\r
3487         )\r
3488 {\r
3489         u1Byte          wifiRssiState, btRssiState=BTC_RSSI_STATE_HIGH;\r
3490         u4Byte          wifiBw;\r
3491 \r
3492         wifiRssiState = halbtc8192e2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
3493         btRssiState = halbtc8192e2ant_BtRssiState(3, 34, 42);\r
3494 \r
3495         halbtc8192e2ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 1);\r
3496         halbtc8192e2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
3497 \r
3498         halbtc8192e2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 6);\r
3499 \r
3500         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3501 \r
3502         halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 3);\r
3503 \r
3504         if( (btRssiState == BTC_RSSI_STATE_LOW) ||\r
3505                 (btRssiState == BTC_RSSI_STATE_STAY_LOW) )\r
3506         {\r
3507                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3508                 halbtc8192e2ant_TdmaDurationAdjust(pBtCoexist, TRUE, TRUE, 3);\r
3509         }\r
3510         else if( (btRssiState == BTC_RSSI_STATE_MEDIUM) ||\r
3511                         (btRssiState == BTC_RSSI_STATE_STAY_MEDIUM) )\r
3512         {\r
3513                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3514                 halbtc8192e2ant_TdmaDurationAdjust(pBtCoexist, TRUE, FALSE, 3);\r
3515         }\r
3516         else if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
3517                         (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3518         {\r
3519                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);\r
3520                 halbtc8192e2ant_TdmaDurationAdjust(pBtCoexist, TRUE, FALSE, 3);\r
3521         }\r
3522 \r
3523         // sw mechanism\r
3524         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3525         {\r
3526                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3527                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3528                 {\r
3529                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
3530                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3531                 }\r
3532                 else\r
3533                 {\r
3534                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
3535                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3536                 }\r
3537         }\r
3538         else\r
3539         {\r
3540                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3541                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3542                 {\r
3543                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
3544                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3545                 }\r
3546                 else\r
3547                 {\r
3548                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
3549                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3550                 }\r
3551         }\r
3552 }\r
3553 \r
3554 VOID\r
3555 halbtc8192e2ant_ActionHidA2dp(\r
3556         IN      PBTC_COEXIST            pBtCoexist\r
3557         )\r
3558 {\r
3559         u1Byte          wifiRssiState, btRssiState=BTC_RSSI_STATE_HIGH;\r
3560         u4Byte          wifiBw;\r
3561 \r
3562         wifiRssiState = halbtc8192e2ant_WifiRssiState(pBtCoexist, 0, 2, 15, 0);\r
3563         btRssiState = halbtc8192e2ant_BtRssiState(3, 34, 42);\r
3564 \r
3565         halbtc8192e2ant_SwitchSsType(pBtCoexist, NORMAL_EXEC, 1);\r
3566         halbtc8192e2ant_LimitedRx(pBtCoexist, NORMAL_EXEC, FALSE, FALSE, 0x8);\r
3567 \r
3568         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3569 \r
3570         halbtc8192e2ant_CoexTableWithType(pBtCoexist, NORMAL_EXEC, 3);\r
3571         \r
3572         if( (btRssiState == BTC_RSSI_STATE_LOW) ||\r
3573                 (btRssiState == BTC_RSSI_STATE_STAY_LOW) )\r
3574         {\r
3575                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 0);\r
3576                 halbtc8192e2ant_TdmaDurationAdjust(pBtCoexist, TRUE, TRUE, 2);\r
3577         }\r
3578         else if( (btRssiState == BTC_RSSI_STATE_MEDIUM) ||\r
3579                         (btRssiState == BTC_RSSI_STATE_STAY_MEDIUM) )\r
3580         {\r
3581                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 2);\r
3582                 halbtc8192e2ant_TdmaDurationAdjust(pBtCoexist, TRUE, FALSE, 2);\r
3583         }\r
3584         else if( (btRssiState == BTC_RSSI_STATE_HIGH) ||\r
3585                         (btRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3586         {\r
3587                 halbtc8192e2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, 4);\r
3588                 halbtc8192e2ant_TdmaDurationAdjust(pBtCoexist, TRUE, FALSE, 2);\r
3589         }       \r
3590         \r
3591         // sw mechanism\r
3592         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3593         {\r
3594                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3595                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3596                 {\r
3597                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
3598                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3599                 }\r
3600                 else\r
3601                 {\r
3602                         halbtc8192e2ant_SwMechanism1(pBtCoexist,TRUE,TRUE,FALSE,FALSE);\r
3603                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3604                 }\r
3605         }\r
3606         else\r
3607         {\r
3608                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3609                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3610                 {\r
3611                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
3612                         halbtc8192e2ant_SwMechanism2(pBtCoexist,TRUE,FALSE,FALSE,0x18);\r
3613                 }\r
3614                 else\r
3615                 {\r
3616                         halbtc8192e2ant_SwMechanism1(pBtCoexist,FALSE,TRUE,FALSE,FALSE);\r
3617                         halbtc8192e2ant_SwMechanism2(pBtCoexist,FALSE,FALSE,FALSE,0x18);\r
3618                 }\r
3619         }\r
3620 }\r
3621 \r
3622 VOID\r
3623 halbtc8192e2ant_RunCoexistMechanism(\r
3624         IN      PBTC_COEXIST            pBtCoexist\r
3625         )\r
3626 {\r
3627         BOOLEAN                         bWifiUnder5G=FALSE;\r
3628         u1Byte                          btInfoOriginal=0, btRetryCnt=0;\r
3629         u1Byte                          algorithm=0;\r
3630 \r
3631         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], RunCoexistMechanism()===>\n"));\r
3632 \r
3633         if(pBtCoexist->bManualControl)\r
3634         {\r
3635                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"));\r
3636                 return;\r
3637         }\r
3638 \r
3639         if(pCoexSta->bUnderIps)\r
3640         {\r
3641                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], wifi is under IPS !!!\n"));\r
3642                 return;\r
3643         }\r
3644 \r
3645         algorithm = halbtc8192e2ant_ActionAlgorithm(pBtCoexist);\r
3646         if(pCoexSta->bC2hBtInquiryPage && (BT_8192E_2ANT_COEX_ALGO_PANHS!=algorithm))\r
3647         {\r
3648                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT is under inquiry/page scan !!\n"));\r
3649                 halbtc8192e2ant_ActionBtInquiry(pBtCoexist);\r
3650                 return;\r
3651         }\r
3652 \r
3653         pCoexDm->curAlgorithm = algorithm;\r
3654         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Algorithm = %d \n", pCoexDm->curAlgorithm));\r
3655 \r
3656         if(halbtc8192e2ant_IsCommonAction(pBtCoexist))\r
3657         {\r
3658                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant common.\n"));\r
3659                 pCoexDm->bAutoTdmaAdjust = FALSE;\r
3660         }\r
3661         else\r
3662         {\r
3663                 if(pCoexDm->curAlgorithm != pCoexDm->preAlgorithm)\r
3664                 {\r
3665                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], preAlgorithm=%d, curAlgorithm=%d\n", \r
3666                                 pCoexDm->preAlgorithm, pCoexDm->curAlgorithm));\r
3667                         pCoexDm->bAutoTdmaAdjust = FALSE;\r
3668                 }\r
3669                 switch(pCoexDm->curAlgorithm)\r
3670                 {\r
3671                         case BT_8192E_2ANT_COEX_ALGO_SCO:\r
3672                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = SCO.\n"));\r
3673                                 halbtc8192e2ant_ActionSco(pBtCoexist);\r
3674                                 break;\r
3675                         case BT_8192E_2ANT_COEX_ALGO_SCO_PAN:\r
3676                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = SCO+PAN(EDR).\n"));\r
3677                                 halbtc8192e2ant_ActionScoPan(pBtCoexist);\r
3678                                 break;\r
3679                         case BT_8192E_2ANT_COEX_ALGO_HID:\r
3680                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = HID.\n"));\r
3681                                 halbtc8192e2ant_ActionHid(pBtCoexist);\r
3682                                 break;\r
3683                         case BT_8192E_2ANT_COEX_ALGO_A2DP:\r
3684                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = A2DP.\n"));\r
3685                                 halbtc8192e2ant_ActionA2dp(pBtCoexist);\r
3686                                 break;\r
3687                         case BT_8192E_2ANT_COEX_ALGO_A2DP_PANHS:\r
3688                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = A2DP+PAN(HS).\n"));\r
3689                                 halbtc8192e2ant_ActionA2dpPanHs(pBtCoexist);\r
3690                                 break;\r
3691                         case BT_8192E_2ANT_COEX_ALGO_PANEDR:\r
3692                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = PAN(EDR).\n"));\r
3693                                 halbtc8192e2ant_ActionPanEdr(pBtCoexist);\r
3694                                 break;\r
3695                         case BT_8192E_2ANT_COEX_ALGO_PANHS:\r
3696                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = HS mode.\n"));\r
3697                                 halbtc8192e2ant_ActionPanHs(pBtCoexist);\r
3698                                 break;\r
3699                         case BT_8192E_2ANT_COEX_ALGO_PANEDR_A2DP:\r
3700                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = PAN+A2DP.\n"));\r
3701                                 halbtc8192e2ant_ActionPanEdrA2dp(pBtCoexist);\r
3702                                 break;\r
3703                         case BT_8192E_2ANT_COEX_ALGO_PANEDR_HID:\r
3704                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = PAN(EDR)+HID.\n"));\r
3705                                 halbtc8192e2ant_ActionPanEdrHid(pBtCoexist);\r
3706                                 break;\r
3707                         case BT_8192E_2ANT_COEX_ALGO_HID_A2DP_PANEDR:\r
3708                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN.\n"));\r
3709                                 halbtc8192e2ant_ActionHidA2dpPanEdr(pBtCoexist);\r
3710                                 break;\r
3711                         case BT_8192E_2ANT_COEX_ALGO_HID_A2DP:\r
3712                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = HID+A2DP.\n"));\r
3713                                 halbtc8192e2ant_ActionHidA2dp(pBtCoexist);\r
3714                                 break;\r
3715                         default:\r
3716                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], Action 2-Ant, algorithm = unknown!!\n"));\r
3717                                 //halbtc8192e2ant_CoexAllOff(pBtCoexist);\r
3718                                 break;\r
3719                 }\r
3720                 pCoexDm->preAlgorithm = pCoexDm->curAlgorithm;\r
3721         }\r
3722 }\r
3723 \r
3724 VOID\r
3725 halbtc8192e2ant_InitHwConfig(\r
3726         IN      PBTC_COEXIST            pBtCoexist,\r
3727         IN      BOOLEAN                         bBackUp\r
3728         )\r
3729 {\r
3730         u4Byte  u4Tmp=0;\r
3731         u2Byte  u2Tmp=0;\r
3732         u1Byte  u1Tmp=0;\r
3733 \r
3734         BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], 2Ant Init HW Config!!\n"));\r
3735 \r
3736         if(bBackUp)\r
3737         {\r
3738                 // backup rf 0x1e value\r
3739                 pCoexDm->btRf0x1eBackup = \r
3740                         pBtCoexist->fBtcGetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff);\r
3741 \r
3742                 pCoexDm->backupArfrCnt1 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x430);\r
3743                 pCoexDm->backupArfrCnt2 = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x434);\r
3744                 pCoexDm->backupRetryLimit = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x42a);\r
3745                 pCoexDm->backupAmpduMaxTime = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x456);\r
3746         }\r
3747 \r
3748         // antenna sw ctrl to bt\r
3749         halbtc8192e2ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, TRUE, FALSE);\r
3750 \r
3751         halbtc8192e2ant_CoexTableWithType(pBtCoexist, FORCE_EXEC, 0);\r
3752 \r
3753         // antenna switch control parameter\r
3754         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x858, 0x55555555);\r
3755 \r
3756         // coex parameters\r
3757         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x778, 0x3);\r
3758         // 0x790[5:0]=0x5\r
3759         u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x790);\r
3760         u1Tmp &= 0xc0;\r
3761         u1Tmp |= 0x5;\r
3762         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x790, u1Tmp);\r
3763 \r
3764         // enable counter statistics\r
3765         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4);\r
3766 \r
3767         // enable PTA\r
3768         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0x20);\r
3769         // enable mailbox interface\r
3770         u2Tmp = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x40);\r
3771         u2Tmp |= BIT9;\r
3772         pBtCoexist->fBtcWrite2Byte(pBtCoexist, 0x40, u2Tmp);\r
3773 \r
3774         // enable PTA I2C mailbox \r
3775         u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x101);\r
3776         u1Tmp |= BIT4;\r
3777         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x101, u1Tmp);\r
3778 \r
3779         // enable bt clock when wifi is disabled.\r
3780         u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x93);\r
3781         u1Tmp |= BIT0;\r
3782         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x93, u1Tmp);\r
3783         // enable bt clock when suspend.\r
3784         u1Tmp = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x7);\r
3785         u1Tmp |= BIT0;\r
3786         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x7, u1Tmp);\r
3787 }\r
3788 \r
3789 //============================================================\r
3790 // work around function start with wa_halbtc8192e2ant_\r
3791 //============================================================\r
3792 //============================================================\r
3793 // extern function start with EXhalbtc8192e2ant_\r
3794 //============================================================\r
3795 VOID\r
3796 EXhalbtc8192e2ant_PowerOnSetting(\r
3797         IN      PBTC_COEXIST            pBtCoexist\r
3798         )\r
3799 {\r
3800 }\r
3801 \r
3802 VOID\r
3803 EXhalbtc8192e2ant_InitHwConfig(\r
3804         IN      PBTC_COEXIST            pBtCoexist,\r
3805         IN      BOOLEAN                         bWifiOnly\r
3806         )\r
3807 {\r
3808         halbtc8192e2ant_InitHwConfig(pBtCoexist, TRUE);\r
3809 }\r
3810 \r
3811 VOID\r
3812 EXhalbtc8192e2ant_InitCoexDm(\r
3813         IN      PBTC_COEXIST            pBtCoexist\r
3814         )\r
3815 {\r
3816         BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], Coex Mechanism Init!!\n"));\r
3817         \r
3818         halbtc8192e2ant_InitCoexDm(pBtCoexist);\r
3819 }\r
3820 \r
3821 VOID\r
3822 EXhalbtc8192e2ant_DisplayCoexInfo(\r
3823         IN      PBTC_COEXIST            pBtCoexist\r
3824         )\r
3825 {\r
3826         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;\r
3827         PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;\r
3828         pu1Byte                         cliBuf=pBtCoexist->cliBuf;\r
3829         u1Byte                          u1Tmp[4], i, btInfoExt, psTdmaCase=0;\r
3830         u2Byte                          u2Tmp[4];\r
3831         u4Byte                          u4Tmp[4];\r
3832         u4Byte                          faOfdm, faCck;\r
3833         u4Byte                          fwVer=0, btPatchVer=0;\r
3834 \r
3835         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[BT Coexist info]============");\r
3836         CL_PRINTF(cliBuf);\r
3837 \r
3838         if(pBtCoexist->bManualControl)\r
3839         {\r
3840                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[Under Manual Control]============");\r
3841                 CL_PRINTF(cliBuf);\r
3842                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ==========================================");\r
3843                 CL_PRINTF(cliBuf);\r
3844         }\r
3845 \r
3846         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ", "Ant PG number/ Ant mechanism:", \\r
3847                 pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum);\r
3848         CL_PRINTF(cliBuf);\r
3849         \r
3850         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d", "BT stack/ hci ext ver", \\r
3851                 ((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion);\r
3852         CL_PRINTF(cliBuf);\r
3853 \r
3854         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);\r
3855         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);\r
3856         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d_%d/ 0x%x/ 0x%x(%d)", "CoexVer/ FwVer/ PatchVer", \\r
3857                 GLCoexVerDate8192e2Ant, GLCoexVer8192e2Ant, fwVer, btPatchVer, btPatchVer);\r
3858         CL_PRINTF(cliBuf);\r
3859 \r
3860         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", "Wifi channel informed to BT", \\r
3861                 pCoexDm->wifiChnlInfo[0], pCoexDm->wifiChnlInfo[1],\r
3862                 pCoexDm->wifiChnlInfo[2]);\r
3863         CL_PRINTF(cliBuf);\r
3864 \r
3865         // wifi status\r
3866         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Wifi Status]============");\r
3867         CL_PRINTF(cliBuf);\r
3868         pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_WIFI_STATUS);\r
3869 \r
3870         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[BT Status]============");\r
3871         CL_PRINTF(cliBuf);\r
3872 \r
3873         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d] ", "BT [status/ rssi/ retryCnt]", \\r
3874                 ((pBtCoexist->btInfo.bBtDisabled)? ("disabled"):        ((pCoexSta->bC2hBtInquiryPage)?("inquiry/page scan"):((BT_8192E_2ANT_BT_STATUS_NON_CONNECTED_IDLE == pCoexDm->btStatus)? "non-connected idle":\r
3875                 (  (BT_8192E_2ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus)? "connected-idle":"busy")))),\r
3876                 pCoexSta->btRssi, pCoexSta->btRetryCnt);\r
3877         CL_PRINTF(cliBuf);\r
3878 \r
3879         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP", \\r
3880                 pStackInfo->bScoExist, pStackInfo->bHidExist, pStackInfo->bPanExist, pStackInfo->bA2dpExist);\r
3881         CL_PRINTF(cliBuf);\r
3882         pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_BT_LINK_INFO);\r
3883 \r
3884         btInfoExt = pCoexSta->btInfoExt;\r
3885         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "BT Info A2DP rate", \\r
3886                 (btInfoExt&BIT0)? "Basic rate":"EDR rate");\r
3887         CL_PRINTF(cliBuf);      \r
3888 \r
3889         for(i=0; i<BT_INFO_SRC_8192E_2ANT_MAX; i++)\r
3890         {\r
3891                 if(pCoexSta->btInfoC2hCnt[i])\r
3892                 {                               \r
3893                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", GLBtInfoSrc8192e2Ant[i], \\r
3894                                 pCoexSta->btInfoC2h[i][0], pCoexSta->btInfoC2h[i][1],\r
3895                                 pCoexSta->btInfoC2h[i][2], pCoexSta->btInfoC2h[i][3],\r
3896                                 pCoexSta->btInfoC2h[i][4], pCoexSta->btInfoC2h[i][5],\r
3897                                 pCoexSta->btInfoC2h[i][6], pCoexSta->btInfoC2hCnt[i]);\r
3898                         CL_PRINTF(cliBuf);\r
3899                 }\r
3900         }\r
3901 \r
3902         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ", "SS Type", \\r
3903                 pCoexDm->curSsType);\r
3904         CL_PRINTF(cliBuf);\r
3905 \r
3906         // Sw mechanism \r
3907         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw mechanism]============");\r
3908         CL_PRINTF(cliBuf);\r
3909         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d ", "SM1[ShRf/ LpRA/ LimDig]", \\r
3910                 pCoexDm->bCurRfRxLpfShrink, pCoexDm->bCurLowPenaltyRa, pCoexDm->bLimitedDig);\r
3911         CL_PRINTF(cliBuf);\r
3912         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d(0x%x) ", "SM2[AgcT/ AdcB/ SwDacSwing(lvl)]", \\r
3913                 pCoexDm->bCurAgcTableEn, pCoexDm->bCurAdcBackOff, pCoexDm->bCurDacSwingOn, pCoexDm->curDacSwingLvl);\r
3914         CL_PRINTF(cliBuf);\r
3915 \r
3916         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x ", "Rate Mask", \\r
3917                         pBtCoexist->btInfo.raMask);\r
3918         CL_PRINTF(cliBuf);\r
3919 \r
3920         // Fw mechanism         \r
3921         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw mechanism]============");\r
3922         CL_PRINTF(cliBuf);      \r
3923 \r
3924         psTdmaCase = pCoexDm->curPsTdma;\r
3925         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x case-%d (auto:%d)", "PS TDMA", \\r
3926                 pCoexDm->psTdmaPara[0], pCoexDm->psTdmaPara[1],\r
3927                 pCoexDm->psTdmaPara[2], pCoexDm->psTdmaPara[3],\r
3928                 pCoexDm->psTdmaPara[4], psTdmaCase, pCoexDm->bAutoTdmaAdjust);\r
3929         CL_PRINTF(cliBuf);\r
3930 \r
3931         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ", "DecBtPwr/ IgnWlanAct", \\r
3932                 pCoexDm->curBtDecPwrLvl, pCoexDm->bCurIgnoreWlanAct);\r
3933         CL_PRINTF(cliBuf);\r
3934 \r
3935         // Hw setting           \r
3936         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Hw setting]============");\r
3937         CL_PRINTF(cliBuf);      \r
3938 \r
3939         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "RF-A, 0x1e initVal", \\r
3940                 pCoexDm->btRf0x1eBackup);\r
3941         CL_PRINTF(cliBuf);\r
3942 \r
3943         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", "backup ARFR1/ARFR2/RL/AMaxTime", \\r
3944                 pCoexDm->backupArfrCnt1, pCoexDm->backupArfrCnt2, pCoexDm->backupRetryLimit, pCoexDm->backupAmpduMaxTime);\r
3945         CL_PRINTF(cliBuf);\r
3946 \r
3947         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x430);\r
3948         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x434);\r
3949         u2Tmp[0] = pBtCoexist->fBtcRead2Byte(pBtCoexist, 0x42a);\r
3950         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x456);\r
3951         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/0x%x/0x%x/0x%x", "0x430/0x434/0x42a/0x456", \\r
3952                 u4Tmp[0], u4Tmp[1], u2Tmp[0], u1Tmp[0]);\r
3953         CL_PRINTF(cliBuf);\r
3954 \r
3955         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xc04);\r
3956         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xd04);\r
3957         u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x90c);\r
3958         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0xc04/ 0xd04/ 0x90c", \\r
3959                 u4Tmp[0], u4Tmp[1], u4Tmp[2]);\r
3960         CL_PRINTF(cliBuf);\r
3961 \r
3962         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x778);\r
3963         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x778", \\r
3964                 u1Tmp[0]);\r
3965         CL_PRINTF(cliBuf);\r
3966         \r
3967         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x92c);\r
3968         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x930);\r
3969         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0x92c/ 0x930", \\r
3970                 (u1Tmp[0]), u4Tmp[0]);\r
3971         CL_PRINTF(cliBuf);\r
3972 \r
3973         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x40);\r
3974         u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x4f);\r
3975         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0x40/ 0x4f", \\r
3976                 u1Tmp[0], u1Tmp[1]);\r
3977         CL_PRINTF(cliBuf);\r
3978 \r
3979         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x550);\r
3980         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x522);\r
3981         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0x550(bcn ctrl)/0x522", \\r
3982                 u4Tmp[0], u1Tmp[0]);\r
3983         CL_PRINTF(cliBuf);\r
3984 \r
3985         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xc50);\r
3986         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0xc50(dig)", \\r
3987                 u4Tmp[0]);\r
3988         CL_PRINTF(cliBuf);\r
3989         \r
3990         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c0);\r
3991         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c4);\r
3992         u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c8);\r
3993         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x6cc);\r
3994         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)", \\r
3995                 u4Tmp[0], u4Tmp[1], u4Tmp[2], u1Tmp[0]);\r
3996         CL_PRINTF(cliBuf);\r
3997 \r
3998         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x770(hp rx[31:16]/tx[15:0])", \\r
3999                 pCoexSta->highPriorityRx, pCoexSta->highPriorityTx);\r
4000         CL_PRINTF(cliBuf);\r
4001         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x774(lp rx[31:16]/tx[15:0])", \\r
4002                 pCoexSta->lowPriorityRx, pCoexSta->lowPriorityTx);\r
4003         CL_PRINTF(cliBuf);\r
4004 #if(BT_AUTO_REPORT_ONLY_8192E_2ANT == 1)\r
4005         halbtc8192e2ant_MonitorBtCtr(pBtCoexist);\r
4006 #endif\r
4007         pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_COEX_STATISTICS);\r
4008 }\r
4009 \r
4010 \r
4011 VOID\r
4012 EXhalbtc8192e2ant_IpsNotify(\r
4013         IN      PBTC_COEXIST            pBtCoexist,\r
4014         IN      u1Byte                  type\r
4015         )\r
4016 {\r
4017         if(BTC_IPS_ENTER == type)\r
4018         {\r
4019                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], IPS ENTER notify\n"));\r
4020                 pCoexSta->bUnderIps = TRUE;\r
4021                 halbtc8192e2ant_CoexAllOff(pBtCoexist);\r
4022                 halbtc8192e2ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FALSE, TRUE);\r
4023         }\r
4024         else if(BTC_IPS_LEAVE == type)\r
4025         {\r
4026                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], IPS LEAVE notify\n"));\r
4027                 pCoexSta->bUnderIps = FALSE;\r
4028         }\r
4029 }\r
4030 \r
4031 VOID\r
4032 EXhalbtc8192e2ant_LpsNotify(\r
4033         IN      PBTC_COEXIST            pBtCoexist,\r
4034         IN      u1Byte                  type\r
4035         )\r
4036 {\r
4037         if(BTC_LPS_ENABLE == type)\r
4038         {\r
4039                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], LPS ENABLE notify\n"));\r
4040                 pCoexSta->bUnderLps = TRUE;\r
4041         }\r
4042         else if(BTC_LPS_DISABLE == type)\r
4043         {\r
4044                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], LPS DISABLE notify\n"));\r
4045                 pCoexSta->bUnderLps = FALSE;\r
4046         }\r
4047 }\r
4048 \r
4049 VOID\r
4050 EXhalbtc8192e2ant_ScanNotify(\r
4051         IN      PBTC_COEXIST            pBtCoexist,\r
4052         IN      u1Byte                  type\r
4053         )\r
4054 {\r
4055         if(BTC_SCAN_START == type)\r
4056         {\r
4057                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], SCAN START notify\n"));\r
4058         }\r
4059         else if(BTC_SCAN_FINISH == type)\r
4060         {\r
4061                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], SCAN FINISH notify\n"));\r
4062         }\r
4063 }\r
4064 \r
4065 VOID\r
4066 EXhalbtc8192e2ant_ConnectNotify(\r
4067         IN      PBTC_COEXIST            pBtCoexist,\r
4068         IN      u1Byte                  type\r
4069         )\r
4070 {\r
4071         if(BTC_ASSOCIATE_START == type)\r
4072         {\r
4073                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], CONNECT START notify\n"));\r
4074         }\r
4075         else if(BTC_ASSOCIATE_FINISH == type)\r
4076         {\r
4077                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], CONNECT FINISH notify\n"));\r
4078         }\r
4079 }\r
4080 \r
4081 VOID\r
4082 EXhalbtc8192e2ant_MediaStatusNotify(\r
4083         IN      PBTC_COEXIST            pBtCoexist,\r
4084         IN      u1Byte                          type\r
4085         )\r
4086 {\r
4087         u1Byte                  H2C_Parameter[3] ={0};\r
4088         u4Byte                  wifiBw;\r
4089         u1Byte                  wifiCentralChnl;\r
4090 \r
4091         if(pBtCoexist->bManualControl ||\r
4092                 pBtCoexist->bStopCoexDm ||\r
4093                 pBtCoexist->btInfo.bBtDisabled )\r
4094                 return;\r
4095 \r
4096         if(BTC_MEDIA_CONNECT == type)\r
4097         {\r
4098                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], MEDIA connect notify\n"));\r
4099         }\r
4100         else\r
4101         {\r
4102                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], MEDIA disconnect notify\n"));\r
4103         }\r
4104 \r
4105         // only 2.4G we need to inform bt the chnl mask\r
4106         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, &wifiCentralChnl);\r
4107         if( (BTC_MEDIA_CONNECT == type) &&\r
4108                 (wifiCentralChnl <= 14) )\r
4109         {\r
4110                 H2C_Parameter[0] = 0x1;\r
4111                 H2C_Parameter[1] = wifiCentralChnl;\r
4112                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
4113                 if(BTC_WIFI_BW_HT40 == wifiBw)\r
4114                         H2C_Parameter[2] = 0x30;\r
4115                 else\r
4116                         H2C_Parameter[2] = 0x20;\r
4117         }\r
4118         \r
4119         pCoexDm->wifiChnlInfo[0] = H2C_Parameter[0];\r
4120         pCoexDm->wifiChnlInfo[1] = H2C_Parameter[1];\r
4121         pCoexDm->wifiChnlInfo[2] = H2C_Parameter[2];\r
4122         \r
4123         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE_FW_EXEC, ("[BTCoex], FW write 0x66=0x%x\n", \r
4124                 H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));\r
4125 \r
4126         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x66, 3, H2C_Parameter);    \r
4127 }\r
4128 \r
4129 VOID\r
4130 EXhalbtc8192e2ant_SpecialPacketNotify(\r
4131         IN      PBTC_COEXIST                    pBtCoexist,\r
4132         IN      u1Byte                          type\r
4133         )\r
4134 {\r
4135         if(type == BTC_PACKET_DHCP)\r
4136         {\r
4137                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], DHCP Packet notify\n"));\r
4138         }\r
4139 }\r
4140 \r
4141 VOID\r
4142 EXhalbtc8192e2ant_BtInfoNotify(\r
4143         IN      PBTC_COEXIST            pBtCoexist,\r
4144         IN      pu1Byte                 tmpBuf,\r
4145         IN      u1Byte                  length\r
4146         )\r
4147 {\r
4148         PBTC_BT_LINK_INFO       pBtLinkInfo=&pBtCoexist->btLinkInfo;\r
4149         u1Byte                  btInfo=0;\r
4150         u1Byte                  i, rspSource=0;\r
4151         BOOLEAN                 bBtBusy=FALSE, bLimitedDig=FALSE;\r
4152         BOOLEAN                 bWifiConnected=FALSE;\r
4153 \r
4154         pCoexSta->bC2hBtInfoReqSent = FALSE;\r
4155 \r
4156         rspSource = tmpBuf[0]&0xf;\r
4157         if(rspSource >= BT_INFO_SRC_8192E_2ANT_MAX)\r
4158                 rspSource = BT_INFO_SRC_8192E_2ANT_WIFI_FW;\r
4159         pCoexSta->btInfoC2hCnt[rspSource]++;\r
4160 \r
4161         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Bt info[%d], length=%d, hex data=[", rspSource, length));\r
4162         for(i=0; i<length; i++)\r
4163         {\r
4164                 pCoexSta->btInfoC2h[rspSource][i] = tmpBuf[i];\r
4165                 if(i == 1)\r
4166                         btInfo = tmpBuf[i];\r
4167                 if(i == length-1)\r
4168                 {\r
4169                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("0x%02x]\n", tmpBuf[i]));\r
4170                 }\r
4171                 else\r
4172                 {\r
4173                         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("0x%02x, ", tmpBuf[i]));\r
4174                 }\r
4175         }\r
4176 \r
4177         if(BT_INFO_SRC_8192E_2ANT_WIFI_FW != rspSource)\r
4178         {\r
4179                 pCoexSta->btRetryCnt =  // [3:0]\r
4180                         pCoexSta->btInfoC2h[rspSource][2]&0xf;\r
4181 \r
4182                 pCoexSta->btRssi =\r
4183                         pCoexSta->btInfoC2h[rspSource][3]*2+10;\r
4184                 \r
4185                 pCoexSta->btInfoExt = \r
4186                         pCoexSta->btInfoC2h[rspSource][4];\r
4187 \r
4188                 // Here we need to resend some wifi info to BT\r
4189                 // because bt is reset and loss of the info.\r
4190                 if( (pCoexSta->btInfoExt & BIT1) )\r
4191                 {\r
4192                         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"));\r
4193                         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
4194                         if(bWifiConnected)\r
4195                         {\r
4196                                 EXhalbtc8192e2ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_CONNECT);\r
4197                         }\r
4198                         else\r
4199                         {\r
4200                                 EXhalbtc8192e2ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);\r
4201                         }\r
4202                 }\r
4203                 \r
4204                 if( (pCoexSta->btInfoExt & BIT3) )\r
4205                 {\r
4206                         if(!pBtCoexist->bManualControl && !pBtCoexist->bStopCoexDm)\r
4207                         {\r
4208                                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n"));\r
4209                                 halbtc8192e2ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, FALSE);\r
4210                         }\r
4211                 }\r
4212                 else\r
4213                 {\r
4214                         // BT already NOT ignore Wlan active, do nothing here.\r
4215                 }\r
4216 \r
4217 #if(BT_AUTO_REPORT_ONLY_8192E_2ANT == 0)\r
4218                 if( (pCoexSta->btInfoExt & BIT4) )\r
4219                 {\r
4220                         // BT auto report already enabled, do nothing\r
4221                 }\r
4222                 else\r
4223                 {\r
4224                         halbtc8192e2ant_BtAutoReport(pBtCoexist, FORCE_EXEC, TRUE);\r
4225                 }\r
4226 #endif\r
4227         }\r
4228 \r
4229         // check BIT2 first ==> check if bt is under inquiry or page scan\r
4230         if(btInfo & BT_INFO_8192E_2ANT_B_INQ_PAGE)\r
4231                 pCoexSta->bC2hBtInquiryPage = TRUE;\r
4232         else\r
4233                 pCoexSta->bC2hBtInquiryPage = FALSE;\r
4234 \r
4235         // set link exist status\r
4236         if(!(btInfo&BT_INFO_8192E_2ANT_B_CONNECTION))\r
4237         {\r
4238                 pCoexSta->bBtLinkExist = FALSE;\r
4239                 pCoexSta->bPanExist = FALSE;\r
4240                 pCoexSta->bA2dpExist = FALSE;\r
4241                 pCoexSta->bHidExist = FALSE;\r
4242                 pCoexSta->bScoExist = FALSE;\r
4243         }\r
4244         else    // connection exists\r
4245         {\r
4246                 pCoexSta->bBtLinkExist = TRUE;\r
4247                 if(btInfo & BT_INFO_8192E_2ANT_B_FTP)\r
4248                         pCoexSta->bPanExist = TRUE;\r
4249                 else\r
4250                         pCoexSta->bPanExist = FALSE;\r
4251                 if(btInfo & BT_INFO_8192E_2ANT_B_A2DP)\r
4252                         pCoexSta->bA2dpExist = TRUE;\r
4253                 else\r
4254                         pCoexSta->bA2dpExist = FALSE;\r
4255                 if(btInfo & BT_INFO_8192E_2ANT_B_HID)\r
4256                         pCoexSta->bHidExist = TRUE;\r
4257                 else\r
4258                         pCoexSta->bHidExist = FALSE;\r
4259                 if(btInfo & BT_INFO_8192E_2ANT_B_SCO_ESCO)\r
4260                         pCoexSta->bScoExist = TRUE;\r
4261                 else\r
4262                         pCoexSta->bScoExist = FALSE;\r
4263         }\r
4264 \r
4265         halbtc8192e2ant_UpdateBtLinkInfo(pBtCoexist);\r
4266         \r
4267         if(!(btInfo&BT_INFO_8192E_2ANT_B_CONNECTION))\r
4268         {\r
4269                 pCoexDm->btStatus = BT_8192E_2ANT_BT_STATUS_NON_CONNECTED_IDLE;\r
4270                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n"));\r
4271         }\r
4272         else if(btInfo == BT_INFO_8192E_2ANT_B_CONNECTION)      // connection exists but no busy\r
4273         {\r
4274                 pCoexDm->btStatus = BT_8192E_2ANT_BT_STATUS_CONNECTED_IDLE;\r
4275                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n"));\r
4276         }\r
4277         else if((btInfo&BT_INFO_8192E_2ANT_B_SCO_ESCO) ||\r
4278                 (btInfo&BT_INFO_8192E_2ANT_B_SCO_BUSY))\r
4279         {\r
4280                 pCoexDm->btStatus = BT_8192E_2ANT_BT_STATUS_SCO_BUSY;\r
4281                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT SCO busy!!!\n"));\r
4282         }\r
4283         else if(btInfo&BT_INFO_8192E_2ANT_B_ACL_BUSY)\r
4284         {\r
4285                 pCoexDm->btStatus = BT_8192E_2ANT_BT_STATUS_ACL_BUSY;\r
4286                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT ACL busy!!!\n"));\r
4287         }\r
4288         else\r
4289         {\r
4290                 pCoexDm->btStatus = BT_8192E_2ANT_BT_STATUS_MAX;\r
4291                 BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n"));\r
4292         }\r
4293         \r
4294         if( (BT_8192E_2ANT_BT_STATUS_ACL_BUSY == pCoexDm->btStatus) ||\r
4295                 (BT_8192E_2ANT_BT_STATUS_SCO_BUSY == pCoexDm->btStatus) ||\r
4296                 (BT_8192E_2ANT_BT_STATUS_ACL_SCO_BUSY == pCoexDm->btStatus) )\r
4297         {\r
4298                 bBtBusy = TRUE;\r
4299                 bLimitedDig = TRUE;\r
4300         }\r
4301         else\r
4302         {\r
4303                 bBtBusy = FALSE;\r
4304                 bLimitedDig = FALSE;\r
4305         }\r
4306 \r
4307         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);\r
4308 \r
4309         pCoexDm->bLimitedDig = bLimitedDig;\r
4310         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_LIMITED_DIG, &bLimitedDig);\r
4311 \r
4312         halbtc8192e2ant_RunCoexistMechanism(pBtCoexist);\r
4313 }\r
4314 \r
4315 VOID\r
4316 EXhalbtc8192e2ant_HaltNotify(\r
4317         IN      PBTC_COEXIST                    pBtCoexist\r
4318         )\r
4319 {\r
4320         BTC_PRINT(BTC_MSG_INTERFACE, INTF_NOTIFY, ("[BTCoex], Halt notify\n"));\r
4321 \r
4322         halbtc8192e2ant_SetAntPath(pBtCoexist, BTC_ANT_PATH_BT, FALSE, TRUE);\r
4323         halbtc8192e2ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE);\r
4324         EXhalbtc8192e2ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);\r
4325 }\r
4326 \r
4327 VOID\r
4328 EXhalbtc8192e2ant_Periodical(\r
4329         IN      PBTC_COEXIST                    pBtCoexist\r
4330         )\r
4331 {\r
4332         static u1Byte           disVerInfoCnt=0;\r
4333         u4Byte                          fwVer=0, btPatchVer=0;\r
4334         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;\r
4335         PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;\r
4336 \r
4337         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, ("[BTCoex], ==========================Periodical===========================\n"));\r
4338 \r
4339         if(disVerInfoCnt <= 5)\r
4340         {\r
4341                 disVerInfoCnt += 1;\r
4342                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], ****************************************************************\n"));\r
4343                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], Ant PG Num/ Ant Mech/ Ant Pos = %d/ %d/ %d\n", \\r
4344                         pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum, pBoardInfo->btdmAntPos));\r
4345                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], BT stack/ hci ext ver = %s / %d\n", \\r
4346                         ((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion));\r
4347                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_BT_PATCH_VER, &btPatchVer);\r
4348                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_FW_VER, &fwVer);\r
4349                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], CoexVer/ FwVer/ PatchVer = %d_%x/ 0x%x/ 0x%x(%d)\n", \\r
4350                         GLCoexVerDate8192e2Ant, GLCoexVer8192e2Ant, fwVer, btPatchVer, btPatchVer));\r
4351                 BTC_PRINT(BTC_MSG_INTERFACE, INTF_INIT, ("[BTCoex], ****************************************************************\n"));\r
4352         }\r
4353 \r
4354 #if(BT_AUTO_REPORT_ONLY_8192E_2ANT == 0)\r
4355         halbtc8192e2ant_QueryBtInfo(pBtCoexist);\r
4356         halbtc8192e2ant_MonitorBtCtr(pBtCoexist);\r
4357         halbtc8192e2ant_MonitorBtEnableDisable(pBtCoexist);\r
4358 #else\r
4359         if( halbtc8192e2ant_IsWifiStatusChanged(pBtCoexist) ||\r
4360                 pCoexDm->bAutoTdmaAdjust)\r
4361         {\r
4362                 halbtc8192e2ant_RunCoexistMechanism(pBtCoexist);\r
4363         }\r
4364 #endif\r
4365 }\r
4366 \r
4367 \r
4368 #endif\r
4369 \r