net: wireless: rockchip_wlan: add rtl8723ds support
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / rtl8723ds / hal / btc / halbtc8821c2ant.h
1
2 #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1)
3
4 #if (RTL8821C_SUPPORT == 1)
5
6 /* *******************************************
7  * The following is for 8821C 2Ant BT Co-exist definition
8  * ******************************************* */
9 #define BT_AUTO_REPORT_ONLY_8821C_2ANT                          1
10
11
12 #define BT_INFO_8821C_2ANT_B_FTP                                                BIT(7)
13 #define BT_INFO_8821C_2ANT_B_A2DP                                       BIT(6)
14 #define BT_INFO_8821C_2ANT_B_HID                                                BIT(5)
15 #define BT_INFO_8821C_2ANT_B_SCO_BUSY                           BIT(4)
16 #define BT_INFO_8821C_2ANT_B_ACL_BUSY                           BIT(3)
17 #define BT_INFO_8821C_2ANT_B_INQ_PAGE                           BIT(2)
18 #define BT_INFO_8821C_2ANT_B_SCO_ESCO                           BIT(1)
19 #define BT_INFO_8821C_2ANT_B_CONNECTION                         BIT(0)
20
21 #define         BTC_RSSI_COEX_THRESH_TOL_8821C_2ANT             2
22
23
24 #define BT_8821C_2ANT_WIFI_RSSI_COEXSWITCH_THRES1                               80  /* unit: % WiFi RSSI Threshold for   2-Ant free-run/2-Ant TDMA translation, default = 42 */
25 #define BT_8821C_2ANT_BT_RSSI_COEXSWITCH_THRES1                         80 /*  unit: % BT RSSI Threshold for      2-Ant free-run/2-Ant TDMA translation, default = 46 */
26 #define BT_8821C_2ANT_WIFI_RSSI_COEXSWITCH_THRES2                               80  /* unit: % WiFi RSSI Threshold for   1-Ant TDMA/1-Ant PS-TDMA translation, default = 42 */
27 #define BT_8821C_2ANT_BT_RSSI_COEXSWITCH_THRES2                         80 /*  unit: % BT RSSI Threshold for      1-Ant TDMA/1-Ant PS-TDMA translation, default = 46 */
28 #define BT_8821C_2ANT_DEFAULT_ISOLATION                                         15       /*  unit: dB */
29 #define   BT_8821C_2ANT_WIFI_MAX_TX_POWER                                               15       /*  unit: dBm */
30 #define   BT_8821C_2ANT_BT_MAX_TX_POWER                                                 3        /*  unit: dBm */
31 #define   BT_8821C_2ANT_WIFI_SIR_THRES1                                                 -15  /*  unit: dB */
32 #define   BT_8821C_2ANT_WIFI_SIR_THRES2                                                 -30  /*  unit: dB */
33 #define   BT_8821C_2ANT_BT_SIR_THRES1                                                   -15              /*  unit: dB */
34 #define   BT_8821C_2ANT_BT_SIR_THRES2                                                   -30              /*  unit: dB */
35
36
37 /* for Antenna detection */
38 #define BT_8821C_2ANT_ANTDET_PSDTHRES_BACKGROUND                                                50
39 #define BT_8821C_2ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION                         70
40 #define BT_8821C_2ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION                        52
41 #define BT_8821C_2ANT_ANTDET_PSDTHRES_1ANT                                                      40
42 #define BT_8821C_2ANT_ANTDET_RETRY_INTERVAL                                                     10      /* retry timer if ant det is fail, unit: second */
43 #define BT_8821C_2ANT_ANTDET_SWEEPPOINT_DELAY                                                   40000
44 #define BT_8821C_2ANT_ANTDET_ENABLE                                                                             0
45 #define BT_8821C_2ANT_ANTDET_COEXMECHANISMSWITCH_ENABLE                 0
46 #define BT_8821C_2ANT_ANTDET_BTTXTIME                                                                   100
47 #define BT_8821C_2ANT_ANTDET_BTTXCHANNEL                                                                39
48
49 #define BT_8821C_2ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT                30000
50
51 enum bt_8821c_2ant_signal_state {
52         BT_8821C_2ANT_SIG_STA_SET_TO_LOW                = 0x0,
53         BT_8821C_2ANT_SIG_STA_SET_BY_HW         = 0x0,
54         BT_8821C_2ANT_SIG_STA_SET_TO_HIGH               = 0x1,
55         BT_8821C_2ANT_SIG_STA_MAX
56 };
57
58 enum bt_8821c_2ant_path_ctrl_owner {
59         BT_8821C_2ANT_PCO_BTSIDE                = 0x0,
60         BT_8821C_2ANT_PCO_WLSIDE        = 0x1,
61         BT_8821C_2ANT_PCO_MAX
62 };
63
64 enum bt_8821c_2ant_gnt_ctrl_type {
65         BT_8821C_2ANT_GNT_TYPE_CTRL_BY_PTA              = 0x0,
66         BT_8821C_2ANT_GNT_TYPE_CTRL_BY_SW               = 0x1,
67         BT_8821C_2ANT_GNT_TYPE_MAX
68 };
69
70 enum bt_8821c_2ant_gnt_ctrl_block {
71         BT_8821C_2ANT_GNT_BLOCK_RFC_BB          = 0x0,
72         BT_8821C_2ANT_GNT_BLOCK_RFC                     = 0x1,
73         BT_8821C_2ANT_GNT_BLOCK_BB                      = 0x2,
74         BT_8821C_2ANT_GNT_BLOCK_MAX
75 };
76
77 enum bt_8821c_2ant_lte_coex_table_type {
78         BT_8821C_2ANT_CTT_WL_VS_LTE                     = 0x0,
79         BT_8821C_2ANT_CTT_BT_VS_LTE                     = 0x1,
80         BT_8821C_2ANT_CTT_MAX
81 };
82
83 enum bt_8821c_2ant_lte_break_table_type {
84         BT_8821C_2ANT_LBTT_WL_BREAK_LTE                 = 0x0,
85         BT_8821C_2ANT_LBTT_BT_BREAK_LTE                         = 0x1,
86         BT_8821C_2ANT_LBTT_LTE_BREAK_WL                 = 0x2,
87         BT_8821C_2ANT_LBTT_LTE_BREAK_BT                         = 0x3,
88         BT_8821C_2ANT_LBTT_MAX
89 };
90
91 enum bt_info_src_8821c_2ant {
92         BT_INFO_SRC_8821C_2ANT_WIFI_FW                  = 0x0,
93         BT_INFO_SRC_8821C_2ANT_BT_RSP                           = 0x1,
94         BT_INFO_SRC_8821C_2ANT_BT_ACTIVE_SEND           = 0x2,
95         BT_INFO_SRC_8821C_2ANT_MAX
96 };
97
98 enum bt_8821c_2ant_bt_status {
99         BT_8821C_2ANT_BT_STATUS_NON_CONNECTED_IDLE      = 0x0,
100         BT_8821C_2ANT_BT_STATUS_CONNECTED_IDLE          = 0x1,
101         BT_8821C_2ANT_BT_STATUS_INQ_PAGE                                = 0x2,
102         BT_8821C_2ANT_BT_STATUS_ACL_BUSY                                = 0x3,
103         BT_8821C_2ANT_BT_STATUS_SCO_BUSY                                = 0x4,
104         BT_8821C_2ANT_BT_STATUS_ACL_SCO_BUSY                    = 0x5,
105         BT_8821C_2ANT_BT_STATUS_MAX
106 };
107
108 enum bt_8821c_2ant_coex_algo {
109         BT_8821C_2ANT_COEX_ALGO_UNDEFINED                       = 0x0,
110         BT_8821C_2ANT_COEX_ALGO_SCO                             = 0x1,
111         BT_8821C_2ANT_COEX_ALGO_HID                             = 0x2,
112         BT_8821C_2ANT_COEX_ALGO_A2DP                            = 0x3,
113         BT_8821C_2ANT_COEX_ALGO_A2DP_PANHS              = 0x4,
114         BT_8821C_2ANT_COEX_ALGO_PANEDR                  = 0x5,
115         BT_8821C_2ANT_COEX_ALGO_PANHS                   = 0x6,
116         BT_8821C_2ANT_COEX_ALGO_PANEDR_A2DP             = 0x7,
117         BT_8821C_2ANT_COEX_ALGO_PANEDR_HID              = 0x8,
118         BT_8821C_2ANT_COEX_ALGO_HID_A2DP_PANEDR = 0x9,
119         BT_8821C_2ANT_COEX_ALGO_HID_A2DP                        = 0xa,
120         BT_8821C_2ANT_COEX_ALGO_NOPROFILEBUSY           = 0xb,
121         BT_8821C_2ANT_COEX_ALGO_MAX
122 };
123
124 enum bt_8821c_2ant_ext_ant_switch_ctrl_type {
125         BT_8821C_2ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW       = 0x0,
126         BT_8821C_2ANT_EXT_ANT_SWITCH_CTRL_BY_PTA                = 0x1,
127         BT_8821C_2ANT_EXT_ANT_SWITCH_CTRL_BY_ANTDIV     = 0x2,
128         BT_8821C_2ANT_EXT_ANT_SWITCH_CTRL_BY_MAC                = 0x3,
129         BT_8821C_2ANT_EXT_ANT_SWITCH_CTRL_BY_BT         = 0x4,
130         BT_8821C_2ANT_EXT_ANT_SWITCH_CTRL_MAX
131 };
132
133 enum bt_8821c_2ant_ext_ant_switch_pos_type {
134         BT_8821C_2ANT_EXT_ANT_SWITCH_MAIN_TO_BT                 = 0x0,
135         BT_8821C_2ANT_EXT_ANT_SWITCH_MAIN_TO_WLG                        = 0x1,
136         BT_8821C_2ANT_EXT_ANT_SWITCH_MAIN_TO_WLA                        = 0x2,
137         BT_8821C_2ANT_EXT_ANT_SWITCH_MAIN_TO_NOCARE             = 0x3,
138         BT_8821C_2ANT_EXT_ANT_SWITCH_MAIN_TO_MAX
139 };
140
141 enum bt_8821c_2ant_ext_band_switch_pos_type {
142         BT_8821C_2ANT_EXT_BAND_SWITCH_TO_WLG                    = 0x0,
143         BT_8821C_2ANT_EXT_BAND_SWITCH_TO_WLA                    = 0x1,
144         BT_8821C_2ANT_EXT_BAND_SWITCH_TO_MAX
145 };
146
147 enum bt_8821c_2ant_int_block{
148         BT_8821C_2ANT_INT_BLOCK_SWITCH_TO_WLG_OF_BTG                    = 0x0,
149         BT_8821C_2ANT_INT_BLOCK_SWITCH_TO_WLG_OF_WLAG           = 0x1,
150         BT_8821C_2ANT_INT_BLOCK_SWITCH_TO_WLA_OF_WLAG           = 0x2,
151         BT_8821C_2ANT_INT_BLOCK_SWITCH_TO_MAX
152 };
153
154 enum bt_8821c_2ant_phase{
155         BT_8821C_2ANT_PHASE_COEX_INIT                                                           = 0x0,
156         BT_8821C_2ANT_PHASE_WLANONLY_INIT                                                       = 0x1,  
157         BT_8821C_2ANT_PHASE_WLAN_OFF                                                            = 0x2,
158         BT_8821C_2ANT_PHASE_2G_RUNTIME                                                          = 0x3,
159         BT_8821C_2ANT_PHASE_5G_RUNTIME                                                          = 0x4,
160         BT_8821C_2ANT_PHASE_BTMPMODE                                                                    = 0x5,
161         BT_8821C_2ANT_PHASE_MAX
162 };
163
164 struct coex_dm_8821c_2ant {
165         /* hw setting */
166         u32             pre_ant_pos_type;
167         u32             cur_ant_pos_type;
168         /* fw mechanism */
169         u8              pre_bt_dec_pwr_lvl;
170         u8              cur_bt_dec_pwr_lvl;
171         u8              pre_fw_dac_swing_lvl;
172         u8              cur_fw_dac_swing_lvl;
173         boolean         cur_ignore_wlan_act;
174         boolean         pre_ignore_wlan_act;
175         u8              pre_ps_tdma;
176         u8              cur_ps_tdma;
177         u8              ps_tdma_para[5];
178         u8              ps_tdma_du_adj_type;
179         boolean         reset_tdma_adjust;
180         boolean         auto_tdma_adjust;
181         boolean         pre_ps_tdma_on;
182         boolean         cur_ps_tdma_on;
183         boolean         pre_bt_auto_report;
184         boolean         cur_bt_auto_report;
185
186         /* sw mechanism */
187         boolean         pre_rf_rx_lpf_shrink;
188         boolean         cur_rf_rx_lpf_shrink;
189         u32             bt_rf_0x1e_backup;
190         boolean pre_low_penalty_ra;
191         boolean         cur_low_penalty_ra;
192         boolean         pre_dac_swing_on;
193         u32             pre_dac_swing_lvl;
194         boolean         cur_dac_swing_on;
195         u32             cur_dac_swing_lvl;
196         boolean         pre_adc_back_off;
197         boolean         cur_adc_back_off;
198         boolean pre_agc_table_en;
199         boolean         cur_agc_table_en;
200         u32             pre_val0x6c0;
201         u32             cur_val0x6c0;
202         u32             pre_val0x6c4;
203         u32             cur_val0x6c4;
204         u32             pre_val0x6c8;
205         u32             cur_val0x6c8;
206         u8              pre_val0x6cc;
207         u8              cur_val0x6cc;
208         boolean         limited_dig;
209
210         /* algorithm related */
211         u8              pre_algorithm;
212         u8              cur_algorithm;
213         u8              bt_status;
214         u8              wifi_chnl_info[3];
215
216         boolean         need_recover0x948;
217         u32             backup0x948;
218
219         u8              pre_lps;
220         u8              cur_lps;
221         u8              pre_rpwm;
222         u8              cur_rpwm;
223
224         boolean         is_switch_to_1dot5_ant;
225         u8              switch_thres_offset;
226         u32                                     arp_cnt;
227
228         u32             pre_ext_ant_switch_status;
229         u32             cur_ext_ant_switch_status;
230         
231         u8              pre_ext_band_switch_status;
232         u8              cur_ext_band_switch_status;
233
234         u8              pre_int_block_status;
235         u8              cur_int_block_status;
236 };
237
238 struct coex_sta_8821c_2ant {
239         boolean                                 bt_disabled;
240         boolean                                 bt_link_exist;
241         boolean                                 sco_exist;
242         boolean                                 a2dp_exist;
243         boolean                                 hid_exist;
244         boolean                                 pan_exist;
245
246         boolean                                 under_lps;
247         boolean                                 under_ips;
248         u32                                     high_priority_tx;
249         u32                                     high_priority_rx;
250         u32                                     low_priority_tx;
251         u32                                     low_priority_rx;
252         u8                                      bt_rssi;
253         boolean                                 bt_tx_rx_mask;
254         u8                                      pre_bt_rssi_state;
255         u8                                      pre_wifi_rssi_state[4];
256         boolean                                 c2h_bt_info_req_sent;
257         u8                                      bt_info_c2h[BT_INFO_SRC_8821C_2ANT_MAX][10];
258         u32                                     bt_info_c2h_cnt[BT_INFO_SRC_8821C_2ANT_MAX];
259         boolean                         bt_whck_test;
260         boolean                                 c2h_bt_inquiry_page;
261         boolean                                 c2h_bt_remote_name_req;
262         u8                                      bt_retry_cnt;
263         u8                                      bt_info_ext;
264         u32                                     pop_event_cnt;
265         u8                                      scan_ap_num;
266
267         u32                                     crc_ok_cck;
268         u32                                     crc_ok_11g;
269         u32                                     crc_ok_11n;
270         u32                                     crc_ok_11n_agg;
271
272         u32                                     crc_err_cck;
273         u32                                     crc_err_11g;
274         u32                                     crc_err_11n;
275         u32                                     crc_err_11n_agg;
276
277         
278         boolean                                 cck_lock;
279         boolean                                 pre_ccklock;
280         boolean                                 cck_ever_lock;
281
282         u8                                      coex_table_type;
283         boolean                                 force_lps_on;
284
285         u8                                      dis_ver_info_cnt;
286
287         u8                                      a2dp_bit_pool;
288         u8                                      cut_version;
289
290         boolean                                 concurrent_rx_mode_on;
291
292         u16                                     score_board;
293         u8                                      isolation_btween_wb;   /* 0~ 50 */
294         u8                                      wifi_coex_thres;
295         u8                                      bt_coex_thres;
296         u8                                      wifi_coex_thres2;
297         u8                                      bt_coex_thres2;
298
299         u8                                      num_of_profile;
300         boolean                         acl_busy;
301         boolean                         wl_rf_off_on_event;
302         boolean                         bt_create_connection;
303         boolean                         run_time_state;
304         boolean                         wifi_is_high_pri_task;
305         u32                                     specific_pkt_period_cnt;
306         u32                                     bt_coex_supported_feature;
307         u32                                     bt_coex_supported_version;
308 };
309
310 #define  BT_8821C_2ANT_EXT_ANT_SWITCH_USE_DPDT          0
311 #define  BT_8821C_2ANT_EXT_ANT_SWITCH_USE_SPDT          1
312
313 #define  BT_8821C_2ANT_EXT_BAND_SWITCH_USE_DPDT         0
314 #define  BT_8821C_2ANT_EXT_BAND_SWITCH_USE_SPDT         1
315
316
317 struct rfe_type_8821c_2ant{
318
319         u8                      rfe_module_type;        
320         boolean         ext_ant_switch_exist;
321         u8                      ext_ant_switch_type;                    /* 0:DPDT, 1:SPDT */
322         u8                      ext_ant_switch_ctrl_polarity;           /*  iF 0: DPDT_P=0, DPDT_N=1 => BTG to Main, WL_A+G to Aux */
323         
324         boolean         ext_band_switch_exist;
325         u8                      ext_band_switch_type;                   /* 0:DPDT, 1:SPDT */
326         u8                      ext_band_switch_ctrl_polarity;
327
328         boolean         wlg_Locate_at_btg;                              /*  If true:  WLG at BTG, If false: WLG at WLAG  */     
329
330         boolean         ext_ant_switch_diversity;               /* If diversity on  */
331 };
332
333 #define BT_8821C_2ANT_ANTDET_PSD_POINTS                 256     /* MAX:1024 */
334 #define BT_8821C_2ANT_ANTDET_PSD_AVGNUM         1       /* MAX:3 */
335 #define BT_8821C_2ANT_ANTDET_BUF_LEN                    16
336
337 struct psdscan_sta_8821c_2ant {
338
339         u32                     ant_det_bt_le_channel;  /* BT LE Channel ex:2412 */
340         u32                     ant_det_bt_tx_time;
341         u32                     ant_det_pre_psdscan_peak_val;
342         boolean                 ant_det_is_ant_det_available;
343         u32                     ant_det_psd_scan_peak_val;
344         boolean                 ant_det_is_btreply_available;
345         u32                     ant_det_psd_scan_peak_freq;
346
347         u8                      ant_det_result;
348         u8                      ant_det_peak_val[BT_8821C_2ANT_ANTDET_BUF_LEN];
349         u8                      ant_det_peak_freq[BT_8821C_2ANT_ANTDET_BUF_LEN];
350         u32                     ant_det_try_count;
351         u32                     ant_det_fail_count;
352         u32                     ant_det_inteval_count;
353         u32                     ant_det_thres_offset;
354
355         u32                     real_cent_freq;
356         s32                     real_offset;
357         u32                     real_span;
358
359         u32                     psd_band_width;  /* unit: Hz */
360         u32                     psd_point;              /* 128/256/512/1024 */
361         u32                     psd_report[1024];  /* unit:dB (20logx), 0~255 */
362         u32                     psd_report_max_hold[1024];  /* unit:dB (20logx), 0~255 */
363         u32                     psd_start_point;
364         u32                     psd_stop_point;
365         u32                     psd_max_value_point;
366         u32                     psd_max_value;
367         u32                     psd_start_base;
368         u32                     psd_avg_num;    /* 1/8/16/32 */
369         u32                     psd_gen_count;
370         boolean                 is_psd_running;
371         boolean                 is_psd_show_max_only;
372 };
373
374
375 /* *******************************************
376  * The following is interface which will notify coex module.
377  * ******************************************* */
378 void ex_halbtc8821c2ant_power_on_setting(IN struct btc_coexist *btcoexist);
379 void ex_halbtc8821c2ant_pre_load_firmware(IN struct btc_coexist *btcoexist);
380 void ex_halbtc8821c2ant_init_hw_config(IN struct btc_coexist *btcoexist,
381                                        IN boolean wifi_only);
382 void ex_halbtc8821c2ant_init_coex_dm(IN struct btc_coexist *btcoexist);
383 void ex_halbtc8821c2ant_ips_notify(IN struct btc_coexist *btcoexist,
384                                    IN u8 type);
385 void ex_halbtc8821c2ant_lps_notify(IN struct btc_coexist *btcoexist,
386                                    IN u8 type);
387 void ex_halbtc8821c2ant_scan_notify(IN struct btc_coexist *btcoexist,
388                                     IN u8 type);
389 void ex_halbtc8821c2ant_switchband_notify(IN struct btc_coexist *btcoexist,
390                                     IN u8 type);
391 void ex_halbtc8821c2ant_connect_notify(IN struct btc_coexist *btcoexist,
392                                        IN u8 type);
393 void ex_halbtc8821c2ant_media_status_notify(IN struct btc_coexist *btcoexist,
394                 IN u8 type);
395 void ex_halbtc8821c2ant_specific_packet_notify(IN struct btc_coexist *btcoexist,
396                 IN u8 type);
397 void ex_halbtc8821c2ant_bt_info_notify(IN struct btc_coexist *btcoexist,
398                                        IN u8 *tmp_buf, IN u8 length);
399 void ex_halbtc8821c2ant_rf_status_notify(IN struct btc_coexist *btcoexist,
400                 IN u8 type);
401 void ex_halbtc8821c2ant_halt_notify(IN struct btc_coexist *btcoexist);
402 void ex_halbtc8821c2ant_pnp_notify(IN struct btc_coexist *btcoexist,
403                                    IN u8 pnp_state);
404 void ex_halbtc8821c2ant_periodical(IN struct btc_coexist *btcoexist);
405 void ex_halbtc8821c2ant_display_coex_info(IN struct btc_coexist *btcoexist);
406 void ex_halbtc8821c2ant_antenna_detection(IN struct btc_coexist *btcoexist,
407                 IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds);
408 void ex_halbtc8821c2ant_display_ant_detection(IN struct btc_coexist *btcoexist);
409
410
411 #else
412 #define ex_halbtc8821c2ant_power_on_setting(btcoexist)
413 #define ex_halbtc8821c2ant_pre_load_firmware(btcoexist)
414 #define ex_halbtc8821c2ant_init_hw_config(btcoexist, wifi_only)
415 #define ex_halbtc8821c2ant_init_coex_dm(btcoexist)
416 #define ex_halbtc8821c2ant_ips_notify(btcoexist, type)
417 #define ex_halbtc8821c2ant_lps_notify(btcoexist, type)
418 #define ex_halbtc8821c2ant_scan_notify(btcoexist, type)
419 #define   ex_halbtc8821c2ant_switchband_notify(btcoexist,type)
420 #define ex_halbtc8821c2ant_connect_notify(btcoexist, type)
421 #define ex_halbtc8821c2ant_media_status_notify(btcoexist, type)
422 #define ex_halbtc8821c2ant_specific_packet_notify(btcoexist, type)
423 #define ex_halbtc8821c2ant_bt_info_notify(btcoexist, tmp_buf, length)
424 #define ex_halbtc8821c2ant_rf_status_notify(btcoexist, type)
425 #define ex_halbtc8821c2ant_halt_notify(btcoexist)
426 #define ex_halbtc8821c2ant_pnp_notify(btcoexist, pnp_state)
427 #define ex_halbtc8821c2ant_periodical(btcoexist)
428 #define ex_halbtc8821c2ant_display_coex_info(btcoexist)
429 #define ex_halbtc8821c2ant_display_ant_detection(btcoexist)
430 #define ex_halbtc8821c2ant_antenna_detection(btcoexist, centFreq, offset, span, seconds)
431 #endif
432
433 #endif