1 /****************************************************************************** 2 * 3 * Copyright(c) 2016 - 2017 Realtek Corporation. 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 *****************************************************************************/ 15 16 17 #if (BT_SUPPORT == 1 && COEX_SUPPORT == 1) 18 19 #if (RTL8723D_SUPPORT == 1) 20 21 /* ******************************************* 22 * The following is for 8723D 1ANT BT Co-exist definition 23 * ******************************************* */ 24 #define BT_8723D_1ANT_COEX_DBG 0 25 #define BT_AUTO_REPORT_ONLY_8723D_1ANT 1 26 27 #define BT_INFO_8723D_1ANT_B_FTP BIT(7) 28 #define BT_INFO_8723D_1ANT_B_A2DP BIT(6) 29 #define BT_INFO_8723D_1ANT_B_HID BIT(5) 30 #define BT_INFO_8723D_1ANT_B_SCO_BUSY BIT(4) 31 #define BT_INFO_8723D_1ANT_B_ACL_BUSY BIT(3) 32 #define BT_INFO_8723D_1ANT_B_INQ_PAGE BIT(2) 33 #define BT_INFO_8723D_1ANT_B_SCO_ESCO BIT(1) 34 #define BT_INFO_8723D_1ANT_B_CONNECTION BIT(0) 35 36 #define BT_INFO_8723D_1ANT_A2DP_BASIC_RATE(_BT_INFO_EXT_) \ 37 (((_BT_INFO_EXT_&BIT(0))) ? TRUE : FALSE) 38 39 #define BTC_RSSI_COEX_THRESH_TOL_8723D_1ANT 2 40 41 #define BT_8723D_1ANT_WIFI_NOISY_THRESH 30 /*max: 255*/ 42 #define BT_8723D_1ANT_DEFAULT_ISOLATION 15 /*unit: dB*/ 43 44 45 /* for Antenna detection */ 46 #define BT_8723D_1ANT_ANTDET_PSDTHRES_BACKGROUND 50 47 #define BT_8723D_1ANT_ANTDET_PSDTHRES_2ANT_BADISOLATION 70 48 #define BT_8723D_1ANT_ANTDET_PSDTHRES_2ANT_GOODISOLATION 55 49 #define BT_8723D_1ANT_ANTDET_PSDTHRES_1ANT 35 50 #define BT_8723D_1ANT_ANTDET_RETRY_INTERVAL 10 51 #define BT_8723D_1ANT_ANTDET_SWEEPPOINT_DELAY 60000 52 #define BT_8723D_1ANT_ANTDET_ENABLE 0 53 #define BT_8723D_1ANT_ANTDET_BTTXTIME 100 54 #define BT_8723D_1ANT_ANTDET_BTTXCHANNEL 39 55 #define BT_8723D_1ANT_ANTDET_PSD_SWWEEPCOUNT 50 56 57 #define BT_8723D_1ANT_LTECOEX_INDIRECTREG_ACCESS_TIMEOUT 30000 58 59 enum bt_8723d_1ant_signal_state { 60 BT_8723D_1ANT_SIG_STA_SET_TO_LOW = 0x0, 61 BT_8723D_1ANT_SIG_STA_SET_BY_HW = 0x0, 62 BT_8723D_1ANT_SIG_STA_SET_TO_HIGH = 0x1, 63 BT_8723D_1ANT_SIG_STA_MAX 64 }; 65 66 enum bt_8723d_1ant_path_ctrl_owner { 67 BT_8723D_1ANT_PCO_BTSIDE = 0x0, 68 BT_8723D_1ANT_PCO_WLSIDE = 0x1, 69 BT_8723D_1ANT_PCO_MAX 70 }; 71 72 enum bt_8723d_1ant_gnt_ctrl_type { 73 BT_8723D_1ANT_GNT_TYPE_CTRL_BY_PTA = 0x0, 74 BT_8723D_1ANT_GNT_TYPE_CTRL_BY_SW = 0x1, 75 BT_8723D_1ANT_GNT_TYPE_MAX 76 }; 77 78 enum bt_8723d_1ant_gnt_ctrl_block { 79 BT_8723D_1ANT_GNT_BLOCK_RFC_BB = 0x0, 80 BT_8723D_1ANT_GNT_BLOCK_RFC = 0x1, 81 BT_8723D_1ANT_GNT_BLOCK_BB = 0x2, 82 BT_8723D_1ANT_GNT_BLOCK_MAX 83 }; 84 85 enum bt_8723d_1ant_lte_coex_table_type { 86 BT_8723D_1ANT_CTT_WL_VS_LTE = 0x0, 87 BT_8723D_1ANT_CTT_BT_VS_LTE = 0x1, 88 BT_8723D_1ANT_CTT_MAX 89 }; 90 91 enum bt_8723d_1ant_lte_break_table_type { 92 BT_8723D_1ANT_LBTT_WL_BREAK_LTE = 0x0, 93 BT_8723D_1ANT_LBTT_BT_BREAK_LTE = 0x1, 94 BT_8723D_1ANT_LBTT_LTE_BREAK_WL = 0x2, 95 BT_8723D_1ANT_LBTT_LTE_BREAK_BT = 0x3, 96 BT_8723D_1ANT_LBTT_MAX 97 }; 98 99 enum bt_info_src_8723d_1ant { 100 BT_INFO_SRC_8723D_1ANT_WIFI_FW = 0x0, 101 BT_INFO_SRC_8723D_1ANT_BT_RSP = 0x1, 102 BT_INFO_SRC_8723D_1ANT_BT_ACTIVE_SEND = 0x2, 103 BT_INFO_SRC_8723D_1ANT_MAX 104 }; 105 106 enum bt_8723d_1ant_bt_status { 107 BT_8723D_1ANT_BT_STATUS_NON_CONNECTED_IDLE = 0x0, 108 BT_8723D_1ANT_BT_STATUS_CONNECTED_IDLE = 0x1, 109 BT_8723D_1ANT_BT_STATUS_INQ_PAGE = 0x2, 110 BT_8723D_1ANT_BT_STATUS_ACL_BUSY = 0x3, 111 BT_8723D_1ANT_BT_STATUS_SCO_BUSY = 0x4, 112 BT_8723D_1ANT_BT_STATUS_ACL_SCO_BUSY = 0x5, 113 BT_8723D_1ANT_BT_STATUS_MAX 114 }; 115 116 enum bt_8723d_1ant_wifi_status { 117 BT_8723D_1ANT_WIFI_STATUS_NON_CONNECTED_IDLE = 0x0, 118 BT_8723D_1ANT_WIFI_STATUS_NON_CONNECTED_ASSO_AUTH_SCAN = 0x1, 119 BT_8723D_1ANT_WIFI_STATUS_CONNECTED_SCAN = 0x2, 120 BT_8723D_1ANT_WIFI_STATUS_CONNECTED_SPECIFIC_PKT = 0x3, 121 BT_8723D_1ANT_WIFI_STATUS_CONNECTED_IDLE = 0x4, 122 BT_8723D_1ANT_WIFI_STATUS_CONNECTED_BUSY = 0x5, 123 BT_8723D_1ANT_WIFI_STATUS_MAX 124 }; 125 126 enum bt_8723d_1ant_coex_algo { 127 BT_8723D_1ANT_COEX_ALGO_UNDEFINED = 0x0, 128 BT_8723D_1ANT_COEX_ALGO_SCO = 0x1, 129 BT_8723D_1ANT_COEX_ALGO_HID = 0x2, 130 BT_8723D_1ANT_COEX_ALGO_A2DP = 0x3, 131 BT_8723D_1ANT_COEX_ALGO_A2DP_PANHS = 0x4, 132 BT_8723D_1ANT_COEX_ALGO_PANEDR = 0x5, 133 BT_8723D_1ANT_COEX_ALGO_PANHS = 0x6, 134 BT_8723D_1ANT_COEX_ALGO_PANEDR_A2DP = 0x7, 135 BT_8723D_1ANT_COEX_ALGO_PANEDR_HID = 0x8, 136 BT_8723D_1ANT_COEX_ALGO_HID_A2DP_PANEDR = 0x9, 137 BT_8723D_1ANT_COEX_ALGO_HID_A2DP = 0xa, 138 BT_8723D_1ANT_COEX_ALGO_MAX = 0xb, 139 }; 140 141 enum bt_8723d_1ant_phase { 142 BT_8723D_1ANT_PHASE_COEX_INIT = 0x0, 143 BT_8723D_1ANT_PHASE_WLANONLY_INIT = 0x1, 144 BT_8723D_1ANT_PHASE_WLAN_OFF = 0x2, 145 BT_8723D_1ANT_PHASE_2G_RUNTIME = 0x3, 146 BT_8723D_1ANT_PHASE_5G_RUNTIME = 0x4, 147 BT_8723D_1ANT_PHASE_BTMPMODE = 0x5, 148 BT_8723D_1ANT_PHASE_ANTENNA_DET = 0x6, 149 BT_8723D_1ANT_PHASE_COEX_POWERON = 0x7, 150 BT_8723D_1ANT_PHASE_MAX 151 }; 152 153 enum bt_8723d_1ant_Scoreboard { 154 BT_8723D_1ANT_SCOREBOARD_ACTIVE = BIT(0), 155 BT_8723D_1ANT_SCOREBOARD_ONOFF = BIT(1), 156 BT_8723D_1ANT_SCOREBOARD_SCAN = BIT(2), 157 BT_8723D_1ANT_SCOREBOARD_UNDERTEST = BIT(3), 158 BT_8723D_1ANT_SCOREBOARD_RXGAIN = BIT(4), 159 BT_8723D_1ANT_SCOREBOARD_DKTOPP2M = BIT(5), 160 BT_8723D_1ANT_SCOREBOARD_WLBUSY = BIT(6), 161 BT_8723D_1ANT_SCOREBOARD_TDMA = BIT(9), 162 }; 163 164 struct coex_dm_8723d_1ant { 165 /* hw setting */ 166 u8 pre_ant_pos_type; 167 u8 cur_ant_pos_type; 168 /* fw mechanism */ 169 boolean cur_ignore_wlan_act; 170 boolean pre_ignore_wlan_act; 171 u8 cur_ps_tdma; 172 u8 ps_tdma_para[5]; 173 u8 ps_tdma_du_adj_type; 174 boolean cur_ps_tdma_on; 175 boolean pre_bt_auto_report; 176 boolean cur_bt_auto_report; 177 u8 pre_lps; 178 u8 cur_lps; 179 u8 pre_rpwm; 180 u8 cur_rpwm; 181 182 /* sw mechanism */ 183 boolean pre_low_penalty_ra; 184 boolean cur_low_penalty_ra; 185 u32 cur_val0x6c0; 186 u32 cur_val0x6c4; 187 u32 cur_val0x6c8; 188 u8 cur_val0x6cc; 189 boolean limited_dig; 190 191 u32 backup_arfr_cnt1; 192 u32 backup_arfr_cnt2; 193 u16 backup_retry_limit; 194 u8 backup_ampdu_max_time; 195 196 /* algorithm related */ 197 u8 pre_algorithm; 198 u8 cur_algorithm; 199 u8 bt_status; 200 u8 wifi_chnl_info[3]; 201 202 u32 pre_ra_mask; 203 u32 cur_ra_mask; 204 u8 pre_arfr_type; 205 u8 cur_arfr_type; 206 u8 pre_retry_limit_type; 207 u8 cur_retry_limit_type; 208 u8 pre_ampdu_time_type; 209 u8 cur_ampdu_time_type; 210 u32 arp_cnt; 211 212 u8 error_condition; 213 u32 setting_tdma; 214 }; 215 216 struct coex_sta_8723d_1ant { 217 boolean bt_disabled; 218 boolean bt_link_exist; 219 boolean sco_exist; 220 boolean a2dp_exist; 221 boolean hid_exist; 222 boolean pan_exist; 223 boolean bt_hi_pri_link_exist; 224 u8 num_of_profile; 225 226 boolean under_lps; 227 boolean under_ips; 228 u32 specific_pkt_period_cnt; 229 u8 connect_ap_period_cnt; 230 u8 pnp_awake_period_cnt; 231 u32 high_priority_tx; 232 u32 high_priority_rx; 233 u32 low_priority_tx; 234 u32 low_priority_rx; 235 boolean bt_ctr_ok; 236 boolean is_hipri_rx_overhead; 237 s8 bt_rssi; 238 boolean bt_tx_rx_mask; 239 boolean bt_mesh_on; 240 u8 pre_bt_rssi_state; 241 u8 pre_wifi_rssi_state[4]; 242 u8 bt_info_c2h[BT_INFO_SRC_8723D_1ANT_MAX][10]; 243 u32 bt_info_c2h_cnt[BT_INFO_SRC_8723D_1ANT_MAX]; 244 boolean bt_whck_test; 245 boolean c2h_bt_inquiry_page; 246 boolean bt_inq_page_pre; 247 boolean bt_inq_page_remain; 248 boolean c2h_bt_remote_name_req; 249 boolean c2h_bt_page; 250 boolean wifi_is_high_pri_task; 251 boolean wifi_in_scan_task; 252 u8 bt_retry_cnt; 253 u8 bt_info_ext; 254 u8 bt_info_ext2; 255 u32 pop_event_cnt; 256 u8 scan_ap_num; 257 258 u32 crc_ok_cck; 259 u32 crc_ok_11g; 260 u32 crc_ok_11n; 261 u32 crc_ok_11n_vht; 262 263 u32 crc_err_cck; 264 u32 crc_err_11g; 265 u32 crc_err_11n; 266 u32 crc_err_11n_vht; 267 268 boolean cck_lock; 269 boolean cck_lock_ever; 270 boolean cck_lock_warn; 271 272 u8 coex_table_type; 273 boolean force_lps_ctrl; 274 boolean concurrent_rx_mode_on; 275 276 u16 score_board; 277 u8 isolation_btween_wb; /* 0~ 50 */ 278 279 u8 a2dp_bit_pool; 280 u8 kt_ver; 281 boolean acl_busy; 282 boolean bt_create_connection; 283 284 u32 bt_coex_supported_feature; 285 u32 bt_coex_supported_version; 286 287 u8 bt_ble_scan_type; 288 u32 bt_ble_scan_para[3]; 289 290 boolean run_time_state; 291 boolean freeze_coexrun_by_btinfo; 292 293 boolean is_A2DP_3M; 294 boolean voice_over_HOGP; 295 boolean bt_a2dp_active; 296 u8 bt_info; 297 u8 forbidden_slot; 298 u8 hid_busy_num; 299 u8 hid_pair_cnt; 300 301 u32 cnt_remotenamereq; 302 u32 cnt_setuplink; 303 u32 cnt_reinit; 304 u32 cnt_ignwlanact; 305 u32 cnt_page; 306 u32 cnt_roleswitch; 307 308 u16 bt_reg_vendor_ac; 309 u16 bt_reg_vendor_ae; 310 311 boolean is_setup_link; 312 u8 wl_noisy_level; 313 u32 gnt_error_cnt; 314 315 u8 bt_afh_map[10]; 316 u8 bt_relink_downcount; 317 u8 bt_inq_page_downcount; 318 boolean is_tdma_btautoslot; 319 boolean is_tdma_btautoslot_hang; 320 321 boolean is_rf_state_off; 322 323 boolean is_hid_low_pri_tx_overhead; 324 boolean is_bt_multi_link; 325 boolean is_bt_a2dp_sink; 326 boolean is_bt_mesh_ver; 327 328 u8 wl_fw_dbg_info[10]; 329 u8 wl_rx_rate; 330 u8 wl_rts_rx_rate; 331 332 u16 score_board_WB; 333 334 boolean is_hid_rcu; 335 boolean is_ble_scan_en; 336 337 u16 legacy_forbidden_slot; 338 u16 le_forbidden_slot; 339 u8 bt_a2dp_vendor_id; 340 u32 bt_a2dp_device_name; 341 boolean is_bt_opp_exist; 342 boolean is_no_wl_5ms_extend; 343 344 u16 wl_0x42a_backup; 345 u32 wl_0x430_backup; 346 u32 wl_0x434_backup; 347 u8 wl_0x456_backup; 348 349 boolean wl_tx_limit_en; 350 boolean wl_ampdu_limit_en; 351 boolean wl_rxagg_limit_en; 352 u8 wl_rxagg_size; 353 354 u8 tdma_timer_base; 355 u8 wl_iot_peer; 356 357 }; 358 359 #define BT_8723D_1ANT_ANTDET_PSD_POINTS 256 360 #define BT_8723D_1ANT_ANTDET_PSD_AVGNUM 1 361 #define BT_8723D_1ANT_ANTDET_BUF_LEN 16 362 363 struct psdscan_sta_8723d_1ant { 364 365 u32 ant_det_bt_le_channel; /* BT LE Channel ex:2412 */ 366 u32 ant_det_bt_tx_time; 367 u32 ant_det_pre_psdscan_peak_val; 368 boolean ant_det_is_ant_det_available; 369 u32 ant_det_psd_scan_peak_val; 370 boolean ant_det_is_btreply_available; 371 u32 ant_det_psd_scan_peak_freq; 372 373 u8 ant_det_result; 374 u8 ant_det_peak_val[BT_8723D_1ANT_ANTDET_BUF_LEN]; 375 u8 ant_det_peak_freq[BT_8723D_1ANT_ANTDET_BUF_LEN]; 376 u32 ant_det_try_count; 377 u32 ant_det_fail_count; 378 u32 ant_det_inteval_count; 379 u32 ant_det_thres_offset; 380 381 u32 real_cent_freq; 382 s32 real_offset; 383 u32 real_span; 384 385 u32 psd_band_width; 386 u32 psd_point; 387 u32 psd_report[1024]; 388 u32 psd_report_max_hold[1024]; 389 u32 psd_start_point; 390 u32 psd_stop_point; 391 u32 psd_max_value_point; 392 u32 psd_max_value; 393 u32 psd_max_value2; 394 u32 psd_avg_value; 395 u32 psd_loop_max_value[BT_8723D_1ANT_ANTDET_PSD_SWWEEPCOUNT]; 396 u32 psd_start_base; 397 u32 psd_avg_num; /* 1/8/16/32 */ 398 u32 psd_gen_count; 399 boolean is_antdet_running; 400 boolean is_psd_show_max_only; 401 }; 402 403 /* ******************************************* 404 * The following is interface which will notify coex module. 405 * ******************************************* */ 406 void ex_halbtc8723d1ant_power_on_setting(IN struct btc_coexist *btcoexist); 407 void ex_halbtc8723d1ant_pre_load_firmware(IN struct btc_coexist *btcoexist); 408 void ex_halbtc8723d1ant_init_hw_config(IN struct btc_coexist *btcoexist, 409 IN boolean wifi_only); 410 void ex_halbtc8723d1ant_init_coex_dm(IN struct btc_coexist *btcoexist); 411 void ex_halbtc8723d1ant_ips_notify(IN struct btc_coexist *btcoexist, 412 IN u8 type); 413 void ex_halbtc8723d1ant_lps_notify(IN struct btc_coexist *btcoexist, 414 IN u8 type); 415 void ex_halbtc8723d1ant_scan_notify(IN struct btc_coexist *btcoexist, 416 IN u8 type); 417 void ex_halbtc8723d1ant_connect_notify(IN struct btc_coexist *btcoexist, 418 IN u8 type); 419 void ex_halbtc8723d1ant_media_status_notify(IN struct btc_coexist *btcoexist, 420 IN u8 type); 421 void ex_halbtc8723d1ant_specific_packet_notify(IN struct btc_coexist *btcoexist, 422 IN u8 type); 423 void ex_halbtc8723d1ant_bt_info_notify(IN struct btc_coexist *btcoexist, 424 IN u8 *tmp_buf, IN u8 length); 425 void ex_halbtc8723d1ant_wl_fwdbginfo_notify(IN struct btc_coexist *btcoexist, 426 IN u8 *tmp_buf, IN u8 length); 427 void ex_halbtc8723d1ant_rx_rate_change_notify(IN struct btc_coexist *btcoexist, 428 IN BOOLEAN is_data_frame, IN u8 btc_rate_id); 429 void ex_halbtc8723d1ant_rf_status_notify(IN struct btc_coexist *btcoexist, 430 IN u8 type); 431 void ex_halbtc8723d1ant_halt_notify(IN struct btc_coexist *btcoexist); 432 void ex_halbtc8723d1ant_pnp_notify(IN struct btc_coexist *btcoexist, 433 IN u8 pnp_state); 434 void ex_halbtc8723d1ant_coex_dm_reset(IN struct btc_coexist *btcoexist); 435 void ex_halbtc8723d1ant_periodical(IN struct btc_coexist *btcoexist); 436 void ex_halbtc8723d1ant_set_antenna_notify(IN struct btc_coexist *btcoexist, 437 IN u8 type); 438 void ex_halbtc8723d1ant_display_coex_info(IN struct btc_coexist *btcoexist); 439 void ex_halbtc8723d1ant_antenna_detection(IN struct btc_coexist *btcoexist, 440 IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds); 441 void ex_halbtc8723d1ant_antenna_isolation(IN struct btc_coexist *btcoexist, 442 IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds); 443 444 void ex_halbtc8723d1ant_psd_scan(IN struct btc_coexist *btcoexist, 445 IN u32 cent_freq, IN u32 offset, IN u32 span, IN u32 seconds); 446 void ex_halbtc8723d1ant_display_ant_detection(IN struct btc_coexist *btcoexist); 447 448 #else 449 #define ex_halbtc8723d1ant_power_on_setting(btcoexist) 450 #define ex_halbtc8723d1ant_pre_load_firmware(btcoexist) 451 #define ex_halbtc8723d1ant_init_hw_config(btcoexist, wifi_only) 452 #define ex_halbtc8723d1ant_init_coex_dm(btcoexist) 453 #define ex_halbtc8723d1ant_ips_notify(btcoexist, type) 454 #define ex_halbtc8723d1ant_lps_notify(btcoexist, type) 455 #define ex_halbtc8723d1ant_scan_notify(btcoexist, type) 456 #define ex_halbtc8723d1ant_connect_notify(btcoexist, type) 457 #define ex_halbtc8723d1ant_media_status_notify(btcoexist, type) 458 #define ex_halbtc8723d1ant_specific_packet_notify(btcoexist, type) 459 #define ex_halbtc8723d1ant_bt_info_notify(btcoexist, tmp_buf, length) 460 #define ex_halbtc8723d1ant_wl_fwdbginfo_notify(btcoexist, tmp_buf, length) 461 #define ex_halbtc8723d1ant_rx_rate_change_notify(btcoexist, is_data_frame, btc_rate_id) 462 #define ex_halbtc8723d1ant_rf_status_notify(btcoexist, type) 463 #define ex_halbtc8723d1ant_halt_notify(btcoexist) 464 #define ex_halbtc8723d1ant_pnp_notify(btcoexist, pnp_state) 465 #define ex_halbtc8723d1ant_coex_dm_reset(btcoexist) 466 #define ex_halbtc8723d1ant_periodical(btcoexist) 467 #define ex_halbtc8723d1ant_display_coex_info(btcoexist) 468 #define ex_halbtc8723d1ant_set_antenna_notify(btcoexist, type) 469 #define ex_halbtc8723d1ant_antenna_detection(btcoexist, cent_freq, offset, span, seconds) 470 #define ex_halbtc8723d1ant_antenna_isolation(btcoexist, cent_freq, offset, span, seconds) 471 #define ex_halbtc8723d1ant_psd_scan(btcoexist, cent_freq, offset, span, seconds) 472 #define ex_halbtc8723d1ant_display_ant_detection(btcoexist) 473 #endif 474 475 #endif 476 477