blob: bc77a308c901eaf8ccd4c111f2600a754d0774b9 [file] [log] [blame]
Sujithb5aec952009-08-07 09:45:15 +05301/*
2 * Copyright (c) 2008-2009 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
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070017#include "hw.h"
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -040018#include "ar9002_phy.h"
Sujithb5aec952009-08-07 09:45:15 +053019
20static int ath9k_hw_4k_get_eeprom_ver(struct ath_hw *ah)
21{
22 return ((ah->eeprom.map4k.baseEepHeader.version >> 12) & 0xF);
23}
24
25static int ath9k_hw_4k_get_eeprom_rev(struct ath_hw *ah)
26{
27 return ((ah->eeprom.map4k.baseEepHeader.version) & 0xFFF);
28}
29
Sujithb5aec952009-08-07 09:45:15 +053030#define SIZE_EEPROM_4K (sizeof(struct ar5416_eeprom_4k) / sizeof(u16))
Sujith Manoharan04cf53f2011-01-04 13:17:28 +053031
32static bool __ath9k_hw_4k_fill_eeprom(struct ath_hw *ah)
33{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070034 struct ath_common *common = ath9k_hw_common(ah);
Sujithb5aec952009-08-07 09:45:15 +053035 u16 *eep_data = (u16 *)&ah->eeprom.map4k;
Sujith Manoharan04cf53f2011-01-04 13:17:28 +053036 int addr, eep_start_loc = 64;
Sujithb5aec952009-08-07 09:45:15 +053037
38 for (addr = 0; addr < SIZE_EEPROM_4K; addr++) {
Luis R. Rodriguez5bb12792009-09-14 00:55:09 -070039 if (!ath9k_hw_nvram_read(common, addr + eep_start_loc, eep_data)) {
Joe Perches226afe62010-12-02 19:12:37 -080040 ath_dbg(common, ATH_DBG_EEPROM,
41 "Unable to read eeprom region\n");
Sujithb5aec952009-08-07 09:45:15 +053042 return false;
43 }
44 eep_data++;
45 }
46
47 return true;
Sujithb5aec952009-08-07 09:45:15 +053048}
49
Sujith Manoharan04cf53f2011-01-04 13:17:28 +053050static bool __ath9k_hw_usb_4k_fill_eeprom(struct ath_hw *ah)
51{
52 u16 *eep_data = (u16 *)&ah->eeprom.map4k;
53
54 ath9k_hw_usb_gen_fill_eeprom(ah, eep_data, 64, SIZE_EEPROM_4K);
55
56 return true;
57}
58
59static bool ath9k_hw_4k_fill_eeprom(struct ath_hw *ah)
60{
61 struct ath_common *common = ath9k_hw_common(ah);
62
63 if (!ath9k_hw_use_flash(ah)) {
64 ath_dbg(common, ATH_DBG_EEPROM,
65 "Reading from EEPROM, not flash\n");
66 }
67
68 if (common->bus_ops->ath_bus_type == ATH_USB)
69 return __ath9k_hw_usb_4k_fill_eeprom(ah);
70 else
71 return __ath9k_hw_4k_fill_eeprom(ah);
72}
73
74#undef SIZE_EEPROM_4K
75
Sujithb5aec952009-08-07 09:45:15 +053076static int ath9k_hw_4k_check_eeprom(struct ath_hw *ah)
77{
78#define EEPROM_4K_SIZE (sizeof(struct ar5416_eeprom_4k) / sizeof(u16))
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070079 struct ath_common *common = ath9k_hw_common(ah);
Sujithb5aec952009-08-07 09:45:15 +053080 struct ar5416_eeprom_4k *eep =
81 (struct ar5416_eeprom_4k *) &ah->eeprom.map4k;
82 u16 *eepdata, temp, magic, magic2;
83 u32 sum = 0, el;
84 bool need_swap = false;
85 int i, addr;
86
87
88 if (!ath9k_hw_use_flash(ah)) {
Luis R. Rodriguez5bb12792009-09-14 00:55:09 -070089 if (!ath9k_hw_nvram_read(common, AR5416_EEPROM_MAGIC_OFFSET,
Sujithb5aec952009-08-07 09:45:15 +053090 &magic)) {
Joe Perches38002762010-12-02 19:12:36 -080091 ath_err(common, "Reading Magic # failed\n");
Sujithb5aec952009-08-07 09:45:15 +053092 return false;
93 }
94
Joe Perches226afe62010-12-02 19:12:37 -080095 ath_dbg(common, ATH_DBG_EEPROM,
96 "Read Magic = 0x%04X\n", magic);
Sujithb5aec952009-08-07 09:45:15 +053097
98 if (magic != AR5416_EEPROM_MAGIC) {
99 magic2 = swab16(magic);
100
101 if (magic2 == AR5416_EEPROM_MAGIC) {
102 need_swap = true;
103 eepdata = (u16 *) (&ah->eeprom);
104
105 for (addr = 0; addr < EEPROM_4K_SIZE; addr++) {
106 temp = swab16(*eepdata);
107 *eepdata = temp;
108 eepdata++;
109 }
110 } else {
Joe Perches38002762010-12-02 19:12:36 -0800111 ath_err(common,
Joe Perches226afe62010-12-02 19:12:37 -0800112 "Invalid EEPROM Magic. Endianness mismatch.\n");
Sujithb5aec952009-08-07 09:45:15 +0530113 return -EINVAL;
114 }
115 }
116 }
117
Joe Perches226afe62010-12-02 19:12:37 -0800118 ath_dbg(common, ATH_DBG_EEPROM, "need_swap = %s.\n",
119 need_swap ? "True" : "False");
Sujithb5aec952009-08-07 09:45:15 +0530120
121 if (need_swap)
122 el = swab16(ah->eeprom.map4k.baseEepHeader.length);
123 else
124 el = ah->eeprom.map4k.baseEepHeader.length;
125
126 if (el > sizeof(struct ar5416_eeprom_4k))
127 el = sizeof(struct ar5416_eeprom_4k) / sizeof(u16);
128 else
129 el = el / sizeof(u16);
130
131 eepdata = (u16 *)(&ah->eeprom);
132
133 for (i = 0; i < el; i++)
134 sum ^= *eepdata++;
135
136 if (need_swap) {
137 u32 integer;
138 u16 word;
139
Joe Perches226afe62010-12-02 19:12:37 -0800140 ath_dbg(common, ATH_DBG_EEPROM,
141 "EEPROM Endianness is not native.. Changing\n");
Sujithb5aec952009-08-07 09:45:15 +0530142
143 word = swab16(eep->baseEepHeader.length);
144 eep->baseEepHeader.length = word;
145
146 word = swab16(eep->baseEepHeader.checksum);
147 eep->baseEepHeader.checksum = word;
148
149 word = swab16(eep->baseEepHeader.version);
150 eep->baseEepHeader.version = word;
151
152 word = swab16(eep->baseEepHeader.regDmn[0]);
153 eep->baseEepHeader.regDmn[0] = word;
154
155 word = swab16(eep->baseEepHeader.regDmn[1]);
156 eep->baseEepHeader.regDmn[1] = word;
157
158 word = swab16(eep->baseEepHeader.rfSilent);
159 eep->baseEepHeader.rfSilent = word;
160
161 word = swab16(eep->baseEepHeader.blueToothOptions);
162 eep->baseEepHeader.blueToothOptions = word;
163
164 word = swab16(eep->baseEepHeader.deviceCap);
165 eep->baseEepHeader.deviceCap = word;
166
167 integer = swab32(eep->modalHeader.antCtrlCommon);
168 eep->modalHeader.antCtrlCommon = integer;
169
170 for (i = 0; i < AR5416_EEP4K_MAX_CHAINS; i++) {
171 integer = swab32(eep->modalHeader.antCtrlChain[i]);
172 eep->modalHeader.antCtrlChain[i] = integer;
173 }
174
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100175 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujithb5aec952009-08-07 09:45:15 +0530176 word = swab16(eep->modalHeader.spurChans[i].spurChan);
177 eep->modalHeader.spurChans[i].spurChan = word;
178 }
179 }
180
181 if (sum != 0xffff || ah->eep_ops->get_eeprom_ver(ah) != AR5416_EEP_VER ||
182 ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_NO_BACK_VER) {
Joe Perches38002762010-12-02 19:12:36 -0800183 ath_err(common, "Bad EEPROM checksum 0x%x or revision 0x%04x\n",
184 sum, ah->eep_ops->get_eeprom_ver(ah));
Sujithb5aec952009-08-07 09:45:15 +0530185 return -EINVAL;
186 }
187
188 return 0;
189#undef EEPROM_4K_SIZE
190}
191
192static u32 ath9k_hw_4k_get_eeprom(struct ath_hw *ah,
193 enum eeprom_param param)
194{
195 struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k;
196 struct modal_eep_4k_header *pModal = &eep->modalHeader;
197 struct base_eep_header_4k *pBase = &eep->baseEepHeader;
Gabor Juhos970bf9d2010-10-05 11:32:17 +0200198 u16 ver_minor;
199
200 ver_minor = pBase->version & AR5416_EEP_VER_MINOR_MASK;
Sujithb5aec952009-08-07 09:45:15 +0530201
202 switch (param) {
203 case EEP_NFTHRESH_2:
204 return pModal->noiseFloorThreshCh[0];
Luis R. Rodriguez49101672010-04-15 17:39:13 -0400205 case EEP_MAC_LSW:
Sujithb5aec952009-08-07 09:45:15 +0530206 return pBase->macAddr[0] << 8 | pBase->macAddr[1];
Luis R. Rodriguez49101672010-04-15 17:39:13 -0400207 case EEP_MAC_MID:
Sujithb5aec952009-08-07 09:45:15 +0530208 return pBase->macAddr[2] << 8 | pBase->macAddr[3];
Luis R. Rodriguez49101672010-04-15 17:39:13 -0400209 case EEP_MAC_MSW:
Sujithb5aec952009-08-07 09:45:15 +0530210 return pBase->macAddr[4] << 8 | pBase->macAddr[5];
211 case EEP_REG_0:
212 return pBase->regDmn[0];
213 case EEP_REG_1:
214 return pBase->regDmn[1];
215 case EEP_OP_CAP:
216 return pBase->deviceCap;
217 case EEP_OP_MODE:
218 return pBase->opCapFlags;
219 case EEP_RF_SILENT:
220 return pBase->rfSilent;
221 case EEP_OB_2:
Sujith7f638452009-08-07 09:45:23 +0530222 return pModal->ob_0;
Sujithb5aec952009-08-07 09:45:15 +0530223 case EEP_DB_2:
Sujith7f638452009-08-07 09:45:23 +0530224 return pModal->db1_1;
Sujithb5aec952009-08-07 09:45:15 +0530225 case EEP_MINOR_REV:
Gabor Juhos970bf9d2010-10-05 11:32:17 +0200226 return ver_minor;
Sujithb5aec952009-08-07 09:45:15 +0530227 case EEP_TX_MASK:
228 return pBase->txMask;
229 case EEP_RX_MASK:
230 return pBase->rxMask;
231 case EEP_FRAC_N_5G:
232 return 0;
Senthil Balasubramaniane41f0bf2009-09-18 15:08:20 +0530233 case EEP_PWR_TABLE_OFFSET:
234 return AR5416_PWR_TABLE_OFFSET_DB;
Vasanthakumar Thiagarajan754dc532010-09-02 01:34:41 -0700235 case EEP_MODAL_VER:
236 return pModal->version;
237 case EEP_ANT_DIV_CTL1:
238 return pModal->antdiv_ctl1;
Gabor Juhos970bf9d2010-10-05 11:32:17 +0200239 case EEP_TXGAIN_TYPE:
240 if (ver_minor >= AR5416_EEP_MINOR_VER_19)
241 return pBase->txGainType;
242 else
243 return AR5416_EEP_TXGAIN_ORIGINAL;
Sujithb5aec952009-08-07 09:45:15 +0530244 default:
245 return 0;
246 }
247}
248
Sujithb5aec952009-08-07 09:45:15 +0530249static void ath9k_hw_set_4k_power_cal_table(struct ath_hw *ah,
250 struct ath9k_channel *chan,
251 int16_t *pTxPowerIndexOffset)
252{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700253 struct ath_common *common = ath9k_hw_common(ah);
Sujithb5aec952009-08-07 09:45:15 +0530254 struct ar5416_eeprom_4k *pEepData = &ah->eeprom.map4k;
255 struct cal_data_per_freq_4k *pRawDataset;
256 u8 *pCalBChans = NULL;
257 u16 pdGainOverlap_t2;
258 static u8 pdadcValues[AR5416_NUM_PDADC_VALUES];
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100259 u16 gainBoundaries[AR5416_PD_GAINS_IN_MASK];
Sujithb5aec952009-08-07 09:45:15 +0530260 u16 numPiers, i, j;
Sujithb5aec952009-08-07 09:45:15 +0530261 u16 numXpdGain, xpdMask;
262 u16 xpdGainValues[AR5416_EEP4K_NUM_PD_GAINS] = { 0, 0 };
263 u32 reg32, regOffset, regChainOffset;
264
265 xpdMask = pEepData->modalHeader.xpdGain;
266
267 if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
268 AR5416_EEP_MINOR_VER_2) {
269 pdGainOverlap_t2 =
270 pEepData->modalHeader.pdGainOverlap;
271 } else {
272 pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5),
273 AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
274 }
275
276 pCalBChans = pEepData->calFreqPier2G;
277 numPiers = AR5416_EEP4K_NUM_2G_CAL_PIERS;
278
279 numXpdGain = 0;
280
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100281 for (i = 1; i <= AR5416_PD_GAINS_IN_MASK; i++) {
282 if ((xpdMask >> (AR5416_PD_GAINS_IN_MASK - i)) & 1) {
Sujithb5aec952009-08-07 09:45:15 +0530283 if (numXpdGain >= AR5416_EEP4K_NUM_PD_GAINS)
284 break;
285 xpdGainValues[numXpdGain] =
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100286 (u16)(AR5416_PD_GAINS_IN_MASK - i);
Sujithb5aec952009-08-07 09:45:15 +0530287 numXpdGain++;
288 }
289 }
290
291 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
292 (numXpdGain - 1) & 0x3);
293 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,
294 xpdGainValues[0]);
295 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
296 xpdGainValues[1]);
297 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3, 0);
298
299 for (i = 0; i < AR5416_EEP4K_MAX_CHAINS; i++) {
300 if (AR_SREV_5416_20_OR_LATER(ah) &&
301 (ah->rxchainmask == 5 || ah->txchainmask == 5) &&
302 (i != 0)) {
303 regChainOffset = (i == 1) ? 0x2000 : 0x1000;
304 } else
305 regChainOffset = i * 0x1000;
306
307 if (pEepData->baseEepHeader.txMask & (1 << i)) {
308 pRawDataset = pEepData->calPierData2G[i];
309
Felix Fietkau115277a2010-12-12 00:51:09 +0100310 ath9k_hw_get_gain_boundaries_pdadcs(ah, chan,
Sujithb5aec952009-08-07 09:45:15 +0530311 pRawDataset, pCalBChans,
312 numPiers, pdGainOverlap_t2,
Pavel Roskin6eb90d42010-07-06 12:51:27 -0400313 gainBoundaries,
Sujithb5aec952009-08-07 09:45:15 +0530314 pdadcValues, numXpdGain);
315
Sujith7d0d0df2010-04-16 11:53:57 +0530316 ENABLE_REGWRITE_BUFFER(ah);
317
Sujithb5aec952009-08-07 09:45:15 +0530318 if ((i == 0) || AR_SREV_5416_20_OR_LATER(ah)) {
319 REG_WRITE(ah, AR_PHY_TPCRG5 + regChainOffset,
320 SM(pdGainOverlap_t2,
321 AR_PHY_TPCRG5_PD_GAIN_OVERLAP)
322 | SM(gainBoundaries[0],
323 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1)
324 | SM(gainBoundaries[1],
325 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2)
326 | SM(gainBoundaries[2],
327 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3)
328 | SM(gainBoundaries[3],
329 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4));
330 }
331
332 regOffset = AR_PHY_BASE + (672 << 2) + regChainOffset;
333 for (j = 0; j < 32; j++) {
334 reg32 = ((pdadcValues[4 * j + 0] & 0xFF) << 0) |
335 ((pdadcValues[4 * j + 1] & 0xFF) << 8) |
336 ((pdadcValues[4 * j + 2] & 0xFF) << 16)|
337 ((pdadcValues[4 * j + 3] & 0xFF) << 24);
338 REG_WRITE(ah, regOffset, reg32);
339
Joe Perches226afe62010-12-02 19:12:37 -0800340 ath_dbg(common, ATH_DBG_EEPROM,
341 "PDADC (%d,%4x): %4.4x %8.8x\n",
342 i, regChainOffset, regOffset,
343 reg32);
344 ath_dbg(common, ATH_DBG_EEPROM,
345 "PDADC: Chain %d | "
346 "PDADC %3d Value %3d | "
347 "PDADC %3d Value %3d | "
348 "PDADC %3d Value %3d | "
349 "PDADC %3d Value %3d |\n",
350 i, 4 * j, pdadcValues[4 * j],
351 4 * j + 1, pdadcValues[4 * j + 1],
352 4 * j + 2, pdadcValues[4 * j + 2],
353 4 * j + 3, pdadcValues[4 * j + 3]);
Sujithb5aec952009-08-07 09:45:15 +0530354
355 regOffset += 4;
356 }
Sujith7d0d0df2010-04-16 11:53:57 +0530357
358 REGWRITE_BUFFER_FLUSH(ah);
Sujithb5aec952009-08-07 09:45:15 +0530359 }
360 }
361
362 *pTxPowerIndexOffset = 0;
363}
364
365static void ath9k_hw_set_4k_power_per_rate_table(struct ath_hw *ah,
366 struct ath9k_channel *chan,
367 int16_t *ratesArray,
368 u16 cfgCtl,
369 u16 AntennaReduction,
370 u16 twiceMaxRegulatoryPower,
371 u16 powerLimit)
372{
Sujith180d674b2009-08-07 09:45:33 +0530373#define CMP_TEST_GRP \
374 (((cfgCtl & ~CTL_MODE_M)| (pCtlMode[ctlMode] & CTL_MODE_M)) == \
375 pEepData->ctlIndex[i]) \
376 || (((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == \
377 ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL))
Sujithb5aec952009-08-07 09:45:15 +0530378
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700379 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithb5aec952009-08-07 09:45:15 +0530380 int i;
381 int16_t twiceLargestAntenna;
Sujith180d674b2009-08-07 09:45:33 +0530382 u16 twiceMinEdgePower;
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100383 u16 twiceMaxEdgePower = MAX_RATE_POWER;
Sujith180d674b2009-08-07 09:45:33 +0530384 u16 scaledPower = 0, minCtlPower, maxRegAllowedPower;
Joe Perches07b2fa52010-11-20 18:38:53 -0800385 u16 numCtlModes;
386 const u16 *pCtlMode;
387 u16 ctlMode, freq;
Sujith180d674b2009-08-07 09:45:33 +0530388 struct chan_centers centers;
Sujithb5aec952009-08-07 09:45:15 +0530389 struct cal_ctl_data_4k *rep;
Sujith180d674b2009-08-07 09:45:33 +0530390 struct ar5416_eeprom_4k *pEepData = &ah->eeprom.map4k;
391 static const u16 tpScaleReductionTable[5] =
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100392 { 0, 3, 6, 9, MAX_RATE_POWER };
Sujithb5aec952009-08-07 09:45:15 +0530393 struct cal_target_power_leg targetPowerOfdm, targetPowerCck = {
394 0, { 0, 0, 0, 0}
395 };
396 struct cal_target_power_leg targetPowerOfdmExt = {
397 0, { 0, 0, 0, 0} }, targetPowerCckExt = {
398 0, { 0, 0, 0, 0 }
399 };
400 struct cal_target_power_ht targetPowerHt20, targetPowerHt40 = {
401 0, {0, 0, 0, 0}
402 };
Joe Perches07b2fa52010-11-20 18:38:53 -0800403 static const u16 ctlModesFor11g[] = {
404 CTL_11B, CTL_11G, CTL_2GHT20,
405 CTL_11B_EXT, CTL_11G_EXT, CTL_2GHT40
406 };
Sujithb5aec952009-08-07 09:45:15 +0530407
408 ath9k_hw_get_channel_centers(ah, chan, &centers);
409
410 twiceLargestAntenna = pEepData->modalHeader.antennaGainCh[0];
Sujithb5aec952009-08-07 09:45:15 +0530411 twiceLargestAntenna = (int16_t)min(AntennaReduction -
412 twiceLargestAntenna, 0);
413
414 maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700415 if (regulatory->tp_scale != ATH9K_TP_SCALE_MAX) {
Sujithb5aec952009-08-07 09:45:15 +0530416 maxRegAllowedPower -=
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700417 (tpScaleReductionTable[(regulatory->tp_scale)] * 2);
Sujithb5aec952009-08-07 09:45:15 +0530418 }
419
420 scaledPower = min(powerLimit, maxRegAllowedPower);
421 scaledPower = max((u16)0, scaledPower);
422
423 numCtlModes = ARRAY_SIZE(ctlModesFor11g) - SUB_NUM_CTL_MODES_AT_2G_40;
424 pCtlMode = ctlModesFor11g;
425
426 ath9k_hw_get_legacy_target_powers(ah, chan,
427 pEepData->calTargetPowerCck,
428 AR5416_NUM_2G_CCK_TARGET_POWERS,
429 &targetPowerCck, 4, false);
430 ath9k_hw_get_legacy_target_powers(ah, chan,
431 pEepData->calTargetPower2G,
432 AR5416_NUM_2G_20_TARGET_POWERS,
433 &targetPowerOfdm, 4, false);
434 ath9k_hw_get_target_powers(ah, chan,
435 pEepData->calTargetPower2GHT20,
436 AR5416_NUM_2G_20_TARGET_POWERS,
437 &targetPowerHt20, 8, false);
438
439 if (IS_CHAN_HT40(chan)) {
440 numCtlModes = ARRAY_SIZE(ctlModesFor11g);
441 ath9k_hw_get_target_powers(ah, chan,
442 pEepData->calTargetPower2GHT40,
443 AR5416_NUM_2G_40_TARGET_POWERS,
444 &targetPowerHt40, 8, true);
445 ath9k_hw_get_legacy_target_powers(ah, chan,
446 pEepData->calTargetPowerCck,
447 AR5416_NUM_2G_CCK_TARGET_POWERS,
448 &targetPowerCckExt, 4, true);
449 ath9k_hw_get_legacy_target_powers(ah, chan,
450 pEepData->calTargetPower2G,
451 AR5416_NUM_2G_20_TARGET_POWERS,
452 &targetPowerOfdmExt, 4, true);
453 }
454
455 for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
456 bool isHt40CtlMode = (pCtlMode[ctlMode] == CTL_5GHT40) ||
457 (pCtlMode[ctlMode] == CTL_2GHT40);
Sujith180d674b2009-08-07 09:45:33 +0530458
Sujithb5aec952009-08-07 09:45:15 +0530459 if (isHt40CtlMode)
460 freq = centers.synth_center;
461 else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
462 freq = centers.ext_center;
463 else
464 freq = centers.ctl_center;
465
466 if (ah->eep_ops->get_eeprom_ver(ah) == 14 &&
467 ah->eep_ops->get_eeprom_rev(ah) <= 2)
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100468 twiceMaxEdgePower = MAX_RATE_POWER;
Sujithb5aec952009-08-07 09:45:15 +0530469
470 for (i = 0; (i < AR5416_EEP4K_NUM_CTLS) &&
Sujith180d674b2009-08-07 09:45:33 +0530471 pEepData->ctlIndex[i]; i++) {
472
473 if (CMP_TEST_GRP) {
Sujithb5aec952009-08-07 09:45:15 +0530474 rep = &(pEepData->ctlData[i]);
475
Sujith180d674b2009-08-07 09:45:33 +0530476 twiceMinEdgePower = ath9k_hw_get_max_edge_power(
477 freq,
478 rep->ctlEdges[
479 ar5416_get_ntxchains(ah->txchainmask) - 1],
480 IS_CHAN_2GHZ(chan),
481 AR5416_EEP4K_NUM_BAND_EDGES);
Sujithb5aec952009-08-07 09:45:15 +0530482
483 if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {
484 twiceMaxEdgePower =
485 min(twiceMaxEdgePower,
486 twiceMinEdgePower);
487 } else {
488 twiceMaxEdgePower = twiceMinEdgePower;
489 break;
490 }
491 }
492 }
493
494 minCtlPower = (u8)min(twiceMaxEdgePower, scaledPower);
495
496 switch (pCtlMode[ctlMode]) {
497 case CTL_11B:
Sujith180d674b2009-08-07 09:45:33 +0530498 for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x); i++) {
Sujithb5aec952009-08-07 09:45:15 +0530499 targetPowerCck.tPow2x[i] =
500 min((u16)targetPowerCck.tPow2x[i],
501 minCtlPower);
502 }
503 break;
504 case CTL_11G:
Sujith180d674b2009-08-07 09:45:33 +0530505 for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x); i++) {
Sujithb5aec952009-08-07 09:45:15 +0530506 targetPowerOfdm.tPow2x[i] =
507 min((u16)targetPowerOfdm.tPow2x[i],
508 minCtlPower);
509 }
510 break;
511 case CTL_2GHT20:
Sujith180d674b2009-08-07 09:45:33 +0530512 for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) {
Sujithb5aec952009-08-07 09:45:15 +0530513 targetPowerHt20.tPow2x[i] =
514 min((u16)targetPowerHt20.tPow2x[i],
515 minCtlPower);
516 }
517 break;
518 case CTL_11B_EXT:
Sujith180d674b2009-08-07 09:45:33 +0530519 targetPowerCckExt.tPow2x[0] =
520 min((u16)targetPowerCckExt.tPow2x[0],
521 minCtlPower);
Sujithb5aec952009-08-07 09:45:15 +0530522 break;
523 case CTL_11G_EXT:
Sujith180d674b2009-08-07 09:45:33 +0530524 targetPowerOfdmExt.tPow2x[0] =
525 min((u16)targetPowerOfdmExt.tPow2x[0],
526 minCtlPower);
Sujithb5aec952009-08-07 09:45:15 +0530527 break;
528 case CTL_2GHT40:
Sujith180d674b2009-08-07 09:45:33 +0530529 for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
Sujithb5aec952009-08-07 09:45:15 +0530530 targetPowerHt40.tPow2x[i] =
531 min((u16)targetPowerHt40.tPow2x[i],
532 minCtlPower);
533 }
534 break;
535 default:
536 break;
537 }
538 }
539
Sujith180d674b2009-08-07 09:45:33 +0530540 ratesArray[rate6mb] =
541 ratesArray[rate9mb] =
542 ratesArray[rate12mb] =
543 ratesArray[rate18mb] =
544 ratesArray[rate24mb] =
545 targetPowerOfdm.tPow2x[0];
546
Sujithb5aec952009-08-07 09:45:15 +0530547 ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1];
548 ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2];
549 ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3];
550 ratesArray[rateXr] = targetPowerOfdm.tPow2x[0];
551
552 for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++)
553 ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i];
554
555 ratesArray[rate1l] = targetPowerCck.tPow2x[0];
556 ratesArray[rate2s] = ratesArray[rate2l] = targetPowerCck.tPow2x[1];
557 ratesArray[rate5_5s] = ratesArray[rate5_5l] = targetPowerCck.tPow2x[2];
558 ratesArray[rate11s] = ratesArray[rate11l] = targetPowerCck.tPow2x[3];
559
560 if (IS_CHAN_HT40(chan)) {
561 for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
562 ratesArray[rateHt40_0 + i] =
563 targetPowerHt40.tPow2x[i];
564 }
565 ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0];
566 ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0];
567 ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0];
568 ratesArray[rateExtCck] = targetPowerCckExt.tPow2x[0];
569 }
Sujith180d674b2009-08-07 09:45:33 +0530570
571#undef CMP_TEST_GRP
Sujithb5aec952009-08-07 09:45:15 +0530572}
573
574static void ath9k_hw_4k_set_txpower(struct ath_hw *ah,
Sujithbf466fb2009-08-07 09:45:30 +0530575 struct ath9k_channel *chan,
576 u16 cfgCtl,
577 u8 twiceAntennaReduction,
578 u8 twiceMaxRegulatoryPower,
Felix Fietkaude40f312010-10-20 03:08:53 +0200579 u8 powerLimit, bool test)
Sujithb5aec952009-08-07 09:45:15 +0530580{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700581 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithb5aec952009-08-07 09:45:15 +0530582 struct ar5416_eeprom_4k *pEepData = &ah->eeprom.map4k;
583 struct modal_eep_4k_header *pModal = &pEepData->modalHeader;
584 int16_t ratesArray[Ar5416RateSize];
585 int16_t txPowerIndexOffset = 0;
586 u8 ht40PowerIncForPdadc = 2;
587 int i;
588
589 memset(ratesArray, 0, sizeof(ratesArray));
590
591 if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
592 AR5416_EEP_MINOR_VER_2) {
593 ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
594 }
595
596 ath9k_hw_set_4k_power_per_rate_table(ah, chan,
Sujithbf466fb2009-08-07 09:45:30 +0530597 &ratesArray[0], cfgCtl,
598 twiceAntennaReduction,
599 twiceMaxRegulatoryPower,
600 powerLimit);
Sujithb5aec952009-08-07 09:45:15 +0530601
602 ath9k_hw_set_4k_power_cal_table(ah, chan, &txPowerIndexOffset);
603
Felix Fietkaude40f312010-10-20 03:08:53 +0200604 regulatory->max_power_level = 0;
Sujithb5aec952009-08-07 09:45:15 +0530605 for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
606 ratesArray[i] = (int16_t)(txPowerIndexOffset + ratesArray[i]);
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100607 if (ratesArray[i] > MAX_RATE_POWER)
608 ratesArray[i] = MAX_RATE_POWER;
Felix Fietkaude40f312010-10-20 03:08:53 +0200609
610 if (ratesArray[i] > regulatory->max_power_level)
611 regulatory->max_power_level = ratesArray[i];
Sujithb5aec952009-08-07 09:45:15 +0530612 }
613
Felix Fietkaude40f312010-10-20 03:08:53 +0200614 if (test)
615 return;
Sujithbf466fb2009-08-07 09:45:30 +0530616
617 /* Update regulatory */
Sujithbf466fb2009-08-07 09:45:30 +0530618 i = rate6mb;
619 if (IS_CHAN_HT40(chan))
620 i = rateHt40_0;
621 else if (IS_CHAN_HT20(chan))
622 i = rateHt20_0;
623
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700624 regulatory->max_power_level = ratesArray[i];
Sujithbf466fb2009-08-07 09:45:30 +0530625
Felix Fietkau7a370812010-09-22 12:34:52 +0200626 if (AR_SREV_9280_20_OR_LATER(ah)) {
Sujithb5aec952009-08-07 09:45:15 +0530627 for (i = 0; i < Ar5416RateSize; i++)
Senthil Balasubramaniane41f0bf2009-09-18 15:08:20 +0530628 ratesArray[i] -= AR5416_PWR_TABLE_OFFSET_DB * 2;
Sujithb5aec952009-08-07 09:45:15 +0530629 }
630
Sujith7d0d0df2010-04-16 11:53:57 +0530631 ENABLE_REGWRITE_BUFFER(ah);
632
Sujithbf466fb2009-08-07 09:45:30 +0530633 /* OFDM power per rate */
Sujithb5aec952009-08-07 09:45:15 +0530634 REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
635 ATH9K_POW_SM(ratesArray[rate18mb], 24)
636 | ATH9K_POW_SM(ratesArray[rate12mb], 16)
637 | ATH9K_POW_SM(ratesArray[rate9mb], 8)
638 | ATH9K_POW_SM(ratesArray[rate6mb], 0));
639 REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
640 ATH9K_POW_SM(ratesArray[rate54mb], 24)
641 | ATH9K_POW_SM(ratesArray[rate48mb], 16)
642 | ATH9K_POW_SM(ratesArray[rate36mb], 8)
643 | ATH9K_POW_SM(ratesArray[rate24mb], 0));
644
Sujithbf466fb2009-08-07 09:45:30 +0530645 /* CCK power per rate */
646 REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
647 ATH9K_POW_SM(ratesArray[rate2s], 24)
648 | ATH9K_POW_SM(ratesArray[rate2l], 16)
649 | ATH9K_POW_SM(ratesArray[rateXr], 8)
650 | ATH9K_POW_SM(ratesArray[rate1l], 0));
651 REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
652 ATH9K_POW_SM(ratesArray[rate11s], 24)
653 | ATH9K_POW_SM(ratesArray[rate11l], 16)
654 | ATH9K_POW_SM(ratesArray[rate5_5s], 8)
655 | ATH9K_POW_SM(ratesArray[rate5_5l], 0));
Sujithb5aec952009-08-07 09:45:15 +0530656
Sujithbf466fb2009-08-07 09:45:30 +0530657 /* HT20 power per rate */
Sujithb5aec952009-08-07 09:45:15 +0530658 REG_WRITE(ah, AR_PHY_POWER_TX_RATE5,
659 ATH9K_POW_SM(ratesArray[rateHt20_3], 24)
660 | ATH9K_POW_SM(ratesArray[rateHt20_2], 16)
661 | ATH9K_POW_SM(ratesArray[rateHt20_1], 8)
662 | ATH9K_POW_SM(ratesArray[rateHt20_0], 0));
663 REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
664 ATH9K_POW_SM(ratesArray[rateHt20_7], 24)
665 | ATH9K_POW_SM(ratesArray[rateHt20_6], 16)
666 | ATH9K_POW_SM(ratesArray[rateHt20_5], 8)
667 | ATH9K_POW_SM(ratesArray[rateHt20_4], 0));
668
Sujithbf466fb2009-08-07 09:45:30 +0530669 /* HT40 power per rate */
Sujithb5aec952009-08-07 09:45:15 +0530670 if (IS_CHAN_HT40(chan)) {
671 REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
672 ATH9K_POW_SM(ratesArray[rateHt40_3] +
673 ht40PowerIncForPdadc, 24)
674 | ATH9K_POW_SM(ratesArray[rateHt40_2] +
675 ht40PowerIncForPdadc, 16)
676 | ATH9K_POW_SM(ratesArray[rateHt40_1] +
677 ht40PowerIncForPdadc, 8)
678 | ATH9K_POW_SM(ratesArray[rateHt40_0] +
679 ht40PowerIncForPdadc, 0));
680 REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
681 ATH9K_POW_SM(ratesArray[rateHt40_7] +
682 ht40PowerIncForPdadc, 24)
683 | ATH9K_POW_SM(ratesArray[rateHt40_6] +
684 ht40PowerIncForPdadc, 16)
685 | ATH9K_POW_SM(ratesArray[rateHt40_5] +
686 ht40PowerIncForPdadc, 8)
687 | ATH9K_POW_SM(ratesArray[rateHt40_4] +
688 ht40PowerIncForPdadc, 0));
Sujithb5aec952009-08-07 09:45:15 +0530689 REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
690 ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
691 | ATH9K_POW_SM(ratesArray[rateExtCck], 16)
692 | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
693 | ATH9K_POW_SM(ratesArray[rateDupCck], 0));
694 }
Sujith7d0d0df2010-04-16 11:53:57 +0530695
696 REGWRITE_BUFFER_FLUSH(ah);
Sujithb5aec952009-08-07 09:45:15 +0530697}
698
699static void ath9k_hw_4k_set_addac(struct ath_hw *ah,
700 struct ath9k_channel *chan)
701{
702 struct modal_eep_4k_header *pModal;
703 struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k;
704 u8 biaslevel;
705
706 if (ah->hw_version.macVersion != AR_SREV_VERSION_9160)
707 return;
708
709 if (ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_MINOR_VER_7)
710 return;
711
712 pModal = &eep->modalHeader;
713
714 if (pModal->xpaBiasLvl != 0xff) {
715 biaslevel = pModal->xpaBiasLvl;
716 INI_RA(&ah->iniAddac, 7, 1) =
717 (INI_RA(&ah->iniAddac, 7, 1) & (~0x18)) | biaslevel << 3;
718 }
719}
720
721static void ath9k_hw_4k_set_gain(struct ath_hw *ah,
722 struct modal_eep_4k_header *pModal,
723 struct ar5416_eeprom_4k *eep,
Sujitha37414a2009-08-07 09:45:19 +0530724 u8 txRxAttenLocal)
Sujithb5aec952009-08-07 09:45:15 +0530725{
Sujitha37414a2009-08-07 09:45:19 +0530726 REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0,
Sujithb5aec952009-08-07 09:45:15 +0530727 pModal->antCtrlChain[0]);
728
Sujitha37414a2009-08-07 09:45:19 +0530729 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0),
730 (REG_READ(ah, AR_PHY_TIMING_CTRL4(0)) &
Sujithb5aec952009-08-07 09:45:15 +0530731 ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
732 AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
733 SM(pModal->iqCalICh[0], AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
734 SM(pModal->iqCalQCh[0], AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
735
736 if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
737 AR5416_EEP_MINOR_VER_3) {
738 txRxAttenLocal = pModal->txRxAttenCh[0];
739
Sujitha37414a2009-08-07 09:45:19 +0530740 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ,
Sujithb5aec952009-08-07 09:45:15 +0530741 AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN, pModal->bswMargin[0]);
Sujitha37414a2009-08-07 09:45:19 +0530742 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ,
Sujithb5aec952009-08-07 09:45:15 +0530743 AR_PHY_GAIN_2GHZ_XATTEN1_DB, pModal->bswAtten[0]);
Sujitha37414a2009-08-07 09:45:19 +0530744 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ,
Sujithb5aec952009-08-07 09:45:15 +0530745 AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN,
746 pModal->xatten2Margin[0]);
Sujitha37414a2009-08-07 09:45:19 +0530747 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ,
Sujithb5aec952009-08-07 09:45:15 +0530748 AR_PHY_GAIN_2GHZ_XATTEN2_DB, pModal->xatten2Db[0]);
749
750 /* Set the block 1 value to block 0 value */
751 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + 0x1000,
752 AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN,
753 pModal->bswMargin[0]);
754 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + 0x1000,
755 AR_PHY_GAIN_2GHZ_XATTEN1_DB, pModal->bswAtten[0]);
756 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + 0x1000,
757 AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN,
758 pModal->xatten2Margin[0]);
759 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + 0x1000,
760 AR_PHY_GAIN_2GHZ_XATTEN2_DB,
761 pModal->xatten2Db[0]);
762 }
763
Sujitha37414a2009-08-07 09:45:19 +0530764 REG_RMW_FIELD(ah, AR_PHY_RXGAIN,
Sujithb5aec952009-08-07 09:45:15 +0530765 AR9280_PHY_RXGAIN_TXRX_ATTEN, txRxAttenLocal);
Sujitha37414a2009-08-07 09:45:19 +0530766 REG_RMW_FIELD(ah, AR_PHY_RXGAIN,
Sujithb5aec952009-08-07 09:45:15 +0530767 AR9280_PHY_RXGAIN_TXRX_MARGIN, pModal->rxTxMarginCh[0]);
768
769 REG_RMW_FIELD(ah, AR_PHY_RXGAIN + 0x1000,
770 AR9280_PHY_RXGAIN_TXRX_ATTEN, txRxAttenLocal);
771 REG_RMW_FIELD(ah, AR_PHY_RXGAIN + 0x1000,
772 AR9280_PHY_RXGAIN_TXRX_MARGIN, pModal->rxTxMarginCh[0]);
Sujithb5aec952009-08-07 09:45:15 +0530773}
774
775/*
776 * Read EEPROM header info and program the device for correct operation
777 * given the channel value.
778 */
779static void ath9k_hw_4k_set_board_values(struct ath_hw *ah,
780 struct ath9k_channel *chan)
781{
782 struct modal_eep_4k_header *pModal;
783 struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k;
784 u8 txRxAttenLocal;
785 u8 ob[5], db1[5], db2[5];
786 u8 ant_div_control1, ant_div_control2;
787 u32 regVal;
788
789 pModal = &eep->modalHeader;
790 txRxAttenLocal = 23;
791
Felix Fietkaudf3c8b22010-12-12 00:51:11 +0100792 REG_WRITE(ah, AR_PHY_SWITCH_COM, pModal->antCtrlCommon);
Sujithb5aec952009-08-07 09:45:15 +0530793
794 /* Single chain for 4K EEPROM*/
Sujitha37414a2009-08-07 09:45:19 +0530795 ath9k_hw_4k_set_gain(ah, pModal, eep, txRxAttenLocal);
Sujithb5aec952009-08-07 09:45:15 +0530796
797 /* Initialize Ant Diversity settings from EEPROM */
798 if (pModal->version >= 3) {
Sujith7f638452009-08-07 09:45:23 +0530799 ant_div_control1 = pModal->antdiv_ctl1;
800 ant_div_control2 = pModal->antdiv_ctl2;
801
802 regVal = REG_READ(ah, AR_PHY_MULTICHAIN_GAIN_CTL);
803 regVal &= (~(AR_PHY_9285_ANT_DIV_CTL_ALL));
804
805 regVal |= SM(ant_div_control1,
806 AR_PHY_9285_ANT_DIV_CTL);
807 regVal |= SM(ant_div_control2,
808 AR_PHY_9285_ANT_DIV_ALT_LNACONF);
809 regVal |= SM((ant_div_control2 >> 2),
810 AR_PHY_9285_ANT_DIV_MAIN_LNACONF);
811 regVal |= SM((ant_div_control1 >> 1),
812 AR_PHY_9285_ANT_DIV_ALT_GAINTB);
813 regVal |= SM((ant_div_control1 >> 2),
814 AR_PHY_9285_ANT_DIV_MAIN_GAINTB);
815
816
817 REG_WRITE(ah, AR_PHY_MULTICHAIN_GAIN_CTL, regVal);
818 regVal = REG_READ(ah, AR_PHY_MULTICHAIN_GAIN_CTL);
819 regVal = REG_READ(ah, AR_PHY_CCK_DETECT);
820 regVal &= (~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV);
821 regVal |= SM((ant_div_control1 >> 3),
822 AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV);
823
824 REG_WRITE(ah, AR_PHY_CCK_DETECT, regVal);
825 regVal = REG_READ(ah, AR_PHY_CCK_DETECT);
Sujithb5aec952009-08-07 09:45:15 +0530826 }
827
828 if (pModal->version >= 2) {
Sujith7f638452009-08-07 09:45:23 +0530829 ob[0] = pModal->ob_0;
830 ob[1] = pModal->ob_1;
831 ob[2] = pModal->ob_2;
832 ob[3] = pModal->ob_3;
833 ob[4] = pModal->ob_4;
Sujithb5aec952009-08-07 09:45:15 +0530834
Sujith7f638452009-08-07 09:45:23 +0530835 db1[0] = pModal->db1_0;
836 db1[1] = pModal->db1_1;
837 db1[2] = pModal->db1_2;
838 db1[3] = pModal->db1_3;
839 db1[4] = pModal->db1_4;
Sujithb5aec952009-08-07 09:45:15 +0530840
Sujith7f638452009-08-07 09:45:23 +0530841 db2[0] = pModal->db2_0;
842 db2[1] = pModal->db2_1;
843 db2[2] = pModal->db2_2;
844 db2[3] = pModal->db2_3;
845 db2[4] = pModal->db2_4;
Sujithb5aec952009-08-07 09:45:15 +0530846 } else if (pModal->version == 1) {
Sujith7f638452009-08-07 09:45:23 +0530847 ob[0] = pModal->ob_0;
848 ob[1] = ob[2] = ob[3] = ob[4] = pModal->ob_1;
849 db1[0] = pModal->db1_0;
850 db1[1] = db1[2] = db1[3] = db1[4] = pModal->db1_1;
851 db2[0] = pModal->db2_0;
852 db2[1] = db2[2] = db2[3] = db2[4] = pModal->db2_1;
Sujithb5aec952009-08-07 09:45:15 +0530853 } else {
854 int i;
Sujith7f638452009-08-07 09:45:23 +0530855
Sujithb5aec952009-08-07 09:45:15 +0530856 for (i = 0; i < 5; i++) {
Sujith7f638452009-08-07 09:45:23 +0530857 ob[i] = pModal->ob_0;
858 db1[i] = pModal->db1_0;
859 db2[i] = pModal->db1_0;
Sujithb5aec952009-08-07 09:45:15 +0530860 }
861 }
862
863 if (AR_SREV_9271(ah)) {
864 ath9k_hw_analog_shift_rmw(ah,
865 AR9285_AN_RF2G3,
866 AR9271_AN_RF2G3_OB_cck,
867 AR9271_AN_RF2G3_OB_cck_S,
868 ob[0]);
869 ath9k_hw_analog_shift_rmw(ah,
870 AR9285_AN_RF2G3,
871 AR9271_AN_RF2G3_OB_psk,
872 AR9271_AN_RF2G3_OB_psk_S,
873 ob[1]);
874 ath9k_hw_analog_shift_rmw(ah,
875 AR9285_AN_RF2G3,
876 AR9271_AN_RF2G3_OB_qam,
877 AR9271_AN_RF2G3_OB_qam_S,
878 ob[2]);
879 ath9k_hw_analog_shift_rmw(ah,
880 AR9285_AN_RF2G3,
881 AR9271_AN_RF2G3_DB_1,
882 AR9271_AN_RF2G3_DB_1_S,
883 db1[0]);
884 ath9k_hw_analog_shift_rmw(ah,
885 AR9285_AN_RF2G4,
886 AR9271_AN_RF2G4_DB_2,
887 AR9271_AN_RF2G4_DB_2_S,
888 db2[0]);
889 } else {
890 ath9k_hw_analog_shift_rmw(ah,
891 AR9285_AN_RF2G3,
892 AR9285_AN_RF2G3_OB_0,
893 AR9285_AN_RF2G3_OB_0_S,
894 ob[0]);
895 ath9k_hw_analog_shift_rmw(ah,
896 AR9285_AN_RF2G3,
897 AR9285_AN_RF2G3_OB_1,
898 AR9285_AN_RF2G3_OB_1_S,
899 ob[1]);
900 ath9k_hw_analog_shift_rmw(ah,
901 AR9285_AN_RF2G3,
902 AR9285_AN_RF2G3_OB_2,
903 AR9285_AN_RF2G3_OB_2_S,
904 ob[2]);
905 ath9k_hw_analog_shift_rmw(ah,
906 AR9285_AN_RF2G3,
907 AR9285_AN_RF2G3_OB_3,
908 AR9285_AN_RF2G3_OB_3_S,
909 ob[3]);
910 ath9k_hw_analog_shift_rmw(ah,
911 AR9285_AN_RF2G3,
912 AR9285_AN_RF2G3_OB_4,
913 AR9285_AN_RF2G3_OB_4_S,
914 ob[4]);
915
916 ath9k_hw_analog_shift_rmw(ah,
917 AR9285_AN_RF2G3,
918 AR9285_AN_RF2G3_DB1_0,
919 AR9285_AN_RF2G3_DB1_0_S,
920 db1[0]);
921 ath9k_hw_analog_shift_rmw(ah,
922 AR9285_AN_RF2G3,
923 AR9285_AN_RF2G3_DB1_1,
924 AR9285_AN_RF2G3_DB1_1_S,
925 db1[1]);
926 ath9k_hw_analog_shift_rmw(ah,
927 AR9285_AN_RF2G3,
928 AR9285_AN_RF2G3_DB1_2,
929 AR9285_AN_RF2G3_DB1_2_S,
930 db1[2]);
931 ath9k_hw_analog_shift_rmw(ah,
932 AR9285_AN_RF2G4,
933 AR9285_AN_RF2G4_DB1_3,
934 AR9285_AN_RF2G4_DB1_3_S,
935 db1[3]);
936 ath9k_hw_analog_shift_rmw(ah,
937 AR9285_AN_RF2G4,
938 AR9285_AN_RF2G4_DB1_4,
939 AR9285_AN_RF2G4_DB1_4_S, db1[4]);
940
941 ath9k_hw_analog_shift_rmw(ah,
942 AR9285_AN_RF2G4,
943 AR9285_AN_RF2G4_DB2_0,
944 AR9285_AN_RF2G4_DB2_0_S,
945 db2[0]);
946 ath9k_hw_analog_shift_rmw(ah,
947 AR9285_AN_RF2G4,
948 AR9285_AN_RF2G4_DB2_1,
949 AR9285_AN_RF2G4_DB2_1_S,
950 db2[1]);
951 ath9k_hw_analog_shift_rmw(ah,
952 AR9285_AN_RF2G4,
953 AR9285_AN_RF2G4_DB2_2,
954 AR9285_AN_RF2G4_DB2_2_S,
955 db2[2]);
956 ath9k_hw_analog_shift_rmw(ah,
957 AR9285_AN_RF2G4,
958 AR9285_AN_RF2G4_DB2_3,
959 AR9285_AN_RF2G4_DB2_3_S,
960 db2[3]);
961 ath9k_hw_analog_shift_rmw(ah,
962 AR9285_AN_RF2G4,
963 AR9285_AN_RF2G4_DB2_4,
964 AR9285_AN_RF2G4_DB2_4_S,
965 db2[4]);
966 }
967
968
Sujithb5aec952009-08-07 09:45:15 +0530969 REG_RMW_FIELD(ah, AR_PHY_SETTLING, AR_PHY_SETTLING_SWITCH,
970 pModal->switchSettling);
971 REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ, AR_PHY_DESIRED_SZ_ADC,
972 pModal->adcDesiredSize);
973
974 REG_WRITE(ah, AR_PHY_RF_CTL4,
975 SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF) |
976 SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAB_OFF) |
977 SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAA_ON) |
978 SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAB_ON));
979
980 REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON,
981 pModal->txEndToRxOn);
Luis R. Rodriguez0cab6552009-10-19 02:33:32 -0400982
983 if (AR_SREV_9271_10(ah))
984 REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON,
985 pModal->txEndToRxOn);
Sujithb5aec952009-08-07 09:45:15 +0530986 REG_RMW_FIELD(ah, AR_PHY_CCA, AR9280_PHY_CCA_THRESH62,
987 pModal->thresh62);
988 REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0, AR_PHY_EXT_CCA0_THRESH62,
989 pModal->thresh62);
990
991 if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
992 AR5416_EEP_MINOR_VER_2) {
993 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_DATA_START,
994 pModal->txFrameToDataStart);
995 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_PA_ON,
996 pModal->txFrameToPaOn);
997 }
998
999 if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
1000 AR5416_EEP_MINOR_VER_3) {
1001 if (IS_CHAN_HT40(chan))
1002 REG_RMW_FIELD(ah, AR_PHY_SETTLING,
1003 AR_PHY_SETTLING_SWITCH,
1004 pModal->swSettleHt40);
1005 }
1006}
1007
Sujithb5aec952009-08-07 09:45:15 +05301008static u16 ath9k_hw_4k_get_spur_channel(struct ath_hw *ah, u16 i, bool is2GHz)
1009{
1010#define EEP_MAP4K_SPURCHAN \
1011 (ah->eeprom.map4k.modalHeader.spurChans[i].spurChan)
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001012 struct ath_common *common = ath9k_hw_common(ah);
Sujithb5aec952009-08-07 09:45:15 +05301013
1014 u16 spur_val = AR_NO_SPUR;
1015
Joe Perches226afe62010-12-02 19:12:37 -08001016 ath_dbg(common, ATH_DBG_ANI,
1017 "Getting spur idx:%d is2Ghz:%d val:%x\n",
1018 i, is2GHz, ah->config.spurchans[i][is2GHz]);
Sujithb5aec952009-08-07 09:45:15 +05301019
1020 switch (ah->config.spurmode) {
1021 case SPUR_DISABLE:
1022 break;
1023 case SPUR_ENABLE_IOCTL:
1024 spur_val = ah->config.spurchans[i][is2GHz];
Joe Perches226afe62010-12-02 19:12:37 -08001025 ath_dbg(common, ATH_DBG_ANI,
1026 "Getting spur val from new loc. %d\n", spur_val);
Sujithb5aec952009-08-07 09:45:15 +05301027 break;
1028 case SPUR_ENABLE_EEPROM:
1029 spur_val = EEP_MAP4K_SPURCHAN;
1030 break;
1031 }
1032
1033 return spur_val;
1034
1035#undef EEP_MAP4K_SPURCHAN
1036}
1037
1038const struct eeprom_ops eep_4k_ops = {
1039 .check_eeprom = ath9k_hw_4k_check_eeprom,
1040 .get_eeprom = ath9k_hw_4k_get_eeprom,
1041 .fill_eeprom = ath9k_hw_4k_fill_eeprom,
1042 .get_eeprom_ver = ath9k_hw_4k_get_eeprom_ver,
1043 .get_eeprom_rev = ath9k_hw_4k_get_eeprom_rev,
Sujithb5aec952009-08-07 09:45:15 +05301044 .set_board_values = ath9k_hw_4k_set_board_values,
1045 .set_addac = ath9k_hw_4k_set_addac,
1046 .set_txpower = ath9k_hw_4k_set_txpower,
1047 .get_spur_channel = ath9k_hw_4k_get_spur_channel
1048};