2 * Copyright (c) 2008 Atheros Communications Inc.
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.
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.
20 ath9k_hw_write_regs(struct ath_hw *ah, u32 modesIndex, u32 freqIndex,
23 REG_WRITE_ARRAY(&ah->iniBB_RfGain, freqIndex, regWrites);
27 ath9k_hw_set_channel(struct ath_hw *ah, struct ath9k_channel *chan)
34 struct chan_centers centers;
36 ath9k_hw_get_channel_centers(ah, chan, ¢ers);
37 freq = centers.synth_center;
42 if (((freq - 2192) % 5) == 0) {
43 channelSel = ((freq - 672) * 2 - 3040) / 10;
45 } else if (((freq - 2224) % 5) == 0) {
46 channelSel = ((freq - 704) * 2 - 3040) / 10;
49 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
50 "Invalid channel %u MHz\n", freq);
54 channelSel = (channelSel << 2) & 0xff;
55 channelSel = ath9k_hw_reverse_bits(channelSel, 8);
57 txctl = REG_READ(ah, AR_PHY_CCK_TX_CTRL);
60 REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
61 txctl | AR_PHY_CCK_TX_CTRL_JAPAN);
63 REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
64 txctl & ~AR_PHY_CCK_TX_CTRL_JAPAN);
67 } else if ((freq % 20) == 0 && freq >= 5120) {
69 ath9k_hw_reverse_bits(((freq - 4800) / 20 << 2), 8);
70 aModeRefSel = ath9k_hw_reverse_bits(1, 2);
71 } else if ((freq % 10) == 0) {
73 ath9k_hw_reverse_bits(((freq - 4800) / 10 << 1), 8);
74 if (AR_SREV_9100(ah) || AR_SREV_9160_10_OR_LATER(ah))
75 aModeRefSel = ath9k_hw_reverse_bits(2, 2);
77 aModeRefSel = ath9k_hw_reverse_bits(1, 2);
78 } else if ((freq % 5) == 0) {
79 channelSel = ath9k_hw_reverse_bits((freq - 4800) / 5, 8);
80 aModeRefSel = ath9k_hw_reverse_bits(1, 2);
82 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
83 "Invalid channel %u MHz\n", freq);
88 (channelSel << 8) | (aModeRefSel << 2) | (bModeSynth << 1) |
91 REG_WRITE(ah, AR_PHY(0x37), reg32);
94 ah->curchan_rad_index = -1;
100 ath9k_hw_ar9280_set_channel(struct ath_hw *ah,
101 struct ath9k_channel *chan)
103 u16 bMode, fracMode, aModeRefSel = 0;
104 u32 freq, ndiv, channelSel = 0, channelFrac = 0, reg32 = 0;
105 struct chan_centers centers;
108 ath9k_hw_get_channel_centers(ah, chan, ¢ers);
109 freq = centers.synth_center;
111 reg32 = REG_READ(ah, AR_PHY_SYNTH_CONTROL);
120 channelSel = (freq * 0x10000) / 15;
122 txctl = REG_READ(ah, AR_PHY_CCK_TX_CTRL);
125 REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
126 txctl | AR_PHY_CCK_TX_CTRL_JAPAN);
128 REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
129 txctl & ~AR_PHY_CCK_TX_CTRL_JAPAN);
135 switch(ah->eep_ops->get_eeprom(ah, EEP_FRAC_N_5G)) {
137 if ((freq % 20) == 0) {
139 } else if ((freq % 10) == 0) {
149 channelSel = (freq * 0x8000) / 15;
151 REG_RMW_FIELD(ah, AR_AN_SYNTH9,
152 AR_AN_SYNTH9_REFDIVA, refDivA);
157 ndiv = (freq * (refDivA >> aModeRefSel)) / 60;
158 channelSel = ndiv & 0x1ff;
159 channelFrac = (ndiv & 0xfffffe00) * 2;
160 channelSel = (channelSel << 17) | channelFrac;
166 (fracMode << 28) | (aModeRefSel << 26) | (channelSel);
168 REG_WRITE(ah, AR_PHY_SYNTH_CONTROL, reg32);
171 ah->curchan_rad_index = -1;
177 ath9k_phy_modify_rx_buffer(u32 *rfBuf, u32 reg32,
178 u32 numBits, u32 firstBit,
181 u32 tmp32, mask, arrayEntry, lastBit;
182 int32_t bitPosition, bitsLeft;
184 tmp32 = ath9k_hw_reverse_bits(reg32, numBits);
185 arrayEntry = (firstBit - 1) / 8;
186 bitPosition = (firstBit - 1) % 8;
188 while (bitsLeft > 0) {
189 lastBit = (bitPosition + bitsLeft > 8) ?
190 8 : bitPosition + bitsLeft;
191 mask = (((1 << lastBit) - 1) ^ ((1 << bitPosition) - 1)) <<
193 rfBuf[arrayEntry] &= ~mask;
194 rfBuf[arrayEntry] |= ((tmp32 << bitPosition) <<
195 (column * 8)) & mask;
196 bitsLeft -= 8 - bitPosition;
197 tmp32 = tmp32 >> (8 - bitPosition);
204 ath9k_hw_set_rf_regs(struct ath_hw *ah, struct ath9k_channel *chan,
208 u32 ob5GHz = 0, db5GHz = 0;
209 u32 ob2GHz = 0, db2GHz = 0;
212 if (AR_SREV_9280_10_OR_LATER(ah))
215 eepMinorRev = ah->eep_ops->get_eeprom(ah, EEP_MINOR_REV);
217 RF_BANK_SETUP(ah->analogBank0Data, &ah->iniBank0, 1);
219 RF_BANK_SETUP(ah->analogBank1Data, &ah->iniBank1, 1);
221 RF_BANK_SETUP(ah->analogBank2Data, &ah->iniBank2, 1);
223 RF_BANK_SETUP(ah->analogBank3Data, &ah->iniBank3,
227 for (i = 0; i < ah->iniBank6TPC.ia_rows; i++) {
228 ah->analogBank6Data[i] =
229 INI_RA(&ah->iniBank6TPC, i, modesIndex);
233 if (eepMinorRev >= 2) {
234 if (IS_CHAN_2GHZ(chan)) {
235 ob2GHz = ah->eep_ops->get_eeprom(ah, EEP_OB_2);
236 db2GHz = ah->eep_ops->get_eeprom(ah, EEP_DB_2);
237 ath9k_phy_modify_rx_buffer(ah->analogBank6Data,
239 ath9k_phy_modify_rx_buffer(ah->analogBank6Data,
242 ob5GHz = ah->eep_ops->get_eeprom(ah, EEP_OB_5);
243 db5GHz = ah->eep_ops->get_eeprom(ah, EEP_DB_5);
244 ath9k_phy_modify_rx_buffer(ah->analogBank6Data,
246 ath9k_phy_modify_rx_buffer(ah->analogBank6Data,
251 RF_BANK_SETUP(ah->analogBank7Data, &ah->iniBank7, 1);
253 REG_WRITE_RF_ARRAY(&ah->iniBank0, ah->analogBank0Data,
255 REG_WRITE_RF_ARRAY(&ah->iniBank1, ah->analogBank1Data,
257 REG_WRITE_RF_ARRAY(&ah->iniBank2, ah->analogBank2Data,
259 REG_WRITE_RF_ARRAY(&ah->iniBank3, ah->analogBank3Data,
261 REG_WRITE_RF_ARRAY(&ah->iniBank6TPC, ah->analogBank6Data,
263 REG_WRITE_RF_ARRAY(&ah->iniBank7, ah->analogBank7Data,
270 ath9k_hw_rfdetach(struct ath_hw *ah)
272 if (ah->analogBank0Data != NULL) {
273 kfree(ah->analogBank0Data);
274 ah->analogBank0Data = NULL;
276 if (ah->analogBank1Data != NULL) {
277 kfree(ah->analogBank1Data);
278 ah->analogBank1Data = NULL;
280 if (ah->analogBank2Data != NULL) {
281 kfree(ah->analogBank2Data);
282 ah->analogBank2Data = NULL;
284 if (ah->analogBank3Data != NULL) {
285 kfree(ah->analogBank3Data);
286 ah->analogBank3Data = NULL;
288 if (ah->analogBank6Data != NULL) {
289 kfree(ah->analogBank6Data);
290 ah->analogBank6Data = NULL;
292 if (ah->analogBank6TPCData != NULL) {
293 kfree(ah->analogBank6TPCData);
294 ah->analogBank6TPCData = NULL;
296 if (ah->analogBank7Data != NULL) {
297 kfree(ah->analogBank7Data);
298 ah->analogBank7Data = NULL;
300 if (ah->addac5416_21 != NULL) {
301 kfree(ah->addac5416_21);
302 ah->addac5416_21 = NULL;
304 if (ah->bank6Temp != NULL) {
305 kfree(ah->bank6Temp);
306 ah->bank6Temp = NULL;
310 bool ath9k_hw_init_rf(struct ath_hw *ah, int *status)
312 if (!AR_SREV_9280_10_OR_LATER(ah)) {
313 ah->analogBank0Data =
314 kzalloc((sizeof(u32) *
315 ah->iniBank0.ia_rows), GFP_KERNEL);
316 ah->analogBank1Data =
317 kzalloc((sizeof(u32) *
318 ah->iniBank1.ia_rows), GFP_KERNEL);
319 ah->analogBank2Data =
320 kzalloc((sizeof(u32) *
321 ah->iniBank2.ia_rows), GFP_KERNEL);
322 ah->analogBank3Data =
323 kzalloc((sizeof(u32) *
324 ah->iniBank3.ia_rows), GFP_KERNEL);
325 ah->analogBank6Data =
326 kzalloc((sizeof(u32) *
327 ah->iniBank6.ia_rows), GFP_KERNEL);
328 ah->analogBank6TPCData =
329 kzalloc((sizeof(u32) *
330 ah->iniBank6TPC.ia_rows), GFP_KERNEL);
331 ah->analogBank7Data =
332 kzalloc((sizeof(u32) *
333 ah->iniBank7.ia_rows), GFP_KERNEL);
335 if (ah->analogBank0Data == NULL
336 || ah->analogBank1Data == NULL
337 || ah->analogBank2Data == NULL
338 || ah->analogBank3Data == NULL
339 || ah->analogBank6Data == NULL
340 || ah->analogBank6TPCData == NULL
341 || ah->analogBank7Data == NULL) {
342 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
343 "Cannot allocate RF banks\n");
349 kzalloc((sizeof(u32) *
350 ah->iniAddac.ia_rows *
351 ah->iniAddac.ia_columns), GFP_KERNEL);
352 if (ah->addac5416_21 == NULL) {
353 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
354 "Cannot allocate addac5416_21\n");
360 kzalloc((sizeof(u32) *
361 ah->iniBank6.ia_rows), GFP_KERNEL);
362 if (ah->bank6Temp == NULL) {
363 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
364 "Cannot allocate bank6Temp\n");
374 ath9k_hw_decrease_chain_power(struct ath_hw *ah, struct ath9k_channel *chan)
376 int i, regWrites = 0;
378 u32 *bank6Temp = ah->bank6Temp;
380 switch (ah->diversity_control) {
381 case ATH9K_ANT_FIXED_A:
384 antenna_switch_swap & ANTSWAP_AB) ? REDUCE_CHAIN_0 :
387 case ATH9K_ANT_FIXED_B:
390 antenna_switch_swap & ANTSWAP_AB) ? REDUCE_CHAIN_1 :
393 case ATH9K_ANT_VARIABLE:
401 for (i = 0; i < ah->iniBank6.ia_rows; i++)
402 bank6Temp[i] = ah->analogBank6Data[i];
404 REG_WRITE(ah, AR_PHY_BASE + 0xD8, bank6SelMask);
406 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 189, 0);
407 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 190, 0);
408 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 191, 0);
409 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 192, 0);
410 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 193, 0);
411 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 222, 0);
412 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 245, 0);
413 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 246, 0);
414 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 247, 0);
416 REG_WRITE_RF_ARRAY(&ah->iniBank6, bank6Temp, regWrites);
418 REG_WRITE(ah, AR_PHY_BASE + 0xD8, 0x00000053);
420 REG_WRITE(ah, PHY_SWITCH_CHAIN_0,
421 (REG_READ(ah, PHY_SWITCH_CHAIN_0) & ~0x38)
422 | ((REG_READ(ah, PHY_SWITCH_CHAIN_0) >> 3) & 0x38));