1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /****************************************************************************** 3 * 4 * Copyright(c) 2016 Realtek Corporation. 5 * 6 * Contact Information: 7 * wlanfae <wlanfae@realtek.com> 8 * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, 9 * Hsinchu 300, Taiwan. 10 * 11 * Larry Finger <Larry.Finger@lwfinger.net> 12 * 13 *****************************************************************************/ 14 15 /* ******************************************* 16 * The following is for 8822B 1ANT BT Co-exist definition 17 * ********************************************/ 18 #define BT_INFO_8822B_1ANT_B_FTP BIT(7) 19 #define BT_INFO_8822B_1ANT_B_A2DP BIT(6) 20 #define BT_INFO_8822B_1ANT_B_HID BIT(5) 21 #define BT_INFO_8822B_1ANT_B_SCO_BUSY BIT(4) 22 #define BT_INFO_8822B_1ANT_B_ACL_BUSY BIT(3) 23 #define BT_INFO_8822B_1ANT_B_INQ_PAGE BIT(2) 24 #define BT_INFO_8822B_1ANT_B_SCO_ESCO BIT(1) 25 #define BT_INFO_8822B_1ANT_B_CONNECTION BIT(0) 26 27 #define BT_INFO_8822B_1ANT_A2DP_BASIC_RATE(_BT_INFO_EXT_) \ 28 (((_BT_INFO_EXT_ & BIT(0))) ? true : false) 29 30 #define BTC_RSSI_COEX_THRESH_TOL_8822B_1ANT 2 31 32 #define BT_8822B_1ANT_WIFI_NOISY_THRESH 150 /* max: 255 */ 33 #define BT_8822B_1ANT_DEFAULT_ISOLATION 15 /* unit: dB */ 34 35 /* for Antenna detection */ 36 #define BT_8822B_1ANT_ANTDET_PSDTHRES_BACKGROUND 50 37 #define BT_8822B_1ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION 70 38 #define BT_8822B_1ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION 55 39 #define BT_8822B_1ANT_ANTDET_PSDTHRES_1ANT 35 40 #define BT_8822B_1ANT_ANTDET_RETRY_INTERVAL \ 41 10 /* retry timer if ant det is fail, unit: second */ 42 #define BT_8822B_1ANT_ANTDET_ENABLE 0 43 #define BT_8822B_1ANT_ANTDET_COEXMECHANISMSWITCH_ENABLE 0 44 45 #define BT_8822B_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT 30000 46 47 enum bt_8822b_1ant_signal_state { 48 BT_8822B_1ANT_SIG_STA_SET_TO_LOW = 0x0, 49 BT_8822B_1ANT_SIG_STA_SET_BY_HW = 0x0, 50 BT_8822B_1ANT_SIG_STA_SET_TO_HIGH = 0x1, 51 BT_8822B_1ANT_SIG_STA_MAX 52 }; 53 54 enum bt_8822b_1ant_path_ctrl_owner { 55 BT_8822B_1ANT_PCO_BTSIDE = 0x0, 56 BT_8822B_1ANT_PCO_WLSIDE = 0x1, 57 BT_8822B_1ANT_PCO_MAX 58 }; 59 60 enum bt_8822b_1ant_gnt_ctrl_type { 61 BT_8822B_1ANT_GNT_CTRL_BY_PTA = 0x0, 62 BT_8822B_1ANT_GNT_CTRL_BY_SW = 0x1, 63 BT_8822B_1ANT_GNT_CTRL_MAX 64 }; 65 66 enum bt_8822b_1ant_gnt_ctrl_block { 67 BT_8822B_1ANT_GNT_BLOCK_RFC_BB = 0x0, 68 BT_8822B_1ANT_GNT_BLOCK_RFC = 0x1, 69 BT_8822B_1ANT_GNT_BLOCK_BB = 0x2, 70 BT_8822B_1ANT_GNT_BLOCK_MAX 71 }; 72 73 enum bt_8822b_1ant_lte_coex_table_type { 74 BT_8822B_1ANT_CTT_WL_VS_LTE = 0x0, 75 BT_8822B_1ANT_CTT_BT_VS_LTE = 0x1, 76 BT_8822B_1ANT_CTT_MAX 77 }; 78 79 enum bt_8822b_1ant_lte_break_table_type { 80 BT_8822B_1ANT_LBTT_WL_BREAK_LTE = 0x0, 81 BT_8822B_1ANT_LBTT_BT_BREAK_LTE = 0x1, 82 BT_8822B_1ANT_LBTT_LTE_BREAK_WL = 0x2, 83 BT_8822B_1ANT_LBTT_LTE_BREAK_BT = 0x3, 84 BT_8822B_1ANT_LBTT_MAX 85 }; 86 87 enum bt_info_src_8822b_1ant { 88 BT_INFO_SRC_8822B_1ANT_WIFI_FW = 0x0, 89 BT_INFO_SRC_8822B_1ANT_BT_RSP = 0x1, 90 BT_INFO_SRC_8822B_1ANT_BT_ACTIVE_SEND = 0x2, 91 BT_INFO_SRC_8822B_1ANT_MAX 92 }; 93 94 enum bt_8822b_1ant_bt_status { 95 BT_8822B_1ANT_BT_STATUS_NON_CONNECTED_IDLE = 0x0, 96 BT_8822B_1ANT_BT_STATUS_CONNECTED_IDLE = 0x1, 97 BT_8822B_1ANT_BT_STATUS_INQ_PAGE = 0x2, 98 BT_8822B_1ANT_BT_STATUS_ACL_BUSY = 0x3, 99 BT_8822B_1ANT_BT_STATUS_SCO_BUSY = 0x4, 100 BT_8822B_1ANT_BT_STATUS_ACL_SCO_BUSY = 0x5, 101 BT_8822B_1ANT_BT_STATUS_MAX 102 }; 103 104 enum bt_8822b_1ant_wifi_status { 105 BT_8822B_1ANT_WIFI_STATUS_NON_CONNECTED_IDLE = 0x0, 106 BT_8822B_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN = 0x1, 107 BT_8822B_1ANT_WIFI_STATUS_CONNECTED_SCAN = 0x2, 108 BT_8822B_1ANT_WIFI_STATUS_CONNECTED_SPECIFIC_PKT = 0x3, 109 BT_8822B_1ANT_WIFI_STATUS_CONNECTED_IDLE = 0x4, 110 BT_8822B_1ANT_WIFI_STATUS_CONNECTED_BUSY = 0x5, 111 BT_8822B_1ANT_WIFI_STATUS_MAX 112 }; 113 114 enum bt_8822b_1ant_coex_algo { 115 BT_8822B_1ANT_COEX_ALGO_UNDEFINED = 0x0, 116 BT_8822B_1ANT_COEX_ALGO_SCO = 0x1, 117 BT_8822B_1ANT_COEX_ALGO_HID = 0x2, 118 BT_8822B_1ANT_COEX_ALGO_A2DP = 0x3, 119 BT_8822B_1ANT_COEX_ALGO_A2DP_PANHS = 0x4, 120 BT_8822B_1ANT_COEX_ALGO_PANEDR = 0x5, 121 BT_8822B_1ANT_COEX_ALGO_PANHS = 0x6, 122 BT_8822B_1ANT_COEX_ALGO_PANEDR_A2DP = 0x7, 123 BT_8822B_1ANT_COEX_ALGO_PANEDR_HID = 0x8, 124 BT_8822B_1ANT_COEX_ALGO_HID_A2DP_PANEDR = 0x9, 125 BT_8822B_1ANT_COEX_ALGO_HID_A2DP = 0xa, 126 BT_8822B_1ANT_COEX_ALGO_MAX = 0xb, 127 }; 128 129 enum bt_8822b_1ant_ext_ant_switch_type { 130 BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SPDT = 0x0, 131 BT_8822B_1ANT_EXT_ANT_SWITCH_USE_SP3T = 0x1, 132 BT_8822B_1ANT_EXT_ANT_SWITCH_MAX 133 }; 134 135 enum bt_8822b_1ant_ext_ant_switch_ctrl_type { 136 BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_BBSW = 0x0, 137 BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_PTA = 0x1, 138 BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_ANTDIV = 0x2, 139 BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_MAC = 0x3, 140 BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_BY_BT = 0x4, 141 BT_8822B_1ANT_EXT_ANT_SWITCH_CTRL_MAX 142 }; 143 144 enum bt_8822b_1ant_ext_ant_switch_pos_type { 145 BT_8822B_1ANT_EXT_ANT_SWITCH_TO_BT = 0x0, 146 BT_8822B_1ANT_EXT_ANT_SWITCH_TO_WLG = 0x1, 147 BT_8822B_1ANT_EXT_ANT_SWITCH_TO_WLA = 0x2, 148 BT_8822B_1ANT_EXT_ANT_SWITCH_TO_NOCARE = 0x3, 149 BT_8822B_1ANT_EXT_ANT_SWITCH_TO_MAX 150 }; 151 152 enum bt_8822b_1ant_phase { 153 BT_8822B_1ANT_PHASE_COEX_INIT = 0x0, 154 BT_8822B_1ANT_PHASE_WLANONLY_INIT = 0x1, 155 BT_8822B_1ANT_PHASE_WLAN_OFF = 0x2, 156 BT_8822B_1ANT_PHASE_2G_RUNTIME = 0x3, 157 BT_8822B_1ANT_PHASE_5G_RUNTIME = 0x4, 158 BT_8822B_1ANT_PHASE_BTMPMODE = 0x5, 159 BT_8822B_1ANT_PHASE_MAX 160 }; 161 162 /*ADD SCOREBOARD TO FIX BT LPS 32K ISSUE WHILE WL BUSY*/ 163 enum bt_8822b_1ant_scoreboard { 164 BT_8822B_1ANT_SCOREBOARD_ACTIVE = BIT(0), 165 BT_8822B_1ANT_SCOREBOARD_ONOFF = BIT(1), 166 BT_8822B_1ANT_SCOREBOARD_SCAN = BIT(2), 167 BT_8822B_1ANT_SCOREBOARD_UNDERTEST = BIT(3), 168 BT_8822B_1ANT_SCOREBOARD_WLBUSY = BIT(6) 169 }; 170 171 struct coex_dm_8822b_1ant { 172 /* hw setting */ 173 u32 pre_ant_pos_type; 174 u32 cur_ant_pos_type; 175 /* fw mechanism */ 176 bool cur_ignore_wlan_act; 177 bool pre_ignore_wlan_act; 178 u8 pre_ps_tdma; 179 u8 cur_ps_tdma; 180 u8 ps_tdma_para[5]; 181 u8 ps_tdma_du_adj_type; 182 bool auto_tdma_adjust; 183 bool pre_ps_tdma_on; 184 bool cur_ps_tdma_on; 185 bool pre_bt_auto_report; 186 bool cur_bt_auto_report; 187 u8 pre_lps; 188 u8 cur_lps; 189 u8 pre_rpwm; 190 u8 cur_rpwm; 191 192 /* sw mechanism */ 193 bool pre_low_penalty_ra; 194 bool cur_low_penalty_ra; 195 u32 pre_val0x6c0; 196 u32 cur_val0x6c0; 197 u32 pre_val0x6c4; 198 u32 cur_val0x6c4; 199 u32 pre_val0x6c8; 200 u32 cur_val0x6c8; 201 u8 pre_val0x6cc; 202 u8 cur_val0x6cc; 203 bool limited_dig; 204 205 u32 backup_arfr_cnt1; /* Auto Rate Fallback Retry cnt */ 206 u32 backup_arfr_cnt2; /* Auto Rate Fallback Retry cnt */ 207 u16 backup_retry_limit; 208 u8 backup_ampdu_max_time; 209 210 /* algorithm related */ 211 u8 pre_algorithm; 212 u8 cur_algorithm; 213 u8 bt_status; 214 u8 wifi_chnl_info[3]; 215 216 u32 pre_ra_mask; 217 u32 cur_ra_mask; 218 u8 pre_arfr_type; 219 u8 cur_arfr_type; 220 u8 pre_retry_limit_type; 221 u8 cur_retry_limit_type; 222 u8 pre_ampdu_time_type; 223 u8 cur_ampdu_time_type; 224 u32 arp_cnt; 225 226 u32 pre_ext_ant_switch_status; 227 u32 cur_ext_ant_switch_status; 228 229 u8 error_condition; 230 }; 231 232 struct coex_sta_8822b_1ant { 233 bool bt_disabled; 234 bool bt_link_exist; 235 bool sco_exist; 236 bool a2dp_exist; 237 bool hid_exist; 238 bool pan_exist; 239 u8 num_of_profile; 240 241 bool under_lps; 242 bool under_ips; 243 u32 specific_pkt_period_cnt; 244 u32 high_priority_tx; 245 u32 high_priority_rx; 246 u32 low_priority_tx; 247 u32 low_priority_rx; 248 bool is_hi_pri_rx_overhead; 249 s8 bt_rssi; 250 u8 pre_bt_rssi_state; 251 u8 pre_wifi_rssi_state[4]; 252 u8 bt_info_c2h[BT_INFO_SRC_8822B_1ANT_MAX][10]; 253 u32 bt_info_c2h_cnt[BT_INFO_SRC_8822B_1ANT_MAX]; 254 bool bt_whck_test; 255 bool c2h_bt_inquiry_page; 256 bool c2h_bt_remote_name_req; 257 bool c2h_bt_page; /* Add for win8.1 page out issue */ 258 bool wifi_is_high_pri_task; /* Add for win8.1 page out issue */ 259 260 u8 bt_info_ext; 261 u8 bt_info_ext2; 262 u32 pop_event_cnt; 263 u8 scan_ap_num; 264 u8 bt_retry_cnt; 265 266 u32 crc_ok_cck; 267 u32 crc_ok_11g; 268 u32 crc_ok_11n; 269 u32 crc_ok_11n_vht; 270 271 u32 crc_err_cck; 272 u32 crc_err_11g; 273 u32 crc_err_11n; 274 u32 crc_err_11n_vht; 275 276 bool cck_lock; 277 bool pre_ccklock; 278 bool cck_ever_lock; 279 u8 coex_table_type; 280 281 bool force_lps_ctrl; 282 283 bool concurrent_rx_mode_on; 284 285 u16 score_board; 286 u8 isolation_btween_wb; /* 0~ 50 */ 287 288 u8 a2dp_bit_pool; 289 u8 cut_version; 290 bool acl_busy; 291 bool bt_create_connection; 292 293 u32 bt_coex_supported_feature; 294 u32 bt_coex_supported_version; 295 296 u8 bt_ble_scan_type; 297 u32 bt_ble_scan_para[3]; 298 299 bool run_time_state; 300 bool freeze_coexrun_by_btinfo; 301 302 bool is_A2DP_3M; 303 bool voice_over_HOGP; 304 u8 bt_info; 305 bool is_autoslot; 306 u8 forbidden_slot; 307 u8 hid_busy_num; 308 u8 hid_pair_cnt; 309 310 u32 cnt_remote_name_req; 311 u32 cnt_setup_link; 312 u32 cnt_reinit; 313 u32 cnt_ign_wlan_act; 314 u32 cnt_page; 315 u32 cnt_role_switch; 316 317 u16 bt_reg_vendor_ac; 318 u16 bt_reg_vendor_ae; 319 320 bool is_setup_link; 321 u8 wl_noisy_level; 322 u32 gnt_error_cnt; 323 u8 bt_afh_map[10]; 324 u8 bt_relink_downcount; 325 bool is_tdma_btautoslot; 326 bool is_tdma_btautoslot_hang; 327 328 u8 switch_band_notify_to; 329 bool is_rf_state_off; 330 331 bool is_hid_low_pri_tx_overhead; 332 bool is_bt_multi_link; 333 bool is_bt_a2dp_sink; 334 bool rf4ce_enabled; 335 336 bool is_set_ps_state_fail; 337 u8 cnt_set_ps_state_fail; 338 }; 339 340 struct rfe_type_8822b_1ant { 341 u8 rfe_module_type; 342 bool ext_ant_switch_exist; 343 u8 ext_ant_switch_type; 344 /* iF 0: ANTSW(rfe_sel9)=0, ANTSWB(rfe_sel8)=1 => Ant to BT/5G */ 345 u8 ext_ant_switch_ctrl_polarity; 346 }; 347 348 #define BT_8822B_1ANT_ANTDET_PSD_POINTS 256 /* MAX:1024 */ 349 #define BT_8822B_1ANT_ANTDET_PSD_AVGNUM 1 /* MAX:3 */ 350 #define BT_8822B_1ANT_ANTDET_BUF_LEN 16 351 352 struct psdscan_sta_8822b_1ant { 353 u32 ant_det_bt_le_channel; /* BT LE Channel ex:2412 */ 354 u32 ant_det_bt_tx_time; 355 u32 ant_det_pre_psdscan_peak_val; 356 bool ant_det_is_ant_det_available; 357 u32 ant_det_psd_scan_peak_val; 358 bool ant_det_is_btreply_available; 359 u32 ant_det_psd_scan_peak_freq; 360 361 u8 ant_det_result; 362 u8 ant_det_peak_val[BT_8822B_1ANT_ANTDET_BUF_LEN]; 363 u8 ant_det_peak_freq[BT_8822B_1ANT_ANTDET_BUF_LEN]; 364 u32 ant_det_try_count; 365 u32 ant_det_fail_count; 366 u32 ant_det_inteval_count; 367 u32 ant_det_thres_offset; 368 369 u32 real_cent_freq; 370 s32 real_offset; 371 u32 real_span; 372 373 u32 psd_band_width; /* unit: Hz */ 374 u32 psd_point; /* 128/256/512/1024 */ 375 u32 psd_report[1024]; /* unit:dB (20logx), 0~255 */ 376 u32 psd_report_max_hold[1024]; /* unit:dB (20logx), 0~255 */ 377 u32 psd_start_point; 378 u32 psd_stop_point; 379 u32 psd_max_value_point; 380 u32 psd_max_value; 381 u32 psd_start_base; 382 u32 psd_avg_num; /* 1/8/16/32 */ 383 u32 psd_gen_count; 384 bool is_psd_running; 385 bool is_psd_show_max_only; 386 bool is_ant_det_running; 387 }; 388 389 /* ******************************************* 390 * The following is interface which will notify coex module. 391 * ********************************************/ 392 void ex_btc8822b1ant_power_on_setting(struct btc_coexist *btcoexist); 393 void ex_btc8822b1ant_pre_load_firmware(struct btc_coexist *btcoexist); 394 void ex_btc8822b1ant_init_hw_config(struct btc_coexist *btcoexist, 395 bool wifi_only); 396 void ex_btc8822b1ant_init_coex_dm(struct btc_coexist *btcoexist); 397 void ex_btc8822b1ant_ips_notify(struct btc_coexist *btcoexist, u8 type); 398 void ex_btc8822b1ant_lps_notify(struct btc_coexist *btcoexist, u8 type); 399 void ex_btc8822b1ant_scan_notify(struct btc_coexist *btcoexist, u8 type); 400 void ex_btc8822b1ant_scan_notify_without_bt(struct btc_coexist *btcoexist, 401 u8 type); 402 void ex_btc8822b1ant_switchband_notify(struct btc_coexist *btcoexist, u8 type); 403 void ex_btc8822b1ant_switchband_notify_without_bt(struct btc_coexist *btcoexist, 404 u8 type); 405 void ex_btc8822b1ant_connect_notify(struct btc_coexist *btcoexist, u8 type); 406 void ex_btc8822b1ant_media_status_notify(struct btc_coexist *btcoexist, 407 u8 type); 408 void ex_btc8822b1ant_specific_packet_notify(struct btc_coexist *btcoexist, 409 u8 type); 410 void ex_btc8822b1ant_bt_info_notify(struct btc_coexist *btcoexist, u8 *tmp_buf, 411 u8 length); 412 void ex_btc8822b1ant_rf_status_notify(struct btc_coexist *btcoexist, u8 type); 413 void ex_btc8822b1ant_halt_notify(struct btc_coexist *btcoexist); 414 void ex_btc8822b1ant_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state); 415 void ex_halbtc8822b1ant_score_board_status_notify(struct btc_coexist *btcoexist, 416 u8 *tmp_buf, u8 length); 417 void ex_btc8822b1ant_coex_dm_reset(struct btc_coexist *btcoexist); 418 void ex_btc8822b1ant_periodical(struct btc_coexist *btcoexist); 419 void ex_btc8822b1ant_display_coex_info(struct btc_coexist *btcoexist, 420 struct seq_file *m); 421 void ex_btc8822b1ant_antenna_detection(struct btc_coexist *btcoexist, 422 u32 cent_freq, u32 offset, u32 span, 423 u32 seconds); 424 void ex_btc8822b1ant_antenna_isolation(struct btc_coexist *btcoexist, 425 u32 cent_freq, u32 offset, u32 span, 426 u32 seconds); 427 428 void ex_btc8822b1ant_psd_scan(struct btc_coexist *btcoexist, u32 cent_freq, 429 u32 offset, u32 span, u32 seconds); 430 void ex_btc8822b1ant_display_ant_detection(struct btc_coexist *btcoexist); 431 432 void ex_btc8822b1ant_dbg_control(struct btc_coexist *btcoexist, u8 op_code, 433 u8 op_len, u8 *pdata); 434