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.
23 ath9k_hw_write_regs(struct ath_hal *ah, u32 modesIndex, u32 freqIndex,
26 struct ath_hal_5416 *ahp = AH5416(ah);
28 REG_WRITE_ARRAY(&ahp->ah_iniBB_RfGain, freqIndex, regWrites);
32 ath9k_hw_set_channel(struct ath_hal *ah, struct ath9k_channel *chan)
39 struct chan_centers centers;
41 ath9k_hw_get_channel_centers(ah, chan, ¢ers);
42 freq = centers.synth_center;
47 if (((freq - 2192) % 5) == 0) {
48 channelSel = ((freq - 672) * 2 - 3040) / 10;
50 } else if (((freq - 2224) % 5) == 0) {
51 channelSel = ((freq - 704) * 2 - 3040) / 10;
54 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
55 "Invalid channel %u MHz\n", freq);
59 channelSel = (channelSel << 2) & 0xff;
60 channelSel = ath9k_hw_reverse_bits(channelSel, 8);
62 txctl = REG_READ(ah, AR_PHY_CCK_TX_CTRL);
65 REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
66 txctl | AR_PHY_CCK_TX_CTRL_JAPAN);
68 REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
69 txctl & ~AR_PHY_CCK_TX_CTRL_JAPAN);
72 } else if ((freq % 20) == 0 && freq >= 5120) {
74 ath9k_hw_reverse_bits(((freq - 4800) / 20 << 2), 8);
75 aModeRefSel = ath9k_hw_reverse_bits(1, 2);
76 } else if ((freq % 10) == 0) {
78 ath9k_hw_reverse_bits(((freq - 4800) / 10 << 1), 8);
79 if (AR_SREV_9100(ah) || AR_SREV_9160_10_OR_LATER(ah))
80 aModeRefSel = ath9k_hw_reverse_bits(2, 2);
82 aModeRefSel = ath9k_hw_reverse_bits(1, 2);
83 } else if ((freq % 5) == 0) {
84 channelSel = ath9k_hw_reverse_bits((freq - 4800) / 5, 8);
85 aModeRefSel = ath9k_hw_reverse_bits(1, 2);
87 DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
88 "Invalid channel %u MHz\n", freq);
93 (channelSel << 8) | (aModeRefSel << 2) | (bModeSynth << 1) |
96 REG_WRITE(ah, AR_PHY(0x37), reg32);
98 ah->ah_curchan = chan;
100 AH5416(ah)->ah_curchanRadIndex = -1;
106 ath9k_hw_ar9280_set_channel(struct ath_hal *ah,
107 struct ath9k_channel *chan)
109 u16 bMode, fracMode, aModeRefSel = 0;
110 u32 freq, ndiv, channelSel = 0, channelFrac = 0, reg32 = 0;
111 struct chan_centers centers;
114 ath9k_hw_get_channel_centers(ah, chan, ¢ers);
115 freq = centers.synth_center;
117 reg32 = REG_READ(ah, AR_PHY_SYNTH_CONTROL);
126 channelSel = (freq * 0x10000) / 15;
128 txctl = REG_READ(ah, AR_PHY_CCK_TX_CTRL);
131 REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
132 txctl | AR_PHY_CCK_TX_CTRL_JAPAN);
134 REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
135 txctl & ~AR_PHY_CCK_TX_CTRL_JAPAN);
141 if ((freq % 20) == 0) {
143 } else if ((freq % 10) == 0) {
150 channelSel = (freq * 0x8000) / 15;
152 REG_RMW_FIELD(ah, AR_AN_SYNTH9,
153 AR_AN_SYNTH9_REFDIVA, refDivA);
156 ndiv = (freq * (refDivA >> aModeRefSel)) / 60;
157 channelSel = ndiv & 0x1ff;
158 channelFrac = (ndiv & 0xfffffe00) * 2;
159 channelSel = (channelSel << 17) | channelFrac;
165 (fracMode << 28) | (aModeRefSel << 26) | (channelSel);
167 REG_WRITE(ah, AR_PHY_SYNTH_CONTROL, reg32);
169 ah->ah_curchan = chan;
171 AH5416(ah)->ah_curchanRadIndex = -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_hal *ah, struct ath9k_channel *chan,
207 struct ath_hal_5416 *ahp = AH5416(ah);
210 u32 ob5GHz = 0, db5GHz = 0;
211 u32 ob2GHz = 0, db2GHz = 0;
214 if (AR_SREV_9280_10_OR_LATER(ah))
217 eepMinorRev = ath9k_hw_get_eeprom(ah, EEP_MINOR_REV);
219 RF_BANK_SETUP(ahp->ah_analogBank0Data, &ahp->ah_iniBank0, 1);
221 RF_BANK_SETUP(ahp->ah_analogBank1Data, &ahp->ah_iniBank1, 1);
223 RF_BANK_SETUP(ahp->ah_analogBank2Data, &ahp->ah_iniBank2, 1);
225 RF_BANK_SETUP(ahp->ah_analogBank3Data, &ahp->ah_iniBank3,
229 for (i = 0; i < ahp->ah_iniBank6TPC.ia_rows; i++) {
230 ahp->ah_analogBank6Data[i] =
231 INI_RA(&ahp->ah_iniBank6TPC, i, modesIndex);
235 if (eepMinorRev >= 2) {
236 if (IS_CHAN_2GHZ(chan)) {
237 ob2GHz = ath9k_hw_get_eeprom(ah, EEP_OB_2);
238 db2GHz = ath9k_hw_get_eeprom(ah, EEP_DB_2);
239 ath9k_phy_modify_rx_buffer(ahp->ah_analogBank6Data,
241 ath9k_phy_modify_rx_buffer(ahp->ah_analogBank6Data,
244 ob5GHz = ath9k_hw_get_eeprom(ah, EEP_OB_5);
245 db5GHz = ath9k_hw_get_eeprom(ah, EEP_DB_5);
246 ath9k_phy_modify_rx_buffer(ahp->ah_analogBank6Data,
248 ath9k_phy_modify_rx_buffer(ahp->ah_analogBank6Data,
253 RF_BANK_SETUP(ahp->ah_analogBank7Data, &ahp->ah_iniBank7, 1);
255 REG_WRITE_RF_ARRAY(&ahp->ah_iniBank0, ahp->ah_analogBank0Data,
257 REG_WRITE_RF_ARRAY(&ahp->ah_iniBank1, ahp->ah_analogBank1Data,
259 REG_WRITE_RF_ARRAY(&ahp->ah_iniBank2, ahp->ah_analogBank2Data,
261 REG_WRITE_RF_ARRAY(&ahp->ah_iniBank3, ahp->ah_analogBank3Data,
263 REG_WRITE_RF_ARRAY(&ahp->ah_iniBank6TPC, ahp->ah_analogBank6Data,
265 REG_WRITE_RF_ARRAY(&ahp->ah_iniBank7, ahp->ah_analogBank7Data,
272 ath9k_hw_rfdetach(struct ath_hal *ah)
274 struct ath_hal_5416 *ahp = AH5416(ah);
276 if (ahp->ah_analogBank0Data != NULL) {
277 kfree(ahp->ah_analogBank0Data);
278 ahp->ah_analogBank0Data = NULL;
280 if (ahp->ah_analogBank1Data != NULL) {
281 kfree(ahp->ah_analogBank1Data);
282 ahp->ah_analogBank1Data = NULL;
284 if (ahp->ah_analogBank2Data != NULL) {
285 kfree(ahp->ah_analogBank2Data);
286 ahp->ah_analogBank2Data = NULL;
288 if (ahp->ah_analogBank3Data != NULL) {
289 kfree(ahp->ah_analogBank3Data);
290 ahp->ah_analogBank3Data = NULL;
292 if (ahp->ah_analogBank6Data != NULL) {
293 kfree(ahp->ah_analogBank6Data);
294 ahp->ah_analogBank6Data = NULL;
296 if (ahp->ah_analogBank6TPCData != NULL) {
297 kfree(ahp->ah_analogBank6TPCData);
298 ahp->ah_analogBank6TPCData = NULL;
300 if (ahp->ah_analogBank7Data != NULL) {
301 kfree(ahp->ah_analogBank7Data);
302 ahp->ah_analogBank7Data = NULL;
304 if (ahp->ah_addac5416_21 != NULL) {
305 kfree(ahp->ah_addac5416_21);
306 ahp->ah_addac5416_21 = NULL;
308 if (ahp->ah_bank6Temp != NULL) {
309 kfree(ahp->ah_bank6Temp);
310 ahp->ah_bank6Temp = NULL;
314 bool ath9k_hw_init_rf(struct ath_hal *ah, int *status)
316 struct ath_hal_5416 *ahp = AH5416(ah);
318 if (!AR_SREV_9280_10_OR_LATER(ah)) {
320 ahp->ah_analogBank0Data =
321 kzalloc((sizeof(u32) *
322 ahp->ah_iniBank0.ia_rows), GFP_KERNEL);
323 ahp->ah_analogBank1Data =
324 kzalloc((sizeof(u32) *
325 ahp->ah_iniBank1.ia_rows), GFP_KERNEL);
326 ahp->ah_analogBank2Data =
327 kzalloc((sizeof(u32) *
328 ahp->ah_iniBank2.ia_rows), GFP_KERNEL);
329 ahp->ah_analogBank3Data =
330 kzalloc((sizeof(u32) *
331 ahp->ah_iniBank3.ia_rows), GFP_KERNEL);
332 ahp->ah_analogBank6Data =
333 kzalloc((sizeof(u32) *
334 ahp->ah_iniBank6.ia_rows), GFP_KERNEL);
335 ahp->ah_analogBank6TPCData =
336 kzalloc((sizeof(u32) *
337 ahp->ah_iniBank6TPC.ia_rows), GFP_KERNEL);
338 ahp->ah_analogBank7Data =
339 kzalloc((sizeof(u32) *
340 ahp->ah_iniBank7.ia_rows), GFP_KERNEL);
342 if (ahp->ah_analogBank0Data == NULL
343 || ahp->ah_analogBank1Data == NULL
344 || ahp->ah_analogBank2Data == NULL
345 || ahp->ah_analogBank3Data == NULL
346 || ahp->ah_analogBank6Data == NULL
347 || ahp->ah_analogBank6TPCData == NULL
348 || ahp->ah_analogBank7Data == NULL) {
349 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
350 "Cannot allocate RF banks\n");
355 ahp->ah_addac5416_21 =
356 kzalloc((sizeof(u32) *
357 ahp->ah_iniAddac.ia_rows *
358 ahp->ah_iniAddac.ia_columns), GFP_KERNEL);
359 if (ahp->ah_addac5416_21 == NULL) {
360 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
361 "Cannot allocate ah_addac5416_21\n");
367 kzalloc((sizeof(u32) *
368 ahp->ah_iniBank6.ia_rows), GFP_KERNEL);
369 if (ahp->ah_bank6Temp == NULL) {
370 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
371 "Cannot allocate ah_bank6Temp\n");
381 ath9k_hw_decrease_chain_power(struct ath_hal *ah, struct ath9k_channel *chan)
383 int i, regWrites = 0;
384 struct ath_hal_5416 *ahp = AH5416(ah);
386 u32 *bank6Temp = ahp->ah_bank6Temp;
388 switch (ahp->ah_diversityControl) {
389 case ATH9K_ANT_FIXED_A:
392 ah_antennaSwitchSwap & ANTSWAP_AB) ? REDUCE_CHAIN_0 :
395 case ATH9K_ANT_FIXED_B:
398 ah_antennaSwitchSwap & ANTSWAP_AB) ? REDUCE_CHAIN_1 :
401 case ATH9K_ANT_VARIABLE:
409 for (i = 0; i < ahp->ah_iniBank6.ia_rows; i++)
410 bank6Temp[i] = ahp->ah_analogBank6Data[i];
412 REG_WRITE(ah, AR_PHY_BASE + 0xD8, bank6SelMask);
414 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 189, 0);
415 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 190, 0);
416 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 191, 0);
417 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 192, 0);
418 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 193, 0);
419 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 222, 0);
420 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 245, 0);
421 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 246, 0);
422 ath9k_phy_modify_rx_buffer(bank6Temp, 1, 1, 247, 0);
424 REG_WRITE_RF_ARRAY(&ahp->ah_iniBank6, bank6Temp, regWrites);
426 REG_WRITE(ah, AR_PHY_BASE + 0xD8, 0x00000053);
428 REG_WRITE(ah, PHY_SWITCH_CHAIN_0,
429 (REG_READ(ah, PHY_SWITCH_CHAIN_0) & ~0x38)
430 | ((REG_READ(ah, PHY_SWITCH_CHAIN_0) >> 3) & 0x38));