blob: d6ed62807a979aaa62879823a3678cc626fc84b8 [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"
Sujith Manoharanb6ab9ae2015-03-14 11:27:50 +053022#include "ar9003_aic.h"
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +053023
24static void ar9003_mci_reset_req_wakeup(struct ath_hw *ah)
25{
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +053026 REG_RMW_FIELD(ah, AR_MCI_COMMAND2,
27 AR_MCI_COMMAND2_RESET_REQ_WAKEUP, 1);
28 udelay(1);
29 REG_RMW_FIELD(ah, AR_MCI_COMMAND2,
30 AR_MCI_COMMAND2_RESET_REQ_WAKEUP, 0);
31}
32
33static int ar9003_mci_wait_for_interrupt(struct ath_hw *ah, u32 address,
34 u32 bit_position, int time_out)
35{
36 struct ath_common *common = ath9k_hw_common(ah);
37
38 while (time_out) {
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +053039 if (!(REG_READ(ah, address) & bit_position)) {
40 udelay(10);
41 time_out -= 10;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +053042
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +053043 if (time_out < 0)
44 break;
45 else
46 continue;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +053047 }
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +053048 REG_WRITE(ah, address, bit_position);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +053049
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +053050 if (address != AR_MCI_INTERRUPT_RX_MSG_RAW)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +053051 break;
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +053052
53 if (bit_position & AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE)
54 ar9003_mci_reset_req_wakeup(ah);
55
56 if (bit_position & (AR_MCI_INTERRUPT_RX_MSG_SYS_SLEEPING |
57 AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING))
58 REG_WRITE(ah, AR_MCI_INTERRUPT_RAW,
59 AR_MCI_INTERRUPT_REMOTE_SLEEP_UPDATE);
60
61 REG_WRITE(ah, AR_MCI_INTERRUPT_RAW, AR_MCI_INTERRUPT_RX_MSG);
62 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +053063 }
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
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530130 if (mci->bt_version_known ||
131 (mci->bt_state == MCI_BT_SLEEP))
132 return;
133
134 MCI_GPM_SET_TYPE_OPCODE(payload, MCI_GPM_COEX_AGENT,
135 MCI_GPM_COEX_VERSION_QUERY);
136 ar9003_mci_send_message(ah, MCI_GPM, 0, payload, 16, wait_done, true);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530137}
138
139static void ar9003_mci_send_coex_version_response(struct ath_hw *ah,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530140 bool wait_done)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530141{
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530142 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
143 u32 payload[4] = {0, 0, 0, 0};
144
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530145 MCI_GPM_SET_TYPE_OPCODE(payload, MCI_GPM_COEX_AGENT,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530146 MCI_GPM_COEX_VERSION_RESPONSE);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530147 *(((u8 *)payload) + MCI_GPM_COEX_B_MAJOR_VERSION) =
148 mci->wlan_ver_major;
149 *(((u8 *)payload) + MCI_GPM_COEX_B_MINOR_VERSION) =
150 mci->wlan_ver_minor;
151 ar9003_mci_send_message(ah, MCI_GPM, 0, payload, 16, wait_done, true);
152}
153
154static void ar9003_mci_send_coex_wlan_channels(struct ath_hw *ah,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530155 bool wait_done)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530156{
157 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
158 u32 *payload = &mci->wlan_channels[0];
159
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530160 if (!mci->wlan_channels_update ||
161 (mci->bt_state == MCI_BT_SLEEP))
162 return;
163
164 MCI_GPM_SET_TYPE_OPCODE(payload, MCI_GPM_COEX_AGENT,
165 MCI_GPM_COEX_WLAN_CHANNELS);
166 ar9003_mci_send_message(ah, MCI_GPM, 0, payload, 16, wait_done, true);
167 MCI_GPM_SET_TYPE_OPCODE(payload, 0xff, 0xff);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530168}
169
170static void ar9003_mci_send_coex_bt_status_query(struct ath_hw *ah,
171 bool wait_done, u8 query_type)
172{
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530173 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
174 u32 payload[4] = {0, 0, 0, 0};
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530175 bool query_btinfo;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530176
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530177 if (mci->bt_state == MCI_BT_SLEEP)
178 return;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530179
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530180 query_btinfo = !!(query_type & (MCI_GPM_COEX_QUERY_BT_ALL_INFO |
181 MCI_GPM_COEX_QUERY_BT_TOPOLOGY));
182 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
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530185 *(((u8 *)payload) + MCI_GPM_COEX_B_BT_BITMAP) = query_type;
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530186
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +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)) {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530193 if (query_btinfo)
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530194 mci->need_flush_btinfo = true;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530195 }
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530196
197 if (query_btinfo)
198 mci->query_bt = false;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530199}
200
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530201static void ar9003_mci_send_coex_halt_bt_gpm(struct ath_hw *ah, bool halt,
202 bool wait_done)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530203{
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530204 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
205 u32 payload[4] = {0, 0, 0, 0};
206
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530207 MCI_GPM_SET_TYPE_OPCODE(payload, MCI_GPM_COEX_AGENT,
208 MCI_GPM_COEX_HALT_BT_GPM);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530209
210 if (halt) {
211 mci->query_bt = true;
212 /* Send next unhalt no matter halt sent or not */
213 mci->unhalt_bt_gpm = true;
214 mci->need_flush_btinfo = true;
215 *(((u8 *)payload) + MCI_GPM_COEX_B_HALT_STATE) =
216 MCI_GPM_COEX_BT_GPM_HALT;
217 } else
218 *(((u8 *)payload) + MCI_GPM_COEX_B_HALT_STATE) =
219 MCI_GPM_COEX_BT_GPM_UNHALT;
220
221 ar9003_mci_send_message(ah, MCI_GPM, 0, payload, 16, wait_done, true);
222}
223
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530224static void ar9003_mci_prep_interface(struct ath_hw *ah)
225{
226 struct ath_common *common = ath9k_hw_common(ah);
227 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
228 u32 saved_mci_int_en;
229 u32 mci_timeout = 150;
230
231 mci->bt_state = MCI_BT_SLEEP;
232 saved_mci_int_en = REG_READ(ah, AR_MCI_INTERRUPT_EN);
233
234 REG_WRITE(ah, AR_MCI_INTERRUPT_EN, 0);
235 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
236 REG_READ(ah, AR_MCI_INTERRUPT_RX_MSG_RAW));
237 REG_WRITE(ah, AR_MCI_INTERRUPT_RAW,
238 REG_READ(ah, AR_MCI_INTERRUPT_RAW));
239
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530240 ar9003_mci_remote_reset(ah, true);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530241 ar9003_mci_send_req_wake(ah, true);
242
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530243 if (!ar9003_mci_wait_for_interrupt(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
244 AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING, 500))
245 goto clear_redunt;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530246
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530247 mci->bt_state = MCI_BT_AWAKE;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530248
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +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 */
265 ar9003_mci_send_sys_waking(ah, true);
266 udelay(10);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530267
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530268 /*
269 * Set BT priority interrupt value to be 0xff to
270 * avoid having too many BT PRIORITY interrupts.
271 */
272 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);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530277
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530278 /*
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 */
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530283
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530284 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, AR_MCI_INTERRUPT_BT_PRI);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530287
Sujith Manoharanbc80d522015-02-16 10:49:59 +0530288 if (mci->is_2g && MCI_ANT_ARCH_PA_LNA_SHARED(mci)) {
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530289 ar9003_mci_send_lna_transfer(ah, true);
290 udelay(5);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530291 }
292
Sujith Manoharanbc80d522015-02-16 10:49:59 +0530293 if (mci->is_2g && !mci->update_2g5g && MCI_ANT_ARCH_PA_LNA_SHARED(mci)) {
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530294 if (ar9003_mci_wait_for_interrupt(ah,
295 AR_MCI_INTERRUPT_RX_MSG_RAW,
296 AR_MCI_INTERRUPT_RX_MSG_LNA_INFO,
297 mci_timeout))
298 ath_dbg(common, MCI,
299 "MCI WLAN has control over the LNA & BT obeys it\n");
300 else
301 ath_dbg(common, MCI,
302 "MCI BT didn't respond to LNA_TRANS\n");
303 }
304
305clear_redunt:
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530306 /* Clear the extra redundant SYS_WAKING from BT */
307 if ((mci->bt_state == MCI_BT_AWAKE) &&
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530308 (REG_READ_FIELD(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
309 AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING)) &&
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530310 (REG_READ_FIELD(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
311 AR_MCI_INTERRUPT_RX_MSG_SYS_SLEEPING) == 0)) {
312 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
313 AR_MCI_INTERRUPT_RX_MSG_SYS_WAKING);
314 REG_WRITE(ah, AR_MCI_INTERRUPT_RAW,
315 AR_MCI_INTERRUPT_REMOTE_SLEEP_UPDATE);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530316 }
317
318 REG_WRITE(ah, AR_MCI_INTERRUPT_EN, saved_mci_int_en);
319}
320
Sujith Manoharand1ca8b82012-02-22 12:41:01 +0530321void ar9003_mci_set_full_sleep(struct ath_hw *ah)
322{
Sujith Manoharand1ca8b82012-02-22 12:41:01 +0530323 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
324
Rajkumar Manoharanb98ccec2012-06-12 20:18:20 +0530325 if (ar9003_mci_state(ah, MCI_STATE_ENABLE) &&
Sujith Manoharand1ca8b82012-02-22 12:41:01 +0530326 (mci->bt_state != MCI_BT_SLEEP) &&
327 !mci->halted_bt_gpm) {
Sujith Manoharand1ca8b82012-02-22 12:41:01 +0530328 ar9003_mci_send_coex_halt_bt_gpm(ah, true, true);
329 }
330
331 mci->ready = false;
Sujith Manoharand1ca8b82012-02-22 12:41:01 +0530332}
333
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530334static void ar9003_mci_disable_interrupt(struct ath_hw *ah)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530335{
336 REG_WRITE(ah, AR_MCI_INTERRUPT_EN, 0);
337 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_EN, 0);
338}
339
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530340static void ar9003_mci_enable_interrupt(struct ath_hw *ah)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530341{
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530342 REG_WRITE(ah, AR_MCI_INTERRUPT_EN, AR_MCI_INTERRUPT_DEFAULT);
343 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_EN,
344 AR_MCI_INTERRUPT_RX_MSG_DEFAULT);
345}
346
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530347static bool ar9003_mci_check_int(struct ath_hw *ah, u32 ints)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530348{
349 u32 intr;
350
351 intr = REG_READ(ah, AR_MCI_INTERRUPT_RX_MSG_RAW);
352 return ((intr & ints) == ints);
353}
354
355void ar9003_mci_get_interrupt(struct ath_hw *ah, u32 *raw_intr,
356 u32 *rx_msg_intr)
357{
358 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
Felix Fietkau8a309302011-12-17 16:47:56 +0100359
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530360 *raw_intr = mci->raw_intr;
361 *rx_msg_intr = mci->rx_msg_intr;
362
363 /* Clean int bits after the values are read. */
364 mci->raw_intr = 0;
365 mci->rx_msg_intr = 0;
366}
367EXPORT_SYMBOL(ar9003_mci_get_interrupt);
368
Sujith Manoharan5a1e2732012-02-22 12:40:55 +0530369void ar9003_mci_get_isr(struct ath_hw *ah, enum ath9k_int *masked)
370{
371 struct ath_common *common = ath9k_hw_common(ah);
372 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
373 u32 raw_intr, rx_msg_intr;
374
375 rx_msg_intr = REG_READ(ah, AR_MCI_INTERRUPT_RX_MSG_RAW);
376 raw_intr = REG_READ(ah, AR_MCI_INTERRUPT_RAW);
377
378 if ((raw_intr == 0xdeadbeef) || (rx_msg_intr == 0xdeadbeef)) {
379 ath_dbg(common, MCI,
380 "MCI gets 0xdeadbeef during int processing\n");
381 } else {
382 mci->rx_msg_intr |= rx_msg_intr;
383 mci->raw_intr |= raw_intr;
384 *masked |= ATH9K_INT_MCI;
385
386 if (rx_msg_intr & AR_MCI_INTERRUPT_RX_MSG_CONT_INFO)
387 mci->cont_status = REG_READ(ah, AR_MCI_CONT_STATUS);
388
389 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_RAW, rx_msg_intr);
390 REG_WRITE(ah, AR_MCI_INTERRUPT_RAW, raw_intr);
391 }
392}
393
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530394static void ar9003_mci_2g5g_changed(struct ath_hw *ah, bool is_2g)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530395{
396 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
397
398 if (!mci->update_2g5g &&
399 (mci->is_2g != is_2g))
400 mci->update_2g5g = true;
401
402 mci->is_2g = is_2g;
403}
404
405static bool ar9003_mci_is_gpm_valid(struct ath_hw *ah, u32 msg_index)
406{
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530407 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
408 u32 *payload;
409 u32 recv_type, offset;
410
411 if (msg_index == MCI_GPM_INVALID)
412 return false;
413
414 offset = msg_index << 4;
415
416 payload = (u32 *)(mci->gpm_buf + offset);
417 recv_type = MCI_GPM_TYPE(payload);
418
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530419 if (recv_type == MCI_GPM_RSVD_PATTERN)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530420 return false;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530421
422 return true;
423}
424
425static void ar9003_mci_observation_set_up(struct ath_hw *ah)
426{
427 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530428
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530429 if (mci->config & ATH_MCI_CONFIG_MCI_OBS_MCI) {
430 ath9k_hw_cfg_output(ah, 3, AR_GPIO_OUTPUT_MUX_AS_MCI_WLAN_DATA);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530431 ath9k_hw_cfg_output(ah, 2, AR_GPIO_OUTPUT_MUX_AS_MCI_WLAN_CLK);
432 ath9k_hw_cfg_output(ah, 1, AR_GPIO_OUTPUT_MUX_AS_MCI_BT_DATA);
433 ath9k_hw_cfg_output(ah, 0, AR_GPIO_OUTPUT_MUX_AS_MCI_BT_CLK);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530434 } else if (mci->config & ATH_MCI_CONFIG_MCI_OBS_TXRX) {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530435 ath9k_hw_cfg_output(ah, 3, AR_GPIO_OUTPUT_MUX_AS_WL_IN_TX);
436 ath9k_hw_cfg_output(ah, 2, AR_GPIO_OUTPUT_MUX_AS_WL_IN_RX);
437 ath9k_hw_cfg_output(ah, 1, AR_GPIO_OUTPUT_MUX_AS_BT_IN_TX);
438 ath9k_hw_cfg_output(ah, 0, AR_GPIO_OUTPUT_MUX_AS_BT_IN_RX);
439 ath9k_hw_cfg_output(ah, 5, AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530440 } else if (mci->config & ATH_MCI_CONFIG_MCI_OBS_BT) {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530441 ath9k_hw_cfg_output(ah, 3, AR_GPIO_OUTPUT_MUX_AS_BT_IN_TX);
442 ath9k_hw_cfg_output(ah, 2, AR_GPIO_OUTPUT_MUX_AS_BT_IN_RX);
443 ath9k_hw_cfg_output(ah, 1, AR_GPIO_OUTPUT_MUX_AS_MCI_BT_DATA);
444 ath9k_hw_cfg_output(ah, 0, AR_GPIO_OUTPUT_MUX_AS_MCI_BT_CLK);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530445 } else
446 return;
447
448 REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL, AR_GPIO_JTAG_DISABLE);
449
Sujith Manoharan0cc4cde2012-02-22 12:42:15 +0530450 REG_RMW_FIELD(ah, AR_PHY_GLB_CONTROL, AR_GLB_DS_JTAG_DISABLE, 1);
451 REG_RMW_FIELD(ah, AR_PHY_GLB_CONTROL, AR_GLB_WLAN_UART_INTF_EN, 0);
452 REG_SET_BIT(ah, AR_GLB_GPIO_CONTROL, ATH_MCI_CONFIG_MCI_OBS_GPIO);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530453
454 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL2, AR_BTCOEX_CTRL2_GPIO_OBS_SEL, 0);
455 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL2, AR_BTCOEX_CTRL2_MAC_BB_OBS_SEL, 1);
456 REG_WRITE(ah, AR_OBS, 0x4b);
457 REG_RMW_FIELD(ah, AR_DIAG_SW, AR_DIAG_OBS_PT_SEL1, 0x03);
458 REG_RMW_FIELD(ah, AR_DIAG_SW, AR_DIAG_OBS_PT_SEL2, 0x01);
459 REG_RMW_FIELD(ah, AR_MACMISC, AR_MACMISC_MISC_OBS_BUS_LSB, 0x02);
460 REG_RMW_FIELD(ah, AR_MACMISC, AR_MACMISC_MISC_OBS_BUS_MSB, 0x03);
461 REG_RMW_FIELD(ah, AR_PHY_TEST_CTL_STATUS,
462 AR_PHY_TEST_CTL_DEBUGPORT_SEL, 0x07);
463}
464
465static bool ar9003_mci_send_coex_bt_flags(struct ath_hw *ah, bool wait_done,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530466 u8 opcode, u32 bt_flags)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530467{
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530468 u32 pld[4] = {0, 0, 0, 0};
469
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530470 MCI_GPM_SET_TYPE_OPCODE(pld, MCI_GPM_COEX_AGENT,
471 MCI_GPM_COEX_BT_UPDATE_FLAGS);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530472
473 *(((u8 *)pld) + MCI_GPM_COEX_B_BT_FLAGS_OP) = opcode;
474 *(((u8 *)pld) + MCI_GPM_COEX_W_BT_FLAGS + 0) = bt_flags & 0xFF;
475 *(((u8 *)pld) + MCI_GPM_COEX_W_BT_FLAGS + 1) = (bt_flags >> 8) & 0xFF;
476 *(((u8 *)pld) + MCI_GPM_COEX_W_BT_FLAGS + 2) = (bt_flags >> 16) & 0xFF;
477 *(((u8 *)pld) + MCI_GPM_COEX_W_BT_FLAGS + 3) = (bt_flags >> 24) & 0xFF;
478
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530479 return ar9003_mci_send_message(ah, MCI_GPM, 0, pld, 16,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530480 wait_done, true);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530481}
482
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530483static void ar9003_mci_sync_bt_state(struct ath_hw *ah)
484{
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530485 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
486 u32 cur_bt_state;
487
Rajkumar Manoharanb98ccec2012-06-12 20:18:20 +0530488 cur_bt_state = ar9003_mci_state(ah, MCI_STATE_REMOTE_SLEEP);
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530489
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530490 if (mci->bt_state != cur_bt_state)
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530491 mci->bt_state = cur_bt_state;
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530492
493 if (mci->bt_state != MCI_BT_SLEEP) {
494
495 ar9003_mci_send_coex_version_query(ah, true);
496 ar9003_mci_send_coex_wlan_channels(ah, true);
497
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530498 if (mci->unhalt_bt_gpm == true)
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530499 ar9003_mci_send_coex_halt_bt_gpm(ah, false, true);
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530500 }
501}
502
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530503void ar9003_mci_check_bt(struct ath_hw *ah)
504{
505 struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
506
507 if (!mci_hw->ready)
508 return;
509
510 /*
511 * check BT state again to make
512 * sure it's not changed.
513 */
514 ar9003_mci_sync_bt_state(ah);
515 ar9003_mci_2g5g_switch(ah, true);
516
517 if ((mci_hw->bt_state == MCI_BT_AWAKE) &&
518 (mci_hw->query_bt == true)) {
519 mci_hw->need_flush_btinfo = true;
520 }
521}
522
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530523static void ar9003_mci_process_gpm_extra(struct ath_hw *ah, u8 gpm_type,
524 u8 gpm_opcode, u32 *p_gpm)
525{
526 struct ath_common *common = ath9k_hw_common(ah);
527 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
528 u8 *p_data = (u8 *) p_gpm;
529
530 if (gpm_type != MCI_GPM_COEX_AGENT)
531 return;
532
533 switch (gpm_opcode) {
534 case MCI_GPM_COEX_VERSION_QUERY:
535 ath_dbg(common, MCI, "MCI Recv GPM COEX Version Query\n");
536 ar9003_mci_send_coex_version_response(ah, true);
537 break;
538 case MCI_GPM_COEX_VERSION_RESPONSE:
539 ath_dbg(common, MCI, "MCI Recv GPM COEX Version Response\n");
540 mci->bt_ver_major =
541 *(p_data + MCI_GPM_COEX_B_MAJOR_VERSION);
542 mci->bt_ver_minor =
543 *(p_data + MCI_GPM_COEX_B_MINOR_VERSION);
544 mci->bt_version_known = true;
545 ath_dbg(common, MCI, "MCI BT Coex version: %d.%d\n",
546 mci->bt_ver_major, mci->bt_ver_minor);
547 break;
548 case MCI_GPM_COEX_STATUS_QUERY:
549 ath_dbg(common, MCI,
550 "MCI Recv GPM COEX Status Query = 0x%02X\n",
551 *(p_data + MCI_GPM_COEX_B_WLAN_BITMAP));
552 mci->wlan_channels_update = true;
553 ar9003_mci_send_coex_wlan_channels(ah, true);
554 break;
555 case MCI_GPM_COEX_BT_PROFILE_INFO:
556 mci->query_bt = true;
557 ath_dbg(common, MCI, "MCI Recv GPM COEX BT_Profile_Info\n");
558 break;
559 case MCI_GPM_COEX_BT_STATUS_UPDATE:
560 mci->query_bt = true;
561 ath_dbg(common, MCI,
562 "MCI Recv GPM COEX BT_Status_Update SEQ=%d (drop&query)\n",
563 *(p_gpm + 3));
564 break;
565 default:
566 break;
567 }
568}
569
570static u32 ar9003_mci_wait_for_gpm(struct ath_hw *ah, u8 gpm_type,
571 u8 gpm_opcode, int time_out)
572{
573 struct ath_common *common = ath9k_hw_common(ah);
574 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
575 u32 *p_gpm = NULL, mismatch = 0, more_data;
576 u32 offset;
577 u8 recv_type = 0, recv_opcode = 0;
578 bool b_is_bt_cal_done = (gpm_type == MCI_GPM_BT_CAL_DONE);
579
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530580 more_data = time_out ? MCI_GPM_NOMORE : MCI_GPM_MORE;
581
582 while (time_out > 0) {
583 if (p_gpm) {
584 MCI_GPM_RECYCLE(p_gpm);
585 p_gpm = NULL;
586 }
587
588 if (more_data != MCI_GPM_MORE)
589 time_out = ar9003_mci_wait_for_interrupt(ah,
590 AR_MCI_INTERRUPT_RX_MSG_RAW,
591 AR_MCI_INTERRUPT_RX_MSG_GPM,
592 time_out);
593
594 if (!time_out)
595 break;
596
Sujith Manoharanad1dc632015-02-16 10:50:00 +0530597 offset = ar9003_mci_get_next_gpm_offset(ah, &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 Manoharanad1dc632015-02-16 10:50:00 +0530661 offset = ar9003_mci_get_next_gpm_offset(ah, &more_data);
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530662 if (offset == MCI_GPM_INVALID)
663 break;
664
665 p_gpm = (u32 *) (mci->gpm_buf + offset);
666 recv_type = MCI_GPM_TYPE(p_gpm);
667 recv_opcode = MCI_GPM_OPCODE(p_gpm);
668
669 if (!MCI_GPM_IS_CAL_TYPE(recv_type))
670 ar9003_mci_process_gpm_extra(ah, recv_type,
671 recv_opcode, p_gpm);
672
673 MCI_GPM_RECYCLE(p_gpm);
674 }
675
676 return time_out;
677}
678
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530679bool ar9003_mci_start_reset(struct ath_hw *ah, struct ath9k_channel *chan)
680{
681 struct ath_common *common = ath9k_hw_common(ah);
682 struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
683 u32 payload[4] = {0, 0, 0, 0};
684
685 ar9003_mci_2g5g_changed(ah, IS_CHAN_2GHZ(chan));
686
687 if (mci_hw->bt_state != MCI_BT_CAL_START)
688 return false;
689
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530690 mci_hw->bt_state = MCI_BT_CAL;
691
692 /*
693 * MCI FIX: disable mci interrupt here. This is to avoid
694 * SW_MSG_DONE or RX_MSG bits to trigger MCI_INT and
695 * lead to mci_intr reentry.
696 */
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530697 ar9003_mci_disable_interrupt(ah);
698
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530699 MCI_GPM_SET_CAL_TYPE(payload, MCI_GPM_WLAN_CAL_GRANT);
700 ar9003_mci_send_message(ah, MCI_GPM, 0, payload,
701 16, true, false);
702
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530703 /* Wait BT calibration to be completed for 25ms */
704
705 if (ar9003_mci_wait_for_gpm(ah, MCI_GPM_BT_CAL_DONE,
706 0, 25000))
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530707 ath_dbg(common, MCI, "MCI BT_CAL_DONE received\n");
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530708 else
709 ath_dbg(common, MCI,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +0530710 "MCI BT_CAL_DONE not received\n");
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530711
712 mci_hw->bt_state = MCI_BT_AWAKE;
713 /* MCI FIX: enable mci interrupt here */
714 ar9003_mci_enable_interrupt(ah);
715
716 return true;
717}
718
719int ar9003_mci_end_reset(struct ath_hw *ah, struct ath9k_channel *chan,
720 struct ath9k_hw_cal_data *caldata)
721{
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530722 struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
723
724 if (!mci_hw->ready)
725 return 0;
726
727 if (!IS_CHAN_2GHZ(chan) || (mci_hw->bt_state != MCI_BT_SLEEP))
728 goto exit;
729
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530730 if (!ar9003_mci_check_int(ah, AR_MCI_INTERRUPT_RX_MSG_REMOTE_RESET) &&
731 !ar9003_mci_check_int(ah, AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE))
732 goto exit;
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530733
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530734 /*
735 * BT is sleeping. Check if BT wakes up during
736 * WLAN calibration. If BT wakes up during
737 * WLAN calibration, need to go through all
738 * message exchanges again and recal.
739 */
740 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
741 (AR_MCI_INTERRUPT_RX_MSG_REMOTE_RESET |
742 AR_MCI_INTERRUPT_RX_MSG_REQ_WAKE));
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530743
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530744 ar9003_mci_remote_reset(ah, true);
745 ar9003_mci_send_sys_waking(ah, true);
746 udelay(1);
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530747
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530748 if (IS_CHAN_2GHZ(chan))
749 ar9003_mci_send_lna_transfer(ah, true);
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530750
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530751 mci_hw->bt_state = MCI_BT_AWAKE;
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530752
Bala Shanmugamb55f6bb2012-10-15 15:29:48 +0530753 REG_CLR_BIT(ah, AR_PHY_TIMING4,
754 1 << AR_PHY_TIMING_CONTROL4_DO_GAIN_DC_IQ_CAL_SHIFT);
755
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530756 if (caldata) {
Sujith Manoharan4b9b42b2013-09-11 16:36:31 +0530757 clear_bit(TXIQCAL_DONE, &caldata->cal_flags);
758 clear_bit(TXCLCAL_DONE, &caldata->cal_flags);
759 clear_bit(RTT_DONE, &caldata->cal_flags);
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530760 }
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530761
762 if (!ath9k_hw_init_cal(ah, chan))
763 return -EIO;
764
Bala Shanmugamb55f6bb2012-10-15 15:29:48 +0530765 REG_SET_BIT(ah, AR_PHY_TIMING4,
766 1 << AR_PHY_TIMING_CONTROL4_DO_GAIN_DC_IQ_CAL_SHIFT);
767
Sujith Manoharan528e5d32012-02-22 12:41:12 +0530768exit:
769 ar9003_mci_enable_interrupt(ah);
770 return 0;
771}
772
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530773static void ar9003_mci_mute_bt(struct ath_hw *ah)
774{
Sujith Manoharan2f890ca2015-02-16 10:50:01 +0530775 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
776
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530777 /* disable all MCI messages */
778 REG_WRITE(ah, AR_MCI_MSG_ATTRIBUTES_TABLE, 0xffff0000);
Sujith Manoharan2f890ca2015-02-16 10:50:01 +0530779 REG_WRITE(ah, AR_BTCOEX_WL_WEIGHTS0, 0xffffffff);
780 REG_WRITE(ah, AR_BTCOEX_WL_WEIGHTS1, 0xffffffff);
781 REG_WRITE(ah, AR_BTCOEX_WL_WEIGHTS2, 0xffffffff);
782 REG_WRITE(ah, AR_BTCOEX_WL_WEIGHTS3, 0xffffffff);
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530783 REG_SET_BIT(ah, AR_MCI_TX_CTRL, AR_MCI_TX_CTRL_DISABLE_LNA_UPDATE);
784
785 /* wait pending HW messages to flush out */
786 udelay(10);
787
788 /*
789 * Send LNA_TAKE and SYS_SLEEPING when
790 * 1. reset not after resuming from full sleep
791 * 2. before reset MCI RX, to quiet BT and avoid MCI RX misalignment
792 */
Sujith Manoharan2f890ca2015-02-16 10:50:01 +0530793 if (MCI_ANT_ARCH_PA_LNA_SHARED(mci)) {
794 ar9003_mci_send_lna_take(ah, true);
795 udelay(5);
796 }
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530797
Sujith Manoharana3f846f2012-02-22 12:41:24 +0530798 ar9003_mci_send_sys_sleeping(ah, true);
799}
800
Sujith Manoharan4f851df2012-02-22 12:42:10 +0530801static void ar9003_mci_osla_setup(struct ath_hw *ah, bool enable)
802{
803 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
804 u32 thresh;
805
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530806 if (!enable) {
Sujith Manoharan4f851df2012-02-22 12:42:10 +0530807 REG_CLR_BIT(ah, AR_BTCOEX_CTRL,
808 AR_BTCOEX_CTRL_ONE_STEP_LOOK_AHEAD_EN);
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530809 return;
Sujith Manoharan4f851df2012-02-22 12:42:10 +0530810 }
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530811 REG_RMW_FIELD(ah, AR_MCI_SCHD_TABLE_2, AR_MCI_SCHD_TABLE_2_HW_BASED, 1);
812 REG_RMW_FIELD(ah, AR_MCI_SCHD_TABLE_2,
813 AR_MCI_SCHD_TABLE_2_MEM_BASED, 1);
814
Rajkumar Manoharan4c6231a2012-10-15 15:29:45 +0530815 if (AR_SREV_9565(ah))
816 REG_RMW_FIELD(ah, AR_MCI_MISC, AR_MCI_MISC_HW_FIX_EN, 1);
817
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +0530818 if (!(mci->config & ATH_MCI_CONFIG_DISABLE_AGGR_THRESH)) {
819 thresh = MS(mci->config, ATH_MCI_CONFIG_AGGR_THRESH);
820 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL,
821 AR_BTCOEX_CTRL_AGGR_THRESH, thresh);
822 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL,
823 AR_BTCOEX_CTRL_TIME_TO_NEXT_BT_THRESH_EN, 1);
824 } else
825 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL,
826 AR_BTCOEX_CTRL_TIME_TO_NEXT_BT_THRESH_EN, 0);
827
828 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL,
829 AR_BTCOEX_CTRL_ONE_STEP_LOOK_AHEAD_EN, 1);
Sujith Manoharan4f851df2012-02-22 12:42:10 +0530830}
831
Sujith Manoharan4d9f7c62015-02-16 10:49:58 +0530832static void ar9003_mci_stat_setup(struct ath_hw *ah)
833{
834 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
835
836 if (!AR_SREV_9565(ah))
837 return;
838
839 if (mci->config & ATH_MCI_CONFIG_MCI_STAT_DBG) {
840 REG_RMW_FIELD(ah, AR_MCI_DBG_CNT_CTRL,
841 AR_MCI_DBG_CNT_CTRL_ENABLE, 1);
842 REG_RMW_FIELD(ah, AR_MCI_DBG_CNT_CTRL,
843 AR_MCI_DBG_CNT_CTRL_BT_LINKID,
844 MCI_STAT_ALL_BT_LINKID);
845 } else {
846 REG_RMW_FIELD(ah, AR_MCI_DBG_CNT_CTRL,
847 AR_MCI_DBG_CNT_CTRL_ENABLE, 0);
848 }
849}
850
Sujith Manoharane18e1642015-02-16 10:49:56 +0530851static void ar9003_mci_set_btcoex_ctrl_9565_1ANT(struct ath_hw *ah)
852{
853 u32 regval;
854
855 regval = SM(1, AR_BTCOEX_CTRL_AR9462_MODE) |
856 SM(1, AR_BTCOEX_CTRL_WBTIMER_EN) |
857 SM(1, AR_BTCOEX_CTRL_PA_SHARED) |
858 SM(1, AR_BTCOEX_CTRL_LNA_SHARED) |
859 SM(1, AR_BTCOEX_CTRL_NUM_ANTENNAS) |
860 SM(1, AR_BTCOEX_CTRL_RX_CHAIN_MASK) |
861 SM(0, AR_BTCOEX_CTRL_1_CHAIN_ACK) |
862 SM(0, AR_BTCOEX_CTRL_1_CHAIN_BCN) |
863 SM(0, AR_BTCOEX_CTRL_ONE_STEP_LOOK_AHEAD_EN);
864
865 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL2,
866 AR_BTCOEX_CTRL2_TX_CHAIN_MASK, 0x1);
867 REG_WRITE(ah, AR_BTCOEX_CTRL, regval);
868}
869
870static void ar9003_mci_set_btcoex_ctrl_9565_2ANT(struct ath_hw *ah)
871{
872 u32 regval;
873
874 regval = SM(1, AR_BTCOEX_CTRL_AR9462_MODE) |
875 SM(1, AR_BTCOEX_CTRL_WBTIMER_EN) |
876 SM(0, AR_BTCOEX_CTRL_PA_SHARED) |
877 SM(0, AR_BTCOEX_CTRL_LNA_SHARED) |
878 SM(2, AR_BTCOEX_CTRL_NUM_ANTENNAS) |
879 SM(1, AR_BTCOEX_CTRL_RX_CHAIN_MASK) |
880 SM(0, AR_BTCOEX_CTRL_1_CHAIN_ACK) |
881 SM(0, AR_BTCOEX_CTRL_1_CHAIN_BCN) |
882 SM(0, AR_BTCOEX_CTRL_ONE_STEP_LOOK_AHEAD_EN);
883
884 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL2,
885 AR_BTCOEX_CTRL2_TX_CHAIN_MASK, 0x0);
886 REG_WRITE(ah, AR_BTCOEX_CTRL, regval);
887}
888
889static void ar9003_mci_set_btcoex_ctrl_9462(struct ath_hw *ah)
890{
891 u32 regval;
892
893 regval = SM(1, AR_BTCOEX_CTRL_AR9462_MODE) |
894 SM(1, AR_BTCOEX_CTRL_WBTIMER_EN) |
895 SM(1, AR_BTCOEX_CTRL_PA_SHARED) |
896 SM(1, AR_BTCOEX_CTRL_LNA_SHARED) |
897 SM(2, AR_BTCOEX_CTRL_NUM_ANTENNAS) |
898 SM(3, AR_BTCOEX_CTRL_RX_CHAIN_MASK) |
899 SM(0, AR_BTCOEX_CTRL_1_CHAIN_ACK) |
900 SM(0, AR_BTCOEX_CTRL_1_CHAIN_BCN) |
901 SM(0, AR_BTCOEX_CTRL_ONE_STEP_LOOK_AHEAD_EN);
902
903 REG_WRITE(ah, AR_BTCOEX_CTRL, regval);
904}
905
Sujith Manoharan69c6ac62012-09-26 07:54:43 +0530906int ar9003_mci_reset(struct ath_hw *ah, bool en_int, bool is_2g,
907 bool is_full_sleep)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530908{
909 struct ath_common *common = ath9k_hw_common(ah);
910 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
Rajkumar Manoharane82cb032012-10-12 14:07:25 +0530911 u32 regval, i;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530912
Sujith Manoharan4f851df2012-02-22 12:42:10 +0530913 ath_dbg(common, MCI, "MCI Reset (full_sleep = %d, is_2g = %d)\n",
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530914 is_full_sleep, is_2g);
915
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530916 if (REG_READ(ah, AR_BTCOEX_CTRL) == 0xdeadbeef) {
Sujith Manoharan69c6ac62012-09-26 07:54:43 +0530917 ath_err(common, "BTCOEX control register is dead\n");
918 return -EINVAL;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530919 }
920
921 /* Program MCI DMA related registers */
922 REG_WRITE(ah, AR_MCI_GPM_0, mci->gpm_addr);
923 REG_WRITE(ah, AR_MCI_GPM_1, mci->gpm_len);
924 REG_WRITE(ah, AR_MCI_SCHD_TABLE_0, mci->sched_addr);
925
926 /*
927 * To avoid MCI state machine be affected by incoming remote MCI msgs,
928 * MCI mode will be enabled later, right before reset the MCI TX and RX.
929 */
Bala Shanmugamd9575da2012-10-15 15:29:47 +0530930 if (AR_SREV_9565(ah)) {
Sujith Manoharane18e1642015-02-16 10:49:56 +0530931 u8 ant = MS(mci->config, ATH_MCI_CONFIG_ANT_ARCH);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530932
Sujith Manoharane18e1642015-02-16 10:49:56 +0530933 if (ant == ATH_MCI_ANT_ARCH_1_ANT_PA_LNA_SHARED)
934 ar9003_mci_set_btcoex_ctrl_9565_1ANT(ah);
935 else
936 ar9003_mci_set_btcoex_ctrl_9565_2ANT(ah);
937 } else {
938 ar9003_mci_set_btcoex_ctrl_9462(ah);
939 }
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530940
Sujith Manoharan4f851df2012-02-22 12:42:10 +0530941 if (is_2g && !(mci->config & ATH_MCI_CONFIG_DISABLE_OSLA))
942 ar9003_mci_osla_setup(ah, true);
943 else
944 ar9003_mci_osla_setup(ah, false);
945
946 REG_SET_BIT(ah, AR_PHY_GLB_CONTROL,
947 AR_BTCOEX_CTRL_SPDT_ENABLE);
948 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL3,
949 AR_BTCOEX_CTRL3_CONT_INFO_TIMEOUT, 20);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530950
Rajkumar Manoharane75d4ed2012-10-25 17:16:52 +0530951 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL2, AR_BTCOEX_CTRL2_RX_DEWEIGHT, 0);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530952 REG_RMW_FIELD(ah, AR_PCU_MISC, AR_PCU_BT_ANT_PREVENT_RX, 0);
953
Rajkumar Manoharane75d4ed2012-10-25 17:16:52 +0530954 /* Set the time out to 3.125ms (5 BT slots) */
955 REG_RMW_FIELD(ah, AR_BTCOEX_WL_LNA, AR_BTCOEX_WL_LNA_TIMEOUT, 0x3D090);
956
Rajkumar Manoharane82cb032012-10-12 14:07:25 +0530957 /* concurrent tx priority */
958 if (mci->config & ATH_MCI_CONFIG_CONCUR_TX) {
959 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL2,
960 AR_BTCOEX_CTRL2_DESC_BASED_TXPWR_ENABLE, 0);
961 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL2,
962 AR_BTCOEX_CTRL2_TXPWR_THRESH, 0x7f);
963 REG_RMW_FIELD(ah, AR_BTCOEX_CTRL,
964 AR_BTCOEX_CTRL_REDUCE_TXPWR, 0);
965 for (i = 0; i < 8; i++)
966 REG_WRITE(ah, AR_BTCOEX_MAX_TXPWR(i), 0x7f7f7f7f);
967 }
968
Sujith Manoharan4f851df2012-02-22 12:42:10 +0530969 regval = MS(mci->config, ATH_MCI_CONFIG_CLK_DIV);
970 REG_RMW_FIELD(ah, AR_MCI_TX_CTRL, AR_MCI_TX_CTRL_CLK_DIV, regval);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530971 REG_SET_BIT(ah, AR_BTCOEX_CTRL, AR_BTCOEX_CTRL_MCI_MODE_EN);
972
973 /* Resetting the Rx and Tx paths of MCI */
974 regval = REG_READ(ah, AR_MCI_COMMAND2);
975 regval |= SM(1, AR_MCI_COMMAND2_RESET_TX);
976 REG_WRITE(ah, AR_MCI_COMMAND2, regval);
977
978 udelay(1);
979
980 regval &= ~SM(1, AR_MCI_COMMAND2_RESET_TX);
981 REG_WRITE(ah, AR_MCI_COMMAND2, regval);
982
983 if (is_full_sleep) {
984 ar9003_mci_mute_bt(ah);
985 udelay(100);
986 }
987
Rajkumar Manoharan38634952012-06-11 12:19:32 +0530988 /* Check pending GPM msg before MCI Reset Rx */
Rajkumar Manoharan506847a2012-06-12 20:18:16 +0530989 ar9003_mci_check_gpm_offset(ah);
Rajkumar Manoharan38634952012-06-11 12:19:32 +0530990
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +0530991 regval |= SM(1, AR_MCI_COMMAND2_RESET_RX);
992 REG_WRITE(ah, AR_MCI_COMMAND2, regval);
993 udelay(1);
994 regval &= ~SM(1, AR_MCI_COMMAND2_RESET_RX);
995 REG_WRITE(ah, AR_MCI_COMMAND2, regval);
996
Sujith Manoharanad1dc632015-02-16 10:50:00 +0530997 /* Init GPM offset after MCI Reset Rx */
998 ar9003_mci_state(ah, MCI_STATE_INIT_GPM_OFFSET);
Sujith Manoharan4f851df2012-02-22 12:42:10 +0530999
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301000 REG_WRITE(ah, AR_MCI_MSG_ATTRIBUTES_TABLE,
1001 (SM(0xe801, AR_MCI_MSG_ATTRIBUTES_TABLE_INVALID_HDR) |
1002 SM(0x0000, AR_MCI_MSG_ATTRIBUTES_TABLE_CHECKSUM)));
1003
Sujith Manoharand808ecd2015-02-16 10:49:57 +05301004 if (MCI_ANT_ARCH_PA_LNA_SHARED(mci))
1005 REG_CLR_BIT(ah, AR_MCI_TX_CTRL,
1006 AR_MCI_TX_CTRL_DISABLE_LNA_UPDATE);
1007 else
1008 REG_SET_BIT(ah, AR_MCI_TX_CTRL,
1009 AR_MCI_TX_CTRL_DISABLE_LNA_UPDATE);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301010
Sujith Manoharan4f851df2012-02-22 12:42:10 +05301011 ar9003_mci_observation_set_up(ah);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301012
1013 mci->ready = true;
1014 ar9003_mci_prep_interface(ah);
Sujith Manoharan4d9f7c62015-02-16 10:49:58 +05301015 ar9003_mci_stat_setup(ah);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301016
1017 if (en_int)
1018 ar9003_mci_enable_interrupt(ah);
Sujith Manoharan69c6ac62012-09-26 07:54:43 +05301019
1020 return 0;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301021}
1022
Sujith Manoharan528e5d32012-02-22 12:41:12 +05301023void ar9003_mci_stop_bt(struct ath_hw *ah, bool save_fullsleep)
1024{
1025 struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
1026
1027 ar9003_mci_disable_interrupt(ah);
1028
1029 if (mci_hw->ready && !save_fullsleep) {
1030 ar9003_mci_mute_bt(ah);
1031 udelay(20);
1032 REG_WRITE(ah, AR_BTCOEX_CTRL, 0);
1033 }
1034
1035 mci_hw->bt_state = MCI_BT_SLEEP;
1036 mci_hw->ready = false;
1037}
1038
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301039static void ar9003_mci_send_2g5g_status(struct ath_hw *ah, bool wait_done)
1040{
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301041 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
1042 u32 new_flags, to_set, to_clear;
1043
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +05301044 if (!mci->update_2g5g || (mci->bt_state == MCI_BT_SLEEP))
1045 return;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301046
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +05301047 if (mci->is_2g) {
1048 new_flags = MCI_2G_FLAGS;
1049 to_clear = MCI_2G_FLAGS_CLEAR_MASK;
1050 to_set = MCI_2G_FLAGS_SET_MASK;
1051 } else {
1052 new_flags = MCI_5G_FLAGS;
1053 to_clear = MCI_5G_FLAGS_CLEAR_MASK;
1054 to_set = MCI_5G_FLAGS_SET_MASK;
1055 }
1056
1057 if (to_clear)
1058 ar9003_mci_send_coex_bt_flags(ah, wait_done,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +05301059 MCI_GPM_COEX_BT_FLAGS_CLEAR,
1060 to_clear);
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +05301061 if (to_set)
1062 ar9003_mci_send_coex_bt_flags(ah, wait_done,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +05301063 MCI_GPM_COEX_BT_FLAGS_SET,
1064 to_set);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301065}
1066
1067static void ar9003_mci_queue_unsent_gpm(struct ath_hw *ah, u8 header,
1068 u32 *payload, bool queue)
1069{
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301070 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
1071 u8 type, opcode;
1072
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301073 /* check if the message is to be queued */
1074 if (header != MCI_GPM)
1075 return;
1076
1077 type = MCI_GPM_TYPE(payload);
1078 opcode = MCI_GPM_OPCODE(payload);
1079
1080 if (type != MCI_GPM_COEX_AGENT)
1081 return;
1082
1083 switch (opcode) {
1084 case MCI_GPM_COEX_BT_UPDATE_FLAGS:
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301085 if (*(((u8 *)payload) + MCI_GPM_COEX_B_BT_FLAGS_OP) ==
Sujith Manoharanc91ec462012-02-22 12:40:03 +05301086 MCI_GPM_COEX_BT_FLAGS_READ)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301087 break;
1088
1089 mci->update_2g5g = queue;
1090
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301091 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301092 case MCI_GPM_COEX_WLAN_CHANNELS:
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301093 mci->wlan_channels_update = queue;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301094 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301095 case MCI_GPM_COEX_HALT_BT_GPM:
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301096 if (*(((u8 *)payload) + MCI_GPM_COEX_B_HALT_STATE) ==
Sujith Manoharan37cd9d72012-02-22 12:42:21 +05301097 MCI_GPM_COEX_BT_GPM_UNHALT) {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301098 mci->unhalt_bt_gpm = queue;
1099
Sujith Manoharan37cd9d72012-02-22 12:42:21 +05301100 if (!queue)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301101 mci->halted_bt_gpm = false;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301102 }
1103
1104 if (*(((u8 *)payload) + MCI_GPM_COEX_B_HALT_STATE) ==
1105 MCI_GPM_COEX_BT_GPM_HALT) {
1106
1107 mci->halted_bt_gpm = !queue;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301108 }
1109
1110 break;
1111 default:
1112 break;
1113 }
1114}
1115
Rajkumar Manoharan1bde95fa2012-06-11 12:19:33 +05301116void ar9003_mci_2g5g_switch(struct ath_hw *ah, bool force)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301117{
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301118 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
1119
Rajkumar Manoharan1bde95fa2012-06-11 12:19:33 +05301120 if (!mci->update_2g5g && !force)
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +05301121 return;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301122
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +05301123 if (mci->is_2g) {
Rajkumar Manoharan83bfea42012-07-01 19:53:55 +05301124 ar9003_mci_send_2g5g_status(ah, true);
1125 ar9003_mci_send_lna_transfer(ah, true);
1126 udelay(5);
Rajkumar Manoharan4ff6a9d2012-06-18 19:02:40 +05301127
1128 REG_CLR_BIT(ah, AR_MCI_TX_CTRL,
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +05301129 AR_MCI_TX_CTRL_DISABLE_LNA_UPDATE);
1130 REG_CLR_BIT(ah, AR_PHY_GLB_CONTROL,
1131 AR_BTCOEX_CTRL_BT_OWN_SPDT_CTRL);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301132
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +05301133 if (!(mci->config & ATH_MCI_CONFIG_DISABLE_OSLA))
Rajkumar Manoharan1bde95fa2012-06-11 12:19:33 +05301134 ar9003_mci_osla_setup(ah, true);
Rajkumar Manoharan7d478842012-10-15 15:29:46 +05301135
1136 if (AR_SREV_9462(ah))
1137 REG_WRITE(ah, AR_SELFGEN_MASK, 0x02);
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +05301138 } else {
Rajkumar Manoharan83bfea42012-07-01 19:53:55 +05301139 ar9003_mci_send_lna_take(ah, true);
1140 udelay(5);
Rajkumar Manoharan4ff6a9d2012-06-18 19:02:40 +05301141
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +05301142 REG_SET_BIT(ah, AR_MCI_TX_CTRL,
1143 AR_MCI_TX_CTRL_DISABLE_LNA_UPDATE);
1144 REG_SET_BIT(ah, AR_PHY_GLB_CONTROL,
1145 AR_BTCOEX_CTRL_BT_OWN_SPDT_CTRL);
Rajkumar Manoharan4f6bd1a2012-06-04 16:28:08 +05301146
Rajkumar Manoharan1bde95fa2012-06-11 12:19:33 +05301147 ar9003_mci_osla_setup(ah, false);
Rajkumar Manoharan83bfea42012-07-01 19:53:55 +05301148 ar9003_mci_send_2g5g_status(ah, true);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301149 }
1150}
1151
1152bool ar9003_mci_send_message(struct ath_hw *ah, u8 header, u32 flag,
1153 u32 *payload, u8 len, bool wait_done,
1154 bool check_bt)
1155{
1156 struct ath_common *common = ath9k_hw_common(ah);
1157 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
1158 bool msg_sent = false;
1159 u32 regval;
1160 u32 saved_mci_int_en;
1161 int i;
1162
1163 saved_mci_int_en = REG_READ(ah, AR_MCI_INTERRUPT_EN);
1164 regval = REG_READ(ah, AR_BTCOEX_CTRL);
1165
1166 if ((regval == 0xdeadbeef) || !(regval & AR_BTCOEX_CTRL_MCI_MODE_EN)) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001167 ath_dbg(common, MCI,
1168 "MCI Not sending 0x%x. MCI is not enabled. full_sleep = %d\n",
Sujith Manoharan37cd9d72012-02-22 12:42:21 +05301169 header, (ah->power_mode == ATH9K_PM_FULL_SLEEP) ? 1 : 0);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301170 ar9003_mci_queue_unsent_gpm(ah, header, payload, true);
1171 return false;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301172 } else if (check_bt && (mci->bt_state == MCI_BT_SLEEP)) {
Joe Perchesd2182b62011-12-15 14:55:53 -08001173 ath_dbg(common, MCI,
1174 "MCI Don't send message 0x%x. BT is in sleep state\n",
1175 header);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301176 ar9003_mci_queue_unsent_gpm(ah, header, payload, true);
1177 return false;
1178 }
1179
1180 if (wait_done)
1181 REG_WRITE(ah, AR_MCI_INTERRUPT_EN, 0);
1182
1183 /* Need to clear SW_MSG_DONE raw bit before wait */
1184
1185 REG_WRITE(ah, AR_MCI_INTERRUPT_RAW,
1186 (AR_MCI_INTERRUPT_SW_MSG_DONE |
1187 AR_MCI_INTERRUPT_MSG_FAIL_MASK));
1188
1189 if (payload) {
1190 for (i = 0; (i * 4) < len; i++)
1191 REG_WRITE(ah, (AR_MCI_TX_PAYLOAD0 + i * 4),
1192 *(payload + i));
1193 }
1194
1195 REG_WRITE(ah, AR_MCI_COMMAND0,
1196 (SM((flag & MCI_FLAG_DISABLE_TIMESTAMP),
1197 AR_MCI_COMMAND0_DISABLE_TIMESTAMP) |
1198 SM(len, AR_MCI_COMMAND0_LEN) |
1199 SM(header, AR_MCI_COMMAND0_HEADER)));
1200
1201 if (wait_done &&
1202 !(ar9003_mci_wait_for_interrupt(ah, AR_MCI_INTERRUPT_RAW,
Sujith Manoharan37cd9d72012-02-22 12:42:21 +05301203 AR_MCI_INTERRUPT_SW_MSG_DONE, 500)))
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301204 ar9003_mci_queue_unsent_gpm(ah, header, payload, true);
1205 else {
1206 ar9003_mci_queue_unsent_gpm(ah, header, payload, false);
1207 msg_sent = true;
1208 }
1209
1210 if (wait_done)
1211 REG_WRITE(ah, AR_MCI_INTERRUPT_EN, saved_mci_int_en);
1212
1213 return msg_sent;
1214}
1215EXPORT_SYMBOL(ar9003_mci_send_message);
1216
Sujith Manoharanf2f408e2012-02-22 12:41:06 +05301217void ar9003_mci_init_cal_req(struct ath_hw *ah, bool *is_reusable)
1218{
1219 struct ath_common *common = ath9k_hw_common(ah);
1220 struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
1221 u32 pld[4] = {0, 0, 0, 0};
1222
1223 if ((mci_hw->bt_state != MCI_BT_AWAKE) ||
1224 (mci_hw->config & ATH_MCI_CONFIG_DISABLE_MCI_CAL))
1225 return;
1226
Sujith Manoharanf2f408e2012-02-22 12:41:06 +05301227 MCI_GPM_SET_CAL_TYPE(pld, MCI_GPM_WLAN_CAL_REQ);
1228 pld[MCI_GPM_WLAN_CAL_W_SEQUENCE] = mci_hw->wlan_cal_seq++;
1229
1230 ar9003_mci_send_message(ah, MCI_GPM, 0, pld, 16, true, false);
1231
Sujith Manoharanf2f408e2012-02-22 12:41:06 +05301232 if (ar9003_mci_wait_for_gpm(ah, MCI_GPM_BT_CAL_GRANT, 0, 50000)) {
Sujith Manoharan37cd9d72012-02-22 12:42:21 +05301233 ath_dbg(common, MCI, "MCI BT_CAL_GRANT received\n");
Sujith Manoharanf2f408e2012-02-22 12:41:06 +05301234 } else {
Sujith Manoharan2fd5d352012-06-04 16:27:47 +05301235 *is_reusable = false;
Sujith Manoharan37cd9d72012-02-22 12:42:21 +05301236 ath_dbg(common, MCI, "MCI BT_CAL_GRANT not received\n");
Sujith Manoharanf2f408e2012-02-22 12:41:06 +05301237 }
1238}
1239
1240void ar9003_mci_init_cal_done(struct ath_hw *ah)
1241{
Sujith Manoharanf2f408e2012-02-22 12:41:06 +05301242 struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci;
1243 u32 pld[4] = {0, 0, 0, 0};
1244
1245 if ((mci_hw->bt_state != MCI_BT_AWAKE) ||
1246 (mci_hw->config & ATH_MCI_CONFIG_DISABLE_MCI_CAL))
1247 return;
1248
Sujith Manoharanf2f408e2012-02-22 12:41:06 +05301249 MCI_GPM_SET_CAL_TYPE(pld, MCI_GPM_WLAN_CAL_DONE);
1250 pld[MCI_GPM_WLAN_CAL_W_SEQUENCE] = mci_hw->wlan_cal_done++;
1251 ar9003_mci_send_message(ah, MCI_GPM, 0, pld, 16, true, false);
1252}
1253
Sujith Manoharan69c6ac62012-09-26 07:54:43 +05301254int ar9003_mci_setup(struct ath_hw *ah, u32 gpm_addr, void *gpm_buf,
1255 u16 len, u32 sched_addr)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301256{
1257 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301258
1259 mci->gpm_addr = gpm_addr;
1260 mci->gpm_buf = gpm_buf;
1261 mci->gpm_len = len;
1262 mci->sched_addr = sched_addr;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301263
Sujith Manoharan69c6ac62012-09-26 07:54:43 +05301264 return ar9003_mci_reset(ah, true, true, true);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301265}
1266EXPORT_SYMBOL(ar9003_mci_setup);
1267
1268void ar9003_mci_cleanup(struct ath_hw *ah)
1269{
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301270 /* Turn off MCI and Jupiter mode. */
1271 REG_WRITE(ah, AR_BTCOEX_CTRL, 0x00);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301272 ar9003_mci_disable_interrupt(ah);
1273}
1274EXPORT_SYMBOL(ar9003_mci_cleanup);
1275
Rajkumar Manoharanb98ccec2012-06-12 20:18:20 +05301276u32 ar9003_mci_state(struct ath_hw *ah, u32 state_type)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301277{
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301278 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
Rajkumar Manoharan2097fdd2012-10-15 15:29:50 +05301279 u32 value = 0, tsf;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301280 u8 query_type;
1281
1282 switch (state_type) {
1283 case MCI_STATE_ENABLE:
1284 if (mci->ready) {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301285 value = REG_READ(ah, AR_BTCOEX_CTRL);
1286
1287 if ((value == 0xdeadbeef) || (value == 0xffffffff))
1288 value = 0;
1289 }
1290 value &= AR_BTCOEX_CTRL_MCI_MODE_EN;
1291 break;
Sujith Manoharanad1dc632015-02-16 10:50:00 +05301292 case MCI_STATE_INIT_GPM_OFFSET:
1293 value = MS(REG_READ(ah, AR_MCI_GPM_1), AR_MCI_GPM_WRITE_PTR);
1294
1295 if (value < mci->gpm_len)
1296 mci->gpm_idx = value;
1297 else
1298 mci->gpm_idx = 0;
1299 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301300 case MCI_STATE_LAST_SCHD_MSG_OFFSET:
1301 value = MS(REG_READ(ah, AR_MCI_RX_STATUS),
1302 AR_MCI_RX_LAST_SCHD_MSG_INDEX);
1303 /* Make it in bytes */
1304 value <<= 4;
1305 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301306 case MCI_STATE_REMOTE_SLEEP:
1307 value = MS(REG_READ(ah, AR_MCI_RX_STATUS),
1308 AR_MCI_RX_REMOTE_SLEEP) ?
1309 MCI_BT_SLEEP : MCI_BT_AWAKE;
1310 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301311 case MCI_STATE_SET_BT_AWAKE:
1312 mci->bt_state = MCI_BT_AWAKE;
1313 ar9003_mci_send_coex_version_query(ah, true);
1314 ar9003_mci_send_coex_wlan_channels(ah, true);
1315
Sujith Manoharan37cd9d72012-02-22 12:42:21 +05301316 if (mci->unhalt_bt_gpm)
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301317 ar9003_mci_send_coex_halt_bt_gpm(ah, false, true);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301318
Rajkumar Manoharan1bde95fa2012-06-11 12:19:33 +05301319 ar9003_mci_2g5g_switch(ah, false);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301320 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301321 case MCI_STATE_RESET_REQ_WAKE:
1322 ar9003_mci_reset_req_wakeup(ah);
1323 mci->update_2g5g = true;
1324
Sujith Manoharan0cc4cde2012-02-22 12:42:15 +05301325 if (mci->config & ATH_MCI_CONFIG_MCI_OBS_MASK) {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301326 /* Check if we still have control of the GPIOs */
1327 if ((REG_READ(ah, AR_GLB_GPIO_CONTROL) &
Sujith Manoharan37cd9d72012-02-22 12:42:21 +05301328 ATH_MCI_CONFIG_MCI_OBS_GPIO) !=
1329 ATH_MCI_CONFIG_MCI_OBS_GPIO) {
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301330 ar9003_mci_observation_set_up(ah);
1331 }
1332 }
1333 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301334 case MCI_STATE_SEND_WLAN_COEX_VERSION:
1335 ar9003_mci_send_coex_version_response(ah, true);
1336 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301337 case MCI_STATE_SEND_VERSION_QUERY:
1338 ar9003_mci_send_coex_version_query(ah, true);
1339 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301340 case MCI_STATE_SEND_STATUS_QUERY:
Sujith Manoharanc91ec462012-02-22 12:40:03 +05301341 query_type = MCI_GPM_COEX_QUERY_BT_TOPOLOGY;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301342 ar9003_mci_send_coex_bt_status_query(ah, true, query_type);
1343 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301344 case MCI_STATE_RECOVER_RX:
Rajkumar Manoharan2097fdd2012-10-15 15:29:50 +05301345 tsf = ath9k_hw_gettsf32(ah);
1346 if ((tsf - mci->last_recovery) <= MCI_RECOVERY_DUR_TSF) {
1347 ath_dbg(ath9k_hw_common(ah), MCI,
1348 "(MCI) ignore Rx recovery\n");
1349 break;
1350 }
1351 ath_dbg(ath9k_hw_common(ah), MCI, "(MCI) RECOVER RX\n");
1352 mci->last_recovery = tsf;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301353 ar9003_mci_prep_interface(ah);
1354 mci->query_bt = true;
1355 mci->need_flush_btinfo = true;
1356 ar9003_mci_send_coex_wlan_channels(ah, true);
Rajkumar Manoharan1bde95fa2012-06-11 12:19:33 +05301357 ar9003_mci_2g5g_switch(ah, false);
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301358 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301359 case MCI_STATE_NEED_FTP_STOMP:
1360 value = !(mci->config & ATH_MCI_CONFIG_DISABLE_FTP_STOMP);
1361 break;
Rajkumar Manoharand92bb982012-09-12 18:59:21 +05301362 case MCI_STATE_NEED_FLUSH_BT_INFO:
1363 value = (!mci->unhalt_bt_gpm && mci->need_flush_btinfo) ? 1 : 0;
1364 mci->need_flush_btinfo = false;
1365 break;
Sujith Manoharan958b6822015-03-14 11:27:54 +05301366 case MCI_STATE_AIC_CAL_RESET:
1367 if (ath9k_hw_is_aic_enabled(ah))
1368 value = ar9003_aic_cal_reset(ah);
1369 break;
Sujith Manoharanb6ab9ae2015-03-14 11:27:50 +05301370 case MCI_STATE_AIC_CAL_SINGLE:
Sujith Manoharan208837e2015-03-14 11:27:53 +05301371 if (ath9k_hw_is_aic_enabled(ah))
1372 value = ar9003_aic_calibration_single(ah);
Sujith Manoharanb6ab9ae2015-03-14 11:27:50 +05301373 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301374 default:
1375 break;
Mohammed Shafi Shajakhanbbefb872011-11-30 10:41:17 +05301376 }
1377
1378 return value;
1379}
1380EXPORT_SYMBOL(ar9003_mci_state);
Rajkumar Manoharan99922a42012-06-04 16:28:31 +05301381
1382void ar9003_mci_bt_gain_ctrl(struct ath_hw *ah)
1383{
1384 struct ath_common *common = ath9k_hw_common(ah);
1385 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
1386
1387 ath_dbg(common, MCI, "Give LNA and SPDT control to BT\n");
1388
Rajkumar Manoharan4ff6a9d2012-06-18 19:02:40 +05301389 ar9003_mci_send_lna_take(ah, true);
1390 udelay(50);
1391
Rajkumar Manoharan99922a42012-06-04 16:28:31 +05301392 REG_SET_BIT(ah, AR_PHY_GLB_CONTROL, AR_BTCOEX_CTRL_BT_OWN_SPDT_CTRL);
1393 mci->is_2g = false;
1394 mci->update_2g5g = true;
1395 ar9003_mci_send_2g5g_status(ah, true);
1396
1397 /* Force another 2g5g update at next scanning */
1398 mci->update_2g5g = true;
1399}
Rajkumar Manoharan9dd9b0d2012-06-11 12:19:31 +05301400
1401void ar9003_mci_set_power_awake(struct ath_hw *ah)
1402{
1403 u32 btcoex_ctrl2, diag_sw;
1404 int i;
1405 u8 lna_ctrl, bt_sleep;
1406
1407 for (i = 0; i < AH_WAIT_TIMEOUT; i++) {
1408 btcoex_ctrl2 = REG_READ(ah, AR_BTCOEX_CTRL2);
1409 if (btcoex_ctrl2 != 0xdeadbeef)
1410 break;
1411 udelay(AH_TIME_QUANTUM);
1412 }
1413 REG_WRITE(ah, AR_BTCOEX_CTRL2, (btcoex_ctrl2 | BIT(23)));
1414
1415 for (i = 0; i < AH_WAIT_TIMEOUT; i++) {
1416 diag_sw = REG_READ(ah, AR_DIAG_SW);
1417 if (diag_sw != 0xdeadbeef)
1418 break;
1419 udelay(AH_TIME_QUANTUM);
1420 }
1421 REG_WRITE(ah, AR_DIAG_SW, (diag_sw | BIT(27) | BIT(19) | BIT(18)));
1422 lna_ctrl = REG_READ(ah, AR_OBS_BUS_CTRL) & 0x3;
Rajkumar Manoharana50d1fd2012-09-24 14:04:24 +05301423 bt_sleep = MS(REG_READ(ah, AR_MCI_RX_STATUS), AR_MCI_RX_REMOTE_SLEEP);
Rajkumar Manoharan9dd9b0d2012-06-11 12:19:31 +05301424
1425 REG_WRITE(ah, AR_BTCOEX_CTRL2, btcoex_ctrl2);
1426 REG_WRITE(ah, AR_DIAG_SW, diag_sw);
1427
1428 if (bt_sleep && (lna_ctrl == 2)) {
1429 REG_SET_BIT(ah, AR_BTCOEX_RC, 0x1);
1430 REG_CLR_BIT(ah, AR_BTCOEX_RC, 0x1);
1431 udelay(50);
1432 }
1433}
Rajkumar Manoharan506847a2012-06-12 20:18:16 +05301434
1435void ar9003_mci_check_gpm_offset(struct ath_hw *ah)
1436{
1437 struct ath_common *common = ath9k_hw_common(ah);
1438 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
1439 u32 offset;
1440
1441 /*
1442 * This should only be called before "MAC Warm Reset" or "MCI Reset Rx".
1443 */
1444 offset = MS(REG_READ(ah, AR_MCI_GPM_1), AR_MCI_GPM_WRITE_PTR);
1445 if (mci->gpm_idx == offset)
1446 return;
1447 ath_dbg(common, MCI, "GPM cached write pointer mismatch %d %d\n",
1448 mci->gpm_idx, offset);
1449 mci->query_bt = true;
1450 mci->need_flush_btinfo = true;
1451 mci->gpm_idx = 0;
1452}
1453
Sujith Manoharanad1dc632015-02-16 10:50:00 +05301454u32 ar9003_mci_get_next_gpm_offset(struct ath_hw *ah, u32 *more)
Rajkumar Manoharan506847a2012-06-12 20:18:16 +05301455{
1456 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
1457 u32 offset, more_gpm = 0, gpm_ptr;
1458
Rajkumar Manoharan506847a2012-06-12 20:18:16 +05301459 /*
1460 * This could be useful to avoid new GPM message interrupt which
1461 * may lead to spurious interrupt after power sleep, or multiple
1462 * entry of ath_mci_intr().
1463 * Adding empty GPM check by returning HAL_MCI_GPM_INVALID can
1464 * alleviate this effect, but clearing GPM RX interrupt bit is
1465 * safe, because whether this is called from hw or driver code
1466 * there must be an interrupt bit set/triggered initially
1467 */
1468 REG_WRITE(ah, AR_MCI_INTERRUPT_RX_MSG_RAW,
1469 AR_MCI_INTERRUPT_RX_MSG_GPM);
1470
1471 gpm_ptr = MS(REG_READ(ah, AR_MCI_GPM_1), AR_MCI_GPM_WRITE_PTR);
1472 offset = gpm_ptr;
1473
1474 if (!offset)
1475 offset = mci->gpm_len - 1;
1476 else if (offset >= mci->gpm_len) {
1477 if (offset != 0xFFFF)
1478 offset = 0;
1479 } else {
1480 offset--;
1481 }
1482
1483 if ((offset == 0xFFFF) || (gpm_ptr == mci->gpm_idx)) {
1484 offset = MCI_GPM_INVALID;
1485 more_gpm = MCI_GPM_NOMORE;
1486 goto out;
1487 }
1488 for (;;) {
1489 u32 temp_index;
1490
1491 /* skip reserved GPM if any */
1492
1493 if (offset != mci->gpm_idx)
1494 more_gpm = MCI_GPM_MORE;
1495 else
1496 more_gpm = MCI_GPM_NOMORE;
1497
1498 temp_index = mci->gpm_idx;
Mohammed Shafi Shajakhan90be9942012-09-04 19:33:32 +05301499
1500 if (temp_index >= mci->gpm_len)
1501 temp_index = 0;
1502
Rajkumar Manoharan506847a2012-06-12 20:18:16 +05301503 mci->gpm_idx++;
1504
1505 if (mci->gpm_idx >= mci->gpm_len)
1506 mci->gpm_idx = 0;
1507
1508 if (ar9003_mci_is_gpm_valid(ah, temp_index)) {
1509 offset = temp_index;
1510 break;
1511 }
1512
1513 if (more_gpm == MCI_GPM_NOMORE) {
1514 offset = MCI_GPM_INVALID;
1515 break;
1516 }
1517 }
1518
1519 if (offset != MCI_GPM_INVALID)
1520 offset <<= 4;
1521out:
1522 if (more)
1523 *more = more_gpm;
1524
1525 return offset;
1526}
1527EXPORT_SYMBOL(ar9003_mci_get_next_gpm_offset);
Rajkumar Manoharane1763d32012-06-12 20:18:17 +05301528
1529void ar9003_mci_set_bt_version(struct ath_hw *ah, u8 major, u8 minor)
1530{
1531 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
1532
1533 mci->bt_ver_major = major;
1534 mci->bt_ver_minor = minor;
1535 mci->bt_version_known = true;
1536 ath_dbg(ath9k_hw_common(ah), MCI, "MCI BT version set: %d.%d\n",
1537 mci->bt_ver_major, mci->bt_ver_minor);
1538}
1539EXPORT_SYMBOL(ar9003_mci_set_bt_version);
Rajkumar Manoharan2d340ac2012-06-12 20:18:18 +05301540
1541void ar9003_mci_send_wlan_channels(struct ath_hw *ah)
1542{
1543 struct ath9k_hw_mci *mci = &ah->btcoex_hw.mci;
1544
1545 mci->wlan_channels_update = true;
1546 ar9003_mci_send_coex_wlan_channels(ah, true);
1547}
1548EXPORT_SYMBOL(ar9003_mci_send_wlan_channels);
Rajkumar Manoharane82cb032012-10-12 14:07:25 +05301549
1550u16 ar9003_mci_get_max_txpower(struct ath_hw *ah, u8 ctlmode)
1551{
1552 if (!ah->btcoex_hw.mci.concur_tx)
1553 goto out;
1554
1555 if (ctlmode == CTL_2GHT20)
1556 return ATH_BTCOEX_HT20_MAX_TXPOWER;
1557 else if (ctlmode == CTL_2GHT40)
1558 return ATH_BTCOEX_HT40_MAX_TXPOWER;
1559
1560out:
1561 return -1;
1562}