8723BU: Update 8723BU wifi driver to version v4.3.16_14189.20150519_BTCOEX2015119...
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723bu / hal / OUTSRC-BTCoexist / HalBtc8723a2Ant.c
1 //============================================================\r
2 // Description:\r
3 //\r
4 // This file is for RTL8723A Co-exist mechanism\r
5 //\r
6 // History\r
7 // 2012/08/22 Cosa first check in.\r
8 // 2012/11/14 Cosa Revise for 8723A 2Ant out sourcing.\r
9 //\r
10 //============================================================\r
11 \r
12 //============================================================\r
13 // include files\r
14 //============================================================\r
15 #include "Mp_Precomp.h"\r
16 \r
17 #if WPP_SOFTWARE_TRACE\r
18 #include "HalBtc8723a2Ant.tmh"\r
19 #endif\r
20 \r
21 #if(BT_30_SUPPORT == 1)\r
22 //============================================================\r
23 // Global variables, these are static variables\r
24 //============================================================\r
25 static COEX_DM_8723A_2ANT       GLCoexDm8723a2Ant;\r
26 static PCOEX_DM_8723A_2ANT      pCoexDm=&GLCoexDm8723a2Ant;\r
27 static COEX_STA_8723A_2ANT      GLCoexSta8723a2Ant;\r
28 static PCOEX_STA_8723A_2ANT     pCoexSta=&GLCoexSta8723a2Ant;\r
29 \r
30 const char *const GLBtInfoSrc8723a2Ant[]={\r
31         "BT Info[wifi fw]",\r
32         "BT Info[bt rsp]",\r
33         "BT Info[bt auto report]",\r
34 };\r
35 \r
36 //============================================================\r
37 // local function proto type if needed\r
38 //============================================================\r
39 //============================================================\r
40 // local function start with halbtc8723a2ant_\r
41 //============================================================\r
42 BOOLEAN\r
43 halbtc8723a2ant_IsWifiIdle(\r
44         IN      PBTC_COEXIST            pBtCoexist\r
45         )\r
46 {\r
47         BOOLEAN         bWifiConnected=FALSE, bScan=FALSE, bLink=FALSE, bRoam=FALSE;\r
48 \r
49         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
50         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);\r
51         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);\r
52         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);\r
53 \r
54         if(bWifiConnected)\r
55                 return FALSE;\r
56         if(bScan)\r
57                 return FALSE;\r
58         if(bLink)\r
59                 return FALSE;\r
60         if(bRoam)\r
61                 return FALSE;\r
62 \r
63         return TRUE;\r
64 }\r
65 \r
66 BOOLEAN\r
67 halbtc8723a2ant_IsWifiConnectedIdle(\r
68         IN      PBTC_COEXIST            pBtCoexist\r
69         )\r
70 {\r
71         BOOLEAN         bWifiConnected=FALSE, bScan=FALSE, bLink=FALSE, bRoam=FALSE, bWifiBusy=FALSE;\r
72 \r
73         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
74         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);\r
75         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);\r
76         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);\r
77         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_BUSY, &bWifiBusy);\r
78 \r
79         if(bScan)\r
80                 return FALSE;\r
81         if(bLink)\r
82                 return FALSE;\r
83         if(bRoam)\r
84                 return FALSE;\r
85         if(bWifiConnected && !bWifiBusy)\r
86                 return TRUE;\r
87         else \r
88                 return FALSE;\r
89 }\r
90 \r
91 u1Byte\r
92 halbtc8723a2ant_BtRssiState(\r
93         u1Byte                  levelNum,\r
94         u1Byte                  rssiThresh,\r
95         u1Byte                  rssiThresh1\r
96         )\r
97 {\r
98         s4Byte                  btRssi=0;\r
99         u1Byte                  btRssiState=pCoexSta->preBtRssiState;\r
100 \r
101         btRssi = pCoexSta->btRssi;\r
102 \r
103         if(levelNum == 2)\r
104         {                       \r
105                 if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||\r
106                         (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW))\r
107                 {\r
108                         if(btRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8723A_2ANT))\r
109                         {\r
110                                 btRssiState = BTC_RSSI_STATE_HIGH;\r
111                         }\r
112                         else\r
113                         {\r
114                                 btRssiState = BTC_RSSI_STATE_STAY_LOW;\r
115                         }\r
116                 }\r
117                 else\r
118                 {\r
119                         if(btRssi < rssiThresh)\r
120                         {\r
121                                 btRssiState = BTC_RSSI_STATE_LOW;\r
122                         }\r
123                         else\r
124                         {\r
125                                 btRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
126                         }\r
127                 }\r
128         }\r
129         else if(levelNum == 3)\r
130         {\r
131                 if(rssiThresh > rssiThresh1)\r
132                 {\r
133                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT Rssi thresh error!!\n"));\r
134                         return pCoexSta->preBtRssiState;\r
135                 }\r
136                 \r
137                 if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_LOW) ||\r
138                         (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_LOW))\r
139                 {\r
140                         if(btRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8723A_2ANT))\r
141                         {\r
142                                 btRssiState = BTC_RSSI_STATE_MEDIUM;\r
143                         }\r
144                         else\r
145                         {\r
146                                 btRssiState = BTC_RSSI_STATE_STAY_LOW;\r
147                         }\r
148                 }\r
149                 else if( (pCoexSta->preBtRssiState == BTC_RSSI_STATE_MEDIUM) ||\r
150                         (pCoexSta->preBtRssiState == BTC_RSSI_STATE_STAY_MEDIUM))\r
151                 {\r
152                         if(btRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8723A_2ANT))\r
153                         {\r
154                                 btRssiState = BTC_RSSI_STATE_HIGH;\r
155                         }\r
156                         else if(btRssi < rssiThresh)\r
157                         {\r
158                                 btRssiState = BTC_RSSI_STATE_LOW;\r
159                         }\r
160                         else\r
161                         {\r
162                                 btRssiState = BTC_RSSI_STATE_STAY_MEDIUM;\r
163                         }\r
164                 }\r
165                 else\r
166                 {\r
167                         if(btRssi < rssiThresh1)\r
168                         {\r
169                                 btRssiState = BTC_RSSI_STATE_MEDIUM;\r
170                         }\r
171                         else\r
172                         {\r
173                                 btRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
174                         }\r
175                 }\r
176         }\r
177                 \r
178         pCoexSta->preBtRssiState = btRssiState;\r
179 \r
180         return btRssiState;\r
181 }\r
182 \r
183 u1Byte\r
184 halbtc8723a2ant_WifiRssiState(\r
185         IN      PBTC_COEXIST            pBtCoexist,\r
186         IN      u1Byte                  index,\r
187         IN      u1Byte                  levelNum,\r
188         IN      u1Byte                  rssiThresh,\r
189         IN      u1Byte                  rssiThresh1\r
190         )\r
191 {\r
192         s4Byte                  wifiRssi=0;\r
193         u1Byte                  wifiRssiState=pCoexSta->preWifiRssiState[index];\r
194 \r
195         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_WIFI_RSSI, &wifiRssi);\r
196         \r
197         if(levelNum == 2)\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_8723A_2ANT))\r
203                         {\r
204                                 wifiRssiState = BTC_RSSI_STATE_HIGH;\r
205                         }\r
206                         else\r
207                         {\r
208                                 wifiRssiState = BTC_RSSI_STATE_STAY_LOW;\r
209                         }\r
210                 }\r
211                 else\r
212                 {\r
213                         if(wifiRssi < rssiThresh)\r
214                         {\r
215                                 wifiRssiState = BTC_RSSI_STATE_LOW;\r
216                         }\r
217                         else\r
218                         {\r
219                                 wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
220                         }\r
221                 }\r
222         }\r
223         else if(levelNum == 3)\r
224         {\r
225                 if(rssiThresh > rssiThresh1)\r
226                 {\r
227                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], wifi RSSI thresh error!!\n"));\r
228                         return pCoexSta->preWifiRssiState[index];\r
229                 }\r
230                 \r
231                 if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_LOW) ||\r
232                         (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_LOW))\r
233                 {\r
234                         if(wifiRssi >= (rssiThresh+BTC_RSSI_COEX_THRESH_TOL_8723A_2ANT))\r
235                         {\r
236                                 wifiRssiState = BTC_RSSI_STATE_MEDIUM;\r
237                         }\r
238                         else\r
239                         {\r
240                                 wifiRssiState = BTC_RSSI_STATE_STAY_LOW;\r
241                         }\r
242                 }\r
243                 else if( (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_MEDIUM) ||\r
244                         (pCoexSta->preWifiRssiState[index] == BTC_RSSI_STATE_STAY_MEDIUM))\r
245                 {\r
246                         if(wifiRssi >= (rssiThresh1+BTC_RSSI_COEX_THRESH_TOL_8723A_2ANT))\r
247                         {\r
248                                 wifiRssiState = BTC_RSSI_STATE_HIGH;\r
249                         }\r
250                         else if(wifiRssi < rssiThresh)\r
251                         {\r
252                                 wifiRssiState = BTC_RSSI_STATE_LOW;\r
253                         }\r
254                         else\r
255                         {\r
256                                 wifiRssiState = BTC_RSSI_STATE_STAY_MEDIUM;\r
257                         }\r
258                 }\r
259                 else\r
260                 {\r
261                         if(wifiRssi < rssiThresh1)\r
262                         {\r
263                                 wifiRssiState = BTC_RSSI_STATE_MEDIUM;\r
264                         }\r
265                         else\r
266                         {\r
267                                 wifiRssiState = BTC_RSSI_STATE_STAY_HIGH;\r
268                         }\r
269                 }\r
270         }\r
271                 \r
272         pCoexSta->preWifiRssiState[index] = wifiRssiState;\r
273 \r
274         return wifiRssiState;\r
275 }\r
276 \r
277 VOID\r
278 halbtc8723a2ant_IndicateWifiChnlBwInfo(\r
279         IN      PBTC_COEXIST                    pBtCoexist,\r
280         IN      u1Byte                          type\r
281         )\r
282 {\r
283         u1Byte                  H2C_Parameter[3] ={0};\r
284         u4Byte                  wifiBw;\r
285         u1Byte                  wifiCentralChnl;\r
286         \r
287         // only 2.4G we need to inform bt the chnl mask\r
288         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U1_WIFI_CENTRAL_CHNL, &wifiCentralChnl);\r
289         if( (BTC_MEDIA_CONNECT == type) &&\r
290                 (wifiCentralChnl <= 14) )\r
291         {\r
292                 H2C_Parameter[0] = 0x1;\r
293                 H2C_Parameter[1] = wifiCentralChnl;\r
294                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
295                 if(BTC_WIFI_BW_HT40 == wifiBw)\r
296                         H2C_Parameter[2] = 0x30;\r
297                 else\r
298                         H2C_Parameter[2] = 0x20;\r
299         }\r
300                 \r
301         pCoexDm->wifiChnlInfo[0] = H2C_Parameter[0];\r
302         pCoexDm->wifiChnlInfo[1] = H2C_Parameter[1];\r
303         pCoexDm->wifiChnlInfo[2] = H2C_Parameter[2];\r
304         \r
305         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], FW write 0x19=0x%x\n", \r
306                 H2C_Parameter[0]<<16|H2C_Parameter[1]<<8|H2C_Parameter[2]));\r
307 \r
308         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x19, 3, H2C_Parameter);\r
309 }\r
310 \r
311 VOID\r
312 halbtc8723a2ant_QueryBtInfo(\r
313         IN      PBTC_COEXIST            pBtCoexist\r
314         )\r
315 {\r
316         u1Byte                  H2C_Parameter[1] ={0};\r
317 \r
318         pCoexSta->bC2hBtInfoReqSent = TRUE;\r
319 \r
320         H2C_Parameter[0] |= BIT0;       // trigger\r
321 \r
322         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Query Bt Info, FW write 0x38=0x%x\n", \r
323                 H2C_Parameter[0]));\r
324 \r
325         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x38, 1, H2C_Parameter);\r
326 }\r
327 u1Byte\r
328 halbtc8723a2ant_ActionAlgorithm(\r
329         IN      PBTC_COEXIST            pBtCoexist\r
330         )\r
331 {\r
332         PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;\r
333         BOOLEAN                         bBtHsOn=FALSE, bBtBusy=FALSE, bLimitedDig=FALSE;\r
334         u1Byte                          algorithm=BT_8723A_2ANT_COEX_ALGO_UNDEFINED;\r
335         u1Byte                          numOfDiffProfile=0;\r
336 \r
337         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
338 \r
339         //======================\r
340         // here we get BT status first\r
341         //======================\r
342         pCoexDm->btStatus = BT_8723A_2ANT_BT_STATUS_IDLE;\r
343         \r
344         if((pStackInfo->bScoExist) ||(bBtHsOn) ||(pStackInfo->bHidExist))\r
345         {\r
346                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO or HID or HS exists, set BT non-idle !!!\n"));\r
347                 pCoexDm->btStatus = BT_8723A_2ANT_BT_STATUS_NON_IDLE;\r
348         }\r
349         else\r
350         {\r
351                 // A2dp profile\r
352                 if( (pBtCoexist->stackInfo.numOfLink == 1) &&\r
353                         (pStackInfo->bA2dpExist) )\r
354                 {               \r
355                         if( (pCoexSta->lowPriorityTx+   pCoexSta->lowPriorityRx) < 100)\r
356                         {\r
357                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], A2DP, low priority tx+rx < 100, set BT connected-idle!!!\n"));\r
358                                 pCoexDm->btStatus = BT_8723A_2ANT_BT_STATUS_CONNECTED_IDLE;\r
359                         }\r
360                         else\r
361                         {\r
362                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], A2DP, low priority tx+rx >= 100, set BT non-idle!!!\n"));\r
363                                 pCoexDm->btStatus = BT_8723A_2ANT_BT_STATUS_NON_IDLE;\r
364                         }\r
365                 }\r
366                 // Pan profile\r
367                 if( (pBtCoexist->stackInfo.numOfLink == 1) &&\r
368                         (pStackInfo->bPanExist) )\r
369                 {               \r
370                         if((pCoexSta->lowPriorityTx+    pCoexSta->lowPriorityRx) < 600)\r
371                         {\r
372                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], PAN, low priority tx+rx < 600, set BT connected-idle!!!\n"));\r
373                                 pCoexDm->btStatus = BT_8723A_2ANT_BT_STATUS_CONNECTED_IDLE;\r
374                         }\r
375                         else\r
376                         {\r
377                                 if(pCoexSta->lowPriorityTx)\r
378                                 {\r
379                                         if((pCoexSta->lowPriorityRx /pCoexSta->lowPriorityTx)>9 )\r
380                                         {\r
381                                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], PAN, low priority rx/tx > 9, set BT connected-idle!!!\n"));\r
382                                                 pCoexDm->btStatus = BT_8723A_2ANT_BT_STATUS_CONNECTED_IDLE;\r
383                                         }\r
384                                 }\r
385                         }\r
386                         if(BT_8723A_2ANT_BT_STATUS_CONNECTED_IDLE != pCoexDm->btStatus)\r
387                         {\r
388                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], PAN, set BT non-idle!!!\n"));\r
389                                 pCoexDm->btStatus = BT_8723A_2ANT_BT_STATUS_NON_IDLE;\r
390                         }\r
391                 }\r
392                 // Pan+A2dp profile\r
393                 if( (pBtCoexist->stackInfo.numOfLink == 2) &&\r
394                         (pStackInfo->bA2dpExist) &&\r
395                         (pStackInfo->bPanExist) )\r
396                 {\r
397                         if((pCoexSta->lowPriorityTx+    pCoexSta->lowPriorityRx) < 600)\r
398                         {\r
399                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], PAN+A2DP, low priority tx+rx < 600, set BT connected-idle!!!\n"));\r
400                                 pCoexDm->btStatus = BT_8723A_2ANT_BT_STATUS_CONNECTED_IDLE;\r
401                         }\r
402                         else\r
403                         {\r
404                                 if(pCoexSta->lowPriorityTx)\r
405                                 {\r
406                                         if((pCoexSta->lowPriorityRx /pCoexSta->lowPriorityTx)>9 )\r
407                                         {\r
408                                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], PAN+A2DP, low priority rx/tx > 9, set BT connected-idle!!!\n"));\r
409                                                 pCoexDm->btStatus = BT_8723A_2ANT_BT_STATUS_CONNECTED_IDLE;\r
410                                         }\r
411                                 }\r
412                         }\r
413                         if(BT_8723A_2ANT_BT_STATUS_CONNECTED_IDLE != pCoexDm->btStatus)\r
414                         {\r
415                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], PAN+A2DP, set BT non-idle!!!\n"));\r
416                                 pCoexDm->btStatus = BT_8723A_2ANT_BT_STATUS_NON_IDLE;\r
417                         }\r
418                 }\r
419         }\r
420         if(BT_8723A_2ANT_BT_STATUS_IDLE != pCoexDm->btStatus)\r
421         {\r
422                 bBtBusy = TRUE;\r
423                 bLimitedDig = TRUE;\r
424         }\r
425         else\r
426         {\r
427                 bBtBusy = FALSE;\r
428                 bLimitedDig = FALSE;\r
429         }\r
430         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bBtBusy);\r
431         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_LIMITED_DIG, &bLimitedDig);\r
432         //======================\r
433 \r
434         if(!pStackInfo->bBtLinkExist)\r
435         {\r
436                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], No profile exists!!!\n"));\r
437                 return algorithm;\r
438         }\r
439 \r
440         if(pStackInfo->bScoExist)\r
441                 numOfDiffProfile++;\r
442         if(pStackInfo->bHidExist)\r
443                 numOfDiffProfile++;\r
444         if(pStackInfo->bPanExist)\r
445                 numOfDiffProfile++;\r
446         if(pStackInfo->bA2dpExist)\r
447                 numOfDiffProfile++;\r
448         \r
449         if(numOfDiffProfile == 1)\r
450         {\r
451                 if(pStackInfo->bScoExist)\r
452                 {\r
453                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO only\n"));\r
454                         algorithm = BT_8723A_2ANT_COEX_ALGO_SCO;\r
455                 }\r
456                 else\r
457                 {\r
458                         if(pStackInfo->bHidExist)\r
459                         {\r
460                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], HID only\n"));\r
461                                 algorithm = BT_8723A_2ANT_COEX_ALGO_HID;\r
462                         }\r
463                         else if(pStackInfo->bA2dpExist)\r
464                         {\r
465                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], A2DP only\n"));\r
466                                 algorithm = BT_8723A_2ANT_COEX_ALGO_A2DP;\r
467                         }\r
468                         else if(pStackInfo->bPanExist)\r
469                         {\r
470                                 if(bBtHsOn)\r
471                                 {\r
472                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], PAN(HS) only\n"));\r
473                                         algorithm = BT_8723A_2ANT_COEX_ALGO_PANHS;\r
474                                 }\r
475                                 else\r
476                                 {\r
477                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], PAN(EDR) only\n"));\r
478                                         algorithm = BT_8723A_2ANT_COEX_ALGO_PANEDR;\r
479                                 }\r
480                         }\r
481                 }\r
482         }\r
483         else if(numOfDiffProfile == 2)\r
484         {\r
485                 if(pStackInfo->bScoExist)\r
486                 {\r
487                         if(pStackInfo->bHidExist)\r
488                         {\r
489                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + HID\n"));\r
490                                 algorithm = BT_8723A_2ANT_COEX_ALGO_HID;\r
491                         }\r
492                         else if(pStackInfo->bA2dpExist)\r
493                         {\r
494                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + A2DP ==> SCO\n"));\r
495                                 algorithm = BT_8723A_2ANT_COEX_ALGO_SCO;\r
496                         }\r
497                         else if(pStackInfo->bPanExist)\r
498                         {\r
499                                 if(bBtHsOn)\r
500                                 {\r
501                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + PAN(HS)\n"));\r
502                                         algorithm = BT_8723A_2ANT_COEX_ALGO_SCO;\r
503                                 }\r
504                                 else\r
505                                 {\r
506                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + PAN(EDR)\n"));\r
507                                         algorithm = BT_8723A_2ANT_COEX_ALGO_PANEDR_HID;\r
508                                 }\r
509                         }\r
510                 }\r
511                 else\r
512                 {\r
513                         if( pStackInfo->bHidExist &&\r
514                                 pStackInfo->bA2dpExist )\r
515                         {\r
516                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], HID + A2DP\n"));\r
517                                 algorithm = BT_8723A_2ANT_COEX_ALGO_HID_A2DP;\r
518                         }\r
519                         else if( pStackInfo->bHidExist &&\r
520                                 pStackInfo->bPanExist )\r
521                         {\r
522                                 if(bBtHsOn)\r
523                                 {\r
524                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], HID + PAN(HS)\n"));\r
525                                         algorithm = BT_8723A_2ANT_COEX_ALGO_HID_A2DP;\r
526                                 }\r
527                                 else\r
528                                 {\r
529                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], HID + PAN(EDR)\n"));\r
530                                         algorithm = BT_8723A_2ANT_COEX_ALGO_PANEDR_HID;\r
531                                 }\r
532                         }\r
533                         else if( pStackInfo->bPanExist &&\r
534                                 pStackInfo->bA2dpExist )\r
535                         {\r
536                                 if(bBtHsOn)\r
537                                 {\r
538                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], A2DP + PAN(HS)\n"));\r
539                                         algorithm = BT_8723A_2ANT_COEX_ALGO_A2DP;\r
540                                 }\r
541                                 else\r
542                                 {\r
543                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], A2DP + PAN(EDR)\n"));\r
544                                         algorithm = BT_8723A_2ANT_COEX_ALGO_PANEDR_A2DP;\r
545                                 }\r
546                         }\r
547                 }\r
548         }\r
549         else if(numOfDiffProfile == 3)\r
550         {\r
551                 if(pStackInfo->bScoExist)\r
552                 {\r
553                         if( pStackInfo->bHidExist &&\r
554                                 pStackInfo->bA2dpExist )\r
555                         {\r
556                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + HID + A2DP ==> HID\n"));\r
557                                 algorithm = BT_8723A_2ANT_COEX_ALGO_HID;\r
558                         }\r
559                         else if( pStackInfo->bHidExist &&\r
560                                 pStackInfo->bPanExist )\r
561                         {\r
562                                 if(bBtHsOn)\r
563                                 {\r
564                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + HID + PAN(HS)\n"));\r
565                                         algorithm = BT_8723A_2ANT_COEX_ALGO_HID_A2DP;\r
566                                 }\r
567                                 else\r
568                                 {\r
569                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + HID + PAN(EDR)\n"));\r
570                                         algorithm = BT_8723A_2ANT_COEX_ALGO_PANEDR_HID;\r
571                                 }\r
572                         }\r
573                         else if( pStackInfo->bPanExist &&\r
574                                 pStackInfo->bA2dpExist )\r
575                         {\r
576                                 if(bBtHsOn)\r
577                                 {\r
578                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + A2DP + PAN(HS)\n"));\r
579                                         algorithm = BT_8723A_2ANT_COEX_ALGO_SCO;\r
580                                 }\r
581                                 else\r
582                                 {\r
583                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + A2DP + PAN(EDR) ==> HID\n"));\r
584                                         algorithm = BT_8723A_2ANT_COEX_ALGO_PANEDR_HID;\r
585                                 }\r
586                         }\r
587                 }\r
588                 else\r
589                 {\r
590                         if( pStackInfo->bHidExist &&\r
591                                 pStackInfo->bPanExist &&\r
592                                 pStackInfo->bA2dpExist )\r
593                         {\r
594                                 if(bBtHsOn)\r
595                                 {\r
596                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], HID + A2DP + PAN(HS)\n"));\r
597                                         algorithm = BT_8723A_2ANT_COEX_ALGO_HID_A2DP;\r
598                                 }\r
599                                 else\r
600                                 {\r
601                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], HID + A2DP + PAN(EDR)\n"));\r
602                                         algorithm = BT_8723A_2ANT_COEX_ALGO_HID_A2DP_PANEDR;\r
603                                 }\r
604                         }\r
605                 }\r
606         }\r
607         else if(numOfDiffProfile >= 3)\r
608         {\r
609                 if(pStackInfo->bScoExist)\r
610                 {\r
611                         if( pStackInfo->bHidExist &&\r
612                                 pStackInfo->bPanExist &&\r
613                                 pStackInfo->bA2dpExist )\r
614                         {\r
615                                 if(bBtHsOn)\r
616                                 {\r
617                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n"));\r
618 \r
619                                 }\r
620                                 else\r
621                                 {\r
622                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n"));\r
623                                         algorithm = BT_8723A_2ANT_COEX_ALGO_PANEDR_HID;\r
624                                 }\r
625                         }\r
626                 }\r
627         }\r
628 \r
629         return algorithm;\r
630 }\r
631 \r
632 BOOLEAN\r
633 halbtc8723a2ant_NeedToDecBtPwr(\r
634         IN      PBTC_COEXIST            pBtCoexist\r
635         )\r
636 {\r
637         BOOLEAN         bRet=FALSE;\r
638         BOOLEAN         bBtHsOn=FALSE, bWifiConnected=FALSE;\r
639         s4Byte          btHsRssi=0;\r
640         u1Byte          btRssiState=BTC_RSSI_STATE_HIGH;\r
641 \r
642         btRssiState = halbtc8723a2ant_BtRssiState(2, 42, 0);\r
643 \r
644         if(!pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn))\r
645                 return FALSE;\r
646         if(!pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected))\r
647                 return FALSE;\r
648         if(!pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_S4_HS_RSSI, &btHsRssi))\r
649                 return FALSE;\r
650         if(BTC_RSSI_LOW(btRssiState))\r
651                 return FALSE;\r
652 \r
653         if(bWifiConnected)\r
654         {\r
655                 if(bBtHsOn)\r
656                 {\r
657                         if(btHsRssi > 37)\r
658                         {\r
659                                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Need to decrease bt power for HS mode!!\n"));\r
660                                 bRet = TRUE;\r
661                         }\r
662                 }\r
663                 else\r
664                 {\r
665                         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Need to decrease bt power for Wifi is connected!!\n"));\r
666                         bRet = TRUE;\r
667                 }\r
668         }\r
669         \r
670         return bRet;\r
671 }\r
672 \r
673 VOID\r
674 halbtc8723a2ant_SetFwDacSwingLevel(\r
675         IN      PBTC_COEXIST            pBtCoexist,\r
676         IN      u1Byte                  dacSwingLvl\r
677         )\r
678 {\r
679         u1Byte                  H2C_Parameter[1] ={0};\r
680 \r
681         // There are several type of dacswing\r
682         // 0x18/ 0x10/ 0xc/ 0x8/ 0x4/ 0x6\r
683         H2C_Parameter[0] = dacSwingLvl;\r
684 \r
685         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Set Dac Swing Level=0x%x\n", dacSwingLvl));\r
686         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], FW write 0x29=0x%x\n", H2C_Parameter[0]));\r
687 \r
688         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x29, 1, H2C_Parameter);\r
689 }\r
690 \r
691 VOID\r
692 halbtc8723a2ant_SetFwDecBtPwr(\r
693         IN      PBTC_COEXIST            pBtCoexist,\r
694         IN      BOOLEAN                 bDecBtPwr\r
695         )\r
696 {\r
697         u1Byte                  H2C_Parameter[1] ={0};\r
698         \r
699         H2C_Parameter[0] = 0;\r
700 \r
701         if(bDecBtPwr)\r
702         {\r
703                 H2C_Parameter[0] |= BIT1;\r
704         }\r
705 \r
706         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], decrease Bt Power : %s, FW write 0x21=0x%x\n", \r
707                 (bDecBtPwr? "Yes!!":"No!!"), H2C_Parameter[0]));\r
708 \r
709         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x21, 1, H2C_Parameter);    \r
710 }\r
711 \r
712 VOID\r
713 halbtc8723a2ant_DecBtPwr(\r
714         IN      PBTC_COEXIST            pBtCoexist,\r
715         IN      BOOLEAN                 bForceExec,\r
716         IN      BOOLEAN                 bDecBtPwr\r
717         )\r
718 {\r
719         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s Dec BT power = %s\n",  \r
720                 (bForceExec? "force to":""), ((bDecBtPwr)? "ON":"OFF")));\r
721         pCoexDm->bCurDecBtPwr = bDecBtPwr;\r
722 \r
723         if(!bForceExec)\r
724         {\r
725                 if(pCoexDm->bPreDecBtPwr == pCoexDm->bCurDecBtPwr) \r
726                         return;\r
727         }\r
728         halbtc8723a2ant_SetFwDecBtPwr(pBtCoexist, pCoexDm->bCurDecBtPwr);\r
729 \r
730         pCoexDm->bPreDecBtPwr = pCoexDm->bCurDecBtPwr;\r
731 }\r
732 \r
733 VOID\r
734 halbtc8723a2ant_FwDacSwingLvl(\r
735         IN      PBTC_COEXIST            pBtCoexist,\r
736         IN      BOOLEAN                 bForceExec,\r
737         IN      u1Byte                  fwDacSwingLvl\r
738         )\r
739 {\r
740         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s set FW Dac Swing level = %d\n",  \r
741                 (bForceExec? "force to":""), fwDacSwingLvl));\r
742         pCoexDm->curFwDacSwingLvl = fwDacSwingLvl;\r
743 \r
744         if(!bForceExec)\r
745         {\r
746                 if(pCoexDm->preFwDacSwingLvl == pCoexDm->curFwDacSwingLvl) \r
747                         return;\r
748         }\r
749 \r
750         halbtc8723a2ant_SetFwDacSwingLevel(pBtCoexist, pCoexDm->curFwDacSwingLvl);\r
751 \r
752         pCoexDm->preFwDacSwingLvl = pCoexDm->curFwDacSwingLvl;\r
753 }\r
754 \r
755 VOID\r
756 halbtc8723a2ant_SetSwRfRxLpfCorner(\r
757         IN      PBTC_COEXIST            pBtCoexist,\r
758         IN      BOOLEAN                 bRxRfShrinkOn\r
759         )\r
760 {\r
761         if(bRxRfShrinkOn)\r
762         {\r
763                 //Shrink RF Rx LPF corner\r
764                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Shrink RF Rx LPF corner!!\n"));\r
765                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff, 0xf0ff7);\r
766         }\r
767         else\r
768         {\r
769                 //Resume RF Rx LPF corner\r
770                 // After initialized, we can use pCoexDm->btRf0x1eBackup\r
771                 if(pBtCoexist->bInitilized)\r
772                 {\r
773                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Resume RF Rx LPF corner!!\n"));\r
774                         pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff, pCoexDm->btRf0x1eBackup);\r
775                 }\r
776         }\r
777 }\r
778 \r
779 VOID\r
780 halbtc8723a2ant_RfShrink(\r
781         IN      PBTC_COEXIST            pBtCoexist,\r
782         IN      BOOLEAN                 bForceExec,\r
783         IN      BOOLEAN                 bRxRfShrinkOn\r
784         )\r
785 {\r
786         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn Rx RF Shrink = %s\n",  \r
787                 (bForceExec? "force to":""), ((bRxRfShrinkOn)? "ON":"OFF")));\r
788         pCoexDm->bCurRfRxLpfShrink = bRxRfShrinkOn;\r
789 \r
790         if(!bForceExec)\r
791         {\r
792                 if(pCoexDm->bPreRfRxLpfShrink == pCoexDm->bCurRfRxLpfShrink) \r
793                         return;\r
794         }\r
795         halbtc8723a2ant_SetSwRfRxLpfCorner(pBtCoexist, pCoexDm->bCurRfRxLpfShrink);\r
796 \r
797         pCoexDm->bPreRfRxLpfShrink = pCoexDm->bCurRfRxLpfShrink;\r
798 }\r
799 \r
800 VOID\r
801 halbtc8723a2ant_SetSwPenaltyTxRateAdaptive(\r
802         IN      PBTC_COEXIST            pBtCoexist,\r
803         IN      BOOLEAN                 bLowPenaltyRa\r
804         )\r
805 {\r
806         u1Byte  tmpU1;\r
807 \r
808         tmpU1 = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x4fd);\r
809         tmpU1 |= BIT0;\r
810         if(bLowPenaltyRa)\r
811         {\r
812                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Tx rate adaptive, set low penalty!!\n"));\r
813                 tmpU1 &= ~BIT2;\r
814         }\r
815         else\r
816         {\r
817                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Tx rate adaptive, set normal!!\n"));\r
818                 tmpU1 |= BIT2;\r
819         }\r
820 \r
821         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x4fd, tmpU1);\r
822 }\r
823 \r
824 VOID\r
825 halbtc8723a2ant_LowPenaltyRa(\r
826         IN      PBTC_COEXIST            pBtCoexist,\r
827         IN      BOOLEAN                 bForceExec,\r
828         IN      BOOLEAN                 bLowPenaltyRa\r
829         )\r
830 {\r
831         return;\r
832         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn LowPenaltyRA = %s\n",  \r
833                 (bForceExec? "force to":""), ((bLowPenaltyRa)? "ON":"OFF")));\r
834         pCoexDm->bCurLowPenaltyRa = bLowPenaltyRa;\r
835 \r
836         if(!bForceExec)\r
837         {\r
838                 if(pCoexDm->bPreLowPenaltyRa == pCoexDm->bCurLowPenaltyRa) \r
839                         return;\r
840         }\r
841         halbtc8723a2ant_SetSwPenaltyTxRateAdaptive(pBtCoexist, pCoexDm->bCurLowPenaltyRa);\r
842 \r
843         pCoexDm->bPreLowPenaltyRa = pCoexDm->bCurLowPenaltyRa;\r
844 }\r
845 \r
846 VOID\r
847 halbtc8723a2ant_SetSwFullTimeDacSwing(\r
848         IN      PBTC_COEXIST            pBtCoexist,\r
849         IN      BOOLEAN                 bSwDacSwingOn,\r
850         IN      u4Byte                  swDacSwingLvl\r
851         )\r
852 {\r
853         if(bSwDacSwingOn)\r
854         {\r
855                 pBtCoexist->fBtcSetBbReg(pBtCoexist, 0x880, 0xff000000, swDacSwingLvl);\r
856         }\r
857         else\r
858         {\r
859                 pBtCoexist->fBtcSetBbReg(pBtCoexist, 0x880, 0xff000000, 0xc0);\r
860         }\r
861 }\r
862 \r
863 \r
864 VOID\r
865 halbtc8723a2ant_DacSwing(\r
866         IN      PBTC_COEXIST            pBtCoexist,\r
867         IN      BOOLEAN                 bForceExec,\r
868         IN      BOOLEAN                 bDacSwingOn,\r
869         IN      u4Byte                  dacSwingLvl\r
870         )\r
871 {\r
872         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn DacSwing=%s, dacSwingLvl=0x%x\n",  \r
873                 (bForceExec? "force to":""), ((bDacSwingOn)? "ON":"OFF"), dacSwingLvl));\r
874         pCoexDm->bCurDacSwingOn = bDacSwingOn;\r
875         pCoexDm->curDacSwingLvl = dacSwingLvl;\r
876 \r
877         if(!bForceExec)\r
878         {\r
879                 if( (pCoexDm->bPreDacSwingOn == pCoexDm->bCurDacSwingOn) &&\r
880                         (pCoexDm->preDacSwingLvl == pCoexDm->curDacSwingLvl) )\r
881                         return;\r
882         }\r
883         delay_ms(30);\r
884         halbtc8723a2ant_SetSwFullTimeDacSwing(pBtCoexist, bDacSwingOn, dacSwingLvl);\r
885 \r
886         pCoexDm->bPreDacSwingOn = pCoexDm->bCurDacSwingOn;\r
887         pCoexDm->preDacSwingLvl = pCoexDm->curDacSwingLvl;\r
888 }\r
889 \r
890 VOID\r
891 halbtc8723a2ant_SetAdcBackOff(\r
892         IN      PBTC_COEXIST            pBtCoexist,\r
893         IN      BOOLEAN                 bAdcBackOff\r
894         )\r
895 {\r
896         if(bAdcBackOff)\r
897         {\r
898                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BB BackOff Level On!\n"));\r
899                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc04,0x3a07611);\r
900         }\r
901         else\r
902         {\r
903                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BB BackOff Level Off!\n"));           \r
904                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc04,0x3a05611);\r
905         }\r
906 }\r
907 \r
908 VOID\r
909 halbtc8723a2ant_AdcBackOff(\r
910         IN      PBTC_COEXIST            pBtCoexist,\r
911         IN      BOOLEAN                 bForceExec,\r
912         IN      BOOLEAN                 bAdcBackOff\r
913         )\r
914 {\r
915         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn AdcBackOff = %s\n",  \r
916                 (bForceExec? "force to":""), ((bAdcBackOff)? "ON":"OFF")));\r
917         pCoexDm->bCurAdcBackOff = bAdcBackOff;\r
918 \r
919         if(!bForceExec)\r
920         {\r
921                 if(pCoexDm->bPreAdcBackOff == pCoexDm->bCurAdcBackOff) \r
922                         return;\r
923         }\r
924         halbtc8723a2ant_SetAdcBackOff(pBtCoexist, pCoexDm->bCurAdcBackOff);\r
925 \r
926         pCoexDm->bPreAdcBackOff = pCoexDm->bCurAdcBackOff;\r
927 }\r
928 \r
929 VOID\r
930 halbtc8723a2ant_SetAgcTable(\r
931         IN      PBTC_COEXIST            pBtCoexist,\r
932         IN      BOOLEAN                 bAgcTableEn\r
933         )\r
934 {\r
935         u1Byte          rssiAdjustVal=0;\r
936 \r
937         if(bAgcTableEn)\r
938         {\r
939                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Agc Table On!\n"));\r
940                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x4e1c0001);\r
941                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x4d1d0001);\r
942                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x4c1e0001);\r
943                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x4b1f0001);\r
944                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x4a200001);\r
945                 \r
946                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x12, 0xfffff, 0xdc000);\r
947                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x12, 0xfffff, 0x90000);\r
948                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x12, 0xfffff, 0x51000);\r
949                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x12, 0xfffff, 0x12000);\r
950                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1a, 0xfffff, 0x00355);\r
951                 \r
952                 rssiAdjustVal = 6;\r
953         }\r
954         else\r
955         {\r
956                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Agc Table Off!\n"));\r
957                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x641c0001);\r
958                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x631d0001);\r
959                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x621e0001);\r
960                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x611f0001);\r
961                 pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0xc78,0x60200001);\r
962 \r
963                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x12, 0xfffff, 0x32000);\r
964                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x12, 0xfffff, 0x71000);\r
965                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x12, 0xfffff, 0xb0000);\r
966                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x12, 0xfffff, 0xfc000);\r
967                 pBtCoexist->fBtcSetRfReg(pBtCoexist, BTC_RF_A, 0x1a, 0xfffff, 0x30355);\r
968         }\r
969 \r
970         // set rssiAdjustVal for wifi module.\r
971         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON, &rssiAdjustVal);\r
972 }\r
973 \r
974 \r
975 VOID\r
976 halbtc8723a2ant_AgcTable(\r
977         IN      PBTC_COEXIST            pBtCoexist,\r
978         IN      BOOLEAN                 bForceExec,\r
979         IN      BOOLEAN                 bAgcTableEn\r
980         )\r
981 {\r
982         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s %s Agc Table\n",  \r
983                 (bForceExec? "force to":""), ((bAgcTableEn)? "Enable":"Disable")));\r
984         pCoexDm->bCurAgcTableEn = bAgcTableEn;\r
985 \r
986         if(!bForceExec)\r
987         {\r
988                 if(pCoexDm->bPreAgcTableEn == pCoexDm->bCurAgcTableEn) \r
989                         return;\r
990         }\r
991         halbtc8723a2ant_SetAgcTable(pBtCoexist, bAgcTableEn);\r
992 \r
993         pCoexDm->bPreAgcTableEn = pCoexDm->bCurAgcTableEn;\r
994 }\r
995 \r
996 VOID\r
997 halbtc8723a2ant_SetCoexTable(\r
998         IN      PBTC_COEXIST    pBtCoexist,\r
999         IN      u4Byte          val0x6c0,\r
1000         IN      u4Byte          val0x6c8,\r
1001         IN      u1Byte          val0x6cc\r
1002         )\r
1003 {\r
1004         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6c0=0x%x\n", val0x6c0));\r
1005         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c0, val0x6c0);\r
1006 \r
1007         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6c8=0x%x\n", val0x6c8));\r
1008         pBtCoexist->fBtcWrite4Byte(pBtCoexist, 0x6c8, val0x6c8);\r
1009 \r
1010         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set coex table, set 0x6cc=0x%x\n", val0x6cc));\r
1011         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x6cc, val0x6cc);\r
1012 }\r
1013 \r
1014 VOID\r
1015 halbtc8723a2ant_CoexTable(\r
1016         IN      PBTC_COEXIST            pBtCoexist,\r
1017         IN      BOOLEAN                 bForceExec,\r
1018         IN      u4Byte                  val0x6c0,\r
1019         IN      u4Byte                  val0x6c8,\r
1020         IN      u1Byte                  val0x6cc\r
1021         )\r
1022 {\r
1023         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s write Coex Table 0x6c0=0x%x, 0x6c8=0x%x, 0x6cc=0x%x\n", \r
1024                 (bForceExec? "force to":""), val0x6c0, val0x6c8, val0x6cc));\r
1025         pCoexDm->curVal0x6c0 = val0x6c0;\r
1026         pCoexDm->curVal0x6c8 = val0x6c8;\r
1027         pCoexDm->curVal0x6cc = val0x6cc;\r
1028 \r
1029         if(!bForceExec)\r
1030         {       \r
1031                 if( (pCoexDm->preVal0x6c0 == pCoexDm->curVal0x6c0) &&\r
1032                         (pCoexDm->preVal0x6c8 == pCoexDm->curVal0x6c8) &&\r
1033                         (pCoexDm->preVal0x6cc == pCoexDm->curVal0x6cc) )\r
1034                         return;\r
1035         }\r
1036         halbtc8723a2ant_SetCoexTable(pBtCoexist, val0x6c0, val0x6c8, val0x6cc);\r
1037 \r
1038         pCoexDm->preVal0x6c0 = pCoexDm->curVal0x6c0;\r
1039         pCoexDm->preVal0x6c8 = pCoexDm->curVal0x6c8;\r
1040         pCoexDm->preVal0x6cc = pCoexDm->curVal0x6cc;\r
1041 }\r
1042 \r
1043 VOID\r
1044 halbtc8723a2ant_SetFwIgnoreWlanAct(\r
1045         IN      PBTC_COEXIST            pBtCoexist,\r
1046         IN      BOOLEAN                 bEnable\r
1047         )\r
1048 {\r
1049         u1Byte                  H2C_Parameter[1] ={0};\r
1050                 \r
1051         if(bEnable)\r
1052         {\r
1053                 H2C_Parameter[0] |= BIT0;               // function enable\r
1054         }\r
1055         \r
1056         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x25=0x%x\n", \r
1057                 H2C_Parameter[0]));\r
1058 \r
1059         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x25, 1, H2C_Parameter);    \r
1060 }\r
1061 \r
1062 VOID\r
1063 halbtc8723a2ant_IgnoreWlanAct(\r
1064         IN      PBTC_COEXIST            pBtCoexist,\r
1065         IN      BOOLEAN                 bForceExec,\r
1066         IN      BOOLEAN                 bEnable\r
1067         )\r
1068 {\r
1069         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn Ignore WlanAct %s\n", \r
1070                 (bForceExec? "force to":""), (bEnable? "ON":"OFF")));\r
1071         pCoexDm->bCurIgnoreWlanAct = bEnable;\r
1072 \r
1073         if(!bForceExec)\r
1074         {\r
1075                 if(pCoexDm->bPreIgnoreWlanAct == pCoexDm->bCurIgnoreWlanAct)\r
1076                         return;\r
1077         }\r
1078         halbtc8723a2ant_SetFwIgnoreWlanAct(pBtCoexist, bEnable);\r
1079 \r
1080         pCoexDm->bPreIgnoreWlanAct = pCoexDm->bCurIgnoreWlanAct;\r
1081 }\r
1082 \r
1083 VOID\r
1084 halbtc8723a2ant_SetFwPstdma(\r
1085         IN      PBTC_COEXIST            pBtCoexist,\r
1086         IN      u1Byte                  byte1,\r
1087         IN      u1Byte                  byte2,\r
1088         IN      u1Byte                  byte3,\r
1089         IN      u1Byte                  byte4,\r
1090         IN      u1Byte                  byte5\r
1091         )\r
1092 {\r
1093         u1Byte                  H2C_Parameter[5] ={0};\r
1094 \r
1095         H2C_Parameter[0] = byte1;       \r
1096         H2C_Parameter[1] = byte2;       \r
1097         H2C_Parameter[2] = byte3;\r
1098         H2C_Parameter[3] = byte4;\r
1099         H2C_Parameter[4] = byte5;\r
1100 \r
1101         pCoexDm->psTdmaPara[0] = byte1;\r
1102         pCoexDm->psTdmaPara[1] = byte2;\r
1103         pCoexDm->psTdmaPara[2] = byte3;\r
1104         pCoexDm->psTdmaPara[3] = byte4;\r
1105         pCoexDm->psTdmaPara[4] = byte5;\r
1106         \r
1107         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], FW write 0x3a(5bytes)=0x%x%08x\n", \r
1108                 H2C_Parameter[0], \r
1109                 H2C_Parameter[1]<<24|H2C_Parameter[2]<<16|H2C_Parameter[3]<<8|H2C_Parameter[4]));\r
1110 \r
1111         pBtCoexist->fBtcFillH2c(pBtCoexist, 0x3a, 5, H2C_Parameter);\r
1112 }\r
1113 \r
1114 VOID\r
1115 halbtc8723a2ant_PsTdma(\r
1116         IN      PBTC_COEXIST            pBtCoexist,\r
1117         IN      BOOLEAN                 bForceExec,\r
1118         IN      BOOLEAN                 bTurnOn,\r
1119         IN      u1Byte                  type\r
1120         )\r
1121 {\r
1122         u4Byte  btTxRxCnt=0;\r
1123 \r
1124         btTxRxCnt = pCoexSta->highPriorityTx+pCoexSta->highPriorityRx+\r
1125                                 pCoexSta->lowPriorityTx+pCoexSta->lowPriorityRx;\r
1126 \r
1127         if(btTxRxCnt > 3000)\r
1128         {               \r
1129                 pCoexDm->bCurPsTdmaOn = TRUE;\r
1130                 pCoexDm->curPsTdma = 8;\r
1131                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], turn ON PS TDMA, type=%d for BT tx/rx counters=%d(>3000)\n", \r
1132                         pCoexDm->curPsTdma, btTxRxCnt));\r
1133         }\r
1134         else\r
1135         {\r
1136                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], %s turn %s PS TDMA, type=%d\n", \r
1137                         (bForceExec? "force to":""), (bTurnOn? "ON":"OFF"), type));             \r
1138                 pCoexDm->bCurPsTdmaOn = bTurnOn;\r
1139                 pCoexDm->curPsTdma = type;\r
1140         }\r
1141 \r
1142         if(!bForceExec)\r
1143         {\r
1144                 if( (pCoexDm->bPrePsTdmaOn == pCoexDm->bCurPsTdmaOn) &&\r
1145                         (pCoexDm->prePsTdma == pCoexDm->curPsTdma) )\r
1146                         return;\r
1147         }       \r
1148         if(pCoexDm->bCurPsTdmaOn)\r
1149         {\r
1150                 switch(pCoexDm->curPsTdma)\r
1151                 {\r
1152                         case 1:\r
1153                         default:\r
1154                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x98);\r
1155                                 break;\r
1156                         case 2:\r
1157                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0xe1, 0x98);\r
1158                                 break;\r
1159                         case 3:\r
1160                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0xa, 0xe1, 0x98);\r
1161                                 break;\r
1162                         case 4:\r
1163                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xa3, 0x5, 0x5, 0xe1, 0x80);\r
1164                                 break;\r
1165                         case 5:\r
1166                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0x60, 0x98);\r
1167                                 break;\r
1168                         case 6:\r
1169                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0x60, 0x98);\r
1170                                 break;\r
1171                         case 7:\r
1172                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0xa, 0x60, 0x98);\r
1173                                 break;\r
1174                         case 8: \r
1175                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xa3, 0x5, 0x5, 0x60, 0x80);\r
1176                                 break;\r
1177                         case 9: \r
1178                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0xe1, 0x98);\r
1179                                 break;\r
1180                         case 10:        \r
1181                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0xe1, 0x98);\r
1182                                 break;\r
1183                         case 11:        \r
1184                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0xa, 0xe1, 0x98);\r
1185                                 break;\r
1186                         case 12:\r
1187                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x5, 0x5, 0xe1, 0x98);\r
1188                                 break;\r
1189                         case 13:\r
1190                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x1a, 0x1a, 0x60, 0x98);\r
1191                                 break;\r
1192                         case 14:\r
1193                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x12, 0x12, 0x60, 0x98);\r
1194                                 break;\r
1195                         case 15:\r
1196                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0xa, 0xa, 0x60, 0x98);\r
1197                                 break;\r
1198                         case 16:\r
1199                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x5, 0x5, 0x60, 0x98);\r
1200                                 break;\r
1201                         case 17:\r
1202                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xa3, 0x2f, 0x2f, 0x60, 0x80);\r
1203                                 break;\r
1204                         case 18:\r
1205                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x5, 0x5, 0xe1, 0x98);\r
1206                                 break;                  \r
1207                         case 19:\r
1208                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x25, 0xe1, 0x98);\r
1209                                 break;\r
1210                         case 20:\r
1211                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0xe3, 0x25, 0x25, 0x60, 0x98);\r
1212                                 break;\r
1213                 }\r
1214         }\r
1215         else\r
1216         {\r
1217                 // disable PS tdma\r
1218                 switch(pCoexDm->curPsTdma)\r
1219                 {\r
1220                         case 0:\r
1221                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x8, 0x0);\r
1222                                 break;\r
1223                         case 1:\r
1224                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x0, 0x0);\r
1225                                 break;\r
1226                         default:\r
1227                                 halbtc8723a2ant_SetFwPstdma(pBtCoexist, 0x0, 0x0, 0x0, 0x8, 0x0);\r
1228                                 break;\r
1229                 }\r
1230         }\r
1231 \r
1232         // update pre state\r
1233         pCoexDm->bPrePsTdmaOn = pCoexDm->bCurPsTdmaOn;\r
1234         pCoexDm->prePsTdma = pCoexDm->curPsTdma;\r
1235 }\r
1236 \r
1237 \r
1238 VOID\r
1239 halbtc8723a2ant_CoexAllOff(\r
1240         IN      PBTC_COEXIST            pBtCoexist\r
1241         )\r
1242 {\r
1243         // fw all off\r
1244         halbtc8723a2ant_IgnoreWlanAct(pBtCoexist, NORMAL_EXEC, FALSE);\r
1245         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
1246         halbtc8723a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 0x20);\r
1247         halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, FALSE);\r
1248 \r
1249         // sw all off\r
1250         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
1251         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
1252         halbtc8723a2ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, FALSE);\r
1253         halbtc8723a2ant_RfShrink(pBtCoexist, NORMAL_EXEC, FALSE);\r
1254         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
1255 \r
1256         // hw all off\r
1257         halbtc8723a2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3);\r
1258 }\r
1259 \r
1260 VOID\r
1261 halbtc8723a2ant_InitCoexDm(\r
1262         IN      PBTC_COEXIST            pBtCoexist\r
1263         )\r
1264 {\r
1265         // force to reset coex mechanism\r
1266         halbtc8723a2ant_CoexTable(pBtCoexist, FORCE_EXEC, 0x55555555, 0xffff, 0x3);\r
1267         halbtc8723a2ant_PsTdma(pBtCoexist, FORCE_EXEC, FALSE, 0);\r
1268         halbtc8723a2ant_FwDacSwingLvl(pBtCoexist, FORCE_EXEC, 0x20);\r
1269         halbtc8723a2ant_DecBtPwr(pBtCoexist, FORCE_EXEC, FALSE);\r
1270         halbtc8723a2ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, FALSE);\r
1271 \r
1272         halbtc8723a2ant_AgcTable(pBtCoexist, FORCE_EXEC, FALSE);\r
1273         halbtc8723a2ant_AdcBackOff(pBtCoexist, FORCE_EXEC, FALSE);\r
1274         halbtc8723a2ant_LowPenaltyRa(pBtCoexist, FORCE_EXEC, FALSE);\r
1275         halbtc8723a2ant_RfShrink(pBtCoexist, FORCE_EXEC, FALSE);\r
1276         halbtc8723a2ant_DacSwing(pBtCoexist, FORCE_EXEC, FALSE, 0xc0);\r
1277 }\r
1278 \r
1279 VOID\r
1280 halbtc8723a2ant_BtInquiryPage(\r
1281         IN      PBTC_COEXIST            pBtCoexist\r
1282         )\r
1283 {\r
1284         BOOLEAN bLowPwrDisable=TRUE;\r
1285         \r
1286         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
1287 \r
1288         halbtc8723a2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3);\r
1289         halbtc8723a2ant_IgnoreWlanAct(pBtCoexist, NORMAL_EXEC, FALSE);\r
1290         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
1291 }\r
1292 \r
1293 VOID\r
1294 halbtc8723a2ant_BtEnableAction(\r
1295         IN      PBTC_COEXIST            pBtCoexist\r
1296         )\r
1297 {\r
1298         BOOLEAN         bWifiConnected=FALSE;\r
1299         \r
1300         // Here we need to resend some wifi info to BT\r
1301         // because bt is reset and loss of the info.                                            \r
1302         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
1303         if(bWifiConnected)\r
1304         {\r
1305                 halbtc8723a2ant_IndicateWifiChnlBwInfo(pBtCoexist, BTC_MEDIA_CONNECT);\r
1306         }\r
1307         else\r
1308         {\r
1309                 halbtc8723a2ant_IndicateWifiChnlBwInfo(pBtCoexist, BTC_MEDIA_DISCONNECT);\r
1310         }\r
1311 \r
1312         halbtc8723a2ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, FALSE);\r
1313 }\r
1314 \r
1315 VOID\r
1316 halbtc8723a2ant_MonitorBtCtr(\r
1317         IN      PBTC_COEXIST            pBtCoexist\r
1318         )\r
1319 {\r
1320         u4Byte                  regHPTxRx, regLPTxRx, u4Tmp;\r
1321         u4Byte                  regHPTx=0, regHPRx=0, regLPTx=0, regLPRx=0;\r
1322         u1Byte                  u1Tmp;\r
1323         \r
1324         regHPTxRx = 0x770;\r
1325         regLPTxRx = 0x774;\r
1326 \r
1327         u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regHPTxRx);\r
1328         regHPTx = u4Tmp & bMaskLWord;\r
1329         regHPRx = (u4Tmp & bMaskHWord)>>16;\r
1330 \r
1331         u4Tmp = pBtCoexist->fBtcRead4Byte(pBtCoexist, regLPTxRx);\r
1332         regLPTx = u4Tmp & bMaskLWord;\r
1333         regLPRx = (u4Tmp & bMaskHWord)>>16;\r
1334                 \r
1335         pCoexSta->highPriorityTx = regHPTx;\r
1336         pCoexSta->highPriorityRx = regHPRx;\r
1337         pCoexSta->lowPriorityTx = regLPTx;\r
1338         pCoexSta->lowPriorityRx = regLPRx;\r
1339 \r
1340         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], High Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n", \r
1341                 regHPTxRx, regHPTx, regHPTx, regHPRx, regHPRx));\r
1342         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Low Priority Tx/Rx (reg 0x%x)=0x%x(%d)/0x%x(%d)\n", \r
1343                 regLPTxRx, regLPTx, regLPTx, regLPRx, regLPRx));\r
1344 \r
1345         // reset counter\r
1346         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0xc);\r
1347 }\r
1348 \r
1349 VOID\r
1350 halbtc8723a2ant_MonitorBtEnableDisable(\r
1351         IN      PBTC_COEXIST            pBtCoexist\r
1352         )\r
1353 {\r
1354         static BOOLEAN  bPreBtDisabled=FALSE;\r
1355         static u4Byte   btDisableCnt=0;\r
1356         BOOLEAN                 bBtActive=TRUE, bBtDisabled=FALSE;\r
1357 \r
1358         // This function check if bt is disabled\r
1359 \r
1360         if(     pCoexSta->highPriorityTx == 0 &&\r
1361                 pCoexSta->highPriorityRx == 0 &&\r
1362                 pCoexSta->lowPriorityTx == 0 &&\r
1363                 pCoexSta->lowPriorityRx == 0)\r
1364         {\r
1365                 bBtActive = FALSE;\r
1366         }\r
1367         if(     pCoexSta->highPriorityTx == 0xffff &&\r
1368                 pCoexSta->highPriorityRx == 0xffff &&\r
1369                 pCoexSta->lowPriorityTx == 0xffff &&\r
1370                 pCoexSta->lowPriorityRx == 0xffff)\r
1371         {\r
1372                 bBtActive = FALSE;\r
1373         }\r
1374         if(bBtActive)\r
1375         {\r
1376                 btDisableCnt = 0;\r
1377                 bBtDisabled = FALSE;\r
1378                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);\r
1379                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is enabled !!\n"));\r
1380         }\r
1381         else\r
1382         {\r
1383                 btDisableCnt++;\r
1384                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], bt all counters=0, %d times!!\n", \r
1385                                 btDisableCnt));\r
1386                 if(btDisableCnt >= 2)\r
1387                 {\r
1388                         bBtDisabled = TRUE;\r
1389                         pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_BL_BT_DISABLE, &bBtDisabled);\r
1390                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is disabled !!\n"));\r
1391                 }\r
1392         }\r
1393         if(bPreBtDisabled != bBtDisabled)\r
1394         {\r
1395                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], BT is from %s to %s!!\n", \r
1396                         (bPreBtDisabled ? "disabled":"enabled"), \r
1397                         (bBtDisabled ? "disabled":"enabled")));\r
1398                 bPreBtDisabled = bBtDisabled;\r
1399                 if(!bBtDisabled)\r
1400                 {\r
1401                         halbtc8723a2ant_BtEnableAction(pBtCoexist);\r
1402                 }\r
1403         }\r
1404 }\r
1405 \r
1406 BOOLEAN\r
1407 halbtc8723a2ant_IsCommonAction(\r
1408         IN      PBTC_COEXIST            pBtCoexist\r
1409         )\r
1410 {\r
1411         PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;\r
1412         BOOLEAN                 bCommon=FALSE, bWifiConnected=FALSE;\r
1413         BOOLEAN                 bLowPwrDisable=FALSE;\r
1414 \r
1415         if(!pStackInfo->bBtLinkExist)\r
1416         {\r
1417                 bLowPwrDisable = FALSE;\r
1418                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
1419         }\r
1420         else\r
1421         {\r
1422                 bLowPwrDisable = TRUE;\r
1423                 pBtCoexist->fBtcSet(pBtCoexist, BTC_SET_ACT_DISABLE_LOW_POWER, &bLowPwrDisable);\r
1424         }\r
1425 \r
1426         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_CONNECTED, &bWifiConnected);\r
1427 \r
1428         if(halbtc8723a2ant_IsWifiIdle(pBtCoexist) && \r
1429                 BT_8723A_2ANT_BT_STATUS_IDLE == pCoexDm->btStatus)\r
1430         {\r
1431                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi idle + Bt idle!!\n"));\r
1432                         \r
1433                 halbtc8723a2ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, FALSE);\r
1434                 halbtc8723a2ant_RfShrink(pBtCoexist, NORMAL_EXEC, FALSE);\r
1435                 halbtc8723a2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3);\r
1436 \r
1437                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
1438                 halbtc8723a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 0x20);\r
1439                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, FALSE);\r
1440 \r
1441                 halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
1442                 halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
1443                 halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
1444 \r
1445                 bCommon = TRUE;\r
1446         }\r
1447         else if(!halbtc8723a2ant_IsWifiIdle(pBtCoexist) && \r
1448                         (BT_8723A_2ANT_BT_STATUS_IDLE == pCoexDm->btStatus) )\r
1449         {\r
1450                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi non-idle + BT idle!!\n"));\r
1451 \r
1452                 halbtc8723a2ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, TRUE);\r
1453                 halbtc8723a2ant_RfShrink(pBtCoexist, NORMAL_EXEC, FALSE);\r
1454                 halbtc8723a2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3);\r
1455 \r
1456                 halbtc8723a2ant_IgnoreWlanAct(pBtCoexist, NORMAL_EXEC, FALSE);\r
1457                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
1458                 halbtc8723a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 0x20);\r
1459                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, TRUE);\r
1460 \r
1461                 halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
1462                 halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
1463                 halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
1464 \r
1465                 bCommon = TRUE;\r
1466         }\r
1467         else if(halbtc8723a2ant_IsWifiIdle(pBtCoexist) && \r
1468                 (BT_8723A_2ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus) )\r
1469         {\r
1470                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi idle + Bt connected idle!!\n"));\r
1471                 \r
1472                 halbtc8723a2ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, TRUE);\r
1473                 halbtc8723a2ant_RfShrink(pBtCoexist, NORMAL_EXEC, TRUE);\r
1474                 halbtc8723a2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3);\r
1475 \r
1476                 halbtc8723a2ant_IgnoreWlanAct(pBtCoexist, NORMAL_EXEC, FALSE);\r
1477                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
1478                 halbtc8723a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 0x20);\r
1479                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, FALSE);\r
1480 \r
1481                 halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
1482                 halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
1483                 halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
1484 \r
1485                 bCommon = TRUE;\r
1486         }\r
1487         else if(!halbtc8723a2ant_IsWifiIdle(pBtCoexist) && \r
1488                 (BT_8723A_2ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus) )\r
1489         {\r
1490                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi non-idle + Bt connected idle!!\n"));\r
1491 \r
1492                 halbtc8723a2ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, TRUE);\r
1493                 halbtc8723a2ant_RfShrink(pBtCoexist, NORMAL_EXEC, TRUE);\r
1494                 halbtc8723a2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3);\r
1495 \r
1496                 halbtc8723a2ant_IgnoreWlanAct(pBtCoexist, NORMAL_EXEC, FALSE);\r
1497                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
1498                 halbtc8723a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 0x20);\r
1499                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, FALSE);\r
1500 \r
1501                 halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
1502                 halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
1503                 halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
1504 \r
1505                 bCommon = TRUE;\r
1506         }\r
1507         else if(halbtc8723a2ant_IsWifiIdle(pBtCoexist) && \r
1508                         (BT_8723A_2ANT_BT_STATUS_NON_IDLE == pCoexDm->btStatus) )\r
1509         {\r
1510                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi idle + BT non-idle!!\n"));\r
1511                 \r
1512                 halbtc8723a2ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, TRUE);\r
1513                 halbtc8723a2ant_RfShrink(pBtCoexist, NORMAL_EXEC, TRUE);\r
1514                 halbtc8723a2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3);\r
1515 \r
1516                 halbtc8723a2ant_IgnoreWlanAct(pBtCoexist, NORMAL_EXEC, FALSE);\r
1517                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
1518                 halbtc8723a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 0x20);\r
1519                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, FALSE);\r
1520 \r
1521                 halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
1522                 halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
1523                 halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
1524                 \r
1525                 bCommon = TRUE;\r
1526         }\r
1527         else if(halbtc8723a2ant_IsWifiConnectedIdle(pBtCoexist) && \r
1528                         (BT_8723A_2ANT_BT_STATUS_NON_IDLE == pCoexDm->btStatus) )\r
1529         {\r
1530                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi connected-idle + BT non-idle!!\n"));\r
1531 \r
1532                 halbtc8723a2ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, TRUE);\r
1533                 halbtc8723a2ant_RfShrink(pBtCoexist, NORMAL_EXEC, TRUE);\r
1534                 halbtc8723a2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3);\r
1535 \r
1536                 halbtc8723a2ant_IgnoreWlanAct(pBtCoexist, NORMAL_EXEC, FALSE);\r
1537                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
1538                 halbtc8723a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 0x20);\r
1539                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, FALSE);\r
1540 \r
1541                 halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
1542                 halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
1543                 halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
1544                 \r
1545                 bCommon = TRUE;\r
1546         }\r
1547         else\r
1548         {\r
1549                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Wifi non-idle + BT non-idle!!\n"));\r
1550                 halbtc8723a2ant_LowPenaltyRa(pBtCoexist, NORMAL_EXEC, TRUE);\r
1551                 halbtc8723a2ant_RfShrink(pBtCoexist, NORMAL_EXEC, TRUE);\r
1552                 halbtc8723a2ant_IgnoreWlanAct(pBtCoexist, NORMAL_EXEC, FALSE);\r
1553                 halbtc8723a2ant_FwDacSwingLvl(pBtCoexist, NORMAL_EXEC, 0x20);\r
1554                 \r
1555                 bCommon = FALSE;\r
1556         }\r
1557         \r
1558         return bCommon;\r
1559 }\r
1560 VOID\r
1561 halbtc8723a2ant_TdmaDurationAdjust(\r
1562         IN      PBTC_COEXIST            pBtCoexist,\r
1563         IN      BOOLEAN                 bScoHid,\r
1564         IN      BOOLEAN                 bTxPause,\r
1565         IN      u1Byte                  maxInterval\r
1566         )\r
1567 {\r
1568         static s4Byte           up,dn,m,n,WaitCount;\r
1569         s4Byte                  result;   //0: no change, +1: increase WiFi duration, -1: decrease WiFi duration\r
1570         u1Byte                  retryCount=0;\r
1571 \r
1572         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TdmaDurationAdjust()\n"));\r
1573 \r
1574         if(pCoexDm->bResetTdmaAdjust)\r
1575         {\r
1576                 pCoexDm->bResetTdmaAdjust = FALSE;\r
1577                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], first run TdmaDurationAdjust()!!\n"));\r
1578                 {\r
1579                         if(bScoHid)\r
1580                         {\r
1581                                 if(bTxPause)\r
1582                                 {\r
1583                                         if(maxInterval == 1)\r
1584                                         {\r
1585                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);\r
1586                                                 pCoexDm->psTdmaDuAdjType = 13;  \r
1587                                         }\r
1588                                         else if(maxInterval == 2)\r
1589                                         {\r
1590                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
1591                                                 pCoexDm->psTdmaDuAdjType = 14;  \r
1592                                         }\r
1593                                         else if(maxInterval == 3)\r
1594                                         {\r
1595                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
1596                                                 pCoexDm->psTdmaDuAdjType = 15;  \r
1597                                         }\r
1598                                         else\r
1599                                         {\r
1600                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
1601                                                 pCoexDm->psTdmaDuAdjType = 15;\r
1602                                         }\r
1603                                 }\r
1604                                 else\r
1605                                 {\r
1606                                         if(maxInterval == 1)\r
1607                                         {\r
1608                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
1609                                                 pCoexDm->psTdmaDuAdjType = 9;   \r
1610                                         }\r
1611                                         else if(maxInterval == 2)\r
1612                                         {\r
1613                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
1614                                                 pCoexDm->psTdmaDuAdjType = 10;  \r
1615                                         }\r
1616                                         else if(maxInterval == 3)\r
1617                                         {\r
1618                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
1619                                                 pCoexDm->psTdmaDuAdjType = 11;\r
1620                                         }\r
1621                                         else\r
1622                                         {\r
1623                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
1624                                                 pCoexDm->psTdmaDuAdjType = 11;\r
1625                                         }\r
1626                                 }\r
1627                         }\r
1628                         else\r
1629                         {\r
1630                                 if(bTxPause)\r
1631                                 {\r
1632                                         if(maxInterval == 1)\r
1633                                         {\r
1634                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
1635                                                 pCoexDm->psTdmaDuAdjType = 5;   \r
1636                                         }\r
1637                                         else if(maxInterval == 2)\r
1638                                         {\r
1639                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
1640                                                 pCoexDm->psTdmaDuAdjType = 6;   \r
1641                                         }\r
1642                                         else if(maxInterval == 3)\r
1643                                         {\r
1644                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
1645                                                 pCoexDm->psTdmaDuAdjType = 7;\r
1646                                         }\r
1647                                         else\r
1648                                         {\r
1649                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
1650                                                 pCoexDm->psTdmaDuAdjType = 7;\r
1651                                         }\r
1652                                 }\r
1653                                 else\r
1654                                 {\r
1655                                         if(maxInterval == 1)\r
1656                                         {\r
1657                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
1658                                                 pCoexDm->psTdmaDuAdjType = 1;   \r
1659                                         }\r
1660                                         else if(maxInterval == 2)\r
1661                                         {\r
1662                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
1663                                                 pCoexDm->psTdmaDuAdjType = 2;   \r
1664                                         }\r
1665                                         else if(maxInterval == 3)\r
1666                                         {\r
1667                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
1668                                                 pCoexDm->psTdmaDuAdjType = 3;\r
1669                                         }\r
1670                                         else\r
1671                                         {\r
1672                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
1673                                                 pCoexDm->psTdmaDuAdjType = 3;\r
1674                                         }\r
1675                                 }\r
1676                         }\r
1677                 }\r
1678                 //============\r
1679                 up = 0;\r
1680                 dn = 0;\r
1681                 m = 1;\r
1682                 n= 3;\r
1683                 result = 0;\r
1684                 WaitCount = 0;\r
1685         }\r
1686         else\r
1687         {\r
1688                 //accquire the BT TRx retry count from BT_Info byte2\r
1689                 retryCount = pCoexSta->btRetryCnt;\r
1690                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], retryCount = %d\n", retryCount));\r
1691                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], up=%d, dn=%d, m=%d, n=%d, WaitCount=%d\n", \r
1692                         up, dn, m, n, WaitCount));\r
1693                 result = 0;\r
1694                 WaitCount++; \r
1695                   \r
1696                 if(retryCount == 0)  // no retry in the last 2-second duration\r
1697                 {\r
1698                         up++;\r
1699                         dn--;\r
1700 \r
1701                         if (dn <= 0)\r
1702                                 dn = 0;                          \r
1703 \r
1704                         if(up >= n)     // if ³sÄò n ­Ó2¬í retry count¬°0, «h½Õ¼eWiFi duration\r
1705                         {\r
1706                                 WaitCount = 0; \r
1707                                 n = 3;\r
1708                                 up = 0;\r
1709                                 dn = 0;\r
1710                                 result = 1; \r
1711                                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Increase wifi duration!!\n"));\r
1712                         }\r
1713                 }\r
1714                 else if (retryCount <= 3)       // <=3 retry in the last 2-second duration\r
1715                 {\r
1716                         up--; \r
1717                         dn++;\r
1718 \r
1719                         if (up <= 0)\r
1720                                 up = 0;\r
1721 \r
1722                         if (dn == 2)    // if ³sÄò 2 ­Ó2¬í retry count< 3, «h½Õ¯¶WiFi duration\r
1723                         {\r
1724                                 if (WaitCount <= 2)\r
1725                                         m++; // ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^\r
1726                                 else\r
1727                                         m = 1;\r
1728 \r
1729                                 if ( m >= 20) //m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration.\r
1730                                         m = 20;\r
1731 \r
1732                                 n = 3*m;\r
1733                                 up = 0;\r
1734                                 dn = 0;\r
1735                                 WaitCount = 0;\r
1736                                 result = -1; \r
1737                                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter<3!!\n"));\r
1738                         }\r
1739                 }\r
1740                 else  //retry count > 3, ¥u­n1¦¸ retry count > 3, «h½Õ¯¶WiFi duration\r
1741                 {\r
1742                         if (WaitCount == 1)\r
1743                                 m++; // ÁקK¤@ª½¦b¨â­Ólevel¤¤¨Ó¦^\r
1744                         else\r
1745                                 m = 1;\r
1746 \r
1747                         if ( m >= 20) //m ³Ì¤j­È = 20 ' ³Ì¤j120¬í recheck¬O§_½Õ¾ã WiFi duration.\r
1748                                 m = 20;\r
1749 \r
1750                         n = 3*m;\r
1751                         up = 0;\r
1752                         dn = 0;\r
1753                         WaitCount = 0; \r
1754                         result = -1;\r
1755                         RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], Decrease wifi duration for retryCounter>3!!\n"));\r
1756                 }\r
1757 \r
1758                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], max Interval = %d\n", maxInterval));\r
1759                 if(maxInterval == 1)\r
1760                 {\r
1761                         if(bTxPause)\r
1762                         {\r
1763                                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TxPause = 1\n"));\r
1764 \r
1765                                 if(pCoexDm->curPsTdma == 1)\r
1766                                 {\r
1767                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
1768                                         pCoexDm->psTdmaDuAdjType = 5;\r
1769                                 }\r
1770                                 else if(pCoexDm->curPsTdma == 2)\r
1771                                 {\r
1772                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
1773                                         pCoexDm->psTdmaDuAdjType = 6;\r
1774                                 }\r
1775                                 else if(pCoexDm->curPsTdma == 3)\r
1776                                 {\r
1777                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
1778                                         pCoexDm->psTdmaDuAdjType = 7;\r
1779                                 }\r
1780                                 else if(pCoexDm->curPsTdma == 4)\r
1781                                 {\r
1782                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
1783                                         pCoexDm->psTdmaDuAdjType = 8;\r
1784                                 }\r
1785                                 if(pCoexDm->curPsTdma == 9)\r
1786                                 {\r
1787                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);\r
1788                                         pCoexDm->psTdmaDuAdjType = 13;\r
1789                                 }\r
1790                                 else if(pCoexDm->curPsTdma == 10)\r
1791                                 {\r
1792                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
1793                                         pCoexDm->psTdmaDuAdjType = 14;\r
1794                                 }\r
1795                                 else if(pCoexDm->curPsTdma == 11)\r
1796                                 {\r
1797                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
1798                                         pCoexDm->psTdmaDuAdjType = 15;\r
1799                                 }\r
1800                                 else if(pCoexDm->curPsTdma == 12)\r
1801                                 {\r
1802                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
1803                                         pCoexDm->psTdmaDuAdjType = 16;\r
1804                                 }\r
1805                                 \r
1806                                 if(result == -1)\r
1807                                 {                                       \r
1808                                         if(pCoexDm->curPsTdma == 5)\r
1809                                         {\r
1810                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
1811                                                 pCoexDm->psTdmaDuAdjType = 6;\r
1812                                         }\r
1813                                         else if(pCoexDm->curPsTdma == 6)\r
1814                                         {\r
1815                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
1816                                                 pCoexDm->psTdmaDuAdjType = 7;\r
1817                                         }\r
1818                                         else if(pCoexDm->curPsTdma == 7)\r
1819                                         {\r
1820                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
1821                                                 pCoexDm->psTdmaDuAdjType = 8;\r
1822                                         }\r
1823                                         else if(pCoexDm->curPsTdma == 13)\r
1824                                         {\r
1825                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
1826                                                 pCoexDm->psTdmaDuAdjType = 14;\r
1827                                         }\r
1828                                         else if(pCoexDm->curPsTdma == 14)\r
1829                                         {\r
1830                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
1831                                                 pCoexDm->psTdmaDuAdjType = 15;\r
1832                                         }\r
1833                                         else if(pCoexDm->curPsTdma == 15)\r
1834                                         {\r
1835                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
1836                                                 pCoexDm->psTdmaDuAdjType = 16;\r
1837                                         }\r
1838                                 } \r
1839                                 else if (result == 1)\r
1840                                 {\r
1841                                         if(pCoexDm->curPsTdma == 8)\r
1842                                         {\r
1843                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
1844                                                 pCoexDm->psTdmaDuAdjType = 7;\r
1845                                         }\r
1846                                         else if(pCoexDm->curPsTdma == 7)\r
1847                                         {\r
1848                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
1849                                                 pCoexDm->psTdmaDuAdjType = 6;\r
1850                                         }\r
1851                                         else if(pCoexDm->curPsTdma == 6)\r
1852                                         {\r
1853                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 5);\r
1854                                                 pCoexDm->psTdmaDuAdjType = 5;\r
1855                                         }\r
1856                                         else if(pCoexDm->curPsTdma == 16)\r
1857                                         {\r
1858                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
1859                                                 pCoexDm->psTdmaDuAdjType = 15;\r
1860                                         }\r
1861                                         else if(pCoexDm->curPsTdma == 15)\r
1862                                         {\r
1863                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
1864                                                 pCoexDm->psTdmaDuAdjType = 14;\r
1865                                         }\r
1866                                         else if(pCoexDm->curPsTdma == 14)\r
1867                                         {\r
1868                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);\r
1869                                                 pCoexDm->psTdmaDuAdjType = 13;\r
1870                                         }\r
1871                                 }\r
1872                         }\r
1873                         else\r
1874                         {\r
1875                                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TxPause = 0\n"));\r
1876                                 if(pCoexDm->curPsTdma == 5)\r
1877                                 {\r
1878                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
1879                                         pCoexDm->psTdmaDuAdjType = 1;\r
1880                                 }\r
1881                                 else if(pCoexDm->curPsTdma == 6)\r
1882                                 {\r
1883                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
1884                                         pCoexDm->psTdmaDuAdjType = 2;\r
1885                                 }\r
1886                                 else if(pCoexDm->curPsTdma == 7)\r
1887                                 {\r
1888                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
1889                                         pCoexDm->psTdmaDuAdjType = 3;\r
1890                                 }\r
1891                                 else if(pCoexDm->curPsTdma == 8)\r
1892                                 {\r
1893                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
1894                                         pCoexDm->psTdmaDuAdjType = 4;\r
1895                                 }\r
1896                                 if(pCoexDm->curPsTdma == 13)\r
1897                                 {\r
1898                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
1899                                         pCoexDm->psTdmaDuAdjType = 9;\r
1900                                 }\r
1901                                 else if(pCoexDm->curPsTdma == 14)\r
1902                                 {\r
1903                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
1904                                         pCoexDm->psTdmaDuAdjType = 10;\r
1905                                 }\r
1906                                 else if(pCoexDm->curPsTdma == 15)\r
1907                                 {\r
1908                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
1909                                         pCoexDm->psTdmaDuAdjType = 11;\r
1910                                 }\r
1911                                 else if(pCoexDm->curPsTdma == 16)\r
1912                                 {\r
1913                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
1914                                         pCoexDm->psTdmaDuAdjType = 12;\r
1915                                 }\r
1916                                 \r
1917                                 if(result == -1)\r
1918                                 {\r
1919                                         if(pCoexDm->curPsTdma == 1)\r
1920                                         {\r
1921                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
1922                                                 pCoexDm->psTdmaDuAdjType = 2;\r
1923                                         }\r
1924                                         else if(pCoexDm->curPsTdma == 2)\r
1925                                         {\r
1926                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
1927                                                 pCoexDm->psTdmaDuAdjType = 3;\r
1928                                         }\r
1929                                         else if(pCoexDm->curPsTdma == 3)\r
1930                                         {\r
1931                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
1932                                                 pCoexDm->psTdmaDuAdjType = 4;\r
1933                                         }\r
1934                                         else if(pCoexDm->curPsTdma == 9)\r
1935                                         {\r
1936                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
1937                                                 pCoexDm->psTdmaDuAdjType = 10;\r
1938                                         }\r
1939                                         else if(pCoexDm->curPsTdma == 10)\r
1940                                         {\r
1941                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
1942                                                 pCoexDm->psTdmaDuAdjType = 11;\r
1943                                         }\r
1944                                         else if(pCoexDm->curPsTdma == 11)\r
1945                                         {\r
1946                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
1947                                                 pCoexDm->psTdmaDuAdjType = 12;\r
1948                                         }\r
1949                                 } \r
1950                                 else if (result == 1)\r
1951                                 {\r
1952                                         if(pCoexDm->curPsTdma == 4)\r
1953                                         {\r
1954                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
1955                                                 pCoexDm->psTdmaDuAdjType = 3;\r
1956                                         }\r
1957                                         else if(pCoexDm->curPsTdma == 3)\r
1958                                         {\r
1959                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
1960                                                 pCoexDm->psTdmaDuAdjType = 2;\r
1961                                         }\r
1962                                         else if(pCoexDm->curPsTdma == 2)\r
1963                                         {\r
1964                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 1);\r
1965                                                 pCoexDm->psTdmaDuAdjType = 1;\r
1966                                         }\r
1967                                         else if(pCoexDm->curPsTdma == 12)\r
1968                                         {\r
1969                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
1970                                                 pCoexDm->psTdmaDuAdjType = 11;\r
1971                                         }\r
1972                                         else if(pCoexDm->curPsTdma == 11)\r
1973                                         {\r
1974                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
1975                                                 pCoexDm->psTdmaDuAdjType = 10;\r
1976                                         }\r
1977                                         else if(pCoexDm->curPsTdma == 10)\r
1978                                         {\r
1979                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
1980                                                 pCoexDm->psTdmaDuAdjType = 9;\r
1981                                         }\r
1982                                 }\r
1983                         }\r
1984                 }\r
1985                 else if(maxInterval == 2)\r
1986                 {\r
1987                         if(bTxPause)\r
1988                         {\r
1989                                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TxPause = 1\n"));\r
1990                                 if(pCoexDm->curPsTdma == 1)\r
1991                                 {\r
1992                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
1993                                         pCoexDm->psTdmaDuAdjType = 6;\r
1994                                 }\r
1995                                 else if(pCoexDm->curPsTdma == 2)\r
1996                                 {\r
1997                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
1998                                         pCoexDm->psTdmaDuAdjType = 6;\r
1999                                 }\r
2000                                 else if(pCoexDm->curPsTdma == 3)\r
2001                                 {\r
2002                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2003                                         pCoexDm->psTdmaDuAdjType = 7;\r
2004                                 }\r
2005                                 else if(pCoexDm->curPsTdma == 4)\r
2006                                 {\r
2007                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
2008                                         pCoexDm->psTdmaDuAdjType = 8;\r
2009                                 }\r
2010                                 if(pCoexDm->curPsTdma == 9)\r
2011                                 {\r
2012                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2013                                         pCoexDm->psTdmaDuAdjType = 14;\r
2014                                 }\r
2015                                 else if(pCoexDm->curPsTdma == 10)\r
2016                                 {\r
2017                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2018                                         pCoexDm->psTdmaDuAdjType = 14;\r
2019                                 }\r
2020                                 else if(pCoexDm->curPsTdma == 11)\r
2021                                 {\r
2022                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2023                                         pCoexDm->psTdmaDuAdjType = 15;\r
2024                                 }\r
2025                                 else if(pCoexDm->curPsTdma == 12)\r
2026                                 {\r
2027                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
2028                                         pCoexDm->psTdmaDuAdjType = 16;\r
2029                                 }\r
2030                                 if(result == -1)\r
2031                                 {\r
2032                                         if(pCoexDm->curPsTdma == 5) \r
2033                                         {\r
2034                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2035                                                 pCoexDm->psTdmaDuAdjType = 6;\r
2036                                         }\r
2037                                         else if(pCoexDm->curPsTdma == 6)\r
2038                                         {\r
2039                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2040                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2041                                         }\r
2042                                         else if(pCoexDm->curPsTdma == 7)\r
2043                                         {\r
2044                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
2045                                                 pCoexDm->psTdmaDuAdjType = 8;\r
2046                                         }\r
2047                                         else if(pCoexDm->curPsTdma == 13)\r
2048                                         {\r
2049                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2050                                                 pCoexDm->psTdmaDuAdjType = 14;\r
2051                                         }\r
2052                                         else if(pCoexDm->curPsTdma == 14)\r
2053                                         {\r
2054                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2055                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2056                                         }\r
2057                                         else if(pCoexDm->curPsTdma == 15)\r
2058                                         {\r
2059                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
2060                                                 pCoexDm->psTdmaDuAdjType = 16;\r
2061                                         }\r
2062                                 } \r
2063                                 else if (result == 1)\r
2064                                 {\r
2065                                         if(pCoexDm->curPsTdma == 8)\r
2066                                         {\r
2067                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2068                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2069                                         }\r
2070                                         else if(pCoexDm->curPsTdma == 7)\r
2071                                         {\r
2072                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2073                                                 pCoexDm->psTdmaDuAdjType = 6;\r
2074                                         }\r
2075                                         else if(pCoexDm->curPsTdma == 6)\r
2076                                         {\r
2077                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2078                                                 pCoexDm->psTdmaDuAdjType = 6;\r
2079                                         }                                       \r
2080                                         else if(pCoexDm->curPsTdma == 16)\r
2081                                         {\r
2082                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2083                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2084                                         }\r
2085                                         else if(pCoexDm->curPsTdma == 15)\r
2086                                         {\r
2087                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2088                                                 pCoexDm->psTdmaDuAdjType = 14;\r
2089                                         }\r
2090                                         else if(pCoexDm->curPsTdma == 14)\r
2091                                         {\r
2092                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2093                                                 pCoexDm->psTdmaDuAdjType = 14;\r
2094                                         }\r
2095                                 }\r
2096                         }\r
2097                         else\r
2098                         {\r
2099                                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TxPause = 0\n"));\r
2100                                 if(pCoexDm->curPsTdma == 5)\r
2101                                 {\r
2102                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2103                                         pCoexDm->psTdmaDuAdjType = 2;\r
2104                                 }\r
2105                                 else if(pCoexDm->curPsTdma == 6)\r
2106                                 {\r
2107                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2108                                         pCoexDm->psTdmaDuAdjType = 2;\r
2109                                 }\r
2110                                 else if(pCoexDm->curPsTdma == 7)\r
2111                                 {\r
2112                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2113                                         pCoexDm->psTdmaDuAdjType = 3;\r
2114                                 }\r
2115                                 else if(pCoexDm->curPsTdma == 8)\r
2116                                 {\r
2117                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
2118                                         pCoexDm->psTdmaDuAdjType = 4;\r
2119                                 }\r
2120                                 if(pCoexDm->curPsTdma == 13)\r
2121                                 {\r
2122                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2123                                         pCoexDm->psTdmaDuAdjType = 10;\r
2124                                 }\r
2125                                 else if(pCoexDm->curPsTdma == 14)\r
2126                                 {\r
2127                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2128                                         pCoexDm->psTdmaDuAdjType = 10;\r
2129                                 }\r
2130                                 else if(pCoexDm->curPsTdma == 15)\r
2131                                 {\r
2132                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2133                                         pCoexDm->psTdmaDuAdjType = 11;\r
2134                                 }\r
2135                                 else if(pCoexDm->curPsTdma == 16)\r
2136                                 {\r
2137                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
2138                                         pCoexDm->psTdmaDuAdjType = 12;\r
2139                                 }\r
2140                                 if(result == -1)\r
2141                                 {\r
2142                                         if(pCoexDm->curPsTdma == 1)\r
2143                                         {\r
2144                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2145                                                 pCoexDm->psTdmaDuAdjType = 2;\r
2146                                         }\r
2147                                         else if(pCoexDm->curPsTdma == 2)\r
2148                                         {\r
2149                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2150                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2151                                         }\r
2152                                         else if(pCoexDm->curPsTdma == 3)\r
2153                                         {\r
2154                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
2155                                                 pCoexDm->psTdmaDuAdjType = 4;\r
2156                                         }\r
2157                                         else if(pCoexDm->curPsTdma == 9)\r
2158                                         {\r
2159                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2160                                                 pCoexDm->psTdmaDuAdjType = 10;\r
2161                                         }\r
2162                                         else if(pCoexDm->curPsTdma == 10)\r
2163                                         {\r
2164                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2165                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2166                                         }\r
2167                                         else if(pCoexDm->curPsTdma == 11)\r
2168                                         {\r
2169                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
2170                                                 pCoexDm->psTdmaDuAdjType = 12;\r
2171                                         }\r
2172                                 } \r
2173                                 else if (result == 1)\r
2174                                 {\r
2175                                         if(pCoexDm->curPsTdma == 4)\r
2176                                         {\r
2177                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2178                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2179                                         }\r
2180                                         else if(pCoexDm->curPsTdma == 3)\r
2181                                         {\r
2182                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2183                                                 pCoexDm->psTdmaDuAdjType = 2;\r
2184                                         }\r
2185                                         else if(pCoexDm->curPsTdma == 2)\r
2186                                         {\r
2187                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2188                                                 pCoexDm->psTdmaDuAdjType = 2;\r
2189                                         }\r
2190                                         else if(pCoexDm->curPsTdma == 12)\r
2191                                         {\r
2192                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2193                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2194                                         }\r
2195                                         else if(pCoexDm->curPsTdma == 11)\r
2196                                         {\r
2197                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2198                                                 pCoexDm->psTdmaDuAdjType = 10;\r
2199                                         }\r
2200                                         else if(pCoexDm->curPsTdma == 10)\r
2201                                         {\r
2202                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2203                                                 pCoexDm->psTdmaDuAdjType = 10;\r
2204                                         }\r
2205                                 }\r
2206                         }\r
2207                 }\r
2208                 else if(maxInterval == 3)\r
2209                 {\r
2210                         if(bTxPause)\r
2211                         {\r
2212                                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TxPause = 1\n"));\r
2213                                 if(pCoexDm->curPsTdma == 1)\r
2214                                 {\r
2215                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2216                                         pCoexDm->psTdmaDuAdjType = 7;\r
2217                                 }\r
2218                                 else if(pCoexDm->curPsTdma == 2)\r
2219                                 {\r
2220                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2221                                         pCoexDm->psTdmaDuAdjType = 7;\r
2222                                 }\r
2223                                 else if(pCoexDm->curPsTdma == 3)\r
2224                                 {\r
2225                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2226                                         pCoexDm->psTdmaDuAdjType = 7;\r
2227                                 }\r
2228                                 else if(pCoexDm->curPsTdma == 4)\r
2229                                 {\r
2230                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
2231                                         pCoexDm->psTdmaDuAdjType = 8;\r
2232                                 }\r
2233                                 if(pCoexDm->curPsTdma == 9)\r
2234                                 {\r
2235                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2236                                         pCoexDm->psTdmaDuAdjType = 15;\r
2237                                 }\r
2238                                 else if(pCoexDm->curPsTdma == 10)\r
2239                                 {\r
2240                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2241                                         pCoexDm->psTdmaDuAdjType = 15;\r
2242                                 }\r
2243                                 else if(pCoexDm->curPsTdma == 11)\r
2244                                 {\r
2245                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2246                                         pCoexDm->psTdmaDuAdjType = 15;\r
2247                                 }\r
2248                                 else if(pCoexDm->curPsTdma == 12)\r
2249                                 {\r
2250                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
2251                                         pCoexDm->psTdmaDuAdjType = 16;\r
2252                                 }\r
2253                                 if(result == -1)\r
2254                                 {\r
2255                                         if(pCoexDm->curPsTdma == 5) \r
2256                                         {\r
2257                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2258                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2259                                         }\r
2260                                         else if(pCoexDm->curPsTdma == 6)\r
2261                                         {\r
2262                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2263                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2264                                         }\r
2265                                         else if(pCoexDm->curPsTdma == 7)\r
2266                                         {\r
2267                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
2268                                                 pCoexDm->psTdmaDuAdjType = 8;\r
2269                                         }\r
2270                                         else if(pCoexDm->curPsTdma == 13)\r
2271                                         {\r
2272                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2273                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2274                                         }\r
2275                                         else if(pCoexDm->curPsTdma == 14)\r
2276                                         {\r
2277                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2278                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2279                                         }\r
2280                                         else if(pCoexDm->curPsTdma == 15)\r
2281                                         {\r
2282                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
2283                                                 pCoexDm->psTdmaDuAdjType = 16;\r
2284                                         }\r
2285                                 } \r
2286                                 else if (result == 1)\r
2287                                 {\r
2288                                         if(pCoexDm->curPsTdma == 8)\r
2289                                         {\r
2290                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2291                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2292                                         }\r
2293                                         else if(pCoexDm->curPsTdma == 7)\r
2294                                         {\r
2295                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2296                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2297                                         }\r
2298                                         else if(pCoexDm->curPsTdma == 6)\r
2299                                         {\r
2300                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 7);\r
2301                                                 pCoexDm->psTdmaDuAdjType = 7;\r
2302                                         }                                       \r
2303                                         else if(pCoexDm->curPsTdma == 16)\r
2304                                         {\r
2305                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2306                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2307                                         }\r
2308                                         else if(pCoexDm->curPsTdma == 15)\r
2309                                         {\r
2310                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2311                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2312                                         }\r
2313                                         else if(pCoexDm->curPsTdma == 14)\r
2314                                         {\r
2315                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2316                                                 pCoexDm->psTdmaDuAdjType = 15;\r
2317                                         }\r
2318                                 }\r
2319                         }\r
2320                         else\r
2321                         {\r
2322                                 RT_TRACE(COMP_COEX, DBG_TRACE, ("[BTCoex], TxPause = 0\n"));\r
2323                                 if(pCoexDm->curPsTdma == 5)\r
2324                                 {\r
2325                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2326                                         pCoexDm->psTdmaDuAdjType = 3;\r
2327                                 }\r
2328                                 else if(pCoexDm->curPsTdma == 6)\r
2329                                 {\r
2330                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2331                                         pCoexDm->psTdmaDuAdjType = 3;\r
2332                                 }\r
2333                                 else if(pCoexDm->curPsTdma == 7)\r
2334                                 {\r
2335                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2336                                         pCoexDm->psTdmaDuAdjType = 3;\r
2337                                 }\r
2338                                 else if(pCoexDm->curPsTdma == 8)\r
2339                                 {\r
2340                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
2341                                         pCoexDm->psTdmaDuAdjType = 4;\r
2342                                 }\r
2343                                 if(pCoexDm->curPsTdma == 13)\r
2344                                 {\r
2345                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2346                                         pCoexDm->psTdmaDuAdjType = 11;\r
2347                                 }\r
2348                                 else if(pCoexDm->curPsTdma == 14)\r
2349                                 {\r
2350                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2351                                         pCoexDm->psTdmaDuAdjType = 11;\r
2352                                 }\r
2353                                 else if(pCoexDm->curPsTdma == 15)\r
2354                                 {\r
2355                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2356                                         pCoexDm->psTdmaDuAdjType = 11;\r
2357                                 }\r
2358                                 else if(pCoexDm->curPsTdma == 16)\r
2359                                 {\r
2360                                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
2361                                         pCoexDm->psTdmaDuAdjType = 12;\r
2362                                 }\r
2363                                 if(result == -1)\r
2364                                 {\r
2365                                         if(pCoexDm->curPsTdma == 1)\r
2366                                         {\r
2367                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2368                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2369                                         }\r
2370                                         else if(pCoexDm->curPsTdma == 2)\r
2371                                         {\r
2372                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2373                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2374                                         }\r
2375                                         else if(pCoexDm->curPsTdma == 3)\r
2376                                         {\r
2377                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
2378                                                 pCoexDm->psTdmaDuAdjType = 4;\r
2379                                         }\r
2380                                         else if(pCoexDm->curPsTdma == 9)\r
2381                                         {\r
2382                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2383                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2384                                         }\r
2385                                         else if(pCoexDm->curPsTdma == 10)\r
2386                                         {\r
2387                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2388                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2389                                         }\r
2390                                         else if(pCoexDm->curPsTdma == 11)\r
2391                                         {\r
2392                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
2393                                                 pCoexDm->psTdmaDuAdjType = 12;\r
2394                                         }\r
2395                                 } \r
2396                                 else if (result == 1)\r
2397                                 {\r
2398                                         if(pCoexDm->curPsTdma == 4)\r
2399                                         {\r
2400                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2401                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2402                                         }\r
2403                                         else if(pCoexDm->curPsTdma == 3)\r
2404                                         {\r
2405                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2406                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2407                                         }\r
2408                                         else if(pCoexDm->curPsTdma == 2)\r
2409                                         {\r
2410                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 3);\r
2411                                                 pCoexDm->psTdmaDuAdjType = 3;\r
2412                                         }\r
2413                                         else if(pCoexDm->curPsTdma == 12)\r
2414                                         {\r
2415                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2416                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2417                                         }\r
2418                                         else if(pCoexDm->curPsTdma == 11)\r
2419                                         {\r
2420                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2421                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2422                                         }\r
2423                                         else if(pCoexDm->curPsTdma == 10)\r
2424                                         {\r
2425                                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2426                                                 pCoexDm->psTdmaDuAdjType = 11;\r
2427                                         }\r
2428                                 }\r
2429                         }\r
2430                 }\r
2431         }\r
2432 \r
2433         // if current PsTdma not match with the recorded one (when scan, dhcp...), \r
2434         // then we have to adjust it back to the previous record one.\r
2435         if(pCoexDm->curPsTdma != pCoexDm->psTdmaDuAdjType)\r
2436         {\r
2437                 BOOLEAN bScan=FALSE, bLink=FALSE, bRoam=FALSE;\r
2438                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], PsTdma type dismatch!!!, curPsTdma=%d, recordPsTdma=%d\n", \r
2439                         pCoexDm->curPsTdma, pCoexDm->psTdmaDuAdjType));\r
2440 \r
2441                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_SCAN, &bScan);\r
2442                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_LINK, &bLink);\r
2443                 pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_WIFI_ROAM, &bRoam);\r
2444                 \r
2445                 if( !bScan && !bLink && !bRoam)\r
2446                 {\r
2447                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, pCoexDm->psTdmaDuAdjType);\r
2448                 }\r
2449                 else\r
2450                 {\r
2451                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n"));\r
2452                 }\r
2453         }\r
2454 }\r
2455 \r
2456 // SCO only or SCO+PAN(HS)\r
2457 VOID\r
2458 halbtc8723a2ant_ActionSco(\r
2459         IN      PBTC_COEXIST            pBtCoexist\r
2460         )\r
2461 {\r
2462         u1Byte  wifiRssiState, wifiRssiState1;\r
2463         u4Byte  wifiBw;\r
2464 \r
2465         if(halbtc8723a2ant_NeedToDecBtPwr(pBtCoexist))\r
2466                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, TRUE);\r
2467         else    \r
2468                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, FALSE);\r
2469         halbtc8723a2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3);\r
2470         \r
2471         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
2472         if(BTC_WIFI_BW_HT40 == wifiBw)\r
2473         {\r
2474                 wifiRssiState = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 37, 0);\r
2475                 // fw mechanism\r
2476                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2477                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2478                 {\r
2479                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2480                 }\r
2481                 else\r
2482                 {\r
2483                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2484                 }\r
2485 \r
2486                 // sw mechanism         \r
2487                 halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
2488                 halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
2489                 halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2490         }\r
2491         else\r
2492         {\r
2493                 wifiRssiState = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 27, 0);\r
2494                 wifiRssiState1 = halbtc8723a2ant_WifiRssiState(pBtCoexist, 1, 2, 47, 0);\r
2495                 \r
2496                 // fw mechanism\r
2497                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2498                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2499                 {\r
2500                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 11);\r
2501                 }\r
2502                 else\r
2503                 {\r
2504                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 15);\r
2505                 }\r
2506                 \r
2507                 // sw mechanism\r
2508                 if( (wifiRssiState1 == BTC_RSSI_STATE_HIGH) ||\r
2509                         (wifiRssiState1 == BTC_RSSI_STATE_STAY_HIGH) )\r
2510                 {\r
2511                         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, TRUE);\r
2512                         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
2513                         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2514                 }\r
2515                 else\r
2516                 {\r
2517                         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
2518                         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
2519                         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2520                 }               \r
2521         }\r
2522 }\r
2523 \r
2524 \r
2525 VOID\r
2526 halbtc8723a2ant_ActionHid(\r
2527         IN      PBTC_COEXIST            pBtCoexist\r
2528         )\r
2529 {\r
2530         u1Byte  wifiRssiState, wifiRssiState1;\r
2531         u4Byte  wifiBw;\r
2532 \r
2533         if(halbtc8723a2ant_NeedToDecBtPwr(pBtCoexist))\r
2534                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, TRUE);\r
2535         else    \r
2536                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, FALSE);\r
2537         halbtc8723a2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3);\r
2538 \r
2539         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
2540         if(BTC_WIFI_BW_HT40 == wifiBw)\r
2541         {\r
2542                 wifiRssiState = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 37, 0);\r
2543                 // fw mechanism\r
2544                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2545                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2546                 {\r
2547                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
2548                 }\r
2549                 else\r
2550                 {\r
2551                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);\r
2552                 }\r
2553 \r
2554                 // sw mechanism\r
2555                 halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
2556                 halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
2557                 halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2558         }\r
2559         else\r
2560         {\r
2561                 wifiRssiState = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 27, 0);\r
2562                 wifiRssiState1 = halbtc8723a2ant_WifiRssiState(pBtCoexist, 1, 2, 47, 0);\r
2563 \r
2564                 // fw mechanism\r
2565                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2566                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2567                 {\r
2568                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 9);\r
2569                 }\r
2570                 else\r
2571                 {\r
2572                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 13);\r
2573                 }\r
2574 \r
2575                 // sw mechanism\r
2576                 if( (wifiRssiState1 == BTC_RSSI_STATE_HIGH) ||\r
2577                         (wifiRssiState1 == BTC_RSSI_STATE_STAY_HIGH) )\r
2578                 {\r
2579                         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, TRUE);\r
2580                         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
2581                         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2582                 }\r
2583                 else\r
2584                 {\r
2585                         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
2586                         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
2587                         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2588                 }               \r
2589         }\r
2590 }\r
2591 \r
2592 //A2DP only / PAN(EDR) only/ A2DP+PAN(HS)\r
2593 VOID\r
2594 halbtc8723a2ant_ActionA2dp(\r
2595         IN      PBTC_COEXIST            pBtCoexist\r
2596         )\r
2597 {\r
2598         u1Byte          wifiRssiState, wifiRssiState1, btInfoExt;\r
2599         u4Byte          wifiBw;\r
2600 \r
2601         btInfoExt = pCoexSta->btInfoExt;\r
2602 \r
2603         if(halbtc8723a2ant_NeedToDecBtPwr(pBtCoexist))\r
2604                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, TRUE);\r
2605         else    \r
2606                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, FALSE);\r
2607         halbtc8723a2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3);\r
2608         \r
2609         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
2610         if(BTC_WIFI_BW_HT40 == wifiBw)\r
2611         {\r
2612                 wifiRssiState = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 37, 0);\r
2613 \r
2614                 // fw mechanism\r
2615                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2616                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2617                 {\r
2618                         if(btInfoExt&BIT0)      //a2dp rate, 1:basic /0:edr\r
2619                         {\r
2620                                 halbtc8723a2ant_TdmaDurationAdjust(pBtCoexist, FALSE, FALSE, 3);\r
2621                         }\r
2622                         else\r
2623                         {\r
2624                                 halbtc8723a2ant_TdmaDurationAdjust(pBtCoexist, FALSE, FALSE, 1);\r
2625                         }\r
2626                 }\r
2627                 else\r
2628                 {\r
2629                         if(btInfoExt&BIT0)      //a2dp rate, 1:basic /0:edr\r
2630                         {\r
2631                                 halbtc8723a2ant_TdmaDurationAdjust(pBtCoexist, FALSE, TRUE, 3);\r
2632                         }\r
2633                         else\r
2634                         {\r
2635                                 halbtc8723a2ant_TdmaDurationAdjust(pBtCoexist, FALSE, TRUE, 1);\r
2636                         }\r
2637                 }\r
2638 \r
2639                 // sw mechanism         \r
2640                 halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
2641                 halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
2642                 halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2643         }\r
2644         else\r
2645         {\r
2646                 wifiRssiState = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 27, 0);\r
2647                 wifiRssiState1 = halbtc8723a2ant_WifiRssiState(pBtCoexist, 1, 2, 47, 0);\r
2648                 \r
2649                 // fw mechanism\r
2650                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2651                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2652                 {\r
2653                         if(btInfoExt&BIT0)      //a2dp rate, 1:basic /0:edr\r
2654                         {\r
2655                                 halbtc8723a2ant_TdmaDurationAdjust(pBtCoexist, FALSE, FALSE, 3);\r
2656                         }\r
2657                         else\r
2658                         {\r
2659                                 halbtc8723a2ant_TdmaDurationAdjust(pBtCoexist, FALSE, FALSE, 1);\r
2660                         }\r
2661                 }\r
2662                 else\r
2663                 {\r
2664                         if(btInfoExt&BIT0)      //a2dp rate, 1:basic /0:edr\r
2665                         {\r
2666                                 halbtc8723a2ant_TdmaDurationAdjust(pBtCoexist, FALSE, TRUE, 3);\r
2667                         }\r
2668                         else\r
2669                         {\r
2670                                 halbtc8723a2ant_TdmaDurationAdjust(pBtCoexist, FALSE, TRUE, 1);\r
2671                         }\r
2672                 }\r
2673                 \r
2674                 // sw mechanism\r
2675                 if( (wifiRssiState1 == BTC_RSSI_STATE_HIGH) ||\r
2676                         (wifiRssiState1 == BTC_RSSI_STATE_STAY_HIGH) )\r
2677                 {\r
2678                         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, TRUE);\r
2679                         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
2680                         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2681                 }\r
2682                 else\r
2683                 {\r
2684                         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
2685                         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
2686                         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2687                 }               \r
2688         }\r
2689 }\r
2690 \r
2691 VOID\r
2692 halbtc8723a2ant_ActionPanEdr(\r
2693         IN      PBTC_COEXIST            pBtCoexist\r
2694         )\r
2695 {\r
2696         u1Byte          wifiRssiState, wifiRssiState1, btInfoExt;\r
2697         u4Byte          wifiBw;\r
2698         \r
2699         btInfoExt = pCoexSta->btInfoExt;\r
2700 \r
2701         if(halbtc8723a2ant_NeedToDecBtPwr(pBtCoexist))\r
2702                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, TRUE);\r
2703         else    \r
2704                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, FALSE);\r
2705         halbtc8723a2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3);\r
2706 \r
2707         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
2708         if(BTC_WIFI_BW_HT40 == wifiBw)\r
2709         {\r
2710                 wifiRssiState = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 37, 0);\r
2711                         \r
2712                 // fw mechanism\r
2713                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2714                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2715                 {\r
2716                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2717                 }\r
2718                 else\r
2719                 {\r
2720                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2721                 }\r
2722 \r
2723                 // sw mechanism\r
2724                 halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
2725                 halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
2726                 halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2727         }\r
2728         else\r
2729         {\r
2730                 wifiRssiState = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 27, 0);\r
2731                 wifiRssiState1 = halbtc8723a2ant_WifiRssiState(pBtCoexist, 1, 2, 47, 0);\r
2732                 \r
2733                 // fw mechanism\r
2734                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2735                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2736                 {\r
2737                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2738                 }\r
2739                 else\r
2740                 {\r
2741                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2742                 }\r
2743 \r
2744                 // sw mechanism\r
2745                 if( (wifiRssiState1 == BTC_RSSI_STATE_HIGH) ||\r
2746                         (wifiRssiState1 == BTC_RSSI_STATE_STAY_HIGH) )\r
2747                 {\r
2748                         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, TRUE);\r
2749                         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
2750                         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2751                 }\r
2752                 else\r
2753                 {\r
2754                         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
2755                         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
2756                         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2757                 }\r
2758         }\r
2759 }\r
2760 \r
2761 \r
2762 //PAN(HS) only\r
2763 VOID\r
2764 halbtc8723a2ant_ActionPanHs(\r
2765         IN      PBTC_COEXIST            pBtCoexist\r
2766         )\r
2767 {\r
2768         u1Byte          wifiRssiState;\r
2769         u4Byte          wifiBw;\r
2770 \r
2771         halbtc8723a2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3);\r
2772 \r
2773         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
2774         if(BTC_WIFI_BW_HT40 == wifiBw)\r
2775         {\r
2776                 wifiRssiState = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 37, 0);\r
2777 \r
2778                 // fw mechanism\r
2779                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2780                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2781                 {\r
2782                         halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, TRUE);\r
2783                 }\r
2784                 else\r
2785                 {\r
2786                         halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, FALSE);\r
2787                 }\r
2788                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
2789 \r
2790                 // sw mechanism         \r
2791                 halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
2792                 halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
2793                 halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2794         }\r
2795         else\r
2796         {\r
2797                 wifiRssiState = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 37, 0);\r
2798 \r
2799                 // fw mechanism\r
2800                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2801                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2802                 {\r
2803                         halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, TRUE);\r
2804                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
2805                 }\r
2806                 else\r
2807                 {\r
2808                         halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, FALSE);\r
2809                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, FALSE, 0);\r
2810                 }\r
2811 \r
2812                 // sw mechanism\r
2813                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2814                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2815                 {\r
2816                         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, TRUE);\r
2817                         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
2818                         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2819                 }\r
2820                 else\r
2821                 {\r
2822                         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
2823                         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
2824                         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2825                 }\r
2826         }\r
2827 }\r
2828 \r
2829 //PAN(EDR)+A2DP\r
2830 VOID\r
2831 halbtc8723a2ant_ActionPanEdrA2dp(\r
2832         IN      PBTC_COEXIST            pBtCoexist\r
2833         )\r
2834 {\r
2835         u1Byte          wifiRssiState, wifiRssiState1, btInfoExt;\r
2836         u4Byte          wifiBw;\r
2837 \r
2838         btInfoExt = pCoexSta->btInfoExt;\r
2839 \r
2840         if(halbtc8723a2ant_NeedToDecBtPwr(pBtCoexist))\r
2841                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, TRUE);\r
2842         else    \r
2843                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, FALSE);\r
2844         halbtc8723a2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3);\r
2845 \r
2846         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
2847         if(BTC_WIFI_BW_HT40 == wifiBw)\r
2848         {\r
2849                 wifiRssiState = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 37, 0);\r
2850 \r
2851                 // fw mechanism\r
2852                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2853                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2854                 {\r
2855                         if(btInfoExt&BIT0)      //a2dp basic rate\r
2856                         {\r
2857                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
2858                         }\r
2859                         else                            //a2dp edr rate\r
2860                         {\r
2861                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2862                         }\r
2863                 }\r
2864                 else\r
2865                 {\r
2866                         if(btInfoExt&BIT0)      //a2dp basic rate\r
2867                         {\r
2868                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
2869                         }\r
2870                         else                            //a2dp edr rate\r
2871                         {\r
2872                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2873                         }\r
2874                 }\r
2875 \r
2876                 // sw mechanism\r
2877                 halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
2878                 halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
2879                 halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2880         }\r
2881         else\r
2882         {\r
2883                 wifiRssiState = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 27, 0);\r
2884                 wifiRssiState1 = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 47, 0);\r
2885                 \r
2886                 // fw mechanism\r
2887                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2888                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2889                 {\r
2890                         if(btInfoExt&BIT0)      //a2dp basic rate\r
2891                         {\r
2892                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 4);\r
2893                         }\r
2894                         else                            //a2dp edr rate\r
2895                         {\r
2896                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 2);\r
2897                         }\r
2898                 }\r
2899                 else\r
2900                 {\r
2901                         if(btInfoExt&BIT0)      //a2dp basic rate\r
2902                         {\r
2903                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 8);\r
2904                         }\r
2905                         else                            //a2dp edr rate\r
2906                         {\r
2907                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 6);\r
2908                         }\r
2909                 }\r
2910 \r
2911                 // sw mechanism\r
2912                 if( (wifiRssiState1 == BTC_RSSI_STATE_HIGH) ||\r
2913                         (wifiRssiState1 == BTC_RSSI_STATE_STAY_HIGH) )\r
2914                 {\r
2915                         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, TRUE);\r
2916                         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
2917                         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2918                 }\r
2919                 else\r
2920                 {\r
2921                         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
2922                         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
2923                         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2924                 }\r
2925         }\r
2926 }\r
2927 \r
2928 VOID\r
2929 halbtc8723a2ant_ActionPanEdrHid(\r
2930         IN      PBTC_COEXIST            pBtCoexist\r
2931         )\r
2932 {\r
2933         u1Byte          wifiRssiState, wifiRssiState1;\r
2934         u4Byte          wifiBw;\r
2935 \r
2936         if(halbtc8723a2ant_NeedToDecBtPwr(pBtCoexist))\r
2937                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, TRUE);\r
2938         else    \r
2939                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, FALSE);\r
2940         halbtc8723a2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3);\r
2941 \r
2942         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
2943         if(BTC_WIFI_BW_HT40 == wifiBw)\r
2944         {\r
2945                 wifiRssiState = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 37, 0);\r
2946 \r
2947                 // fw mechanism\r
2948                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2949                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2950                 {\r
2951                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10); \r
2952                 }\r
2953                 else\r
2954                 {\r
2955                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14); \r
2956                 }\r
2957 \r
2958                 // sw mechanism\r
2959                 halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
2960                 halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
2961                 halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2962         }\r
2963         else\r
2964         {\r
2965                 wifiRssiState = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 27, 0);\r
2966                 wifiRssiState1 = halbtc8723a2ant_WifiRssiState(pBtCoexist, 1, 2, 47, 0);\r
2967                 \r
2968                 // fw mechanism\r
2969                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2970                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2971                 {\r
2972                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
2973                 }\r
2974                 else\r
2975                 {\r
2976                         halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
2977                 }\r
2978                 \r
2979                 // sw mechanism\r
2980                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
2981                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
2982                 {\r
2983                         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, TRUE);\r
2984                         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
2985                         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2986                 }\r
2987                 else\r
2988                 {\r
2989                         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
2990                         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
2991                         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
2992                 }\r
2993         }\r
2994 }\r
2995 \r
2996 // HID+A2DP+PAN(EDR)\r
2997 VOID\r
2998 halbtc8723a2ant_ActionHidA2dpPanEdr(\r
2999         IN      PBTC_COEXIST            pBtCoexist\r
3000         )\r
3001 {\r
3002         u1Byte          wifiRssiState, wifiRssiState1, btInfoExt;\r
3003         u4Byte          wifiBw;\r
3004 \r
3005         btInfoExt = pCoexSta->btInfoExt;\r
3006 \r
3007         if(halbtc8723a2ant_NeedToDecBtPwr(pBtCoexist))\r
3008                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, TRUE);\r
3009         else    \r
3010                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, FALSE);\r
3011         halbtc8723a2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3);\r
3012 \r
3013         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3014         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3015         {\r
3016                 wifiRssiState = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 37, 0);\r
3017                         \r
3018                 // fw mechanism\r
3019                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3020                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3021                 {\r
3022                         if(btInfoExt&BIT0)      //a2dp basic rate\r
3023                         {\r
3024                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
3025                         }\r
3026                         else                            //a2dp edr rate\r
3027                         {\r
3028                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
3029                         }\r
3030                 }\r
3031                 else\r
3032                 {\r
3033                         if(btInfoExt&BIT0)      //a2dp basic rate\r
3034                         {\r
3035                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
3036                         }\r
3037                         else                            //a2dp edr rate\r
3038                         {\r
3039                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
3040                         }\r
3041                 }\r
3042                 \r
3043                 // sw mechanism\r
3044                 halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
3045                 halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
3046                 halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
3047         }\r
3048         else\r
3049         {\r
3050                 wifiRssiState = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 27, 0);\r
3051                 wifiRssiState1 = halbtc8723a2ant_WifiRssiState(pBtCoexist, 1, 2, 47, 0);\r
3052                 \r
3053                 // fw mechanism\r
3054                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3055                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3056                 {\r
3057                         if(btInfoExt&BIT0)      //a2dp basic rate\r
3058                         {\r
3059                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 12);\r
3060                         }\r
3061                         else                            //a2dp edr rate\r
3062                         {\r
3063                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 10);\r
3064                         }\r
3065                 }\r
3066                 else\r
3067                 {\r
3068                         if(btInfoExt&BIT0)      //a2dp basic rate\r
3069                         {\r
3070                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 16);\r
3071                         }\r
3072                         else                            //a2dp edr rate\r
3073                         {\r
3074                                 halbtc8723a2ant_PsTdma(pBtCoexist, NORMAL_EXEC, TRUE, 14);\r
3075                         }\r
3076                 }\r
3077 \r
3078                 // sw mechanism\r
3079                 if( (wifiRssiState1 == BTC_RSSI_STATE_HIGH) ||\r
3080                         (wifiRssiState1 == BTC_RSSI_STATE_STAY_HIGH) )\r
3081                 {\r
3082                         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, TRUE);\r
3083                         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
3084                         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
3085                 }\r
3086                 else\r
3087                 {\r
3088                         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
3089                         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
3090                         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
3091                 }\r
3092         }\r
3093 }\r
3094 \r
3095 VOID\r
3096 halbtc8723a2ant_ActionHidA2dp(\r
3097         IN      PBTC_COEXIST            pBtCoexist\r
3098         )\r
3099 {\r
3100         u1Byte          wifiRssiState, wifiRssiState1, btInfoExt;\r
3101         u4Byte          wifiBw;\r
3102 \r
3103         btInfoExt = pCoexSta->btInfoExt;\r
3104 \r
3105         if(halbtc8723a2ant_NeedToDecBtPwr(pBtCoexist))\r
3106                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, TRUE);\r
3107         else    \r
3108                 halbtc8723a2ant_DecBtPwr(pBtCoexist, NORMAL_EXEC, FALSE);\r
3109         halbtc8723a2ant_CoexTable(pBtCoexist, NORMAL_EXEC, 0x55555555, 0xffff, 0x3);\r
3110 \r
3111         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_U4_WIFI_BW, &wifiBw);\r
3112         if(BTC_WIFI_BW_HT40 == wifiBw)\r
3113         {\r
3114                 wifiRssiState = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 37, 0);\r
3115                 \r
3116                 // fw mechanism\r
3117                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3118                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3119                 {\r
3120                         if(btInfoExt&BIT0)      //a2dp basic rate\r
3121                         {\r
3122                                 halbtc8723a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, FALSE, 3);\r
3123                         }\r
3124                         else                            //a2dp edr rate\r
3125                         {\r
3126                                 halbtc8723a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, FALSE, 1);\r
3127                         }\r
3128                 }\r
3129                 else\r
3130                 {\r
3131                         if(btInfoExt&BIT0)      //a2dp basic rate\r
3132                         {\r
3133                                 halbtc8723a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, TRUE, 3);\r
3134                         }\r
3135                         else                            //a2dp edr rate\r
3136                         {\r
3137                                 halbtc8723a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, TRUE, 1);\r
3138                         }\r
3139                 }\r
3140                 \r
3141                 // sw mechanism\r
3142                 halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
3143                 halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
3144                 halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
3145         }\r
3146         else\r
3147         {\r
3148                 wifiRssiState = halbtc8723a2ant_WifiRssiState(pBtCoexist, 0, 2, 27, 0);\r
3149                 wifiRssiState1 = halbtc8723a2ant_WifiRssiState(pBtCoexist, 1, 2, 47, 0);\r
3150                 \r
3151                 // fw mechanism\r
3152                 if( (wifiRssiState == BTC_RSSI_STATE_HIGH) ||\r
3153                         (wifiRssiState == BTC_RSSI_STATE_STAY_HIGH) )\r
3154                 {\r
3155                         if(btInfoExt&BIT0)      //a2dp basic rate\r
3156                         {\r
3157                                 halbtc8723a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, FALSE, 3);\r
3158                         }\r
3159                         else                            //a2dp edr rate\r
3160                         {\r
3161                                 halbtc8723a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, FALSE, 1);\r
3162                         }\r
3163                 }\r
3164                 else\r
3165                 {\r
3166                         if(btInfoExt&BIT0)      //a2dp basic rate\r
3167                         {\r
3168                                 halbtc8723a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, TRUE, 3);\r
3169                         }\r
3170                         else                            //a2dp edr rate\r
3171                         {\r
3172                                 halbtc8723a2ant_TdmaDurationAdjust(pBtCoexist, TRUE, TRUE, 1);\r
3173                         }\r
3174                 }\r
3175 \r
3176                 // sw mechanism\r
3177                 if( (wifiRssiState1 == BTC_RSSI_STATE_HIGH) ||\r
3178                         (wifiRssiState1 == BTC_RSSI_STATE_STAY_HIGH) )\r
3179                 {\r
3180                         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, TRUE);\r
3181                         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, TRUE);\r
3182                         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
3183                 }\r
3184                 else\r
3185                 {\r
3186                         halbtc8723a2ant_AgcTable(pBtCoexist, NORMAL_EXEC, FALSE);\r
3187                         halbtc8723a2ant_AdcBackOff(pBtCoexist, NORMAL_EXEC, FALSE);\r
3188                         halbtc8723a2ant_DacSwing(pBtCoexist, NORMAL_EXEC, FALSE, 0xc0);\r
3189                 }\r
3190         }\r
3191 }\r
3192 \r
3193 VOID\r
3194 halbtc8723a2ant_RunCoexistMechanism(\r
3195         IN      PBTC_COEXIST            pBtCoexist\r
3196         )\r
3197 {\r
3198         PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;\r
3199         u1Byte                          btInfoOriginal=0, btRetryCnt=0;\r
3200         u1Byte                          algorithm=0;\r
3201 \r
3202         if(pBtCoexist->bManualControl)\r
3203         {\r
3204                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Manual control!!!\n"));\r
3205                 return;\r
3206         }\r
3207 \r
3208         if(pStackInfo->bProfileNotified)\r
3209         {\r
3210                 if(pCoexSta->bHoldForStackOperation)\r
3211                 {\r
3212                         // if bt inquiry/page/pair, do not execute.\r
3213                         return;\r
3214                 }\r
3215                 \r
3216                 algorithm = halbtc8723a2ant_ActionAlgorithm(pBtCoexist);\r
3217                 if(pCoexSta->bHoldPeriodCnt && (BT_8723A_2ANT_COEX_ALGO_PANHS!=algorithm))\r
3218                 {\r
3219                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex],Hold BT inquiry/page scan setting (cnt = %d)!!\n", \r
3220                                 pCoexSta->bHoldPeriodCnt));\r
3221                         if(pCoexSta->bHoldPeriodCnt >= 6)\r
3222                         {\r
3223                                 pCoexSta->bHoldPeriodCnt = 0;\r
3224                                 // next time the coexist parameters should be reset again.\r
3225                         }\r
3226                         else\r
3227                                 pCoexSta->bHoldPeriodCnt++;\r
3228                         return;\r
3229                 }\r
3230 \r
3231                 pCoexDm->curAlgorithm = algorithm;\r
3232                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Algorithm = %d \n", pCoexDm->curAlgorithm));\r
3233                 if(halbtc8723a2ant_IsCommonAction(pBtCoexist))\r
3234                 {\r
3235                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant common.\n"));\r
3236                         pCoexDm->bResetTdmaAdjust = TRUE;\r
3237                 }\r
3238                 else\r
3239                 {\r
3240                         if(pCoexDm->curAlgorithm != pCoexDm->preAlgorithm)\r
3241                         {\r
3242                                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], preAlgorithm=%d, curAlgorithm=%d\n", \r
3243                                         pCoexDm->preAlgorithm, pCoexDm->curAlgorithm));\r
3244                                 pCoexDm->bResetTdmaAdjust = TRUE;\r
3245                         }\r
3246                         switch(pCoexDm->curAlgorithm)\r
3247                         {\r
3248                                 case BT_8723A_2ANT_COEX_ALGO_SCO:\r
3249                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = SCO.\n"));\r
3250                                         halbtc8723a2ant_ActionSco(pBtCoexist);\r
3251                                         break;\r
3252                                 case BT_8723A_2ANT_COEX_ALGO_HID:\r
3253                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = HID.\n"));\r
3254                                         halbtc8723a2ant_ActionHid(pBtCoexist);\r
3255                                         break;\r
3256                                 case BT_8723A_2ANT_COEX_ALGO_A2DP:\r
3257                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = A2DP.\n"));\r
3258                                         halbtc8723a2ant_ActionA2dp(pBtCoexist);\r
3259                                         break;\r
3260                                 case BT_8723A_2ANT_COEX_ALGO_PANEDR:\r
3261                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = PAN(EDR).\n"));\r
3262                                         halbtc8723a2ant_ActionPanEdr(pBtCoexist);\r
3263                                         break;\r
3264                                 case BT_8723A_2ANT_COEX_ALGO_PANHS:\r
3265                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = HS mode.\n"));\r
3266                                         halbtc8723a2ant_ActionPanHs(pBtCoexist);\r
3267                                         break;\r
3268                                 case BT_8723A_2ANT_COEX_ALGO_PANEDR_A2DP:\r
3269                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = PAN+A2DP.\n"));\r
3270                                         halbtc8723a2ant_ActionPanEdrA2dp(pBtCoexist);\r
3271                                         break;\r
3272                                 case BT_8723A_2ANT_COEX_ALGO_PANEDR_HID:\r
3273                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = PAN(EDR)+HID.\n"));\r
3274                                         halbtc8723a2ant_ActionPanEdrHid(pBtCoexist);\r
3275                                         break;\r
3276                                 case BT_8723A_2ANT_COEX_ALGO_HID_A2DP_PANEDR:\r
3277                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN.\n"));\r
3278                                         halbtc8723a2ant_ActionHidA2dpPanEdr(pBtCoexist);\r
3279                                         break;\r
3280                                 case BT_8723A_2ANT_COEX_ALGO_HID_A2DP:\r
3281                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = HID+A2DP.\n"));\r
3282                                         halbtc8723a2ant_ActionHidA2dp(pBtCoexist);\r
3283                                         break;\r
3284                                 default:\r
3285                                         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Action 2-Ant, algorithm = coexist All Off!!\n"));\r
3286                                         halbtc8723a2ant_CoexAllOff(pBtCoexist);\r
3287                                         break;\r
3288                         }\r
3289                         pCoexDm->preAlgorithm = pCoexDm->curAlgorithm;\r
3290                 }\r
3291         }\r
3292 }\r
3293 \r
3294 //============================================================\r
3295 // work around function start with wa_halbtc8723a2ant_\r
3296 //============================================================\r
3297 VOID\r
3298 wa_halbtc8723a2ant_MonitorC2h(\r
3299         IN      PBTC_COEXIST                    pBtCoexist\r
3300         )\r
3301 {\r
3302         u1Byte  tmp1b=0x0;\r
3303         u4Byte  curC2hTotalCnt=0x0;\r
3304         static u4Byte   preC2hTotalCnt=0x0, sameCntPollingTime=0x0;\r
3305 \r
3306         curC2hTotalCnt+=pCoexSta->btInfoC2hCnt[BT_INFO_SRC_8723A_2ANT_BT_RSP];\r
3307 \r
3308         if(curC2hTotalCnt == preC2hTotalCnt)\r
3309         {\r
3310                 sameCntPollingTime++;\r
3311         }\r
3312         else\r
3313         {\r
3314                 preC2hTotalCnt = curC2hTotalCnt;\r
3315                 sameCntPollingTime = 0;\r
3316         }\r
3317 \r
3318         if(sameCntPollingTime >= 2)\r
3319         {\r
3320                 tmp1b = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x1af);\r
3321                 if(tmp1b != 0x0)\r
3322                 {\r
3323                         pCoexSta->c2hHangDetectCnt++;\r
3324                         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x1af, 0x0);\r
3325                 }\r
3326         }\r
3327 }\r
3328 \r
3329 //============================================================\r
3330 // extern function start with EXhalbtc8723a2ant_\r
3331 //============================================================\r
3332 VOID\r
3333 EXhalbtc8723a2ant_PowerOnSetting(\r
3334         IN      PBTC_COEXIST            pBtCoexist\r
3335         )\r
3336 {\r
3337 }\r
3338 \r
3339 VOID\r
3340 EXhalbtc8723a2ant_InitHwConfig(\r
3341         IN      PBTC_COEXIST            pBtCoexist,\r
3342         IN      BOOLEAN                         bWifiOnly\r
3343         )\r
3344 {\r
3345         u4Byte  u4Tmp=0;\r
3346         u1Byte  u1Tmp=0;\r
3347 \r
3348         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], 2Ant Init HW Config!!\n"));\r
3349 \r
3350         // backup rf 0x1e value\r
3351         pCoexDm->btRf0x1eBackup = \r
3352                 pBtCoexist->fBtcGetRfReg(pBtCoexist, BTC_RF_A, 0x1e, 0xfffff);\r
3353 \r
3354         // Enable counter statistics\r
3355         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x76e, 0x4);\r
3356         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x778, 0x3);\r
3357         pBtCoexist->fBtcWrite1Byte(pBtCoexist, 0x40, 0x20);\r
3358 }\r
3359 \r
3360 VOID\r
3361 EXhalbtc8723a2ant_InitCoexDm(\r
3362         IN      PBTC_COEXIST            pBtCoexist\r
3363         )\r
3364 {\r
3365         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Coex Mechanism Init!!\n"));\r
3366         \r
3367         halbtc8723a2ant_InitCoexDm(pBtCoexist);\r
3368 }\r
3369 \r
3370 VOID\r
3371 EXhalbtc8723a2ant_DisplayCoexInfo(\r
3372         IN      PBTC_COEXIST            pBtCoexist\r
3373         )\r
3374 {\r
3375         PBTC_BOARD_INFO         pBoardInfo=&pBtCoexist->boardInfo;\r
3376         PBTC_STACK_INFO         pStackInfo=&pBtCoexist->stackInfo;\r
3377         pu1Byte                         cliBuf=pBtCoexist->cliBuf;\r
3378         u1Byte                          u1Tmp[4], i, btInfoExt, psTdmaCase=0;\r
3379         u4Byte                          u4Tmp[4];\r
3380 \r
3381         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n ============[BT Coexist info]============");\r
3382         CL_PRINTF(cliBuf);\r
3383 \r
3384         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ", "Ant PG number/ Ant mechanism:", \\r
3385                 pBoardInfo->pgAntNum, pBoardInfo->btdmAntNum);\r
3386         CL_PRINTF(cliBuf);      \r
3387         \r
3388         if(pBtCoexist->bManualControl)\r
3389         {\r
3390                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "[Action Manual control]!!");\r
3391                 CL_PRINTF(cliBuf);\r
3392         }\r
3393         \r
3394         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s / %d", "BT stack/ hci ext ver", \\r
3395                 ((pStackInfo->bProfileNotified)? "Yes":"No"), pStackInfo->hciVersion);\r
3396         CL_PRINTF(cliBuf);\r
3397 \r
3398         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x ", "Wifi channel informed to BT", \\r
3399                 pCoexDm->wifiChnlInfo[0], pCoexDm->wifiChnlInfo[1],\r
3400                 pCoexDm->wifiChnlInfo[2]);\r
3401         CL_PRINTF(cliBuf);\r
3402         \r
3403         // wifi status\r
3404         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Wifi Status]============");\r
3405         CL_PRINTF(cliBuf);\r
3406         pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_WIFI_STATUS);\r
3407 \r
3408         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[BT Status]============");\r
3409         CL_PRINTF(cliBuf);\r
3410 \r
3411         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = [%s/ %d/ %d] ", "BT [status/ rssi/ retryCnt]", \\r
3412                 ((pCoexSta->bC2hBtInquiryPage)?("inquiry/page scan"):((BT_8723A_2ANT_BT_STATUS_IDLE == pCoexDm->btStatus)? "idle":(  (BT_8723A_2ANT_BT_STATUS_CONNECTED_IDLE == pCoexDm->btStatus)? "connected-idle":"busy"))),\r
3413                 pCoexSta->btRssi, pCoexSta->btRetryCnt);\r
3414         CL_PRINTF(cliBuf);\r
3415         \r
3416         if(pStackInfo->bProfileNotified)\r
3417         {                       \r
3418                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d / %d / %d / %d", "SCO/HID/PAN/A2DP", \\r
3419                         pStackInfo->bScoExist, pStackInfo->bHidExist, pStackInfo->bPanExist, pStackInfo->bA2dpExist);\r
3420                 CL_PRINTF(cliBuf);      \r
3421 \r
3422                 pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_BT_LINK_INFO);\r
3423         }\r
3424 \r
3425         btInfoExt = pCoexSta->btInfoExt;\r
3426         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %s", "BT Info A2DP rate", \\r
3427                 (btInfoExt&BIT0)? "Basic rate":"EDR rate");\r
3428         CL_PRINTF(cliBuf);      \r
3429 \r
3430         for(i=0; i<BT_INFO_SRC_8723A_2ANT_MAX; i++)\r
3431         {\r
3432                 if(pCoexSta->btInfoC2hCnt[i])\r
3433                 {                               \r
3434                         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x %02x %02x(%d)", GLBtInfoSrc8723a2Ant[i], \\r
3435                                 pCoexSta->btInfoC2h[i][0], pCoexSta->btInfoC2h[i][1],\r
3436                                 pCoexSta->btInfoC2h[i][2], pCoexSta->btInfoC2h[i][3],\r
3437                                 pCoexSta->btInfoC2h[i][4], pCoexSta->btInfoC2h[i][5],\r
3438                                 pCoexSta->btInfoC2h[i][6], pCoexSta->btInfoC2hCnt[i]);\r
3439                         CL_PRINTF(cliBuf);\r
3440                 }\r
3441         }\r
3442 \r
3443         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d", "write 0x1af=0x0 num", \\r
3444                 pCoexSta->c2hHangDetectCnt);\r
3445         CL_PRINTF(cliBuf);\r
3446         \r
3447         // Sw mechanism \r
3448         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Sw mechanism]============");\r
3449         CL_PRINTF(cliBuf);\r
3450         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d", "SM1[ShRf/ LpRA/ LimDig]", \\r
3451                 pCoexDm->bCurRfRxLpfShrink, pCoexDm->bCurLowPenaltyRa, pCoexDm->bLimitedDig);\r
3452         CL_PRINTF(cliBuf);\r
3453         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d/ %d(0x%x) ", "SM2[AgcT/ AdcB/ SwDacSwing(lvl)]", \\r
3454                 pCoexDm->bCurAgcTableEn, pCoexDm->bCurAdcBackOff, pCoexDm->bCurDacSwingOn, pCoexDm->curDacSwingLvl);\r
3455         CL_PRINTF(cliBuf);\r
3456 \r
3457         // Fw mechanism         \r
3458         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Fw mechanism]============");\r
3459         CL_PRINTF(cliBuf);      \r
3460         \r
3461         if(!pBtCoexist->bManualControl)\r
3462         {\r
3463                 psTdmaCase = pCoexDm->curPsTdma;\r
3464                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %02x %02x %02x %02x %02x case-%d", "PS TDMA", \\r
3465                         pCoexDm->psTdmaPara[0], pCoexDm->psTdmaPara[1],\r
3466                         pCoexDm->psTdmaPara[2], pCoexDm->psTdmaPara[3],\r
3467                         pCoexDm->psTdmaPara[4], psTdmaCase);\r
3468                 CL_PRINTF(cliBuf);\r
3469         \r
3470                 CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d ", "DecBtPwr/ IgnWlanAct", \\r
3471                         pCoexDm->bCurDecBtPwr, pCoexDm->bCurIgnoreWlanAct);\r
3472                 CL_PRINTF(cliBuf);\r
3473         }\r
3474 \r
3475         // Hw setting           \r
3476         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s", "============[Hw setting]============");\r
3477         CL_PRINTF(cliBuf);      \r
3478 \r
3479         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "RF-A, 0x1e initVal", \\r
3480                 pCoexDm->btRf0x1eBackup);\r
3481         CL_PRINTF(cliBuf);\r
3482 \r
3483         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x778);\r
3484         u1Tmp[1] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x783);\r
3485         u1Tmp[2] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x796);\r
3486         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x", "0x778/ 0x783/ 0x796", \\r
3487                 u1Tmp[0], u1Tmp[1], u1Tmp[2]);\r
3488         CL_PRINTF(cliBuf);\r
3489 \r
3490         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x880);\r
3491         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x880", \\r
3492                 u4Tmp[0]);\r
3493         CL_PRINTF(cliBuf);\r
3494 \r
3495         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x40);\r
3496         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x40", \\r
3497                 u1Tmp[0]);\r
3498         CL_PRINTF(cliBuf);\r
3499 \r
3500         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x550);\r
3501         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x522);\r
3502         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x", "0x550(bcn ctrl)/0x522", \\r
3503                 u4Tmp[0], u1Tmp[0]);\r
3504         CL_PRINTF(cliBuf);\r
3505 \r
3506         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x484);\r
3507         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0x484(rate adaptive)", \\r
3508                 u4Tmp[0]);\r
3509         CL_PRINTF(cliBuf);\r
3510 \r
3511         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xc50);\r
3512         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x", "0xc50(dig)", \\r
3513                 u4Tmp[0]);\r
3514         CL_PRINTF(cliBuf);\r
3515 \r
3516         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda0);\r
3517         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda4);\r
3518         u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xda8);\r
3519         u4Tmp[3] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0xdac);\r
3520         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0xda0/0xda4/0xda8/0xdac(FA cnt)", \\r
3521                 u4Tmp[0], u4Tmp[1], u4Tmp[2], u4Tmp[3]);\r
3522         CL_PRINTF(cliBuf);\r
3523 \r
3524         u4Tmp[0] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c0);\r
3525         u4Tmp[1] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c4);\r
3526         u4Tmp[2] = pBtCoexist->fBtcRead4Byte(pBtCoexist, 0x6c8);\r
3527         u1Tmp[0] = pBtCoexist->fBtcRead1Byte(pBtCoexist, 0x6cc);\r
3528         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)", \\r
3529                 u4Tmp[0], u4Tmp[1], u4Tmp[2], u1Tmp[0]);\r
3530         CL_PRINTF(cliBuf);\r
3531 \r
3532         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x770 (hp rx[31:16]/tx[15:0])", \\r
3533                 pCoexSta->highPriorityRx, pCoexSta->highPriorityTx);\r
3534         CL_PRINTF(cliBuf);\r
3535         CL_SPRINTF(cliBuf, BT_TMP_BUF_SIZE, "\r\n %-35s = %d/ %d", "0x774(lp rx[31:16]/tx[15:0])", \\r
3536                 pCoexSta->lowPriorityRx, pCoexSta->lowPriorityTx);\r
3537         CL_PRINTF(cliBuf);\r
3538 \r
3539         pBtCoexist->fBtcDispDbgMsg(pBtCoexist, BTC_DBG_DISP_COEX_STATISTICS);\r
3540 }\r
3541 \r
3542 \r
3543 VOID\r
3544 EXhalbtc8723a2ant_IpsNotify(\r
3545         IN      PBTC_COEXIST            pBtCoexist,\r
3546         IN      u1Byte                  type\r
3547         )\r
3548 {\r
3549         if(BTC_IPS_ENTER == type)\r
3550         {\r
3551                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], IPS ENTER notify\n"));\r
3552                 halbtc8723a2ant_CoexAllOff(pBtCoexist);\r
3553         }\r
3554         else if(BTC_IPS_LEAVE == type)\r
3555         {\r
3556                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], IPS LEAVE notify\n"));\r
3557                 //halbtc8723a2ant_InitCoexDm(pBtCoexist);\r
3558         }\r
3559 }\r
3560 \r
3561 VOID\r
3562 EXhalbtc8723a2ant_LpsNotify(\r
3563         IN      PBTC_COEXIST            pBtCoexist,\r
3564         IN      u1Byte                  type\r
3565         )\r
3566 {\r
3567         if(BTC_LPS_ENABLE == type)\r
3568         {\r
3569                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], LPS ENABLE notify\n"));\r
3570         }\r
3571         else if(BTC_LPS_DISABLE == type)\r
3572         {\r
3573                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], LPS DISABLE notify\n"));\r
3574         }\r
3575 }\r
3576 \r
3577 VOID\r
3578 EXhalbtc8723a2ant_ScanNotify(\r
3579         IN      PBTC_COEXIST            pBtCoexist,\r
3580         IN      u1Byte                  type\r
3581         )\r
3582 {\r
3583         if(BTC_SCAN_START == type)\r
3584         {\r
3585                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN START notify\n"));\r
3586         }\r
3587         else if(BTC_SCAN_FINISH == type)\r
3588         {\r
3589                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], SCAN FINISH notify\n"));\r
3590         }\r
3591 }\r
3592 \r
3593 VOID\r
3594 EXhalbtc8723a2ant_ConnectNotify(\r
3595         IN      PBTC_COEXIST            pBtCoexist,\r
3596         IN      u1Byte                  type\r
3597         )\r
3598 {\r
3599         if(BTC_ASSOCIATE_START == type)\r
3600         {\r
3601                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT START notify\n"));\r
3602         }\r
3603         else if(BTC_ASSOCIATE_FINISH == type)\r
3604         {\r
3605                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], CONNECT FINISH notify\n"));\r
3606         }\r
3607 }\r
3608 \r
3609 VOID\r
3610 EXhalbtc8723a2ant_MediaStatusNotify(\r
3611         IN      PBTC_COEXIST                    pBtCoexist,\r
3612         IN      u1Byte                          type\r
3613         )\r
3614 {\r
3615         if(BTC_MEDIA_CONNECT == type)\r
3616         {\r
3617                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], MEDIA connect notify\n"));\r
3618         }\r
3619         else\r
3620         {\r
3621                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], MEDIA disconnect notify\n"));\r
3622         }\r
3623 \r
3624         halbtc8723a2ant_IndicateWifiChnlBwInfo(pBtCoexist, type);\r
3625 }\r
3626 \r
3627 VOID\r
3628 EXhalbtc8723a2ant_SpecialPacketNotify(\r
3629         IN      PBTC_COEXIST                    pBtCoexist,\r
3630         IN      u1Byte                          type\r
3631         )\r
3632 {\r
3633         if(type == BTC_PACKET_DHCP)\r
3634         {\r
3635                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], DHCP Packet notify\n"));\r
3636         }\r
3637 }\r
3638 \r
3639 VOID\r
3640 EXhalbtc8723a2ant_BtInfoNotify(\r
3641         IN      PBTC_COEXIST            pBtCoexist,\r
3642         IN      pu1Byte                 tmpBuf,\r
3643         IN      u1Byte                  length\r
3644         )\r
3645 {\r
3646         u1Byte                  btInfo=0;\r
3647         u1Byte                  i, rspSource=0;\r
3648         BOOLEAN                 bBtBusy=FALSE, bLimitedDig=FALSE;\r
3649         BOOLEAN                 bWifiConnected=FALSE, bBtHsOn=FALSE;\r
3650 \r
3651         pCoexSta->bC2hBtInfoReqSent = FALSE;\r
3652         \r
3653         rspSource = BT_INFO_SRC_8723A_2ANT_BT_RSP;\r
3654         pCoexSta->btInfoC2hCnt[rspSource]++;\r
3655 \r
3656         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Bt info[%d], length=%d, hex data=[", rspSource, length));\r
3657         for(i=0; i<length; i++)\r
3658         {\r
3659                 pCoexSta->btInfoC2h[rspSource][i] = tmpBuf[i];\r
3660                 if(i == 0)\r
3661                         btInfo = tmpBuf[i];\r
3662                 if(i == length-1)\r
3663                 {\r
3664                         RT_TRACE(COMP_COEX, DBG_LOUD, ("0x%02x]\n", tmpBuf[i]));\r
3665                 }\r
3666                 else\r
3667                 {\r
3668                         RT_TRACE(COMP_COEX, DBG_LOUD, ("0x%02x, ", tmpBuf[i]));\r
3669                 }\r
3670         }\r
3671 \r
3672         if(BT_INFO_SRC_8723A_2ANT_WIFI_FW != rspSource)\r
3673         {\r
3674                 pCoexSta->btRetryCnt =\r
3675                         pCoexSta->btInfoC2h[rspSource][1];\r
3676 \r
3677                 pCoexSta->btRssi =\r
3678                         pCoexSta->btInfoC2h[rspSource][2]*2+10;\r
3679 \r
3680                 pCoexSta->btInfoExt = \r
3681                         pCoexSta->btInfoC2h[rspSource][3];\r
3682         }\r
3683                 \r
3684         pBtCoexist->fBtcGet(pBtCoexist, BTC_GET_BL_HS_OPERATION, &bBtHsOn);\r
3685         // check BIT2 first ==> check if bt is under inquiry or page scan\r
3686         if(btInfo & BT_INFO_8723A_2ANT_B_INQ_PAGE)\r
3687         {\r
3688                 pCoexSta->bC2hBtInquiryPage = TRUE;\r
3689         }\r
3690         else\r
3691         {\r
3692                 pCoexSta->bC2hBtInquiryPage = FALSE;\r
3693         }\r
3694 }\r
3695 \r
3696 VOID\r
3697 EXhalbtc8723a2ant_StackOperationNotify(\r
3698         IN      PBTC_COEXIST                    pBtCoexist,\r
3699         IN      u1Byte                          type\r
3700         )\r
3701 {\r
3702         if(BTC_STACK_OP_INQ_PAGE_PAIR_START == type)\r
3703         {\r
3704                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], StackOP Inquiry/page/pair start notify\n"));\r
3705                 pCoexSta->bHoldForStackOperation = TRUE;\r
3706                 pCoexSta->bHoldPeriodCnt = 1;\r
3707                 halbtc8723a2ant_BtInquiryPage(pBtCoexist);\r
3708         }\r
3709         else if(BTC_STACK_OP_INQ_PAGE_PAIR_FINISH == type)\r
3710         {\r
3711                 RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], StackOP Inquiry/page/pair finish notify\n"));\r
3712                 pCoexSta->bHoldForStackOperation = FALSE;\r
3713         }\r
3714 }\r
3715 \r
3716 VOID\r
3717 EXhalbtc8723a2ant_HaltNotify(\r
3718         IN      PBTC_COEXIST                    pBtCoexist\r
3719         )\r
3720 {\r
3721         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], Halt notify\n"));\r
3722 \r
3723         halbtc8723a2ant_IgnoreWlanAct(pBtCoexist, FORCE_EXEC, TRUE);\r
3724         EXhalbtc8723a2ant_MediaStatusNotify(pBtCoexist, BTC_MEDIA_DISCONNECT);\r
3725 }\r
3726 \r
3727 VOID\r
3728 EXhalbtc8723a2ant_Periodical(\r
3729         IN      PBTC_COEXIST                    pBtCoexist\r
3730         )\r
3731 {\r
3732         RT_TRACE(COMP_COEX, DBG_LOUD, ("[BTCoex], 2Ant Periodical!!\n"));\r
3733 \r
3734         // work around for c2h hang\r
3735         wa_halbtc8723a2ant_MonitorC2h(pBtCoexist);\r
3736         \r
3737         halbtc8723a2ant_QueryBtInfo(pBtCoexist);\r
3738         halbtc8723a2ant_MonitorBtCtr(pBtCoexist);\r
3739         halbtc8723a2ant_MonitorBtEnableDisable(pBtCoexist);\r
3740 \r
3741         halbtc8723a2ant_RunCoexistMechanism(pBtCoexist);\r
3742 }\r
3743 \r
3744 \r
3745 #endif\r
3746 \r