Commit | Line | Data |
---|---|---|
637625f2 SM |
1 | /* |
2 | * Copyright (c) 2015 Qualcomm Atheros 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 "hw.h" | |
18 | #include "hw-ops.h" | |
19 | #include "ar9003_mci.h" | |
20 | #include "ar9003_aic.h" | |
6dacafea | 21 | #include "reg_aic.h" |
637625f2 SM |
22 | |
23 | static bool ar9003_hw_is_aic_enabled(struct ath_hw *ah) | |
24 | { | |
25 | struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci; | |
26 | ||
27 | if (mci_hw->config & ATH_MCI_CONFIG_DISABLE_AIC) | |
28 | return false; | |
29 | ||
30 | return true; | |
31 | } | |
32 | ||
b6ab9ae2 SM |
33 | static void ar9003_aic_gain_table(struct ath_hw *ah) |
34 | { | |
35 | u32 aic_atten_word[19], i; | |
36 | ||
37 | /* Config LNA gain difference */ | |
38 | REG_WRITE(ah, AR_PHY_BT_COEX_4, 0x2c200a00); | |
39 | REG_WRITE(ah, AR_PHY_BT_COEX_5, 0x5c4e4438); | |
40 | ||
41 | /* Program gain table */ | |
42 | aic_atten_word[0] = (0x1 & 0xf) << 14 | (0x1f & 0x1f) << 9 | (0x0 & 0xf) << 5 | | |
43 | (0x1f & 0x1f); /* -01 dB: 4'd1, 5'd31, 00 dB: 4'd0, 5'd31 */ | |
44 | aic_atten_word[1] = (0x3 & 0xf) << 14 | (0x1f & 0x1f) << 9 | (0x2 & 0xf) << 5 | | |
45 | (0x1f & 0x1f); /* -03 dB: 4'd3, 5'd31, -02 dB: 4'd2, 5'd31 */ | |
46 | aic_atten_word[2] = (0x5 & 0xf) << 14 | (0x1f & 0x1f) << 9 | (0x4 & 0xf) << 5 | | |
47 | (0x1f & 0x1f); /* -05 dB: 4'd5, 5'd31, -04 dB: 4'd4, 5'd31 */ | |
48 | aic_atten_word[3] = (0x1 & 0xf) << 14 | (0x1e & 0x1f) << 9 | (0x0 & 0xf) << 5 | | |
49 | (0x1e & 0x1f); /* -07 dB: 4'd1, 5'd30, -06 dB: 4'd0, 5'd30 */ | |
50 | aic_atten_word[4] = (0x3 & 0xf) << 14 | (0x1e & 0x1f) << 9 | (0x2 & 0xf) << 5 | | |
51 | (0x1e & 0x1f); /* -09 dB: 4'd3, 5'd30, -08 dB: 4'd2, 5'd30 */ | |
52 | aic_atten_word[5] = (0x5 & 0xf) << 14 | (0x1e & 0x1f) << 9 | (0x4 & 0xf) << 5 | | |
53 | (0x1e & 0x1f); /* -11 dB: 4'd5, 5'd30, -10 dB: 4'd4, 5'd30 */ | |
54 | aic_atten_word[6] = (0x1 & 0xf) << 14 | (0xf & 0x1f) << 9 | (0x0 & 0xf) << 5 | | |
55 | (0xf & 0x1f); /* -13 dB: 4'd1, 5'd15, -12 dB: 4'd0, 5'd15 */ | |
56 | aic_atten_word[7] = (0x3 & 0xf) << 14 | (0xf & 0x1f) << 9 | (0x2 & 0xf) << 5 | | |
57 | (0xf & 0x1f); /* -15 dB: 4'd3, 5'd15, -14 dB: 4'd2, 5'd15 */ | |
58 | aic_atten_word[8] = (0x5 & 0xf) << 14 | (0xf & 0x1f) << 9 | (0x4 & 0xf) << 5 | | |
59 | (0xf & 0x1f); /* -17 dB: 4'd5, 5'd15, -16 dB: 4'd4, 5'd15 */ | |
60 | aic_atten_word[9] = (0x1 & 0xf) << 14 | (0x7 & 0x1f) << 9 | (0x0 & 0xf) << 5 | | |
61 | (0x7 & 0x1f); /* -19 dB: 4'd1, 5'd07, -18 dB: 4'd0, 5'd07 */ | |
62 | aic_atten_word[10] = (0x3 & 0xf) << 14 | (0x7 & 0x1f) << 9 | (0x2 & 0xf) << 5 | | |
63 | (0x7 & 0x1f); /* -21 dB: 4'd3, 5'd07, -20 dB: 4'd2, 5'd07 */ | |
64 | aic_atten_word[11] = (0x5 & 0xf) << 14 | (0x7 & 0x1f) << 9 | (0x4 & 0xf) << 5 | | |
65 | (0x7 & 0x1f); /* -23 dB: 4'd5, 5'd07, -22 dB: 4'd4, 5'd07 */ | |
66 | aic_atten_word[12] = (0x7 & 0xf) << 14 | (0x7 & 0x1f) << 9 | (0x6 & 0xf) << 5 | | |
67 | (0x7 & 0x1f); /* -25 dB: 4'd7, 5'd07, -24 dB: 4'd6, 5'd07 */ | |
68 | aic_atten_word[13] = (0x3 & 0xf) << 14 | (0x3 & 0x1f) << 9 | (0x2 & 0xf) << 5 | | |
69 | (0x3 & 0x1f); /* -27 dB: 4'd3, 5'd03, -26 dB: 4'd2, 5'd03 */ | |
70 | aic_atten_word[14] = (0x5 & 0xf) << 14 | (0x3 & 0x1f) << 9 | (0x4 & 0xf) << 5 | | |
71 | (0x3 & 0x1f); /* -29 dB: 4'd5, 5'd03, -28 dB: 4'd4, 5'd03 */ | |
72 | aic_atten_word[15] = (0x1 & 0xf) << 14 | (0x1 & 0x1f) << 9 | (0x0 & 0xf) << 5 | | |
73 | (0x1 & 0x1f); /* -31 dB: 4'd1, 5'd01, -30 dB: 4'd0, 5'd01 */ | |
74 | aic_atten_word[16] = (0x3 & 0xf) << 14 | (0x1 & 0x1f) << 9 | (0x2 & 0xf) << 5 | | |
75 | (0x1 & 0x1f); /* -33 dB: 4'd3, 5'd01, -32 dB: 4'd2, 5'd01 */ | |
76 | aic_atten_word[17] = (0x5 & 0xf) << 14 | (0x1 & 0x1f) << 9 | (0x4 & 0xf) << 5 | | |
77 | (0x1 & 0x1f); /* -35 dB: 4'd5, 5'd01, -34 dB: 4'd4, 5'd01 */ | |
78 | aic_atten_word[18] = (0x7 & 0xf) << 14 | (0x1 & 0x1f) << 9 | (0x6 & 0xf) << 5 | | |
79 | (0x1 & 0x1f); /* -37 dB: 4'd7, 5'd01, -36 dB: 4'd6, 5'd01 */ | |
80 | ||
81 | /* Write to Gain table with auto increment enabled. */ | |
82 | REG_WRITE(ah, (AR_PHY_AIC_SRAM_ADDR_B0 + 0x3000), | |
83 | (ATH_AIC_SRAM_AUTO_INCREMENT | | |
84 | ATH_AIC_SRAM_GAIN_TABLE_OFFSET)); | |
85 | ||
86 | for (i = 0; i < 19; i++) { | |
87 | REG_WRITE(ah, (AR_PHY_AIC_SRAM_DATA_B0 + 0x3000), | |
88 | aic_atten_word[i]); | |
89 | } | |
90 | } | |
91 | ||
92 | static void ar9003_aic_cal_start(struct ath_hw *ah, u8 min_valid_count) | |
93 | { | |
94 | struct ath9k_hw_aic *aic = &ah->btcoex_hw.aic; | |
95 | int i; | |
96 | ||
97 | /* Write to Gain table with auto increment enabled. */ | |
98 | REG_WRITE(ah, (AR_PHY_AIC_SRAM_ADDR_B0 + 0x3000), | |
99 | (ATH_AIC_SRAM_AUTO_INCREMENT | | |
100 | ATH_AIC_SRAM_CAL_OFFSET)); | |
101 | ||
102 | for (i = 0; i < ATH_AIC_MAX_BT_CHANNEL; i++) { | |
103 | REG_WRITE(ah, (AR_PHY_AIC_SRAM_DATA_B0 + 0x3000), 0); | |
104 | aic->aic_sram[i] = 0; | |
105 | } | |
106 | ||
107 | REG_WRITE(ah, AR_PHY_AIC_CTRL_0_B0, | |
108 | (SM(0, AR_PHY_AIC_MON_ENABLE) | | |
109 | SM(127, AR_PHY_AIC_CAL_MAX_HOP_COUNT) | | |
110 | SM(min_valid_count, AR_PHY_AIC_CAL_MIN_VALID_COUNT) | | |
111 | SM(37, AR_PHY_AIC_F_WLAN) | | |
112 | SM(1, AR_PHY_AIC_CAL_CH_VALID_RESET) | | |
113 | SM(0, AR_PHY_AIC_CAL_ENABLE) | | |
114 | SM(0x40, AR_PHY_AIC_BTTX_PWR_THR) | | |
115 | SM(0, AR_PHY_AIC_ENABLE))); | |
116 | ||
117 | REG_WRITE(ah, AR_PHY_AIC_CTRL_0_B1, | |
118 | (SM(0, AR_PHY_AIC_MON_ENABLE) | | |
119 | SM(1, AR_PHY_AIC_CAL_CH_VALID_RESET) | | |
120 | SM(0, AR_PHY_AIC_CAL_ENABLE) | | |
121 | SM(0x40, AR_PHY_AIC_BTTX_PWR_THR) | | |
122 | SM(0, AR_PHY_AIC_ENABLE))); | |
123 | ||
124 | REG_WRITE(ah, AR_PHY_AIC_CTRL_1_B0, | |
125 | (SM(8, AR_PHY_AIC_CAL_BT_REF_DELAY) | | |
126 | SM(0, AR_PHY_AIC_BT_IDLE_CFG) | | |
127 | SM(1, AR_PHY_AIC_STDBY_COND) | | |
128 | SM(37, AR_PHY_AIC_STDBY_ROT_ATT_DB) | | |
129 | SM(5, AR_PHY_AIC_STDBY_COM_ATT_DB) | | |
130 | SM(15, AR_PHY_AIC_RSSI_MAX) | | |
131 | SM(0, AR_PHY_AIC_RSSI_MIN))); | |
132 | ||
133 | REG_WRITE(ah, AR_PHY_AIC_CTRL_1_B1, | |
134 | (SM(15, AR_PHY_AIC_RSSI_MAX) | | |
135 | SM(0, AR_PHY_AIC_RSSI_MIN))); | |
136 | ||
137 | REG_WRITE(ah, AR_PHY_AIC_CTRL_2_B0, | |
138 | (SM(44, AR_PHY_AIC_RADIO_DELAY) | | |
139 | SM(8, AR_PHY_AIC_CAL_STEP_SIZE_CORR) | | |
140 | SM(12, AR_PHY_AIC_CAL_ROT_IDX_CORR) | | |
141 | SM(2, AR_PHY_AIC_CAL_CONV_CHECK_FACTOR) | | |
142 | SM(5, AR_PHY_AIC_ROT_IDX_COUNT_MAX) | | |
143 | SM(0, AR_PHY_AIC_CAL_SYNTH_TOGGLE) | | |
144 | SM(0, AR_PHY_AIC_CAL_SYNTH_AFTER_BTRX) | | |
145 | SM(200, AR_PHY_AIC_CAL_SYNTH_SETTLING))); | |
146 | ||
147 | REG_WRITE(ah, AR_PHY_AIC_CTRL_3_B0, | |
148 | (SM(2, AR_PHY_AIC_MON_MAX_HOP_COUNT) | | |
149 | SM(1, AR_PHY_AIC_MON_MIN_STALE_COUNT) | | |
150 | SM(1, AR_PHY_AIC_MON_PWR_EST_LONG) | | |
151 | SM(2, AR_PHY_AIC_MON_PD_TALLY_SCALING) | | |
152 | SM(10, AR_PHY_AIC_MON_PERF_THR) | | |
153 | SM(2, AR_PHY_AIC_CAL_TARGET_MAG_SETTING) | | |
154 | SM(1, AR_PHY_AIC_CAL_PERF_CHECK_FACTOR) | | |
155 | SM(1, AR_PHY_AIC_CAL_PWR_EST_LONG))); | |
156 | ||
157 | REG_WRITE(ah, AR_PHY_AIC_CTRL_4_B0, | |
158 | (SM(2, AR_PHY_AIC_CAL_ROT_ATT_DB_EST_ISO) | | |
159 | SM(3, AR_PHY_AIC_CAL_COM_ATT_DB_EST_ISO) | | |
160 | SM(0, AR_PHY_AIC_CAL_ISO_EST_INIT_SETTING) | | |
161 | SM(2, AR_PHY_AIC_CAL_COM_ATT_DB_BACKOFF) | | |
162 | SM(1, AR_PHY_AIC_CAL_COM_ATT_DB_FIXED))); | |
163 | ||
164 | REG_WRITE(ah, AR_PHY_AIC_CTRL_4_B1, | |
165 | (SM(2, AR_PHY_AIC_CAL_ROT_ATT_DB_EST_ISO) | | |
166 | SM(3, AR_PHY_AIC_CAL_COM_ATT_DB_EST_ISO) | | |
167 | SM(0, AR_PHY_AIC_CAL_ISO_EST_INIT_SETTING) | | |
168 | SM(2, AR_PHY_AIC_CAL_COM_ATT_DB_BACKOFF) | | |
169 | SM(1, AR_PHY_AIC_CAL_COM_ATT_DB_FIXED))); | |
170 | ||
171 | ar9003_aic_gain_table(ah); | |
172 | ||
173 | /* Need to enable AIC reference signal in BT modem. */ | |
174 | REG_WRITE(ah, ATH_AIC_BT_JUPITER_CTRL, | |
175 | (REG_READ(ah, ATH_AIC_BT_JUPITER_CTRL) | | |
176 | ATH_AIC_BT_AIC_ENABLE)); | |
177 | ||
178 | aic->aic_cal_start_time = REG_READ(ah, AR_TSF_L32); | |
179 | ||
180 | /* Start calibration */ | |
181 | REG_CLR_BIT(ah, AR_PHY_AIC_CTRL_0_B1, AR_PHY_AIC_CAL_ENABLE); | |
182 | REG_SET_BIT(ah, AR_PHY_AIC_CTRL_0_B1, AR_PHY_AIC_CAL_CH_VALID_RESET); | |
183 | REG_SET_BIT(ah, AR_PHY_AIC_CTRL_0_B1, AR_PHY_AIC_CAL_ENABLE); | |
184 | ||
185 | aic->aic_caled_chan = 0; | |
186 | aic->aic_cal_state = AIC_CAL_STATE_STARTED; | |
187 | } | |
188 | ||
716eed4c SM |
189 | static void ar9003_aic_cal_done(struct ath_hw *ah) |
190 | { | |
191 | /* Disable AIC reference signal in BT modem. */ | |
192 | REG_WRITE(ah, ATH_AIC_BT_JUPITER_CTRL, | |
193 | (REG_READ(ah, ATH_AIC_BT_JUPITER_CTRL) & | |
194 | ~ATH_AIC_BT_AIC_ENABLE)); | |
195 | } | |
196 | ||
197 | static u8 ar9003_aic_cal_continue(struct ath_hw *ah, bool cal_once) | |
198 | { | |
199 | struct ath_common *common = ath9k_hw_common(ah); | |
200 | struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci; | |
201 | struct ath9k_hw_aic *aic = &ah->btcoex_hw.aic; | |
202 | int i, num_chan; | |
203 | ||
204 | num_chan = MS(mci_hw->config, ATH_MCI_CONFIG_AIC_CAL_NUM_CHAN); | |
205 | ||
206 | if (!num_chan) { | |
207 | aic->aic_cal_state = AIC_CAL_STATE_ERROR; | |
208 | return aic->aic_cal_state; | |
209 | } | |
210 | ||
211 | if (cal_once) { | |
212 | for (i = 0; i < 10000; i++) { | |
213 | if ((REG_READ(ah, AR_PHY_AIC_CTRL_0_B1) & | |
214 | AR_PHY_AIC_CAL_ENABLE) == 0) | |
215 | break; | |
216 | ||
217 | udelay(100); | |
218 | } | |
219 | } | |
220 | ||
221 | /* | |
222 | * Use AR_PHY_AIC_CAL_ENABLE bit instead of AR_PHY_AIC_CAL_DONE. | |
223 | * Sometimes CAL_DONE bit is not asserted. | |
224 | */ | |
225 | if ((REG_READ(ah, AR_PHY_AIC_CTRL_0_B1) & | |
226 | AR_PHY_AIC_CAL_ENABLE) != 0) { | |
227 | ath_dbg(common, MCI, "AIC cal is not done after 40ms"); | |
228 | goto exit; | |
229 | } | |
230 | ||
231 | REG_WRITE(ah, AR_PHY_AIC_SRAM_ADDR_B1, | |
232 | (ATH_AIC_SRAM_CAL_OFFSET | ATH_AIC_SRAM_AUTO_INCREMENT)); | |
233 | ||
234 | for (i = 0; i < ATH_AIC_MAX_BT_CHANNEL; i++) { | |
235 | u32 value; | |
236 | ||
237 | value = REG_READ(ah, AR_PHY_AIC_SRAM_DATA_B1); | |
238 | ||
239 | if (value & 0x01) { | |
240 | if (aic->aic_sram[i] == 0) | |
241 | aic->aic_caled_chan++; | |
242 | ||
243 | aic->aic_sram[i] = value; | |
244 | ||
245 | if (!cal_once) | |
246 | break; | |
247 | } | |
248 | } | |
249 | ||
250 | if ((aic->aic_caled_chan >= num_chan) || cal_once) { | |
251 | ar9003_aic_cal_done(ah); | |
252 | } else { | |
253 | /* Start calibration */ | |
254 | REG_CLR_BIT(ah, AR_PHY_AIC_CTRL_0_B1, AR_PHY_AIC_CAL_ENABLE); | |
255 | REG_SET_BIT(ah, AR_PHY_AIC_CTRL_0_B1, | |
256 | AR_PHY_AIC_CAL_CH_VALID_RESET); | |
257 | REG_SET_BIT(ah, AR_PHY_AIC_CTRL_0_B1, AR_PHY_AIC_CAL_ENABLE); | |
258 | } | |
259 | exit: | |
260 | return aic->aic_cal_state; | |
261 | ||
262 | } | |
263 | ||
b6ab9ae2 SM |
264 | u8 ar9003_aic_calibration_single(struct ath_hw *ah) |
265 | { | |
266 | struct ath9k_hw_mci *mci_hw = &ah->btcoex_hw.mci; | |
716eed4c | 267 | u8 cal_ret; |
b6ab9ae2 SM |
268 | int num_chan; |
269 | ||
270 | num_chan = MS(mci_hw->config, ATH_MCI_CONFIG_AIC_CAL_NUM_CHAN); | |
271 | ||
272 | ar9003_aic_cal_start(ah, num_chan); | |
716eed4c | 273 | cal_ret = ar9003_aic_cal_continue(ah, true); |
b6ab9ae2 SM |
274 | |
275 | return cal_ret; | |
276 | } | |
277 | ||
637625f2 SM |
278 | void ar9003_hw_attach_aic_ops(struct ath_hw *ah) |
279 | { | |
280 | struct ath_hw_private_ops *priv_ops = ath9k_hw_private_ops(ah); | |
281 | ||
282 | priv_ops->is_aic_enabled = ar9003_hw_is_aic_enabled; | |
283 | } |