blob: 2654f741b8bf6d970133143837b5c5030c15edab [file] [log] [blame]
Sujithb5aec952009-08-07 09:45:15 +05301/*
Sujith Manoharan5b681382011-05-17 13:36:18 +05302 * Copyright (c) 2008-2011 Atheros Communications Inc.
Sujithb5aec952009-08-07 09:45:15 +05303 *
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
Pavel Roskin78fa99a2011-07-15 19:06:33 -040017#include <asm/unaligned.h>
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070018#include "hw.h"
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -040019#include "ar9002_phy.h"
Sujithb5aec952009-08-07 09:45:15 +053020
21static void ath9k_get_txgain_index(struct ath_hw *ah,
22 struct ath9k_channel *chan,
23 struct calDataPerFreqOpLoop *rawDatasetOpLoop,
24 u8 *calChans, u16 availPiers, u8 *pwr, u8 *pcdacIdx)
25{
26 u8 pcdac, i = 0;
27 u16 idxL = 0, idxR = 0, numPiers;
28 bool match;
29 struct chan_centers centers;
30
31 ath9k_hw_get_channel_centers(ah, chan, &centers);
32
33 for (numPiers = 0; numPiers < availPiers; numPiers++)
34 if (calChans[numPiers] == AR5416_BCHAN_UNUSED)
35 break;
36
37 match = ath9k_hw_get_lower_upper_index(
38 (u8)FREQ2FBIN(centers.synth_center, IS_CHAN_2GHZ(chan)),
39 calChans, numPiers, &idxL, &idxR);
40 if (match) {
41 pcdac = rawDatasetOpLoop[idxL].pcdac[0][0];
42 *pwr = rawDatasetOpLoop[idxL].pwrPdg[0][0];
43 } else {
44 pcdac = rawDatasetOpLoop[idxR].pcdac[0][0];
45 *pwr = (rawDatasetOpLoop[idxL].pwrPdg[0][0] +
46 rawDatasetOpLoop[idxR].pwrPdg[0][0])/2;
47 }
48
49 while (pcdac > ah->originalGain[i] &&
50 i < (AR9280_TX_GAIN_TABLE_SIZE - 1))
51 i++;
52
53 *pcdacIdx = i;
Sujithb5aec952009-08-07 09:45:15 +053054}
55
56static void ath9k_olc_get_pdadcs(struct ath_hw *ah,
57 u32 initTxGain,
58 int txPower,
59 u8 *pPDADCValues)
60{
61 u32 i;
62 u32 offset;
63
64 REG_RMW_FIELD(ah, AR_PHY_TX_PWRCTRL6_0,
65 AR_PHY_TX_PWRCTRL_ERR_EST_MODE, 3);
66 REG_RMW_FIELD(ah, AR_PHY_TX_PWRCTRL6_1,
67 AR_PHY_TX_PWRCTRL_ERR_EST_MODE, 3);
68
69 REG_RMW_FIELD(ah, AR_PHY_TX_PWRCTRL7,
70 AR_PHY_TX_PWRCTRL_INIT_TX_GAIN, initTxGain);
71
72 offset = txPower;
73 for (i = 0; i < AR5416_NUM_PDADC_VALUES; i++)
74 if (i < offset)
75 pPDADCValues[i] = 0x0;
76 else
77 pPDADCValues[i] = 0xFF;
78}
79
80static int ath9k_hw_def_get_eeprom_ver(struct ath_hw *ah)
81{
82 return ((ah->eeprom.def.baseEepHeader.version >> 12) & 0xF);
83}
84
85static int ath9k_hw_def_get_eeprom_rev(struct ath_hw *ah)
86{
87 return ((ah->eeprom.def.baseEepHeader.version) & 0xFFF);
88}
89
Sujithb5aec952009-08-07 09:45:15 +053090#define SIZE_EEPROM_DEF (sizeof(struct ar5416_eeprom_def) / sizeof(u16))
Sujith Manoharan04cf53f2011-01-04 13:17:28 +053091
92static bool __ath9k_hw_def_fill_eeprom(struct ath_hw *ah)
93{
Luis R. Rodriguez5bb12792009-09-14 00:55:09 -070094 struct ath_common *common = ath9k_hw_common(ah);
Sujithb5aec952009-08-07 09:45:15 +053095 u16 *eep_data = (u16 *)&ah->eeprom.def;
96 int addr, ar5416_eep_start_loc = 0x100;
97
98 for (addr = 0; addr < SIZE_EEPROM_DEF; addr++) {
Luis R. Rodriguez5bb12792009-09-14 00:55:09 -070099 if (!ath9k_hw_nvram_read(common, addr + ar5416_eep_start_loc,
Gabor Juhos2fd2cdf2012-12-10 15:30:25 +0100100 eep_data))
Sujithb5aec952009-08-07 09:45:15 +0530101 return false;
Sujithb5aec952009-08-07 09:45:15 +0530102 eep_data++;
103 }
104 return true;
Sujithb5aec952009-08-07 09:45:15 +0530105}
106
Sujith Manoharan04cf53f2011-01-04 13:17:28 +0530107static bool __ath9k_hw_usb_def_fill_eeprom(struct ath_hw *ah)
108{
109 u16 *eep_data = (u16 *)&ah->eeprom.def;
110
111 ath9k_hw_usb_gen_fill_eeprom(ah, eep_data,
112 0x100, SIZE_EEPROM_DEF);
113 return true;
114}
115
116static bool ath9k_hw_def_fill_eeprom(struct ath_hw *ah)
117{
118 struct ath_common *common = ath9k_hw_common(ah);
119
120 if (!ath9k_hw_use_flash(ah)) {
Joe Perchesd2182b62011-12-15 14:55:53 -0800121 ath_dbg(common, EEPROM, "Reading from EEPROM, not flash\n");
Sujith Manoharan04cf53f2011-01-04 13:17:28 +0530122 }
123
124 if (common->bus_ops->ath_bus_type == ATH_USB)
125 return __ath9k_hw_usb_def_fill_eeprom(ah);
126 else
127 return __ath9k_hw_def_fill_eeprom(ah);
128}
129
130#undef SIZE_EEPROM_DEF
131
Rajkumar Manoharan1b37d3e2011-07-29 17:38:11 +0530132#if defined(CONFIG_ATH9K_DEBUGFS) || defined(CONFIG_ATH9K_HTC_DEBUGFS)
133static u32 ath9k_def_dump_modal_eeprom(char *buf, u32 len, u32 size,
134 struct modal_eep_header *modal_hdr)
135{
136 PR_EEP("Chain0 Ant. Control", modal_hdr->antCtrlChain[0]);
137 PR_EEP("Chain1 Ant. Control", modal_hdr->antCtrlChain[1]);
138 PR_EEP("Chain2 Ant. Control", modal_hdr->antCtrlChain[2]);
139 PR_EEP("Ant. Common Control", modal_hdr->antCtrlCommon);
140 PR_EEP("Chain0 Ant. Gain", modal_hdr->antennaGainCh[0]);
141 PR_EEP("Chain1 Ant. Gain", modal_hdr->antennaGainCh[1]);
142 PR_EEP("Chain2 Ant. Gain", modal_hdr->antennaGainCh[2]);
143 PR_EEP("Switch Settle", modal_hdr->switchSettling);
144 PR_EEP("Chain0 TxRxAtten", modal_hdr->txRxAttenCh[0]);
145 PR_EEP("Chain1 TxRxAtten", modal_hdr->txRxAttenCh[1]);
146 PR_EEP("Chain2 TxRxAtten", modal_hdr->txRxAttenCh[2]);
147 PR_EEP("Chain0 RxTxMargin", modal_hdr->rxTxMarginCh[0]);
148 PR_EEP("Chain1 RxTxMargin", modal_hdr->rxTxMarginCh[1]);
149 PR_EEP("Chain2 RxTxMargin", modal_hdr->rxTxMarginCh[2]);
150 PR_EEP("ADC Desired size", modal_hdr->adcDesiredSize);
151 PR_EEP("PGA Desired size", modal_hdr->pgaDesiredSize);
152 PR_EEP("Chain0 xlna Gain", modal_hdr->xlnaGainCh[0]);
153 PR_EEP("Chain1 xlna Gain", modal_hdr->xlnaGainCh[1]);
154 PR_EEP("Chain2 xlna Gain", modal_hdr->xlnaGainCh[2]);
155 PR_EEP("txEndToXpaOff", modal_hdr->txEndToXpaOff);
156 PR_EEP("txEndToRxOn", modal_hdr->txEndToRxOn);
157 PR_EEP("txFrameToXpaOn", modal_hdr->txFrameToXpaOn);
158 PR_EEP("CCA Threshold)", modal_hdr->thresh62);
159 PR_EEP("Chain0 NF Threshold", modal_hdr->noiseFloorThreshCh[0]);
160 PR_EEP("Chain1 NF Threshold", modal_hdr->noiseFloorThreshCh[1]);
161 PR_EEP("Chain2 NF Threshold", modal_hdr->noiseFloorThreshCh[2]);
162 PR_EEP("xpdGain", modal_hdr->xpdGain);
163 PR_EEP("External PD", modal_hdr->xpd);
164 PR_EEP("Chain0 I Coefficient", modal_hdr->iqCalICh[0]);
165 PR_EEP("Chain1 I Coefficient", modal_hdr->iqCalICh[1]);
166 PR_EEP("Chain2 I Coefficient", modal_hdr->iqCalICh[2]);
167 PR_EEP("Chain0 Q Coefficient", modal_hdr->iqCalQCh[0]);
168 PR_EEP("Chain1 Q Coefficient", modal_hdr->iqCalQCh[1]);
169 PR_EEP("Chain2 Q Coefficient", modal_hdr->iqCalQCh[2]);
170 PR_EEP("pdGainOverlap", modal_hdr->pdGainOverlap);
171 PR_EEP("Chain0 OutputBias", modal_hdr->ob);
172 PR_EEP("Chain0 DriverBias", modal_hdr->db);
173 PR_EEP("xPA Bias Level", modal_hdr->xpaBiasLvl);
174 PR_EEP("2chain pwr decrease", modal_hdr->pwrDecreaseFor2Chain);
175 PR_EEP("3chain pwr decrease", modal_hdr->pwrDecreaseFor3Chain);
176 PR_EEP("txFrameToDataStart", modal_hdr->txFrameToDataStart);
177 PR_EEP("txFrameToPaOn", modal_hdr->txFrameToPaOn);
178 PR_EEP("HT40 Power Inc.", modal_hdr->ht40PowerIncForPdadc);
179 PR_EEP("Chain0 bswAtten", modal_hdr->bswAtten[0]);
180 PR_EEP("Chain1 bswAtten", modal_hdr->bswAtten[1]);
181 PR_EEP("Chain2 bswAtten", modal_hdr->bswAtten[2]);
182 PR_EEP("Chain0 bswMargin", modal_hdr->bswMargin[0]);
183 PR_EEP("Chain1 bswMargin", modal_hdr->bswMargin[1]);
184 PR_EEP("Chain2 bswMargin", modal_hdr->bswMargin[2]);
185 PR_EEP("HT40 Switch Settle", modal_hdr->swSettleHt40);
186 PR_EEP("Chain0 xatten2Db", modal_hdr->xatten2Db[0]);
187 PR_EEP("Chain1 xatten2Db", modal_hdr->xatten2Db[1]);
188 PR_EEP("Chain2 xatten2Db", modal_hdr->xatten2Db[2]);
189 PR_EEP("Chain0 xatten2Margin", modal_hdr->xatten2Margin[0]);
190 PR_EEP("Chain1 xatten2Margin", modal_hdr->xatten2Margin[1]);
191 PR_EEP("Chain2 xatten2Margin", modal_hdr->xatten2Margin[2]);
192 PR_EEP("Chain1 OutputBias", modal_hdr->ob_ch1);
193 PR_EEP("Chain1 DriverBias", modal_hdr->db_ch1);
194 PR_EEP("LNA Control", modal_hdr->lna_ctl);
195 PR_EEP("XPA Bias Freq0", modal_hdr->xpaBiasLvlFreq[0]);
196 PR_EEP("XPA Bias Freq1", modal_hdr->xpaBiasLvlFreq[1]);
197 PR_EEP("XPA Bias Freq2", modal_hdr->xpaBiasLvlFreq[2]);
198
199 return len;
200}
201
202static u32 ath9k_hw_def_dump_eeprom(struct ath_hw *ah, bool dump_base_hdr,
203 u8 *buf, u32 len, u32 size)
204{
205 struct ar5416_eeprom_def *eep = &ah->eeprom.def;
206 struct base_eep_header *pBase = &eep->baseEepHeader;
207
208 if (!dump_base_hdr) {
209 len += snprintf(buf + len, size - len,
210 "%20s :\n", "2GHz modal Header");
Mohammed Shafi Shajakhand25360b2012-05-15 15:24:47 +0530211 len = ath9k_def_dump_modal_eeprom(buf, len, size,
Rajkumar Manoharan1b37d3e2011-07-29 17:38:11 +0530212 &eep->modalHeader[0]);
213 len += snprintf(buf + len, size - len,
214 "%20s :\n", "5GHz modal Header");
Mohammed Shafi Shajakhand25360b2012-05-15 15:24:47 +0530215 len = ath9k_def_dump_modal_eeprom(buf, len, size,
Rajkumar Manoharan1b37d3e2011-07-29 17:38:11 +0530216 &eep->modalHeader[1]);
217 goto out;
218 }
219
220 PR_EEP("Major Version", pBase->version >> 12);
221 PR_EEP("Minor Version", pBase->version & 0xFFF);
222 PR_EEP("Checksum", pBase->checksum);
223 PR_EEP("Length", pBase->length);
224 PR_EEP("RegDomain1", pBase->regDmn[0]);
225 PR_EEP("RegDomain2", pBase->regDmn[1]);
226 PR_EEP("TX Mask", pBase->txMask);
227 PR_EEP("RX Mask", pBase->rxMask);
228 PR_EEP("Allow 5GHz", !!(pBase->opCapFlags & AR5416_OPFLAGS_11A));
229 PR_EEP("Allow 2GHz", !!(pBase->opCapFlags & AR5416_OPFLAGS_11G));
230 PR_EEP("Disable 2GHz HT20", !!(pBase->opCapFlags &
231 AR5416_OPFLAGS_N_2G_HT20));
232 PR_EEP("Disable 2GHz HT40", !!(pBase->opCapFlags &
233 AR5416_OPFLAGS_N_2G_HT40));
234 PR_EEP("Disable 5Ghz HT20", !!(pBase->opCapFlags &
235 AR5416_OPFLAGS_N_5G_HT20));
236 PR_EEP("Disable 5Ghz HT40", !!(pBase->opCapFlags &
237 AR5416_OPFLAGS_N_5G_HT40));
238 PR_EEP("Big Endian", !!(pBase->eepMisc & 0x01));
239 PR_EEP("Cal Bin Major Ver", (pBase->binBuildNumber >> 24) & 0xFF);
240 PR_EEP("Cal Bin Minor Ver", (pBase->binBuildNumber >> 16) & 0xFF);
241 PR_EEP("Cal Bin Build", (pBase->binBuildNumber >> 8) & 0xFF);
242 PR_EEP("OpenLoop Power Ctrl", pBase->openLoopPwrCntl);
243
244 len += snprintf(buf + len, size - len, "%20s : %pM\n", "MacAddress",
245 pBase->macAddr);
246
247out:
248 if (len > size)
249 len = size;
250
251 return len;
252}
253#else
254static u32 ath9k_hw_def_dump_eeprom(struct ath_hw *ah, bool dump_base_hdr,
255 u8 *buf, u32 len, u32 size)
256{
257 return 0;
258}
259#endif
260
261
Sujithb5aec952009-08-07 09:45:15 +0530262static int ath9k_hw_def_check_eeprom(struct ath_hw *ah)
263{
Joe Perches2c208892012-06-04 12:44:17 +0000264 struct ar5416_eeprom_def *eep = &ah->eeprom.def;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700265 struct ath_common *common = ath9k_hw_common(ah);
Sujithb5aec952009-08-07 09:45:15 +0530266 u16 *eepdata, temp, magic, magic2;
267 u32 sum = 0, el;
268 bool need_swap = false;
269 int i, addr, size;
270
Luis R. Rodriguez5bb12792009-09-14 00:55:09 -0700271 if (!ath9k_hw_nvram_read(common, AR5416_EEPROM_MAGIC_OFFSET, &magic)) {
Joe Perches38002762010-12-02 19:12:36 -0800272 ath_err(common, "Reading Magic # failed\n");
Sujithb5aec952009-08-07 09:45:15 +0530273 return false;
274 }
275
276 if (!ath9k_hw_use_flash(ah)) {
Joe Perchesd2182b62011-12-15 14:55:53 -0800277 ath_dbg(common, EEPROM, "Read Magic = 0x%04X\n", magic);
Sujithb5aec952009-08-07 09:45:15 +0530278
279 if (magic != AR5416_EEPROM_MAGIC) {
280 magic2 = swab16(magic);
281
282 if (magic2 == AR5416_EEPROM_MAGIC) {
283 size = sizeof(struct ar5416_eeprom_def);
284 need_swap = true;
285 eepdata = (u16 *) (&ah->eeprom);
286
287 for (addr = 0; addr < size / sizeof(u16); addr++) {
288 temp = swab16(*eepdata);
289 *eepdata = temp;
290 eepdata++;
291 }
292 } else {
Joe Perches38002762010-12-02 19:12:36 -0800293 ath_err(common,
294 "Invalid EEPROM Magic. Endianness mismatch.\n");
Sujithb5aec952009-08-07 09:45:15 +0530295 return -EINVAL;
296 }
297 }
298 }
299
Joe Perchesd2182b62011-12-15 14:55:53 -0800300 ath_dbg(common, EEPROM, "need_swap = %s\n",
Joe Perches226afe62010-12-02 19:12:37 -0800301 need_swap ? "True" : "False");
Sujithb5aec952009-08-07 09:45:15 +0530302
303 if (need_swap)
304 el = swab16(ah->eeprom.def.baseEepHeader.length);
305 else
306 el = ah->eeprom.def.baseEepHeader.length;
307
308 if (el > sizeof(struct ar5416_eeprom_def))
309 el = sizeof(struct ar5416_eeprom_def) / sizeof(u16);
310 else
311 el = el / sizeof(u16);
312
313 eepdata = (u16 *)(&ah->eeprom);
314
315 for (i = 0; i < el; i++)
316 sum ^= *eepdata++;
317
318 if (need_swap) {
319 u32 integer, j;
320 u16 word;
321
Joe Perchesd2182b62011-12-15 14:55:53 -0800322 ath_dbg(common, EEPROM,
Joe Perches226afe62010-12-02 19:12:37 -0800323 "EEPROM Endianness is not native.. Changing.\n");
Sujithb5aec952009-08-07 09:45:15 +0530324
325 word = swab16(eep->baseEepHeader.length);
326 eep->baseEepHeader.length = word;
327
328 word = swab16(eep->baseEepHeader.checksum);
329 eep->baseEepHeader.checksum = word;
330
331 word = swab16(eep->baseEepHeader.version);
332 eep->baseEepHeader.version = word;
333
334 word = swab16(eep->baseEepHeader.regDmn[0]);
335 eep->baseEepHeader.regDmn[0] = word;
336
337 word = swab16(eep->baseEepHeader.regDmn[1]);
338 eep->baseEepHeader.regDmn[1] = word;
339
340 word = swab16(eep->baseEepHeader.rfSilent);
341 eep->baseEepHeader.rfSilent = word;
342
343 word = swab16(eep->baseEepHeader.blueToothOptions);
344 eep->baseEepHeader.blueToothOptions = word;
345
346 word = swab16(eep->baseEepHeader.deviceCap);
347 eep->baseEepHeader.deviceCap = word;
348
349 for (j = 0; j < ARRAY_SIZE(eep->modalHeader); j++) {
350 struct modal_eep_header *pModal =
351 &eep->modalHeader[j];
352 integer = swab32(pModal->antCtrlCommon);
353 pModal->antCtrlCommon = integer;
354
355 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
356 integer = swab32(pModal->antCtrlChain[i]);
357 pModal->antCtrlChain[i] = integer;
358 }
Adrian Chadd25f63a52011-04-23 12:48:53 +0800359 for (i = 0; i < 3; i++) {
360 word = swab16(pModal->xpaBiasLvlFreq[i]);
361 pModal->xpaBiasLvlFreq[i] = word;
362 }
Sujithb5aec952009-08-07 09:45:15 +0530363
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100364 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujithb5aec952009-08-07 09:45:15 +0530365 word = swab16(pModal->spurChans[i].spurChan);
366 pModal->spurChans[i].spurChan = word;
367 }
368 }
369 }
370
371 if (sum != 0xffff || ah->eep_ops->get_eeprom_ver(ah) != AR5416_EEP_VER ||
372 ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_NO_BACK_VER) {
Joe Perches38002762010-12-02 19:12:36 -0800373 ath_err(common, "Bad EEPROM checksum 0x%x or revision 0x%04x\n",
Sujithb5aec952009-08-07 09:45:15 +0530374 sum, ah->eep_ops->get_eeprom_ver(ah));
375 return -EINVAL;
376 }
377
Felix Fietkau57b98382010-04-15 17:39:17 -0400378 /* Enable fixup for AR_AN_TOP2 if necessary */
Sujith Manoharan4d906742011-01-26 21:59:18 +0530379 if ((ah->hw_version.devid == AR9280_DEVID_PCI) &&
380 ((eep->baseEepHeader.version & 0xff) > 0x0a) &&
381 (eep->baseEepHeader.pwdclkind == 0))
Rusty Russell3db1cd52011-12-19 13:56:45 +0000382 ah->need_an_top2_fixup = true;
Felix Fietkau57b98382010-04-15 17:39:17 -0400383
Sujith Manoharan69bdacc2011-01-04 13:17:05 +0530384 if ((common->bus_ops->ath_bus_type == ATH_USB) &&
385 (AR_SREV_9280(ah)))
386 eep->modalHeader[0].xpaBiasLvl = 0;
387
Sujithb5aec952009-08-07 09:45:15 +0530388 return 0;
389}
390
391static u32 ath9k_hw_def_get_eeprom(struct ath_hw *ah,
392 enum eeprom_param param)
393{
394 struct ar5416_eeprom_def *eep = &ah->eeprom.def;
395 struct modal_eep_header *pModal = eep->modalHeader;
396 struct base_eep_header *pBase = &eep->baseEepHeader;
Felix Fietkauca2c68c2011-10-08 20:06:20 +0200397 int band = 0;
Sujithb5aec952009-08-07 09:45:15 +0530398
399 switch (param) {
400 case EEP_NFTHRESH_5:
401 return pModal[0].noiseFloorThreshCh[0];
402 case EEP_NFTHRESH_2:
403 return pModal[1].noiseFloorThreshCh[0];
Luis R. Rodriguez49101672010-04-15 17:39:13 -0400404 case EEP_MAC_LSW:
Pavel Roskin78fa99a2011-07-15 19:06:33 -0400405 return get_unaligned_be16(pBase->macAddr);
Luis R. Rodriguez49101672010-04-15 17:39:13 -0400406 case EEP_MAC_MID:
Pavel Roskin78fa99a2011-07-15 19:06:33 -0400407 return get_unaligned_be16(pBase->macAddr + 2);
Luis R. Rodriguez49101672010-04-15 17:39:13 -0400408 case EEP_MAC_MSW:
Pavel Roskin78fa99a2011-07-15 19:06:33 -0400409 return get_unaligned_be16(pBase->macAddr + 4);
Sujithb5aec952009-08-07 09:45:15 +0530410 case EEP_REG_0:
411 return pBase->regDmn[0];
Sujithb5aec952009-08-07 09:45:15 +0530412 case EEP_OP_CAP:
413 return pBase->deviceCap;
414 case EEP_OP_MODE:
415 return pBase->opCapFlags;
416 case EEP_RF_SILENT:
417 return pBase->rfSilent;
418 case EEP_OB_5:
419 return pModal[0].ob;
420 case EEP_DB_5:
421 return pModal[0].db;
422 case EEP_OB_2:
423 return pModal[1].ob;
424 case EEP_DB_2:
425 return pModal[1].db;
426 case EEP_MINOR_REV:
427 return AR5416_VER_MASK;
428 case EEP_TX_MASK:
429 return pBase->txMask;
430 case EEP_RX_MASK:
431 return pBase->rxMask;
Felix Fietkau5b75d0f2010-04-26 15:04:34 -0400432 case EEP_FSTCLK_5G:
433 return pBase->fastClk5g;
Sujithb5aec952009-08-07 09:45:15 +0530434 case EEP_RXGAIN_TYPE:
435 return pBase->rxGainType;
436 case EEP_TXGAIN_TYPE:
437 return pBase->txGainType;
438 case EEP_OL_PWRCTRL:
439 if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
440 return pBase->openLoopPwrCntl ? true : false;
441 else
442 return false;
443 case EEP_RC_CHAIN_MASK:
444 if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
445 return pBase->rcChainMask;
446 else
447 return 0;
448 case EEP_DAC_HPWR_5G:
449 if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_20)
450 return pBase->dacHiPwrMode_5G;
451 else
452 return 0;
453 case EEP_FRAC_N_5G:
454 if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_22)
455 return pBase->frac_n_5g;
456 else
457 return 0;
Senthil Balasubramaniane41f0bf2009-09-18 15:08:20 +0530458 case EEP_PWR_TABLE_OFFSET:
459 if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_21)
460 return pBase->pwr_table_offset;
461 else
462 return AR5416_PWR_TABLE_OFFSET_DB;
Felix Fietkauca2c68c2011-10-08 20:06:20 +0200463 case EEP_ANTENNA_GAIN_2G:
464 band = 1;
465 /* fall through */
466 case EEP_ANTENNA_GAIN_5G:
467 return max_t(u8, max_t(u8,
468 pModal[band].antennaGainCh[0],
469 pModal[band].antennaGainCh[1]),
470 pModal[band].antennaGainCh[2]);
Sujithb5aec952009-08-07 09:45:15 +0530471 default:
472 return 0;
473 }
474}
475
476static void ath9k_hw_def_set_gain(struct ath_hw *ah,
477 struct modal_eep_header *pModal,
478 struct ar5416_eeprom_def *eep,
479 u8 txRxAttenLocal, int regChainOffset, int i)
480{
481 if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_3) {
482 txRxAttenLocal = pModal->txRxAttenCh[i];
483
Felix Fietkau7a370812010-09-22 12:34:52 +0200484 if (AR_SREV_9280_20_OR_LATER(ah)) {
Sujithb5aec952009-08-07 09:45:15 +0530485 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
486 AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN,
487 pModal->bswMargin[i]);
488 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
489 AR_PHY_GAIN_2GHZ_XATTEN1_DB,
490 pModal->bswAtten[i]);
491 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
492 AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN,
493 pModal->xatten2Margin[i]);
494 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
495 AR_PHY_GAIN_2GHZ_XATTEN2_DB,
496 pModal->xatten2Db[i]);
497 } else {
498 REG_WRITE(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
499 (REG_READ(ah, AR_PHY_GAIN_2GHZ + regChainOffset) &
500 ~AR_PHY_GAIN_2GHZ_BSW_MARGIN)
501 | SM(pModal-> bswMargin[i],
502 AR_PHY_GAIN_2GHZ_BSW_MARGIN));
503 REG_WRITE(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
504 (REG_READ(ah, AR_PHY_GAIN_2GHZ + regChainOffset) &
505 ~AR_PHY_GAIN_2GHZ_BSW_ATTEN)
506 | SM(pModal->bswAtten[i],
507 AR_PHY_GAIN_2GHZ_BSW_ATTEN));
508 }
509 }
510
Felix Fietkau7a370812010-09-22 12:34:52 +0200511 if (AR_SREV_9280_20_OR_LATER(ah)) {
Sujithb5aec952009-08-07 09:45:15 +0530512 REG_RMW_FIELD(ah,
513 AR_PHY_RXGAIN + regChainOffset,
514 AR9280_PHY_RXGAIN_TXRX_ATTEN, txRxAttenLocal);
515 REG_RMW_FIELD(ah,
516 AR_PHY_RXGAIN + regChainOffset,
517 AR9280_PHY_RXGAIN_TXRX_MARGIN, pModal->rxTxMarginCh[i]);
518 } else {
519 REG_WRITE(ah,
520 AR_PHY_RXGAIN + regChainOffset,
521 (REG_READ(ah, AR_PHY_RXGAIN + regChainOffset) &
522 ~AR_PHY_RXGAIN_TXRX_ATTEN)
523 | SM(txRxAttenLocal, AR_PHY_RXGAIN_TXRX_ATTEN));
524 REG_WRITE(ah,
525 AR_PHY_GAIN_2GHZ + regChainOffset,
526 (REG_READ(ah, AR_PHY_GAIN_2GHZ + regChainOffset) &
527 ~AR_PHY_GAIN_2GHZ_RXTX_MARGIN) |
528 SM(pModal->rxTxMarginCh[i], AR_PHY_GAIN_2GHZ_RXTX_MARGIN));
529 }
530}
531
532static void ath9k_hw_def_set_board_values(struct ath_hw *ah,
533 struct ath9k_channel *chan)
534{
535 struct modal_eep_header *pModal;
536 struct ar5416_eeprom_def *eep = &ah->eeprom.def;
537 int i, regChainOffset;
538 u8 txRxAttenLocal;
539
540 pModal = &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
541 txRxAttenLocal = IS_CHAN_2GHZ(chan) ? 23 : 44;
542
Felix Fietkaudf3c8b22010-12-12 00:51:11 +0100543 REG_WRITE(ah, AR_PHY_SWITCH_COM, pModal->antCtrlCommon & 0xffff);
Sujithb5aec952009-08-07 09:45:15 +0530544
545 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
546 if (AR_SREV_9280(ah)) {
547 if (i >= 2)
548 break;
549 }
550
Felix Fietkau1b8714f2011-09-15 14:25:35 +0200551 if ((ah->rxchainmask == 5 || ah->txchainmask == 5) && (i != 0))
Sujithb5aec952009-08-07 09:45:15 +0530552 regChainOffset = (i == 1) ? 0x2000 : 0x1000;
553 else
554 regChainOffset = i * 0x1000;
555
556 REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
557 pModal->antCtrlChain[i]);
558
559 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
560 (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset) &
561 ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
562 AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
563 SM(pModal->iqCalICh[i],
564 AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
565 SM(pModal->iqCalQCh[i],
566 AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
567
Felix Fietkau1b8714f2011-09-15 14:25:35 +0200568 ath9k_hw_def_set_gain(ah, pModal, eep, txRxAttenLocal,
569 regChainOffset, i);
Sujithb5aec952009-08-07 09:45:15 +0530570 }
571
Felix Fietkau7a370812010-09-22 12:34:52 +0200572 if (AR_SREV_9280_20_OR_LATER(ah)) {
Sujithb5aec952009-08-07 09:45:15 +0530573 if (IS_CHAN_2GHZ(chan)) {
574 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH0,
575 AR_AN_RF2G1_CH0_OB,
576 AR_AN_RF2G1_CH0_OB_S,
577 pModal->ob);
578 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH0,
579 AR_AN_RF2G1_CH0_DB,
580 AR_AN_RF2G1_CH0_DB_S,
581 pModal->db);
582 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH1,
583 AR_AN_RF2G1_CH1_OB,
584 AR_AN_RF2G1_CH1_OB_S,
585 pModal->ob_ch1);
586 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH1,
587 AR_AN_RF2G1_CH1_DB,
588 AR_AN_RF2G1_CH1_DB_S,
589 pModal->db_ch1);
590 } else {
591 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH0,
592 AR_AN_RF5G1_CH0_OB5,
593 AR_AN_RF5G1_CH0_OB5_S,
594 pModal->ob);
595 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH0,
596 AR_AN_RF5G1_CH0_DB5,
597 AR_AN_RF5G1_CH0_DB5_S,
598 pModal->db);
599 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH1,
600 AR_AN_RF5G1_CH1_OB5,
601 AR_AN_RF5G1_CH1_OB5_S,
602 pModal->ob_ch1);
603 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH1,
604 AR_AN_RF5G1_CH1_DB5,
605 AR_AN_RF5G1_CH1_DB5_S,
606 pModal->db_ch1);
607 }
608 ath9k_hw_analog_shift_rmw(ah, AR_AN_TOP2,
609 AR_AN_TOP2_XPABIAS_LVL,
610 AR_AN_TOP2_XPABIAS_LVL_S,
611 pModal->xpaBiasLvl);
612 ath9k_hw_analog_shift_rmw(ah, AR_AN_TOP2,
613 AR_AN_TOP2_LOCALBIAS,
614 AR_AN_TOP2_LOCALBIAS_S,
Felix Fietkauf67e07e2010-12-01 19:07:47 +0100615 !!(pModal->lna_ctl &
616 LNA_CTL_LOCAL_BIAS));
Sujithb5aec952009-08-07 09:45:15 +0530617 REG_RMW_FIELD(ah, AR_PHY_XPA_CFG, AR_PHY_FORCE_XPA_CFG,
Felix Fietkauf67e07e2010-12-01 19:07:47 +0100618 !!(pModal->lna_ctl & LNA_CTL_FORCE_XPA));
Sujithb5aec952009-08-07 09:45:15 +0530619 }
620
621 REG_RMW_FIELD(ah, AR_PHY_SETTLING, AR_PHY_SETTLING_SWITCH,
622 pModal->switchSettling);
623 REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ, AR_PHY_DESIRED_SZ_ADC,
624 pModal->adcDesiredSize);
625
Felix Fietkau7a370812010-09-22 12:34:52 +0200626 if (!AR_SREV_9280_20_OR_LATER(ah))
Sujithb5aec952009-08-07 09:45:15 +0530627 REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
628 AR_PHY_DESIRED_SZ_PGA,
629 pModal->pgaDesiredSize);
630
631 REG_WRITE(ah, AR_PHY_RF_CTL4,
632 SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF)
633 | SM(pModal->txEndToXpaOff,
634 AR_PHY_RF_CTL4_TX_END_XPAB_OFF)
635 | SM(pModal->txFrameToXpaOn,
636 AR_PHY_RF_CTL4_FRAME_XPAA_ON)
637 | SM(pModal->txFrameToXpaOn,
638 AR_PHY_RF_CTL4_FRAME_XPAB_ON));
639
640 REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON,
641 pModal->txEndToRxOn);
642
Felix Fietkau7a370812010-09-22 12:34:52 +0200643 if (AR_SREV_9280_20_OR_LATER(ah)) {
Sujithb5aec952009-08-07 09:45:15 +0530644 REG_RMW_FIELD(ah, AR_PHY_CCA, AR9280_PHY_CCA_THRESH62,
645 pModal->thresh62);
646 REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0,
647 AR_PHY_EXT_CCA0_THRESH62,
648 pModal->thresh62);
649 } else {
650 REG_RMW_FIELD(ah, AR_PHY_CCA, AR_PHY_CCA_THRESH62,
651 pModal->thresh62);
652 REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
653 AR_PHY_EXT_CCA_THRESH62,
654 pModal->thresh62);
655 }
656
657 if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_2) {
658 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
659 AR_PHY_TX_END_DATA_START,
660 pModal->txFrameToDataStart);
661 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_PA_ON,
662 pModal->txFrameToPaOn);
663 }
664
665 if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_3) {
666 if (IS_CHAN_HT40(chan))
667 REG_RMW_FIELD(ah, AR_PHY_SETTLING,
668 AR_PHY_SETTLING_SWITCH,
669 pModal->swSettleHt40);
670 }
671
672 if (AR_SREV_9280_20_OR_LATER(ah) &&
673 AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
674 REG_RMW_FIELD(ah, AR_PHY_CCK_TX_CTRL,
675 AR_PHY_CCK_TX_CTRL_TX_DAC_SCALE_CCK,
676 pModal->miscBits);
677
678
679 if (AR_SREV_9280_20(ah) && AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_20) {
680 if (IS_CHAN_2GHZ(chan))
681 REG_RMW_FIELD(ah, AR_AN_TOP1, AR_AN_TOP1_DACIPMODE,
682 eep->baseEepHeader.dacLpMode);
683 else if (eep->baseEepHeader.dacHiPwrMode_5G)
684 REG_RMW_FIELD(ah, AR_AN_TOP1, AR_AN_TOP1_DACIPMODE, 0);
685 else
686 REG_RMW_FIELD(ah, AR_AN_TOP1, AR_AN_TOP1_DACIPMODE,
687 eep->baseEepHeader.dacLpMode);
688
Senthil Balasubramaniand865ca6c2009-09-17 09:28:21 +0530689 udelay(100);
690
Sujithb5aec952009-08-07 09:45:15 +0530691 REG_RMW_FIELD(ah, AR_PHY_FRAME_CTL, AR_PHY_FRAME_CTL_TX_CLIP,
692 pModal->miscBits >> 2);
693
694 REG_RMW_FIELD(ah, AR_PHY_TX_PWRCTRL9,
695 AR_PHY_TX_DESIRED_SCALE_CCK,
696 eep->baseEepHeader.desiredScaleCCK);
697 }
698}
699
700static void ath9k_hw_def_set_addac(struct ath_hw *ah,
701 struct ath9k_channel *chan)
702{
703#define XPA_LVL_FREQ(cnt) (pModal->xpaBiasLvlFreq[cnt])
704 struct modal_eep_header *pModal;
705 struct ar5416_eeprom_def *eep = &ah->eeprom.def;
706 u8 biaslevel;
707
708 if (ah->hw_version.macVersion != AR_SREV_VERSION_9160)
709 return;
710
711 if (ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_MINOR_VER_7)
712 return;
713
714 pModal = &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
715
716 if (pModal->xpaBiasLvl != 0xff) {
717 biaslevel = pModal->xpaBiasLvl;
718 } else {
719 u16 resetFreqBin, freqBin, freqCount = 0;
720 struct chan_centers centers;
721
722 ath9k_hw_get_channel_centers(ah, chan, &centers);
723
724 resetFreqBin = FREQ2FBIN(centers.synth_center,
725 IS_CHAN_2GHZ(chan));
726 freqBin = XPA_LVL_FREQ(0) & 0xff;
727 biaslevel = (u8) (XPA_LVL_FREQ(0) >> 14);
728
729 freqCount++;
730
731 while (freqCount < 3) {
732 if (XPA_LVL_FREQ(freqCount) == 0x0)
733 break;
734
735 freqBin = XPA_LVL_FREQ(freqCount) & 0xff;
736 if (resetFreqBin >= freqBin)
737 biaslevel = (u8)(XPA_LVL_FREQ(freqCount) >> 14);
738 else
739 break;
740 freqCount++;
741 }
742 }
743
744 if (IS_CHAN_2GHZ(chan)) {
745 INI_RA(&ah->iniAddac, 7, 1) = (INI_RA(&ah->iniAddac,
746 7, 1) & (~0x18)) | biaslevel << 3;
747 } else {
748 INI_RA(&ah->iniAddac, 6, 1) = (INI_RA(&ah->iniAddac,
749 6, 1) & (~0xc0)) | biaslevel << 6;
750 }
751#undef XPA_LVL_FREQ
752}
753
Senthil Balasubramaniane41f0bf2009-09-18 15:08:20 +0530754static int16_t ath9k_change_gain_boundary_setting(struct ath_hw *ah,
755 u16 *gb,
756 u16 numXpdGain,
757 u16 pdGainOverlap_t2,
758 int8_t pwr_table_offset,
759 int16_t *diff)
760
761{
762 u16 k;
763
764 /* Prior to writing the boundaries or the pdadc vs. power table
765 * into the chip registers the default starting point on the pdadc
766 * vs. power table needs to be checked and the curve boundaries
767 * adjusted accordingly
768 */
769 if (AR_SREV_9280_20_OR_LATER(ah)) {
770 u16 gb_limit;
771
772 if (AR5416_PWR_TABLE_OFFSET_DB != pwr_table_offset) {
773 /* get the difference in dB */
774 *diff = (u16)(pwr_table_offset - AR5416_PWR_TABLE_OFFSET_DB);
775 /* get the number of half dB steps */
776 *diff *= 2;
777 /* change the original gain boundary settings
778 * by the number of half dB steps
779 */
780 for (k = 0; k < numXpdGain; k++)
781 gb[k] = (u16)(gb[k] - *diff);
782 }
783 /* Because of a hardware limitation, ensure the gain boundary
784 * is not larger than (63 - overlap)
785 */
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100786 gb_limit = (u16)(MAX_RATE_POWER - pdGainOverlap_t2);
Senthil Balasubramaniane41f0bf2009-09-18 15:08:20 +0530787
788 for (k = 0; k < numXpdGain; k++)
789 gb[k] = (u16)min(gb_limit, gb[k]);
790 }
791
792 return *diff;
793}
794
795static void ath9k_adjust_pdadc_values(struct ath_hw *ah,
796 int8_t pwr_table_offset,
797 int16_t diff,
798 u8 *pdadcValues)
799{
800#define NUM_PDADC(diff) (AR5416_NUM_PDADC_VALUES - diff)
801 u16 k;
802
803 /* If this is a board that has a pwrTableOffset that differs from
804 * the default AR5416_PWR_TABLE_OFFSET_DB then the start of the
805 * pdadc vs pwr table needs to be adjusted prior to writing to the
806 * chip.
807 */
808 if (AR_SREV_9280_20_OR_LATER(ah)) {
809 if (AR5416_PWR_TABLE_OFFSET_DB != pwr_table_offset) {
810 /* shift the table to start at the new offset */
811 for (k = 0; k < (u16)NUM_PDADC(diff); k++ ) {
812 pdadcValues[k] = pdadcValues[k + diff];
813 }
814
815 /* fill the back of the table */
816 for (k = (u16)NUM_PDADC(diff); k < NUM_PDADC(0); k++) {
817 pdadcValues[k] = pdadcValues[NUM_PDADC(diff)];
818 }
819 }
820 }
821#undef NUM_PDADC
822}
823
Sujithb5aec952009-08-07 09:45:15 +0530824static void ath9k_hw_set_def_power_cal_table(struct ath_hw *ah,
Felix Fietkaue832bf12011-07-27 15:01:03 +0200825 struct ath9k_channel *chan)
Sujithb5aec952009-08-07 09:45:15 +0530826{
827#define SM_PD_GAIN(x) SM(0x38, AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_##x)
828#define SM_PDGAIN_B(x, y) \
829 SM((gainBoundaries[x]), AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_##y)
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700830 struct ath_common *common = ath9k_hw_common(ah);
Sujithb5aec952009-08-07 09:45:15 +0530831 struct ar5416_eeprom_def *pEepData = &ah->eeprom.def;
832 struct cal_data_per_freq *pRawDataset;
833 u8 *pCalBChans = NULL;
834 u16 pdGainOverlap_t2;
835 static u8 pdadcValues[AR5416_NUM_PDADC_VALUES];
836 u16 gainBoundaries[AR5416_PD_GAINS_IN_MASK];
837 u16 numPiers, i, j;
Pavel Roskin6eb90d42010-07-06 12:51:27 -0400838 int16_t diff = 0;
Sujithb5aec952009-08-07 09:45:15 +0530839 u16 numXpdGain, xpdMask;
840 u16 xpdGainValues[AR5416_NUM_PD_GAINS] = { 0, 0, 0, 0 };
841 u32 reg32, regOffset, regChainOffset;
842 int16_t modalIdx;
Senthil Balasubramaniane41f0bf2009-09-18 15:08:20 +0530843 int8_t pwr_table_offset;
Sujithb5aec952009-08-07 09:45:15 +0530844
845 modalIdx = IS_CHAN_2GHZ(chan) ? 1 : 0;
846 xpdMask = pEepData->modalHeader[modalIdx].xpdGain;
847
Senthil Balasubramaniane41f0bf2009-09-18 15:08:20 +0530848 pwr_table_offset = ah->eep_ops->get_eeprom(ah, EEP_PWR_TABLE_OFFSET);
849
Sujithb5aec952009-08-07 09:45:15 +0530850 if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
851 AR5416_EEP_MINOR_VER_2) {
852 pdGainOverlap_t2 =
853 pEepData->modalHeader[modalIdx].pdGainOverlap;
854 } else {
855 pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5),
856 AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
857 }
858
859 if (IS_CHAN_2GHZ(chan)) {
860 pCalBChans = pEepData->calFreqPier2G;
861 numPiers = AR5416_NUM_2G_CAL_PIERS;
862 } else {
863 pCalBChans = pEepData->calFreqPier5G;
864 numPiers = AR5416_NUM_5G_CAL_PIERS;
865 }
866
867 if (OLC_FOR_AR9280_20_LATER && IS_CHAN_2GHZ(chan)) {
868 pRawDataset = pEepData->calPierData2G[0];
869 ah->initPDADC = ((struct calDataPerFreqOpLoop *)
870 pRawDataset)->vpdPdg[0][0];
871 }
872
873 numXpdGain = 0;
874
875 for (i = 1; i <= AR5416_PD_GAINS_IN_MASK; i++) {
876 if ((xpdMask >> (AR5416_PD_GAINS_IN_MASK - i)) & 1) {
877 if (numXpdGain >= AR5416_NUM_PD_GAINS)
878 break;
879 xpdGainValues[numXpdGain] =
880 (u16)(AR5416_PD_GAINS_IN_MASK - i);
881 numXpdGain++;
882 }
883 }
884
885 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
886 (numXpdGain - 1) & 0x3);
887 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,
888 xpdGainValues[0]);
889 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
890 xpdGainValues[1]);
891 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3,
892 xpdGainValues[2]);
893
894 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
Felix Fietkau1b8714f2011-09-15 14:25:35 +0200895 if ((ah->rxchainmask == 5 || ah->txchainmask == 5) &&
Sujithb5aec952009-08-07 09:45:15 +0530896 (i != 0)) {
897 regChainOffset = (i == 1) ? 0x2000 : 0x1000;
898 } else
899 regChainOffset = i * 0x1000;
900
901 if (pEepData->baseEepHeader.txMask & (1 << i)) {
902 if (IS_CHAN_2GHZ(chan))
903 pRawDataset = pEepData->calPierData2G[i];
904 else
905 pRawDataset = pEepData->calPierData5G[i];
906
907
908 if (OLC_FOR_AR9280_20_LATER) {
909 u8 pcdacIdx;
910 u8 txPower;
911
912 ath9k_get_txgain_index(ah, chan,
913 (struct calDataPerFreqOpLoop *)pRawDataset,
914 pCalBChans, numPiers, &txPower, &pcdacIdx);
915 ath9k_olc_get_pdadcs(ah, pcdacIdx,
916 txPower/2, pdadcValues);
917 } else {
Felix Fietkau115277a2010-12-12 00:51:09 +0100918 ath9k_hw_get_gain_boundaries_pdadcs(ah,
Sujithb5aec952009-08-07 09:45:15 +0530919 chan, pRawDataset,
920 pCalBChans, numPiers,
921 pdGainOverlap_t2,
Sujithb5aec952009-08-07 09:45:15 +0530922 gainBoundaries,
923 pdadcValues,
924 numXpdGain);
925 }
926
Senthil Balasubramaniane41f0bf2009-09-18 15:08:20 +0530927 diff = ath9k_change_gain_boundary_setting(ah,
928 gainBoundaries,
929 numXpdGain,
930 pdGainOverlap_t2,
931 pwr_table_offset,
932 &diff);
933
Rajkumar Manoharane7fc6332011-03-15 23:11:35 +0530934 ENABLE_REGWRITE_BUFFER(ah);
935
Felix Fietkau1b8714f2011-09-15 14:25:35 +0200936 if (OLC_FOR_AR9280_20_LATER) {
937 REG_WRITE(ah,
938 AR_PHY_TPCRG5 + regChainOffset,
939 SM(0x6,
940 AR_PHY_TPCRG5_PD_GAIN_OVERLAP) |
941 SM_PD_GAIN(1) | SM_PD_GAIN(2) |
942 SM_PD_GAIN(3) | SM_PD_GAIN(4));
943 } else {
944 REG_WRITE(ah,
945 AR_PHY_TPCRG5 + regChainOffset,
946 SM(pdGainOverlap_t2,
947 AR_PHY_TPCRG5_PD_GAIN_OVERLAP)|
948 SM_PDGAIN_B(0, 1) |
949 SM_PDGAIN_B(1, 2) |
950 SM_PDGAIN_B(2, 3) |
951 SM_PDGAIN_B(3, 4));
Sujithb5aec952009-08-07 09:45:15 +0530952 }
953
Senthil Balasubramaniane41f0bf2009-09-18 15:08:20 +0530954 ath9k_adjust_pdadc_values(ah, pwr_table_offset,
955 diff, pdadcValues);
956
Sujithb5aec952009-08-07 09:45:15 +0530957 regOffset = AR_PHY_BASE + (672 << 2) + regChainOffset;
958 for (j = 0; j < 32; j++) {
Pavel Roskin78fa99a2011-07-15 19:06:33 -0400959 reg32 = get_unaligned_le32(&pdadcValues[4 * j]);
Sujithb5aec952009-08-07 09:45:15 +0530960 REG_WRITE(ah, regOffset, reg32);
961
Joe Perchesd2182b62011-12-15 14:55:53 -0800962 ath_dbg(common, EEPROM,
Joe Perches226afe62010-12-02 19:12:37 -0800963 "PDADC (%d,%4x): %4.4x %8.8x\n",
964 i, regChainOffset, regOffset,
965 reg32);
Joe Perchesd2182b62011-12-15 14:55:53 -0800966 ath_dbg(common, EEPROM,
967 "PDADC: Chain %d | PDADC %3d Value %3d | PDADC %3d Value %3d | PDADC %3d Value %3d | PDADC %3d Value %3d |\n",
Joe Perches226afe62010-12-02 19:12:37 -0800968 i, 4 * j, pdadcValues[4 * j],
969 4 * j + 1, pdadcValues[4 * j + 1],
970 4 * j + 2, pdadcValues[4 * j + 2],
971 4 * j + 3, pdadcValues[4 * j + 3]);
Sujithb5aec952009-08-07 09:45:15 +0530972
973 regOffset += 4;
974 }
Rajkumar Manoharane7fc6332011-03-15 23:11:35 +0530975 REGWRITE_BUFFER_FLUSH(ah);
Sujithb5aec952009-08-07 09:45:15 +0530976 }
977 }
978
Sujithb5aec952009-08-07 09:45:15 +0530979#undef SM_PD_GAIN
980#undef SM_PDGAIN_B
981}
982
983static void ath9k_hw_set_def_power_per_rate_table(struct ath_hw *ah,
984 struct ath9k_channel *chan,
985 int16_t *ratesArray,
986 u16 cfgCtl,
Felix Fietkauca2c68c2011-10-08 20:06:20 +0200987 u16 antenna_reduction,
Sujithb5aec952009-08-07 09:45:15 +0530988 u16 powerLimit)
989{
Sujithb5aec952009-08-07 09:45:15 +0530990 struct ar5416_eeprom_def *pEepData = &ah->eeprom.def;
Rajkumar Manoharana261f0e2011-11-22 18:52:00 +0530991 u16 twiceMaxEdgePower;
Sujithb5aec952009-08-07 09:45:15 +0530992 int i;
Sujithb5aec952009-08-07 09:45:15 +0530993 struct cal_ctl_data *rep;
994 struct cal_target_power_leg targetPowerOfdm, targetPowerCck = {
995 0, { 0, 0, 0, 0}
996 };
997 struct cal_target_power_leg targetPowerOfdmExt = {
998 0, { 0, 0, 0, 0} }, targetPowerCckExt = {
999 0, { 0, 0, 0, 0 }
1000 };
1001 struct cal_target_power_ht targetPowerHt20, targetPowerHt40 = {
1002 0, {0, 0, 0, 0}
1003 };
Felix Fietkauca2c68c2011-10-08 20:06:20 +02001004 u16 scaledPower = 0, minCtlPower;
Joe Perches07b2fa52010-11-20 18:38:53 -08001005 static const u16 ctlModesFor11a[] = {
1006 CTL_11A, CTL_5GHT20, CTL_11A_EXT, CTL_5GHT40
1007 };
1008 static const u16 ctlModesFor11g[] = {
1009 CTL_11B, CTL_11G, CTL_2GHT20,
1010 CTL_11B_EXT, CTL_11G_EXT, CTL_2GHT40
1011 };
1012 u16 numCtlModes;
1013 const u16 *pCtlMode;
1014 u16 ctlMode, freq;
Sujithb5aec952009-08-07 09:45:15 +05301015 struct chan_centers centers;
1016 int tx_chainmask;
1017 u16 twiceMinEdgePower;
1018
1019 tx_chainmask = ah->txchainmask;
1020
1021 ath9k_hw_get_channel_centers(ah, chan, &centers);
1022
Gabor Juhosea6f7922012-04-14 22:01:58 +02001023 scaledPower = ath9k_hw_get_scaled_power(ah, powerLimit,
1024 antenna_reduction);
Sujithb5aec952009-08-07 09:45:15 +05301025
Sujithb5aec952009-08-07 09:45:15 +05301026 if (IS_CHAN_2GHZ(chan)) {
1027 numCtlModes = ARRAY_SIZE(ctlModesFor11g) -
1028 SUB_NUM_CTL_MODES_AT_2G_40;
1029 pCtlMode = ctlModesFor11g;
1030
1031 ath9k_hw_get_legacy_target_powers(ah, chan,
1032 pEepData->calTargetPowerCck,
1033 AR5416_NUM_2G_CCK_TARGET_POWERS,
1034 &targetPowerCck, 4, false);
1035 ath9k_hw_get_legacy_target_powers(ah, chan,
1036 pEepData->calTargetPower2G,
1037 AR5416_NUM_2G_20_TARGET_POWERS,
1038 &targetPowerOfdm, 4, false);
1039 ath9k_hw_get_target_powers(ah, chan,
1040 pEepData->calTargetPower2GHT20,
1041 AR5416_NUM_2G_20_TARGET_POWERS,
1042 &targetPowerHt20, 8, false);
1043
1044 if (IS_CHAN_HT40(chan)) {
1045 numCtlModes = ARRAY_SIZE(ctlModesFor11g);
1046 ath9k_hw_get_target_powers(ah, chan,
1047 pEepData->calTargetPower2GHT40,
1048 AR5416_NUM_2G_40_TARGET_POWERS,
1049 &targetPowerHt40, 8, true);
1050 ath9k_hw_get_legacy_target_powers(ah, chan,
1051 pEepData->calTargetPowerCck,
1052 AR5416_NUM_2G_CCK_TARGET_POWERS,
1053 &targetPowerCckExt, 4, true);
1054 ath9k_hw_get_legacy_target_powers(ah, chan,
1055 pEepData->calTargetPower2G,
1056 AR5416_NUM_2G_20_TARGET_POWERS,
1057 &targetPowerOfdmExt, 4, true);
1058 }
1059 } else {
1060 numCtlModes = ARRAY_SIZE(ctlModesFor11a) -
1061 SUB_NUM_CTL_MODES_AT_5G_40;
1062 pCtlMode = ctlModesFor11a;
1063
1064 ath9k_hw_get_legacy_target_powers(ah, chan,
1065 pEepData->calTargetPower5G,
1066 AR5416_NUM_5G_20_TARGET_POWERS,
1067 &targetPowerOfdm, 4, false);
1068 ath9k_hw_get_target_powers(ah, chan,
1069 pEepData->calTargetPower5GHT20,
1070 AR5416_NUM_5G_20_TARGET_POWERS,
1071 &targetPowerHt20, 8, false);
1072
1073 if (IS_CHAN_HT40(chan)) {
1074 numCtlModes = ARRAY_SIZE(ctlModesFor11a);
1075 ath9k_hw_get_target_powers(ah, chan,
1076 pEepData->calTargetPower5GHT40,
1077 AR5416_NUM_5G_40_TARGET_POWERS,
1078 &targetPowerHt40, 8, true);
1079 ath9k_hw_get_legacy_target_powers(ah, chan,
1080 pEepData->calTargetPower5G,
1081 AR5416_NUM_5G_20_TARGET_POWERS,
1082 &targetPowerOfdmExt, 4, true);
1083 }
1084 }
1085
1086 for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
1087 bool isHt40CtlMode = (pCtlMode[ctlMode] == CTL_5GHT40) ||
1088 (pCtlMode[ctlMode] == CTL_2GHT40);
1089 if (isHt40CtlMode)
1090 freq = centers.synth_center;
1091 else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
1092 freq = centers.ext_center;
1093 else
1094 freq = centers.ctl_center;
1095
Rajkumar Manoharana261f0e2011-11-22 18:52:00 +05301096 twiceMaxEdgePower = MAX_RATE_POWER;
Sujithb5aec952009-08-07 09:45:15 +05301097
1098 for (i = 0; (i < AR5416_NUM_CTLS) && pEepData->ctlIndex[i]; i++) {
1099 if ((((cfgCtl & ~CTL_MODE_M) |
1100 (pCtlMode[ctlMode] & CTL_MODE_M)) ==
1101 pEepData->ctlIndex[i]) ||
1102 (((cfgCtl & ~CTL_MODE_M) |
1103 (pCtlMode[ctlMode] & CTL_MODE_M)) ==
1104 ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL))) {
1105 rep = &(pEepData->ctlData[i]);
1106
1107 twiceMinEdgePower = ath9k_hw_get_max_edge_power(freq,
1108 rep->ctlEdges[ar5416_get_ntxchains(tx_chainmask) - 1],
1109 IS_CHAN_2GHZ(chan), AR5416_NUM_BAND_EDGES);
1110
1111 if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {
1112 twiceMaxEdgePower = min(twiceMaxEdgePower,
1113 twiceMinEdgePower);
1114 } else {
1115 twiceMaxEdgePower = twiceMinEdgePower;
1116 break;
1117 }
1118 }
1119 }
1120
1121 minCtlPower = min(twiceMaxEdgePower, scaledPower);
1122
1123 switch (pCtlMode[ctlMode]) {
1124 case CTL_11B:
1125 for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x); i++) {
1126 targetPowerCck.tPow2x[i] =
1127 min((u16)targetPowerCck.tPow2x[i],
1128 minCtlPower);
1129 }
1130 break;
1131 case CTL_11A:
1132 case CTL_11G:
1133 for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x); i++) {
1134 targetPowerOfdm.tPow2x[i] =
1135 min((u16)targetPowerOfdm.tPow2x[i],
1136 minCtlPower);
1137 }
1138 break;
1139 case CTL_5GHT20:
1140 case CTL_2GHT20:
1141 for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) {
1142 targetPowerHt20.tPow2x[i] =
1143 min((u16)targetPowerHt20.tPow2x[i],
1144 minCtlPower);
1145 }
1146 break;
1147 case CTL_11B_EXT:
1148 targetPowerCckExt.tPow2x[0] = min((u16)
1149 targetPowerCckExt.tPow2x[0],
1150 minCtlPower);
1151 break;
1152 case CTL_11A_EXT:
1153 case CTL_11G_EXT:
1154 targetPowerOfdmExt.tPow2x[0] = min((u16)
1155 targetPowerOfdmExt.tPow2x[0],
1156 minCtlPower);
1157 break;
1158 case CTL_5GHT40:
1159 case CTL_2GHT40:
1160 for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
1161 targetPowerHt40.tPow2x[i] =
1162 min((u16)targetPowerHt40.tPow2x[i],
1163 minCtlPower);
1164 }
1165 break;
1166 default:
1167 break;
1168 }
1169 }
1170
1171 ratesArray[rate6mb] = ratesArray[rate9mb] = ratesArray[rate12mb] =
1172 ratesArray[rate18mb] = ratesArray[rate24mb] =
1173 targetPowerOfdm.tPow2x[0];
1174 ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1];
1175 ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2];
1176 ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3];
1177 ratesArray[rateXr] = targetPowerOfdm.tPow2x[0];
1178
1179 for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++)
1180 ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i];
1181
1182 if (IS_CHAN_2GHZ(chan)) {
1183 ratesArray[rate1l] = targetPowerCck.tPow2x[0];
1184 ratesArray[rate2s] = ratesArray[rate2l] =
1185 targetPowerCck.tPow2x[1];
1186 ratesArray[rate5_5s] = ratesArray[rate5_5l] =
1187 targetPowerCck.tPow2x[2];
1188 ratesArray[rate11s] = ratesArray[rate11l] =
1189 targetPowerCck.tPow2x[3];
1190 }
1191 if (IS_CHAN_HT40(chan)) {
1192 for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
1193 ratesArray[rateHt40_0 + i] =
1194 targetPowerHt40.tPow2x[i];
1195 }
1196 ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0];
1197 ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0];
1198 ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0];
1199 if (IS_CHAN_2GHZ(chan)) {
1200 ratesArray[rateExtCck] =
1201 targetPowerCckExt.tPow2x[0];
1202 }
1203 }
1204}
1205
1206static void ath9k_hw_def_set_txpower(struct ath_hw *ah,
1207 struct ath9k_channel *chan,
1208 u16 cfgCtl,
1209 u8 twiceAntennaReduction,
Felix Fietkaude40f312010-10-20 03:08:53 +02001210 u8 powerLimit, bool test)
Sujithb5aec952009-08-07 09:45:15 +05301211{
1212#define RT_AR_DELTA(x) (ratesArray[x] - cck_ofdm_delta)
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -07001213 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithb5aec952009-08-07 09:45:15 +05301214 struct ar5416_eeprom_def *pEepData = &ah->eeprom.def;
1215 struct modal_eep_header *pModal =
1216 &(pEepData->modalHeader[IS_CHAN_2GHZ(chan)]);
1217 int16_t ratesArray[Ar5416RateSize];
Sujithb5aec952009-08-07 09:45:15 +05301218 u8 ht40PowerIncForPdadc = 2;
1219 int i, cck_ofdm_delta = 0;
1220
1221 memset(ratesArray, 0, sizeof(ratesArray));
1222
1223 if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
1224 AR5416_EEP_MINOR_VER_2) {
1225 ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
1226 }
1227
1228 ath9k_hw_set_def_power_per_rate_table(ah, chan,
1229 &ratesArray[0], cfgCtl,
1230 twiceAntennaReduction,
Sujithb5aec952009-08-07 09:45:15 +05301231 powerLimit);
1232
Felix Fietkaue832bf12011-07-27 15:01:03 +02001233 ath9k_hw_set_def_power_cal_table(ah, chan);
Sujithb5aec952009-08-07 09:45:15 +05301234
Felix Fietkaude40f312010-10-20 03:08:53 +02001235 regulatory->max_power_level = 0;
Sujithb5aec952009-08-07 09:45:15 +05301236 for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
Felix Fietkau4ddfcd72010-12-12 00:51:08 +01001237 if (ratesArray[i] > MAX_RATE_POWER)
1238 ratesArray[i] = MAX_RATE_POWER;
Felix Fietkaude40f312010-10-20 03:08:53 +02001239 if (ratesArray[i] > regulatory->max_power_level)
1240 regulatory->max_power_level = ratesArray[i];
Sujithb5aec952009-08-07 09:45:15 +05301241 }
1242
Gabor Juhosd9e91452012-04-14 20:35:19 +02001243 ath9k_hw_update_regulatory_maxpower(ah);
Felix Fietkaude40f312010-10-20 03:08:53 +02001244
1245 if (test)
1246 return;
1247
Felix Fietkau7a370812010-09-22 12:34:52 +02001248 if (AR_SREV_9280_20_OR_LATER(ah)) {
Senthil Balasubramaniane41f0bf2009-09-18 15:08:20 +05301249 for (i = 0; i < Ar5416RateSize; i++) {
1250 int8_t pwr_table_offset;
1251
1252 pwr_table_offset = ah->eep_ops->get_eeprom(ah,
1253 EEP_PWR_TABLE_OFFSET);
1254 ratesArray[i] -= pwr_table_offset * 2;
1255 }
Sujithb5aec952009-08-07 09:45:15 +05301256 }
1257
Rajkumar Manoharane7fc6332011-03-15 23:11:35 +05301258 ENABLE_REGWRITE_BUFFER(ah);
1259
Sujithb5aec952009-08-07 09:45:15 +05301260 REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
1261 ATH9K_POW_SM(ratesArray[rate18mb], 24)
1262 | ATH9K_POW_SM(ratesArray[rate12mb], 16)
1263 | ATH9K_POW_SM(ratesArray[rate9mb], 8)
1264 | ATH9K_POW_SM(ratesArray[rate6mb], 0));
1265 REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
1266 ATH9K_POW_SM(ratesArray[rate54mb], 24)
1267 | ATH9K_POW_SM(ratesArray[rate48mb], 16)
1268 | ATH9K_POW_SM(ratesArray[rate36mb], 8)
1269 | ATH9K_POW_SM(ratesArray[rate24mb], 0));
1270
1271 if (IS_CHAN_2GHZ(chan)) {
1272 if (OLC_FOR_AR9280_20_LATER) {
1273 cck_ofdm_delta = 2;
1274 REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
1275 ATH9K_POW_SM(RT_AR_DELTA(rate2s), 24)
1276 | ATH9K_POW_SM(RT_AR_DELTA(rate2l), 16)
1277 | ATH9K_POW_SM(ratesArray[rateXr], 8)
1278 | ATH9K_POW_SM(RT_AR_DELTA(rate1l), 0));
1279 REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
1280 ATH9K_POW_SM(RT_AR_DELTA(rate11s), 24)
1281 | ATH9K_POW_SM(RT_AR_DELTA(rate11l), 16)
1282 | ATH9K_POW_SM(RT_AR_DELTA(rate5_5s), 8)
1283 | ATH9K_POW_SM(RT_AR_DELTA(rate5_5l), 0));
1284 } else {
1285 REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
1286 ATH9K_POW_SM(ratesArray[rate2s], 24)
1287 | ATH9K_POW_SM(ratesArray[rate2l], 16)
1288 | ATH9K_POW_SM(ratesArray[rateXr], 8)
1289 | ATH9K_POW_SM(ratesArray[rate1l], 0));
1290 REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
1291 ATH9K_POW_SM(ratesArray[rate11s], 24)
1292 | ATH9K_POW_SM(ratesArray[rate11l], 16)
1293 | ATH9K_POW_SM(ratesArray[rate5_5s], 8)
1294 | ATH9K_POW_SM(ratesArray[rate5_5l], 0));
1295 }
1296 }
1297
1298 REG_WRITE(ah, AR_PHY_POWER_TX_RATE5,
1299 ATH9K_POW_SM(ratesArray[rateHt20_3], 24)
1300 | ATH9K_POW_SM(ratesArray[rateHt20_2], 16)
1301 | ATH9K_POW_SM(ratesArray[rateHt20_1], 8)
1302 | ATH9K_POW_SM(ratesArray[rateHt20_0], 0));
1303 REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
1304 ATH9K_POW_SM(ratesArray[rateHt20_7], 24)
1305 | ATH9K_POW_SM(ratesArray[rateHt20_6], 16)
1306 | ATH9K_POW_SM(ratesArray[rateHt20_5], 8)
1307 | ATH9K_POW_SM(ratesArray[rateHt20_4], 0));
1308
1309 if (IS_CHAN_HT40(chan)) {
1310 REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
1311 ATH9K_POW_SM(ratesArray[rateHt40_3] +
1312 ht40PowerIncForPdadc, 24)
1313 | ATH9K_POW_SM(ratesArray[rateHt40_2] +
1314 ht40PowerIncForPdadc, 16)
1315 | ATH9K_POW_SM(ratesArray[rateHt40_1] +
1316 ht40PowerIncForPdadc, 8)
1317 | ATH9K_POW_SM(ratesArray[rateHt40_0] +
1318 ht40PowerIncForPdadc, 0));
1319 REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
1320 ATH9K_POW_SM(ratesArray[rateHt40_7] +
1321 ht40PowerIncForPdadc, 24)
1322 | ATH9K_POW_SM(ratesArray[rateHt40_6] +
1323 ht40PowerIncForPdadc, 16)
1324 | ATH9K_POW_SM(ratesArray[rateHt40_5] +
1325 ht40PowerIncForPdadc, 8)
1326 | ATH9K_POW_SM(ratesArray[rateHt40_4] +
1327 ht40PowerIncForPdadc, 0));
1328 if (OLC_FOR_AR9280_20_LATER) {
1329 REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
1330 ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
1331 | ATH9K_POW_SM(RT_AR_DELTA(rateExtCck), 16)
1332 | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
1333 | ATH9K_POW_SM(RT_AR_DELTA(rateDupCck), 0));
1334 } else {
1335 REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
1336 ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
1337 | ATH9K_POW_SM(ratesArray[rateExtCck], 16)
1338 | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
1339 | ATH9K_POW_SM(ratesArray[rateDupCck], 0));
1340 }
1341 }
1342
1343 REG_WRITE(ah, AR_PHY_POWER_TX_SUB,
1344 ATH9K_POW_SM(pModal->pwrDecreaseFor3Chain, 6)
1345 | ATH9K_POW_SM(pModal->pwrDecreaseFor2Chain, 0));
Rajkumar Manoharane7fc6332011-03-15 23:11:35 +05301346
1347 REGWRITE_BUFFER_FLUSH(ah);
Sujithb5aec952009-08-07 09:45:15 +05301348}
1349
Sujithb5aec952009-08-07 09:45:15 +05301350static u16 ath9k_hw_def_get_spur_channel(struct ath_hw *ah, u16 i, bool is2GHz)
1351{
1352#define EEP_DEF_SPURCHAN \
1353 (ah->eeprom.def.modalHeader[is2GHz].spurChans[i].spurChan)
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001354 struct ath_common *common = ath9k_hw_common(ah);
Sujithb5aec952009-08-07 09:45:15 +05301355
1356 u16 spur_val = AR_NO_SPUR;
1357
Joe Perchesd2182b62011-12-15 14:55:53 -08001358 ath_dbg(common, ANI, "Getting spur idx:%d is2Ghz:%d val:%x\n",
Joe Perches226afe62010-12-02 19:12:37 -08001359 i, is2GHz, ah->config.spurchans[i][is2GHz]);
Sujithb5aec952009-08-07 09:45:15 +05301360
1361 switch (ah->config.spurmode) {
1362 case SPUR_DISABLE:
1363 break;
1364 case SPUR_ENABLE_IOCTL:
1365 spur_val = ah->config.spurchans[i][is2GHz];
Joe Perchesd2182b62011-12-15 14:55:53 -08001366 ath_dbg(common, ANI, "Getting spur val from new loc. %d\n",
1367 spur_val);
Sujithb5aec952009-08-07 09:45:15 +05301368 break;
1369 case SPUR_ENABLE_EEPROM:
1370 spur_val = EEP_DEF_SPURCHAN;
1371 break;
1372 }
1373
1374 return spur_val;
1375
1376#undef EEP_DEF_SPURCHAN
1377}
1378
1379const struct eeprom_ops eep_def_ops = {
1380 .check_eeprom = ath9k_hw_def_check_eeprom,
1381 .get_eeprom = ath9k_hw_def_get_eeprom,
1382 .fill_eeprom = ath9k_hw_def_fill_eeprom,
Rajkumar Manoharan1b37d3e2011-07-29 17:38:11 +05301383 .dump_eeprom = ath9k_hw_def_dump_eeprom,
Sujithb5aec952009-08-07 09:45:15 +05301384 .get_eeprom_ver = ath9k_hw_def_get_eeprom_ver,
1385 .get_eeprom_rev = ath9k_hw_def_get_eeprom_rev,
Sujithb5aec952009-08-07 09:45:15 +05301386 .set_board_values = ath9k_hw_def_set_board_values,
1387 .set_addac = ath9k_hw_def_set_addac,
1388 .set_txpower = ath9k_hw_def_set_txpower,
1389 .get_spur_channel = ath9k_hw_def_get_spur_channel
1390};