Staging: rtl8812ae: remove undefined Kconfig macros
[firefly-linux-kernel-4.4.55.git] / drivers / staging / rtl8821ae / btcoexist / halbtcoutsrc.c
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2013 Realtek Corporation. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  * You should have received a copy of the GNU General Public License along with
15  * this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
17  *
18  *
19  ******************************************************************************/
20
21 #include "halbt_precomp.h"
22
23 /*#if(BT_30_SUPPORT == 1)*/
24 #if 1
25 /***********************************************
26  *              Global variables
27  ***********************************************/
28 const char *const bt_profile_string[]={
29         "NONE",
30         "A2DP",
31         "PAN",
32         "HID",
33         "SCO",
34 };
35
36 const char *const bt_spec_string[]={
37         "1.0b",
38         "1.1",
39         "1.2",
40         "2.0+EDR",
41         "2.1+EDR",
42         "3.0+HS",
43         "4.0",
44 };
45
46 const char *const bt_link_role_string[]={
47         "Master",
48         "Slave",
49 };
50
51 const char *const h2c_state_string[]={
52         "successful",
53         "h2c busy",
54         "rf off",
55         "fw not read",
56 };
57
58 const char *const io_state_string[]={
59         "IO_STATUS_SUCCESS",
60         "IO_STATUS_FAIL_CANNOT_IO",
61         "IO_STATUS_FAIL_RF_OFF",
62         "IO_STATUS_FAIL_FW_READ_CLEAR_TIMEOUT",
63         "IO_STATUS_FAIL_WAIT_IO_EVENT_TIMEOUT",
64         "IO_STATUS_INVALID_LEN",
65         "IO_STATUS_IO_IDLE_QUEUE_EMPTY",
66         "IO_STATUS_IO_INSERT_WAIT_QUEUE_FAIL",
67         "IO_STATUS_UNKNOWN_FAIL",
68         "IO_STATUS_WRONG_LEVEL",
69         "IO_STATUS_H2C_STOPPED",
70 };
71
72 struct btc_coexist gl_bt_coexist;
73
74 u32 btc_dbg_type[BTC_MSG_MAX];
75 u8 btc_dbg_buf[100];
76
77 /***************************************************
78  *              Debug related function
79  ***************************************************/
80 bool halbtc_is_bt_coexist_available(struct btc_coexist *btcoexist)
81 {
82         if (!btcoexist->binded || NULL == btcoexist->adapter)
83                 return false;
84         
85         return true;
86 }
87
88 bool halbtc_is_wifi_busy(struct rtl_priv *rtlpriv)
89 {
90
91         if (rtlpriv->link_info.b_busytraffic)
92                 return true;
93         else
94                 return false;
95 }
96
97
98 void halbtc_dbg_init(void)
99 {
100         u8 i;
101
102         for (i = 0; i < BTC_MSG_MAX; i++)
103                 btc_dbg_type[i] = 0;
104
105         btc_dbg_type[BTC_MSG_INTERFACE]                 =       \
106 //                      INTF_INIT                               |
107 //                      INTF_NOTIFY                             |
108                         0;
109         
110         btc_dbg_type[BTC_MSG_ALGORITHM]                 =       \
111 //                      ALGO_BT_RSSI_STATE                      |
112 //                      ALGO_WIFI_RSSI_STATE                    |
113 //                      ALGO_BT_MONITOR                         |
114 //                      ALGO_TRACE                              |
115 //                      ALGO_TRACE_FW                           |
116 //                      ALGO_TRACE_FW_DETAIL                    |
117 //                      ALGO_TRACE_FW_EXEC                      |
118 //                      ALGO_TRACE_SW                           |
119 //                      ALGO_TRACE_SW_DETAIL                    |
120 //                      ALGO_TRACE_SW_EXEC                      |
121                         0;
122 }
123
124 bool halbtc_is_hw_mailbox_exist(struct btc_coexist *btcoexist)
125 {
126         return true;
127 }
128
129 bool halbtc_is_bt40(struct rtl_priv *adapter)
130 {
131         struct rtl_priv *rtlpriv = adapter;
132         struct rtl_phy *rtlphy = &(rtlpriv->phy);
133         bool is_ht40 = true;
134         enum ht_channel_width bw = rtlphy->current_chan_bw;
135         
136         
137         if (bw == HT_CHANNEL_WIDTH_20)
138                 is_ht40 = false;
139         else if (bw == HT_CHANNEL_WIDTH_20_40)
140                 is_ht40 = true;
141
142         return is_ht40;
143 }
144
145 bool halbtc_legacy(struct rtl_priv *adapter)
146 {
147         struct rtl_priv *rtlpriv = adapter;
148         struct rtl_mac *mac = rtl_mac(rtlpriv);
149         
150         bool is_legacy = false;
151
152         if ((mac->mode == WIRELESS_MODE_B) || (mac->mode == WIRELESS_MODE_B))
153                 is_legacy = true;
154
155         return is_legacy;
156 }
157
158 bool halbtc_is_wifi_uplink(struct rtl_priv *adapter)
159 {
160         struct rtl_priv *rtlpriv = adapter;
161         
162         if (rtlpriv->link_info.b_tx_busy_traffic)
163                 return true;
164         else
165                 return false;
166 }
167
168 u32 halbtc_get_wifi_bw(struct btc_coexist *btcoexist)
169 {
170         struct rtl_priv *rtlpriv = 
171                 (struct rtl_priv *)btcoexist->adapter;
172         u32 wifi_bw = BTC_WIFI_BW_HT20;
173         
174         if (halbtc_is_bt40(rtlpriv)){
175                 wifi_bw = BTC_WIFI_BW_HT40;     
176         } else {
177                 if(halbtc_legacy(rtlpriv))
178                         wifi_bw = BTC_WIFI_BW_LEGACY;
179                 else
180                         wifi_bw = BTC_WIFI_BW_HT20;
181         }
182         return wifi_bw;
183 }
184
185 u8 halbtc_get_wifi_central_chnl(struct btc_coexist *btcoexist)
186 {
187         struct rtl_priv *rtlpriv = btcoexist->adapter;
188         struct rtl_phy  *rtlphy = &(rtlpriv->phy);
189         u8 chnl = 1;
190         
191
192         if (rtlphy->current_channel != 0)
193                 chnl = rtlphy->current_channel;
194         BTC_PRINT(BTC_MSG_ALGORITHM, ALGO_TRACE, 
195                   "halbtc_get_wifi_central_chnl:%d\n",chnl);
196         return chnl;
197 }
198
199 void halbtc_leave_lps(struct btc_coexist *btcoexist)
200 {
201         struct rtl_priv *rtlpriv;
202         struct rtl_ps_ctl *ppsc;
203         bool ap_enable = false;
204         
205         rtlpriv = btcoexist->adapter;
206         ppsc = rtl_psc(rtlpriv);
207         
208         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE,
209                            &ap_enable);
210         
211         if (ap_enable) {
212                 printk("halbtc_leave_lps()<--dont leave lps under AP mode\n");
213                 return;
214         }
215
216         btcoexist->bt_info.bt_ctrl_lps = true;
217         btcoexist->bt_info.bt_lps_on = false;
218 }
219
220 void halbtc_enter_lps(struct btc_coexist *btcoexist)
221 {
222         struct rtl_priv *rtlpriv;
223         struct rtl_ps_ctl *ppsc;
224         bool ap_enable = false;
225         
226         rtlpriv = btcoexist->adapter;
227         ppsc = rtl_psc(rtlpriv);
228         
229         btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_AP_MODE_ENABLE, 
230                            &ap_enable);
231         
232         if (ap_enable) {
233                 printk("halbtc_enter_lps()<--dont enter lps under AP mode\n");
234                 return;
235         }
236         
237         btcoexist->bt_info.bt_ctrl_lps = true;
238         btcoexist->bt_info.bt_lps_on = false;
239 }
240
241 void halbtc_normal_lps(struct btc_coexist *btcoexist)
242 {
243         if (btcoexist->bt_info.bt_ctrl_lps) {
244                 btcoexist->bt_info.bt_lps_on = false;
245                 btcoexist->bt_info.bt_ctrl_lps = false;
246         }
247                 
248 }
249
250 void halbtc_leave_low_power(void)
251 {
252 }
253
254 void halbtc_nomal_low_power(void)
255 {
256 }
257
258 void halbtc_disable_low_power(void)
259 {
260 }
261
262 void halbtc_aggregation_check(void)
263 {
264 }
265
266
267 u32 halbtc_get_bt_patch_version(struct btc_coexist *btcoexist)
268 {
269         return 0;
270 }
271
272 s32 halbtc_get_wifi_rssi(struct rtl_priv *adapter)
273 {
274         struct rtl_priv *rtlpriv = adapter;
275         s32     undecorated_smoothed_pwdb = 0;
276         
277         if (rtlpriv->mac80211.link_state >= MAC80211_LINKED)
278                 undecorated_smoothed_pwdb = 
279                         rtlpriv->dm.undecorated_smoothed_pwdb;
280         else /* associated entry pwdb */
281                 undecorated_smoothed_pwdb =
282                         rtlpriv->dm.undecorated_smoothed_pwdb;
283         return undecorated_smoothed_pwdb;
284 }
285
286 bool halbtc_get(void *void_btcoexist, u8 get_type, void *out_buf)
287 {
288         struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist;
289         struct rtl_priv *rtlpriv = btcoexist->adapter;
290         struct rtl_phy *rtlphy = &(rtlpriv->phy);
291         struct rtl_mac *mac = rtl_mac(rtlpriv);
292         struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
293         bool *bool_tmp = (bool*)out_buf;
294         int *s32_tmp = (int*)out_buf;
295         u32 *u32_tmp = (u32*)out_buf;
296         u8 *u8_tmp = (u8*)out_buf;
297         bool tmp = false;
298
299
300         if (!halbtc_is_bt_coexist_available(btcoexist))
301                 return false;
302         
303
304         switch (get_type){
305         case BTC_GET_BL_HS_OPERATION:
306                 *bool_tmp = false;
307                 break;
308         case BTC_GET_BL_HS_CONNECTING:
309                 *bool_tmp = false;
310                 break;
311         case BTC_GET_BL_WIFI_CONNECTED:
312                 if (rtlpriv->mac80211.link_state >= MAC80211_LINKED)
313                         tmp = true;
314                                 
315                 *bool_tmp = tmp;
316                 break;
317         case BTC_GET_BL_WIFI_BUSY:
318                 if(halbtc_is_wifi_busy(rtlpriv))
319                         *bool_tmp = true;
320                 else
321                         *bool_tmp = false;
322                 break;
323         case BTC_GET_BL_WIFI_SCAN:
324                 if (mac->act_scanning == true)
325                         *bool_tmp = true;
326                 else
327                         *bool_tmp = false;
328                 break;
329         case BTC_GET_BL_WIFI_LINK:
330                 if (mac->link_state == MAC80211_LINKING)
331                         *bool_tmp = true;
332                 else
333                         *bool_tmp = false;
334                 break;
335         case BTC_GET_BL_WIFI_ROAM:      /*TODO*/
336                 if (mac->link_state == MAC80211_LINKING)
337                         *bool_tmp = true;
338                 else
339                         *bool_tmp = false;
340                 break;
341         case BTC_GET_BL_WIFI_4_WAY_PROGRESS:    /*TODO*/
342                         *bool_tmp = false;
343
344                 break;
345         case BTC_GET_BL_WIFI_UNDER_5G:
346                 *bool_tmp = false; /*TODO*/
347                 
348         case BTC_GET_BL_WIFI_DHCP:      /*TODO*/
349                 break;
350         case BTC_GET_BL_WIFI_SOFTAP_IDLE:
351                 *bool_tmp = true;
352                 break;
353         case BTC_GET_BL_WIFI_SOFTAP_LINKING:
354                 *bool_tmp = false;
355                 break;
356         case BTC_GET_BL_WIFI_IN_EARLY_SUSPEND:
357                 *bool_tmp = false;
358                 break;
359         case BTC_GET_BL_WIFI_AP_MODE_ENABLE:
360                 *bool_tmp = false;
361                 break;
362         case BTC_GET_BL_WIFI_ENABLE_ENCRYPTION:
363                 if (NO_ENCRYPTION == rtlpriv->sec.pairwise_enc_algorithm)
364                         *bool_tmp = false;
365                 else
366                         *bool_tmp = true;
367                 break;
368         case BTC_GET_BL_WIFI_UNDER_B_MODE:
369                 *bool_tmp = false; /*TODO*/
370                 break;
371         case BTC_GET_BL_EXT_SWITCH:
372                 *bool_tmp = false;
373                 break;
374         case BTC_GET_S4_WIFI_RSSI:
375                 *s32_tmp = halbtc_get_wifi_rssi(rtlpriv);
376                 break;
377         case BTC_GET_S4_HS_RSSI:        /*TODO*/
378                 *s32_tmp = halbtc_get_wifi_rssi(rtlpriv);
379                 break;
380         case BTC_GET_U4_WIFI_BW:
381                 *u32_tmp = halbtc_get_wifi_bw(btcoexist);
382                 break;
383         case BTC_GET_U4_WIFI_TRAFFIC_DIRECTION:
384                 if (halbtc_is_wifi_uplink(rtlpriv))
385                         *u32_tmp = BTC_WIFI_TRAFFIC_TX;
386                 else
387                         *u32_tmp = BTC_WIFI_TRAFFIC_RX;
388                 break;
389         case BTC_GET_U4_WIFI_FW_VER:
390                 *u32_tmp = rtlhal->fw_version;
391                 break;
392         case BTC_GET_U4_BT_PATCH_VER:
393                 *u32_tmp = halbtc_get_bt_patch_version(btcoexist);
394                 break;
395         case BTC_GET_U1_WIFI_DOT11_CHNL:
396                 *u8_tmp = rtlphy->current_channel;
397                 break;
398         case BTC_GET_U1_WIFI_CENTRAL_CHNL:
399                 *u8_tmp = halbtc_get_wifi_central_chnl(btcoexist);
400                 break;
401         case BTC_GET_U1_WIFI_HS_CHNL:
402                 *u8_tmp = 1;/* BT_OperateChnl(rtlpriv); */
403                 break;
404         case BTC_GET_U1_MAC_PHY_MODE:
405                 *u8_tmp = BTC_MP_UNKNOWN;
406                 break;
407         case BTC_GET_U1_AP_NUM:
408                 /* driver don't know AP num in Linux, 
409                  * So, the return value here is not right */
410                 *u8_tmp = 1;/* pDefMgntInfo->NumBssDesc4Query; */
411                 break;
412
413         /************* 1Ant **************/
414         case BTC_GET_U1_LPS_MODE:
415                 *u8_tmp = btcoexist->pwr_mode_val[0];
416                 break;
417                                         
418         default:
419                 break;
420         }
421         
422         return true;
423 }
424
425 bool halbtc_set(void *void_btcoexist, u8 set_type, void *in_buf)
426 {
427         struct btc_coexist *btcoexist = (struct btc_coexist *)void_btcoexist;
428         bool *bool_tmp = (bool *)in_buf;
429         u8 *u8_tmp = (u8 *)in_buf;
430         u32 *u32_tmp = (u32 *)in_buf;
431         
432         
433         if (!halbtc_is_bt_coexist_available(btcoexist))
434                 return false;
435
436         switch (set_type) {
437         /* set some bool type variables. */
438         case BTC_SET_BL_BT_DISABLE:
439                 btcoexist->bt_info.bt_disabled = *bool_tmp;
440                 break;
441         case BTC_SET_BL_BT_TRAFFIC_BUSY:
442                 btcoexist->bt_info.bt_busy = *bool_tmp;
443                 break;
444         case BTC_SET_BL_BT_LIMITED_DIG:
445                 btcoexist->bt_info.limited_dig = *bool_tmp;
446                 break;
447         case BTC_SET_BL_FORCE_TO_ROAM:
448                 btcoexist->bt_info.force_to_roam = *bool_tmp;
449                 break;
450         case BTC_SET_BL_TO_REJ_AP_AGG_PKT:
451                 btcoexist->bt_info.reject_agg_pkt = *bool_tmp;
452                 break;
453         case BTC_SET_BL_BT_CTRL_AGG_SIZE:
454                 btcoexist->bt_info.b_bt_ctrl_buf_size = *bool_tmp;
455                 break;
456         case BTC_SET_BL_INC_SCAN_DEV_NUM:
457                 btcoexist->bt_info.increase_scan_dev_num = *bool_tmp;
458                 break;
459                 /* set some u1Byte type variables. */
460         case BTC_SET_U1_RSSI_ADJ_VAL_FOR_AGC_TABLE_ON:
461                 btcoexist->bt_info.rssi_adjust_for_agc_table_on = *u8_tmp;
462                 break;
463         case BTC_SET_U1_AGG_BUF_SIZE:
464                 btcoexist->bt_info.agg_buf_size = *u8_tmp;
465                 break;
466                 /* the following are some action which will be triggered */
467         case BTC_SET_ACT_GET_BT_RSSI:
468                 /*BTHCI_SendGetBtRssiEvent(rtlpriv);*/
469                 break;
470         case BTC_SET_ACT_AGGREGATE_CTRL:
471                 halbtc_aggregation_check();
472                 break;
473
474                 /* 1Ant */
475         case BTC_SET_U1_RSSI_ADJ_VAL_FOR_1ANT_COEX_TYPE:
476                 btcoexist->bt_info.rssi_adjust_for_1ant_coex_type = *u8_tmp;
477                 break;
478         case BTC_SET_UI_SCAN_SIG_COMPENSATION:
479         /*      rtlpriv->mlmepriv.scan_compensation = *u8_tmp;  */
480                 break;
481         case BTC_SET_U1_1ANT_LPS:
482                 btcoexist->bt_info.lps_1ant = *u8_tmp;
483                 break;
484         case BTC_SET_U1_1ANT_RPWM:
485                 btcoexist->bt_info.rpwm_1ant = *u8_tmp;
486                 break;
487         /* the following are some action which will be triggered  */
488         case BTC_SET_ACT_LEAVE_LPS:
489                 halbtc_leave_lps(btcoexist);
490                 break;
491         case BTC_SET_ACT_ENTER_LPS:
492                 halbtc_enter_lps(btcoexist);
493                 break;
494         case BTC_SET_ACT_NORMAL_LPS:
495                 halbtc_normal_lps(btcoexist);
496                 break;
497         case BTC_SET_ACT_DISABLE_LOW_POWER:
498                 halbtc_disable_low_power();
499                 break;
500         case BTC_SET_ACT_UPDATE_ra_mask:
501                 btcoexist->bt_info.ra_mask = *u32_tmp;
502                 break;
503         case BTC_SET_ACT_SEND_MIMO_PS:
504                 break;
505         case BTC_SET_ACT_INC_FORCE_EXEC_PWR_CMD_CNT:
506                 btcoexist->bt_info.force_exec_pwr_cmd_cnt++;
507                 break;
508         case BTC_SET_ACT_CTRL_BT_INFO: /*wait for 8812/8821*/
509                 break;
510         case BTC_SET_ACT_CTRL_BT_COEX:
511                 break;
512         default:
513                 break;
514         }
515         
516         return true;
517 }
518
519 void halbtc_display_coex_statistics(struct btc_coexist *btcoexist)
520 {
521 }
522
523 void halbtc_display_bt_link_info(struct btc_coexist *btcoexist)
524 {
525 }
526
527 void halbtc_display_bt_fw_info(struct btc_coexist *btcoexist)
528 {
529 }
530
531 void halbtc_display_fw_pwr_mode_cmd(struct btc_coexist *btcoexist)
532 {
533 }
534
535 /************************************************************
536  *              IO related function
537  ************************************************************/
538 u8 halbtc_read_1byte(void *bt_context, u32 reg_addr)
539 {
540         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
541         struct rtl_priv *rtlpriv = btcoexist->adapter;
542         
543         return  rtl_read_byte(rtlpriv, reg_addr);
544 }
545
546
547 u16 halbtc_read_2byte(void *bt_context, u32 reg_addr)
548 {
549         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
550         struct rtl_priv *rtlpriv = btcoexist->adapter;
551
552         return  rtl_read_word(rtlpriv, reg_addr);
553 }
554
555
556 u32 halbtc_read_4byte(void *bt_context, u32 reg_addr)
557 {
558         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
559         struct rtl_priv *rtlpriv = btcoexist->adapter;
560         
561         return  rtl_read_dword(rtlpriv, reg_addr);
562 }
563
564
565 void halbtc_write_1byte(void *bt_context, u32 reg_addr, u8 data)
566 {
567         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
568         struct rtl_priv *rtlpriv = btcoexist->adapter;
569
570         rtl_write_byte(rtlpriv, reg_addr, data);
571 }
572
573 void halbtc_bitmask_write_1byte(void *bt_context, u32 reg_addr, 
574                                 u8 bit_mask, u8 data)
575 {
576         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
577         struct rtl_priv *rtlpriv = btcoexist->adapter;
578         u8 original_value, bit_shift = 0;
579         u8 i;
580
581         if (bit_mask != MASKDWORD) {/*if not "double word" write*/
582                 original_value = rtl_read_byte(rtlpriv, reg_addr);      
583                 for (i=0; i<=7; i++) {
584                         if((bit_mask>>i)&0x1)
585                                 break;
586                 }
587                 bit_shift = i;
588                 data = (original_value & (~bit_mask)) | 
589                         ((data << bit_shift) & bit_mask);
590         }
591         rtl_write_byte(rtlpriv, reg_addr, data);
592 }
593
594
595 void halbtc_write_2byte(void *bt_context, u32 reg_addr, u16 data)
596 {
597         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
598         struct rtl_priv *rtlpriv = btcoexist->adapter;
599
600         rtl_write_word(rtlpriv, reg_addr, data);
601 }
602
603
604 void halbtc_write_4byte(void *bt_context, u32 reg_addr, u32 data)
605 {
606         struct btc_coexist *btcoexist = 
607                 (struct btc_coexist *)bt_context;
608         struct rtl_priv *rtlpriv = btcoexist->adapter;
609
610         rtl_write_dword(rtlpriv, reg_addr, data);
611 }
612
613
614 void halbtc_set_macreg(void *bt_context, u32 reg_addr, u32 bit_mask, u32 data)
615 {
616         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
617         struct rtl_priv *rtlpriv = btcoexist->adapter;
618
619         rtl_set_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask, data);
620 }
621
622
623 u32 halbtc_get_macreg(void *bt_context, u32 reg_addr, u32 bit_mask)
624 {
625         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
626         struct rtl_priv *rtlpriv = btcoexist->adapter;
627
628         return rtl_get_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask);
629 }
630
631
632 void halbtc_set_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask, u32 data)
633 {
634         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
635         struct rtl_priv *rtlpriv = btcoexist->adapter;
636
637         rtl_set_bbreg(rtlpriv->mac80211.hw, reg_addr, bit_mask, data);
638 }
639
640
641 u32 halbtc_get_bbreg(void *bt_context, u32 reg_addr, u32 bit_mask)
642 {
643         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
644         struct rtl_priv *rtlpriv = btcoexist->adapter;
645
646         return rtl_get_bbreg(rtlpriv->mac80211.hw,reg_addr, bit_mask);
647 }
648
649
650 void halbtc_set_rfreg(void *bt_context, u8 rf_path, u32 reg_addr, 
651                       u32 bit_mask, u32 data)
652 {
653         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
654         struct rtl_priv *rtlpriv = btcoexist->adapter;
655
656         rtl_set_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask, data);
657 }
658
659
660 u32 halbtc_get_rfreg(void *bt_context, u8 rf_path, u32 reg_addr, u32 bit_mask)
661 {
662         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
663         struct rtl_priv *rtlpriv = btcoexist->adapter;
664
665         return rtl_get_rfreg(rtlpriv->mac80211.hw, rf_path, reg_addr, bit_mask);
666 }
667
668
669 void halbtc_fill_h2c_cmd(void *bt_context, u8 element_id, 
670                          u32 cmd_len, u8 *cmd_buf)
671 {
672         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
673         struct rtl_priv *rtlpriv = btcoexist->adapter;
674         
675         rtlpriv->cfg->ops->fill_h2c_cmd(rtlpriv->mac80211.hw, element_id, 
676                                         cmd_len, cmd_buf);
677 }
678
679 void halbtc_display_dbg_msg(void *bt_context, u8 disp_type)
680 {
681         struct btc_coexist *btcoexist = (struct btc_coexist *)bt_context;
682         switch (disp_type) {
683         case BTC_DBG_DISP_COEX_STATISTICS:
684                 halbtc_display_coex_statistics(btcoexist);
685                 break;
686         case BTC_DBG_DISP_BT_LINK_INFO:
687                 halbtc_display_bt_link_info(btcoexist);
688                 break;
689         case BTC_DBG_DISP_BT_FW_VER:
690                 halbtc_display_bt_fw_info(btcoexist);
691                 break;
692         case BTC_DBG_DISP_FW_PWR_MODE_CMD:
693                 halbtc_display_fw_pwr_mode_cmd(btcoexist);
694                 break;
695         default:
696                 break;
697         }
698 }
699
700 bool halbtc_under_ips(struct btc_coexist *btcoexist)
701 {
702         struct rtl_priv *rtlpriv = btcoexist->adapter;
703         struct rtl_ps_ctl *ppsc = rtl_psc(rtlpriv);
704         enum rf_pwrstate rtstate;
705         
706         if (ppsc->b_inactiveps) {
707                 rtstate = ppsc->rfpwr_state;
708
709                 if (rtstate != ERFON &&
710                     ppsc->rfoff_reason == RF_CHANGE_BY_IPS) {
711
712                         return true;
713                 }
714         }
715
716         return false;
717 }
718
719 /*****************************************************************
720  *         Extern functions called by other module
721  *****************************************************************/
722 bool exhalbtc_initlize_variables(struct rtl_priv *adapter)
723 {
724         struct btc_coexist *btcoexist = &gl_bt_coexist;
725
726         btcoexist->statistics.cnt_bind++;
727         
728         halbtc_dbg_init();
729
730         if (btcoexist->binded)
731                 return false;
732         else
733                 btcoexist->binded = true;
734
735         btcoexist->chip_interface = BTC_INTF_UNKNOWN;
736
737         if (NULL == btcoexist->adapter)
738                 btcoexist->adapter = adapter;
739
740         btcoexist->stack_info.profile_notified = false;
741
742         btcoexist->btc_read_1byte = halbtc_read_1byte;
743         btcoexist->btc_write_1byte = halbtc_write_1byte;
744         btcoexist->btc_write_1byte_bitmask = halbtc_bitmask_write_1byte;
745         btcoexist->btc_read_2byte = halbtc_read_2byte;
746         btcoexist->btc_write_2byte = halbtc_write_2byte;
747         btcoexist->btc_read_4byte = halbtc_read_4byte;
748         btcoexist->btc_write_4byte = halbtc_write_4byte;
749
750         btcoexist->btc_set_bb_reg = halbtc_set_bbreg;
751         btcoexist->btc_get_bb_reg = halbtc_get_bbreg;
752
753         btcoexist->btc_set_rf_reg = halbtc_set_rfreg;
754         btcoexist->btc_get_rf_reg = halbtc_get_rfreg;
755
756         btcoexist->btc_fill_h2c = halbtc_fill_h2c_cmd;
757         btcoexist->btc_disp_dbg_msg = halbtc_display_dbg_msg;
758         
759         btcoexist->btc_get = halbtc_get;
760         btcoexist->btc_set = halbtc_set;
761
762         btcoexist->cli_buf = &btc_dbg_buf[0];
763
764         btcoexist->bt_info.b_bt_ctrl_buf_size = false;
765         btcoexist->bt_info.agg_buf_size = 5;
766
767         btcoexist->bt_info.increase_scan_dev_num = false;
768         return true;
769 }
770
771 void exhalbtc_init_hw_config(struct btc_coexist *btcoexist)
772 {
773         struct rtl_priv *rtlpriv = btcoexist->adapter;
774         struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
775         
776         if (!halbtc_is_bt_coexist_available(btcoexist))
777                 return;
778
779         btcoexist->statistics.cnt_init_hw_config++;
780
781         if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) {
782                 if (btcoexist->board_info.btdm_ant_num == 2)
783                         ex_halbtc8723b2ant_init_hwconfig(btcoexist);
784                 else if(btcoexist->board_info.btdm_ant_num == 1)
785                         ex_halbtc8723b1ant_init_hwconfig(btcoexist);
786         } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192EE) {
787                 ex_halbtc8192e2ant_init_hwconfig(btcoexist);
788         }
789         
790 }
791
792 void exhalbtc_init_coex_dm(struct btc_coexist *btcoexist)
793 {
794         struct rtl_priv *rtlpriv = btcoexist->adapter;
795         struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
796         
797         if (!halbtc_is_bt_coexist_available(btcoexist))
798                 return;
799
800         btcoexist->statistics.cnt_init_coex_dm++;
801
802         if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) {
803                 if (btcoexist->board_info.btdm_ant_num == 2)
804                         ex_halbtc8723b2ant_init_coex_dm(btcoexist);             
805                 else if(btcoexist->board_info.btdm_ant_num == 1)
806                         ex_halbtc8723b1ant_init_coex_dm(btcoexist);
807         } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192EE) {
808                 ex_halbtc8192e2ant_init_coex_dm(btcoexist);
809         }
810         
811         btcoexist->initilized = true;
812 }
813
814 void exhalbtc_ips_notify(struct btc_coexist *btcoexist, u8 type)
815 {
816         struct rtl_priv *rtlpriv = btcoexist->adapter;
817         struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
818         u8 ips_type;
819
820         if (!halbtc_is_bt_coexist_available(btcoexist))
821                 return;
822         btcoexist->statistics.cnt_ips_notify++;
823         if (btcoexist->manual_control)
824                 return;
825
826         if (ERFOFF == type)
827                 ips_type = BTC_IPS_ENTER;
828         else
829                 ips_type = BTC_IPS_LEAVE;
830
831         halbtc_leave_low_power();
832         
833         if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) {
834                 if (btcoexist->board_info.btdm_ant_num == 2)
835                         ex_halbtc8723b2ant_ips_notify(btcoexist, ips_type);
836                 else if(btcoexist->board_info.btdm_ant_num == 1)
837                         ex_halbtc8723b1ant_ips_notify(btcoexist, ips_type);
838         } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192EE) {
839                 ex_halbtc8192e2ant_ips_notify(btcoexist, ips_type);
840         }
841
842         halbtc_nomal_low_power();
843 }
844
845 void exhalbtc_lps_notify(struct btc_coexist *btcoexist, u8 type)
846 {
847         struct rtl_priv *rtlpriv = btcoexist->adapter;
848         struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
849         u8 lps_type;
850
851         if (!halbtc_is_bt_coexist_available(btcoexist))
852                 return;
853         btcoexist->statistics.cnt_lps_notify++;
854         if (btcoexist->manual_control)
855                 return;
856         
857         if (EACTIVE == type)
858                 lps_type = BTC_LPS_DISABLE;
859         else
860                 lps_type = BTC_LPS_ENABLE;
861
862         if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) {
863                 if (btcoexist->board_info.btdm_ant_num == 2)
864                         ex_halbtc8723b2ant_lps_notify(btcoexist, lps_type);
865                 else if(btcoexist->board_info.btdm_ant_num == 1)
866                         ex_halbtc8723b1ant_lps_notify(btcoexist, lps_type);
867         } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192EE) {
868                 ex_halbtc8192e2ant_lps_notify(btcoexist, lps_type);
869         }
870 }
871
872 void exhalbtc_scan_notify(struct btc_coexist *btcoexist, u8 type)
873 {
874         struct rtl_priv *rtlpriv = btcoexist->adapter;
875         struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
876         u8 scan_type;
877
878         if (!halbtc_is_bt_coexist_available(btcoexist))
879                 return;
880         btcoexist->statistics.cnt_scan_notify++;
881         if (btcoexist->manual_control)
882                 return;
883
884         if (type)
885                 scan_type = BTC_SCAN_START;
886         else
887                 scan_type = BTC_SCAN_FINISH;
888
889         halbtc_leave_low_power();
890         
891         if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) {
892                 if (btcoexist->board_info.btdm_ant_num == 2)
893                         ex_halbtc8723b2ant_scan_notify(btcoexist, scan_type);
894                 else if(btcoexist->board_info.btdm_ant_num == 1)
895                         ex_halbtc8723b1ant_scan_notify(btcoexist, scan_type);
896         } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192EE) {
897                 ex_halbtc8192e2ant_scan_notify(btcoexist, scan_type);
898         }
899
900         halbtc_nomal_low_power();
901 }
902
903 void exhalbtc_connect_notify(struct btc_coexist *btcoexist, u8 action)
904 {
905         struct rtl_priv *rtlpriv = btcoexist->adapter;
906         struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
907         u8 asso_type;
908
909         if (!halbtc_is_bt_coexist_available(btcoexist))
910                 return;
911         btcoexist->statistics.cnt_connect_notify++;
912         if (btcoexist->manual_control)
913                 return;
914
915         if (action)
916                 asso_type = BTC_ASSOCIATE_START;
917         else
918                 asso_type = BTC_ASSOCIATE_FINISH;
919
920         halbtc_leave_low_power();
921         
922         if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) {
923                 if (btcoexist->board_info.btdm_ant_num == 2)
924                         ex_halbtc8723b2ant_connect_notify(btcoexist, asso_type);
925                 else if(btcoexist->board_info.btdm_ant_num == 1)
926                         ex_halbtc8723b1ant_connect_notify(btcoexist, asso_type);
927         } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192EE) {
928                 ex_halbtc8192e2ant_connect_notify(btcoexist, asso_type);
929         }
930
931         halbtc_nomal_low_power();
932 }
933
934 void exhalbtc_mediastatus_notify(struct btc_coexist *btcoexist, 
935                                  enum rt_media_status media_status)
936 {
937         struct rtl_priv *rtlpriv = btcoexist->adapter;
938         struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
939         u8 status;
940
941         if (!halbtc_is_bt_coexist_available(btcoexist))
942                 return;
943         btcoexist->statistics.cnt_media_status_notify++;
944         if (btcoexist->manual_control)
945                 return;
946
947         if (RT_MEDIA_CONNECT == media_status)
948                 status = BTC_MEDIA_CONNECT;
949         else
950                 status = BTC_MEDIA_DISCONNECT;
951
952         halbtc_leave_low_power();
953         
954         if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) {
955                 if (btcoexist->board_info.btdm_ant_num == 2)
956                         ex_halbtc8723b2ant_media_status_notify(btcoexist, status);
957                 else if(btcoexist->board_info.btdm_ant_num == 1)
958                         ex_halbtc8723b1ant_media_status_notify(btcoexist, status);
959         } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192EE) {
960                 ex_halbtc8192e2ant_media_status_notify(btcoexist, status);
961         }
962
963         halbtc_nomal_low_power();
964 }
965
966 void exhalbtc_special_packet_notify(struct btc_coexist *btcoexist, u8 pkt_type)
967 {
968         u8 packet_type;
969
970         if (!halbtc_is_bt_coexist_available(btcoexist))
971                 return;
972         btcoexist->statistics.cnt_special_packet_notify++;
973         if (btcoexist->manual_control)
974                 return;
975
976         /*if(PACKET_DHCP == pkt_type)*/
977                 packet_type = BTC_PACKET_DHCP;
978         /*else if(PACKET_EAPOL == pkt_type)
979                 packet_type = BTC_PACKET_EAPOL;
980         else
981                 packet_type = BTC_PACKET_UNKNOWN;*/
982
983         halbtc_leave_low_power();
984
985         if (btcoexist->board_info.btdm_ant_num == 2)
986                 ex_halbtc8723b2ant_special_packet_notify(btcoexist,
987                                                          packet_type);
988         else if (btcoexist->board_info.btdm_ant_num == 1)
989                 ex_halbtc8723b1ant_special_packet_notify(btcoexist,
990                                                          packet_type);
991
992         halbtc_nomal_low_power();
993 }
994
995 void exhalbtc_bt_info_notify(struct btc_coexist *btcoexist, 
996                              u8 *tmp_buf, u8 length)
997 {
998         struct rtl_priv *rtlpriv = btcoexist->adapter;
999         struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
1000         if (!halbtc_is_bt_coexist_available(btcoexist))
1001                 return;
1002         btcoexist->statistics.cnt_bt_info_notify++;
1003
1004         if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) {
1005                 if (btcoexist->board_info.btdm_ant_num == 2)
1006                         ex_halbtc8723b2ant_bt_info_notify(btcoexist, tmp_buf, length);
1007                 else if(btcoexist->board_info.btdm_ant_num == 1)
1008                         ex_halbtc8723b1ant_bt_info_notify(btcoexist, tmp_buf, length);
1009         } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192EE) {
1010         //      ex_halbtc8192e2ant_bt_info_notify(btcoexist, tmp_buf, length);
1011         }
1012 }
1013
1014 void exhalbtc_stack_operation_notify(struct btc_coexist *btcoexist, u8 type)
1015 {
1016         u8 stack_op_type;
1017
1018         if (!halbtc_is_bt_coexist_available(btcoexist))
1019                 return;
1020         btcoexist->statistics.cnt_stack_operation_notify++;
1021         if (btcoexist->manual_control)
1022                 return;
1023
1024         stack_op_type = BTC_STACK_OP_NONE;
1025 }
1026
1027 void exhalbtc_halt_notify(struct btc_coexist *btcoexist)
1028 {
1029         struct rtl_priv *rtlpriv = btcoexist->adapter;
1030         struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
1031         if (!halbtc_is_bt_coexist_available(btcoexist))
1032                 return;
1033
1034         if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) {
1035                 if (btcoexist->board_info.btdm_ant_num == 2)
1036                         ex_halbtc8723b2ant_halt_notify(btcoexist);
1037                 else if(btcoexist->board_info.btdm_ant_num == 1)
1038                         ex_halbtc8723b1ant_halt_notify(btcoexist);
1039         } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192EE) {
1040                 ex_halbtc8192e2ant_halt_notify(btcoexist);
1041         }
1042 }
1043
1044 void exhalbtc_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state)
1045 {
1046         if (!halbtc_is_bt_coexist_available(btcoexist))
1047                 return;
1048 }
1049
1050 void exhalbtc_periodical(struct btc_coexist *btcoexist)
1051 {
1052         struct rtl_priv *rtlpriv = btcoexist->adapter;
1053         struct rtl_hal *rtlhal = rtl_hal(rtlpriv);
1054         if (!halbtc_is_bt_coexist_available(btcoexist))
1055                 return;
1056         btcoexist->statistics.cnt_periodical++;
1057
1058         halbtc_leave_low_power();
1059
1060         if (rtlhal->hw_type == HARDWARE_TYPE_RTL8723BE) {
1061                 if (btcoexist->board_info.btdm_ant_num == 2)
1062                         ex_halbtc8723b2ant_periodical(btcoexist);
1063                 else if(btcoexist->board_info.btdm_ant_num == 1)
1064                         ex_halbtc8723b1ant_periodical(btcoexist);
1065         } else if (rtlhal->hw_type == HARDWARE_TYPE_RTL8192EE) {
1066                 ex_halbtc8192e2ant_periodical(btcoexist);
1067         }
1068
1069         halbtc_nomal_low_power();
1070 }
1071
1072 void exhalbtc_dbg_control(struct btc_coexist *btcoexist, 
1073                           u8 code, u8 len, u8 *data)
1074 {
1075         if (!halbtc_is_bt_coexist_available(btcoexist))
1076                 return;
1077         btcoexist->statistics.cnt_dbg_ctrl++;
1078 }
1079
1080 void exhalbtc_stack_update_profile_info()
1081 {
1082 }
1083
1084 void exhalbtc_update_min_bt_rssi(char bt_rssi)
1085 {
1086         struct btc_coexist *btcoexist = &gl_bt_coexist;
1087
1088         if (!halbtc_is_bt_coexist_available(btcoexist))
1089                 return;
1090
1091         btcoexist->stack_info.min_bt_rssi = bt_rssi;
1092 }
1093
1094
1095 void exhalbtc_set_hci_version(u16 hci_version)
1096 {
1097         struct btc_coexist *btcoexist = &gl_bt_coexist;
1098
1099         if (!halbtc_is_bt_coexist_available(btcoexist))
1100                 return;
1101
1102         btcoexist->stack_info.hci_version = hci_version;
1103 }
1104
1105 void exhalbtc_set_bt_patch_version(u16 bt_hci_version, u16 bt_patch_version) 
1106 {
1107         struct btc_coexist *btcoexist = &gl_bt_coexist;
1108
1109         if (!halbtc_is_bt_coexist_available(btcoexist))
1110                 return;
1111
1112         btcoexist->bt_info.bt_real_fw_ver = bt_patch_version;
1113         btcoexist->bt_info.bt_hci_ver = bt_hci_version;
1114 }
1115
1116 void exhalbtc_set_bt_exist(bool bt_exist)
1117 {
1118         gl_bt_coexist.board_info.bt_exist = bt_exist;
1119 }
1120
1121 void exhalbtc_set_chip_type(u8 chip_type)
1122 {
1123         switch (chip_type) {
1124         default:
1125         case BT_2WIRE:
1126         case BT_ISSC_3WIRE:
1127         case BT_ACCEL:
1128         case BT_RTL8756:
1129                 gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_UNDEF;
1130                 break;
1131         case BT_CSR_BC4:
1132                 gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_CSR_BC4;
1133                 break;
1134         case BT_CSR_BC8:
1135                 gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_CSR_BC8;
1136                 break;
1137         case BT_RTL8723A:
1138                 gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_RTL8723A;
1139                 break;
1140         case BT_RTL8821A:
1141                 gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_RTL8821;
1142                 break;
1143         case BT_RTL8723B:
1144                 gl_bt_coexist.board_info.bt_chip_type = BTC_CHIP_RTL8723B;
1145                 break;
1146         }
1147 }
1148
1149 void exhalbtc_set_ant_num(u8 type, u8 ant_num)
1150 {
1151         if (BT_COEX_ANT_TYPE_PG == type) {
1152                 gl_bt_coexist.board_info.pg_ant_num = ant_num;
1153                 gl_bt_coexist.board_info.btdm_ant_num = ant_num;
1154         } else if (BT_COEX_ANT_TYPE_ANTDIV == type) {
1155                 gl_bt_coexist.board_info.btdm_ant_num = ant_num;
1156         }
1157 }
1158
1159 void exhalbtc_display_bt_coex_info(struct btc_coexist *btcoexist)
1160 {
1161         if (!halbtc_is_bt_coexist_available(btcoexist))
1162                 return;
1163         
1164         if (btcoexist->board_info.btdm_ant_num == 2)
1165                 ex_halbtc8723b2ant_display_coex_info(btcoexist);
1166         else if (btcoexist->board_info.btdm_ant_num == 1)
1167                 ex_halbtc8723b1ant_display_coex_info(btcoexist);
1168 }
1169
1170 #endif
1171