blob: b501bf14343724e81866fb1802e528c59a73cc4d [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) {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +053038 if (REG_READ(ah, address) & bit_position) {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +053039 REG_WRITE(ah, address, bit_position);
40
41 if (address == AR_MCI_INTERRUPT_RX_MSG_RAW) {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +053042 if (bit_position &
43 AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE)
44 ar9003_mci_reset_req_wakeup(ah);
45
46 if (bit_position &
47 (AR_MCI_INTERRUPT_RX_MSG_SYS_SLEEPING |
48 AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING))
49 REG_WRITE(ah, AR_MCI_INTERRUPT_RAW,
50 AR_MCI_INTERRUPT_REMOTE_SLEEP_UPDATE);
51
52 REG_WRITE(ah, AR_MCI_INTERRUPT_RAW,
53 AR_MCI_INTERRUPT_RX_MSG);
54 }
55 break;
56 }
57
58 udelay(10);
59 time_out -= 10;
60
61 if (time_out < 0)
62 break;
63 }
64
65 if (time_out <= 0) {
Joe Perchesd2182b62011-12-15 14:55:53 -080066 ath_dbg(common, MCI,
67 "MCI Wait for Reg 0x%08x = 0x%08x timeout\n",
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +053068 address, bit_position);
Joe Perchesd2182b62011-12-15 14:55:53 -080069 ath_dbg(common, MCI,
70 "MCI INT_RAW = 0x%08x, RX_MSG_RAW = 0x%08x\n",
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +053071 REG_READ(ah, AR_MCI_INTERRUPT_RAW),
72 REG_READ(ah, AR_MCI_INTERRUPT_RX_MSG_RAW));
73 time_out = 0;
74 }
75
76 return time_out;
77}
78
Sujith Manoharana3f846f2012-02-22 12:41:24 +053079static void ar9003_mci_remote_reset(struct ath_hw *ah, bool wait_done)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +053080{
81 u32 payload[4] = { 0xffffffff, 0xffffffff, 0xffffffff, 0xffffff00};
82
83 ar9003_mci_send_message(ah, MCI_REMOTE_RESET, 0, payload, 16,
84 wait_done, false);
85 udelay(5);
86}
87
Sujith Manoharana3f846f2012-02-22 12:41:24 +053088static void ar9003_mci_send_lna_transfer(struct ath_hw *ah, bool wait_done)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +053089{
90 u32 payload = 0x00000000;
91
92 ar9003_mci_send_message(ah, MCI_LNA_TRANS, 0, &payload, 1,
93 wait_done, false);
94}
95
96static void ar9003_mci_send_req_wake(struct ath_hw *ah, bool wait_done)
97{
98 ar9003_mci_send_message(ah, MCI_REQ_WAKE, MCI_FLAG_DISABLE_TIMESTAMP,
99 NULL, 0, wait_done, false);
100 udelay(5);
101}
102
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530103static void ar9003_mci_send_sys_waking(struct ath_hw *ah, bool wait_done)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530104{
105 ar9003_mci_send_message(ah, MCI_SYS_WAKING, MCI_FLAG_DISABLE_TIMESTAMP,
106 NULL, 0, wait_done, false);
107}
108
109static void ar9003_mci_send_lna_take(struct ath_hw *ah, bool wait_done)
110{
111 u32 payload = 0x70000000;
112
113 ar9003_mci_send_message(ah, MCI_LNA_TAKE, 0, &payload, 1,
114 wait_done, false);
115}
116
117static void ar9003_mci_send_sys_sleeping(struct ath_hw *ah, bool wait_done)
118{
119 ar9003_mci_send_message(ah, MCI_SYS_SLEEPING,
120 MCI_FLAG_DISABLE_TIMESTAMP,
121 NULL, 0, wait_done, false);
122}
123
124static void ar9003_mci_send_coex_version_query(struct ath_hw *ah,
125 bool wait_done)
126{
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530127 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
128 u32 payload[4] = {0, 0, 0, 0};
129
130 if (!mci->bt_version_known &&
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530131 (mci->bt_state != MCI_BT_SLEEP)) {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530132 MCI_GPM_SET_TYPE_OPCODE(payload,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530133 MCI_GPM_COEX_AGENT,
134 MCI_GPM_COEX_VERSION_QUERY);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530135 ar9003_mci_send_message(ah, MCI_GPM, 0, payload, 16,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530136 wait_done, true);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530137 }
138}
139
140static void ar9003_mci_send_coex_version_response(struct ath_hw *ah,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530141 bool wait_done)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530142{
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530143 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
144 u32 payload[4] = {0, 0, 0, 0};
145
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530146 MCI_GPM_SET_TYPE_OPCODE(payload, MCI_GPM_COEX_AGENT,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530147 MCI_GPM_COEX_VERSION_RESPONSE);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530148 *(((u8 *)payload) + MCI_GPM_COEX_B_MAJOR_VERSION) =
149 mci->wlan_ver_major;
150 *(((u8 *)payload) + MCI_GPM_COEX_B_MINOR_VERSION) =
151 mci->wlan_ver_minor;
152 ar9003_mci_send_message(ah, MCI_GPM, 0, payload, 16, wait_done, true);
153}
154
155static void ar9003_mci_send_coex_wlan_channels(struct ath_hw *ah,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530156 bool wait_done)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530157{
158 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
159 u32 *payload = &mci->wlan_channels[0];
160
161 if ((mci->wlan_channels_update == true) &&
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530162 (mci->bt_state != MCI_BT_SLEEP)) {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530163 MCI_GPM_SET_TYPE_OPCODE(payload,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530164 MCI_GPM_COEX_AGENT,
165 MCI_GPM_COEX_WLAN_CHANNELS);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530166 ar9003_mci_send_message(ah, MCI_GPM, 0, payload, 16,
167 wait_done, true);
168 MCI_GPM_SET_TYPE_OPCODE(payload, 0xff, 0xff);
169 }
170}
171
172static void ar9003_mci_send_coex_bt_status_query(struct ath_hw *ah,
173 bool wait_done, u8 query_type)
174{
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530175 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
176 u32 payload[4] = {0, 0, 0, 0};
177 bool query_btinfo = !!(query_type & (MCI_GPM_COEX_QUERY_BT_ALL_INFO |
178 MCI_GPM_COEX_QUERY_BT_TOPOLOGY));
179
180 if (mci->bt_state != MCI_BT_SLEEP) {
181
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530182 MCI_GPM_SET_TYPE_OPCODE(payload, MCI_GPM_COEX_AGENT,
183 MCI_GPM_COEX_STATUS_QUERY);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530184
185 *(((u8 *)payload) + MCI_GPM_COEX_B_BT_BITMAP) = query_type;
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530186
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530187 /*
188 * If bt_status_query message is not sent successfully,
189 * then need_flush_btinfo should be set again.
190 */
191 if (!ar9003_mci_send_message(ah, MCI_GPM, 0, payload, 16,
192 wait_done, true)) {
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530193 if (query_btinfo)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530194 mci->need_flush_btinfo = true;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530195 }
196
197 if (query_btinfo)
198 mci->query_bt = false;
199 }
200}
201
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530202static void ar9003_mci_send_coex_halt_bt_gpm(struct ath_hw *ah, bool halt,
203 bool wait_done)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530204{
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530205 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
206 u32 payload[4] = {0, 0, 0, 0};
207
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530208 MCI_GPM_SET_TYPE_OPCODE(payload, MCI_GPM_COEX_AGENT,
209 MCI_GPM_COEX_HALT_BT_GPM);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530210
211 if (halt) {
212 mci->query_bt = true;
213 /* Send next unhalt no matter halt sent or not */
214 mci->unhalt_bt_gpm = true;
215 mci->need_flush_btinfo = true;
216 *(((u8 *)payload) + MCI_GPM_COEX_B_HALT_STATE) =
217 MCI_GPM_COEX_BT_GPM_HALT;
218 } else
219 *(((u8 *)payload) + MCI_GPM_COEX_B_HALT_STATE) =
220 MCI_GPM_COEX_BT_GPM_UNHALT;
221
222 ar9003_mci_send_message(ah, MCI_GPM, 0, payload, 16, wait_done, true);
223}
224
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530225static void ar9003_mci_prep_interface(struct ath_hw *ah)
226{
227 struct ath_common *common = ath9k_hw_common(ah);
228 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
229 u32 saved_mci_int_en;
230 u32 mci_timeout = 150;
231
232 mci->bt_state = MCI_BT_SLEEP;
233 saved_mci_int_en = REG_READ(ah, AR_MCI_INTERRUPT_EN);
234
235 REG_WRITE(ah, AR_MCI_INTERRUPT_EN, 0);
236 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
237 REG_READ(ah, AR_MCI_INTERRUPT_RX_MSG_RAW));
238 REG_WRITE(ah, AR_MCI_INTERRUPT_RAW,
239 REG_READ(ah, AR_MCI_INTERRUPT_RAW));
240
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530241 ar9003_mci_remote_reset(ah, true);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530242 ar9003_mci_send_req_wake(ah, true);
243
244 if (ar9003_mci_wait_for_interrupt(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530245 AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING, 500)) {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530246
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530247 mci->bt_state = MCI_BT_AWAKE;
248
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530249 /*
250 * we don't need to send more remote_reset at this moment.
251 * If BT receive first remote_reset, then BT HW will
252 * be cleaned up and will be able to receive req_wake
253 * and BT HW will respond sys_waking.
254 * In this case, WLAN will receive BT's HW sys_waking.
255 * Otherwise, if BT SW missed initial remote_reset,
256 * that remote_reset will still clean up BT MCI RX,
257 * and the req_wake will wake BT up,
258 * and BT SW will respond this req_wake with a remote_reset and
259 * sys_waking. In this case, WLAN will receive BT's SW
260 * sys_waking. In either case, BT's RX is cleaned up. So we
261 * don't need to reply BT's remote_reset now, if any.
262 * Similarly, if in any case, WLAN can receive BT's sys_waking,
263 * that means WLAN's RX is also fine.
264 */
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530265 ar9003_mci_send_sys_waking(ah, true);
266 udelay(10);
267
268 /*
269 * Set BT priority interrupt value to be 0xff to
270 * avoid having too many BT PRIORITY interrupts.
271 */
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530272 REG_WRITE(ah, AR_MCI_BT_PRI0, 0xFFFFFFFF);
273 REG_WRITE(ah, AR_MCI_BT_PRI1, 0xFFFFFFFF);
274 REG_WRITE(ah, AR_MCI_BT_PRI2, 0xFFFFFFFF);
275 REG_WRITE(ah, AR_MCI_BT_PRI3, 0xFFFFFFFF);
276 REG_WRITE(ah, AR_MCI_BT_PRI, 0X000000FF);
277
278 /*
279 * A contention reset will be received after send out
280 * sys_waking. Also BT priority interrupt bits will be set.
281 * Clear those bits before the next step.
282 */
283
284 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
285 AR_MCI_INTERRUPT_RX_MSG_CONT_RST);
286 REG_WRITE(ah, AR_MCI_INTERRUPT_RAW,
287 AR_MCI_INTERRUPT_BT_PRI);
288
Sujith Manoharanc91ec462012-02-22 12:40:03 +0530289 if (mci->is_2g) {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530290 ar9003_mci_send_lna_transfer(ah, true);
291 udelay(5);
292 }
293
Sujith Manoharanc91ec462012-02-22 12:40:03 +0530294 if ((mci->is_2g && !mci->update_2g5g)) {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530295 if (ar9003_mci_wait_for_interrupt(ah,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530296 AR_MCI_INTERRUPT_RX_MSG_RAW,
297 AR_MCI_INTERRUPT_RX_MSG_LNA_INFO,
298 mci_timeout))
Joe Perchesd2182b62011-12-15 14:55:53 -0800299 ath_dbg(common, MCI,
300 "MCI WLAN has control over the LNA & BT obeys it\n");
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530301 else
Joe Perchesd2182b62011-12-15 14:55:53 -0800302 ath_dbg(common, MCI,
303 "MCI BT didn't respond to LNA_TRANS\n");
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530304 }
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530305 }
306
307 /* Clear the extra redundant SYS_WAKING from BT */
308 if ((mci->bt_state == MCI_BT_AWAKE) &&
309 (REG_READ_FIELD(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
310 AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING)) &&
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530311 (REG_READ_FIELD(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
312 AR_MCI_INTERRUPT_RX_MSG_SYS_SLEEPING) == 0)) {
313 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
314 AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING);
315 REG_WRITE(ah, AR_MCI_INTERRUPT_RAW,
316 AR_MCI_INTERRUPT_REMOTE_SLEEP_UPDATE);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530317 }
318
319 REG_WRITE(ah, AR_MCI_INTERRUPT_EN, saved_mci_int_en);
320}
321
Sujith Manoharand1ca8b82012-02-22 12:41:01 +0530322void ar9003_mci_set_full_sleep(struct ath_hw *ah)
323{
Sujith Manoharand1ca8b82012-02-22 12:41:01 +0530324 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
325
326 if (ar9003_mci_state(ah, MCI_STATE_ENABLE, NULL) &&
327 (mci->bt_state != MCI_BT_SLEEP) &&
328 !mci->halted_bt_gpm) {
Sujith Manoharand1ca8b82012-02-22 12:41:01 +0530329 ar9003_mci_send_coex_halt_bt_gpm(ah, true, true);
330 }
331
332 mci->ready = false;
Sujith Manoharand1ca8b82012-02-22 12:41:01 +0530333}
334
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530335static void ar9003_mci_disable_interrupt(struct ath_hw *ah)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530336{
337 REG_WRITE(ah, AR_MCI_INTERRUPT_EN, 0);
338 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_EN, 0);
339}
340
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530341static void ar9003_mci_enable_interrupt(struct ath_hw *ah)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530342{
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530343 REG_WRITE(ah, AR_MCI_INTERRUPT_EN, AR_MCI_INTERRUPT_DEFAULT);
344 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_EN,
345 AR_MCI_INTERRUPT_RX_MSG_DEFAULT);
346}
347
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530348static bool ar9003_mci_check_int(struct ath_hw *ah, u32 ints)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530349{
350 u32 intr;
351
352 intr = REG_READ(ah, AR_MCI_INTERRUPT_RX_MSG_RAW);
353 return ((intr & ints) == ints);
354}
355
356void ar9003_mci_get_interrupt(struct ath_hw *ah, u32 *raw_intr,
357 u32 *rx_msg_intr)
358{
359 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
Felix Fietkau8a309302011-12-17 16:47:56 +0100360
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530361 *raw_intr = mci->raw_intr;
362 *rx_msg_intr = mci->rx_msg_intr;
363
364 /* Clean int bits after the values are read. */
365 mci->raw_intr = 0;
366 mci->rx_msg_intr = 0;
367}
368EXPORT_SYMBOL(ar9003_mci_get_interrupt);
369
Sujith Manoharan5a1e2732012-02-22 12:40:55 +0530370void ar9003_mci_get_isr(struct ath_hw *ah, enum ath9k_int *masked)
371{
372 struct ath_common *common = ath9k_hw_common(ah);
373 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
374 u32 raw_intr, rx_msg_intr;
375
376 rx_msg_intr = REG_READ(ah, AR_MCI_INTERRUPT_RX_MSG_RAW);
377 raw_intr = REG_READ(ah, AR_MCI_INTERRUPT_RAW);
378
379 if ((raw_intr == 0xdeadbeef) || (rx_msg_intr == 0xdeadbeef)) {
380 ath_dbg(common, MCI,
381 "MCI gets 0xdeadbeef during int processing\n");
382 } else {
383 mci->rx_msg_intr |= rx_msg_intr;
384 mci->raw_intr |= raw_intr;
385 *masked |= ATH9K_INT_MCI;
386
387 if (rx_msg_intr & AR_MCI_INTERRUPT_RX_MSG_CONT_INFO)
388 mci->cont_status = REG_READ(ah, AR_MCI_CONT_STATUS);
389
390 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_RAW, rx_msg_intr);
391 REG_WRITE(ah, AR_MCI_INTERRUPT_RAW, raw_intr);
392 }
393}
394
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530395static void ar9003_mci_2g5g_changed(struct ath_hw *ah, bool is_2g)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530396{
397 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
398
399 if (!mci->update_2g5g &&
400 (mci->is_2g != is_2g))
401 mci->update_2g5g = true;
402
403 mci->is_2g = is_2g;
404}
405
406static bool ar9003_mci_is_gpm_valid(struct ath_hw *ah, u32 msg_index)
407{
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530408 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
409 u32 *payload;
410 u32 recv_type, offset;
411
412 if (msg_index == MCI_GPM_INVALID)
413 return false;
414
415 offset = msg_index << 4;
416
417 payload = (u32 *)(mci->gpm_buf + offset);
418 recv_type = MCI_GPM_TYPE(payload);
419
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530420 if (recv_type == MCI_GPM_RSVD_PATTERN)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530421 return false;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530422
423 return true;
424}
425
426static void ar9003_mci_observation_set_up(struct ath_hw *ah)
427{
428 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530429
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530430 if (mci->config & ATH_MCI_CONFIG_MCI_OBS_MCI) {
431 ath9k_hw_cfg_output(ah, 3, AR_GPIO_OUTPUT_MUX_AS_MCI_WLAN_DATA);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530432 ath9k_hw_cfg_output(ah, 2, AR_GPIO_OUTPUT_MUX_AS_MCI_WLAN_CLK);
433 ath9k_hw_cfg_output(ah, 1, AR_GPIO_OUTPUT_MUX_AS_MCI_BT_DATA);
434 ath9k_hw_cfg_output(ah, 0, AR_GPIO_OUTPUT_MUX_AS_MCI_BT_CLK);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530435 } else if (mci->config & ATH_MCI_CONFIG_MCI_OBS_TXRX) {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530436 ath9k_hw_cfg_output(ah, 3, AR_GPIO_OUTPUT_MUX_AS_WL_IN_TX);
437 ath9k_hw_cfg_output(ah, 2, AR_GPIO_OUTPUT_MUX_AS_WL_IN_RX);
438 ath9k_hw_cfg_output(ah, 1, AR_GPIO_OUTPUT_MUX_AS_BT_IN_TX);
439 ath9k_hw_cfg_output(ah, 0, AR_GPIO_OUTPUT_MUX_AS_BT_IN_RX);
440 ath9k_hw_cfg_output(ah, 5, AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530441 } else if (mci->config & ATH_MCI_CONFIG_MCI_OBS_BT) {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530442 ath9k_hw_cfg_output(ah, 3, AR_GPIO_OUTPUT_MUX_AS_BT_IN_TX);
443 ath9k_hw_cfg_output(ah, 2, AR_GPIO_OUTPUT_MUX_AS_BT_IN_RX);
444 ath9k_hw_cfg_output(ah, 1, AR_GPIO_OUTPUT_MUX_AS_MCI_BT_DATA);
445 ath9k_hw_cfg_output(ah, 0, AR_GPIO_OUTPUT_MUX_AS_MCI_BT_CLK);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530446 } else
447 return;
448
449 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
450
Sujith Manoharan0cc4cde2012-02-22 12:42:15 +0530451 REG_RMW_FIELD(ah, AR_PHY_GLB_CONTROL, AR_GLB_DS_JTAG_DISABLE, 1);
452 REG_RMW_FIELD(ah, AR_PHY_GLB_CONTROL, AR_GLB_WLAN_UART_INTF_EN, 0);
453 REG_SET_BIT(ah, AR_GLB_GPIO_CONTROL, ATH_MCI_CONFIG_MCI_OBS_GPIO);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530454
455 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL2, AR_BTCOEX_CTRL2_GPIO_OBS_SEL, 0);
456 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL2, AR_BTCOEX_CTRL2_MAC_BB_OBS_SEL, 1);
457 REG_WRITE(ah, AR_OBS, 0x4b);
458 REG_RMW_FIELD(ah, AR_DIAG_SW, AR_DIAG_OBS_PT_SEL1, 0x03);
459 REG_RMW_FIELD(ah, AR_DIAG_SW, AR_DIAG_OBS_PT_SEL2, 0x01);
460 REG_RMW_FIELD(ah, AR_MACMISC, AR_MACMISC_MISC_OBS_BUS_LSB, 0x02);
461 REG_RMW_FIELD(ah, AR_MACMISC, AR_MACMISC_MISC_OBS_BUS_MSB, 0x03);
462 REG_RMW_FIELD(ah, AR_PHY_TEST_CTL_STATUS,
463 AR_PHY_TEST_CTL_DEBUGPORT_SEL, 0x07);
464}
465
466static bool ar9003_mci_send_coex_bt_flags(struct ath_hw *ah, bool wait_done,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530467 u8 opcode, u32 bt_flags)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530468{
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530469 u32 pld[4] = {0, 0, 0, 0};
470
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530471 MCI_GPM_SET_TYPE_OPCODE(pld, MCI_GPM_COEX_AGENT,
472 MCI_GPM_COEX_BT_UPDATE_FLAGS);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530473
474 *(((u8 *)pld) + MCI_GPM_COEX_B_BT_FLAGS_OP) = opcode;
475 *(((u8 *)pld) + MCI_GPM_COEX_W_BT_FLAGS + 0) = bt_flags & 0xFF;
476 *(((u8 *)pld) + MCI_GPM_COEX_W_BT_FLAGS + 1) = (bt_flags >> 8) & 0xFF;
477 *(((u8 *)pld) + MCI_GPM_COEX_W_BT_FLAGS + 2) = (bt_flags >> 16) & 0xFF;
478 *(((u8 *)pld) + MCI_GPM_COEX_W_BT_FLAGS + 3) = (bt_flags >> 24) & 0xFF;
479
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530480 return ar9003_mci_send_message(ah, MCI_GPM, 0, pld, 16,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530481 wait_done, true);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530482}
483
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530484static void ar9003_mci_sync_bt_state(struct ath_hw *ah)
485{
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530486 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
487 u32 cur_bt_state;
488
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530489 cur_bt_state = ar9003_mci_state(ah, MCI_STATE_REMOTE_SLEEP, NULL);
490
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530491 if (mci->bt_state != cur_bt_state)
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530492 mci->bt_state = cur_bt_state;
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530493
494 if (mci->bt_state != MCI_BT_SLEEP) {
495
496 ar9003_mci_send_coex_version_query(ah, true);
497 ar9003_mci_send_coex_wlan_channels(ah, true);
498
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530499 if (mci->unhalt_bt_gpm == true)
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530500 ar9003_mci_send_coex_halt_bt_gpm(ah, false, true);
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530501 }
502}
503
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530504void ar9003_mci_check_bt(struct ath_hw *ah)
505{
506 struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
507
508 if (!mci_hw->ready)
509 return;
510
511 /*
512 * check BT state again to make
513 * sure it's not changed.
514 */
515 ar9003_mci_sync_bt_state(ah);
516 ar9003_mci_2g5g_switch(ah, true);
517
518 if ((mci_hw->bt_state == MCI_BT_AWAKE) &&
519 (mci_hw->query_bt == true)) {
520 mci_hw->need_flush_btinfo = true;
521 }
522}
523
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530524static void ar9003_mci_process_gpm_extra(struct ath_hw *ah, u8 gpm_type,
525 u8 gpm_opcode, u32 *p_gpm)
526{
527 struct ath_common *common = ath9k_hw_common(ah);
528 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
529 u8 *p_data = (u8 *) p_gpm;
530
531 if (gpm_type != MCI_GPM_COEX_AGENT)
532 return;
533
534 switch (gpm_opcode) {
535 case MCI_GPM_COEX_VERSION_QUERY:
536 ath_dbg(common, MCI, "MCI Recv GPM COEX Version Query\n");
537 ar9003_mci_send_coex_version_response(ah, true);
538 break;
539 case MCI_GPM_COEX_VERSION_RESPONSE:
540 ath_dbg(common, MCI, "MCI Recv GPM COEX Version Response\n");
541 mci->bt_ver_major =
542 *(p_data + MCI_GPM_COEX_B_MAJOR_VERSION);
543 mci->bt_ver_minor =
544 *(p_data + MCI_GPM_COEX_B_MINOR_VERSION);
545 mci->bt_version_known = true;
546 ath_dbg(common, MCI, "MCI BT Coex version: %d.%d\n",
547 mci->bt_ver_major, mci->bt_ver_minor);
548 break;
549 case MCI_GPM_COEX_STATUS_QUERY:
550 ath_dbg(common, MCI,
551 "MCI Recv GPM COEX Status Query = 0x%02X\n",
552 *(p_data + MCI_GPM_COEX_B_WLAN_BITMAP));
553 mci->wlan_channels_update = true;
554 ar9003_mci_send_coex_wlan_channels(ah, true);
555 break;
556 case MCI_GPM_COEX_BT_PROFILE_INFO:
557 mci->query_bt = true;
558 ath_dbg(common, MCI, "MCI Recv GPM COEX BT_Profile_Info\n");
559 break;
560 case MCI_GPM_COEX_BT_STATUS_UPDATE:
561 mci->query_bt = true;
562 ath_dbg(common, MCI,
563 "MCI Recv GPM COEX BT_Status_Update SEQ=%d (drop&query)\n",
564 *(p_gpm + 3));
565 break;
566 default:
567 break;
568 }
569}
570
571static u32 ar9003_mci_wait_for_gpm(struct ath_hw *ah, u8 gpm_type,
572 u8 gpm_opcode, int time_out)
573{
574 struct ath_common *common = ath9k_hw_common(ah);
575 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
576 u32 *p_gpm = NULL, mismatch = 0, more_data;
577 u32 offset;
578 u8 recv_type = 0, recv_opcode = 0;
579 bool b_is_bt_cal_done = (gpm_type == MCI_GPM_BT_CAL_DONE);
580
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530581 more_data = time_out ? MCI_GPM_NOMORE : MCI_GPM_MORE;
582
583 while (time_out > 0) {
584 if (p_gpm) {
585 MCI_GPM_RECYCLE(p_gpm);
586 p_gpm = NULL;
587 }
588
589 if (more_data != MCI_GPM_MORE)
590 time_out = ar9003_mci_wait_for_interrupt(ah,
591 AR_MCI_INTERRUPT_RX_MSG_RAW,
592 AR_MCI_INTERRUPT_RX_MSG_GPM,
593 time_out);
594
595 if (!time_out)
596 break;
597
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530598 offset = ar9003_mci_state(ah, MCI_STATE_NEXT_GPM_OFFSET,
599 &more_data);
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530600
601 if (offset == MCI_GPM_INVALID)
602 continue;
603
604 p_gpm = (u32 *) (mci->gpm_buf + offset);
605 recv_type = MCI_GPM_TYPE(p_gpm);
606 recv_opcode = MCI_GPM_OPCODE(p_gpm);
607
608 if (MCI_GPM_IS_CAL_TYPE(recv_type)) {
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530609 if (recv_type == gpm_type) {
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530610 if ((gpm_type == MCI_GPM_BT_CAL_DONE) &&
611 !b_is_bt_cal_done) {
612 gpm_type = MCI_GPM_BT_CAL_GRANT;
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530613 continue;
614 }
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530615 break;
616 }
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530617 } else if ((recv_type == gpm_type) && (recv_opcode == gpm_opcode)) {
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530618 break;
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530619 }
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530620
621 /*
622 * check if it's cal_grant
623 *
624 * When we're waiting for cal_grant in reset routine,
625 * it's possible that BT sends out cal_request at the
626 * same time. Since BT's calibration doesn't happen
627 * that often, we'll let BT completes calibration then
628 * we continue to wait for cal_grant from BT.
629 * Orginal: Wait BT_CAL_GRANT.
630 * New: Receive BT_CAL_REQ -> send WLAN_CAL_GRANT->wait
631 * BT_CAL_DONE -> Wait BT_CAL_GRANT.
632 */
633
634 if ((gpm_type == MCI_GPM_BT_CAL_GRANT) &&
635 (recv_type == MCI_GPM_BT_CAL_REQ)) {
636
637 u32 payload[4] = {0, 0, 0, 0};
638
639 gpm_type = MCI_GPM_BT_CAL_DONE;
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530640 MCI_GPM_SET_CAL_TYPE(payload,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530641 MCI_GPM_WLAN_CAL_GRANT);
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530642 ar9003_mci_send_message(ah, MCI_GPM, 0, payload, 16,
643 false, false);
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530644 continue;
645 } else {
646 ath_dbg(common, MCI, "MCI GPM subtype not match 0x%x\n",
647 *(p_gpm + 1));
648 mismatch++;
649 ar9003_mci_process_gpm_extra(ah, recv_type,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530650 recv_opcode, p_gpm);
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530651 }
652 }
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530653
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530654 if (p_gpm) {
655 MCI_GPM_RECYCLE(p_gpm);
656 p_gpm = NULL;
657 }
658
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530659 if (time_out <= 0)
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530660 time_out = 0;
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530661
662 while (more_data == MCI_GPM_MORE) {
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530663 offset = ar9003_mci_state(ah, MCI_STATE_NEXT_GPM_OFFSET,
664 &more_data);
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530665 if (offset == MCI_GPM_INVALID)
666 break;
667
668 p_gpm = (u32 *) (mci->gpm_buf + offset);
669 recv_type = MCI_GPM_TYPE(p_gpm);
670 recv_opcode = MCI_GPM_OPCODE(p_gpm);
671
672 if (!MCI_GPM_IS_CAL_TYPE(recv_type))
673 ar9003_mci_process_gpm_extra(ah, recv_type,
674 recv_opcode, p_gpm);
675
676 MCI_GPM_RECYCLE(p_gpm);
677 }
678
679 return time_out;
680}
681
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530682bool ar9003_mci_start_reset(struct ath_hw *ah, struct ath9k_channel *chan)
683{
684 struct ath_common *common = ath9k_hw_common(ah);
685 struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
686 u32 payload[4] = {0, 0, 0, 0};
687
688 ar9003_mci_2g5g_changed(ah, IS_CHAN_2GHZ(chan));
689
690 if (mci_hw->bt_state != MCI_BT_CAL_START)
691 return false;
692
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530693 mci_hw->bt_state = MCI_BT_CAL;
694
695 /*
696 * MCI FIX: disable mci interrupt here. This is to avoid
697 * SW_MSG_DONE or RX_MSG bits to trigger MCI_INT and
698 * lead to mci_intr reentry.
699 */
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530700 ar9003_mci_disable_interrupt(ah);
701
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530702 MCI_GPM_SET_CAL_TYPE(payload, MCI_GPM_WLAN_CAL_GRANT);
703 ar9003_mci_send_message(ah, MCI_GPM, 0, payload,
704 16, true, false);
705
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530706 /* Wait BT calibration to be completed for 25ms */
707
708 if (ar9003_mci_wait_for_gpm(ah, MCI_GPM_BT_CAL_DONE,
709 0, 25000))
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530710 ath_dbg(common, MCI, "MCI BT_CAL_DONE received\n");
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530711 else
712 ath_dbg(common, MCI,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530713 "MCI BT_CAL_DONE not received\n");
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530714
715 mci_hw->bt_state = MCI_BT_AWAKE;
716 /* MCI FIX: enable mci interrupt here */
717 ar9003_mci_enable_interrupt(ah);
718
719 return true;
720}
721
722int ar9003_mci_end_reset(struct ath_hw *ah, struct ath9k_channel *chan,
723 struct ath9k_hw_cal_data *caldata)
724{
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530725 struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
726
727 if (!mci_hw->ready)
728 return 0;
729
730 if (!IS_CHAN_2GHZ(chan) || (mci_hw->bt_state != MCI_BT_SLEEP))
731 goto exit;
732
733 if (ar9003_mci_check_int(ah, AR_MCI_INTERRUPT_RX_MSG_REMOTE_RESET) ||
734 ar9003_mci_check_int(ah, AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE)) {
735
736 /*
737 * BT is sleeping. Check if BT wakes up during
738 * WLAN calibration. If BT wakes up during
739 * WLAN calibration, need to go through all
740 * message exchanges again and recal.
741 */
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530742 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
743 AR_MCI_INTERRUPT_RX_MSG_REMOTE_RESET |
744 AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE);
745
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530746 ar9003_mci_remote_reset(ah, true);
747 ar9003_mci_send_sys_waking(ah, true);
748 udelay(1);
749
750 if (IS_CHAN_2GHZ(chan))
751 ar9003_mci_send_lna_transfer(ah, true);
752
753 mci_hw->bt_state = MCI_BT_AWAKE;
754
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530755 if (caldata) {
756 caldata->done_txiqcal_once = false;
757 caldata->done_txclcal_once = false;
Sujith Manoharan8a905552012-05-04 13:23:59 +0530758 caldata->rtt_done = false;
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530759 }
760
761 if (!ath9k_hw_init_cal(ah, chan))
762 return -EIO;
763
764 }
765exit:
766 ar9003_mci_enable_interrupt(ah);
767 return 0;
768}
769
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530770static void ar9003_mci_mute_bt(struct ath_hw *ah)
771{
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530772 /* disable all MCI messages */
773 REG_WRITE(ah, AR_MCI_MSG_ATTRIBUTES_TABLE, 0xffff0000);
774 REG_WRITE(ah, AR_BTCOEX_WL_WEIGHTS0, 0xffffffff);
775 REG_WRITE(ah, AR_BTCOEX_WL_WEIGHTS1, 0xffffffff);
776 REG_WRITE(ah, AR_BTCOEX_WL_WEIGHTS2, 0xffffffff);
777 REG_WRITE(ah, AR_BTCOEX_WL_WEIGHTS3, 0xffffffff);
778 REG_SET_BIT(ah, AR_MCI_TX_CTRL, AR_MCI_TX_CTRL_DISABLE_LNA_UPDATE);
779
780 /* wait pending HW messages to flush out */
781 udelay(10);
782
783 /*
784 * Send LNA_TAKE and SYS_SLEEPING when
785 * 1. reset not after resuming from full sleep
786 * 2. before reset MCI RX, to quiet BT and avoid MCI RX misalignment
787 */
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530788 ar9003_mci_send_lna_take(ah, true);
789
790 udelay(5);
791
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530792 ar9003_mci_send_sys_sleeping(ah, true);
793}
794
Sujith Manoharan4f851df2012-02-22 12:42:10 +0530795static void ar9003_mci_osla_setup(struct ath_hw *ah, bool enable)
796{
797 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
798 u32 thresh;
799
800 if (enable) {
801 REG_RMW_FIELD(ah, AR_MCI_SCHD_TABLE_2,
802 AR_MCI_SCHD_TABLE_2_HW_BASED, 1);
803 REG_RMW_FIELD(ah, AR_MCI_SCHD_TABLE_2,
804 AR_MCI_SCHD_TABLE_2_MEM_BASED, 1);
805
806 if (!(mci->config & ATH_MCI_CONFIG_DISABLE_AGGR_THRESH)) {
807 thresh = MS(mci->config, ATH_MCI_CONFIG_AGGR_THRESH);
808 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL,
809 AR_BTCOEX_CTRL_AGGR_THRESH, thresh);
810 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL,
811 AR_BTCOEX_CTRL_TIME_TO_NEXT_BT_THRESH_EN, 1);
812 } else {
813 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL,
814 AR_BTCOEX_CTRL_TIME_TO_NEXT_BT_THRESH_EN, 0);
815 }
816
817 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL,
818 AR_BTCOEX_CTRL_ONE_STEP_LOOK_AHEAD_EN, 1);
819 } else {
820 REG_CLR_BIT(ah, AR_BTCOEX_CTRL,
821 AR_BTCOEX_CTRL_ONE_STEP_LOOK_AHEAD_EN);
822 }
823}
824
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530825void ar9003_mci_reset(struct ath_hw *ah, bool en_int, bool is_2g,
826 bool is_full_sleep)
827{
828 struct ath_common *common = ath9k_hw_common(ah);
829 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
Sujith Manoharan4f851df2012-02-22 12:42:10 +0530830 u32 regval;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530831
Sujith Manoharan4f851df2012-02-22 12:42:10 +0530832 ath_dbg(common, MCI, "MCI Reset (full_sleep = %d, is_2g = %d)\n",
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530833 is_full_sleep, is_2g);
834
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530835 if (!mci->gpm_addr && !mci->sched_addr) {
Joe Perchesd2182b62011-12-15 14:55:53 -0800836 ath_dbg(common, MCI,
837 "MCI GPM and schedule buffers are not allocated\n");
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530838 return;
839 }
840
841 if (REG_READ(ah, AR_BTCOEX_CTRL) == 0xdeadbeef) {
Sujith Manoharan4f851df2012-02-22 12:42:10 +0530842 ath_dbg(common, MCI, "BTCOEX control register is dead\n");
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530843 return;
844 }
845
846 /* Program MCI DMA related registers */
847 REG_WRITE(ah, AR_MCI_GPM_0, mci->gpm_addr);
848 REG_WRITE(ah, AR_MCI_GPM_1, mci->gpm_len);
849 REG_WRITE(ah, AR_MCI_SCHD_TABLE_0, mci->sched_addr);
850
851 /*
852 * To avoid MCI state machine be affected by incoming remote MCI msgs,
853 * MCI mode will be enabled later, right before reset the MCI TX and RX.
854 */
855
856 regval = SM(1, AR_BTCOEX_CTRL_AR9462_MODE) |
857 SM(1, AR_BTCOEX_CTRL_WBTIMER_EN) |
858 SM(1, AR_BTCOEX_CTRL_PA_SHARED) |
859 SM(1, AR_BTCOEX_CTRL_LNA_SHARED) |
860 SM(2, AR_BTCOEX_CTRL_NUM_ANTENNAS) |
861 SM(3, AR_BTCOEX_CTRL_RX_CHAIN_MASK) |
862 SM(0, AR_BTCOEX_CTRL_1_CHAIN_ACK) |
863 SM(0, AR_BTCOEX_CTRL_1_CHAIN_BCN) |
864 SM(0, AR_BTCOEX_CTRL_ONE_STEP_LOOK_AHEAD_EN);
865
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530866 REG_WRITE(ah, AR_BTCOEX_CTRL, regval);
867
Sujith Manoharan4f851df2012-02-22 12:42:10 +0530868 if (is_2g && !(mci->config & ATH_MCI_CONFIG_DISABLE_OSLA))
869 ar9003_mci_osla_setup(ah, true);
870 else
871 ar9003_mci_osla_setup(ah, false);
872
873 REG_SET_BIT(ah, AR_PHY_GLB_CONTROL,
874 AR_BTCOEX_CTRL_SPDT_ENABLE);
875 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL3,
876 AR_BTCOEX_CTRL3_CONT_INFO_TIMEOUT, 20);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530877
878 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL2, AR_BTCOEX_CTRL2_RX_DEWEIGHT, 1);
879 REG_RMW_FIELD(ah, AR_PCU_MISC, AR_PCU_BT_ANT_PREVENT_RX, 0);
880
Sujith Manoharan4f851df2012-02-22 12:42:10 +0530881 regval = MS(mci->config, ATH_MCI_CONFIG_CLK_DIV);
882 REG_RMW_FIELD(ah, AR_MCI_TX_CTRL, AR_MCI_TX_CTRL_CLK_DIV, regval);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530883 REG_SET_BIT(ah, AR_BTCOEX_CTRL, AR_BTCOEX_CTRL_MCI_MODE_EN);
884
885 /* Resetting the Rx and Tx paths of MCI */
886 regval = REG_READ(ah, AR_MCI_COMMAND2);
887 regval |= SM(1, AR_MCI_COMMAND2_RESET_TX);
888 REG_WRITE(ah, AR_MCI_COMMAND2, regval);
889
890 udelay(1);
891
892 regval &= ~SM(1, AR_MCI_COMMAND2_RESET_TX);
893 REG_WRITE(ah, AR_MCI_COMMAND2, regval);
894
895 if (is_full_sleep) {
896 ar9003_mci_mute_bt(ah);
897 udelay(100);
898 }
899
900 regval |= SM(1, AR_MCI_COMMAND2_RESET_RX);
901 REG_WRITE(ah, AR_MCI_COMMAND2, regval);
902 udelay(1);
903 regval &= ~SM(1, AR_MCI_COMMAND2_RESET_RX);
904 REG_WRITE(ah, AR_MCI_COMMAND2, regval);
905
906 ar9003_mci_state(ah, MCI_STATE_INIT_GPM_OFFSET, NULL);
Sujith Manoharan4f851df2012-02-22 12:42:10 +0530907
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530908 REG_WRITE(ah, AR_MCI_MSG_ATTRIBUTES_TABLE,
909 (SM(0xe801, AR_MCI_MSG_ATTRIBUTES_TABLE_INVALID_HDR) |
910 SM(0x0000, AR_MCI_MSG_ATTRIBUTES_TABLE_CHECKSUM)));
911
912 REG_CLR_BIT(ah, AR_MCI_TX_CTRL,
Sujith Manoharan4f851df2012-02-22 12:42:10 +0530913 AR_MCI_TX_CTRL_DISABLE_LNA_UPDATE);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530914
Sujith Manoharan4f851df2012-02-22 12:42:10 +0530915 ar9003_mci_observation_set_up(ah);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530916
917 mci->ready = true;
918 ar9003_mci_prep_interface(ah);
919
920 if (en_int)
921 ar9003_mci_enable_interrupt(ah);
922}
923
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530924void ar9003_mci_stop_bt(struct ath_hw *ah, bool save_fullsleep)
925{
926 struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
927
928 ar9003_mci_disable_interrupt(ah);
929
930 if (mci_hw->ready && !save_fullsleep) {
931 ar9003_mci_mute_bt(ah);
932 udelay(20);
933 REG_WRITE(ah, AR_BTCOEX_CTRL, 0);
934 }
935
936 mci_hw->bt_state = MCI_BT_SLEEP;
937 mci_hw->ready = false;
938}
939
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530940static void ar9003_mci_send_2g5g_status(struct ath_hw *ah, bool wait_done)
941{
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530942 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
943 u32 new_flags, to_set, to_clear;
944
Sujith Manoharan0cc4cde2012-02-22 12:42:15 +0530945 if (mci->update_2g5g && (mci->bt_state != MCI_BT_SLEEP)) {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530946 if (mci->is_2g) {
947 new_flags = MCI_2G_FLAGS;
948 to_clear = MCI_2G_FLAGS_CLEAR_MASK;
949 to_set = MCI_2G_FLAGS_SET_MASK;
950 } else {
951 new_flags = MCI_5G_FLAGS;
952 to_clear = MCI_5G_FLAGS_CLEAR_MASK;
953 to_set = MCI_5G_FLAGS_SET_MASK;
954 }
955
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530956 if (to_clear)
957 ar9003_mci_send_coex_bt_flags(ah, wait_done,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530958 MCI_GPM_COEX_BT_FLAGS_CLEAR,
959 to_clear);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530960 if (to_set)
961 ar9003_mci_send_coex_bt_flags(ah, wait_done,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530962 MCI_GPM_COEX_BT_FLAGS_SET,
963 to_set);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530964 }
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530965}
966
967static void ar9003_mci_queue_unsent_gpm(struct ath_hw *ah, u8 header,
968 u32 *payload, bool queue)
969{
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530970 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
971 u8 type, opcode;
972
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530973 /* check if the message is to be queued */
974 if (header != MCI_GPM)
975 return;
976
977 type = MCI_GPM_TYPE(payload);
978 opcode = MCI_GPM_OPCODE(payload);
979
980 if (type != MCI_GPM_COEX_AGENT)
981 return;
982
983 switch (opcode) {
984 case MCI_GPM_COEX_BT_UPDATE_FLAGS:
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530985 if (*(((u8 *)payload) + MCI_GPM_COEX_B_BT_FLAGS_OP) ==
Sujith Manoharanc91ec462012-02-22 12:40:03 +0530986 MCI_GPM_COEX_BT_FLAGS_READ)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530987 break;
988
989 mci->update_2g5g = queue;
990
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530991 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530992 case MCI_GPM_COEX_WLAN_CHANNELS:
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530993 mci->wlan_channels_update = queue;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530994 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530995 case MCI_GPM_COEX_HALT_BT_GPM:
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530996 if (*(((u8 *)payload) + MCI_GPM_COEX_B_HALT_STATE) ==
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530997 MCI_GPM_COEX_BT_GPM_UNHALT) {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530998 mci->unhalt_bt_gpm = queue;
999
Sujith Manoharan37cd9d72012-02-22 12:42:21 +05301000 if (!queue)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301001 mci->halted_bt_gpm = false;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301002 }
1003
1004 if (*(((u8 *)payload) + MCI_GPM_COEX_B_HALT_STATE) ==
1005 MCI_GPM_COEX_BT_GPM_HALT) {
1006
1007 mci->halted_bt_gpm = !queue;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301008 }
1009
1010 break;
1011 default:
1012 break;
1013 }
1014}
1015
1016void ar9003_mci_2g5g_switch(struct ath_hw *ah, bool wait_done)
1017{
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301018 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
1019
1020 if (mci->update_2g5g) {
1021 if (mci->is_2g) {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301022 ar9003_mci_send_2g5g_status(ah, true);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301023 ar9003_mci_send_lna_transfer(ah, true);
1024 udelay(5);
1025
1026 REG_CLR_BIT(ah, AR_MCI_TX_CTRL,
1027 AR_MCI_TX_CTRL_DISABLE_LNA_UPDATE);
Sujith Manoharan37cd9d72012-02-22 12:42:21 +05301028 REG_CLR_BIT(ah, AR_PHY_GLB_CONTROL,
1029 AR_BTCOEX_CTRL_BT_OWN_SPDT_CTRL);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301030
Sujith Manoharan37cd9d72012-02-22 12:42:21 +05301031 if (!(mci->config & ATH_MCI_CONFIG_DISABLE_OSLA)) {
1032 REG_SET_BIT(ah, AR_BTCOEX_CTRL,
1033 AR_BTCOEX_CTRL_ONE_STEP_LOOK_AHEAD_EN);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301034 }
1035 } else {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301036 ar9003_mci_send_lna_take(ah, true);
1037 udelay(5);
1038
1039 REG_SET_BIT(ah, AR_MCI_TX_CTRL,
1040 AR_MCI_TX_CTRL_DISABLE_LNA_UPDATE);
Sujith Manoharan0cc4cde2012-02-22 12:42:15 +05301041 REG_SET_BIT(ah, AR_PHY_GLB_CONTROL,
1042 AR_BTCOEX_CTRL_BT_OWN_SPDT_CTRL);
1043 REG_CLR_BIT(ah, AR_BTCOEX_CTRL,
1044 AR_BTCOEX_CTRL_ONE_STEP_LOOK_AHEAD_EN);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301045
1046 ar9003_mci_send_2g5g_status(ah, true);
1047 }
1048 }
1049}
1050
1051bool ar9003_mci_send_message(struct ath_hw *ah, u8 header, u32 flag,
1052 u32 *payload, u8 len, bool wait_done,
1053 bool check_bt)
1054{
1055 struct ath_common *common = ath9k_hw_common(ah);
1056 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
1057 bool msg_sent = false;
1058 u32 regval;
1059 u32 saved_mci_int_en;
1060 int i;
1061
1062 saved_mci_int_en = REG_READ(ah, AR_MCI_INTERRUPT_EN);
1063 regval = REG_READ(ah, AR_BTCOEX_CTRL);
1064
1065 if ((regval == 0xdeadbeef) || !(regval & AR_BTCOEX_CTRL_MCI_MODE_EN)) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001066 ath_dbg(common, MCI,
1067 "MCI Not sending 0x%x. MCI is not enabled. full_sleep = %d\n",
Sujith Manoharan37cd9d72012-02-22 12:42:21 +05301068 header, (ah->power_mode == ATH9K_PM_FULL_SLEEP) ? 1 : 0);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301069 ar9003_mci_queue_unsent_gpm(ah, header, payload, true);
1070 return false;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301071 } else if (check_bt && (mci->bt_state == MCI_BT_SLEEP)) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001072 ath_dbg(common, MCI,
1073 "MCI Don't send message 0x%x. BT is in sleep state\n",
1074 header);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301075 ar9003_mci_queue_unsent_gpm(ah, header, payload, true);
1076 return false;
1077 }
1078
1079 if (wait_done)
1080 REG_WRITE(ah, AR_MCI_INTERRUPT_EN, 0);
1081
1082 /* Need to clear SW_MSG_DONE raw bit before wait */
1083
1084 REG_WRITE(ah, AR_MCI_INTERRUPT_RAW,
1085 (AR_MCI_INTERRUPT_SW_MSG_DONE |
1086 AR_MCI_INTERRUPT_MSG_FAIL_MASK));
1087
1088 if (payload) {
1089 for (i = 0; (i * 4) < len; i++)
1090 REG_WRITE(ah, (AR_MCI_TX_PAYLOAD0 + i * 4),
1091 *(payload + i));
1092 }
1093
1094 REG_WRITE(ah, AR_MCI_COMMAND0,
1095 (SM((flag & MCI_FLAG_DISABLE_TIMESTAMP),
1096 AR_MCI_COMMAND0_DISABLE_TIMESTAMP) |
1097 SM(len, AR_MCI_COMMAND0_LEN) |
1098 SM(header, AR_MCI_COMMAND0_HEADER)));
1099
1100 if (wait_done &&
1101 !(ar9003_mci_wait_for_interrupt(ah, AR_MCI_INTERRUPT_RAW,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +05301102 AR_MCI_INTERRUPT_SW_MSG_DONE, 500)))
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301103 ar9003_mci_queue_unsent_gpm(ah, header, payload, true);
1104 else {
1105 ar9003_mci_queue_unsent_gpm(ah, header, payload, false);
1106 msg_sent = true;
1107 }
1108
1109 if (wait_done)
1110 REG_WRITE(ah, AR_MCI_INTERRUPT_EN, saved_mci_int_en);
1111
1112 return msg_sent;
1113}
1114EXPORT_SYMBOL(ar9003_mci_send_message);
1115
Sujith Manoharanf2f408e2012-02-22 12:41:06 +05301116void ar9003_mci_init_cal_req(struct ath_hw *ah, bool *is_reusable)
1117{
1118 struct ath_common *common = ath9k_hw_common(ah);
1119 struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
1120 u32 pld[4] = {0, 0, 0, 0};
1121
1122 if ((mci_hw->bt_state != MCI_BT_AWAKE) ||
1123 (mci_hw->config & ATH_MCI_CONFIG_DISABLE_MCI_CAL))
1124 return;
1125
Sujith Manoharanf2f408e2012-02-22 12:41:06 +05301126 MCI_GPM_SET_CAL_TYPE(pld, MCI_GPM_WLAN_CAL_REQ);
1127 pld[MCI_GPM_WLAN_CAL_W_SEQUENCE] = mci_hw->wlan_cal_seq++;
1128
1129 ar9003_mci_send_message(ah, MCI_GPM, 0, pld, 16, true, false);
1130
Sujith Manoharanf2f408e2012-02-22 12:41:06 +05301131 if (ar9003_mci_wait_for_gpm(ah, MCI_GPM_BT_CAL_GRANT, 0, 50000)) {
Sujith Manoharan37cd9d72012-02-22 12:42:21 +05301132 ath_dbg(common, MCI, "MCI BT_CAL_GRANT received\n");
Sujith Manoharanf2f408e2012-02-22 12:41:06 +05301133 } else {
Sujith Manoharan2fd5d352012-06-04 16:27:47 +05301134 *is_reusable = false;
Sujith Manoharan37cd9d72012-02-22 12:42:21 +05301135 ath_dbg(common, MCI, "MCI BT_CAL_GRANT not received\n");
Sujith Manoharanf2f408e2012-02-22 12:41:06 +05301136 }
1137}
1138
1139void ar9003_mci_init_cal_done(struct ath_hw *ah)
1140{
Sujith Manoharanf2f408e2012-02-22 12:41:06 +05301141 struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
1142 u32 pld[4] = {0, 0, 0, 0};
1143
1144 if ((mci_hw->bt_state != MCI_BT_AWAKE) ||
1145 (mci_hw->config & ATH_MCI_CONFIG_DISABLE_MCI_CAL))
1146 return;
1147
Sujith Manoharanf2f408e2012-02-22 12:41:06 +05301148 MCI_GPM_SET_CAL_TYPE(pld, MCI_GPM_WLAN_CAL_DONE);
1149 pld[MCI_GPM_WLAN_CAL_W_SEQUENCE] = mci_hw->wlan_cal_done++;
1150 ar9003_mci_send_message(ah, MCI_GPM, 0, pld, 16, true, false);
1151}
1152
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301153void ar9003_mci_setup(struct ath_hw *ah, u32 gpm_addr, void *gpm_buf,
1154 u16 len, u32 sched_addr)
1155{
1156 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301157
1158 mci->gpm_addr = gpm_addr;
1159 mci->gpm_buf = gpm_buf;
1160 mci->gpm_len = len;
1161 mci->sched_addr = sched_addr;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301162
1163 ar9003_mci_reset(ah, true, true, true);
1164}
1165EXPORT_SYMBOL(ar9003_mci_setup);
1166
1167void ar9003_mci_cleanup(struct ath_hw *ah)
1168{
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301169 /* Turn off MCI and Jupiter mode. */
1170 REG_WRITE(ah, AR_BTCOEX_CTRL, 0x00);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301171 ar9003_mci_disable_interrupt(ah);
1172}
1173EXPORT_SYMBOL(ar9003_mci_cleanup);
1174
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301175u32 ar9003_mci_state(struct ath_hw *ah, u32 state_type, u32 *p_data)
1176{
1177 struct ath_common *common = ath9k_hw_common(ah);
1178 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
1179 u32 value = 0, more_gpm = 0, gpm_ptr;
1180 u8 query_type;
1181
1182 switch (state_type) {
1183 case MCI_STATE_ENABLE:
1184 if (mci->ready) {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301185 value = REG_READ(ah, AR_BTCOEX_CTRL);
1186
1187 if ((value == 0xdeadbeef) || (value == 0xffffffff))
1188 value = 0;
1189 }
1190 value &= AR_BTCOEX_CTRL_MCI_MODE_EN;
1191 break;
1192 case MCI_STATE_INIT_GPM_OFFSET:
1193 value = MS(REG_READ(ah, AR_MCI_GPM_1), AR_MCI_GPM_WRITE_PTR);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301194 mci->gpm_idx = value;
1195 break;
1196 case MCI_STATE_NEXT_GPM_OFFSET:
1197 case MCI_STATE_LAST_GPM_OFFSET:
1198 /*
1199 * This could be useful to avoid new GPM message interrupt which
1200 * may lead to spurious interrupt after power sleep, or multiple
1201 * entry of ath_mci_intr().
1202 * Adding empty GPM check by returning HAL_MCI_GPM_INVALID can
1203 * alleviate this effect, but clearing GPM RX interrupt bit is
1204 * safe, because whether this is called from hw or driver code
1205 * there must be an interrupt bit set/triggered initially
1206 */
1207 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
1208 AR_MCI_INTERRUPT_RX_MSG_GPM);
1209
1210 gpm_ptr = MS(REG_READ(ah, AR_MCI_GPM_1), AR_MCI_GPM_WRITE_PTR);
1211 value = gpm_ptr;
1212
1213 if (value == 0)
1214 value = mci->gpm_len - 1;
1215 else if (value >= mci->gpm_len) {
Sujith Manoharan37cd9d72012-02-22 12:42:21 +05301216 if (value != 0xFFFF)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301217 value = 0;
Sujith Manoharan37cd9d72012-02-22 12:42:21 +05301218 } else {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301219 value--;
Sujith Manoharan37cd9d72012-02-22 12:42:21 +05301220 }
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301221
1222 if (value == 0xFFFF) {
1223 value = MCI_GPM_INVALID;
1224 more_gpm = MCI_GPM_NOMORE;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301225 } else if (state_type == MCI_STATE_NEXT_GPM_OFFSET) {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301226 if (gpm_ptr == mci->gpm_idx) {
1227 value = MCI_GPM_INVALID;
1228 more_gpm = MCI_GPM_NOMORE;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301229 } else {
1230 for (;;) {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301231 u32 temp_index;
1232
1233 /* skip reserved GPM if any */
1234
1235 if (value != mci->gpm_idx)
1236 more_gpm = MCI_GPM_MORE;
1237 else
1238 more_gpm = MCI_GPM_NOMORE;
1239
1240 temp_index = mci->gpm_idx;
1241 mci->gpm_idx++;
1242
1243 if (mci->gpm_idx >=
1244 mci->gpm_len)
1245 mci->gpm_idx = 0;
1246
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301247 if (ar9003_mci_is_gpm_valid(ah,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +05301248 temp_index)) {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301249 value = temp_index;
1250 break;
1251 }
1252
1253 if (more_gpm == MCI_GPM_NOMORE) {
1254 value = MCI_GPM_INVALID;
1255 break;
1256 }
1257 }
1258 }
1259 if (p_data)
1260 *p_data = more_gpm;
1261 }
1262
1263 if (value != MCI_GPM_INVALID)
1264 value <<= 4;
1265
1266 break;
1267 case MCI_STATE_LAST_SCHD_MSG_OFFSET:
1268 value = MS(REG_READ(ah, AR_MCI_RX_STATUS),
1269 AR_MCI_RX_LAST_SCHD_MSG_INDEX);
1270 /* Make it in bytes */
1271 value <<= 4;
1272 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301273 case MCI_STATE_REMOTE_SLEEP:
1274 value = MS(REG_READ(ah, AR_MCI_RX_STATUS),
1275 AR_MCI_RX_REMOTE_SLEEP) ?
1276 MCI_BT_SLEEP : MCI_BT_AWAKE;
1277 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301278 case MCI_STATE_CONT_RSSI_POWER:
1279 value = MS(mci->cont_status, AR_MCI_CONT_RSSI_POWER);
Sujith Manoharan37cd9d72012-02-22 12:42:21 +05301280 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301281 case MCI_STATE_CONT_PRIORITY:
1282 value = MS(mci->cont_status, AR_MCI_CONT_RRIORITY);
1283 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301284 case MCI_STATE_CONT_TXRX:
1285 value = MS(mci->cont_status, AR_MCI_CONT_TXRX);
1286 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301287 case MCI_STATE_BT:
1288 value = mci->bt_state;
1289 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301290 case MCI_STATE_SET_BT_SLEEP:
1291 mci->bt_state = MCI_BT_SLEEP;
1292 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301293 case MCI_STATE_SET_BT_AWAKE:
1294 mci->bt_state = MCI_BT_AWAKE;
1295 ar9003_mci_send_coex_version_query(ah, true);
1296 ar9003_mci_send_coex_wlan_channels(ah, true);
1297
Sujith Manoharan37cd9d72012-02-22 12:42:21 +05301298 if (mci->unhalt_bt_gpm)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301299 ar9003_mci_send_coex_halt_bt_gpm(ah, false, true);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301300
1301 ar9003_mci_2g5g_switch(ah, true);
1302 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301303 case MCI_STATE_SET_BT_CAL_START:
1304 mci->bt_state = MCI_BT_CAL_START;
1305 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301306 case MCI_STATE_SET_BT_CAL:
1307 mci->bt_state = MCI_BT_CAL;
1308 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301309 case MCI_STATE_RESET_REQ_WAKE:
1310 ar9003_mci_reset_req_wakeup(ah);
1311 mci->update_2g5g = true;
1312
Sujith Manoharan0cc4cde2012-02-22 12:42:15 +05301313 if (mci->config & ATH_MCI_CONFIG_MCI_OBS_MASK) {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301314 /* Check if we still have control of the GPIOs */
1315 if ((REG_READ(ah, AR_GLB_GPIO_CONTROL) &
Sujith Manoharan37cd9d72012-02-22 12:42:21 +05301316 ATH_MCI_CONFIG_MCI_OBS_GPIO) !=
1317 ATH_MCI_CONFIG_MCI_OBS_GPIO) {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301318 ar9003_mci_observation_set_up(ah);
1319 }
1320 }
1321 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301322 case MCI_STATE_SEND_WLAN_COEX_VERSION:
1323 ar9003_mci_send_coex_version_response(ah, true);
1324 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301325 case MCI_STATE_SET_BT_COEX_VERSION:
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301326 if (!p_data)
Joe Perchesd2182b62011-12-15 14:55:53 -08001327 ath_dbg(common, MCI,
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301328 "MCI Set BT Coex version with NULL data!!\n");
1329 else {
1330 mci->bt_ver_major = (*p_data >> 8) & 0xff;
1331 mci->bt_ver_minor = (*p_data) & 0xff;
1332 mci->bt_version_known = true;
Joe Perchesd2182b62011-12-15 14:55:53 -08001333 ath_dbg(common, MCI, "MCI BT version set: %d.%d\n",
1334 mci->bt_ver_major, mci->bt_ver_minor);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301335 }
1336 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301337 case MCI_STATE_SEND_WLAN_CHANNELS:
1338 if (p_data) {
1339 if (((mci->wlan_channels[1] & 0xffff0000) ==
1340 (*(p_data + 1) & 0xffff0000)) &&
1341 (mci->wlan_channels[2] == *(p_data + 2)) &&
1342 (mci->wlan_channels[3] == *(p_data + 3)))
1343 break;
1344
1345 mci->wlan_channels[0] = *p_data++;
1346 mci->wlan_channels[1] = *p_data++;
1347 mci->wlan_channels[2] = *p_data++;
1348 mci->wlan_channels[3] = *p_data++;
1349 }
1350 mci->wlan_channels_update = true;
1351 ar9003_mci_send_coex_wlan_channels(ah, true);
1352 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301353 case MCI_STATE_SEND_VERSION_QUERY:
1354 ar9003_mci_send_coex_version_query(ah, true);
1355 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301356 case MCI_STATE_SEND_STATUS_QUERY:
Sujith Manoharanc91ec462012-02-22 12:40:03 +05301357 query_type = MCI_GPM_COEX_QUERY_BT_TOPOLOGY;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301358 ar9003_mci_send_coex_bt_status_query(ah, true, query_type);
1359 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301360 case MCI_STATE_NEED_FLUSH_BT_INFO:
1361 /*
1362 * btcoex_hw.mci.unhalt_bt_gpm means whether it's
1363 * needed to send UNHALT message. It's set whenever
1364 * there's a request to send HALT message.
1365 * mci_halted_bt_gpm means whether HALT message is sent
1366 * out successfully.
1367 *
1368 * Checking (mci_unhalt_bt_gpm == false) instead of
1369 * checking (ah->mci_halted_bt_gpm == false) will make
1370 * sure currently is in UNHALT-ed mode and BT can
1371 * respond to status query.
1372 */
1373 value = (!mci->unhalt_bt_gpm &&
1374 mci->need_flush_btinfo) ? 1 : 0;
1375 if (p_data)
1376 mci->need_flush_btinfo =
1377 (*p_data != 0) ? true : false;
1378 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301379 case MCI_STATE_RECOVER_RX:
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301380 ar9003_mci_prep_interface(ah);
1381 mci->query_bt = true;
1382 mci->need_flush_btinfo = true;
1383 ar9003_mci_send_coex_wlan_channels(ah, true);
1384 ar9003_mci_2g5g_switch(ah, true);
1385 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301386 case MCI_STATE_NEED_FTP_STOMP:
1387 value = !(mci->config & ATH_MCI_CONFIG_DISABLE_FTP_STOMP);
1388 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301389 case MCI_STATE_NEED_TUNING:
1390 value = !(mci->config & ATH_MCI_CONFIG_DISABLE_TUNING);
1391 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301392 default:
1393 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301394 }
1395
1396 return value;
1397}
1398EXPORT_SYMBOL(ar9003_mci_state);