1 // SPDX-License-Identifier: GPL-2.0 2 /* Copyright(c) 2012 Realtek Corporation.*/ 3 4 /*************************************************************** 5 * Description: 6 * 7 * This file is for RTL8723B Co-exist mechanism 8 * 9 * History 10 * 2012/11/15 Cosa first check in. 11 * 12 **************************************************************/ 13 /************************************************************** 14 * include files 15 **************************************************************/ 16 #include "halbt_precomp.h" 17 /************************************************************** 18 * Global variables, these are static variables 19 **************************************************************/ 20 static struct coex_dm_8723b_2ant glcoex_dm_8723b_2ant; 21 static struct coex_dm_8723b_2ant *coex_dm = &glcoex_dm_8723b_2ant; 22 static struct coex_sta_8723b_2ant glcoex_sta_8723b_2ant; 23 static struct coex_sta_8723b_2ant *coex_sta = &glcoex_sta_8723b_2ant; 24 25 static const char *const glbt_info_src_8723b_2ant[] = { 26 "BT Info[wifi fw]", 27 "BT Info[bt rsp]", 28 "BT Info[bt auto report]", 29 }; 30 31 static u32 glcoex_ver_date_8723b_2ant = 20131113; 32 static u32 glcoex_ver_8723b_2ant = 0x3f; 33 34 /************************************************************** 35 * local function proto type if needed 36 **************************************************************/ 37 /************************************************************** 38 * local function start with btc8723b2ant_ 39 **************************************************************/ 40 static u8 btc8723b2ant_bt_rssi_state(struct btc_coexist *btcoexist, 41 u8 level_num, u8 rssi_thresh, 42 u8 rssi_thresh1) 43 { 44 struct rtl_priv *rtlpriv = btcoexist->adapter; 45 s32 bt_rssi = 0; 46 u8 bt_rssi_state = coex_sta->pre_bt_rssi_state; 47 48 bt_rssi = coex_sta->bt_rssi; 49 50 if (level_num == 2) { 51 if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) || 52 (coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_STAY_LOW)) { 53 if (bt_rssi >= rssi_thresh + 54 BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT) { 55 bt_rssi_state = BTC_RSSI_STATE_HIGH; 56 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 57 "[BTCoex], BT Rssi state switch to High\n"); 58 } else { 59 bt_rssi_state = BTC_RSSI_STATE_STAY_LOW; 60 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 61 "[BTCoex], BT Rssi state stay at Low\n"); 62 } 63 } else { 64 if (bt_rssi < rssi_thresh) { 65 bt_rssi_state = BTC_RSSI_STATE_LOW; 66 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 67 "[BTCoex], BT Rssi state switch to Low\n"); 68 } else { 69 bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH; 70 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 71 "[BTCoex], BT Rssi state stay at High\n"); 72 } 73 } 74 } else if (level_num == 3) { 75 if (rssi_thresh > rssi_thresh1) { 76 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 77 "[BTCoex], BT Rssi thresh error!!\n"); 78 return coex_sta->pre_bt_rssi_state; 79 } 80 81 if ((coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_LOW) || 82 (coex_sta->pre_bt_rssi_state == BTC_RSSI_STATE_STAY_LOW)) { 83 if (bt_rssi >= rssi_thresh + 84 BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT) { 85 bt_rssi_state = BTC_RSSI_STATE_MEDIUM; 86 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 87 "[BTCoex], BT Rssi state switch to Medium\n"); 88 } else { 89 bt_rssi_state = BTC_RSSI_STATE_STAY_LOW; 90 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 91 "[BTCoex], BT Rssi state stay at Low\n"); 92 } 93 } else if ((coex_sta->pre_bt_rssi_state == 94 BTC_RSSI_STATE_MEDIUM) || 95 (coex_sta->pre_bt_rssi_state == 96 BTC_RSSI_STATE_STAY_MEDIUM)) { 97 if (bt_rssi >= rssi_thresh1 + 98 BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT) { 99 bt_rssi_state = BTC_RSSI_STATE_HIGH; 100 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 101 "[BTCoex], BT Rssi state switch to High\n"); 102 } else if (bt_rssi < rssi_thresh) { 103 bt_rssi_state = BTC_RSSI_STATE_LOW; 104 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 105 "[BTCoex], BT Rssi state switch to Low\n"); 106 } else { 107 bt_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM; 108 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 109 "[BTCoex], BT Rssi state stay at Medium\n"); 110 } 111 } else { 112 if (bt_rssi < rssi_thresh1) { 113 bt_rssi_state = BTC_RSSI_STATE_MEDIUM; 114 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 115 "[BTCoex], BT Rssi state switch to Medium\n"); 116 } else { 117 bt_rssi_state = BTC_RSSI_STATE_STAY_HIGH; 118 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 119 "[BTCoex], BT Rssi state stay at High\n"); 120 } 121 } 122 } 123 124 coex_sta->pre_bt_rssi_state = bt_rssi_state; 125 126 return bt_rssi_state; 127 } 128 129 static u8 btc8723b2ant_wifi_rssi_state(struct btc_coexist *btcoexist, 130 u8 index, u8 level_num, 131 u8 rssi_thresh, u8 rssi_thresh1) 132 { 133 struct rtl_priv *rtlpriv = btcoexist->adapter; 134 s32 wifi_rssi = 0; 135 u8 wifi_rssi_state = coex_sta->pre_wifi_rssi_state[index]; 136 137 btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi); 138 139 if (level_num == 2) { 140 if ((coex_sta->pre_wifi_rssi_state[index] == 141 BTC_RSSI_STATE_LOW) || 142 (coex_sta->pre_wifi_rssi_state[index] == 143 BTC_RSSI_STATE_STAY_LOW)) { 144 if (wifi_rssi >= rssi_thresh + 145 BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT) { 146 wifi_rssi_state = BTC_RSSI_STATE_HIGH; 147 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 148 "[BTCoex], wifi RSSI state switch to High\n"); 149 } else { 150 wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW; 151 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 152 "[BTCoex], wifi RSSI state stay at Low\n"); 153 } 154 } else { 155 if (wifi_rssi < rssi_thresh) { 156 wifi_rssi_state = BTC_RSSI_STATE_LOW; 157 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 158 "[BTCoex], wifi RSSI state switch to Low\n"); 159 } else { 160 wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH; 161 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 162 "[BTCoex], wifi RSSI state stay at High\n"); 163 } 164 } 165 } else if (level_num == 3) { 166 if (rssi_thresh > rssi_thresh1) { 167 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 168 "[BTCoex], wifi RSSI thresh error!!\n"); 169 return coex_sta->pre_wifi_rssi_state[index]; 170 } 171 172 if ((coex_sta->pre_wifi_rssi_state[index] == 173 BTC_RSSI_STATE_LOW) || 174 (coex_sta->pre_wifi_rssi_state[index] == 175 BTC_RSSI_STATE_STAY_LOW)) { 176 if (wifi_rssi >= rssi_thresh + 177 BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT) { 178 wifi_rssi_state = BTC_RSSI_STATE_MEDIUM; 179 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 180 "[BTCoex], wifi RSSI state switch to Medium\n"); 181 } else { 182 wifi_rssi_state = BTC_RSSI_STATE_STAY_LOW; 183 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 184 "[BTCoex], wifi RSSI state stay at Low\n"); 185 } 186 } else if ((coex_sta->pre_wifi_rssi_state[index] == 187 BTC_RSSI_STATE_MEDIUM) || 188 (coex_sta->pre_wifi_rssi_state[index] == 189 BTC_RSSI_STATE_STAY_MEDIUM)) { 190 if (wifi_rssi >= rssi_thresh1 + 191 BTC_RSSI_COEX_THRESH_TOL_8723B_2ANT) { 192 wifi_rssi_state = BTC_RSSI_STATE_HIGH; 193 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 194 "[BTCoex], wifi RSSI state switch to High\n"); 195 } else if (wifi_rssi < rssi_thresh) { 196 wifi_rssi_state = BTC_RSSI_STATE_LOW; 197 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 198 "[BTCoex], wifi RSSI state switch to Low\n"); 199 } else { 200 wifi_rssi_state = BTC_RSSI_STATE_STAY_MEDIUM; 201 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 202 "[BTCoex], wifi RSSI state stay at Medium\n"); 203 } 204 } else { 205 if (wifi_rssi < rssi_thresh1) { 206 wifi_rssi_state = BTC_RSSI_STATE_MEDIUM; 207 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 208 "[BTCoex], wifi RSSI state switch to Medium\n"); 209 } else { 210 wifi_rssi_state = BTC_RSSI_STATE_STAY_HIGH; 211 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 212 "[BTCoex], wifi RSSI state stay at High\n"); 213 } 214 } 215 } 216 217 coex_sta->pre_wifi_rssi_state[index] = wifi_rssi_state; 218 219 return wifi_rssi_state; 220 } 221 222 static 223 void btc8723b2ant_limited_rx(struct btc_coexist *btcoexist, bool force_exec, 224 bool rej_ap_agg_pkt, bool bt_ctrl_agg_buf_size, 225 u8 agg_buf_size) 226 { 227 bool reject_rx_agg = rej_ap_agg_pkt; 228 bool bt_ctrl_rx_agg_size = bt_ctrl_agg_buf_size; 229 u8 rx_agg_size = agg_buf_size; 230 231 /* ============================================ */ 232 /* Rx Aggregation related setting */ 233 /* ============================================ */ 234 btcoexist->btc_set(btcoexist, BTC_SET_BL_TO_REJ_AP_AGG_PKT, 235 &reject_rx_agg); 236 /* decide BT control aggregation buf size or not */ 237 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_CTRL_AGG_SIZE, 238 &bt_ctrl_rx_agg_size); 239 /* aggregate buf size, only work when BT control Rx aggregate size */ 240 btcoexist->btc_set(btcoexist, BTC_SET_U1_AGG_BUF_SIZE, &rx_agg_size); 241 /* real update aggregation setting */ 242 btcoexist->btc_set(btcoexist, BTC_SET_ACT_AGGREGATE_CTRL, NULL); 243 } 244 245 static void btc8723b2ant_monitor_bt_ctr(struct btc_coexist *btcoexist) 246 { 247 struct rtl_priv *rtlpriv = btcoexist->adapter; 248 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; 249 u32 reg_hp_txrx, reg_lp_txrx, u32tmp; 250 u32 reg_hp_tx = 0, reg_hp_rx = 0; 251 u32 reg_lp_tx = 0, reg_lp_rx = 0; 252 253 reg_hp_txrx = 0x770; 254 reg_lp_txrx = 0x774; 255 256 u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_hp_txrx); 257 reg_hp_tx = u32tmp & MASKLWORD; 258 reg_hp_rx = (u32tmp & MASKHWORD) >> 16; 259 260 u32tmp = btcoexist->btc_read_4byte(btcoexist, reg_lp_txrx); 261 reg_lp_tx = u32tmp & MASKLWORD; 262 reg_lp_rx = (u32tmp & MASKHWORD) >> 16; 263 264 coex_sta->high_priority_tx = reg_hp_tx; 265 coex_sta->high_priority_rx = reg_hp_rx; 266 coex_sta->low_priority_tx = reg_lp_tx; 267 coex_sta->low_priority_rx = reg_lp_rx; 268 269 if ((coex_sta->low_priority_tx > 1050) && 270 (!coex_sta->c2h_bt_inquiry_page)) 271 coex_sta->pop_event_cnt++; 272 273 if ((coex_sta->low_priority_rx >= 950) && 274 (coex_sta->low_priority_rx >= coex_sta->low_priority_tx) && 275 (!coex_sta->under_ips)) 276 bt_link_info->slave_role = true; 277 else 278 bt_link_info->slave_role = false; 279 280 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 281 "[BTCoex], High Priority Tx/Rx(reg 0x%x)=0x%x(%d)/0x%x(%d)\n", 282 reg_hp_txrx, reg_hp_tx, reg_hp_tx, reg_hp_rx, reg_hp_rx); 283 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 284 "[BTCoex], Low Priority Tx/Rx(reg 0x%x)=0x%x(%d)/0x%x(%d)\n", 285 reg_lp_txrx, reg_lp_tx, reg_lp_tx, reg_lp_rx, reg_lp_rx); 286 287 /* reset counter */ 288 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0xc); 289 } 290 291 static void btc8723b2ant_monitor_wifi_ctr(struct btc_coexist *btcoexist) 292 { 293 if (coex_sta->under_ips) { 294 coex_sta->crc_ok_cck = 0; 295 coex_sta->crc_ok_11g = 0; 296 coex_sta->crc_ok_11n = 0; 297 coex_sta->crc_ok_11n_agg = 0; 298 299 coex_sta->crc_err_cck = 0; 300 coex_sta->crc_err_11g = 0; 301 coex_sta->crc_err_11n = 0; 302 coex_sta->crc_err_11n_agg = 0; 303 } else { 304 coex_sta->crc_ok_cck = 305 btcoexist->btc_read_4byte(btcoexist, 0xf88); 306 coex_sta->crc_ok_11g = 307 btcoexist->btc_read_2byte(btcoexist, 0xf94); 308 coex_sta->crc_ok_11n = 309 btcoexist->btc_read_2byte(btcoexist, 0xf90); 310 coex_sta->crc_ok_11n_agg = 311 btcoexist->btc_read_2byte(btcoexist, 0xfb8); 312 313 coex_sta->crc_err_cck = 314 btcoexist->btc_read_4byte(btcoexist, 0xf84); 315 coex_sta->crc_err_11g = 316 btcoexist->btc_read_2byte(btcoexist, 0xf96); 317 coex_sta->crc_err_11n = 318 btcoexist->btc_read_2byte(btcoexist, 0xf92); 319 coex_sta->crc_err_11n_agg = 320 btcoexist->btc_read_2byte(btcoexist, 0xfba); 321 } 322 323 /* reset counter */ 324 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xf16, 0x1, 0x1); 325 btcoexist->btc_write_1byte_bitmask(btcoexist, 0xf16, 0x1, 0x0); 326 } 327 328 static void btc8723b2ant_query_bt_info(struct btc_coexist *btcoexist) 329 { 330 struct rtl_priv *rtlpriv = btcoexist->adapter; 331 u8 h2c_parameter[1] = {0}; 332 333 coex_sta->c2h_bt_info_req_sent = true; 334 335 h2c_parameter[0] |= BIT0; /* trigger */ 336 337 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 338 "[BTCoex], Query Bt Info, FW write 0x61 = 0x%x\n", 339 h2c_parameter[0]); 340 341 btcoexist->btc_fill_h2c(btcoexist, 0x61, 1, h2c_parameter); 342 } 343 344 static bool btc8723b2ant_is_wifi_status_changed(struct btc_coexist *btcoexist) 345 { 346 static bool pre_wifi_busy; 347 static bool pre_under_4way; 348 static bool pre_bt_hs_on; 349 bool wifi_busy = false, under_4way = false, bt_hs_on = false; 350 bool wifi_connected = false; 351 u8 wifi_rssi_state = BTC_RSSI_STATE_HIGH; 352 u8 tmp; 353 354 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, 355 &wifi_connected); 356 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); 357 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); 358 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_4_WAY_PROGRESS, 359 &under_4way); 360 361 if (wifi_connected) { 362 if (wifi_busy != pre_wifi_busy) { 363 pre_wifi_busy = wifi_busy; 364 return true; 365 } 366 367 if (under_4way != pre_under_4way) { 368 pre_under_4way = under_4way; 369 return true; 370 } 371 372 if (bt_hs_on != pre_bt_hs_on) { 373 pre_bt_hs_on = bt_hs_on; 374 return true; 375 } 376 377 tmp = BT_8723B_2ANT_WIFI_RSSI_COEXSWITCH_THRES - 378 coex_dm->switch_thres_offset; 379 wifi_rssi_state = 380 btc8723b2ant_wifi_rssi_state(btcoexist, 0, 2, tmp, 0); 381 382 if ((wifi_rssi_state == BTC_RSSI_STATE_HIGH) || 383 (wifi_rssi_state == BTC_RSSI_STATE_LOW)) 384 return true; 385 } 386 387 return false; 388 } 389 390 static void btc8723b2ant_update_bt_link_info(struct btc_coexist *btcoexist) 391 { 392 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; 393 bool bt_hs_on = false; 394 395 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); 396 397 bt_link_info->bt_link_exist = coex_sta->bt_link_exist; 398 bt_link_info->sco_exist = coex_sta->sco_exist; 399 bt_link_info->a2dp_exist = coex_sta->a2dp_exist; 400 bt_link_info->pan_exist = coex_sta->pan_exist; 401 bt_link_info->hid_exist = coex_sta->hid_exist; 402 403 /* work around for HS mode. */ 404 if (bt_hs_on) { 405 bt_link_info->pan_exist = true; 406 bt_link_info->bt_link_exist = true; 407 } 408 409 /* check if Sco only */ 410 if (bt_link_info->sco_exist && !bt_link_info->a2dp_exist && 411 !bt_link_info->pan_exist && !bt_link_info->hid_exist) 412 bt_link_info->sco_only = true; 413 else 414 bt_link_info->sco_only = false; 415 416 /* check if A2dp only */ 417 if (!bt_link_info->sco_exist && bt_link_info->a2dp_exist && 418 !bt_link_info->pan_exist && !bt_link_info->hid_exist) 419 bt_link_info->a2dp_only = true; 420 else 421 bt_link_info->a2dp_only = false; 422 423 /* check if Pan only */ 424 if (!bt_link_info->sco_exist && !bt_link_info->a2dp_exist && 425 bt_link_info->pan_exist && !bt_link_info->hid_exist) 426 bt_link_info->pan_only = true; 427 else 428 bt_link_info->pan_only = false; 429 430 /* check if Hid only */ 431 if (!bt_link_info->sco_exist && !bt_link_info->a2dp_exist && 432 !bt_link_info->pan_exist && bt_link_info->hid_exist) 433 bt_link_info->hid_only = true; 434 else 435 bt_link_info->hid_only = false; 436 } 437 438 static u8 btc8723b2ant_action_algorithm(struct btc_coexist *btcoexist) 439 { 440 struct rtl_priv *rtlpriv = btcoexist->adapter; 441 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; 442 bool bt_hs_on = false; 443 u8 algorithm = BT_8723B_2ANT_COEX_ALGO_UNDEFINED; 444 u8 num_of_diff_profile = 0; 445 446 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); 447 448 if (!bt_link_info->bt_link_exist) { 449 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 450 "[BTCoex], No BT link exists!!!\n"); 451 return algorithm; 452 } 453 454 if (bt_link_info->sco_exist) 455 num_of_diff_profile++; 456 if (bt_link_info->hid_exist) 457 num_of_diff_profile++; 458 if (bt_link_info->pan_exist) 459 num_of_diff_profile++; 460 if (bt_link_info->a2dp_exist) 461 num_of_diff_profile++; 462 463 if (num_of_diff_profile == 1) { 464 if (bt_link_info->sco_exist) { 465 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 466 "[BTCoex], SCO only\n"); 467 algorithm = BT_8723B_2ANT_COEX_ALGO_SCO; 468 } else { 469 if (bt_link_info->hid_exist) { 470 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 471 "[BTCoex], HID only\n"); 472 algorithm = BT_8723B_2ANT_COEX_ALGO_HID; 473 } else if (bt_link_info->a2dp_exist) { 474 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 475 "[BTCoex], A2DP only\n"); 476 algorithm = BT_8723B_2ANT_COEX_ALGO_A2DP; 477 } else if (bt_link_info->pan_exist) { 478 if (bt_hs_on) { 479 rtl_dbg(rtlpriv, COMP_BT_COEXIST, 480 DBG_LOUD, 481 "[BTCoex], PAN(HS) only\n"); 482 algorithm = 483 BT_8723B_2ANT_COEX_ALGO_PANHS; 484 } else { 485 rtl_dbg(rtlpriv, COMP_BT_COEXIST, 486 DBG_LOUD, 487 "[BTCoex], PAN(EDR) only\n"); 488 algorithm = 489 BT_8723B_2ANT_COEX_ALGO_PANEDR; 490 } 491 } 492 } 493 } else if (num_of_diff_profile == 2) { 494 if (bt_link_info->sco_exist) { 495 if (bt_link_info->hid_exist) { 496 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 497 "[BTCoex], SCO + HID\n"); 498 algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID; 499 } else if (bt_link_info->a2dp_exist) { 500 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 501 "[BTCoex], SCO + A2DP ==> SCO\n"); 502 algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID; 503 } else if (bt_link_info->pan_exist) { 504 if (bt_hs_on) { 505 rtl_dbg(rtlpriv, COMP_BT_COEXIST, 506 DBG_LOUD, 507 "[BTCoex], SCO + PAN(HS)\n"); 508 algorithm = BT_8723B_2ANT_COEX_ALGO_SCO; 509 } else { 510 rtl_dbg(rtlpriv, COMP_BT_COEXIST, 511 DBG_LOUD, 512 "[BTCoex], SCO + PAN(EDR)\n"); 513 algorithm = 514 BT_8723B_2ANT_COEX_ALGO_PANEDR_HID; 515 } 516 } 517 } else { 518 if (bt_link_info->hid_exist && 519 bt_link_info->a2dp_exist) { 520 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 521 "[BTCoex], HID + A2DP\n"); 522 algorithm = BT_8723B_2ANT_COEX_ALGO_HID_A2DP; 523 } else if (bt_link_info->hid_exist && 524 bt_link_info->pan_exist) { 525 if (bt_hs_on) { 526 rtl_dbg(rtlpriv, COMP_BT_COEXIST, 527 DBG_LOUD, 528 "[BTCoex], HID + PAN(HS)\n"); 529 algorithm = BT_8723B_2ANT_COEX_ALGO_HID; 530 } else { 531 rtl_dbg(rtlpriv, COMP_BT_COEXIST, 532 DBG_LOUD, 533 "[BTCoex], HID + PAN(EDR)\n"); 534 algorithm = 535 BT_8723B_2ANT_COEX_ALGO_PANEDR_HID; 536 } 537 } else if (bt_link_info->pan_exist && 538 bt_link_info->a2dp_exist) { 539 if (bt_hs_on) { 540 rtl_dbg(rtlpriv, COMP_BT_COEXIST, 541 DBG_LOUD, 542 "[BTCoex], A2DP + PAN(HS)\n"); 543 algorithm = 544 BT_8723B_2ANT_COEX_ALGO_A2DP_PANHS; 545 } else { 546 rtl_dbg(rtlpriv, COMP_BT_COEXIST, 547 DBG_LOUD, 548 "[BTCoex],A2DP + PAN(EDR)\n"); 549 algorithm = 550 BT_8723B_2ANT_COEX_ALGO_PANEDR_A2DP; 551 } 552 } 553 } 554 } else if (num_of_diff_profile == 3) { 555 if (bt_link_info->sco_exist) { 556 if (bt_link_info->hid_exist && 557 bt_link_info->a2dp_exist) { 558 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 559 "[BTCoex], SCO + HID + A2DP ==> HID\n"); 560 algorithm = BT_8723B_2ANT_COEX_ALGO_PANEDR_HID; 561 } else if (bt_link_info->hid_exist && 562 bt_link_info->pan_exist) { 563 if (bt_hs_on) { 564 rtl_dbg(rtlpriv, COMP_BT_COEXIST, 565 DBG_LOUD, 566 "[BTCoex], SCO + HID + PAN(HS)\n"); 567 algorithm = 568 BT_8723B_2ANT_COEX_ALGO_PANEDR_HID; 569 } else { 570 rtl_dbg(rtlpriv, COMP_BT_COEXIST, 571 DBG_LOUD, 572 "[BTCoex], SCO + HID + PAN(EDR)\n"); 573 algorithm = 574 BT_8723B_2ANT_COEX_ALGO_PANEDR_HID; 575 } 576 } else if (bt_link_info->pan_exist && 577 bt_link_info->a2dp_exist) { 578 if (bt_hs_on) { 579 rtl_dbg(rtlpriv, COMP_BT_COEXIST, 580 DBG_LOUD, 581 "[BTCoex], SCO + A2DP + PAN(HS)\n"); 582 algorithm = 583 BT_8723B_2ANT_COEX_ALGO_PANEDR_HID; 584 } else { 585 rtl_dbg(rtlpriv, COMP_BT_COEXIST, 586 DBG_LOUD, 587 "[BTCoex], SCO + A2DP + PAN(EDR) ==> HID\n"); 588 algorithm = 589 BT_8723B_2ANT_COEX_ALGO_PANEDR_HID; 590 } 591 } 592 } else { 593 if (bt_link_info->hid_exist && 594 bt_link_info->pan_exist && 595 bt_link_info->a2dp_exist) { 596 if (bt_hs_on) { 597 rtl_dbg(rtlpriv, COMP_BT_COEXIST, 598 DBG_LOUD, 599 "[BTCoex], HID + A2DP + PAN(HS)\n"); 600 algorithm = 601 BT_8723B_2ANT_COEX_ALGO_HID_A2DP; 602 } else { 603 rtl_dbg(rtlpriv, COMP_BT_COEXIST, 604 DBG_LOUD, 605 "[BTCoex], HID + A2DP + PAN(EDR)\n"); 606 algorithm = 607 BT_8723B_2ANT_COEX_ALGO_HID_A2DP_PANEDR; 608 } 609 } 610 } 611 } else if (num_of_diff_profile >= 3) { 612 if (bt_link_info->sco_exist) { 613 if (bt_link_info->hid_exist && 614 bt_link_info->pan_exist && 615 bt_link_info->a2dp_exist) { 616 if (bt_hs_on) { 617 rtl_dbg(rtlpriv, COMP_BT_COEXIST, 618 DBG_LOUD, 619 "[BTCoex], Error!!! SCO + HID + A2DP + PAN(HS)\n"); 620 } else { 621 rtl_dbg(rtlpriv, COMP_BT_COEXIST, 622 DBG_LOUD, 623 "[BTCoex], SCO + HID + A2DP + PAN(EDR)==>PAN(EDR)+HID\n"); 624 algorithm = 625 BT_8723B_2ANT_COEX_ALGO_PANEDR_HID; 626 } 627 } 628 } 629 } 630 return algorithm; 631 } 632 633 static void btc8723b2ant_set_fw_dac_swing_level(struct btc_coexist *btcoexist, 634 u8 dac_swing_lvl) 635 { 636 struct rtl_priv *rtlpriv = btcoexist->adapter; 637 u8 h2c_parameter[1] = {0}; 638 639 /* There are several type of dacswing 640 * 0x18/ 0x10/ 0xc/ 0x8/ 0x4/ 0x6 641 */ 642 h2c_parameter[0] = dac_swing_lvl; 643 644 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 645 "[BTCoex], Set Dac Swing Level=0x%x\n", dac_swing_lvl); 646 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 647 "[BTCoex], FW write 0x64=0x%x\n", h2c_parameter[0]); 648 649 btcoexist->btc_fill_h2c(btcoexist, 0x64, 1, h2c_parameter); 650 } 651 652 static void btc8723b2ant_set_fw_dec_bt_pwr(struct btc_coexist *btcoexist, 653 u8 dec_bt_pwr_lvl) 654 { 655 struct rtl_priv *rtlpriv = btcoexist->adapter; 656 u8 h2c_parameter[1] = {0}; 657 658 h2c_parameter[0] = dec_bt_pwr_lvl; 659 660 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 661 "[BTCoex], decrease Bt Power Level : %u\n", dec_bt_pwr_lvl); 662 663 btcoexist->btc_fill_h2c(btcoexist, 0x62, 1, h2c_parameter); 664 } 665 666 static void btc8723b2ant_dec_bt_pwr(struct btc_coexist *btcoexist, 667 bool force_exec, u8 dec_bt_pwr_lvl) 668 { 669 struct rtl_priv *rtlpriv = btcoexist->adapter; 670 671 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 672 "[BTCoex], Dec BT power level = %u\n", dec_bt_pwr_lvl); 673 coex_dm->cur_dec_bt_pwr_lvl = dec_bt_pwr_lvl; 674 675 if (!force_exec) { 676 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 677 "[BTCoex], PreDecBtPwrLvl=%d, CurDecBtPwrLvl=%d\n", 678 coex_dm->pre_dec_bt_pwr_lvl, 679 coex_dm->cur_dec_bt_pwr_lvl); 680 681 if (coex_dm->pre_dec_bt_pwr_lvl == coex_dm->cur_dec_bt_pwr_lvl) 682 return; 683 } 684 btc8723b2ant_set_fw_dec_bt_pwr(btcoexist, coex_dm->cur_dec_bt_pwr_lvl); 685 686 coex_dm->pre_dec_bt_pwr_lvl = coex_dm->cur_dec_bt_pwr_lvl; 687 } 688 689 static 690 void halbtc8723b2ant_set_bt_auto_report(struct btc_coexist *btcoexist, 691 bool enable_auto_report) 692 { 693 u8 h2c_parameter[1] = {0}; 694 695 h2c_parameter[0] = 0; 696 697 if (enable_auto_report) 698 h2c_parameter[0] |= BIT(0); 699 700 btcoexist->btc_fill_h2c(btcoexist, 0x68, 1, h2c_parameter); 701 } 702 703 static 704 void btc8723b2ant_bt_auto_report(struct btc_coexist *btcoexist, 705 bool force_exec, bool enable_auto_report) 706 { 707 coex_dm->cur_bt_auto_report = enable_auto_report; 708 709 if (!force_exec) { 710 if (coex_dm->pre_bt_auto_report == coex_dm->cur_bt_auto_report) 711 return; 712 } 713 halbtc8723b2ant_set_bt_auto_report(btcoexist, 714 coex_dm->cur_bt_auto_report); 715 716 coex_dm->pre_bt_auto_report = coex_dm->cur_bt_auto_report; 717 } 718 719 static void btc8723b2ant_fw_dac_swing_lvl(struct btc_coexist *btcoexist, 720 bool force_exec, u8 fw_dac_swing_lvl) 721 { 722 struct rtl_priv *rtlpriv = btcoexist->adapter; 723 724 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 725 "[BTCoex], %s set FW Dac Swing level = %d\n", 726 (force_exec ? "force to" : ""), fw_dac_swing_lvl); 727 coex_dm->cur_fw_dac_swing_lvl = fw_dac_swing_lvl; 728 729 if (!force_exec) { 730 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 731 "[BTCoex], preFwDacSwingLvl=%d, curFwDacSwingLvl=%d\n", 732 coex_dm->pre_fw_dac_swing_lvl, 733 coex_dm->cur_fw_dac_swing_lvl); 734 735 if (coex_dm->pre_fw_dac_swing_lvl == 736 coex_dm->cur_fw_dac_swing_lvl) 737 return; 738 } 739 740 btc8723b2ant_set_fw_dac_swing_level(btcoexist, 741 coex_dm->cur_fw_dac_swing_lvl); 742 coex_dm->pre_fw_dac_swing_lvl = coex_dm->cur_fw_dac_swing_lvl; 743 } 744 745 static void btc8723b_set_penalty_txrate(struct btc_coexist *btcoexist, 746 bool low_penalty_ra) 747 { 748 struct rtl_priv *rtlpriv = btcoexist->adapter; 749 u8 h2c_parameter[6] = {0}; 750 751 h2c_parameter[0] = 0x6; /* op_code, 0x6 = Retry_Penalty */ 752 753 if (low_penalty_ra) { 754 h2c_parameter[1] |= BIT0; 755 /* normal rate except MCS7/6/5, OFDM54/48/36 */ 756 h2c_parameter[2] = 0x00; 757 h2c_parameter[3] = 0xf4; /* MCS7 or OFDM54 */ 758 h2c_parameter[4] = 0xf5; /* MCS6 or OFDM48 */ 759 h2c_parameter[5] = 0xf6; /* MCS5 or OFDM36 */ 760 } 761 762 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 763 "[BTCoex], set WiFi Low-Penalty Retry: %s", 764 (low_penalty_ra ? "ON!!" : "OFF!!")); 765 766 btcoexist->btc_fill_h2c(btcoexist, 0x69, 6, h2c_parameter); 767 } 768 769 static void btc8723b2ant_low_penalty_ra(struct btc_coexist *btcoexist, 770 bool force_exec, bool low_penalty_ra) 771 { 772 struct rtl_priv *rtlpriv = btcoexist->adapter; 773 774 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 775 "[BTCoex], %s turn LowPenaltyRA = %s\n", 776 (force_exec ? "force to" : ""), (low_penalty_ra ? 777 "ON" : "OFF")); 778 coex_dm->cur_low_penalty_ra = low_penalty_ra; 779 780 if (!force_exec) { 781 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 782 "[BTCoex], bPreLowPenaltyRa=%d, bCurLowPenaltyRa=%d\n", 783 coex_dm->pre_low_penalty_ra, 784 coex_dm->cur_low_penalty_ra); 785 786 if (coex_dm->pre_low_penalty_ra == coex_dm->cur_low_penalty_ra) 787 return; 788 } 789 btc8723b_set_penalty_txrate(btcoexist, coex_dm->cur_low_penalty_ra); 790 791 coex_dm->pre_low_penalty_ra = coex_dm->cur_low_penalty_ra; 792 } 793 794 static void btc8723b2ant_set_dac_swing_reg(struct btc_coexist *btcoexist, 795 u32 level) 796 { 797 struct rtl_priv *rtlpriv = btcoexist->adapter; 798 u8 val = (u8) level; 799 800 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 801 "[BTCoex], Write SwDacSwing = 0x%x\n", level); 802 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x883, 0x3e, val); 803 } 804 805 static void btc8723b2ant_set_sw_fulltime_dac_swing(struct btc_coexist *btcoex, 806 bool sw_dac_swing_on, 807 u32 sw_dac_swing_lvl) 808 { 809 if (sw_dac_swing_on) 810 btc8723b2ant_set_dac_swing_reg(btcoex, sw_dac_swing_lvl); 811 else 812 btc8723b2ant_set_dac_swing_reg(btcoex, 0x18); 813 } 814 815 static void btc8723b2ant_dac_swing(struct btc_coexist *btcoexist, 816 bool force_exec, bool dac_swing_on, 817 u32 dac_swing_lvl) 818 { 819 struct rtl_priv *rtlpriv = btcoexist->adapter; 820 821 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 822 "[BTCoex], %s turn DacSwing=%s, dac_swing_lvl=0x%x\n", 823 (force_exec ? "force to" : ""), 824 (dac_swing_on ? "ON" : "OFF"), dac_swing_lvl); 825 coex_dm->cur_dac_swing_on = dac_swing_on; 826 coex_dm->cur_dac_swing_lvl = dac_swing_lvl; 827 828 if (!force_exec) { 829 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 830 "[BTCoex], bPreDacSwingOn=%d, preDacSwingLvl=0x%x, bCurDacSwingOn=%d, curDacSwingLvl=0x%x\n", 831 coex_dm->pre_dac_swing_on, 832 coex_dm->pre_dac_swing_lvl, 833 coex_dm->cur_dac_swing_on, 834 coex_dm->cur_dac_swing_lvl); 835 836 if ((coex_dm->pre_dac_swing_on == coex_dm->cur_dac_swing_on) && 837 (coex_dm->pre_dac_swing_lvl == coex_dm->cur_dac_swing_lvl)) 838 return; 839 } 840 mdelay(30); 841 btc8723b2ant_set_sw_fulltime_dac_swing(btcoexist, dac_swing_on, 842 dac_swing_lvl); 843 844 coex_dm->pre_dac_swing_on = coex_dm->cur_dac_swing_on; 845 coex_dm->pre_dac_swing_lvl = coex_dm->cur_dac_swing_lvl; 846 } 847 848 static void btc8723b2ant_set_coex_table(struct btc_coexist *btcoexist, 849 u32 val0x6c0, u32 val0x6c4, 850 u32 val0x6c8, u8 val0x6cc) 851 { 852 struct rtl_priv *rtlpriv = btcoexist->adapter; 853 854 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 855 "[BTCoex], set coex table, set 0x6c0=0x%x\n", val0x6c0); 856 btcoexist->btc_write_4byte(btcoexist, 0x6c0, val0x6c0); 857 858 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 859 "[BTCoex], set coex table, set 0x6c4=0x%x\n", val0x6c4); 860 btcoexist->btc_write_4byte(btcoexist, 0x6c4, val0x6c4); 861 862 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 863 "[BTCoex], set coex table, set 0x6c8=0x%x\n", val0x6c8); 864 btcoexist->btc_write_4byte(btcoexist, 0x6c8, val0x6c8); 865 866 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 867 "[BTCoex], set coex table, set 0x6cc=0x%x\n", val0x6cc); 868 btcoexist->btc_write_1byte(btcoexist, 0x6cc, val0x6cc); 869 } 870 871 static void btc8723b2ant_coex_table(struct btc_coexist *btcoexist, 872 bool force_exec, u32 val0x6c0, 873 u32 val0x6c4, u32 val0x6c8, 874 u8 val0x6cc) 875 { 876 struct rtl_priv *rtlpriv = btcoexist->adapter; 877 878 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 879 "[BTCoex], %s write Coex Table 0x6c0=0x%x, 0x6c4=0x%x, 0x6c8=0x%x, 0x6cc=0x%x\n", 880 force_exec ? "force to" : "", 881 val0x6c0, val0x6c4, val0x6c8, val0x6cc); 882 coex_dm->cur_val0x6c0 = val0x6c0; 883 coex_dm->cur_val0x6c4 = val0x6c4; 884 coex_dm->cur_val0x6c8 = val0x6c8; 885 coex_dm->cur_val0x6cc = val0x6cc; 886 887 if (!force_exec) { 888 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 889 "[BTCoex], preVal0x6c0=0x%x, preVal0x6c4=0x%x, preVal0x6c8=0x%x, preVal0x6cc=0x%x !!\n", 890 coex_dm->pre_val0x6c0, coex_dm->pre_val0x6c4, 891 coex_dm->pre_val0x6c8, coex_dm->pre_val0x6cc); 892 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 893 "[BTCoex], curVal0x6c0=0x%x, curVal0x6c4=0x%x, curVal0x6c8=0x%x, curVal0x6cc=0x%x !!\n", 894 coex_dm->cur_val0x6c0, coex_dm->cur_val0x6c4, 895 coex_dm->cur_val0x6c8, coex_dm->cur_val0x6cc); 896 897 if ((coex_dm->pre_val0x6c0 == coex_dm->cur_val0x6c0) && 898 (coex_dm->pre_val0x6c4 == coex_dm->cur_val0x6c4) && 899 (coex_dm->pre_val0x6c8 == coex_dm->cur_val0x6c8) && 900 (coex_dm->pre_val0x6cc == coex_dm->cur_val0x6cc)) 901 return; 902 } 903 btc8723b2ant_set_coex_table(btcoexist, val0x6c0, val0x6c4, 904 val0x6c8, val0x6cc); 905 906 coex_dm->pre_val0x6c0 = coex_dm->cur_val0x6c0; 907 coex_dm->pre_val0x6c4 = coex_dm->cur_val0x6c4; 908 coex_dm->pre_val0x6c8 = coex_dm->cur_val0x6c8; 909 coex_dm->pre_val0x6cc = coex_dm->cur_val0x6cc; 910 } 911 912 static void btc8723b2ant_coex_table_with_type(struct btc_coexist *btcoexist, 913 bool force_exec, u8 type) 914 { 915 switch (type) { 916 case 0: 917 btc8723b2ant_coex_table(btcoexist, force_exec, 0x55555555, 918 0x55555555, 0xffffff, 0x3); 919 break; 920 case 1: 921 btc8723b2ant_coex_table(btcoexist, force_exec, 0x55555555, 922 0x5afa5afa, 0xffffff, 0x3); 923 break; 924 case 2: 925 btc8723b2ant_coex_table(btcoexist, force_exec, 0x5ada5ada, 926 0x5ada5ada, 0xffffff, 0x3); 927 break; 928 case 3: 929 btc8723b2ant_coex_table(btcoexist, force_exec, 0xaaaaaaaa, 930 0xaaaaaaaa, 0xffffff, 0x3); 931 break; 932 case 4: 933 btc8723b2ant_coex_table(btcoexist, force_exec, 0xffffffff, 934 0xffffffff, 0xffffff, 0x3); 935 break; 936 case 5: 937 btc8723b2ant_coex_table(btcoexist, force_exec, 0x5fff5fff, 938 0x5fff5fff, 0xffffff, 0x3); 939 break; 940 case 6: 941 btc8723b2ant_coex_table(btcoexist, force_exec, 0x55ff55ff, 942 0x5a5a5a5a, 0xffffff, 0x3); 943 break; 944 case 7: 945 btc8723b2ant_coex_table(btcoexist, force_exec, 0x55dd55dd, 946 0x5ada5ada, 0xffffff, 0x3); 947 break; 948 case 8: 949 btc8723b2ant_coex_table(btcoexist, force_exec, 0x55dd55dd, 950 0x5ada5ada, 0xffffff, 0x3); 951 break; 952 case 9: 953 btc8723b2ant_coex_table(btcoexist, force_exec, 0x55dd55dd, 954 0x5ada5ada, 0xffffff, 0x3); 955 break; 956 case 10: 957 btc8723b2ant_coex_table(btcoexist, force_exec, 0x55dd55dd, 958 0x5ada5ada, 0xffffff, 0x3); 959 break; 960 case 11: 961 btc8723b2ant_coex_table(btcoexist, force_exec, 0x55dd55dd, 962 0x5ada5ada, 0xffffff, 0x3); 963 break; 964 case 12: 965 btc8723b2ant_coex_table(btcoexist, force_exec, 0x55dd55dd, 966 0x5ada5ada, 0xffffff, 0x3); 967 break; 968 case 13: 969 btc8723b2ant_coex_table(btcoexist, force_exec, 0x5fff5fff, 970 0xaaaaaaaa, 0xffffff, 0x3); 971 break; 972 case 14: 973 btc8723b2ant_coex_table(btcoexist, force_exec, 0x5fff5fff, 974 0x5ada5ada, 0xffffff, 0x3); 975 break; 976 case 15: 977 btc8723b2ant_coex_table(btcoexist, force_exec, 0x55dd55dd, 978 0xaaaaaaaa, 0xffffff, 0x3); 979 break; 980 default: 981 break; 982 } 983 } 984 985 static void btc8723b2ant_set_fw_ignore_wlan_act(struct btc_coexist *btcoexist, 986 bool enable) 987 { 988 struct rtl_priv *rtlpriv = btcoexist->adapter; 989 u8 h2c_parameter[1] = {0}; 990 991 if (enable) 992 h2c_parameter[0] |= BIT0; /* function enable */ 993 994 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 995 "[BTCoex], set FW for BT Ignore Wlan_Act, FW write 0x63=0x%x\n", 996 h2c_parameter[0]); 997 998 btcoexist->btc_fill_h2c(btcoexist, 0x63, 1, h2c_parameter); 999 } 1000 1001 static void btc8723b2ant_set_lps_rpwm(struct btc_coexist *btcoexist, 1002 u8 lps_val, u8 rpwm_val) 1003 { 1004 u8 lps = lps_val; 1005 u8 rpwm = rpwm_val; 1006 1007 btcoexist->btc_set(btcoexist, BTC_SET_U1_LPS_VAL, &lps); 1008 btcoexist->btc_set(btcoexist, BTC_SET_U1_RPWM_VAL, &rpwm); 1009 } 1010 1011 static void btc8723b2ant_lps_rpwm(struct btc_coexist *btcoexist, 1012 bool force_exec, u8 lps_val, u8 rpwm_val) 1013 { 1014 coex_dm->cur_lps = lps_val; 1015 coex_dm->cur_rpwm = rpwm_val; 1016 1017 if (!force_exec) { 1018 if ((coex_dm->pre_lps == coex_dm->cur_lps) && 1019 (coex_dm->pre_rpwm == coex_dm->cur_rpwm)) 1020 return; 1021 } 1022 btc8723b2ant_set_lps_rpwm(btcoexist, lps_val, rpwm_val); 1023 1024 coex_dm->pre_lps = coex_dm->cur_lps; 1025 coex_dm->pre_rpwm = coex_dm->cur_rpwm; 1026 } 1027 1028 static void btc8723b2ant_ignore_wlan_act(struct btc_coexist *btcoexist, 1029 bool force_exec, bool enable) 1030 { 1031 struct rtl_priv *rtlpriv = btcoexist->adapter; 1032 1033 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1034 "[BTCoex], %s turn Ignore WlanAct %s\n", 1035 (force_exec ? "force to" : ""), (enable ? "ON" : "OFF")); 1036 coex_dm->cur_ignore_wlan_act = enable; 1037 1038 if (!force_exec) { 1039 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1040 "[BTCoex], bPreIgnoreWlanAct = %d, bCurIgnoreWlanAct = %d!!\n", 1041 coex_dm->pre_ignore_wlan_act, 1042 coex_dm->cur_ignore_wlan_act); 1043 1044 if (coex_dm->pre_ignore_wlan_act == 1045 coex_dm->cur_ignore_wlan_act) 1046 return; 1047 } 1048 btc8723b2ant_set_fw_ignore_wlan_act(btcoexist, enable); 1049 1050 coex_dm->pre_ignore_wlan_act = coex_dm->cur_ignore_wlan_act; 1051 } 1052 1053 static void btc8723b2ant_set_fw_ps_tdma(struct btc_coexist *btcoexist, u8 byte1, 1054 u8 byte2, u8 byte3, u8 byte4, u8 byte5) 1055 { 1056 struct rtl_priv *rtlpriv = btcoexist->adapter; 1057 u8 h2c_parameter[5]; 1058 if ((coex_sta->a2dp_exist) && (coex_sta->hid_exist)) 1059 byte5 = byte5 | 0x1; 1060 1061 h2c_parameter[0] = byte1; 1062 h2c_parameter[1] = byte2; 1063 h2c_parameter[2] = byte3; 1064 h2c_parameter[3] = byte4; 1065 h2c_parameter[4] = byte5; 1066 1067 coex_dm->ps_tdma_para[0] = byte1; 1068 coex_dm->ps_tdma_para[1] = byte2; 1069 coex_dm->ps_tdma_para[2] = byte3; 1070 coex_dm->ps_tdma_para[3] = byte4; 1071 coex_dm->ps_tdma_para[4] = byte5; 1072 1073 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1074 "[BTCoex], FW write 0x60(5bytes)=0x%x%08x\n", 1075 h2c_parameter[0], 1076 h2c_parameter[1] << 24 | h2c_parameter[2] << 16 | 1077 h2c_parameter[3] << 8 | h2c_parameter[4]); 1078 1079 btcoexist->btc_fill_h2c(btcoexist, 0x60, 5, h2c_parameter); 1080 } 1081 1082 static void btc8723b2ant_sw_mechanism(struct btc_coexist *btcoexist, 1083 bool shrink_rx_lpf, bool low_penalty_ra, 1084 bool limited_dig, bool bt_lna_constrain) 1085 { 1086 btc8723b2ant_low_penalty_ra(btcoexist, NORMAL_EXEC, low_penalty_ra); 1087 } 1088 1089 static void btc8723b2ant_set_ant_path(struct btc_coexist *btcoexist, 1090 u8 antpos_type, bool init_hwcfg, 1091 bool wifi_off) 1092 { 1093 struct btc_board_info *board_info = &btcoexist->board_info; 1094 u32 fw_ver = 0, u32tmp = 0; 1095 bool pg_ext_switch = false; 1096 bool use_ext_switch = false; 1097 u8 h2c_parameter[2] = {0}; 1098 1099 btcoexist->btc_get(btcoexist, BTC_GET_BL_EXT_SWITCH, &pg_ext_switch); 1100 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver); 1101 1102 if ((fw_ver < 0xc0000) || pg_ext_switch) 1103 use_ext_switch = true; 1104 1105 if (init_hwcfg) { 1106 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x39, 0x8, 0x1); 1107 btcoexist->btc_write_1byte(btcoexist, 0x974, 0xff); 1108 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x944, 0x3, 0x3); 1109 btcoexist->btc_write_1byte(btcoexist, 0x930, 0x77); 1110 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x20, 0x1); 1111 1112 if (fw_ver >= 0x180000) { 1113 /* Use H2C to set GNT_BT to High to avoid A2DP click */ 1114 h2c_parameter[0] = 1; 1115 btcoexist->btc_fill_h2c(btcoexist, 0x6E, 1, 1116 h2c_parameter); 1117 } else { 1118 btcoexist->btc_write_1byte(btcoexist, 0x765, 0x18); 1119 } 1120 1121 btcoexist->btc_write_4byte(btcoexist, 0x948, 0x0); 1122 1123 /* WiFi TRx Mask off */ 1124 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 1125 0x1, 0xfffff, 0x0); 1126 1127 if (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT) { 1128 /* tell firmware "no antenna inverse" */ 1129 h2c_parameter[0] = 0; 1130 } else { 1131 /* tell firmware "antenna inverse" */ 1132 h2c_parameter[0] = 1; 1133 } 1134 1135 if (use_ext_switch) { 1136 /* ext switch type */ 1137 h2c_parameter[1] = 1; 1138 } else { 1139 /* int switch type */ 1140 h2c_parameter[1] = 0; 1141 } 1142 btcoexist->btc_fill_h2c(btcoexist, 0x65, 2, h2c_parameter); 1143 } else { 1144 if (fw_ver >= 0x180000) { 1145 /* Use H2C to set GNT_BT to "Control by PTA"*/ 1146 h2c_parameter[0] = 0; 1147 btcoexist->btc_fill_h2c(btcoexist, 0x6E, 1, 1148 h2c_parameter); 1149 } else { 1150 btcoexist->btc_write_1byte(btcoexist, 0x765, 0x0); 1151 } 1152 } 1153 1154 /* ext switch setting */ 1155 if (use_ext_switch) { 1156 if (init_hwcfg) { 1157 /* 0x4c[23] = 0, 0x4c[24] = 1 Ant controlled by WL/BT */ 1158 u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c); 1159 u32tmp &= ~BIT23; 1160 u32tmp |= BIT24; 1161 btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp); 1162 } 1163 1164 /* fixed internal switch S1->WiFi, S0->BT */ 1165 if (board_info->btdm_ant_pos == BTC_ANTENNA_AT_MAIN_PORT) 1166 btcoexist->btc_write_2byte(btcoexist, 0x948, 0x0); 1167 else 1168 btcoexist->btc_write_2byte(btcoexist, 0x948, 0x280); 1169 1170 switch (antpos_type) { 1171 case BTC_ANT_WIFI_AT_MAIN: 1172 /* ext switch main at wifi */ 1173 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x92c, 1174 0x3, 0x1); 1175 break; 1176 case BTC_ANT_WIFI_AT_AUX: 1177 /* ext switch aux at wifi */ 1178 btcoexist->btc_write_1byte_bitmask(btcoexist, 1179 0x92c, 0x3, 0x2); 1180 break; 1181 } 1182 } else { 1183 /* internal switch */ 1184 if (init_hwcfg) { 1185 /* 0x4c[23] = 0, 0x4c[24] = 1 Ant controlled by WL/BT */ 1186 u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x4c); 1187 u32tmp |= BIT23; 1188 u32tmp &= ~BIT24; 1189 btcoexist->btc_write_4byte(btcoexist, 0x4c, u32tmp); 1190 } 1191 1192 /* fixed ext switch, S1->Main, S0->Aux */ 1193 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x64, 0x1, 0x0); 1194 switch (antpos_type) { 1195 case BTC_ANT_WIFI_AT_MAIN: 1196 /* fixed internal switch S1->WiFi, S0->BT */ 1197 btcoexist->btc_write_2byte(btcoexist, 0x948, 0x0); 1198 break; 1199 case BTC_ANT_WIFI_AT_AUX: 1200 /* fixed internal switch S0->WiFi, S1->BT */ 1201 btcoexist->btc_write_2byte(btcoexist, 0x948, 0x280); 1202 break; 1203 } 1204 } 1205 } 1206 1207 static void btc8723b2ant_ps_tdma(struct btc_coexist *btcoexist, bool force_exec, 1208 bool turn_on, u8 type) 1209 { 1210 struct rtl_priv *rtlpriv = btcoexist->adapter; 1211 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; 1212 u8 wifi_rssi_state, bt_rssi_state; 1213 s8 wifi_duration_adjust = 0x0; 1214 u8 tdma_byte4_modify = 0x0; 1215 u8 tmp = BT_8723B_2ANT_WIFI_RSSI_COEXSWITCH_THRES - 1216 coex_dm->switch_thres_offset; 1217 1218 wifi_rssi_state = btc8723b2ant_wifi_rssi_state(btcoexist, 0, 2, tmp, 0); 1219 tmp = BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES - 1220 coex_dm->switch_thres_offset; 1221 bt_rssi_state = btc8723b2ant_bt_rssi_state(btcoexist, 2, tmp, 0); 1222 1223 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1224 "[BTCoex], %s turn %s PS TDMA, type=%d\n", 1225 (force_exec ? "force to" : ""), 1226 (turn_on ? "ON" : "OFF"), type); 1227 coex_dm->cur_ps_tdma_on = turn_on; 1228 coex_dm->cur_ps_tdma = type; 1229 1230 if (!(BTC_RSSI_HIGH(wifi_rssi_state) && 1231 BTC_RSSI_HIGH(bt_rssi_state)) && turn_on) { 1232 /* for WiFi RSSI low or BT RSSI low */ 1233 type = type + 100; 1234 coex_dm->is_switch_to_1dot5_ant = true; 1235 } else { 1236 coex_dm->is_switch_to_1dot5_ant = false; 1237 } 1238 1239 if (!force_exec) { 1240 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1241 "[BTCoex], bPrePsTdmaOn = %d, bCurPsTdmaOn = %d!!\n", 1242 coex_dm->pre_ps_tdma_on, coex_dm->cur_ps_tdma_on); 1243 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1244 "[BTCoex], prePsTdma = %d, curPsTdma = %d!!\n", 1245 coex_dm->pre_ps_tdma, coex_dm->cur_ps_tdma); 1246 1247 if ((coex_dm->pre_ps_tdma_on == coex_dm->cur_ps_tdma_on) && 1248 (coex_dm->pre_ps_tdma == coex_dm->cur_ps_tdma)) 1249 return; 1250 } 1251 1252 if (coex_sta->scan_ap_num <= 5) { 1253 if (coex_sta->a2dp_bit_pool >= 45) 1254 wifi_duration_adjust = -15; 1255 else if (coex_sta->a2dp_bit_pool >= 35) 1256 wifi_duration_adjust = -10; 1257 else 1258 wifi_duration_adjust = 5; 1259 } else if (coex_sta->scan_ap_num <= 20) { 1260 if (coex_sta->a2dp_bit_pool >= 45) 1261 wifi_duration_adjust = -15; 1262 else if (coex_sta->a2dp_bit_pool >= 35) 1263 wifi_duration_adjust = -10; 1264 else 1265 wifi_duration_adjust = 0; 1266 } else if (coex_sta->scan_ap_num <= 40) { 1267 if (coex_sta->a2dp_bit_pool >= 45) 1268 wifi_duration_adjust = -15; 1269 else if (coex_sta->a2dp_bit_pool >= 35) 1270 wifi_duration_adjust = -10; 1271 else 1272 wifi_duration_adjust = -5; 1273 } else { 1274 if (coex_sta->a2dp_bit_pool >= 45) 1275 wifi_duration_adjust = -15; 1276 else if (coex_sta->a2dp_bit_pool >= 35) 1277 wifi_duration_adjust = -10; 1278 else 1279 wifi_duration_adjust = -10; 1280 } 1281 1282 if ((bt_link_info->slave_role) && (bt_link_info->a2dp_exist)) 1283 /* 0x778 = 0x1 at wifi slot (no blocking BT Low-Pri pkts) */ 1284 tdma_byte4_modify = 0x1; 1285 1286 if (turn_on) { 1287 switch (type) { 1288 case 1: 1289 default: 1290 btc8723b2ant_set_fw_ps_tdma( 1291 btcoexist, 0xe3, 0x3c, 1292 0x03, 0xf1, 0x90 | tdma_byte4_modify); 1293 break; 1294 case 2: 1295 btc8723b2ant_set_fw_ps_tdma( 1296 btcoexist, 0xe3, 0x2d, 1297 0x03, 0xf1, 0x90 | tdma_byte4_modify); 1298 break; 1299 case 3: 1300 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x1c, 1301 0x3, 0xf1, 1302 0x90 | tdma_byte4_modify); 1303 break; 1304 case 4: 1305 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x10, 1306 0x03, 0xf1, 1307 0x90 | tdma_byte4_modify); 1308 break; 1309 case 5: 1310 btc8723b2ant_set_fw_ps_tdma( 1311 btcoexist, 0xe3, 0x3c, 1312 0x3, 0x70, 0x90 | tdma_byte4_modify); 1313 break; 1314 case 6: 1315 btc8723b2ant_set_fw_ps_tdma( 1316 btcoexist, 0xe3, 0x2d, 1317 0x3, 0x70, 0x90 | tdma_byte4_modify); 1318 break; 1319 case 7: 1320 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x1c, 1321 0x3, 0x70, 1322 0x90 | tdma_byte4_modify); 1323 break; 1324 case 8: 1325 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xa3, 0x10, 1326 0x3, 0x70, 1327 0x90 | tdma_byte4_modify); 1328 break; 1329 case 9: 1330 btc8723b2ant_set_fw_ps_tdma( 1331 btcoexist, 0xe3, 0x3c + wifi_duration_adjust, 1332 0x03, 0xf1, 0x90 | tdma_byte4_modify); 1333 break; 1334 case 10: 1335 btc8723b2ant_set_fw_ps_tdma( 1336 btcoexist, 0xe3, 0x2d, 1337 0x03, 0xf1, 0x90 | tdma_byte4_modify); 1338 break; 1339 case 11: 1340 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x1c, 1341 0x3, 0xf1, 1342 0x90 | tdma_byte4_modify); 1343 break; 1344 case 12: 1345 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x10, 1346 0x3, 0xf1, 1347 0x90 | tdma_byte4_modify); 1348 break; 1349 case 13: 1350 btc8723b2ant_set_fw_ps_tdma( 1351 btcoexist, 0xe3, 0x3c, 1352 0x3, 0x70, 0x90 | tdma_byte4_modify); 1353 break; 1354 case 14: 1355 btc8723b2ant_set_fw_ps_tdma( 1356 btcoexist, 0xe3, 0x2d, 1357 0x3, 0x70, 0x90 | tdma_byte4_modify); 1358 break; 1359 case 15: 1360 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x1c, 1361 0x3, 0x70, 1362 0x90 | tdma_byte4_modify); 1363 break; 1364 case 16: 1365 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x10, 1366 0x3, 0x70, 1367 0x90 | tdma_byte4_modify); 1368 break; 1369 case 17: 1370 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xa3, 0x2f, 1371 0x2f, 0x60, 0x90); 1372 break; 1373 case 18: 1374 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x5, 0x5, 1375 0xe1, 0x90); 1376 break; 1377 case 19: 1378 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x25, 1379 0x25, 0xe1, 0x90); 1380 break; 1381 case 20: 1382 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x25, 1383 0x25, 0x60, 0x90); 1384 break; 1385 case 21: 1386 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x15, 1387 0x03, 0x70, 0x90); 1388 break; 1389 1390 case 23: 1391 case 123: 1392 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x35, 1393 0x03, 0x71, 0x10); 1394 break; 1395 case 71: 1396 btc8723b2ant_set_fw_ps_tdma( 1397 btcoexist, 0xe3, 0x3c + wifi_duration_adjust, 1398 0x03, 0xf1, 0x90); 1399 break; 1400 case 101: 1401 case 105: 1402 case 113: 1403 case 171: 1404 btc8723b2ant_set_fw_ps_tdma( 1405 btcoexist, 0xd3, 0x3a + wifi_duration_adjust, 1406 0x03, 0x70, 0x50 | tdma_byte4_modify); 1407 break; 1408 case 102: 1409 case 106: 1410 case 110: 1411 case 114: 1412 btc8723b2ant_set_fw_ps_tdma( 1413 btcoexist, 0xd3, 0x2d + wifi_duration_adjust, 1414 0x03, 0x70, 0x50 | tdma_byte4_modify); 1415 break; 1416 case 103: 1417 case 107: 1418 case 111: 1419 case 115: 1420 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xd3, 0x1c, 1421 0x03, 0x70, 1422 0x50 | tdma_byte4_modify); 1423 break; 1424 case 104: 1425 case 108: 1426 case 112: 1427 case 116: 1428 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xd3, 0x10, 1429 0x03, 0x70, 1430 0x50 | tdma_byte4_modify); 1431 break; 1432 case 109: 1433 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x3c, 1434 0x03, 0xf1, 1435 0x90 | tdma_byte4_modify); 1436 break; 1437 case 121: 1438 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x15, 1439 0x03, 0x70, 1440 0x90 | tdma_byte4_modify); 1441 break; 1442 case 22: 1443 case 122: 1444 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0xe3, 0x35, 1445 0x03, 0x71, 0x11); 1446 break; 1447 } 1448 } else { 1449 /* disable PS tdma */ 1450 switch (type) { 1451 case 0: 1452 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0x0, 0x0, 0x0, 1453 0x40, 0x0); 1454 break; 1455 case 1: 1456 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0x0, 0x0, 0x0, 1457 0x48, 0x0); 1458 break; 1459 default: 1460 btc8723b2ant_set_fw_ps_tdma(btcoexist, 0x0, 0x0, 0x0, 1461 0x40, 0x0); 1462 break; 1463 } 1464 } 1465 1466 /* update pre state */ 1467 coex_dm->pre_ps_tdma_on = coex_dm->cur_ps_tdma_on; 1468 coex_dm->pre_ps_tdma = coex_dm->cur_ps_tdma; 1469 } 1470 1471 static void btc8723b2ant_ps_tdma_check_for_power_save_state( 1472 struct btc_coexist *btcoexist, bool new_ps_state) 1473 { 1474 u8 lps_mode = 0x0; 1475 1476 btcoexist->btc_get(btcoexist, BTC_GET_U1_LPS_MODE, &lps_mode); 1477 1478 if (lps_mode) { 1479 /* already under LPS state */ 1480 if (new_ps_state) { 1481 /* keep state under LPS, do nothing. */ 1482 } else { 1483 /* will leave LPS state, turn off psTdma first */ 1484 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1); 1485 } 1486 } else { 1487 /* NO PS state */ 1488 if (new_ps_state) { 1489 /* will enter LPS state, turn off psTdma first */ 1490 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1); 1491 } else { 1492 /* keep state under NO PS state, do nothing. */ 1493 } 1494 } 1495 } 1496 1497 static void btc8723b2ant_power_save_state(struct btc_coexist *btcoexist, 1498 u8 ps_type, u8 lps_val, u8 rpwm_val) 1499 { 1500 bool low_pwr_disable = false; 1501 1502 switch (ps_type) { 1503 case BTC_PS_WIFI_NATIVE: 1504 /* recover to original 32k low power setting */ 1505 low_pwr_disable = false; 1506 btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER, 1507 &low_pwr_disable); 1508 btcoexist->btc_set(btcoexist, BTC_SET_ACT_NORMAL_LPS, NULL); 1509 coex_sta->force_lps_on = false; 1510 break; 1511 case BTC_PS_LPS_ON: 1512 btc8723b2ant_ps_tdma_check_for_power_save_state(btcoexist, 1513 true); 1514 btc8723b2ant_lps_rpwm(btcoexist, NORMAL_EXEC, lps_val, 1515 rpwm_val); 1516 /* when coex force to enter LPS, do not enter 32k low power */ 1517 low_pwr_disable = true; 1518 btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER, 1519 &low_pwr_disable); 1520 /* power save must executed before psTdma */ 1521 btcoexist->btc_set(btcoexist, BTC_SET_ACT_ENTER_LPS, NULL); 1522 coex_sta->force_lps_on = true; 1523 break; 1524 case BTC_PS_LPS_OFF: 1525 btc8723b2ant_ps_tdma_check_for_power_save_state(btcoexist, 1526 false); 1527 btcoexist->btc_set(btcoexist, BTC_SET_ACT_LEAVE_LPS, NULL); 1528 coex_sta->force_lps_on = false; 1529 break; 1530 default: 1531 break; 1532 } 1533 } 1534 1535 static void btc8723b2ant_coex_alloff(struct btc_coexist *btcoexist) 1536 { 1537 /* fw all off */ 1538 btc8723b2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0); 1539 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1); 1540 btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); 1541 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); 1542 1543 /* sw all off */ 1544 btc8723b2ant_sw_mechanism(btcoexist, false, false, false, false); 1545 1546 /* hw all off */ 1547 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); 1548 btc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); 1549 } 1550 1551 static void btc8723b2ant_init_coex_dm(struct btc_coexist *btcoexist) 1552 { 1553 /* force to reset coex mechanism*/ 1554 btc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); 1555 btc8723b2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0); 1556 1557 btc8723b2ant_ps_tdma(btcoexist, FORCE_EXEC, false, 1); 1558 btc8723b2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 6); 1559 btc8723b2ant_dec_bt_pwr(btcoexist, FORCE_EXEC, 0); 1560 1561 btc8723b2ant_sw_mechanism(btcoexist, false, false, false, false); 1562 1563 coex_sta->pop_event_cnt = 0; 1564 } 1565 1566 static void btc8723b2ant_action_bt_inquiry(struct btc_coexist *btcoexist) 1567 { 1568 struct rtl_priv *rtlpriv = btcoexist->adapter; 1569 bool wifi_connected = false; 1570 bool low_pwr_disable = true; 1571 bool scan = false, link = false, roam = false; 1572 1573 btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER, 1574 &low_pwr_disable); 1575 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, 1576 &wifi_connected); 1577 1578 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); 1579 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); 1580 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); 1581 1582 btc8723b2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0); 1583 1584 if (coex_sta->bt_abnormal_scan) { 1585 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 23); 1586 btc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 3); 1587 } else if (scan || link || roam) { 1588 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1589 "[BTCoex], Wifi link process + BT Inq/Page!!\n"); 1590 btc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 15); 1591 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22); 1592 } else if (wifi_connected) { 1593 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1594 "[BTCoex], Wifi connected + BT Inq/Page!!\n"); 1595 btc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 15); 1596 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22); 1597 } else { 1598 btc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); 1599 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1); 1600 } 1601 btc8723b2ant_fw_dac_swing_lvl(btcoexist, FORCE_EXEC, 6); 1602 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); 1603 1604 btc8723b2ant_sw_mechanism(btcoexist, false, false, false, false); 1605 } 1606 1607 static void btc8723b2ant_action_wifi_link_process(struct btc_coexist 1608 *btcoexist) 1609 { 1610 struct rtl_priv *rtlpriv = btcoexist->adapter; 1611 u32 u32tmp; 1612 u8 u8tmpa, u8tmpb; 1613 1614 btc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 15); 1615 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 22); 1616 1617 btc8723b2ant_sw_mechanism(btcoexist, false, false, false, false); 1618 1619 u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x948); 1620 u8tmpa = btcoexist->btc_read_1byte(btcoexist, 0x765); 1621 u8tmpb = btcoexist->btc_read_1byte(btcoexist, 0x76e); 1622 1623 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1624 "[BTCoex], 0x948 = 0x%x, 0x765 = 0x%x, 0x76e = 0x%x\n", 1625 u32tmp, u8tmpa, u8tmpb); 1626 } 1627 1628 static bool btc8723b2ant_action_wifi_idle_process(struct btc_coexist *btcoexist) 1629 { 1630 struct rtl_priv *rtlpriv = btcoexist->adapter; 1631 u8 wifi_rssi_state1; 1632 u8 ap_num = 0; 1633 u8 tmp = BT_8723B_2ANT_WIFI_RSSI_COEXSWITCH_THRES - 1634 coex_dm->switch_thres_offset - coex_dm->switch_thres_offset; 1635 1636 btc8723b2ant_wifi_rssi_state(btcoexist, 0, 2, 15, 0); 1637 wifi_rssi_state1 = btc8723b2ant_wifi_rssi_state(btcoexist, 1, 2, 1638 tmp, 0); 1639 tmp = BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES - 1640 coex_dm->switch_thres_offset - coex_dm->switch_thres_offset; 1641 btc8723b2ant_bt_rssi_state(btcoexist, 2, tmp, 0); 1642 1643 btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, &ap_num); 1644 1645 /* office environment */ 1646 if (BTC_RSSI_HIGH(wifi_rssi_state1) && (coex_sta->hid_exist) && 1647 (coex_sta->a2dp_exist)) { 1648 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1649 "[BTCoex], Wifi idle process for BT HID+A2DP exist!!\n"); 1650 1651 btc8723b2ant_dac_swing(btcoexist, NORMAL_EXEC, true, 0x6); 1652 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); 1653 1654 /* sw all off */ 1655 btc8723b2ant_sw_mechanism(btcoexist, false, false, false, 1656 false); 1657 btc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); 1658 btc8723b2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 1659 0x0, 0x0); 1660 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1); 1661 1662 return true; 1663 } 1664 1665 btc8723b2ant_dac_swing(btcoexist, NORMAL_EXEC, true, 0x18); 1666 return false; 1667 } 1668 1669 static bool btc8723b2ant_is_common_action(struct btc_coexist *btcoexist) 1670 { 1671 struct rtl_priv *rtlpriv = btcoexist->adapter; 1672 bool common = false, wifi_connected = false; 1673 bool wifi_busy = false; 1674 bool bt_hs_on = false, low_pwr_disable = false; 1675 1676 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); 1677 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, 1678 &wifi_connected); 1679 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); 1680 1681 if (!wifi_connected) { 1682 low_pwr_disable = false; 1683 btcoexist->btc_set(btcoexist, BTC_SET_ACT_DISABLE_LOW_POWER, 1684 &low_pwr_disable); 1685 btc8723b2ant_limited_rx(btcoexist, NORMAL_EXEC, 1686 false, false, 0x8); 1687 1688 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1689 "[BTCoex], Wifi non-connected idle!!\n"); 1690 1691 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 1692 0x0); 1693 btc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); 1694 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1); 1695 btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); 1696 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); 1697 1698 btc8723b2ant_sw_mechanism(btcoexist, false, false, false, 1699 false); 1700 1701 common = true; 1702 } else { 1703 if (BT_8723B_2ANT_BT_STATUS_NON_CONNECTED_IDLE == 1704 coex_dm->bt_status) { 1705 low_pwr_disable = false; 1706 btcoexist->btc_set(btcoexist, 1707 BTC_SET_ACT_DISABLE_LOW_POWER, 1708 &low_pwr_disable); 1709 btc8723b2ant_limited_rx(btcoexist, NORMAL_EXEC, 1710 false, false, 0x8); 1711 1712 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1713 "[BTCoex], Wifi connected + BT non connected-idle!!\n"); 1714 1715 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 1716 0xfffff, 0x0); 1717 btc8723b2ant_coex_table_with_type(btcoexist, 1718 NORMAL_EXEC, 0); 1719 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1); 1720 btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 1721 0xb); 1722 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); 1723 1724 btc8723b2ant_sw_mechanism(btcoexist, false, false, 1725 false, false); 1726 1727 common = true; 1728 } else if (BT_8723B_2ANT_BT_STATUS_CONNECTED_IDLE == 1729 coex_dm->bt_status) { 1730 low_pwr_disable = true; 1731 btcoexist->btc_set(btcoexist, 1732 BTC_SET_ACT_DISABLE_LOW_POWER, 1733 &low_pwr_disable); 1734 1735 if (bt_hs_on) 1736 return false; 1737 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1738 "[BTCoex], Wifi connected + BT connected-idle!!\n"); 1739 btc8723b2ant_limited_rx(btcoexist, NORMAL_EXEC, 1740 false, false, 0x8); 1741 1742 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 1743 0xfffff, 0x0); 1744 btc8723b2ant_coex_table_with_type(btcoexist, 1745 NORMAL_EXEC, 0); 1746 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1); 1747 btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 1748 0xb); 1749 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); 1750 1751 btc8723b2ant_sw_mechanism(btcoexist, true, false, 1752 false, false); 1753 1754 common = true; 1755 } else { 1756 low_pwr_disable = true; 1757 btcoexist->btc_set(btcoexist, 1758 BTC_SET_ACT_DISABLE_LOW_POWER, 1759 &low_pwr_disable); 1760 1761 if (wifi_busy) { 1762 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1763 "[BTCoex], Wifi Connected-Busy + BT Busy!!\n"); 1764 common = false; 1765 } else { 1766 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1767 "[BTCoex], Wifi Connected-Idle + BT Busy!!\n"); 1768 1769 common = 1770 btc8723b2ant_action_wifi_idle_process( 1771 btcoexist); 1772 } 1773 } 1774 } 1775 1776 return common; 1777 } 1778 1779 static void btc8723b2ant_tdma_duration_adjust(struct btc_coexist *btcoexist, 1780 bool sco_hid, bool tx_pause, 1781 u8 max_interval) 1782 { 1783 struct rtl_priv *rtlpriv = btcoexist->adapter; 1784 static s32 up, dn, m, n, wait_count; 1785 /*0: no change, +1: increase WiFi duration, -1: decrease WiFi duration*/ 1786 s32 result; 1787 u8 retry_count = 0; 1788 1789 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1790 "[BTCoex], TdmaDurationAdjust()\n"); 1791 1792 if (!coex_dm->auto_tdma_adjust) { 1793 coex_dm->auto_tdma_adjust = true; 1794 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1795 "[BTCoex], first run TdmaDurationAdjust()!!\n"); 1796 if (sco_hid) { 1797 if (tx_pause) { 1798 if (max_interval == 1) { 1799 btc8723b2ant_ps_tdma(btcoexist, 1800 NORMAL_EXEC, 1801 true, 13); 1802 coex_dm->ps_tdma_du_adj_type = 13; 1803 } else if (max_interval == 2) { 1804 btc8723b2ant_ps_tdma(btcoexist, 1805 NORMAL_EXEC, 1806 true, 14); 1807 coex_dm->ps_tdma_du_adj_type = 14; 1808 } else if (max_interval == 3) { 1809 btc8723b2ant_ps_tdma(btcoexist, 1810 NORMAL_EXEC, 1811 true, 15); 1812 coex_dm->ps_tdma_du_adj_type = 15; 1813 } else { 1814 btc8723b2ant_ps_tdma(btcoexist, 1815 NORMAL_EXEC, 1816 true, 15); 1817 coex_dm->ps_tdma_du_adj_type = 15; 1818 } 1819 } else { 1820 if (max_interval == 1) { 1821 btc8723b2ant_ps_tdma(btcoexist, 1822 NORMAL_EXEC, 1823 true, 9); 1824 coex_dm->ps_tdma_du_adj_type = 9; 1825 } else if (max_interval == 2) { 1826 btc8723b2ant_ps_tdma(btcoexist, 1827 NORMAL_EXEC, 1828 true, 10); 1829 coex_dm->ps_tdma_du_adj_type = 10; 1830 } else if (max_interval == 3) { 1831 btc8723b2ant_ps_tdma(btcoexist, 1832 NORMAL_EXEC, 1833 true, 11); 1834 coex_dm->ps_tdma_du_adj_type = 11; 1835 } else { 1836 btc8723b2ant_ps_tdma(btcoexist, 1837 NORMAL_EXEC, 1838 true, 11); 1839 coex_dm->ps_tdma_du_adj_type = 11; 1840 } 1841 } 1842 } else { 1843 if (tx_pause) { 1844 if (max_interval == 1) { 1845 btc8723b2ant_ps_tdma(btcoexist, 1846 NORMAL_EXEC, 1847 true, 5); 1848 coex_dm->ps_tdma_du_adj_type = 5; 1849 } else if (max_interval == 2) { 1850 btc8723b2ant_ps_tdma(btcoexist, 1851 NORMAL_EXEC, 1852 true, 6); 1853 coex_dm->ps_tdma_du_adj_type = 6; 1854 } else if (max_interval == 3) { 1855 btc8723b2ant_ps_tdma(btcoexist, 1856 NORMAL_EXEC, 1857 true, 7); 1858 coex_dm->ps_tdma_du_adj_type = 7; 1859 } else { 1860 btc8723b2ant_ps_tdma(btcoexist, 1861 NORMAL_EXEC, 1862 true, 7); 1863 coex_dm->ps_tdma_du_adj_type = 7; 1864 } 1865 } else { 1866 if (max_interval == 1) { 1867 btc8723b2ant_ps_tdma(btcoexist, 1868 NORMAL_EXEC, 1869 true, 1); 1870 coex_dm->ps_tdma_du_adj_type = 1; 1871 } else if (max_interval == 2) { 1872 btc8723b2ant_ps_tdma(btcoexist, 1873 NORMAL_EXEC, 1874 true, 2); 1875 coex_dm->ps_tdma_du_adj_type = 2; 1876 } else if (max_interval == 3) { 1877 btc8723b2ant_ps_tdma(btcoexist, 1878 NORMAL_EXEC, 1879 true, 3); 1880 coex_dm->ps_tdma_du_adj_type = 3; 1881 } else { 1882 btc8723b2ant_ps_tdma(btcoexist, 1883 NORMAL_EXEC, 1884 true, 3); 1885 coex_dm->ps_tdma_du_adj_type = 3; 1886 } 1887 } 1888 } 1889 1890 up = 0; 1891 dn = 0; 1892 m = 1; 1893 n = 3; 1894 result = 0; 1895 wait_count = 0; 1896 } else { 1897 /*accquire the BT TRx retry count from BT_Info byte2*/ 1898 retry_count = coex_sta->bt_retry_cnt; 1899 1900 if ((coex_sta->low_priority_tx) > 1050 || 1901 (coex_sta->low_priority_rx) > 1250) 1902 retry_count++; 1903 1904 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1905 "[BTCoex], retry_count = %d\n", retry_count); 1906 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1907 "[BTCoex], up=%d, dn=%d, m=%d, n=%d, wait_count=%d\n", 1908 up, dn, m, n, wait_count); 1909 result = 0; 1910 wait_count++; 1911 /* no retry in the last 2-second duration*/ 1912 if (retry_count == 0) { 1913 up++; 1914 dn--; 1915 1916 if (dn <= 0) 1917 dn = 0; 1918 1919 if (up >= n) { 1920 /* if retry count during continuous n*2 1921 * seconds is 0, enlarge WiFi duration 1922 */ 1923 wait_count = 0; 1924 n = 3; 1925 up = 0; 1926 dn = 0; 1927 result = 1; 1928 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1929 "[BTCoex], Increase wifi duration!!\n"); 1930 } /* <=3 retry in the last 2-second duration*/ 1931 } else if (retry_count <= 3) { 1932 up--; 1933 dn++; 1934 1935 if (up <= 0) 1936 up = 0; 1937 1938 if (dn == 2) { 1939 /* if continuous 2 retry count(every 2 1940 * seconds) >0 and < 3, reduce WiFi duration 1941 */ 1942 if (wait_count <= 2) 1943 /* avoid loop between the two levels */ 1944 m++; 1945 else 1946 m = 1; 1947 1948 if (m >= 20) 1949 /* maximum of m = 20 ' will recheck if 1950 * need to adjust wifi duration in 1951 * maximum time interval 120 seconds 1952 */ 1953 m = 20; 1954 1955 n = 3 * m; 1956 up = 0; 1957 dn = 0; 1958 wait_count = 0; 1959 result = -1; 1960 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1961 "[BTCoex], Decrease wifi duration for retry_counter<3!!\n"); 1962 } 1963 } else { 1964 /* retry count > 3, once retry count > 3, to reduce 1965 * WiFi duration 1966 */ 1967 if (wait_count == 1) 1968 /* to avoid loop between the two levels */ 1969 m++; 1970 else 1971 m = 1; 1972 1973 if (m >= 20) 1974 /* maximum of m = 20 ' will recheck if need to 1975 * adjust wifi duration in maximum time interval 1976 * 120 seconds 1977 */ 1978 m = 20; 1979 1980 n = 3 * m; 1981 up = 0; 1982 dn = 0; 1983 wait_count = 0; 1984 result = -1; 1985 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1986 "[BTCoex], Decrease wifi duration for retry_counter>3!!\n"); 1987 } 1988 1989 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 1990 "[BTCoex], max Interval = %d\n", max_interval); 1991 if (max_interval == 1) { 1992 if (tx_pause) { 1993 if (coex_dm->cur_ps_tdma == 71) { 1994 btc8723b2ant_ps_tdma(btcoexist, 1995 NORMAL_EXEC, 1996 true, 5); 1997 coex_dm->ps_tdma_du_adj_type = 5; 1998 } else if (coex_dm->cur_ps_tdma == 1) { 1999 btc8723b2ant_ps_tdma(btcoexist, 2000 NORMAL_EXEC, 2001 true, 5); 2002 coex_dm->ps_tdma_du_adj_type = 5; 2003 } else if (coex_dm->cur_ps_tdma == 2) { 2004 btc8723b2ant_ps_tdma(btcoexist, 2005 NORMAL_EXEC, 2006 true, 6); 2007 coex_dm->ps_tdma_du_adj_type = 6; 2008 } else if (coex_dm->cur_ps_tdma == 3) { 2009 btc8723b2ant_ps_tdma(btcoexist, 2010 NORMAL_EXEC, 2011 true, 7); 2012 coex_dm->ps_tdma_du_adj_type = 7; 2013 } else if (coex_dm->cur_ps_tdma == 4) { 2014 btc8723b2ant_ps_tdma(btcoexist, 2015 NORMAL_EXEC, 2016 true, 8); 2017 coex_dm->ps_tdma_du_adj_type = 8; 2018 } 2019 if (coex_dm->cur_ps_tdma == 9) { 2020 btc8723b2ant_ps_tdma(btcoexist, 2021 NORMAL_EXEC, 2022 true, 13); 2023 coex_dm->ps_tdma_du_adj_type = 13; 2024 } else if (coex_dm->cur_ps_tdma == 10) { 2025 btc8723b2ant_ps_tdma(btcoexist, 2026 NORMAL_EXEC, 2027 true, 14); 2028 coex_dm->ps_tdma_du_adj_type = 14; 2029 } else if (coex_dm->cur_ps_tdma == 11) { 2030 btc8723b2ant_ps_tdma(btcoexist, 2031 NORMAL_EXEC, 2032 true, 15); 2033 coex_dm->ps_tdma_du_adj_type = 15; 2034 } else if (coex_dm->cur_ps_tdma == 12) { 2035 btc8723b2ant_ps_tdma(btcoexist, 2036 NORMAL_EXEC, 2037 true, 16); 2038 coex_dm->ps_tdma_du_adj_type = 16; 2039 } 2040 2041 if (result == -1) { 2042 if (coex_dm->cur_ps_tdma == 5) { 2043 btc8723b2ant_ps_tdma( 2044 btcoexist, NORMAL_EXEC, 2045 true, 6); 2046 coex_dm->ps_tdma_du_adj_type = 2047 6; 2048 } else if (coex_dm->cur_ps_tdma == 6) { 2049 btc8723b2ant_ps_tdma( 2050 btcoexist, NORMAL_EXEC, 2051 true, 7); 2052 coex_dm->ps_tdma_du_adj_type = 2053 7; 2054 } else if (coex_dm->cur_ps_tdma == 7) { 2055 btc8723b2ant_ps_tdma( 2056 btcoexist, NORMAL_EXEC, 2057 true, 8); 2058 coex_dm->ps_tdma_du_adj_type = 2059 8; 2060 } else if (coex_dm->cur_ps_tdma == 13) { 2061 btc8723b2ant_ps_tdma( 2062 btcoexist, NORMAL_EXEC, 2063 true, 14); 2064 coex_dm->ps_tdma_du_adj_type = 2065 14; 2066 } else if (coex_dm->cur_ps_tdma == 14) { 2067 btc8723b2ant_ps_tdma( 2068 btcoexist, NORMAL_EXEC, 2069 true, 15); 2070 coex_dm->ps_tdma_du_adj_type = 2071 15; 2072 } else if (coex_dm->cur_ps_tdma == 15) { 2073 btc8723b2ant_ps_tdma( 2074 btcoexist, NORMAL_EXEC, 2075 true, 16); 2076 coex_dm->ps_tdma_du_adj_type = 2077 16; 2078 } 2079 } else if (result == 1) { 2080 if (coex_dm->cur_ps_tdma == 8) { 2081 btc8723b2ant_ps_tdma( 2082 btcoexist, NORMAL_EXEC, 2083 true, 7); 2084 coex_dm->ps_tdma_du_adj_type = 2085 7; 2086 } else if (coex_dm->cur_ps_tdma == 7) { 2087 btc8723b2ant_ps_tdma( 2088 btcoexist, NORMAL_EXEC, 2089 true, 6); 2090 coex_dm->ps_tdma_du_adj_type = 2091 6; 2092 } else if (coex_dm->cur_ps_tdma == 6) { 2093 btc8723b2ant_ps_tdma( 2094 btcoexist, NORMAL_EXEC, 2095 true, 5); 2096 coex_dm->ps_tdma_du_adj_type = 2097 5; 2098 } else if (coex_dm->cur_ps_tdma == 16) { 2099 btc8723b2ant_ps_tdma( 2100 btcoexist, NORMAL_EXEC, 2101 true, 15); 2102 coex_dm->ps_tdma_du_adj_type = 2103 15; 2104 } else if (coex_dm->cur_ps_tdma == 15) { 2105 btc8723b2ant_ps_tdma( 2106 btcoexist, NORMAL_EXEC, 2107 true, 14); 2108 coex_dm->ps_tdma_du_adj_type = 2109 14; 2110 } else if (coex_dm->cur_ps_tdma == 14) { 2111 btc8723b2ant_ps_tdma( 2112 btcoexist, NORMAL_EXEC, 2113 true, 13); 2114 coex_dm->ps_tdma_du_adj_type = 2115 13; 2116 } 2117 } 2118 } else { 2119 if (coex_dm->cur_ps_tdma == 5) { 2120 btc8723b2ant_ps_tdma(btcoexist, 2121 NORMAL_EXEC, 2122 true, 71); 2123 coex_dm->ps_tdma_du_adj_type = 71; 2124 } else if (coex_dm->cur_ps_tdma == 6) { 2125 btc8723b2ant_ps_tdma(btcoexist, 2126 NORMAL_EXEC, 2127 true, 2); 2128 coex_dm->ps_tdma_du_adj_type = 2; 2129 } else if (coex_dm->cur_ps_tdma == 7) { 2130 btc8723b2ant_ps_tdma(btcoexist, 2131 NORMAL_EXEC, 2132 true, 3); 2133 coex_dm->ps_tdma_du_adj_type = 3; 2134 } else if (coex_dm->cur_ps_tdma == 8) { 2135 btc8723b2ant_ps_tdma(btcoexist, 2136 NORMAL_EXEC, 2137 true, 4); 2138 coex_dm->ps_tdma_du_adj_type = 4; 2139 } 2140 if (coex_dm->cur_ps_tdma == 13) { 2141 btc8723b2ant_ps_tdma(btcoexist, 2142 NORMAL_EXEC, 2143 true, 9); 2144 coex_dm->ps_tdma_du_adj_type = 9; 2145 } else if (coex_dm->cur_ps_tdma == 14) { 2146 btc8723b2ant_ps_tdma(btcoexist, 2147 NORMAL_EXEC, 2148 true, 10); 2149 coex_dm->ps_tdma_du_adj_type = 10; 2150 } else if (coex_dm->cur_ps_tdma == 15) { 2151 btc8723b2ant_ps_tdma(btcoexist, 2152 NORMAL_EXEC, 2153 true, 11); 2154 coex_dm->ps_tdma_du_adj_type = 11; 2155 } else if (coex_dm->cur_ps_tdma == 16) { 2156 btc8723b2ant_ps_tdma(btcoexist, 2157 NORMAL_EXEC, 2158 true, 12); 2159 coex_dm->ps_tdma_du_adj_type = 12; 2160 } 2161 2162 if (result == -1) { 2163 if (coex_dm->cur_ps_tdma == 71) { 2164 btc8723b2ant_ps_tdma( 2165 btcoexist, NORMAL_EXEC, 2166 true, 1); 2167 coex_dm->ps_tdma_du_adj_type = 2168 1; 2169 } else if (coex_dm->cur_ps_tdma == 1) { 2170 btc8723b2ant_ps_tdma( 2171 btcoexist, NORMAL_EXEC, 2172 true, 2); 2173 coex_dm->ps_tdma_du_adj_type = 2174 2; 2175 } else if (coex_dm->cur_ps_tdma == 2) { 2176 btc8723b2ant_ps_tdma( 2177 btcoexist, NORMAL_EXEC, 2178 true, 3); 2179 coex_dm->ps_tdma_du_adj_type = 2180 3; 2181 } else if (coex_dm->cur_ps_tdma == 3) { 2182 btc8723b2ant_ps_tdma( 2183 btcoexist, NORMAL_EXEC, 2184 true, 4); 2185 coex_dm->ps_tdma_du_adj_type = 2186 4; 2187 } else if (coex_dm->cur_ps_tdma == 9) { 2188 btc8723b2ant_ps_tdma( 2189 btcoexist, NORMAL_EXEC, 2190 true, 10); 2191 coex_dm->ps_tdma_du_adj_type = 2192 10; 2193 } else if (coex_dm->cur_ps_tdma == 10) { 2194 btc8723b2ant_ps_tdma( 2195 btcoexist, NORMAL_EXEC, 2196 true, 11); 2197 coex_dm->ps_tdma_du_adj_type = 2198 11; 2199 } else if (coex_dm->cur_ps_tdma == 11) { 2200 btc8723b2ant_ps_tdma( 2201 btcoexist, NORMAL_EXEC, 2202 true, 12); 2203 coex_dm->ps_tdma_du_adj_type = 2204 12; 2205 } 2206 } else if (result == 1) { 2207 if (coex_dm->cur_ps_tdma == 4) { 2208 btc8723b2ant_ps_tdma( 2209 btcoexist, NORMAL_EXEC, 2210 true, 3); 2211 coex_dm->ps_tdma_du_adj_type = 2212 3; 2213 } else if (coex_dm->cur_ps_tdma == 3) { 2214 btc8723b2ant_ps_tdma( 2215 btcoexist, NORMAL_EXEC, 2216 true, 2); 2217 coex_dm->ps_tdma_du_adj_type = 2218 2; 2219 } else if (coex_dm->cur_ps_tdma == 2) { 2220 btc8723b2ant_ps_tdma( 2221 btcoexist, NORMAL_EXEC, 2222 true, 1); 2223 coex_dm->ps_tdma_du_adj_type = 2224 1; 2225 } else if (coex_dm->cur_ps_tdma == 1) { 2226 btc8723b2ant_ps_tdma( 2227 btcoexist, NORMAL_EXEC, 2228 true, 71); 2229 coex_dm->ps_tdma_du_adj_type = 2230 71; 2231 } else if (coex_dm->cur_ps_tdma == 12) { 2232 btc8723b2ant_ps_tdma( 2233 btcoexist, NORMAL_EXEC, 2234 true, 11); 2235 coex_dm->ps_tdma_du_adj_type = 2236 11; 2237 } else if (coex_dm->cur_ps_tdma == 11) { 2238 btc8723b2ant_ps_tdma( 2239 btcoexist, NORMAL_EXEC, 2240 true, 10); 2241 coex_dm->ps_tdma_du_adj_type = 2242 10; 2243 } else if (coex_dm->cur_ps_tdma == 10) { 2244 btc8723b2ant_ps_tdma( 2245 btcoexist, NORMAL_EXEC, 2246 true, 9); 2247 coex_dm->ps_tdma_du_adj_type = 2248 9; 2249 } 2250 } 2251 } 2252 } else if (max_interval == 2) { 2253 if (tx_pause) { 2254 if (coex_dm->cur_ps_tdma == 1) { 2255 btc8723b2ant_ps_tdma(btcoexist, 2256 NORMAL_EXEC, 2257 true, 6); 2258 coex_dm->ps_tdma_du_adj_type = 6; 2259 } else if (coex_dm->cur_ps_tdma == 2) { 2260 btc8723b2ant_ps_tdma(btcoexist, 2261 NORMAL_EXEC, 2262 true, 6); 2263 coex_dm->ps_tdma_du_adj_type = 6; 2264 } else if (coex_dm->cur_ps_tdma == 3) { 2265 btc8723b2ant_ps_tdma(btcoexist, 2266 NORMAL_EXEC, 2267 true, 7); 2268 coex_dm->ps_tdma_du_adj_type = 7; 2269 } else if (coex_dm->cur_ps_tdma == 4) { 2270 btc8723b2ant_ps_tdma(btcoexist, 2271 NORMAL_EXEC, 2272 true, 8); 2273 coex_dm->ps_tdma_du_adj_type = 8; 2274 } 2275 if (coex_dm->cur_ps_tdma == 9) { 2276 btc8723b2ant_ps_tdma(btcoexist, 2277 NORMAL_EXEC, 2278 true, 14); 2279 coex_dm->ps_tdma_du_adj_type = 14; 2280 } else if (coex_dm->cur_ps_tdma == 10) { 2281 btc8723b2ant_ps_tdma(btcoexist, 2282 NORMAL_EXEC, 2283 true, 14); 2284 coex_dm->ps_tdma_du_adj_type = 14; 2285 } else if (coex_dm->cur_ps_tdma == 11) { 2286 btc8723b2ant_ps_tdma(btcoexist, 2287 NORMAL_EXEC, 2288 true, 15); 2289 coex_dm->ps_tdma_du_adj_type = 15; 2290 } else if (coex_dm->cur_ps_tdma == 12) { 2291 btc8723b2ant_ps_tdma(btcoexist, 2292 NORMAL_EXEC, 2293 true, 16); 2294 coex_dm->ps_tdma_du_adj_type = 16; 2295 } 2296 if (result == -1) { 2297 if (coex_dm->cur_ps_tdma == 5) { 2298 btc8723b2ant_ps_tdma( 2299 btcoexist, NORMAL_EXEC, 2300 true, 6); 2301 coex_dm->ps_tdma_du_adj_type = 2302 6; 2303 } else if (coex_dm->cur_ps_tdma == 6) { 2304 btc8723b2ant_ps_tdma( 2305 btcoexist, NORMAL_EXEC, 2306 true, 7); 2307 coex_dm->ps_tdma_du_adj_type = 2308 7; 2309 } else if (coex_dm->cur_ps_tdma == 7) { 2310 btc8723b2ant_ps_tdma( 2311 btcoexist, NORMAL_EXEC, 2312 true, 8); 2313 coex_dm->ps_tdma_du_adj_type = 2314 8; 2315 } else if (coex_dm->cur_ps_tdma == 13) { 2316 btc8723b2ant_ps_tdma( 2317 btcoexist, NORMAL_EXEC, 2318 true, 14); 2319 coex_dm->ps_tdma_du_adj_type = 2320 14; 2321 } else if (coex_dm->cur_ps_tdma == 14) { 2322 btc8723b2ant_ps_tdma( 2323 btcoexist, NORMAL_EXEC, 2324 true, 15); 2325 coex_dm->ps_tdma_du_adj_type = 2326 15; 2327 } else if (coex_dm->cur_ps_tdma == 15) { 2328 btc8723b2ant_ps_tdma( 2329 btcoexist, NORMAL_EXEC, 2330 true, 16); 2331 coex_dm->ps_tdma_du_adj_type = 2332 16; 2333 } 2334 } else if (result == 1) { 2335 if (coex_dm->cur_ps_tdma == 8) { 2336 btc8723b2ant_ps_tdma( 2337 btcoexist, NORMAL_EXEC, 2338 true, 7); 2339 coex_dm->ps_tdma_du_adj_type = 2340 7; 2341 } else if (coex_dm->cur_ps_tdma == 7) { 2342 btc8723b2ant_ps_tdma( 2343 btcoexist, NORMAL_EXEC, 2344 true, 6); 2345 coex_dm->ps_tdma_du_adj_type = 2346 6; 2347 } else if (coex_dm->cur_ps_tdma == 6) { 2348 btc8723b2ant_ps_tdma( 2349 btcoexist, NORMAL_EXEC, 2350 true, 6); 2351 coex_dm->ps_tdma_du_adj_type = 2352 6; 2353 } else if (coex_dm->cur_ps_tdma == 16) { 2354 btc8723b2ant_ps_tdma( 2355 btcoexist, NORMAL_EXEC, 2356 true, 15); 2357 coex_dm->ps_tdma_du_adj_type = 2358 15; 2359 } else if (coex_dm->cur_ps_tdma == 15) { 2360 btc8723b2ant_ps_tdma( 2361 btcoexist, NORMAL_EXEC, 2362 true, 14); 2363 coex_dm->ps_tdma_du_adj_type = 2364 14; 2365 } else if (coex_dm->cur_ps_tdma == 14) { 2366 btc8723b2ant_ps_tdma( 2367 btcoexist, NORMAL_EXEC, 2368 true, 14); 2369 coex_dm->ps_tdma_du_adj_type = 2370 14; 2371 } 2372 } 2373 } else { 2374 if (coex_dm->cur_ps_tdma == 5) { 2375 btc8723b2ant_ps_tdma(btcoexist, 2376 NORMAL_EXEC, 2377 true, 2); 2378 coex_dm->ps_tdma_du_adj_type = 2; 2379 } else if (coex_dm->cur_ps_tdma == 6) { 2380 btc8723b2ant_ps_tdma(btcoexist, 2381 NORMAL_EXEC, 2382 true, 2); 2383 coex_dm->ps_tdma_du_adj_type = 2; 2384 } else if (coex_dm->cur_ps_tdma == 7) { 2385 btc8723b2ant_ps_tdma(btcoexist, 2386 NORMAL_EXEC, 2387 true, 3); 2388 coex_dm->ps_tdma_du_adj_type = 3; 2389 } else if (coex_dm->cur_ps_tdma == 8) { 2390 btc8723b2ant_ps_tdma(btcoexist, 2391 NORMAL_EXEC, 2392 true, 4); 2393 coex_dm->ps_tdma_du_adj_type = 4; 2394 } 2395 if (coex_dm->cur_ps_tdma == 13) { 2396 btc8723b2ant_ps_tdma(btcoexist, 2397 NORMAL_EXEC, 2398 true, 10); 2399 coex_dm->ps_tdma_du_adj_type = 10; 2400 } else if (coex_dm->cur_ps_tdma == 14) { 2401 btc8723b2ant_ps_tdma(btcoexist, 2402 NORMAL_EXEC, 2403 true, 10); 2404 coex_dm->ps_tdma_du_adj_type = 10; 2405 } else if (coex_dm->cur_ps_tdma == 15) { 2406 btc8723b2ant_ps_tdma(btcoexist, 2407 NORMAL_EXEC, 2408 true, 11); 2409 coex_dm->ps_tdma_du_adj_type = 11; 2410 } else if (coex_dm->cur_ps_tdma == 16) { 2411 btc8723b2ant_ps_tdma(btcoexist, 2412 NORMAL_EXEC, 2413 true, 12); 2414 coex_dm->ps_tdma_du_adj_type = 12; 2415 } 2416 if (result == -1) { 2417 if (coex_dm->cur_ps_tdma == 1) { 2418 btc8723b2ant_ps_tdma( 2419 btcoexist, NORMAL_EXEC, 2420 true, 2); 2421 coex_dm->ps_tdma_du_adj_type = 2422 2; 2423 } else if (coex_dm->cur_ps_tdma == 2) { 2424 btc8723b2ant_ps_tdma( 2425 btcoexist, NORMAL_EXEC, 2426 true, 3); 2427 coex_dm->ps_tdma_du_adj_type = 2428 3; 2429 } else if (coex_dm->cur_ps_tdma == 3) { 2430 btc8723b2ant_ps_tdma( 2431 btcoexist, NORMAL_EXEC, 2432 true, 4); 2433 coex_dm->ps_tdma_du_adj_type = 2434 4; 2435 } else if (coex_dm->cur_ps_tdma == 9) { 2436 btc8723b2ant_ps_tdma( 2437 btcoexist, NORMAL_EXEC, 2438 true, 10); 2439 coex_dm->ps_tdma_du_adj_type = 2440 10; 2441 } else if (coex_dm->cur_ps_tdma == 10) { 2442 btc8723b2ant_ps_tdma( 2443 btcoexist, NORMAL_EXEC, 2444 true, 11); 2445 coex_dm->ps_tdma_du_adj_type = 2446 11; 2447 } else if (coex_dm->cur_ps_tdma == 11) { 2448 btc8723b2ant_ps_tdma( 2449 btcoexist, NORMAL_EXEC, 2450 true, 12); 2451 coex_dm->ps_tdma_du_adj_type = 2452 12; 2453 } 2454 } else if (result == 1) { 2455 if (coex_dm->cur_ps_tdma == 4) { 2456 btc8723b2ant_ps_tdma( 2457 btcoexist, NORMAL_EXEC, 2458 true, 3); 2459 coex_dm->ps_tdma_du_adj_type = 2460 3; 2461 } else if (coex_dm->cur_ps_tdma == 3) { 2462 btc8723b2ant_ps_tdma( 2463 btcoexist, NORMAL_EXEC, 2464 true, 2); 2465 coex_dm->ps_tdma_du_adj_type = 2466 2; 2467 } else if (coex_dm->cur_ps_tdma == 2) { 2468 btc8723b2ant_ps_tdma( 2469 btcoexist, NORMAL_EXEC, 2470 true, 2); 2471 coex_dm->ps_tdma_du_adj_type = 2472 2; 2473 } else if (coex_dm->cur_ps_tdma == 12) { 2474 btc8723b2ant_ps_tdma( 2475 btcoexist, NORMAL_EXEC, 2476 true, 11); 2477 coex_dm->ps_tdma_du_adj_type = 2478 11; 2479 } else if (coex_dm->cur_ps_tdma == 11) { 2480 btc8723b2ant_ps_tdma( 2481 btcoexist, NORMAL_EXEC, 2482 true, 10); 2483 coex_dm->ps_tdma_du_adj_type = 2484 10; 2485 } else if (coex_dm->cur_ps_tdma == 10) { 2486 btc8723b2ant_ps_tdma( 2487 btcoexist, NORMAL_EXEC, 2488 true, 10); 2489 coex_dm->ps_tdma_du_adj_type = 2490 10; 2491 } 2492 } 2493 } 2494 } else if (max_interval == 3) { 2495 if (tx_pause) { 2496 if (coex_dm->cur_ps_tdma == 1) { 2497 btc8723b2ant_ps_tdma(btcoexist, 2498 NORMAL_EXEC, 2499 true, 7); 2500 coex_dm->ps_tdma_du_adj_type = 7; 2501 } else if (coex_dm->cur_ps_tdma == 2) { 2502 btc8723b2ant_ps_tdma(btcoexist, 2503 NORMAL_EXEC, 2504 true, 7); 2505 coex_dm->ps_tdma_du_adj_type = 7; 2506 } else if (coex_dm->cur_ps_tdma == 3) { 2507 btc8723b2ant_ps_tdma(btcoexist, 2508 NORMAL_EXEC, 2509 true, 7); 2510 coex_dm->ps_tdma_du_adj_type = 7; 2511 } else if (coex_dm->cur_ps_tdma == 4) { 2512 btc8723b2ant_ps_tdma(btcoexist, 2513 NORMAL_EXEC, 2514 true, 8); 2515 coex_dm->ps_tdma_du_adj_type = 8; 2516 } 2517 if (coex_dm->cur_ps_tdma == 9) { 2518 btc8723b2ant_ps_tdma(btcoexist, 2519 NORMAL_EXEC, 2520 true, 15); 2521 coex_dm->ps_tdma_du_adj_type = 15; 2522 } else if (coex_dm->cur_ps_tdma == 10) { 2523 btc8723b2ant_ps_tdma(btcoexist, 2524 NORMAL_EXEC, 2525 true, 15); 2526 coex_dm->ps_tdma_du_adj_type = 15; 2527 } else if (coex_dm->cur_ps_tdma == 11) { 2528 btc8723b2ant_ps_tdma(btcoexist, 2529 NORMAL_EXEC, 2530 true, 15); 2531 coex_dm->ps_tdma_du_adj_type = 15; 2532 } else if (coex_dm->cur_ps_tdma == 12) { 2533 btc8723b2ant_ps_tdma(btcoexist, 2534 NORMAL_EXEC, 2535 true, 16); 2536 coex_dm->ps_tdma_du_adj_type = 16; 2537 } 2538 if (result == -1) { 2539 if (coex_dm->cur_ps_tdma == 5) { 2540 btc8723b2ant_ps_tdma( 2541 btcoexist, NORMAL_EXEC, 2542 true, 7); 2543 coex_dm->ps_tdma_du_adj_type = 2544 7; 2545 } else if (coex_dm->cur_ps_tdma == 6) { 2546 btc8723b2ant_ps_tdma( 2547 btcoexist, NORMAL_EXEC, 2548 true, 7); 2549 coex_dm->ps_tdma_du_adj_type = 2550 7; 2551 } else if (coex_dm->cur_ps_tdma == 7) { 2552 btc8723b2ant_ps_tdma( 2553 btcoexist, NORMAL_EXEC, 2554 true, 8); 2555 coex_dm->ps_tdma_du_adj_type = 2556 8; 2557 } else if (coex_dm->cur_ps_tdma == 13) { 2558 btc8723b2ant_ps_tdma( 2559 btcoexist, NORMAL_EXEC, 2560 true, 15); 2561 coex_dm->ps_tdma_du_adj_type = 2562 15; 2563 } else if (coex_dm->cur_ps_tdma == 14) { 2564 btc8723b2ant_ps_tdma( 2565 btcoexist, NORMAL_EXEC, 2566 true, 15); 2567 coex_dm->ps_tdma_du_adj_type = 2568 15; 2569 } else if (coex_dm->cur_ps_tdma == 15) { 2570 btc8723b2ant_ps_tdma( 2571 btcoexist, NORMAL_EXEC, 2572 true, 16); 2573 coex_dm->ps_tdma_du_adj_type = 2574 16; 2575 } 2576 } else if (result == 1) { 2577 if (coex_dm->cur_ps_tdma == 8) { 2578 btc8723b2ant_ps_tdma( 2579 btcoexist, NORMAL_EXEC, 2580 true, 7); 2581 coex_dm->ps_tdma_du_adj_type = 2582 7; 2583 } else if (coex_dm->cur_ps_tdma == 7) { 2584 btc8723b2ant_ps_tdma( 2585 btcoexist, NORMAL_EXEC, 2586 true, 7); 2587 coex_dm->ps_tdma_du_adj_type = 2588 7; 2589 } else if (coex_dm->cur_ps_tdma == 6) { 2590 btc8723b2ant_ps_tdma( 2591 btcoexist, NORMAL_EXEC, 2592 true, 7); 2593 coex_dm->ps_tdma_du_adj_type = 2594 7; 2595 } else if (coex_dm->cur_ps_tdma == 16) { 2596 btc8723b2ant_ps_tdma( 2597 btcoexist, NORMAL_EXEC, 2598 true, 15); 2599 coex_dm->ps_tdma_du_adj_type = 2600 15; 2601 } else if (coex_dm->cur_ps_tdma == 15) { 2602 btc8723b2ant_ps_tdma( 2603 btcoexist, NORMAL_EXEC, 2604 true, 15); 2605 coex_dm->ps_tdma_du_adj_type = 2606 15; 2607 } else if (coex_dm->cur_ps_tdma == 14) { 2608 btc8723b2ant_ps_tdma( 2609 btcoexist, NORMAL_EXEC, 2610 true, 15); 2611 coex_dm->ps_tdma_du_adj_type = 2612 15; 2613 } 2614 } 2615 } else { 2616 if (coex_dm->cur_ps_tdma == 5) { 2617 btc8723b2ant_ps_tdma(btcoexist, 2618 NORMAL_EXEC, 2619 true, 3); 2620 coex_dm->ps_tdma_du_adj_type = 3; 2621 } else if (coex_dm->cur_ps_tdma == 6) { 2622 btc8723b2ant_ps_tdma(btcoexist, 2623 NORMAL_EXEC, 2624 true, 3); 2625 coex_dm->ps_tdma_du_adj_type = 3; 2626 } else if (coex_dm->cur_ps_tdma == 7) { 2627 btc8723b2ant_ps_tdma(btcoexist, 2628 NORMAL_EXEC, 2629 true, 3); 2630 coex_dm->ps_tdma_du_adj_type = 3; 2631 } else if (coex_dm->cur_ps_tdma == 8) { 2632 btc8723b2ant_ps_tdma(btcoexist, 2633 NORMAL_EXEC, 2634 true, 4); 2635 coex_dm->ps_tdma_du_adj_type = 4; 2636 } 2637 if (coex_dm->cur_ps_tdma == 13) { 2638 btc8723b2ant_ps_tdma(btcoexist, 2639 NORMAL_EXEC, 2640 true, 11); 2641 coex_dm->ps_tdma_du_adj_type = 11; 2642 } else if (coex_dm->cur_ps_tdma == 14) { 2643 btc8723b2ant_ps_tdma(btcoexist, 2644 NORMAL_EXEC, 2645 true, 11); 2646 coex_dm->ps_tdma_du_adj_type = 11; 2647 } else if (coex_dm->cur_ps_tdma == 15) { 2648 btc8723b2ant_ps_tdma(btcoexist, 2649 NORMAL_EXEC, 2650 true, 11); 2651 coex_dm->ps_tdma_du_adj_type = 11; 2652 } else if (coex_dm->cur_ps_tdma == 16) { 2653 btc8723b2ant_ps_tdma(btcoexist, 2654 NORMAL_EXEC, 2655 true, 12); 2656 coex_dm->ps_tdma_du_adj_type = 12; 2657 } 2658 if (result == -1) { 2659 if (coex_dm->cur_ps_tdma == 1) { 2660 btc8723b2ant_ps_tdma( 2661 btcoexist, NORMAL_EXEC, 2662 true, 3); 2663 coex_dm->ps_tdma_du_adj_type = 2664 3; 2665 } else if (coex_dm->cur_ps_tdma == 2) { 2666 btc8723b2ant_ps_tdma( 2667 btcoexist, NORMAL_EXEC, 2668 true, 3); 2669 coex_dm->ps_tdma_du_adj_type = 2670 3; 2671 } else if (coex_dm->cur_ps_tdma == 3) { 2672 btc8723b2ant_ps_tdma( 2673 btcoexist, NORMAL_EXEC, 2674 true, 4); 2675 coex_dm->ps_tdma_du_adj_type = 2676 4; 2677 } else if (coex_dm->cur_ps_tdma == 9) { 2678 btc8723b2ant_ps_tdma( 2679 btcoexist, NORMAL_EXEC, 2680 true, 11); 2681 coex_dm->ps_tdma_du_adj_type = 2682 11; 2683 } else if (coex_dm->cur_ps_tdma == 10) { 2684 btc8723b2ant_ps_tdma( 2685 btcoexist, NORMAL_EXEC, 2686 true, 11); 2687 coex_dm->ps_tdma_du_adj_type = 2688 11; 2689 } else if (coex_dm->cur_ps_tdma == 11) { 2690 btc8723b2ant_ps_tdma( 2691 btcoexist, NORMAL_EXEC, 2692 true, 12); 2693 coex_dm->ps_tdma_du_adj_type = 2694 12; 2695 } 2696 } else if (result == 1) { 2697 if (coex_dm->cur_ps_tdma == 4) { 2698 btc8723b2ant_ps_tdma( 2699 btcoexist, NORMAL_EXEC, 2700 true, 3); 2701 coex_dm->ps_tdma_du_adj_type = 2702 3; 2703 } else if (coex_dm->cur_ps_tdma == 3) { 2704 btc8723b2ant_ps_tdma( 2705 btcoexist, NORMAL_EXEC, 2706 true, 3); 2707 coex_dm->ps_tdma_du_adj_type = 2708 3; 2709 } else if (coex_dm->cur_ps_tdma == 2) { 2710 btc8723b2ant_ps_tdma( 2711 btcoexist, NORMAL_EXEC, 2712 true, 3); 2713 coex_dm->ps_tdma_du_adj_type = 2714 3; 2715 } else if (coex_dm->cur_ps_tdma == 12) { 2716 btc8723b2ant_ps_tdma( 2717 btcoexist, NORMAL_EXEC, 2718 true, 11); 2719 coex_dm->ps_tdma_du_adj_type = 2720 11; 2721 } else if (coex_dm->cur_ps_tdma == 11) { 2722 btc8723b2ant_ps_tdma( 2723 btcoexist, NORMAL_EXEC, 2724 true, 11); 2725 coex_dm->ps_tdma_du_adj_type = 2726 11; 2727 } else if (coex_dm->cur_ps_tdma == 10) { 2728 btc8723b2ant_ps_tdma( 2729 btcoexist, NORMAL_EXEC, 2730 true, 11); 2731 coex_dm->ps_tdma_du_adj_type = 2732 11; 2733 } 2734 } 2735 } 2736 } 2737 } 2738 2739 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2740 "[BTCoex], max Interval = %d\n", max_interval); 2741 2742 /* if current PsTdma not match with the recorded one (scan, dhcp, ...), 2743 * then we have to adjust it back to the previous recorded one. 2744 */ 2745 if (coex_dm->cur_ps_tdma != coex_dm->ps_tdma_du_adj_type) { 2746 bool scan = false, link = false, roam = false; 2747 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2748 "[BTCoex], PsTdma type mismatch!!!, curPsTdma=%d, recordPsTdma=%d\n", 2749 coex_dm->cur_ps_tdma, coex_dm->ps_tdma_du_adj_type); 2750 2751 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); 2752 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); 2753 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); 2754 2755 if (!scan && !link && !roam) 2756 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 2757 coex_dm->ps_tdma_du_adj_type); 2758 else 2759 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 2760 "[BTCoex], roaming/link/scan is under progress, will adjust next time!!!\n"); 2761 } 2762 } 2763 2764 /* SCO only or SCO+PAN(HS) */ 2765 static void btc8723b2ant_action_sco(struct btc_coexist *btcoexist) 2766 { 2767 u8 bt_rssi_state; 2768 u32 wifi_bw; 2769 2770 btc8723b2ant_wifi_rssi_state(btcoexist, 0, 2, 15, 0); 2771 bt_rssi_state = btc8723b2ant_bt_rssi_state( 2772 btcoexist, 2, BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES - 2773 coex_dm->switch_thres_offset, 2774 0); 2775 2776 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); 2777 2778 btc8723b2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); 2779 btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 4); 2780 2781 if (BTC_RSSI_HIGH(bt_rssi_state)) 2782 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); 2783 else 2784 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); 2785 2786 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); 2787 2788 if (BTC_WIFI_BW_LEGACY == wifi_bw) 2789 /* for SCO quality at 11b/g mode */ 2790 btc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 2); 2791 else 2792 /* for SCO quality & wifi performance balance at 11n mode */ 2793 btc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 8); 2794 2795 /* for voice quality */ 2796 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 0); 2797 2798 /* sw mechanism */ 2799 if (BTC_WIFI_BW_HT40 == wifi_bw) { 2800 btc8723b2ant_sw_mechanism(btcoexist, true, true, 2801 false, false); 2802 } else { 2803 btc8723b2ant_sw_mechanism(btcoexist, false, true, 2804 false, false); 2805 } 2806 } 2807 2808 static void btc8723b2ant_action_hid(struct btc_coexist *btcoexist) 2809 { 2810 u8 bt_rssi_state; 2811 u32 wifi_bw; 2812 u8 tmp = BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES - 2813 coex_dm->switch_thres_offset; 2814 2815 btc8723b2ant_wifi_rssi_state(btcoexist, 0, 2, 15, 0); 2816 bt_rssi_state = btc8723b2ant_bt_rssi_state(btcoexist, 2, tmp, 0); 2817 2818 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); 2819 2820 btc8723b2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); 2821 btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); 2822 2823 if (BTC_RSSI_HIGH(bt_rssi_state)) 2824 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); 2825 else 2826 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); 2827 2828 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); 2829 2830 if (wifi_bw == BTC_WIFI_BW_LEGACY) 2831 /* for HID at 11b/g mode */ 2832 btc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); 2833 else 2834 /* for HID quality & wifi performance balance at 11n mode */ 2835 btc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 9); 2836 2837 btc8723b2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0); 2838 2839 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) || 2840 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) 2841 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 9); 2842 else 2843 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 13); 2844 2845 /* sw mechanism */ 2846 if (wifi_bw == BTC_WIFI_BW_HT40) 2847 btc8723b2ant_sw_mechanism(btcoexist, true, true, false, false); 2848 else 2849 btc8723b2ant_sw_mechanism(btcoexist, false, true, false, false); 2850 } 2851 2852 /* A2DP only / PAN(EDR) only/ A2DP+PAN(HS) */ 2853 static void btc8723b2ant_action_a2dp(struct btc_coexist *btcoexist) 2854 { 2855 u8 wifi_rssi_state1, bt_rssi_state; 2856 u32 wifi_bw; 2857 u8 ap_num = 0; 2858 u8 tmp = BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES - 2859 coex_dm->switch_thres_offset; 2860 2861 btc8723b2ant_wifi_rssi_state(btcoexist, 0, 2, 15, 0); 2862 wifi_rssi_state1 = btc8723b2ant_wifi_rssi_state(btcoexist, 1, 2, 40, 0); 2863 bt_rssi_state = btc8723b2ant_bt_rssi_state(btcoexist, 2, tmp, 0); 2864 2865 btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, &ap_num); 2866 2867 /* define the office environment */ 2868 /* driver don't know AP num in Linux, so we will never enter this if */ 2869 if (ap_num >= 10 && BTC_RSSI_HIGH(wifi_rssi_state1)) { 2870 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 2871 0x0); 2872 btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); 2873 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, false); 2874 btc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); 2875 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1); 2876 2877 /* sw mechanism */ 2878 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); 2879 if (BTC_WIFI_BW_HT40 == wifi_bw) { 2880 btc8723b2ant_sw_mechanism(btcoexist, true, false, 2881 false, false); 2882 } else { 2883 btc8723b2ant_sw_mechanism(btcoexist, false, false, 2884 false, false); 2885 } 2886 return; 2887 } 2888 2889 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); 2890 btc8723b2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); 2891 2892 btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); 2893 2894 if (BTC_RSSI_HIGH(bt_rssi_state)) 2895 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); 2896 else 2897 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); 2898 2899 if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) { 2900 btc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); 2901 btc8723b2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 2902 0x0, 0x0); 2903 } else { 2904 btc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 13); 2905 btc8723b2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50, 2906 0x4); 2907 } 2908 2909 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) || 2910 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) 2911 btc8723b2ant_tdma_duration_adjust(btcoexist, false, 2912 false, 1); 2913 else 2914 btc8723b2ant_tdma_duration_adjust(btcoexist, false, true, 1); 2915 2916 /* sw mechanism */ 2917 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); 2918 if (BTC_WIFI_BW_HT40 == wifi_bw) { 2919 btc8723b2ant_sw_mechanism(btcoexist, true, false, 2920 false, false); 2921 } else { 2922 btc8723b2ant_sw_mechanism(btcoexist, false, false, 2923 false, false); 2924 } 2925 } 2926 2927 static void btc8723b2ant_action_a2dp_pan_hs(struct btc_coexist *btcoexist) 2928 { 2929 u8 wifi_rssi_state1, bt_rssi_state; 2930 u32 wifi_bw; 2931 u8 tmp = BT_8723B_2ANT_WIFI_RSSI_COEXSWITCH_THRES - 2932 coex_dm->switch_thres_offset; 2933 2934 btc8723b2ant_wifi_rssi_state(btcoexist, 0, 2, 15, 0); 2935 wifi_rssi_state1 = btc8723b2ant_wifi_rssi_state(btcoexist, 1, 2, 2936 tmp, 0); 2937 tmp = BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES - 2938 coex_dm->switch_thres_offset; 2939 bt_rssi_state = btc8723b2ant_bt_rssi_state(btcoexist, 2, tmp, 0); 2940 2941 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); 2942 2943 btc8723b2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); 2944 btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); 2945 2946 if (BTC_RSSI_HIGH(bt_rssi_state)) 2947 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); 2948 else 2949 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); 2950 2951 if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) { 2952 btc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); 2953 btc8723b2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 2954 0x0, 0x0); 2955 } else { 2956 btc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 13); 2957 btc8723b2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50, 2958 0x4); 2959 } 2960 2961 btc8723b2ant_tdma_duration_adjust(btcoexist, false, true, 2); 2962 2963 /* sw mechanism */ 2964 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); 2965 if (BTC_WIFI_BW_HT40 == wifi_bw) { 2966 btc8723b2ant_sw_mechanism(btcoexist, true, false, 2967 false, false); 2968 } else { 2969 btc8723b2ant_sw_mechanism(btcoexist, false, false, 2970 false, false); 2971 } 2972 } 2973 2974 static void btc8723b2ant_action_pan_edr(struct btc_coexist *btcoexist) 2975 { 2976 u8 wifi_rssi_state1, bt_rssi_state; 2977 u32 wifi_bw; 2978 u8 tmp = BT_8723B_2ANT_WIFI_RSSI_COEXSWITCH_THRES - 2979 coex_dm->switch_thres_offset; 2980 2981 btc8723b2ant_wifi_rssi_state(btcoexist, 0, 2, 15, 0); 2982 wifi_rssi_state1 = btc8723b2ant_wifi_rssi_state(btcoexist, 1, 2, 2983 tmp, 0); 2984 tmp = BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES - 2985 coex_dm->switch_thres_offset; 2986 bt_rssi_state = btc8723b2ant_bt_rssi_state(btcoexist, 2, tmp, 0); 2987 2988 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); 2989 2990 btc8723b2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); 2991 btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); 2992 2993 if (BTC_RSSI_HIGH(bt_rssi_state)) 2994 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); 2995 else 2996 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); 2997 2998 if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) { 2999 btc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 10); 3000 btc8723b2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 3001 0x0, 0x0); 3002 } else { 3003 btc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 13); 3004 btc8723b2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50, 3005 0x4); 3006 } 3007 3008 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) || 3009 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) 3010 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 1); 3011 else 3012 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 5); 3013 3014 /* sw mechanism */ 3015 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); 3016 if (BTC_WIFI_BW_HT40 == wifi_bw) { 3017 btc8723b2ant_sw_mechanism(btcoexist, true, false, 3018 false, false); 3019 } else { 3020 btc8723b2ant_sw_mechanism(btcoexist, false, false, 3021 false, false); 3022 } 3023 } 3024 3025 /* PAN(HS) only */ 3026 static void btc8723b2ant_action_pan_hs(struct btc_coexist *btcoexist) 3027 { 3028 u8 bt_rssi_state; 3029 u32 wifi_bw; 3030 u8 tmp = BT_8723B_2ANT_WIFI_RSSI_COEXSWITCH_THRES - 3031 coex_dm->switch_thres_offset; 3032 3033 btc8723b2ant_wifi_rssi_state(btcoexist, 0, 2, 15, 0); 3034 btc8723b2ant_wifi_rssi_state(btcoexist, 1, 2, 3035 tmp, 0); 3036 tmp = BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES - 3037 coex_dm->switch_thres_offset; 3038 bt_rssi_state = btc8723b2ant_bt_rssi_state(btcoexist, 2, tmp, 0); 3039 3040 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); 3041 3042 btc8723b2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); 3043 btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); 3044 3045 if (BTC_RSSI_HIGH(bt_rssi_state)) 3046 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); 3047 else 3048 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); 3049 3050 btc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); 3051 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1); 3052 3053 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); 3054 if (BTC_WIFI_BW_HT40 == wifi_bw) { 3055 btc8723b2ant_sw_mechanism(btcoexist, true, false, 3056 false, false); 3057 } else { 3058 btc8723b2ant_sw_mechanism(btcoexist, false, false, 3059 false, false); 3060 } 3061 } 3062 3063 /* PAN(EDR) + A2DP */ 3064 static void btc8723b2ant_action_pan_edr_a2dp(struct btc_coexist *btcoexist) 3065 { 3066 u8 wifi_rssi_state1, bt_rssi_state; 3067 u32 wifi_bw; 3068 u8 tmp = BT_8723B_2ANT_WIFI_RSSI_COEXSWITCH_THRES - 3069 coex_dm->switch_thres_offset; 3070 3071 btc8723b2ant_wifi_rssi_state(btcoexist, 0, 2, 15, 0); 3072 wifi_rssi_state1 = btc8723b2ant_wifi_rssi_state(btcoexist, 1, 2, 3073 tmp, 0); 3074 tmp = BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES - 3075 coex_dm->switch_thres_offset; 3076 bt_rssi_state = btc8723b2ant_bt_rssi_state(btcoexist, 2, tmp, 0); 3077 3078 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); 3079 3080 btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); 3081 3082 if (BTC_RSSI_HIGH(bt_rssi_state)) 3083 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); 3084 else 3085 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); 3086 3087 if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) 3088 btc8723b2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 3089 0x0, 0x0); 3090 else 3091 btc8723b2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50, 3092 0x4); 3093 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); 3094 3095 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) || 3096 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { 3097 btc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 12); 3098 if (BTC_WIFI_BW_HT40 == wifi_bw) 3099 btc8723b2ant_tdma_duration_adjust(btcoexist, false, 3100 true, 3); 3101 else 3102 btc8723b2ant_tdma_duration_adjust(btcoexist, false, 3103 false, 3); 3104 } else { 3105 btc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); 3106 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, true, 3); 3107 } 3108 3109 /* sw mechanism */ 3110 if (BTC_WIFI_BW_HT40 == wifi_bw) { 3111 btc8723b2ant_sw_mechanism(btcoexist, true, false, 3112 false, false); 3113 } else { 3114 btc8723b2ant_sw_mechanism(btcoexist, false, false, 3115 false, false); 3116 } 3117 } 3118 3119 static void btc8723b2ant_action_pan_edr_hid(struct btc_coexist *btcoexist) 3120 { 3121 u8 wifi_rssi_state1, bt_rssi_state; 3122 u32 wifi_bw; 3123 u8 tmp = BT_8723B_2ANT_WIFI_RSSI_COEXSWITCH_THRES - 3124 coex_dm->switch_thres_offset; 3125 3126 btc8723b2ant_wifi_rssi_state(btcoexist, 0, 2, 15, 0); 3127 wifi_rssi_state1 = btc8723b2ant_wifi_rssi_state(btcoexist, 1, 2, 3128 tmp, 0); 3129 tmp = BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES - 3130 coex_dm->switch_thres_offset; 3131 bt_rssi_state = btc8723b2ant_bt_rssi_state(btcoexist, 2, tmp, 0); 3132 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); 3133 3134 btc8723b2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); 3135 3136 if (BTC_RSSI_HIGH(bt_rssi_state)) 3137 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); 3138 else 3139 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); 3140 3141 if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) { 3142 btc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); 3143 btc8723b2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 3144 0x0, 0x0); 3145 } else { 3146 btc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 14); 3147 btc8723b2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50, 3148 0x4); 3149 } 3150 3151 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) || 3152 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { 3153 if (BTC_WIFI_BW_HT40 == wifi_bw) { 3154 btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 3155 3); 3156 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 3157 0xfffff, 0x780); 3158 } else { 3159 btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 3160 6); 3161 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 3162 0xfffff, 0x0); 3163 } 3164 btc8723b2ant_tdma_duration_adjust(btcoexist, true, false, 2); 3165 } else { 3166 btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); 3167 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 3168 0x0); 3169 btc8723b2ant_tdma_duration_adjust(btcoexist, true, true, 2); 3170 } 3171 3172 /* sw mechanism */ 3173 if (BTC_WIFI_BW_HT40 == wifi_bw) { 3174 btc8723b2ant_sw_mechanism(btcoexist, true, true, 3175 false, false); 3176 } else { 3177 btc8723b2ant_sw_mechanism(btcoexist, false, true, 3178 false, false); 3179 } 3180 } 3181 3182 /* HID + A2DP + PAN(EDR) */ 3183 static void btc8723b2ant_action_hid_a2dp_pan_edr(struct btc_coexist *btcoexist) 3184 { 3185 u8 wifi_rssi_state1, bt_rssi_state; 3186 u32 wifi_bw; 3187 u8 tmp = BT_8723B_2ANT_WIFI_RSSI_COEXSWITCH_THRES - 3188 coex_dm->switch_thres_offset; 3189 3190 btc8723b2ant_wifi_rssi_state(btcoexist, 0, 2, 15, 0); 3191 wifi_rssi_state1 = btc8723b2ant_wifi_rssi_state(btcoexist, 1, 2, 3192 tmp, 0); 3193 tmp = BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES - 3194 coex_dm->switch_thres_offset; 3195 bt_rssi_state = btc8723b2ant_bt_rssi_state(btcoexist, 2, tmp, 0); 3196 3197 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); 3198 3199 btc8723b2ant_limited_rx(btcoexist, NORMAL_EXEC, false, false, 0x8); 3200 btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); 3201 3202 if (BTC_RSSI_HIGH(bt_rssi_state)) 3203 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); 3204 else 3205 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); 3206 3207 if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) { 3208 btc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); 3209 btc8723b2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 3210 0x0, 0x0); 3211 } else { 3212 btc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 14); 3213 btc8723b2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50, 3214 0x4); 3215 } 3216 3217 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); 3218 3219 3220 if ((bt_rssi_state == BTC_RSSI_STATE_HIGH) || 3221 (bt_rssi_state == BTC_RSSI_STATE_STAY_HIGH)) { 3222 if (BTC_WIFI_BW_HT40 == wifi_bw) 3223 btc8723b2ant_tdma_duration_adjust(btcoexist, true, 3224 true, 2); 3225 else 3226 btc8723b2ant_tdma_duration_adjust(btcoexist, true, 3227 false, 3); 3228 } else { 3229 btc8723b2ant_tdma_duration_adjust(btcoexist, true, true, 3); 3230 } 3231 3232 /* sw mechanism */ 3233 if (BTC_WIFI_BW_HT40 == wifi_bw) { 3234 btc8723b2ant_sw_mechanism(btcoexist, true, true, 3235 false, false); 3236 } else { 3237 btc8723b2ant_sw_mechanism(btcoexist, false, true, 3238 false, false); 3239 } 3240 } 3241 3242 static void btc8723b2ant_action_hid_a2dp(struct btc_coexist *btcoexist) 3243 { 3244 u8 wifi_rssi_state1, bt_rssi_state; 3245 u32 wifi_bw; 3246 u8 ap_num = 0; 3247 u8 tmp = BT_8723B_2ANT_WIFI_RSSI_COEXSWITCH_THRES - 3248 coex_dm->switch_thres_offset; 3249 3250 btc8723b2ant_wifi_rssi_state(btcoexist, 0, 2, 15, 0); 3251 wifi_rssi_state1 = btc8723b2ant_wifi_rssi_state(btcoexist, 1, 2, 3252 tmp, 0); 3253 tmp = BT_8723B_2ANT_BT_RSSI_COEXSWITCH_THRES - 3254 coex_dm->switch_thres_offset; 3255 bt_rssi_state = btc8723b2ant_bt_rssi_state(btcoexist, 3, tmp, 37); 3256 3257 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x0); 3258 3259 btc8723b2ant_limited_rx(btcoexist, NORMAL_EXEC, false, true, 0x5); 3260 btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); 3261 3262 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); 3263 3264 if (wifi_bw == BTC_WIFI_BW_LEGACY) { 3265 if (BTC_RSSI_HIGH(bt_rssi_state)) 3266 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); 3267 else if (BTC_RSSI_MEDIUM(bt_rssi_state)) 3268 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); 3269 else 3270 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); 3271 } else { 3272 /* only 802.11N mode we have to dec bt power to 4 degree */ 3273 if (BTC_RSSI_HIGH(bt_rssi_state)) { 3274 /* need to check ap Number of Not */ 3275 if (ap_num < 10) 3276 btc8723b2ant_dec_bt_pwr(btcoexist, 3277 NORMAL_EXEC, 4); 3278 else 3279 btc8723b2ant_dec_bt_pwr(btcoexist, 3280 NORMAL_EXEC, 2); 3281 } else if (BTC_RSSI_MEDIUM(bt_rssi_state)) { 3282 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 2); 3283 } else { 3284 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); 3285 } 3286 } 3287 3288 if (BTC_RSSI_HIGH(wifi_rssi_state1) && BTC_RSSI_HIGH(bt_rssi_state)) { 3289 btc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 7); 3290 btc8723b2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 3291 0x0, 0x0); 3292 } else { 3293 btc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 14); 3294 btc8723b2ant_power_save_state(btcoexist, BTC_PS_LPS_ON, 0x50, 3295 0x4); 3296 } 3297 3298 if (BTC_RSSI_HIGH(bt_rssi_state)) { 3299 if (ap_num < 10) 3300 btc8723b2ant_tdma_duration_adjust(btcoexist, true, 3301 false, 1); 3302 else 3303 btc8723b2ant_tdma_duration_adjust(btcoexist, true, 3304 false, 3); 3305 } else { 3306 btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 18); 3307 btcoexist->btc_write_1byte(btcoexist, 0x456, 0x38); 3308 btcoexist->btc_write_2byte(btcoexist, 0x42a, 0x0808); 3309 btcoexist->btc_write_4byte(btcoexist, 0x430, 0x0); 3310 btcoexist->btc_write_4byte(btcoexist, 0x434, 0x01010000); 3311 3312 if (ap_num < 10) 3313 btc8723b2ant_tdma_duration_adjust(btcoexist, true, 3314 true, 1); 3315 else 3316 btc8723b2ant_tdma_duration_adjust(btcoexist, true, 3317 true, 3); 3318 } 3319 3320 /* sw mechanism */ 3321 if (BTC_WIFI_BW_HT40 == wifi_bw) { 3322 btc8723b2ant_sw_mechanism(btcoexist, true, true, 3323 false, false); 3324 } else { 3325 btc8723b2ant_sw_mechanism(btcoexist, false, true, 3326 false, false); 3327 } 3328 } 3329 3330 static void btc8723b2ant_action_wifi_multi_port(struct btc_coexist *btcoexist) 3331 { 3332 btc8723b2ant_fw_dac_swing_lvl(btcoexist, NORMAL_EXEC, 6); 3333 btc8723b2ant_dec_bt_pwr(btcoexist, NORMAL_EXEC, 0); 3334 3335 /* sw all off */ 3336 btc8723b2ant_sw_mechanism(btcoexist, false, false, false, false); 3337 3338 /* hw all off */ 3339 btc8723b2ant_coex_table_with_type(btcoexist, NORMAL_EXEC, 0); 3340 3341 btc8723b2ant_power_save_state(btcoexist, BTC_PS_WIFI_NATIVE, 0x0, 0x0); 3342 btc8723b2ant_ps_tdma(btcoexist, NORMAL_EXEC, false, 1); 3343 } 3344 3345 static void btc8723b2ant_run_coexist_mechanism(struct btc_coexist *btcoexist) 3346 { 3347 struct rtl_priv *rtlpriv = btcoexist->adapter; 3348 u8 algorithm = 0; 3349 u32 num_of_wifi_link = 0; 3350 u32 wifi_link_status = 0; 3351 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; 3352 bool miracast_plus_bt = false; 3353 bool scan = false, link = false, roam = false; 3354 3355 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3356 "[BTCoex], RunCoexistMechanism()===>\n"); 3357 3358 if (btcoexist->manual_control) { 3359 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3360 "[BTCoex], RunCoexistMechanism(), return for Manual CTRL <===\n"); 3361 return; 3362 } 3363 3364 if (coex_sta->under_ips) { 3365 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3366 "[BTCoex], wifi is under IPS !!!\n"); 3367 return; 3368 } 3369 3370 algorithm = btc8723b2ant_action_algorithm(btcoexist); 3371 if (coex_sta->c2h_bt_inquiry_page && 3372 (BT_8723B_2ANT_COEX_ALGO_PANHS != algorithm)) { 3373 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3374 "[BTCoex], BT is under inquiry/page scan !!\n"); 3375 btc8723b2ant_action_bt_inquiry(btcoexist); 3376 return; 3377 } 3378 3379 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); 3380 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); 3381 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); 3382 3383 if (scan || link || roam) { 3384 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3385 "[BTCoex], WiFi is under Link Process !!\n"); 3386 btc8723b2ant_action_wifi_link_process(btcoexist); 3387 return; 3388 } 3389 3390 /* for P2P */ 3391 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_LINK_STATUS, 3392 &wifi_link_status); 3393 num_of_wifi_link = wifi_link_status >> 16; 3394 3395 if ((num_of_wifi_link >= 2) || 3396 (wifi_link_status & WIFI_P2P_GO_CONNECTED)) { 3397 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3398 "############# [BTCoex], Multi-Port num_of_wifi_link = %d, wifi_link_status = 0x%x\n", 3399 num_of_wifi_link, wifi_link_status); 3400 3401 if (bt_link_info->bt_link_exist) 3402 miracast_plus_bt = true; 3403 else 3404 miracast_plus_bt = false; 3405 3406 btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT, 3407 &miracast_plus_bt); 3408 btc8723b2ant_action_wifi_multi_port(btcoexist); 3409 3410 return; 3411 } 3412 3413 miracast_plus_bt = false; 3414 btcoexist->btc_set(btcoexist, BTC_SET_BL_MIRACAST_PLUS_BT, 3415 &miracast_plus_bt); 3416 3417 coex_dm->cur_algorithm = algorithm; 3418 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3419 "[BTCoex], Algorithm = %d\n", 3420 coex_dm->cur_algorithm); 3421 3422 if (btc8723b2ant_is_common_action(btcoexist)) { 3423 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3424 "[BTCoex], Action 2-Ant common\n"); 3425 coex_dm->auto_tdma_adjust = false; 3426 } else { 3427 if (coex_dm->cur_algorithm != coex_dm->pre_algorithm) { 3428 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3429 "[BTCoex], preAlgorithm=%d, curAlgorithm=%d\n", 3430 coex_dm->pre_algorithm, 3431 coex_dm->cur_algorithm); 3432 coex_dm->auto_tdma_adjust = false; 3433 } 3434 switch (coex_dm->cur_algorithm) { 3435 case BT_8723B_2ANT_COEX_ALGO_SCO: 3436 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3437 "[BTCoex], Action 2-Ant, algorithm = SCO\n"); 3438 btc8723b2ant_action_sco(btcoexist); 3439 break; 3440 case BT_8723B_2ANT_COEX_ALGO_HID: 3441 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3442 "[BTCoex], Action 2-Ant, algorithm = HID\n"); 3443 btc8723b2ant_action_hid(btcoexist); 3444 break; 3445 case BT_8723B_2ANT_COEX_ALGO_A2DP: 3446 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3447 "[BTCoex], Action 2-Ant, algorithm = A2DP\n"); 3448 btc8723b2ant_action_a2dp(btcoexist); 3449 break; 3450 case BT_8723B_2ANT_COEX_ALGO_A2DP_PANHS: 3451 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3452 "[BTCoex], Action 2-Ant, algorithm = A2DP+PAN(HS)\n"); 3453 btc8723b2ant_action_a2dp_pan_hs(btcoexist); 3454 break; 3455 case BT_8723B_2ANT_COEX_ALGO_PANEDR: 3456 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3457 "[BTCoex], Action 2-Ant, algorithm = PAN(EDR)\n"); 3458 btc8723b2ant_action_pan_edr(btcoexist); 3459 break; 3460 case BT_8723B_2ANT_COEX_ALGO_PANHS: 3461 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3462 "[BTCoex], Action 2-Ant, algorithm = HS mode\n"); 3463 btc8723b2ant_action_pan_hs(btcoexist); 3464 break; 3465 case BT_8723B_2ANT_COEX_ALGO_PANEDR_A2DP: 3466 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3467 "[BTCoex], Action 2-Ant, algorithm = PAN+A2DP\n"); 3468 btc8723b2ant_action_pan_edr_a2dp(btcoexist); 3469 break; 3470 case BT_8723B_2ANT_COEX_ALGO_PANEDR_HID: 3471 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3472 "[BTCoex], Action 2-Ant, algorithm = PAN(EDR)+HID\n"); 3473 btc8723b2ant_action_pan_edr_hid(btcoexist); 3474 break; 3475 case BT_8723B_2ANT_COEX_ALGO_HID_A2DP_PANEDR: 3476 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3477 "[BTCoex], Action 2-Ant, algorithm = HID+A2DP+PAN\n"); 3478 btc8723b2ant_action_hid_a2dp_pan_edr(btcoexist); 3479 break; 3480 case BT_8723B_2ANT_COEX_ALGO_HID_A2DP: 3481 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3482 "[BTCoex], Action 2-Ant, algorithm = HID+A2DP\n"); 3483 btc8723b2ant_action_hid_a2dp(btcoexist); 3484 break; 3485 default: 3486 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3487 "[BTCoex], Action 2-Ant, algorithm = coexist All Off!!\n"); 3488 btc8723b2ant_coex_alloff(btcoexist); 3489 break; 3490 } 3491 coex_dm->pre_algorithm = coex_dm->cur_algorithm; 3492 } 3493 } 3494 3495 static void btc8723b2ant_wifioff_hwcfg(struct btc_coexist *btcoexist) 3496 { 3497 bool is_in_mp_mode = false; 3498 u8 h2c_parameter[2] = {0}; 3499 u32 fw_ver = 0; 3500 3501 /* set wlan_act to low */ 3502 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4); 3503 3504 /* WiFi standby while GNT_BT 0 -> 1 */ 3505 btcoexist->btc_set_rf_reg(btcoexist, BTC_RF_A, 0x1, 0xfffff, 0x780); 3506 3507 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver); 3508 if (fw_ver >= 0x180000) { 3509 /* Use H2C to set GNT_BT to HIGH */ 3510 h2c_parameter[0] = 1; 3511 btcoexist->btc_fill_h2c(btcoexist, 0x6E, 1, h2c_parameter); 3512 } else { 3513 btcoexist->btc_write_1byte(btcoexist, 0x765, 0x18); 3514 } 3515 3516 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_IS_IN_MP_MODE, 3517 &is_in_mp_mode); 3518 if (!is_in_mp_mode) 3519 /* BT select s0/s1 is controlled by BT */ 3520 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x20, 0x0); 3521 else 3522 /* BT select s0/s1 is controlled by WiFi */ 3523 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x67, 0x20, 0x1); 3524 } 3525 3526 /********************************************************************* 3527 * extern function start with ex_btc8723b2ant_ 3528 *********************************************************************/ 3529 void ex_btc8723b2ant_init_hwconfig(struct btc_coexist *btcoexist) 3530 { 3531 struct rtl_priv *rtlpriv = btcoexist->adapter; 3532 u8 u8tmp = 0; 3533 3534 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3535 "[BTCoex], 2Ant Init HW Config!!\n"); 3536 coex_dm->bt_rf0x1e_backup = 3537 btcoexist->btc_get_rf_reg(btcoexist, BTC_RF_A, 0x1e, 0xfffff); 3538 3539 /* 0x790[5:0] = 0x5 */ 3540 u8tmp = btcoexist->btc_read_1byte(btcoexist, 0x790); 3541 u8tmp &= 0xc0; 3542 u8tmp |= 0x5; 3543 btcoexist->btc_write_1byte(btcoexist, 0x790, u8tmp); 3544 3545 /* Antenna config */ 3546 btc8723b2ant_set_ant_path(btcoexist, BTC_ANT_WIFI_AT_MAIN, 3547 true, false); 3548 coex_sta->dis_ver_info_cnt = 0; 3549 3550 /* PTA parameter */ 3551 btc8723b2ant_coex_table_with_type(btcoexist, FORCE_EXEC, 0); 3552 3553 /* Enable counter statistics */ 3554 /* 0x76e[3] = 1, WLAN_ACT controlled by PTA */ 3555 btcoexist->btc_write_1byte(btcoexist, 0x76e, 0x4); 3556 btcoexist->btc_write_1byte(btcoexist, 0x778, 0x3); 3557 btcoexist->btc_write_1byte_bitmask(btcoexist, 0x40, 0x20, 0x1); 3558 btcoexist->auto_report_2ant = true; 3559 } 3560 3561 void ex_btc8723b2ant_power_on_setting(struct btc_coexist *btcoexist) 3562 { 3563 struct btc_board_info *board_info = &btcoexist->board_info; 3564 u16 u16tmp = 0x0; 3565 u32 value = 0; 3566 3567 btcoexist->btc_write_1byte(btcoexist, 0x67, 0x20); 3568 3569 /* enable BB, REG_SYS_FUNC_EN such that we can write 0x948 correctly */ 3570 u16tmp = btcoexist->btc_read_2byte(btcoexist, 0x2); 3571 btcoexist->btc_write_2byte(btcoexist, 0x2, u16tmp | BIT0 | BIT1); 3572 3573 btcoexist->btc_write_4byte(btcoexist, 0x948, 0x0); 3574 3575 if (btcoexist->chip_interface == BTC_INTF_USB) { 3576 /* fixed at S0 for USB interface */ 3577 board_info->btdm_ant_pos = BTC_ANTENNA_AT_AUX_PORT; 3578 } else { 3579 /* for PCIE and SDIO interface, we check efuse 0xc3[6] */ 3580 if (board_info->single_ant_path == 0) { 3581 /* set to S1 */ 3582 board_info->btdm_ant_pos = BTC_ANTENNA_AT_MAIN_PORT; 3583 } else if (board_info->single_ant_path == 1) { 3584 /* set to S0 */ 3585 board_info->btdm_ant_pos = BTC_ANTENNA_AT_AUX_PORT; 3586 } 3587 btcoexist->btc_set(btcoexist, BTC_SET_ACT_ANTPOSREGRISTRY_CTRL, 3588 &value); 3589 } 3590 } 3591 3592 void ex_btc8723b2ant_pre_load_firmware(struct btc_coexist *btcoexist) 3593 { 3594 struct btc_board_info *board_info = &btcoexist->board_info; 3595 u8 u8tmp = 0x4; /* Set BIT2 by default since it's 2ant case */ 3596 3597 /** 3598 * S0 or S1 setting and Local register setting(By this fw can get 3599 * ant number, S0/S1, ... info) 3600 * 3601 * Local setting bit define 3602 * BIT0: "0" : no antenna inverse; "1" : antenna inverse 3603 * BIT1: "0" : internal switch; "1" : external switch 3604 * BIT2: "0" : one antenna; "1" : two antennas 3605 * 3606 * NOTE: here default all internal switch and 1-antenna ==> BIT1=0 and 3607 * BIT2 = 0 3608 */ 3609 if (btcoexist->chip_interface == BTC_INTF_USB) { 3610 /* fixed at S0 for USB interface */ 3611 u8tmp |= 0x1; /* antenna inverse */ 3612 btcoexist->btc_write_local_reg_1byte(btcoexist, 0xfe08, u8tmp); 3613 } else { 3614 /* for PCIE and SDIO interface, we check efuse 0xc3[6] */ 3615 if (board_info->single_ant_path == 0) { 3616 } else if (board_info->single_ant_path == 1) { 3617 /* set to S0 */ 3618 u8tmp |= 0x1; /* antenna inverse */ 3619 } 3620 3621 if (btcoexist->chip_interface == BTC_INTF_PCI) 3622 btcoexist->btc_write_local_reg_1byte(btcoexist, 0x384, 3623 u8tmp); 3624 else if (btcoexist->chip_interface == BTC_INTF_SDIO) 3625 btcoexist->btc_write_local_reg_1byte(btcoexist, 0x60, 3626 u8tmp); 3627 } 3628 } 3629 3630 void ex_btc8723b2ant_init_coex_dm(struct btc_coexist *btcoexist) 3631 { 3632 struct rtl_priv *rtlpriv = btcoexist->adapter; 3633 3634 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3635 "[BTCoex], Coex Mechanism Init!!\n"); 3636 btc8723b2ant_init_coex_dm(btcoexist); 3637 } 3638 3639 void ex_btc8723b2ant_display_coex_info(struct btc_coexist *btcoexist, 3640 struct seq_file *m) 3641 { 3642 struct btc_board_info *board_info = &btcoexist->board_info; 3643 struct btc_stack_info *stack_info = &btcoexist->stack_info; 3644 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; 3645 u8 u8tmp[4], i, bt_info_ext, ps_tdma_case = 0; 3646 u32 u32tmp[4]; 3647 bool roam = false, scan = false; 3648 bool link = false, wifi_under_5g = false; 3649 bool bt_hs_on = false, wifi_busy = false; 3650 s32 wifi_rssi = 0, bt_hs_rssi = 0; 3651 u32 wifi_bw, wifi_traffic_dir, fa_ofdm, fa_cck; 3652 u8 wifi_dot11_chnl, wifi_hs_chnl; 3653 u32 fw_ver = 0, bt_patch_ver = 0; 3654 u8 ap_num = 0; 3655 3656 seq_puts(m, "\n ============[BT Coexist info]============"); 3657 3658 if (btcoexist->manual_control) { 3659 seq_puts(m, "\n ==========[Under Manual Control]============"); 3660 seq_puts(m, "\n =========================================="); 3661 } 3662 3663 seq_printf(m, "\n %-35s = %d/ %d ", 3664 "Ant PG number/ Ant mechanism:", 3665 board_info->pg_ant_num, board_info->btdm_ant_num); 3666 3667 seq_printf(m, "\n %-35s = %s / %d", 3668 "BT stack/ hci ext ver", 3669 ((stack_info->profile_notified) ? "Yes" : "No"), 3670 stack_info->hci_version); 3671 3672 btcoexist->btc_get(btcoexist, BTC_GET_U4_BT_PATCH_VER, &bt_patch_ver); 3673 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_FW_VER, &fw_ver); 3674 seq_printf(m, "\n %-35s = %d_%x/ 0x%x/ 0x%x(%d)", 3675 "CoexVer/ FwVer/ PatchVer", 3676 glcoex_ver_date_8723b_2ant, glcoex_ver_8723b_2ant, 3677 fw_ver, bt_patch_ver, bt_patch_ver); 3678 3679 btcoexist->btc_get(btcoexist, BTC_GET_BL_HS_OPERATION, &bt_hs_on); 3680 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_DOT11_CHNL, 3681 &wifi_dot11_chnl); 3682 btcoexist->btc_get(btcoexist, BTC_GET_U1_WIFI_HS_CHNL, &wifi_hs_chnl); 3683 3684 seq_printf(m, "\n %-35s = %d / %d(%d)", 3685 "Dot11 channel / HsChnl(HsMode)", 3686 wifi_dot11_chnl, wifi_hs_chnl, bt_hs_on); 3687 3688 seq_printf(m, "\n %-35s = %3ph ", 3689 "H2C Wifi inform bt chnl Info", coex_dm->wifi_chnl_info); 3690 3691 btcoexist->btc_get(btcoexist, BTC_GET_S4_WIFI_RSSI, &wifi_rssi); 3692 btcoexist->btc_get(btcoexist, BTC_GET_S4_HS_RSSI, &bt_hs_rssi); 3693 btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, &ap_num); 3694 seq_printf(m, "\n %-35s = %d/ %d/ %d", 3695 "Wifi rssi/ HS rssi/ AP#", wifi_rssi, bt_hs_rssi, ap_num); 3696 3697 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_SCAN, &scan); 3698 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_LINK, &link); 3699 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_ROAM, &roam); 3700 seq_printf(m, "\n %-35s = %d/ %d/ %d ", 3701 "Wifi link/ roam/ scan", link, roam, scan); 3702 3703 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_UNDER_5G, &wifi_under_5g); 3704 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_BW, &wifi_bw); 3705 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_BUSY, &wifi_busy); 3706 btcoexist->btc_get(btcoexist, BTC_GET_U4_WIFI_TRAFFIC_DIRECTION, 3707 &wifi_traffic_dir); 3708 seq_printf(m, "\n %-35s = %s / %s/ %s ", 3709 "Wifi status", (wifi_under_5g ? "5G" : "2.4G"), 3710 ((wifi_bw == BTC_WIFI_BW_LEGACY) ? "Legacy" : 3711 (((wifi_bw == BTC_WIFI_BW_HT40) ? "HT40" : "HT20"))), 3712 ((!wifi_busy) ? "idle" : 3713 ((wifi_traffic_dir == BTC_WIFI_TRAFFIC_TX) ? 3714 "uplink" : "downlink"))); 3715 3716 seq_printf(m, "\n %-35s = %d / %d / %d / %d", 3717 "SCO/HID/PAN/A2DP", 3718 bt_link_info->sco_exist, bt_link_info->hid_exist, 3719 bt_link_info->pan_exist, bt_link_info->a2dp_exist); 3720 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_BT_LINK_INFO, m); 3721 3722 bt_info_ext = coex_sta->bt_info_ext; 3723 seq_printf(m, "\n %-35s = %s", 3724 "BT Info A2DP rate", 3725 (bt_info_ext & BIT0) ? "Basic rate" : "EDR rate"); 3726 3727 for (i = 0; i < BT_INFO_SRC_8723B_2ANT_MAX; i++) { 3728 if (coex_sta->bt_info_c2h_cnt[i]) { 3729 seq_printf(m, "\n %-35s = %7ph(%d)", 3730 glbt_info_src_8723b_2ant[i], 3731 coex_sta->bt_info_c2h[i], 3732 coex_sta->bt_info_c2h_cnt[i]); 3733 } 3734 } 3735 3736 seq_printf(m, "\n %-35s = %s/%s", 3737 "PS state, IPS/LPS", 3738 ((coex_sta->under_ips ? "IPS ON" : "IPS OFF")), 3739 ((coex_sta->under_lps ? "LPS ON" : "LPS OFF"))); 3740 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_FW_PWR_MODE_CMD, m); 3741 3742 /* Sw mechanism */ 3743 seq_printf(m, 3744 "\n %-35s", "============[Sw mechanism]============"); 3745 seq_printf(m, "\n %-35s = %d/ %d/ %d ", 3746 "SM1[ShRf/ LpRA/ LimDig]", coex_dm->cur_rf_rx_lpf_shrink, 3747 coex_dm->cur_low_penalty_ra, coex_dm->limited_dig); 3748 seq_printf(m, "\n %-35s = %d/ %d/ %d(0x%x) ", 3749 "SM2[AgcT/ AdcB/ SwDacSwing(lvl)]", 3750 coex_dm->cur_agc_table_en, coex_dm->cur_adc_back_off, 3751 coex_dm->cur_dac_swing_on, coex_dm->cur_dac_swing_lvl); 3752 3753 /* Fw mechanism */ 3754 seq_printf(m, "\n %-35s", 3755 "============[Fw mechanism]============"); 3756 3757 ps_tdma_case = coex_dm->cur_ps_tdma; 3758 seq_printf(m, "\n %-35s = %5ph case-%d (auto:%d)", 3759 "PS TDMA", coex_dm->ps_tdma_para, 3760 ps_tdma_case, coex_dm->auto_tdma_adjust); 3761 3762 seq_printf(m, "\n %-35s = %d/ %d ", 3763 "DecBtPwr/ IgnWlanAct", coex_dm->cur_dec_bt_pwr_lvl, 3764 coex_dm->cur_ignore_wlan_act); 3765 3766 /* Hw setting */ 3767 seq_printf(m, "\n %-35s", 3768 "============[Hw setting]============"); 3769 3770 seq_printf(m, "\n %-35s = 0x%x", 3771 "RF-A, 0x1e initVal", coex_dm->bt_rf0x1e_backup); 3772 3773 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x778); 3774 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x880); 3775 seq_printf(m, "\n %-35s = 0x%x/ 0x%x", 3776 "0x778/0x880[29:25]", u8tmp[0], 3777 (u32tmp[0] & 0x3e000000) >> 25); 3778 3779 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x948); 3780 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x67); 3781 u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x765); 3782 seq_printf(m, "\n %-35s = 0x%x/ 0x%x/ 0x%x", 3783 "0x948/ 0x67[5] / 0x765", 3784 u32tmp[0], ((u8tmp[0] & 0x20) >> 5), u8tmp[1]); 3785 3786 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x92c); 3787 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x930); 3788 u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x944); 3789 seq_printf(m, "\n %-35s = 0x%x/ 0x%x/ 0x%x", 3790 "0x92c[1:0]/ 0x930[7:0]/0x944[1:0]", 3791 u32tmp[0] & 0x3, u32tmp[1] & 0xff, u32tmp[2] & 0x3); 3792 3793 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x39); 3794 u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0x40); 3795 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x4c); 3796 u8tmp[2] = btcoexist->btc_read_1byte(btcoexist, 0x64); 3797 seq_printf(m, "\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", 3798 "0x38[11]/0x40/0x4c[24:23]/0x64[0]", 3799 ((u8tmp[0] & 0x8) >> 3), u8tmp[1], 3800 ((u32tmp[0] & 0x01800000) >> 23), u8tmp[2] & 0x1); 3801 3802 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x550); 3803 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x522); 3804 seq_printf(m, "\n %-35s = 0x%x/ 0x%x", 3805 "0x550(bcn ctrl)/0x522", u32tmp[0], u8tmp[0]); 3806 3807 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xc50); 3808 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x49c); 3809 seq_printf(m, "\n %-35s = 0x%x/ 0x%x", 3810 "0xc50(dig)/0x49c(null-drop)", u32tmp[0] & 0xff, u8tmp[0]); 3811 3812 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0xda0); 3813 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0xda4); 3814 u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0xda8); 3815 u32tmp[3] = btcoexist->btc_read_4byte(btcoexist, 0xcf0); 3816 3817 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0xa5b); 3818 u8tmp[1] = btcoexist->btc_read_1byte(btcoexist, 0xa5c); 3819 3820 fa_ofdm = ((u32tmp[0]&0xffff0000) >> 16) + 3821 ((u32tmp[1]&0xffff0000) >> 16) + 3822 (u32tmp[1] & 0xffff) + 3823 (u32tmp[2] & 0xffff) + 3824 ((u32tmp[3]&0xffff0000) >> 16) + 3825 (u32tmp[3] & 0xffff); 3826 fa_cck = (u8tmp[0] << 8) + u8tmp[1]; 3827 3828 seq_printf(m, "\n %-35s = 0x%x/ 0x%x/ 0x%x", 3829 "OFDM-CCA/OFDM-FA/CCK-FA", 3830 u32tmp[0] & 0xffff, fa_ofdm, fa_cck); 3831 3832 u32tmp[0] = btcoexist->btc_read_4byte(btcoexist, 0x6c0); 3833 u32tmp[1] = btcoexist->btc_read_4byte(btcoexist, 0x6c4); 3834 u32tmp[2] = btcoexist->btc_read_4byte(btcoexist, 0x6c8); 3835 u8tmp[0] = btcoexist->btc_read_1byte(btcoexist, 0x6cc); 3836 seq_printf(m, "\n %-35s = 0x%x/ 0x%x/ 0x%x/ 0x%x", 3837 "0x6c0/0x6c4/0x6c8/0x6cc(coexTable)", 3838 u32tmp[0], u32tmp[1], u32tmp[2], u8tmp[0]); 3839 3840 seq_printf(m, "\n %-35s = %d/ %d", 3841 "0x770(high-pri rx/tx)", 3842 coex_sta->high_priority_rx, coex_sta->high_priority_tx); 3843 seq_printf(m, "\n %-35s = %d/ %d", 3844 "0x774(low-pri rx/tx)", coex_sta->low_priority_rx, 3845 coex_sta->low_priority_tx); 3846 if (btcoexist->auto_report_2ant) 3847 btc8723b2ant_monitor_bt_ctr(btcoexist); 3848 btcoexist->btc_disp_dbg_msg(btcoexist, BTC_DBG_DISP_COEX_STATISTICS, m); 3849 } 3850 3851 void ex_btc8723b2ant_ips_notify(struct btc_coexist *btcoexist, u8 type) 3852 { 3853 struct rtl_priv *rtlpriv = btcoexist->adapter; 3854 3855 if (BTC_IPS_ENTER == type) { 3856 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3857 "[BTCoex], IPS ENTER notify\n"); 3858 coex_sta->under_ips = true; 3859 btc8723b2ant_wifioff_hwcfg(btcoexist); 3860 btc8723b2ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true); 3861 btc8723b2ant_coex_alloff(btcoexist); 3862 } else if (BTC_IPS_LEAVE == type) { 3863 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3864 "[BTCoex], IPS LEAVE notify\n"); 3865 coex_sta->under_ips = false; 3866 ex_btc8723b2ant_init_hwconfig(btcoexist); 3867 btc8723b2ant_init_coex_dm(btcoexist); 3868 btc8723b2ant_query_bt_info(btcoexist); 3869 } 3870 } 3871 3872 void ex_btc8723b2ant_lps_notify(struct btc_coexist *btcoexist, u8 type) 3873 { 3874 struct rtl_priv *rtlpriv = btcoexist->adapter; 3875 3876 if (BTC_LPS_ENABLE == type) { 3877 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3878 "[BTCoex], LPS ENABLE notify\n"); 3879 coex_sta->under_lps = true; 3880 } else if (BTC_LPS_DISABLE == type) { 3881 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3882 "[BTCoex], LPS DISABLE notify\n"); 3883 coex_sta->under_lps = false; 3884 } 3885 } 3886 3887 void ex_btc8723b2ant_scan_notify(struct btc_coexist *btcoexist, u8 type) 3888 { 3889 struct rtl_priv *rtlpriv = btcoexist->adapter; 3890 u32 u32tmp; 3891 u8 u8tmpa, u8tmpb; 3892 3893 u32tmp = btcoexist->btc_read_4byte(btcoexist, 0x948); 3894 u8tmpa = btcoexist->btc_read_1byte(btcoexist, 0x765); 3895 u8tmpb = btcoexist->btc_read_1byte(btcoexist, 0x76e); 3896 3897 if (BTC_SCAN_START == type) 3898 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3899 "[BTCoex], SCAN START notify\n"); 3900 else if (BTC_SCAN_FINISH == type) 3901 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3902 "[BTCoex], SCAN FINISH notify\n"); 3903 btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, 3904 &coex_sta->scan_ap_num); 3905 3906 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3907 "############# [BTCoex], 0x948=0x%x, 0x765=0x%x, 0x76e=0x%x\n", 3908 u32tmp, u8tmpa, u8tmpb); 3909 } 3910 3911 void ex_btc8723b2ant_connect_notify(struct btc_coexist *btcoexist, u8 type) 3912 { 3913 struct rtl_priv *rtlpriv = btcoexist->adapter; 3914 3915 if (BTC_ASSOCIATE_START == type) 3916 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3917 "[BTCoex], CONNECT START notify\n"); 3918 else if (BTC_ASSOCIATE_FINISH == type) 3919 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3920 "[BTCoex], CONNECT FINISH notify\n"); 3921 } 3922 3923 void ex_btc8723b2ant_media_status_notify(struct btc_coexist *btcoexist, 3924 u8 type) 3925 { 3926 struct rtl_priv *rtlpriv = btcoexist->adapter; 3927 u8 h2c_parameter[3] = {0}; 3928 u32 wifi_bw; 3929 u8 wifi_central_chnl; 3930 u8 ap_num = 0; 3931 3932 if (BTC_MEDIA_CONNECT == type) 3933 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3934 "[BTCoex], MEDIA connect notify\n"); 3935 else 3936 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3937 "[BTCoex], MEDIA disconnect notify\n"); 3938 3939 /* only 2.4G we need to inform bt the chnl mask */ 3940 btcoexist->btc_get(btcoexist, 3941 BTC_GET_U1_WIFI_CENTRAL_CHNL, &wifi_central_chnl); 3942 if ((BTC_MEDIA_CONNECT == type) && 3943 (wifi_central_chnl <= 14)) { 3944 h2c_parameter[0] = 0x1; 3945 h2c_parameter[1] = wifi_central_chnl; 3946 btcoexist->btc_get(btcoexist, 3947 BTC_GET_U4_WIFI_BW, &wifi_bw); 3948 if (wifi_bw == BTC_WIFI_BW_HT40) { 3949 h2c_parameter[2] = 0x30; 3950 } else { 3951 btcoexist->btc_get(btcoexist, BTC_GET_U1_AP_NUM, 3952 &ap_num); 3953 if (ap_num < 10) 3954 h2c_parameter[2] = 0x30; 3955 else 3956 h2c_parameter[2] = 0x20; 3957 } 3958 } 3959 3960 coex_dm->wifi_chnl_info[0] = h2c_parameter[0]; 3961 coex_dm->wifi_chnl_info[1] = h2c_parameter[1]; 3962 coex_dm->wifi_chnl_info[2] = h2c_parameter[2]; 3963 3964 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3965 "[BTCoex], FW write 0x66=0x%x\n", 3966 h2c_parameter[0] << 16 | h2c_parameter[1] << 8 | 3967 h2c_parameter[2]); 3968 3969 btcoexist->btc_fill_h2c(btcoexist, 0x66, 3, h2c_parameter); 3970 } 3971 3972 void ex_btc8723b2ant_special_packet_notify(struct btc_coexist *btcoexist, 3973 u8 type) 3974 { 3975 struct rtl_priv *rtlpriv = btcoexist->adapter; 3976 3977 if (type == BTC_PACKET_DHCP) 3978 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3979 "[BTCoex], DHCP Packet notify\n"); 3980 } 3981 3982 void ex_btc8723b2ant_bt_info_notify(struct btc_coexist *btcoexist, 3983 u8 *tmpbuf, u8 length) 3984 { 3985 struct rtl_priv *rtlpriv = btcoexist->adapter; 3986 u8 bt_info = 0; 3987 u8 i, rsp_source = 0; 3988 bool bt_busy = false, limited_dig = false; 3989 bool wifi_connected = false; 3990 3991 coex_sta->c2h_bt_info_req_sent = false; 3992 3993 rsp_source = tmpbuf[0]&0xf; 3994 if (rsp_source >= BT_INFO_SRC_8723B_2ANT_MAX) 3995 rsp_source = BT_INFO_SRC_8723B_2ANT_WIFI_FW; 3996 coex_sta->bt_info_c2h_cnt[rsp_source]++; 3997 3998 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 3999 "[BTCoex], Bt info[%d], length=%d, hex data=[", 4000 rsp_source, length); 4001 for (i = 0; i < length; i++) { 4002 coex_sta->bt_info_c2h[rsp_source][i] = tmpbuf[i]; 4003 if (i == 1) 4004 bt_info = tmpbuf[i]; 4005 if (i == length - 1) 4006 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 4007 "0x%02x]\n", tmpbuf[i]); 4008 else 4009 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 4010 "0x%02x, ", tmpbuf[i]); 4011 } 4012 4013 if (btcoexist->manual_control) { 4014 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 4015 "[BTCoex], BtInfoNotify(), return for Manual CTRL<===\n"); 4016 return; 4017 } 4018 4019 if (BT_INFO_SRC_8723B_2ANT_WIFI_FW != rsp_source) { 4020 coex_sta->bt_retry_cnt = 4021 coex_sta->bt_info_c2h[rsp_source][2] & 0xf; 4022 4023 if (coex_sta->bt_retry_cnt >= 1) 4024 coex_sta->pop_event_cnt++; 4025 4026 coex_sta->bt_rssi = 4027 coex_sta->bt_info_c2h[rsp_source][3] * 2 + 10; 4028 4029 coex_sta->bt_info_ext = coex_sta->bt_info_c2h[rsp_source][4]; 4030 4031 if (coex_sta->bt_info_c2h[rsp_source][2] & 0x20) 4032 coex_sta->c2h_bt_remote_name_req = true; 4033 else 4034 coex_sta->c2h_bt_remote_name_req = false; 4035 4036 if (coex_sta->bt_info_c2h[rsp_source][1] == 0x49) 4037 coex_sta->a2dp_bit_pool = 4038 coex_sta->bt_info_c2h[rsp_source][6]; 4039 else 4040 coex_sta->a2dp_bit_pool = 0; 4041 4042 /* Here we need to resend some wifi info to BT 4043 * because BT is reset and loss of the info. 4044 */ 4045 if ((coex_sta->bt_info_ext & BIT1)) { 4046 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 4047 "[BTCoex], BT ext info bit1 check, send wifi BW&Chnl to BT!!\n"); 4048 btcoexist->btc_get(btcoexist, BTC_GET_BL_WIFI_CONNECTED, 4049 &wifi_connected); 4050 if (wifi_connected) 4051 ex_btc8723b2ant_media_status_notify( 4052 btcoexist, 4053 BTC_MEDIA_CONNECT); 4054 else 4055 ex_btc8723b2ant_media_status_notify( 4056 btcoexist, 4057 BTC_MEDIA_DISCONNECT); 4058 } 4059 4060 if ((coex_sta->bt_info_ext & BIT3)) { 4061 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 4062 "[BTCoex], BT ext info bit3 check, set BT NOT to ignore Wlan active!!\n"); 4063 btc8723b2ant_ignore_wlan_act(btcoexist, FORCE_EXEC, 4064 false); 4065 } else { 4066 /* BT already NOT ignore Wlan active, do nothing here.*/ 4067 } 4068 if (!btcoexist->auto_report_2ant) { 4069 if (!(coex_sta->bt_info_ext & BIT4)) 4070 btc8723b2ant_bt_auto_report(btcoexist, 4071 FORCE_EXEC, true); 4072 } 4073 } 4074 4075 /* check BIT2 first ==> check if bt is under inquiry or page scan */ 4076 if (bt_info & BT_INFO_8723B_2ANT_B_INQ_PAGE) 4077 coex_sta->c2h_bt_inquiry_page = true; 4078 else 4079 coex_sta->c2h_bt_inquiry_page = false; 4080 4081 if (!(bt_info & BT_INFO_8723B_2ANT_B_CONNECTION)) { 4082 /* set link exist status */ 4083 coex_sta->bt_link_exist = false; 4084 coex_sta->pan_exist = false; 4085 coex_sta->a2dp_exist = false; 4086 coex_sta->hid_exist = false; 4087 coex_sta->sco_exist = false; 4088 } else { 4089 /* connection exists */ 4090 coex_sta->bt_link_exist = true; 4091 if (bt_info & BT_INFO_8723B_2ANT_B_FTP) 4092 coex_sta->pan_exist = true; 4093 else 4094 coex_sta->pan_exist = false; 4095 if (bt_info & BT_INFO_8723B_2ANT_B_A2DP) 4096 coex_sta->a2dp_exist = true; 4097 else 4098 coex_sta->a2dp_exist = false; 4099 if (bt_info & BT_INFO_8723B_2ANT_B_HID) 4100 coex_sta->hid_exist = true; 4101 else 4102 coex_sta->hid_exist = false; 4103 if (bt_info & BT_INFO_8723B_2ANT_B_SCO_ESCO) 4104 coex_sta->sco_exist = true; 4105 else 4106 coex_sta->sco_exist = false; 4107 4108 if ((!coex_sta->hid_exist) && 4109 (!coex_sta->c2h_bt_inquiry_page) && 4110 (!coex_sta->sco_exist)) { 4111 if (coex_sta->high_priority_tx + 4112 coex_sta->high_priority_rx >= 160) { 4113 coex_sta->hid_exist = true; 4114 bt_info = bt_info | 0x28; 4115 } 4116 } 4117 } 4118 4119 btc8723b2ant_update_bt_link_info(btcoexist); 4120 4121 if (!(bt_info & BT_INFO_8723B_2ANT_B_CONNECTION)) { 4122 coex_dm->bt_status = BT_8723B_2ANT_BT_STATUS_NON_CONNECTED_IDLE; 4123 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 4124 "[BTCoex], BtInfoNotify(), BT Non-Connected idle!!!\n"); 4125 /* connection exists but no busy */ 4126 } else if (bt_info == BT_INFO_8723B_2ANT_B_CONNECTION) { 4127 coex_dm->bt_status = BT_8723B_2ANT_BT_STATUS_CONNECTED_IDLE; 4128 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 4129 "[BTCoex], BtInfoNotify(), BT Connected-idle!!!\n"); 4130 } else if ((bt_info & BT_INFO_8723B_2ANT_B_SCO_ESCO) || 4131 (bt_info & BT_INFO_8723B_2ANT_B_SCO_BUSY)) { 4132 coex_dm->bt_status = BT_8723B_2ANT_BT_STATUS_SCO_BUSY; 4133 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 4134 "[BTCoex], BtInfoNotify(), BT SCO busy!!!\n"); 4135 } else if (bt_info&BT_INFO_8723B_2ANT_B_ACL_BUSY) { 4136 coex_dm->bt_status = BT_8723B_2ANT_BT_STATUS_ACL_BUSY; 4137 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 4138 "[BTCoex], BtInfoNotify(), BT ACL busy!!!\n"); 4139 } else { 4140 coex_dm->bt_status = BT_8723B_2ANT_BT_STATUS_MAX; 4141 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 4142 "[BTCoex], BtInfoNotify(), BT Non-Defined state!!!\n"); 4143 } 4144 4145 if ((BT_8723B_2ANT_BT_STATUS_ACL_BUSY == coex_dm->bt_status) || 4146 (BT_8723B_2ANT_BT_STATUS_SCO_BUSY == coex_dm->bt_status) || 4147 (BT_8723B_2ANT_BT_STATUS_ACL_SCO_BUSY == coex_dm->bt_status)) { 4148 bt_busy = true; 4149 limited_dig = true; 4150 } else { 4151 bt_busy = false; 4152 limited_dig = false; 4153 } 4154 4155 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_TRAFFIC_BUSY, &bt_busy); 4156 4157 coex_dm->limited_dig = limited_dig; 4158 btcoexist->btc_set(btcoexist, BTC_SET_BL_BT_LIMITED_DIG, &limited_dig); 4159 4160 btc8723b2ant_run_coexist_mechanism(btcoexist); 4161 } 4162 4163 void ex_btc8723b2ant_halt_notify(struct btc_coexist *btcoexist) 4164 { 4165 struct rtl_priv *rtlpriv = btcoexist->adapter; 4166 4167 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, "[BTCoex], Halt notify\n"); 4168 4169 btc8723b2ant_wifioff_hwcfg(btcoexist); 4170 btc8723b2ant_ignore_wlan_act(btcoexist, FORCE_EXEC, true); 4171 ex_btc8723b2ant_media_status_notify(btcoexist, BTC_MEDIA_DISCONNECT); 4172 } 4173 4174 void ex_btc8723b2ant_pnp_notify(struct btc_coexist *btcoexist, u8 pnp_state) 4175 { 4176 struct rtl_priv *rtlpriv = btcoexist->adapter; 4177 4178 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, "[BTCoex], Pnp notify\n"); 4179 4180 if (pnp_state == BTC_WIFI_PNP_SLEEP) { 4181 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 4182 "[BTCoex], Pnp notify to SLEEP\n"); 4183 4184 /* Driver do not leave IPS/LPS when driver is going to sleep, so 4185 * BTCoexistence think wifi is still under IPS/LPS 4186 * 4187 * BT should clear UnderIPS/UnderLPS state to avoid mismatch 4188 * state after wakeup. 4189 */ 4190 coex_sta->under_ips = false; 4191 coex_sta->under_lps = false; 4192 } else if (pnp_state == BTC_WIFI_PNP_WAKE_UP) { 4193 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 4194 "[BTCoex], Pnp notify to WAKE UP\n"); 4195 ex_btc8723b2ant_init_hwconfig(btcoexist); 4196 btc8723b2ant_init_coex_dm(btcoexist); 4197 btc8723b2ant_query_bt_info(btcoexist); 4198 } 4199 } 4200 4201 void ex_btc8723b2ant_periodical(struct btc_coexist *btcoexist) 4202 { 4203 struct rtl_priv *rtlpriv = btcoexist->adapter; 4204 struct btc_bt_link_info *bt_link_info = &btcoexist->bt_link_info; 4205 4206 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 4207 "[BTCoex], ==========================Periodical===========================\n"); 4208 4209 if (coex_sta->dis_ver_info_cnt <= 5) { 4210 coex_sta->dis_ver_info_cnt += 1; 4211 if (coex_sta->dis_ver_info_cnt == 3) { 4212 /* Antenna config to set 0x765 = 0x0 (GNT_BT control by 4213 * PTA) after initial 4214 */ 4215 rtl_dbg(rtlpriv, COMP_BT_COEXIST, DBG_LOUD, 4216 "[BTCoex], Set GNT_BT control by PTA\n"); 4217 btc8723b2ant_set_ant_path( 4218 btcoexist, BTC_ANT_WIFI_AT_MAIN, false, false); 4219 } 4220 } 4221 4222 if (!btcoexist->auto_report_2ant) { 4223 btc8723b2ant_query_bt_info(btcoexist); 4224 } else { 4225 btc8723b2ant_monitor_bt_ctr(btcoexist); 4226 btc8723b2ant_monitor_wifi_ctr(btcoexist); 4227 4228 /* for some BT speakers that High-Priority pkts appear before 4229 * playing, this will cause HID exist 4230 */ 4231 if ((coex_sta->high_priority_tx + 4232 coex_sta->high_priority_rx < 50) && 4233 (bt_link_info->hid_exist)) 4234 bt_link_info->hid_exist = false; 4235 4236 if (btc8723b2ant_is_wifi_status_changed(btcoexist) || 4237 coex_dm->auto_tdma_adjust) 4238 btc8723b2ant_run_coexist_mechanism(btcoexist); 4239 } 4240 } 4241