blob: 8b09a8239c1c492f4a9c9d8b8c06a9f249e21a8d [file] [log] [blame]
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301/*
2 * Copyright (c) 2008-2011 Atheros Communications Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#include <linux/export.h>
18#include "hw.h"
Sujith Manoharan528e5d32012-02-22 12:41:12 +053019#include "hw-ops.h"
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +053020#include "ar9003_phy.h"
21#include "ar9003_mci.h"
22
23static void ar9003_mci_reset_req_wakeup(struct ath_hw *ah)
24{
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +053025 REG_RMW_FIELD(ah, AR_MCI_COMMAND2,
26 AR_MCI_COMMAND2_RESET_REQ_WAKEUP, 1);
27 udelay(1);
28 REG_RMW_FIELD(ah, AR_MCI_COMMAND2,
29 AR_MCI_COMMAND2_RESET_REQ_WAKEUP, 0);
30}
31
32static int ar9003_mci_wait_for_interrupt(struct ath_hw *ah, u32 address,
33 u32 bit_position, int time_out)
34{
35 struct ath_common *common = ath9k_hw_common(ah);
36
37 while (time_out) {
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +053038 if (!(REG_READ(ah, address) & bit_position)) {
39 udelay(10);
40 time_out -= 10;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +053041
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +053042 if (time_out < 0)
43 break;
44 else
45 continue;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +053046 }
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +053047 REG_WRITE(ah, address, bit_position);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +053048
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +053049 if (address != AR_MCI_INTERRUPT_RX_MSG_RAW)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +053050 break;
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +053051
52 if (bit_position & AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE)
53 ar9003_mci_reset_req_wakeup(ah);
54
55 if (bit_position & (AR_MCI_INTERRUPT_RX_MSG_SYS_SLEEPING |
56 AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING))
57 REG_WRITE(ah, AR_MCI_INTERRUPT_RAW,
58 AR_MCI_INTERRUPT_REMOTE_SLEEP_UPDATE);
59
60 REG_WRITE(ah, AR_MCI_INTERRUPT_RAW, AR_MCI_INTERRUPT_RX_MSG);
61 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +053062 }
63
64 if (time_out <= 0) {
Joe Perchesd2182b62011-12-15 14:55:53 -080065 ath_dbg(common, MCI,
66 "MCI Wait for Reg 0x%08x = 0x%08x timeout\n",
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +053067 address, bit_position);
Joe Perchesd2182b62011-12-15 14:55:53 -080068 ath_dbg(common, MCI,
69 "MCI INT_RAW = 0x%08x, RX_MSG_RAW = 0x%08x\n",
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +053070 REG_READ(ah, AR_MCI_INTERRUPT_RAW),
71 REG_READ(ah, AR_MCI_INTERRUPT_RX_MSG_RAW));
72 time_out = 0;
73 }
74
75 return time_out;
76}
77
Sujith Manoharana3f846f2012-02-22 12:41:24 +053078static void ar9003_mci_remote_reset(struct ath_hw *ah, bool wait_done)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +053079{
80 u32 payload[4] = { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffff00};
81
82 ar9003_mci_send_message(ah, MCI_REMOTE_RESET, 0, payload, 16,
83 wait_done, false);
84 udelay(5);
85}
86
Sujith Manoharana3f846f2012-02-22 12:41:24 +053087static void ar9003_mci_send_lna_transfer(struct ath_hw *ah, bool wait_done)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +053088{
89 u32 payload = 0x00000000;
90
91 ar9003_mci_send_message(ah, MCI_LNA_TRANS, 0, &payload, 1,
92 wait_done, false);
93}
94
95static void ar9003_mci_send_req_wake(struct ath_hw *ah, bool wait_done)
96{
97 ar9003_mci_send_message(ah, MCI_REQ_WAKE, MCI_FLAG_DISABLE_TIMESTAMP,
98 NULL, 0, wait_done, false);
99 udelay(5);
100}
101
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530102static void ar9003_mci_send_sys_waking(struct ath_hw *ah, bool wait_done)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530103{
104 ar9003_mci_send_message(ah, MCI_SYS_WAKING, MCI_FLAG_DISABLE_TIMESTAMP,
105 NULL, 0, wait_done, false);
106}
107
108static void ar9003_mci_send_lna_take(struct ath_hw *ah, bool wait_done)
109{
110 u32 payload = 0x70000000;
111
112 ar9003_mci_send_message(ah, MCI_LNA_TAKE, 0, &payload, 1,
113 wait_done, false);
114}
115
116static void ar9003_mci_send_sys_sleeping(struct ath_hw *ah, bool wait_done)
117{
118 ar9003_mci_send_message(ah, MCI_SYS_SLEEPING,
119 MCI_FLAG_DISABLE_TIMESTAMP,
120 NULL, 0, wait_done, false);
121}
122
123static void ar9003_mci_send_coex_version_query(struct ath_hw *ah,
124 bool wait_done)
125{
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530126 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
127 u32 payload[4] = {0, 0, 0, 0};
128
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530129 if (mci->bt_version_known ||
130 (mci->bt_state == MCI_BT_SLEEP))
131 return;
132
133 MCI_GPM_SET_TYPE_OPCODE(payload, MCI_GPM_COEX_AGENT,
134 MCI_GPM_COEX_VERSION_QUERY);
135 ar9003_mci_send_message(ah, MCI_GPM, 0, payload, 16, wait_done, true);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530136}
137
138static void ar9003_mci_send_coex_version_response(struct ath_hw *ah,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530139 bool wait_done)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530140{
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530141 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
142 u32 payload[4] = {0, 0, 0, 0};
143
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530144 MCI_GPM_SET_TYPE_OPCODE(payload, MCI_GPM_COEX_AGENT,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530145 MCI_GPM_COEX_VERSION_RESPONSE);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530146 *(((u8 *)payload) + MCI_GPM_COEX_B_MAJOR_VERSION) =
147 mci->wlan_ver_major;
148 *(((u8 *)payload) + MCI_GPM_COEX_B_MINOR_VERSION) =
149 mci->wlan_ver_minor;
150 ar9003_mci_send_message(ah, MCI_GPM, 0, payload, 16, wait_done, true);
151}
152
153static void ar9003_mci_send_coex_wlan_channels(struct ath_hw *ah,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530154 bool wait_done)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530155{
156 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
157 u32 *payload = &mci->wlan_channels[0];
158
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530159 if (!mci->wlan_channels_update ||
160 (mci->bt_state == MCI_BT_SLEEP))
161 return;
162
163 MCI_GPM_SET_TYPE_OPCODE(payload, MCI_GPM_COEX_AGENT,
164 MCI_GPM_COEX_WLAN_CHANNELS);
165 ar9003_mci_send_message(ah, MCI_GPM, 0, payload, 16, wait_done, true);
166 MCI_GPM_SET_TYPE_OPCODE(payload, 0xff, 0xff);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530167}
168
169static void ar9003_mci_send_coex_bt_status_query(struct ath_hw *ah,
170 bool wait_done, u8 query_type)
171{
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530172 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
173 u32 payload[4] = {0, 0, 0, 0};
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530174 bool query_btinfo;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530175
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530176 if (mci->bt_state == MCI_BT_SLEEP)
177 return;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530178
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530179 query_btinfo = !!(query_type & (MCI_GPM_COEX_QUERY_BT_ALL_INFO |
180 MCI_GPM_COEX_QUERY_BT_TOPOLOGY));
181 MCI_GPM_SET_TYPE_OPCODE(payload, MCI_GPM_COEX_AGENT,
182 MCI_GPM_COEX_STATUS_QUERY);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530183
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530184 *(((u8 *)payload) + MCI_GPM_COEX_B_BT_BITMAP) = query_type;
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530185
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530186 /*
187 * If bt_status_query message is not sent successfully,
188 * then need_flush_btinfo should be set again.
189 */
190 if (!ar9003_mci_send_message(ah, MCI_GPM, 0, payload, 16,
191 wait_done, true)) {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530192 if (query_btinfo)
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530193 mci->need_flush_btinfo = true;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530194 }
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530195
196 if (query_btinfo)
197 mci->query_bt = false;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530198}
199
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530200static void ar9003_mci_send_coex_halt_bt_gpm(struct ath_hw *ah, bool halt,
201 bool wait_done)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530202{
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530203 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
204 u32 payload[4] = {0, 0, 0, 0};
205
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530206 MCI_GPM_SET_TYPE_OPCODE(payload, MCI_GPM_COEX_AGENT,
207 MCI_GPM_COEX_HALT_BT_GPM);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530208
209 if (halt) {
210 mci->query_bt = true;
211 /* Send next unhalt no matter halt sent or not */
212 mci->unhalt_bt_gpm = true;
213 mci->need_flush_btinfo = true;
214 *(((u8 *)payload) + MCI_GPM_COEX_B_HALT_STATE) =
215 MCI_GPM_COEX_BT_GPM_HALT;
216 } else
217 *(((u8 *)payload) + MCI_GPM_COEX_B_HALT_STATE) =
218 MCI_GPM_COEX_BT_GPM_UNHALT;
219
220 ar9003_mci_send_message(ah, MCI_GPM, 0, payload, 16, wait_done, true);
221}
222
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530223static void ar9003_mci_prep_interface(struct ath_hw *ah)
224{
225 struct ath_common *common = ath9k_hw_common(ah);
226 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
227 u32 saved_mci_int_en;
228 u32 mci_timeout = 150;
229
230 mci->bt_state = MCI_BT_SLEEP;
231 saved_mci_int_en = REG_READ(ah, AR_MCI_INTERRUPT_EN);
232
233 REG_WRITE(ah, AR_MCI_INTERRUPT_EN, 0);
234 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
235 REG_READ(ah, AR_MCI_INTERRUPT_RX_MSG_RAW));
236 REG_WRITE(ah, AR_MCI_INTERRUPT_RAW,
237 REG_READ(ah, AR_MCI_INTERRUPT_RAW));
238
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530239 ar9003_mci_remote_reset(ah, true);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530240 ar9003_mci_send_req_wake(ah, true);
241
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530242 if (!ar9003_mci_wait_for_interrupt(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
243 AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING, 500))
244 goto clear_redunt;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530245
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530246 mci->bt_state = MCI_BT_AWAKE;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530247
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530248 /*
249 * we don't need to send more remote_reset at this moment.
250 * If BT receive first remote_reset, then BT HW will
251 * be cleaned up and will be able to receive req_wake
252 * and BT HW will respond sys_waking.
253 * In this case, WLAN will receive BT's HW sys_waking.
254 * Otherwise, if BT SW missed initial remote_reset,
255 * that remote_reset will still clean up BT MCI RX,
256 * and the req_wake will wake BT up,
257 * and BT SW will respond this req_wake with a remote_reset and
258 * sys_waking. In this case, WLAN will receive BT's SW
259 * sys_waking. In either case, BT's RX is cleaned up. So we
260 * don't need to reply BT's remote_reset now, if any.
261 * Similarly, if in any case, WLAN can receive BT's sys_waking,
262 * that means WLAN's RX is also fine.
263 */
264 ar9003_mci_send_sys_waking(ah, true);
265 udelay(10);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530266
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530267 /*
268 * Set BT priority interrupt value to be 0xff to
269 * avoid having too many BT PRIORITY interrupts.
270 */
271 REG_WRITE(ah, AR_MCI_BT_PRI0, 0xFFFFFFFF);
272 REG_WRITE(ah, AR_MCI_BT_PRI1, 0xFFFFFFFF);
273 REG_WRITE(ah, AR_MCI_BT_PRI2, 0xFFFFFFFF);
274 REG_WRITE(ah, AR_MCI_BT_PRI3, 0xFFFFFFFF);
275 REG_WRITE(ah, AR_MCI_BT_PRI, 0X000000FF);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530276
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530277 /*
278 * A contention reset will be received after send out
279 * sys_waking. Also BT priority interrupt bits will be set.
280 * Clear those bits before the next step.
281 */
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530282
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530283 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
284 AR_MCI_INTERRUPT_RX_MSG_CONT_RST);
285 REG_WRITE(ah, AR_MCI_INTERRUPT_RAW, AR_MCI_INTERRUPT_BT_PRI);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530286
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530287 if (mci->is_2g) {
288 ar9003_mci_send_lna_transfer(ah, true);
289 udelay(5);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530290 }
291
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530292 if ((mci->is_2g && !mci->update_2g5g)) {
293 if (ar9003_mci_wait_for_interrupt(ah,
294 AR_MCI_INTERRUPT_RX_MSG_RAW,
295 AR_MCI_INTERRUPT_RX_MSG_LNA_INFO,
296 mci_timeout))
297 ath_dbg(common, MCI,
298 "MCI WLAN has control over the LNA & BT obeys it\n");
299 else
300 ath_dbg(common, MCI,
301 "MCI BT didn't respond to LNA_TRANS\n");
302 }
303
304clear_redunt:
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530305 /* Clear the extra redundant SYS_WAKING from BT */
306 if ((mci->bt_state == MCI_BT_AWAKE) &&
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530307 (REG_READ_FIELD(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
308 AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING)) &&
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530309 (REG_READ_FIELD(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
310 AR_MCI_INTERRUPT_RX_MSG_SYS_SLEEPING) == 0)) {
311 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
312 AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING);
313 REG_WRITE(ah, AR_MCI_INTERRUPT_RAW,
314 AR_MCI_INTERRUPT_REMOTE_SLEEP_UPDATE);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530315 }
316
317 REG_WRITE(ah, AR_MCI_INTERRUPT_EN, saved_mci_int_en);
318}
319
Sujith Manoharand1ca8b82012-02-22 12:41:01 +0530320void ar9003_mci_set_full_sleep(struct ath_hw *ah)
321{
Sujith Manoharand1ca8b82012-02-22 12:41:01 +0530322 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
323
324 if (ar9003_mci_state(ah, MCI_STATE_ENABLE, NULL) &&
325 (mci->bt_state != MCI_BT_SLEEP) &&
326 !mci->halted_bt_gpm) {
Sujith Manoharand1ca8b82012-02-22 12:41:01 +0530327 ar9003_mci_send_coex_halt_bt_gpm(ah, true, true);
328 }
329
330 mci->ready = false;
Sujith Manoharand1ca8b82012-02-22 12:41:01 +0530331}
332
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530333static void ar9003_mci_disable_interrupt(struct ath_hw *ah)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530334{
335 REG_WRITE(ah, AR_MCI_INTERRUPT_EN, 0);
336 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_EN, 0);
337}
338
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530339static void ar9003_mci_enable_interrupt(struct ath_hw *ah)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530340{
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530341 REG_WRITE(ah, AR_MCI_INTERRUPT_EN, AR_MCI_INTERRUPT_DEFAULT);
342 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_EN,
343 AR_MCI_INTERRUPT_RX_MSG_DEFAULT);
344}
345
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530346static bool ar9003_mci_check_int(struct ath_hw *ah, u32 ints)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530347{
348 u32 intr;
349
350 intr = REG_READ(ah, AR_MCI_INTERRUPT_RX_MSG_RAW);
351 return ((intr & ints) == ints);
352}
353
354void ar9003_mci_get_interrupt(struct ath_hw *ah, u32 *raw_intr,
355 u32 *rx_msg_intr)
356{
357 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
Felix Fietkau8a309302011-12-17 16:47:56 +0100358
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530359 *raw_intr = mci->raw_intr;
360 *rx_msg_intr = mci->rx_msg_intr;
361
362 /* Clean int bits after the values are read. */
363 mci->raw_intr = 0;
364 mci->rx_msg_intr = 0;
365}
366EXPORT_SYMBOL(ar9003_mci_get_interrupt);
367
Sujith Manoharan5a1e2732012-02-22 12:40:55 +0530368void ar9003_mci_get_isr(struct ath_hw *ah, enum ath9k_int *masked)
369{
370 struct ath_common *common = ath9k_hw_common(ah);
371 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
372 u32 raw_intr, rx_msg_intr;
373
374 rx_msg_intr = REG_READ(ah, AR_MCI_INTERRUPT_RX_MSG_RAW);
375 raw_intr = REG_READ(ah, AR_MCI_INTERRUPT_RAW);
376
377 if ((raw_intr == 0xdeadbeef) || (rx_msg_intr == 0xdeadbeef)) {
378 ath_dbg(common, MCI,
379 "MCI gets 0xdeadbeef during int processing\n");
380 } else {
381 mci->rx_msg_intr |= rx_msg_intr;
382 mci->raw_intr |= raw_intr;
383 *masked |= ATH9K_INT_MCI;
384
385 if (rx_msg_intr & AR_MCI_INTERRUPT_RX_MSG_CONT_INFO)
386 mci->cont_status = REG_READ(ah, AR_MCI_CONT_STATUS);
387
388 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_RAW, rx_msg_intr);
389 REG_WRITE(ah, AR_MCI_INTERRUPT_RAW, raw_intr);
390 }
391}
392
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530393static void ar9003_mci_2g5g_changed(struct ath_hw *ah, bool is_2g)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530394{
395 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
396
397 if (!mci->update_2g5g &&
398 (mci->is_2g != is_2g))
399 mci->update_2g5g = true;
400
401 mci->is_2g = is_2g;
402}
403
404static bool ar9003_mci_is_gpm_valid(struct ath_hw *ah, u32 msg_index)
405{
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530406 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
407 u32 *payload;
408 u32 recv_type, offset;
409
410 if (msg_index == MCI_GPM_INVALID)
411 return false;
412
413 offset = msg_index << 4;
414
415 payload = (u32 *)(mci->gpm_buf + offset);
416 recv_type = MCI_GPM_TYPE(payload);
417
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530418 if (recv_type == MCI_GPM_RSVD_PATTERN)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530419 return false;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530420
421 return true;
422}
423
424static void ar9003_mci_observation_set_up(struct ath_hw *ah)
425{
426 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530427
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530428 if (mci->config & ATH_MCI_CONFIG_MCI_OBS_MCI) {
429 ath9k_hw_cfg_output(ah, 3, AR_GPIO_OUTPUT_MUX_AS_MCI_WLAN_DATA);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530430 ath9k_hw_cfg_output(ah, 2, AR_GPIO_OUTPUT_MUX_AS_MCI_WLAN_CLK);
431 ath9k_hw_cfg_output(ah, 1, AR_GPIO_OUTPUT_MUX_AS_MCI_BT_DATA);
432 ath9k_hw_cfg_output(ah, 0, AR_GPIO_OUTPUT_MUX_AS_MCI_BT_CLK);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530433 } else if (mci->config & ATH_MCI_CONFIG_MCI_OBS_TXRX) {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530434 ath9k_hw_cfg_output(ah, 3, AR_GPIO_OUTPUT_MUX_AS_WL_IN_TX);
435 ath9k_hw_cfg_output(ah, 2, AR_GPIO_OUTPUT_MUX_AS_WL_IN_RX);
436 ath9k_hw_cfg_output(ah, 1, AR_GPIO_OUTPUT_MUX_AS_BT_IN_TX);
437 ath9k_hw_cfg_output(ah, 0, AR_GPIO_OUTPUT_MUX_AS_BT_IN_RX);
438 ath9k_hw_cfg_output(ah, 5, AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530439 } else if (mci->config & ATH_MCI_CONFIG_MCI_OBS_BT) {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530440 ath9k_hw_cfg_output(ah, 3, AR_GPIO_OUTPUT_MUX_AS_BT_IN_TX);
441 ath9k_hw_cfg_output(ah, 2, AR_GPIO_OUTPUT_MUX_AS_BT_IN_RX);
442 ath9k_hw_cfg_output(ah, 1, AR_GPIO_OUTPUT_MUX_AS_MCI_BT_DATA);
443 ath9k_hw_cfg_output(ah, 0, AR_GPIO_OUTPUT_MUX_AS_MCI_BT_CLK);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530444 } else
445 return;
446
447 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
448
Sujith Manoharan0cc4cde2012-02-22 12:42:15 +0530449 REG_RMW_FIELD(ah, AR_PHY_GLB_CONTROL, AR_GLB_DS_JTAG_DISABLE, 1);
450 REG_RMW_FIELD(ah, AR_PHY_GLB_CONTROL, AR_GLB_WLAN_UART_INTF_EN, 0);
451 REG_SET_BIT(ah, AR_GLB_GPIO_CONTROL, ATH_MCI_CONFIG_MCI_OBS_GPIO);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530452
453 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL2, AR_BTCOEX_CTRL2_GPIO_OBS_SEL, 0);
454 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL2, AR_BTCOEX_CTRL2_MAC_BB_OBS_SEL, 1);
455 REG_WRITE(ah, AR_OBS, 0x4b);
456 REG_RMW_FIELD(ah, AR_DIAG_SW, AR_DIAG_OBS_PT_SEL1, 0x03);
457 REG_RMW_FIELD(ah, AR_DIAG_SW, AR_DIAG_OBS_PT_SEL2, 0x01);
458 REG_RMW_FIELD(ah, AR_MACMISC, AR_MACMISC_MISC_OBS_BUS_LSB, 0x02);
459 REG_RMW_FIELD(ah, AR_MACMISC, AR_MACMISC_MISC_OBS_BUS_MSB, 0x03);
460 REG_RMW_FIELD(ah, AR_PHY_TEST_CTL_STATUS,
461 AR_PHY_TEST_CTL_DEBUGPORT_SEL, 0x07);
462}
463
464static bool ar9003_mci_send_coex_bt_flags(struct ath_hw *ah, bool wait_done,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530465 u8 opcode, u32 bt_flags)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530466{
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530467 u32 pld[4] = {0, 0, 0, 0};
468
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530469 MCI_GPM_SET_TYPE_OPCODE(pld, MCI_GPM_COEX_AGENT,
470 MCI_GPM_COEX_BT_UPDATE_FLAGS);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530471
472 *(((u8 *)pld) + MCI_GPM_COEX_B_BT_FLAGS_OP) = opcode;
473 *(((u8 *)pld) + MCI_GPM_COEX_W_BT_FLAGS + 0) = bt_flags & 0xFF;
474 *(((u8 *)pld) + MCI_GPM_COEX_W_BT_FLAGS + 1) = (bt_flags >> 8) & 0xFF;
475 *(((u8 *)pld) + MCI_GPM_COEX_W_BT_FLAGS + 2) = (bt_flags >> 16) & 0xFF;
476 *(((u8 *)pld) + MCI_GPM_COEX_W_BT_FLAGS + 3) = (bt_flags >> 24) & 0xFF;
477
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530478 return ar9003_mci_send_message(ah, MCI_GPM, 0, pld, 16,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530479 wait_done, true);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530480}
481
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530482static void ar9003_mci_sync_bt_state(struct ath_hw *ah)
483{
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530484 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
485 u32 cur_bt_state;
486
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530487 cur_bt_state = ar9003_mci_state(ah, MCI_STATE_REMOTE_SLEEP, NULL);
488
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530489 if (mci->bt_state != cur_bt_state)
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530490 mci->bt_state = cur_bt_state;
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530491
492 if (mci->bt_state != MCI_BT_SLEEP) {
493
494 ar9003_mci_send_coex_version_query(ah, true);
495 ar9003_mci_send_coex_wlan_channels(ah, true);
496
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530497 if (mci->unhalt_bt_gpm == true)
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530498 ar9003_mci_send_coex_halt_bt_gpm(ah, false, true);
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530499 }
500}
501
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530502void ar9003_mci_check_bt(struct ath_hw *ah)
503{
504 struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
505
506 if (!mci_hw->ready)
507 return;
508
509 /*
510 * check BT state again to make
511 * sure it's not changed.
512 */
513 ar9003_mci_sync_bt_state(ah);
514 ar9003_mci_2g5g_switch(ah, true);
515
516 if ((mci_hw->bt_state == MCI_BT_AWAKE) &&
517 (mci_hw->query_bt == true)) {
518 mci_hw->need_flush_btinfo = true;
519 }
520}
521
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530522static void ar9003_mci_process_gpm_extra(struct ath_hw *ah, u8 gpm_type,
523 u8 gpm_opcode, u32 *p_gpm)
524{
525 struct ath_common *common = ath9k_hw_common(ah);
526 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
527 u8 *p_data = (u8 *) p_gpm;
528
529 if (gpm_type != MCI_GPM_COEX_AGENT)
530 return;
531
532 switch (gpm_opcode) {
533 case MCI_GPM_COEX_VERSION_QUERY:
534 ath_dbg(common, MCI, "MCI Recv GPM COEX Version Query\n");
535 ar9003_mci_send_coex_version_response(ah, true);
536 break;
537 case MCI_GPM_COEX_VERSION_RESPONSE:
538 ath_dbg(common, MCI, "MCI Recv GPM COEX Version Response\n");
539 mci->bt_ver_major =
540 *(p_data + MCI_GPM_COEX_B_MAJOR_VERSION);
541 mci->bt_ver_minor =
542 *(p_data + MCI_GPM_COEX_B_MINOR_VERSION);
543 mci->bt_version_known = true;
544 ath_dbg(common, MCI, "MCI BT Coex version: %d.%d\n",
545 mci->bt_ver_major, mci->bt_ver_minor);
546 break;
547 case MCI_GPM_COEX_STATUS_QUERY:
548 ath_dbg(common, MCI,
549 "MCI Recv GPM COEX Status Query = 0x%02X\n",
550 *(p_data + MCI_GPM_COEX_B_WLAN_BITMAP));
551 mci->wlan_channels_update = true;
552 ar9003_mci_send_coex_wlan_channels(ah, true);
553 break;
554 case MCI_GPM_COEX_BT_PROFILE_INFO:
555 mci->query_bt = true;
556 ath_dbg(common, MCI, "MCI Recv GPM COEX BT_Profile_Info\n");
557 break;
558 case MCI_GPM_COEX_BT_STATUS_UPDATE:
559 mci->query_bt = true;
560 ath_dbg(common, MCI,
561 "MCI Recv GPM COEX BT_Status_Update SEQ=%d (drop&query)\n",
562 *(p_gpm + 3));
563 break;
564 default:
565 break;
566 }
567}
568
569static u32 ar9003_mci_wait_for_gpm(struct ath_hw *ah, u8 gpm_type,
570 u8 gpm_opcode, int time_out)
571{
572 struct ath_common *common = ath9k_hw_common(ah);
573 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
574 u32 *p_gpm = NULL, mismatch = 0, more_data;
575 u32 offset;
576 u8 recv_type = 0, recv_opcode = 0;
577 bool b_is_bt_cal_done = (gpm_type == MCI_GPM_BT_CAL_DONE);
578
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530579 more_data = time_out ? MCI_GPM_NOMORE : MCI_GPM_MORE;
580
581 while (time_out > 0) {
582 if (p_gpm) {
583 MCI_GPM_RECYCLE(p_gpm);
584 p_gpm = NULL;
585 }
586
587 if (more_data != MCI_GPM_MORE)
588 time_out = ar9003_mci_wait_for_interrupt(ah,
589 AR_MCI_INTERRUPT_RX_MSG_RAW,
590 AR_MCI_INTERRUPT_RX_MSG_GPM,
591 time_out);
592
593 if (!time_out)
594 break;
595
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530596 offset = ar9003_mci_state(ah, MCI_STATE_NEXT_GPM_OFFSET,
597 &more_data);
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530598
599 if (offset == MCI_GPM_INVALID)
600 continue;
601
602 p_gpm = (u32 *) (mci->gpm_buf + offset);
603 recv_type = MCI_GPM_TYPE(p_gpm);
604 recv_opcode = MCI_GPM_OPCODE(p_gpm);
605
606 if (MCI_GPM_IS_CAL_TYPE(recv_type)) {
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530607 if (recv_type == gpm_type) {
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530608 if ((gpm_type == MCI_GPM_BT_CAL_DONE) &&
609 !b_is_bt_cal_done) {
610 gpm_type = MCI_GPM_BT_CAL_GRANT;
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530611 continue;
612 }
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530613 break;
614 }
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530615 } else if ((recv_type == gpm_type) &&
616 (recv_opcode == gpm_opcode))
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530617 break;
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530618
619 /*
620 * check if it's cal_grant
621 *
622 * When we're waiting for cal_grant in reset routine,
623 * it's possible that BT sends out cal_request at the
624 * same time. Since BT's calibration doesn't happen
625 * that often, we'll let BT completes calibration then
626 * we continue to wait for cal_grant from BT.
627 * Orginal: Wait BT_CAL_GRANT.
628 * New: Receive BT_CAL_REQ -> send WLAN_CAL_GRANT->wait
629 * BT_CAL_DONE -> Wait BT_CAL_GRANT.
630 */
631
632 if ((gpm_type == MCI_GPM_BT_CAL_GRANT) &&
633 (recv_type == MCI_GPM_BT_CAL_REQ)) {
634
635 u32 payload[4] = {0, 0, 0, 0};
636
637 gpm_type = MCI_GPM_BT_CAL_DONE;
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530638 MCI_GPM_SET_CAL_TYPE(payload,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530639 MCI_GPM_WLAN_CAL_GRANT);
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530640 ar9003_mci_send_message(ah, MCI_GPM, 0, payload, 16,
641 false, false);
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530642 continue;
643 } else {
644 ath_dbg(common, MCI, "MCI GPM subtype not match 0x%x\n",
645 *(p_gpm + 1));
646 mismatch++;
647 ar9003_mci_process_gpm_extra(ah, recv_type,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530648 recv_opcode, p_gpm);
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530649 }
650 }
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530651
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530652 if (p_gpm) {
653 MCI_GPM_RECYCLE(p_gpm);
654 p_gpm = NULL;
655 }
656
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530657 if (time_out <= 0)
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530658 time_out = 0;
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530659
660 while (more_data == MCI_GPM_MORE) {
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530661 offset = ar9003_mci_state(ah, MCI_STATE_NEXT_GPM_OFFSET,
662 &more_data);
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530663 if (offset == MCI_GPM_INVALID)
664 break;
665
666 p_gpm = (u32 *) (mci->gpm_buf + offset);
667 recv_type = MCI_GPM_TYPE(p_gpm);
668 recv_opcode = MCI_GPM_OPCODE(p_gpm);
669
670 if (!MCI_GPM_IS_CAL_TYPE(recv_type))
671 ar9003_mci_process_gpm_extra(ah, recv_type,
672 recv_opcode, p_gpm);
673
674 MCI_GPM_RECYCLE(p_gpm);
675 }
676
677 return time_out;
678}
679
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530680bool ar9003_mci_start_reset(struct ath_hw *ah, struct ath9k_channel *chan)
681{
682 struct ath_common *common = ath9k_hw_common(ah);
683 struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
684 u32 payload[4] = {0, 0, 0, 0};
685
686 ar9003_mci_2g5g_changed(ah, IS_CHAN_2GHZ(chan));
687
688 if (mci_hw->bt_state != MCI_BT_CAL_START)
689 return false;
690
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530691 mci_hw->bt_state = MCI_BT_CAL;
692
693 /*
694 * MCI FIX: disable mci interrupt here. This is to avoid
695 * SW_MSG_DONE or RX_MSG bits to trigger MCI_INT and
696 * lead to mci_intr reentry.
697 */
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530698 ar9003_mci_disable_interrupt(ah);
699
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530700 MCI_GPM_SET_CAL_TYPE(payload, MCI_GPM_WLAN_CAL_GRANT);
701 ar9003_mci_send_message(ah, MCI_GPM, 0, payload,
702 16, true, false);
703
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530704 /* Wait BT calibration to be completed for 25ms */
705
706 if (ar9003_mci_wait_for_gpm(ah, MCI_GPM_BT_CAL_DONE,
707 0, 25000))
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530708 ath_dbg(common, MCI, "MCI BT_CAL_DONE received\n");
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530709 else
710 ath_dbg(common, MCI,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530711 "MCI BT_CAL_DONE not received\n");
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530712
713 mci_hw->bt_state = MCI_BT_AWAKE;
714 /* MCI FIX: enable mci interrupt here */
715 ar9003_mci_enable_interrupt(ah);
716
717 return true;
718}
719
720int ar9003_mci_end_reset(struct ath_hw *ah, struct ath9k_channel *chan,
721 struct ath9k_hw_cal_data *caldata)
722{
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530723 struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
724
725 if (!mci_hw->ready)
726 return 0;
727
728 if (!IS_CHAN_2GHZ(chan) || (mci_hw->bt_state != MCI_BT_SLEEP))
729 goto exit;
730
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530731 if (!ar9003_mci_check_int(ah, AR_MCI_INTERRUPT_RX_MSG_REMOTE_RESET) &&
732 !ar9003_mci_check_int(ah, AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE))
733 goto exit;
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530734
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530735 /*
736 * BT is sleeping. Check if BT wakes up during
737 * WLAN calibration. If BT wakes up during
738 * WLAN calibration, need to go through all
739 * message exchanges again and recal.
740 */
741 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
742 (AR_MCI_INTERRUPT_RX_MSG_REMOTE_RESET |
743 AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE));
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530744
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530745 ar9003_mci_remote_reset(ah, true);
746 ar9003_mci_send_sys_waking(ah, true);
747 udelay(1);
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530748
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530749 if (IS_CHAN_2GHZ(chan))
750 ar9003_mci_send_lna_transfer(ah, true);
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530751
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530752 mci_hw->bt_state = MCI_BT_AWAKE;
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530753
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530754 if (caldata) {
755 caldata->done_txiqcal_once = false;
756 caldata->done_txclcal_once = false;
757 caldata->rtt_done = false;
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530758 }
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530759
760 if (!ath9k_hw_init_cal(ah, chan))
761 return -EIO;
762
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530763exit:
764 ar9003_mci_enable_interrupt(ah);
765 return 0;
766}
767
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530768static void ar9003_mci_mute_bt(struct ath_hw *ah)
769{
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530770 /* disable all MCI messages */
771 REG_WRITE(ah, AR_MCI_MSG_ATTRIBUTES_TABLE, 0xffff0000);
772 REG_WRITE(ah, AR_BTCOEX_WL_WEIGHTS0, 0xffffffff);
773 REG_WRITE(ah, AR_BTCOEX_WL_WEIGHTS1, 0xffffffff);
774 REG_WRITE(ah, AR_BTCOEX_WL_WEIGHTS2, 0xffffffff);
775 REG_WRITE(ah, AR_BTCOEX_WL_WEIGHTS3, 0xffffffff);
776 REG_SET_BIT(ah, AR_MCI_TX_CTRL, AR_MCI_TX_CTRL_DISABLE_LNA_UPDATE);
777
778 /* wait pending HW messages to flush out */
779 udelay(10);
780
781 /*
782 * Send LNA_TAKE and SYS_SLEEPING when
783 * 1. reset not after resuming from full sleep
784 * 2. before reset MCI RX, to quiet BT and avoid MCI RX misalignment
785 */
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530786 ar9003_mci_send_lna_take(ah, true);
787
788 udelay(5);
789
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530790 ar9003_mci_send_sys_sleeping(ah, true);
791}
792
Sujith Manoharan4f851df2012-02-22 12:42:10 +0530793static void ar9003_mci_osla_setup(struct ath_hw *ah, bool enable)
794{
795 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
796 u32 thresh;
797
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530798 if (!enable) {
Sujith Manoharan4f851df2012-02-22 12:42:10 +0530799 REG_CLR_BIT(ah, AR_BTCOEX_CTRL,
800 AR_BTCOEX_CTRL_ONE_STEP_LOOK_AHEAD_EN);
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530801 return;
Sujith Manoharan4f851df2012-02-22 12:42:10 +0530802 }
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530803 REG_RMW_FIELD(ah, AR_MCI_SCHD_TABLE_2, AR_MCI_SCHD_TABLE_2_HW_BASED, 1);
804 REG_RMW_FIELD(ah, AR_MCI_SCHD_TABLE_2,
805 AR_MCI_SCHD_TABLE_2_MEM_BASED, 1);
806
807 if (!(mci->config & ATH_MCI_CONFIG_DISABLE_AGGR_THRESH)) {
808 thresh = MS(mci->config, ATH_MCI_CONFIG_AGGR_THRESH);
809 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL,
810 AR_BTCOEX_CTRL_AGGR_THRESH, thresh);
811 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL,
812 AR_BTCOEX_CTRL_TIME_TO_NEXT_BT_THRESH_EN, 1);
813 } else
814 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL,
815 AR_BTCOEX_CTRL_TIME_TO_NEXT_BT_THRESH_EN, 0);
816
817 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL,
818 AR_BTCOEX_CTRL_ONE_STEP_LOOK_AHEAD_EN, 1);
Sujith Manoharan4f851df2012-02-22 12:42:10 +0530819}
820
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530821void ar9003_mci_reset(struct ath_hw *ah, bool en_int, bool is_2g,
822 bool is_full_sleep)
823{
824 struct ath_common *common = ath9k_hw_common(ah);
825 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
Sujith Manoharan4f851df2012-02-22 12:42:10 +0530826 u32 regval;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530827
Sujith Manoharan4f851df2012-02-22 12:42:10 +0530828 ath_dbg(common, MCI, "MCI Reset (full_sleep = %d, is_2g = %d)\n",
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530829 is_full_sleep, is_2g);
830
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530831 if (!mci->gpm_addr && !mci->sched_addr) {
Joe Perchesd2182b62011-12-15 14:55:53 -0800832 ath_dbg(common, MCI,
833 "MCI GPM and schedule buffers are not allocated\n");
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530834 return;
835 }
836
837 if (REG_READ(ah, AR_BTCOEX_CTRL) == 0xdeadbeef) {
Sujith Manoharan4f851df2012-02-22 12:42:10 +0530838 ath_dbg(common, MCI, "BTCOEX control register is dead\n");
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530839 return;
840 }
841
842 /* Program MCI DMA related registers */
843 REG_WRITE(ah, AR_MCI_GPM_0, mci->gpm_addr);
844 REG_WRITE(ah, AR_MCI_GPM_1, mci->gpm_len);
845 REG_WRITE(ah, AR_MCI_SCHD_TABLE_0, mci->sched_addr);
846
847 /*
848 * To avoid MCI state machine be affected by incoming remote MCI msgs,
849 * MCI mode will be enabled later, right before reset the MCI TX and RX.
850 */
851
852 regval = SM(1, AR_BTCOEX_CTRL_AR9462_MODE) |
853 SM(1, AR_BTCOEX_CTRL_WBTIMER_EN) |
854 SM(1, AR_BTCOEX_CTRL_PA_SHARED) |
855 SM(1, AR_BTCOEX_CTRL_LNA_SHARED) |
856 SM(2, AR_BTCOEX_CTRL_NUM_ANTENNAS) |
857 SM(3, AR_BTCOEX_CTRL_RX_CHAIN_MASK) |
858 SM(0, AR_BTCOEX_CTRL_1_CHAIN_ACK) |
859 SM(0, AR_BTCOEX_CTRL_1_CHAIN_BCN) |
860 SM(0, AR_BTCOEX_CTRL_ONE_STEP_LOOK_AHEAD_EN);
861
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530862 REG_WRITE(ah, AR_BTCOEX_CTRL, regval);
863
Sujith Manoharan4f851df2012-02-22 12:42:10 +0530864 if (is_2g && !(mci->config & ATH_MCI_CONFIG_DISABLE_OSLA))
865 ar9003_mci_osla_setup(ah, true);
866 else
867 ar9003_mci_osla_setup(ah, false);
868
869 REG_SET_BIT(ah, AR_PHY_GLB_CONTROL,
870 AR_BTCOEX_CTRL_SPDT_ENABLE);
871 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL3,
872 AR_BTCOEX_CTRL3_CONT_INFO_TIMEOUT, 20);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530873
874 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL2, AR_BTCOEX_CTRL2_RX_DEWEIGHT, 1);
875 REG_RMW_FIELD(ah, AR_PCU_MISC, AR_PCU_BT_ANT_PREVENT_RX, 0);
876
Sujith Manoharan4f851df2012-02-22 12:42:10 +0530877 regval = MS(mci->config, ATH_MCI_CONFIG_CLK_DIV);
878 REG_RMW_FIELD(ah, AR_MCI_TX_CTRL, AR_MCI_TX_CTRL_CLK_DIV, regval);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530879 REG_SET_BIT(ah, AR_BTCOEX_CTRL, AR_BTCOEX_CTRL_MCI_MODE_EN);
880
881 /* Resetting the Rx and Tx paths of MCI */
882 regval = REG_READ(ah, AR_MCI_COMMAND2);
883 regval |= SM(1, AR_MCI_COMMAND2_RESET_TX);
884 REG_WRITE(ah, AR_MCI_COMMAND2, regval);
885
886 udelay(1);
887
888 regval &= ~SM(1, AR_MCI_COMMAND2_RESET_TX);
889 REG_WRITE(ah, AR_MCI_COMMAND2, regval);
890
891 if (is_full_sleep) {
892 ar9003_mci_mute_bt(ah);
893 udelay(100);
894 }
895
896 regval |= SM(1, AR_MCI_COMMAND2_RESET_RX);
897 REG_WRITE(ah, AR_MCI_COMMAND2, regval);
898 udelay(1);
899 regval &= ~SM(1, AR_MCI_COMMAND2_RESET_RX);
900 REG_WRITE(ah, AR_MCI_COMMAND2, regval);
901
902 ar9003_mci_state(ah, MCI_STATE_INIT_GPM_OFFSET, NULL);
Sujith Manoharan4f851df2012-02-22 12:42:10 +0530903
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530904 REG_WRITE(ah, AR_MCI_MSG_ATTRIBUTES_TABLE,
905 (SM(0xe801, AR_MCI_MSG_ATTRIBUTES_TABLE_INVALID_HDR) |
906 SM(0x0000, AR_MCI_MSG_ATTRIBUTES_TABLE_CHECKSUM)));
907
908 REG_CLR_BIT(ah, AR_MCI_TX_CTRL,
Sujith Manoharan4f851df2012-02-22 12:42:10 +0530909 AR_MCI_TX_CTRL_DISABLE_LNA_UPDATE);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530910
Sujith Manoharan4f851df2012-02-22 12:42:10 +0530911 ar9003_mci_observation_set_up(ah);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530912
913 mci->ready = true;
914 ar9003_mci_prep_interface(ah);
915
916 if (en_int)
917 ar9003_mci_enable_interrupt(ah);
918}
919
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530920void ar9003_mci_stop_bt(struct ath_hw *ah, bool save_fullsleep)
921{
922 struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
923
924 ar9003_mci_disable_interrupt(ah);
925
926 if (mci_hw->ready && !save_fullsleep) {
927 ar9003_mci_mute_bt(ah);
928 udelay(20);
929 REG_WRITE(ah, AR_BTCOEX_CTRL, 0);
930 }
931
932 mci_hw->bt_state = MCI_BT_SLEEP;
933 mci_hw->ready = false;
934}
935
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530936static void ar9003_mci_send_2g5g_status(struct ath_hw *ah, bool wait_done)
937{
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530938 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
939 u32 new_flags, to_set, to_clear;
940
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530941 if (!mci->update_2g5g || (mci->bt_state == MCI_BT_SLEEP))
942 return;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530943
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530944 if (mci->is_2g) {
945 new_flags = MCI_2G_FLAGS;
946 to_clear = MCI_2G_FLAGS_CLEAR_MASK;
947 to_set = MCI_2G_FLAGS_SET_MASK;
948 } else {
949 new_flags = MCI_5G_FLAGS;
950 to_clear = MCI_5G_FLAGS_CLEAR_MASK;
951 to_set = MCI_5G_FLAGS_SET_MASK;
952 }
953
954 if (to_clear)
955 ar9003_mci_send_coex_bt_flags(ah, wait_done,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530956 MCI_GPM_COEX_BT_FLAGS_CLEAR,
957 to_clear);
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530958 if (to_set)
959 ar9003_mci_send_coex_bt_flags(ah, wait_done,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530960 MCI_GPM_COEX_BT_FLAGS_SET,
961 to_set);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530962}
963
964static void ar9003_mci_queue_unsent_gpm(struct ath_hw *ah, u8 header,
965 u32 *payload, bool queue)
966{
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530967 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
968 u8 type, opcode;
969
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530970 /* check if the message is to be queued */
971 if (header != MCI_GPM)
972 return;
973
974 type = MCI_GPM_TYPE(payload);
975 opcode = MCI_GPM_OPCODE(payload);
976
977 if (type != MCI_GPM_COEX_AGENT)
978 return;
979
980 switch (opcode) {
981 case MCI_GPM_COEX_BT_UPDATE_FLAGS:
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530982 if (*(((u8 *)payload) + MCI_GPM_COEX_B_BT_FLAGS_OP) ==
Sujith Manoharanc91ec462012-02-22 12:40:03 +0530983 MCI_GPM_COEX_BT_FLAGS_READ)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530984 break;
985
986 mci->update_2g5g = queue;
987
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530988 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530989 case MCI_GPM_COEX_WLAN_CHANNELS:
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530990 mci->wlan_channels_update = queue;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530991 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530992 case MCI_GPM_COEX_HALT_BT_GPM:
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530993 if (*(((u8 *)payload) + MCI_GPM_COEX_B_HALT_STATE) ==
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530994 MCI_GPM_COEX_BT_GPM_UNHALT) {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530995 mci->unhalt_bt_gpm = queue;
996
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530997 if (!queue)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530998 mci->halted_bt_gpm = false;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530999 }
1000
1001 if (*(((u8 *)payload) + MCI_GPM_COEX_B_HALT_STATE) ==
1002 MCI_GPM_COEX_BT_GPM_HALT) {
1003
1004 mci->halted_bt_gpm = !queue;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301005 }
1006
1007 break;
1008 default:
1009 break;
1010 }
1011}
1012
1013void ar9003_mci_2g5g_switch(struct ath_hw *ah, bool wait_done)
1014{
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301015 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
1016
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +05301017 if (!mci->update_2g5g)
1018 return;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301019
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +05301020 if (mci->is_2g) {
1021 ar9003_mci_send_2g5g_status(ah, true);
1022 ar9003_mci_send_lna_transfer(ah, true);
1023 udelay(5);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301024
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +05301025 REG_CLR_BIT(ah, AR_MCI_TX_CTRL,
1026 AR_MCI_TX_CTRL_DISABLE_LNA_UPDATE);
1027 REG_CLR_BIT(ah, AR_PHY_GLB_CONTROL,
1028 AR_BTCOEX_CTRL_BT_OWN_SPDT_CTRL);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301029
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +05301030 if (!(mci->config & ATH_MCI_CONFIG_DISABLE_OSLA))
1031 REG_SET_BIT(ah, AR_BTCOEX_CTRL,
Sujith Manoharan0cc4cde2012-02-22 12:42:15 +05301032 AR_BTCOEX_CTRL_ONE_STEP_LOOK_AHEAD_EN);
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +05301033 } else {
1034 ar9003_mci_send_lna_take(ah, true);
1035 udelay(5);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301036
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +05301037 REG_SET_BIT(ah, AR_MCI_TX_CTRL,
1038 AR_MCI_TX_CTRL_DISABLE_LNA_UPDATE);
1039 REG_SET_BIT(ah, AR_PHY_GLB_CONTROL,
1040 AR_BTCOEX_CTRL_BT_OWN_SPDT_CTRL);
1041 REG_CLR_BIT(ah, AR_BTCOEX_CTRL,
1042 AR_BTCOEX_CTRL_ONE_STEP_LOOK_AHEAD_EN);
1043
1044 ar9003_mci_send_2g5g_status(ah, true);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301045 }
1046}
1047
1048bool ar9003_mci_send_message(struct ath_hw *ah, u8 header, u32 flag,
1049 u32 *payload, u8 len, bool wait_done,
1050 bool check_bt)
1051{
1052 struct ath_common *common = ath9k_hw_common(ah);
1053 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
1054 bool msg_sent = false;
1055 u32 regval;
1056 u32 saved_mci_int_en;
1057 int i;
1058
1059 saved_mci_int_en = REG_READ(ah, AR_MCI_INTERRUPT_EN);
1060 regval = REG_READ(ah, AR_BTCOEX_CTRL);
1061
1062 if ((regval == 0xdeadbeef) || !(regval & AR_BTCOEX_CTRL_MCI_MODE_EN)) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001063 ath_dbg(common, MCI,
1064 "MCI Not sending 0x%x. MCI is not enabled. full_sleep = %d\n",
Sujith Manoharan37cd9d72012-02-22 12:42:21 +05301065 header, (ah->power_mode == ATH9K_PM_FULL_SLEEP) ? 1 : 0);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301066 ar9003_mci_queue_unsent_gpm(ah, header, payload, true);
1067 return false;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301068 } else if (check_bt && (mci->bt_state == MCI_BT_SLEEP)) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001069 ath_dbg(common, MCI,
1070 "MCI Don't send message 0x%x. BT is in sleep state\n",
1071 header);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301072 ar9003_mci_queue_unsent_gpm(ah, header, payload, true);
1073 return false;
1074 }
1075
1076 if (wait_done)
1077 REG_WRITE(ah, AR_MCI_INTERRUPT_EN, 0);
1078
1079 /* Need to clear SW_MSG_DONE raw bit before wait */
1080
1081 REG_WRITE(ah, AR_MCI_INTERRUPT_RAW,
1082 (AR_MCI_INTERRUPT_SW_MSG_DONE |
1083 AR_MCI_INTERRUPT_MSG_FAIL_MASK));
1084
1085 if (payload) {
1086 for (i = 0; (i * 4) < len; i++)
1087 REG_WRITE(ah, (AR_MCI_TX_PAYLOAD0 + i * 4),
1088 *(payload + i));
1089 }
1090
1091 REG_WRITE(ah, AR_MCI_COMMAND0,
1092 (SM((flag & MCI_FLAG_DISABLE_TIMESTAMP),
1093 AR_MCI_COMMAND0_DISABLE_TIMESTAMP) |
1094 SM(len, AR_MCI_COMMAND0_LEN) |
1095 SM(header, AR_MCI_COMMAND0_HEADER)));
1096
1097 if (wait_done &&
1098 !(ar9003_mci_wait_for_interrupt(ah, AR_MCI_INTERRUPT_RAW,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +05301099 AR_MCI_INTERRUPT_SW_MSG_DONE, 500)))
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301100 ar9003_mci_queue_unsent_gpm(ah, header, payload, true);
1101 else {
1102 ar9003_mci_queue_unsent_gpm(ah, header, payload, false);
1103 msg_sent = true;
1104 }
1105
1106 if (wait_done)
1107 REG_WRITE(ah, AR_MCI_INTERRUPT_EN, saved_mci_int_en);
1108
1109 return msg_sent;
1110}
1111EXPORT_SYMBOL(ar9003_mci_send_message);
1112
Sujith Manoharanf2f408e2012-02-22 12:41:06 +05301113void ar9003_mci_init_cal_req(struct ath_hw *ah, bool *is_reusable)
1114{
1115 struct ath_common *common = ath9k_hw_common(ah);
1116 struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
1117 u32 pld[4] = {0, 0, 0, 0};
1118
1119 if ((mci_hw->bt_state != MCI_BT_AWAKE) ||
1120 (mci_hw->config & ATH_MCI_CONFIG_DISABLE_MCI_CAL))
1121 return;
1122
Sujith Manoharanf2f408e2012-02-22 12:41:06 +05301123 MCI_GPM_SET_CAL_TYPE(pld, MCI_GPM_WLAN_CAL_REQ);
1124 pld[MCI_GPM_WLAN_CAL_W_SEQUENCE] = mci_hw->wlan_cal_seq++;
1125
1126 ar9003_mci_send_message(ah, MCI_GPM, 0, pld, 16, true, false);
1127
Sujith Manoharanf2f408e2012-02-22 12:41:06 +05301128 if (ar9003_mci_wait_for_gpm(ah, MCI_GPM_BT_CAL_GRANT, 0, 50000)) {
Sujith Manoharan37cd9d72012-02-22 12:42:21 +05301129 ath_dbg(common, MCI, "MCI BT_CAL_GRANT received\n");
Sujith Manoharanf2f408e2012-02-22 12:41:06 +05301130 } else {
Sujith Manoharan2fd5d352012-06-04 16:27:47 +05301131 *is_reusable = false;
Sujith Manoharan37cd9d72012-02-22 12:42:21 +05301132 ath_dbg(common, MCI, "MCI BT_CAL_GRANT not received\n");
Sujith Manoharanf2f408e2012-02-22 12:41:06 +05301133 }
1134}
1135
1136void ar9003_mci_init_cal_done(struct ath_hw *ah)
1137{
Sujith Manoharanf2f408e2012-02-22 12:41:06 +05301138 struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
1139 u32 pld[4] = {0, 0, 0, 0};
1140
1141 if ((mci_hw->bt_state != MCI_BT_AWAKE) ||
1142 (mci_hw->config & ATH_MCI_CONFIG_DISABLE_MCI_CAL))
1143 return;
1144
Sujith Manoharanf2f408e2012-02-22 12:41:06 +05301145 MCI_GPM_SET_CAL_TYPE(pld, MCI_GPM_WLAN_CAL_DONE);
1146 pld[MCI_GPM_WLAN_CAL_W_SEQUENCE] = mci_hw->wlan_cal_done++;
1147 ar9003_mci_send_message(ah, MCI_GPM, 0, pld, 16, true, false);
1148}
1149
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301150void ar9003_mci_setup(struct ath_hw *ah, u32 gpm_addr, void *gpm_buf,
1151 u16 len, u32 sched_addr)
1152{
1153 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301154
1155 mci->gpm_addr = gpm_addr;
1156 mci->gpm_buf = gpm_buf;
1157 mci->gpm_len = len;
1158 mci->sched_addr = sched_addr;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301159
1160 ar9003_mci_reset(ah, true, true, true);
1161}
1162EXPORT_SYMBOL(ar9003_mci_setup);
1163
1164void ar9003_mci_cleanup(struct ath_hw *ah)
1165{
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301166 /* Turn off MCI and Jupiter mode. */
1167 REG_WRITE(ah, AR_BTCOEX_CTRL, 0x00);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301168 ar9003_mci_disable_interrupt(ah);
1169}
1170EXPORT_SYMBOL(ar9003_mci_cleanup);
1171
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301172u32 ar9003_mci_state(struct ath_hw *ah, u32 state_type, u32 *p_data)
1173{
1174 struct ath_common *common = ath9k_hw_common(ah);
1175 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
1176 u32 value = 0, more_gpm = 0, gpm_ptr;
1177 u8 query_type;
1178
1179 switch (state_type) {
1180 case MCI_STATE_ENABLE:
1181 if (mci->ready) {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301182 value = REG_READ(ah, AR_BTCOEX_CTRL);
1183
1184 if ((value == 0xdeadbeef) || (value == 0xffffffff))
1185 value = 0;
1186 }
1187 value &= AR_BTCOEX_CTRL_MCI_MODE_EN;
1188 break;
1189 case MCI_STATE_INIT_GPM_OFFSET:
1190 value = MS(REG_READ(ah, AR_MCI_GPM_1), AR_MCI_GPM_WRITE_PTR);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301191 mci->gpm_idx = value;
1192 break;
1193 case MCI_STATE_NEXT_GPM_OFFSET:
1194 case MCI_STATE_LAST_GPM_OFFSET:
1195 /*
1196 * This could be useful to avoid new GPM message interrupt which
1197 * may lead to spurious interrupt after power sleep, or multiple
1198 * entry of ath_mci_intr().
1199 * Adding empty GPM check by returning HAL_MCI_GPM_INVALID can
1200 * alleviate this effect, but clearing GPM RX interrupt bit is
1201 * safe, because whether this is called from hw or driver code
1202 * there must be an interrupt bit set/triggered initially
1203 */
1204 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
1205 AR_MCI_INTERRUPT_RX_MSG_GPM);
1206
1207 gpm_ptr = MS(REG_READ(ah, AR_MCI_GPM_1), AR_MCI_GPM_WRITE_PTR);
1208 value = gpm_ptr;
1209
1210 if (value == 0)
1211 value = mci->gpm_len - 1;
1212 else if (value >= mci->gpm_len) {
Sujith Manoharan37cd9d72012-02-22 12:42:21 +05301213 if (value != 0xFFFF)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301214 value = 0;
Sujith Manoharan37cd9d72012-02-22 12:42:21 +05301215 } else {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301216 value--;
Sujith Manoharan37cd9d72012-02-22 12:42:21 +05301217 }
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301218
1219 if (value == 0xFFFF) {
1220 value = MCI_GPM_INVALID;
1221 more_gpm = MCI_GPM_NOMORE;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301222 } else if (state_type == MCI_STATE_NEXT_GPM_OFFSET) {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301223 if (gpm_ptr == mci->gpm_idx) {
1224 value = MCI_GPM_INVALID;
1225 more_gpm = MCI_GPM_NOMORE;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301226 } else {
1227 for (;;) {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301228 u32 temp_index;
1229
1230 /* skip reserved GPM if any */
1231
1232 if (value != mci->gpm_idx)
1233 more_gpm = MCI_GPM_MORE;
1234 else
1235 more_gpm = MCI_GPM_NOMORE;
1236
1237 temp_index = mci->gpm_idx;
1238 mci->gpm_idx++;
1239
1240 if (mci->gpm_idx >=
1241 mci->gpm_len)
1242 mci->gpm_idx = 0;
1243
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301244 if (ar9003_mci_is_gpm_valid(ah,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +05301245 temp_index)) {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301246 value = temp_index;
1247 break;
1248 }
1249
1250 if (more_gpm == MCI_GPM_NOMORE) {
1251 value = MCI_GPM_INVALID;
1252 break;
1253 }
1254 }
1255 }
1256 if (p_data)
1257 *p_data = more_gpm;
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +05301258 }
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301259
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +05301260 if (value != MCI_GPM_INVALID)
1261 value <<= 4;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301262
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +05301263 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301264 case MCI_STATE_LAST_SCHD_MSG_OFFSET:
1265 value = MS(REG_READ(ah, AR_MCI_RX_STATUS),
1266 AR_MCI_RX_LAST_SCHD_MSG_INDEX);
1267 /* Make it in bytes */
1268 value <<= 4;
1269 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301270 case MCI_STATE_REMOTE_SLEEP:
1271 value = MS(REG_READ(ah, AR_MCI_RX_STATUS),
1272 AR_MCI_RX_REMOTE_SLEEP) ?
1273 MCI_BT_SLEEP : MCI_BT_AWAKE;
1274 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301275 case MCI_STATE_CONT_RSSI_POWER:
1276 value = MS(mci->cont_status, AR_MCI_CONT_RSSI_POWER);
Sujith Manoharan37cd9d72012-02-22 12:42:21 +05301277 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301278 case MCI_STATE_CONT_PRIORITY:
1279 value = MS(mci->cont_status, AR_MCI_CONT_RRIORITY);
1280 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301281 case MCI_STATE_CONT_TXRX:
1282 value = MS(mci->cont_status, AR_MCI_CONT_TXRX);
1283 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301284 case MCI_STATE_BT:
1285 value = mci->bt_state;
1286 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301287 case MCI_STATE_SET_BT_SLEEP:
1288 mci->bt_state = MCI_BT_SLEEP;
1289 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301290 case MCI_STATE_SET_BT_AWAKE:
1291 mci->bt_state = MCI_BT_AWAKE;
1292 ar9003_mci_send_coex_version_query(ah, true);
1293 ar9003_mci_send_coex_wlan_channels(ah, true);
1294
Sujith Manoharan37cd9d72012-02-22 12:42:21 +05301295 if (mci->unhalt_bt_gpm)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301296 ar9003_mci_send_coex_halt_bt_gpm(ah, false, true);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301297
1298 ar9003_mci_2g5g_switch(ah, true);
1299 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301300 case MCI_STATE_SET_BT_CAL_START:
1301 mci->bt_state = MCI_BT_CAL_START;
1302 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301303 case MCI_STATE_SET_BT_CAL:
1304 mci->bt_state = MCI_BT_CAL;
1305 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301306 case MCI_STATE_RESET_REQ_WAKE:
1307 ar9003_mci_reset_req_wakeup(ah);
1308 mci->update_2g5g = true;
1309
Sujith Manoharan0cc4cde2012-02-22 12:42:15 +05301310 if (mci->config & ATH_MCI_CONFIG_MCI_OBS_MASK) {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301311 /* Check if we still have control of the GPIOs */
1312 if ((REG_READ(ah, AR_GLB_GPIO_CONTROL) &
Sujith Manoharan37cd9d72012-02-22 12:42:21 +05301313 ATH_MCI_CONFIG_MCI_OBS_GPIO) !=
1314 ATH_MCI_CONFIG_MCI_OBS_GPIO) {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301315 ar9003_mci_observation_set_up(ah);
1316 }
1317 }
1318 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301319 case MCI_STATE_SEND_WLAN_COEX_VERSION:
1320 ar9003_mci_send_coex_version_response(ah, true);
1321 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301322 case MCI_STATE_SET_BT_COEX_VERSION:
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301323 if (!p_data)
Joe Perchesd2182b62011-12-15 14:55:53 -08001324 ath_dbg(common, MCI,
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301325 "MCI Set BT Coex version with NULL data!!\n");
1326 else {
1327 mci->bt_ver_major = (*p_data >> 8) & 0xff;
1328 mci->bt_ver_minor = (*p_data) & 0xff;
1329 mci->bt_version_known = true;
Joe Perchesd2182b62011-12-15 14:55:53 -08001330 ath_dbg(common, MCI, "MCI BT version set: %d.%d\n",
1331 mci->bt_ver_major, mci->bt_ver_minor);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301332 }
1333 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301334 case MCI_STATE_SEND_WLAN_CHANNELS:
1335 if (p_data) {
1336 if (((mci->wlan_channels[1] & 0xffff0000) ==
1337 (*(p_data + 1) & 0xffff0000)) &&
1338 (mci->wlan_channels[2] == *(p_data + 2)) &&
1339 (mci->wlan_channels[3] == *(p_data + 3)))
1340 break;
1341
1342 mci->wlan_channels[0] = *p_data++;
1343 mci->wlan_channels[1] = *p_data++;
1344 mci->wlan_channels[2] = *p_data++;
1345 mci->wlan_channels[3] = *p_data++;
1346 }
1347 mci->wlan_channels_update = true;
1348 ar9003_mci_send_coex_wlan_channels(ah, true);
1349 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301350 case MCI_STATE_SEND_VERSION_QUERY:
1351 ar9003_mci_send_coex_version_query(ah, true);
1352 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301353 case MCI_STATE_SEND_STATUS_QUERY:
Sujith Manoharanc91ec462012-02-22 12:40:03 +05301354 query_type = MCI_GPM_COEX_QUERY_BT_TOPOLOGY;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301355 ar9003_mci_send_coex_bt_status_query(ah, true, query_type);
1356 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301357 case MCI_STATE_NEED_FLUSH_BT_INFO:
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +05301358 /*
1359 * btcoex_hw.mci.unhalt_bt_gpm means whether it's
1360 * needed to send UNHALT message. It's set whenever
1361 * there's a request to send HALT message.
1362 * mci_halted_bt_gpm means whether HALT message is sent
1363 * out successfully.
1364 *
1365 * Checking (mci_unhalt_bt_gpm == false) instead of
1366 * checking (ah->mci_halted_bt_gpm == false) will make
1367 * sure currently is in UNHALT-ed mode and BT can
1368 * respond to status query.
1369 */
1370 value = (!mci->unhalt_bt_gpm && mci->need_flush_btinfo) ? 1 : 0;
1371 if (p_data)
1372 mci->need_flush_btinfo = (*p_data != 0) ? true : false;
1373 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301374 case MCI_STATE_RECOVER_RX:
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301375 ar9003_mci_prep_interface(ah);
1376 mci->query_bt = true;
1377 mci->need_flush_btinfo = true;
1378 ar9003_mci_send_coex_wlan_channels(ah, true);
1379 ar9003_mci_2g5g_switch(ah, true);
1380 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301381 case MCI_STATE_NEED_FTP_STOMP:
1382 value = !(mci->config & ATH_MCI_CONFIG_DISABLE_FTP_STOMP);
1383 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301384 case MCI_STATE_NEED_TUNING:
1385 value = !(mci->config & ATH_MCI_CONFIG_DISABLE_TUNING);
1386 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301387 default:
1388 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301389 }
1390
1391 return value;
1392}
1393EXPORT_SYMBOL(ar9003_mci_state);
Rajkumar Manoharan99922a42012-06-04 16:28:31 +05301394
1395void ar9003_mci_bt_gain_ctrl(struct ath_hw *ah)
1396{
1397 struct ath_common *common = ath9k_hw_common(ah);
1398 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
1399
1400 ath_dbg(common, MCI, "Give LNA and SPDT control to BT\n");
1401
1402 REG_SET_BIT(ah, AR_PHY_GLB_CONTROL, AR_BTCOEX_CTRL_BT_OWN_SPDT_CTRL);
1403 mci->is_2g = false;
1404 mci->update_2g5g = true;
1405 ar9003_mci_send_2g5g_status(ah, true);
1406
1407 /* Force another 2g5g update at next scanning */
1408 mci->update_2g5g = true;
1409}