17 #include <linux/export.h>
23 static void ar9003_mci_reset_req_wakeup(
struct ath_hw *
ah)
33 u32 bit_position,
int time_out)
38 if (!(
REG_READ(ah, address) & bit_position)) {
53 ar9003_mci_reset_req_wakeup(ah);
66 "MCI Wait for Reg 0x%08x = 0x%08x timeout\n",
67 address, bit_position);
69 "MCI INT_RAW = 0x%08x, RX_MSG_RAW = 0x%08x\n",
78 static void ar9003_mci_remote_reset(
struct ath_hw *ah,
bool wait_done)
80 u32 payload[4] = { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffff00};
87 static void ar9003_mci_send_lna_transfer(
struct ath_hw *ah,
bool wait_done)
95 static void ar9003_mci_send_req_wake(
struct ath_hw *ah,
bool wait_done)
98 NULL, 0, wait_done,
false);
102 static void ar9003_mci_send_sys_waking(
struct ath_hw *ah,
bool wait_done)
105 NULL, 0, wait_done,
false);
108 static void ar9003_mci_send_lna_take(
struct ath_hw *ah,
bool wait_done)
116 static void ar9003_mci_send_sys_sleeping(
struct ath_hw *ah,
bool wait_done)
120 NULL, 0, wait_done,
false);
123 static void ar9003_mci_send_coex_version_query(
struct ath_hw *ah,
138 static void ar9003_mci_send_coex_version_response(
struct ath_hw *ah,
142 u32 payload[4] = {0, 0, 0, 0};
153 static void ar9003_mci_send_coex_wlan_channels(
struct ath_hw *ah,
169 static void ar9003_mci_send_coex_bt_status_query(
struct ath_hw *ah,
170 bool wait_done,
u8 query_type)
173 u32 payload[4] = {0, 0, 0, 0};
200 static void ar9003_mci_send_coex_halt_bt_gpm(
struct ath_hw *ah,
bool halt,
204 u32 payload[4] = {0, 0, 0, 0};
223 static void ar9003_mci_prep_interface(
struct ath_hw *ah)
225 struct ath_common *common = ath9k_hw_common(ah);
227 u32 saved_mci_int_en;
228 u32 mci_timeout = 150;
239 ar9003_mci_remote_reset(ah,
true);
240 ar9003_mci_send_req_wake(ah,
true);
264 ar9003_mci_send_sys_waking(ah,
true);
288 ar9003_mci_send_lna_transfer(ah,
true);
293 if (ar9003_mci_wait_for_interrupt(ah,
298 "MCI WLAN has control over the LNA & BT obeys it\n");
301 "MCI BT didn't respond to LNA_TRANS\n");
327 ar9003_mci_send_coex_halt_bt_gpm(ah,
true,
true);
333 static void ar9003_mci_disable_interrupt(
struct ath_hw *ah)
339 static void ar9003_mci_enable_interrupt(
struct ath_hw *ah)
346 static bool ar9003_mci_check_int(
struct ath_hw *ah,
u32 ints)
351 return ((intr & ints) == ints);
370 struct ath_common *common = ath9k_hw_common(ah);
377 if ((raw_intr == 0xdeadbeef) || (rx_msg_intr == 0xdeadbeef)) {
379 "MCI gets 0xdeadbeef during int processing\n");
393 static void ar9003_mci_2g5g_changed(
struct ath_hw *ah,
bool is_2g)
398 (mci->
is_2g != is_2g))
404 static bool ar9003_mci_is_gpm_valid(
struct ath_hw *ah,
u32 msg_index)
413 offset = msg_index << 4;
424 static void ar9003_mci_observation_set_up(
struct ath_hw *ah)
464 static bool ar9003_mci_send_coex_bt_flags(
struct ath_hw *ah,
bool wait_done,
467 u32 pld[4] = {0, 0, 0, 0};
482 static void ar9003_mci_sync_bt_state(
struct ath_hw *ah)
494 ar9003_mci_send_coex_version_query(ah,
true);
495 ar9003_mci_send_coex_wlan_channels(ah,
true);
498 ar9003_mci_send_coex_halt_bt_gpm(ah,
false,
true);
513 ar9003_mci_sync_bt_state(ah);
522 static void ar9003_mci_process_gpm_extra(
struct ath_hw *ah,
u8 gpm_type,
523 u8 gpm_opcode,
u32 *p_gpm)
525 struct ath_common *common = ath9k_hw_common(ah);
532 switch (gpm_opcode) {
534 ath_dbg(common, MCI,
"MCI Recv GPM COEX Version Query\n");
535 ar9003_mci_send_coex_version_response(ah,
true);
538 ath_dbg(common, MCI,
"MCI Recv GPM COEX Version Response\n");
544 ath_dbg(common, MCI,
"MCI BT Coex version: %d.%d\n",
549 "MCI Recv GPM COEX Status Query = 0x%02X\n",
552 ar9003_mci_send_coex_wlan_channels(ah,
true);
556 ath_dbg(common, MCI,
"MCI Recv GPM COEX BT_Profile_Info\n");
561 "MCI Recv GPM COEX BT_Status_Update SEQ=%d (drop&query)\n",
569 static u32 ar9003_mci_wait_for_gpm(
struct ath_hw *ah,
u8 gpm_type,
570 u8 gpm_opcode,
int time_out)
572 struct ath_common *common = ath9k_hw_common(ah);
576 u8 recv_type = 0, recv_opcode = 0;
581 while (time_out > 0) {
588 time_out = ar9003_mci_wait_for_interrupt(ah,
606 if (recv_type == gpm_type) {
614 }
else if ((recv_type == gpm_type) &&
615 (recv_opcode == gpm_opcode))
634 u32 payload[4] = {0, 0, 0, 0};
643 ath_dbg(common, MCI,
"MCI GPM subtype not match 0x%x\n",
646 ar9003_mci_process_gpm_extra(ah, recv_type,
669 ar9003_mci_process_gpm_extra(ah, recv_type,
680 struct ath_common *common = ath9k_hw_common(ah);
682 u32 payload[4] = {0, 0, 0, 0};
696 ar9003_mci_disable_interrupt(ah);
706 ath_dbg(common, MCI,
"MCI BT_CAL_DONE received\n");
709 "MCI BT_CAL_DONE not received\n");
713 ar9003_mci_enable_interrupt(ah);
731 !ar9003_mci_check_int(ah, AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE))
742 AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE));
744 ar9003_mci_remote_reset(ah,
true);
745 ar9003_mci_send_sys_waking(ah,
true);
749 ar9003_mci_send_lna_transfer(ah,
true);
759 if (!ath9k_hw_init_cal(ah, chan))
763 ar9003_mci_enable_interrupt(ah);
767 static void ar9003_mci_mute_bt(
struct ath_hw *ah)
781 ar9003_mci_send_lna_take(ah,
true);
785 ar9003_mci_send_sys_sleeping(ah,
true);
788 static void ar9003_mci_osla_setup(
struct ath_hw *ah,
bool enable)
819 struct ath_common *common = ath9k_hw_common(ah);
823 ath_dbg(common, MCI,
"MCI Reset (full_sleep = %d, is_2g = %d)\n",
824 is_full_sleep, is_2g);
827 ath_err(common,
"MCI GPM and schedule buffers are not allocated\n");
832 ath_err(common,
"BTCOEX control register is dead\n");
859 ar9003_mci_osla_setup(ah,
true);
861 ar9003_mci_osla_setup(ah,
false);
886 ar9003_mci_mute_bt(ah);
908 ar9003_mci_observation_set_up(ah);
911 ar9003_mci_prep_interface(ah);
914 ar9003_mci_enable_interrupt(ah);
923 ar9003_mci_disable_interrupt(ah);
925 if (mci_hw->
ready && !save_fullsleep) {
926 ar9003_mci_mute_bt(ah);
932 mci_hw->
ready =
false;
935 static void ar9003_mci_send_2g5g_status(
struct ath_hw *ah,
bool wait_done)
938 u32 new_flags, to_set, to_clear;
954 ar9003_mci_send_coex_bt_flags(ah, wait_done,
958 ar9003_mci_send_coex_bt_flags(ah, wait_done,
963 static void ar9003_mci_queue_unsent_gpm(
struct ath_hw *ah,
u8 header,
1020 ar9003_mci_send_2g5g_status(ah,
true);
1021 ar9003_mci_send_lna_transfer(ah,
true);
1030 ar9003_mci_osla_setup(ah,
true);
1033 ar9003_mci_send_lna_take(ah,
true);
1041 ar9003_mci_osla_setup(ah,
false);
1042 ar9003_mci_send_2g5g_status(ah,
true);
1047 u32 *payload,
u8 len,
bool wait_done,
1050 struct ath_common *common = ath9k_hw_common(ah);
1052 bool msg_sent =
false;
1054 u32 saved_mci_int_en;
1062 "MCI Not sending 0x%x. MCI is not enabled. full_sleep = %d\n",
1064 ar9003_mci_queue_unsent_gpm(ah, header, payload,
true);
1068 "MCI Don't send message 0x%x. BT is in sleep state\n",
1070 ar9003_mci_queue_unsent_gpm(ah, header, payload,
true);
1084 for (i = 0; (i * 4) < len; i++)
1098 ar9003_mci_queue_unsent_gpm(ah, header, payload,
true);
1100 ar9003_mci_queue_unsent_gpm(ah, header, payload,
false);
1113 struct ath_common *common = ath9k_hw_common(ah);
1115 u32 pld[4] = {0, 0, 0, 0};
1127 ath_dbg(common, MCI,
"MCI BT_CAL_GRANT received\n");
1129 *is_reusable =
false;
1130 ath_dbg(common, MCI,
"MCI BT_CAL_GRANT not received\n");
1137 u32 pld[4] = {0, 0, 0, 0};
1166 ar9003_mci_disable_interrupt(ah);
1176 switch (state_type) {
1181 if ((value == 0xdeadbeef) || (value == 0xffffffff))
1199 ar9003_mci_send_coex_version_query(ah,
true);
1200 ar9003_mci_send_coex_wlan_channels(ah,
true);
1203 ar9003_mci_send_coex_halt_bt_gpm(ah,
false,
true);
1208 ar9003_mci_reset_req_wakeup(ah);
1215 ATH_MCI_CONFIG_MCI_OBS_GPIO) {
1216 ar9003_mci_observation_set_up(ah);
1221 ar9003_mci_send_coex_version_response(ah,
true);
1224 ar9003_mci_send_coex_version_query(ah,
true);
1228 ar9003_mci_send_coex_bt_status_query(ah,
true, query_type);
1231 ar9003_mci_prep_interface(ah);
1234 ar9003_mci_send_coex_wlan_channels(ah,
true);
1254 struct ath_common *common = ath9k_hw_common(ah);
1257 ath_dbg(common, MCI,
"Give LNA and SPDT control to BT\n");
1259 ar9003_mci_send_lna_take(ah,
true);
1265 ar9003_mci_send_2g5g_status(ah,
true);
1273 u32 btcoex_ctrl2, diag_sw;
1275 u8 lna_ctrl, bt_sleep;
1279 if (btcoex_ctrl2 != 0xdeadbeef)
1287 if (diag_sw != 0xdeadbeef)
1298 if (bt_sleep && (lna_ctrl == 2)) {
1307 struct ath_common *common = ath9k_hw_common(ah);
1317 ath_dbg(common, MCI,
"GPM cached write pointer mismatch %d %d\n",
1356 else if (offset >= mci->
gpm_len) {
1357 if (offset != 0xFFFF)
1363 if ((offset == 0xFFFF) || (gpm_ptr == mci->
gpm_idx)) {
1380 if (temp_index >= mci->
gpm_len)
1388 if (ar9003_mci_is_gpm_valid(ah, temp_index)) {
1389 offset = temp_index;
1416 ath_dbg(ath9k_hw_common(ah), MCI,
"MCI BT version set: %d.%d\n",
1426 ar9003_mci_send_coex_wlan_channels(ah,
true);