1 /******************************************************************************
3 * Copyright(c) 2016 Realtek Corporation.
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.
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
14 * The full GNU General Public License is included in this distribution in the
15 * file called LICENSE.
17 * Contact Information:
18 * wlanfae <wlanfae@realtek.com>
19 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park,
20 * Hsinchu 300, Taiwan.
22 * Larry Finger <Larry.Finger@lwfinger.net>
24 *****************************************************************************/
26 /* *******************************************
27 * The following is for 8822B 1ANT BT Co-exist definition
28 * ********************************************/
29 #define BT_INFO_8822B_1ANT_B_FTP BIT(7)
30 #define BT_INFO_8822B_1ANT_B_A2DP BIT(6)
31 #define BT_INFO_8822B_1ANT_B_HID BIT(5)
32 #define BT_INFO_8822B_1ANT_B_SCO_BUSY BIT(4)
33 #define BT_INFO_8822B_1ANT_B_ACL_BUSY BIT(3)
34 #define BT_INFO_8822B_1ANT_B_INQ_PAGE BIT(2)
35 #define BT_INFO_8822B_1ANT_B_SCO_ESCO BIT(1)
36 #define BT_INFO_8822B_1ANT_B_CONNECTION BIT(0)
38 #define BT_INFO_8822B_1ANT_A2DP_BASIC_RATE(_BT_INFO_EXT_) \
39 (((_BT_INFO_EXT_ & BIT(0))) ? true : false)
41 #define BTC_RSSI_COEX_THRESH_TOL_8822B_1ANT 2
43 #define BT_8822B_1ANT_WIFI_NOISY_THRESH 150 /* max: 255 */
44 #define BT_8822B_1ANT_DEFAULT_ISOLATION 15 /* unit: dB */
46 /* for Antenna detection */
47 #define BT_8822B_1ANT_ANTDET_PSDTHRES_BACKGROUND 50
48 #define BT_8822B_1ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION 70
49 #define BT_8822B_1ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION 55
50 #define BT_8822B_1ANT_ANTDET_PSDTHRES_1ANT 35
51 #define BT_8822B_1ANT_ANTDET_RETRY_INTERVAL \
52 10 /* retry timer if ant det is fail, unit: second */
53 #define BT_8822B_1ANT_ANTDET_ENABLE 0
54 #define BT_8822B_1ANT_ANTDET_COEXMECHANISMSWITCH_ENABLE 0
56 #define BT_8822B_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT 30000
58 enum bt_8822b_1ant_signal_state {
59 BT_8822B_1ANT_SIG_STA_SET_TO_LOW = 0x0,
60 BT_8822B_1ANT_SIG_STA_SET_BY_HW = 0x0,
61 BT_8822B_1ANT_SIG_STA_SET_TO_HIGH = 0x1,
62 BT_8822B_1ANT_SIG_STA_MAX
65 enum bt_8822b_1ant_path_ctrl_owner {
66 BT_8822B_1ANT_PCO_BTSIDE = 0x0,
67 BT_8822B_1ANT_PCO_WLSIDE = 0x1,
71 enum bt_8822b_1ant_gnt_ctrl_type {
72 BT_8822B_1ANT_GNT_CTRL_BY_PTA = 0x0,
73 BT_8822B_1ANT_GNT_CTRL_BY_SW = 0x1,
74 BT_8822B_1ANT_GNT_CTRL_MAX
77 enum bt_8822b_1ant_gnt_ctrl_block {
78 BT_8822B_1ANT_GNT_BLOCK_RFC_BB = 0x0,
79 BT_8822B_1ANT_GNT_BLOCK_RFC = 0x1,
80 BT_8822B_1ANT_GNT_BLOCK_BB = 0x2,
81 BT_8822B_1ANT_GNT_BLOCK_MAX
84 enum bt_8822b_1ant_lte_coex_table_type {
85 BT_8822B_1ANT_CTT_WL_VS_LTE = 0x0,
86 BT_8822B_1ANT_CTT_BT_VS_LTE = 0x1,
90 enum bt_8822b_1ant_lte_break_table_type {
91 BT_8822B_1ANT_LBTT_WL_BREAK_LTE = 0x0,
92 BT_8822B_1ANT_LBTT_BT_BREAK_LTE = 0x1,
93 BT_8822B_1ANT_LBTT_LTE_BREAK_WL = 0x2,
94 BT_8822B_1ANT_LBTT_LTE_BREAK_BT = 0x3,
95 BT_8822B_1ANT_LBTT_MAX
98 enum bt_info_src_8822b_1ant {
99 BT_INFO_SRC_8822B_1ANT_WIFI_FW = 0x0,
100 BT_INFO_SRC_8822B_1ANT_BT_RSP = 0x1,
101 BT_INFO_SRC_8822B_1ANT_BT_ACTIVE_SEND = 0x2,
102 BT_INFO_SRC_8822B_1ANT_MAX
105 enum bt_8822b_1ant_bt_status {
106 BT_8822B_1ANT_BT_STATUS_NON_CONNECTED_IDLE = 0x0,
107 BT_8822B_1ANT_BT_STATUS_CONNECTED_IDLE = 0x1,
108 BT_8822B_1ANT_BT_STATUS_INQ_PAGE = 0x2,
109 BT_8822B_1ANT_BT_STATUS_ACL_BUSY = 0x3,
110 BT_8822B_1ANT_BT_STATUS_SCO_BUSY = 0x4,
111 BT_8822B_1ANT_BT_STATUS_ACL_SCO_BUSY = 0x5,
112 BT_8822B_1ANT_BT_STATUS_MAX
115 enum bt_8822b_1ant_wifi_status {
116 BT_8822B_1ANT_WIFI_STATUS_NON_CONNECTED_IDLE = 0x0,
117 BT_8822B_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN = 0x1,
118 BT_8822B_1ANT_WIFI_STATUS_CONNECTED_SCAN = 0x2,
119 BT_8822B_1ANT_WIFI_STATUS_CONNECTED_SPECIFIC_PKT = 0x3,
120 BT_8822B_1ANT_WIFI_STATUS_CONNECTED_IDLE = 0x4,
121 BT_8822B_1ANT_WIFI_STATUS_CONNECTED_BUSY = 0x5,
122 BT_8822B_1ANT_WIFI_STATUS_MAX
125 enum bt_8822b_1ant_coex_algo {
126 BT_8822B_1ANT_COEX_ALGO_UNDEFINED = 0x0,
127 BT_8822B_1ANT_COEX_ALGO_SCO = 0x1,
128 BT_8822B_1ANT_COEX_ALGO_HID = 0x2,
129 BT_8822B_1ANT_COEX_ALGO_A2DP = 0x3,
130 BT_8822B_1ANT_COEX_ALGO_A2DP_PANHS = 0x4,
131 BT_8822B_1ANT_COEX_ALGO_PANEDR = 0x5,
132 BT_8822B_1ANT_COEX_ALGO_PANHS = 0x6,
133 BT_8822B_1ANT_COEX_ALGO_PANEDR_A2DP = 0x7,
134 BT_8822B_1ANT_COEX_ALGO_PANEDR_HID = 0x8,
135 BT_8822B_1ANT_COEX_ALGO_HID_A2DP_PANEDR = 0x9,
136 BT_8822B_1ANT_COEX_ALGO_HID_A2DP = 0xa,
137 BT_8822B_1ANT_COEX_ALGO_MAX = 0xb,
140 enum bt_8822b_1ant_ext_ant_switch_type {
141 BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SPDT = 0x0,
142 BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SP3T = 0x1,
143 BT_8822B_1ANT_EXT_ANT_SWITCH_MAX
146 enum bt_8822b_1ant_ext_ant_switch_ctrl_type {
147 BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW = 0x0,
148 BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_PTA = 0x1,
149 BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_ANTDIV = 0x2,
150 BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_MAC = 0x3,
151 BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_BT = 0x4,
152 BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_MAX
155 enum bt_8822b_1ant_ext_ant_switch_pos_type {
156 BT_8822B_1ANT_EXT_ANT_SWITCH_TO_BT = 0x0,
157 BT_8822B_1ANT_EXT_ANT_SWITCH_TO_WLG = 0x1,
158 BT_8822B_1ANT_EXT_ANT_SWITCH_TO_WLA = 0x2,
159 BT_8822B_1ANT_EXT_ANT_SWITCH_TO_NOCARE = 0x3,
160 BT_8822B_1ANT_EXT_ANT_SWITCH_TO_MAX
163 enum bt_8822b_1ant_phase {
164 BT_8822B_1ANT_PHASE_COEX_INIT = 0x0,
165 BT_8822B_1ANT_PHASE_WLANONLY_INIT = 0x1,
166 BT_8822B_1ANT_PHASE_WLAN_OFF = 0x2,
167 BT_8822B_1ANT_PHASE_2G_RUNTIME = 0x3,
168 BT_8822B_1ANT_PHASE_5G_RUNTIME = 0x4,
169 BT_8822B_1ANT_PHASE_BTMPMODE = 0x5,
170 BT_8822B_1ANT_PHASE_MAX
173 /*ADD SCOREBOARD TO FIX BT LPS 32K ISSUE WHILE WL BUSY*/
174 enum bt_8822b_1ant_scoreboard {
175 BT_8822B_1ANT_SCOREBOARD_ACTIVE = BIT(0),
176 BT_8822B_1ANT_SCOREBOARD_ONOFF = BIT(1),
177 BT_8822B_1ANT_SCOREBOARD_SCAN = BIT(2),
178 BT_8822B_1ANT_SCOREBOARD_UNDERTEST = BIT(3),
179 BT_8822B_1ANT_SCOREBOARD_WLBUSY = BIT(6)
182 struct coex_dm_8822b_1ant {
184 u32 pre_ant_pos_type;
185 u32 cur_ant_pos_type;
187 bool cur_ignore_wlan_act;
188 bool pre_ignore_wlan_act;
192 u8 ps_tdma_du_adj_type;
193 bool auto_tdma_adjust;
196 bool pre_bt_auto_report;
197 bool cur_bt_auto_report;
204 bool pre_low_penalty_ra;
205 bool cur_low_penalty_ra;
216 u32 backup_arfr_cnt1; /* Auto Rate Fallback Retry cnt */
217 u32 backup_arfr_cnt2; /* Auto Rate Fallback Retry cnt */
218 u16 backup_retry_limit;
219 u8 backup_ampdu_max_time;
221 /* algorithm related */
225 u8 wifi_chnl_info[3];
231 u8 pre_retry_limit_type;
232 u8 cur_retry_limit_type;
233 u8 pre_ampdu_time_type;
234 u8 cur_ampdu_time_type;
237 u32 pre_ext_ant_switch_status;
238 u32 cur_ext_ant_switch_status;
243 struct coex_sta_8822b_1ant {
254 u32 specific_pkt_period_cnt;
255 u32 high_priority_tx;
256 u32 high_priority_rx;
259 bool is_hi_pri_rx_overhead;
261 u8 pre_bt_rssi_state;
262 u8 pre_wifi_rssi_state[4];
263 u8 bt_info_c2h[BT_INFO_SRC_8822B_1ANT_MAX][10];
264 u32 bt_info_c2h_cnt[BT_INFO_SRC_8822B_1ANT_MAX];
266 bool c2h_bt_inquiry_page;
267 bool c2h_bt_remote_name_req;
268 bool c2h_bt_page; /* Add for win8.1 page out issue */
269 bool wifi_is_high_pri_task; /* Add for win8.1 page out issue */
294 bool concurrent_rx_mode_on;
297 u8 isolation_btween_wb; /* 0~ 50 */
302 bool bt_create_connection;
304 u32 bt_coex_supported_feature;
305 u32 bt_coex_supported_version;
308 u32 bt_ble_scan_para[3];
311 bool freeze_coexrun_by_btinfo;
314 bool voice_over_HOGP;
321 u32 cnt_remote_name_req;
324 u32 cnt_ign_wlan_act;
328 u16 bt_reg_vendor_ac;
329 u16 bt_reg_vendor_ae;
335 u8 bt_relink_downcount;
336 bool is_tdma_btautoslot;
337 bool is_tdma_btautoslot_hang;
339 u8 switch_band_notify_to;
340 bool is_rf_state_off;
342 bool is_hid_low_pri_tx_overhead;
343 bool is_bt_multi_link;
344 bool is_bt_a2dp_sink;
347 bool is_set_ps_state_fail;
348 u8 cnt_set_ps_state_fail;
351 struct rfe_type_8822b_1ant {
353 bool ext_ant_switch_exist;
354 u8 ext_ant_switch_type;
355 /* iF 0: ANTSW(rfe_sel9)=0, ANTSWB(rfe_sel8)=1 => Ant to BT/5G */
356 u8 ext_ant_switch_ctrl_polarity;
359 #define BT_8822B_1ANT_ANTDET_PSD_POINTS 256 /* MAX:1024 */
360 #define BT_8822B_1ANT_ANTDET_PSD_AVGNUM 1 /* MAX:3 */
361 #define BT_8822B_1ANT_ANTDET_BUF_LEN 16
363 struct psdscan_sta_8822b_1ant {
364 u32 ant_det_bt_le_channel; /* BT LE Channel ex:2412 */
365 u32 ant_det_bt_tx_time;
366 u32 ant_det_pre_psdscan_peak_val;
367 bool ant_det_is_ant_det_available;
368 u32 ant_det_psd_scan_peak_val;
369 bool ant_det_is_btreply_available;
370 u32 ant_det_psd_scan_peak_freq;
373 u8 ant_det_peak_val[BT_8822B_1ANT_ANTDET_BUF_LEN];
374 u8 ant_det_peak_freq[BT_8822B_1ANT_ANTDET_BUF_LEN];
375 u32 ant_det_try_count;
376 u32 ant_det_fail_count;
377 u32 ant_det_inteval_count;
378 u32 ant_det_thres_offset;
384 u32 psd_band_width; /* unit: Hz */
385 u32 psd_point; /* 128/256/512/1024 */
386 u32 psd_report[1024]; /* unit:dB (20logx), 0~255 */
387 u32 psd_report_max_hold[1024]; /* unit:dB (20logx), 0~255 */
390 u32 psd_max_value_point;
393 u32 psd_avg_num; /* 1/8/16/32 */
396 bool is_psd_show_max_only;
397 bool is_ant_det_running;
400 /* *******************************************
401 * The following is interface which will notify coex module.
402 * ********************************************/
403 void ex_btc8822b1ant_power_on_setting(struct btc_coexist *btcoexist);
404 void ex_btc8822b1ant_pre_load_firmware(struct btc_coexist *btcoexist);
405 void ex_btc8822b1ant_init_hw_config(struct btc_coexist *btcoexist,
407 void ex_btc8822b1ant_init_coex_dm(struct btc_coexist *btcoexist);
408 void ex_btc8822b1ant_ips_notify(struct btc_coexist *btcoexist, u8 type);
409 void ex_btc8822b1ant_lps_notify(struct btc_coexist *btcoexist, u8 type);
410 void ex_btc8822b1ant_scan_notify(struct btc_coexist *btcoexist, u8 type);
411 void ex_btc8822b1ant_scan_notify_without_bt(struct btc_coexist *btcoexist,
413 void ex_btc8822b1ant_switchband_notify(struct btc_coexist *btcoexist, u8 type);
414 void ex_btc8822b1ant_switchband_notify_without_bt(struct btc_coexist *btcoexist,
416 void ex_btc8822b1ant_connect_notify(struct btc_coexist *btcoexist, u8 type);
417 void ex_btc8822b1ant_media_status_notify(struct btc_coexist *btcoexist,
419 void ex_btc8822b1ant_specific_packet_notify(struct btc_coexist *btcoexist,
421 void ex_btc8822b1ant_bt_info_notify(struct btc_coexist *btcoexist, u8 *tmp_buf,
423 void ex_btc8822b1ant_rf_status_notify(struct btc_coexist *btcoexist, u8 type);
424 void ex_btc8822b1ant_halt_notify(struct btc_coexist *btcoexist);
425 void ex_btc8822b1ant_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state);
426 void ex_halbtc8822b1ant_score_board_status_notify(struct btc_coexist *btcoexist,
427 u8 *tmp_buf, u8 length);
428 void ex_btc8822b1ant_coex_dm_reset(struct btc_coexist *btcoexist);
429 void ex_btc8822b1ant_periodical(struct btc_coexist *btcoexist);
430 void ex_btc8822b1ant_display_coex_info(struct btc_coexist *btcoexist,
432 void ex_btc8822b1ant_antenna_detection(struct btc_coexist *btcoexist,
433 u32 cent_freq, u32 offset, u32 span,
435 void ex_btc8822b1ant_antenna_isolation(struct btc_coexist *btcoexist,
436 u32 cent_freq, u32 offset, u32 span,
439 void ex_btc8822b1ant_psd_scan(struct btc_coexist *btcoexist, u32 cent_freq,
440 u32 offset, u32 span, u32 seconds);
441 void ex_btc8822b1ant_display_ant_detection(struct btc_coexist *btcoexist);
443 void ex_btc8822b1ant_dbg_control(struct btc_coexist *btcoexist, u8 op_code,
444 u8 op_len, u8 *pdata);