blob: 5f3b20b54d352c78e2a79a2b8775e76d550ee835 [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
Sujith16c94ac2010-06-01 15:14:04 +053020#define NUM_EEP_WORDS (sizeof(struct ar9287_eeprom) / sizeof(u16))
21
22static int ath9k_hw_ar9287_get_eeprom_ver(struct ath_hw *ah)
Sujithb5aec952009-08-07 09:45:15 +053023{
24 return (ah->eeprom.map9287.baseEepHeader.version >> 12) & 0xF;
25}
26
Sujith16c94ac2010-06-01 15:14:04 +053027static int ath9k_hw_ar9287_get_eeprom_rev(struct ath_hw *ah)
Sujithb5aec952009-08-07 09:45:15 +053028{
29 return (ah->eeprom.map9287.baseEepHeader.version) & 0xFFF;
30}
31
Sujith16c94ac2010-06-01 15:14:04 +053032static bool ath9k_hw_ar9287_fill_eeprom(struct ath_hw *ah)
Sujithb5aec952009-08-07 09:45:15 +053033{
34 struct ar9287_eeprom *eep = &ah->eeprom.map9287;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070035 struct ath_common *common = ath9k_hw_common(ah);
Sujithb5aec952009-08-07 09:45:15 +053036 u16 *eep_data;
37 int addr, eep_start_loc = AR9287_EEP_START_LOC;
38 eep_data = (u16 *)eep;
39
40 if (!ath9k_hw_use_flash(ah)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070041 ath_print(common, ATH_DBG_EEPROM,
42 "Reading from EEPROM, not flash\n");
Sujithb5aec952009-08-07 09:45:15 +053043 }
44
Sujith16c94ac2010-06-01 15:14:04 +053045 for (addr = 0; addr < NUM_EEP_WORDS; addr++) {
46 if (!ath9k_hw_nvram_read(common, addr + eep_start_loc,
47 eep_data)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070048 ath_print(common, ATH_DBG_EEPROM,
Frans Pop60ece402010-03-24 19:46:30 +010049 "Unable to read eeprom region\n");
Sujithb5aec952009-08-07 09:45:15 +053050 return false;
51 }
52 eep_data++;
53 }
Sujith16c94ac2010-06-01 15:14:04 +053054
Sujithb5aec952009-08-07 09:45:15 +053055 return true;
56}
57
Sujith16c94ac2010-06-01 15:14:04 +053058static int ath9k_hw_ar9287_check_eeprom(struct ath_hw *ah)
Sujithb5aec952009-08-07 09:45:15 +053059{
60 u32 sum = 0, el, integer;
61 u16 temp, word, magic, magic2, *eepdata;
62 int i, addr;
63 bool need_swap = false;
64 struct ar9287_eeprom *eep = &ah->eeprom.map9287;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070065 struct ath_common *common = ath9k_hw_common(ah);
Sujithb5aec952009-08-07 09:45:15 +053066
67 if (!ath9k_hw_use_flash(ah)) {
Sujith16c94ac2010-06-01 15:14:04 +053068 if (!ath9k_hw_nvram_read(common, AR5416_EEPROM_MAGIC_OFFSET,
69 &magic)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070070 ath_print(common, ATH_DBG_FATAL,
71 "Reading Magic # failed\n");
Sujithb5aec952009-08-07 09:45:15 +053072 return false;
73 }
74
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070075 ath_print(common, ATH_DBG_EEPROM,
76 "Read Magic = 0x%04X\n", magic);
Sujith16c94ac2010-06-01 15:14:04 +053077
Sujithb5aec952009-08-07 09:45:15 +053078 if (magic != AR5416_EEPROM_MAGIC) {
79 magic2 = swab16(magic);
80
81 if (magic2 == AR5416_EEPROM_MAGIC) {
82 need_swap = true;
83 eepdata = (u16 *)(&ah->eeprom);
84
Sujith16c94ac2010-06-01 15:14:04 +053085 for (addr = 0; addr < NUM_EEP_WORDS; addr++) {
Sujithb5aec952009-08-07 09:45:15 +053086 temp = swab16(*eepdata);
87 *eepdata = temp;
88 eepdata++;
89 }
90 } else {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070091 ath_print(common, ATH_DBG_FATAL,
92 "Invalid EEPROM Magic. "
Sujith16c94ac2010-06-01 15:14:04 +053093 "Endianness mismatch.\n");
Sujithb5aec952009-08-07 09:45:15 +053094 return -EINVAL;
95 }
96 }
97 }
Sujith16c94ac2010-06-01 15:14:04 +053098
99 ath_print(common, ATH_DBG_EEPROM, "need_swap = %s.\n",
100 need_swap ? "True" : "False");
Sujithb5aec952009-08-07 09:45:15 +0530101
102 if (need_swap)
103 el = swab16(ah->eeprom.map9287.baseEepHeader.length);
104 else
105 el = ah->eeprom.map9287.baseEepHeader.length;
106
107 if (el > sizeof(struct ar9287_eeprom))
108 el = sizeof(struct ar9287_eeprom) / sizeof(u16);
109 else
110 el = el / sizeof(u16);
111
112 eepdata = (u16 *)(&ah->eeprom);
Sujith16c94ac2010-06-01 15:14:04 +0530113
Sujithb5aec952009-08-07 09:45:15 +0530114 for (i = 0; i < el; i++)
115 sum ^= *eepdata++;
116
117 if (need_swap) {
118 word = swab16(eep->baseEepHeader.length);
119 eep->baseEepHeader.length = word;
120
121 word = swab16(eep->baseEepHeader.checksum);
122 eep->baseEepHeader.checksum = word;
123
124 word = swab16(eep->baseEepHeader.version);
125 eep->baseEepHeader.version = word;
126
127 word = swab16(eep->baseEepHeader.regDmn[0]);
128 eep->baseEepHeader.regDmn[0] = word;
129
130 word = swab16(eep->baseEepHeader.regDmn[1]);
131 eep->baseEepHeader.regDmn[1] = word;
132
133 word = swab16(eep->baseEepHeader.rfSilent);
134 eep->baseEepHeader.rfSilent = word;
135
136 word = swab16(eep->baseEepHeader.blueToothOptions);
137 eep->baseEepHeader.blueToothOptions = word;
138
139 word = swab16(eep->baseEepHeader.deviceCap);
140 eep->baseEepHeader.deviceCap = word;
141
142 integer = swab32(eep->modalHeader.antCtrlCommon);
143 eep->modalHeader.antCtrlCommon = integer;
144
145 for (i = 0; i < AR9287_MAX_CHAINS; i++) {
146 integer = swab32(eep->modalHeader.antCtrlChain[i]);
147 eep->modalHeader.antCtrlChain[i] = integer;
148 }
149
150 for (i = 0; i < AR9287_EEPROM_MODAL_SPURS; i++) {
151 word = swab16(eep->modalHeader.spurChans[i].spurChan);
152 eep->modalHeader.spurChans[i].spurChan = word;
153 }
154 }
155
156 if (sum != 0xffff || ah->eep_ops->get_eeprom_ver(ah) != AR9287_EEP_VER
157 || ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_NO_BACK_VER) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700158 ath_print(common, ATH_DBG_FATAL,
159 "Bad EEPROM checksum 0x%x or revision 0x%04x\n",
160 sum, ah->eep_ops->get_eeprom_ver(ah));
Sujithb5aec952009-08-07 09:45:15 +0530161 return -EINVAL;
162 }
163
164 return 0;
165}
166
Sujith16c94ac2010-06-01 15:14:04 +0530167static u32 ath9k_hw_ar9287_get_eeprom(struct ath_hw *ah,
Sujithb5aec952009-08-07 09:45:15 +0530168 enum eeprom_param param)
169{
170 struct ar9287_eeprom *eep = &ah->eeprom.map9287;
171 struct modal_eep_ar9287_header *pModal = &eep->modalHeader;
172 struct base_eep_ar9287_header *pBase = &eep->baseEepHeader;
173 u16 ver_minor;
174
175 ver_minor = pBase->version & AR9287_EEP_VER_MINOR_MASK;
Sujith16c94ac2010-06-01 15:14:04 +0530176
Sujithb5aec952009-08-07 09:45:15 +0530177 switch (param) {
178 case EEP_NFTHRESH_2:
179 return pModal->noiseFloorThreshCh[0];
Luis R. Rodriguez49101672010-04-15 17:39:13 -0400180 case EEP_MAC_LSW:
Sujithb5aec952009-08-07 09:45:15 +0530181 return pBase->macAddr[0] << 8 | pBase->macAddr[1];
Luis R. Rodriguez49101672010-04-15 17:39:13 -0400182 case EEP_MAC_MID:
Sujithb5aec952009-08-07 09:45:15 +0530183 return pBase->macAddr[2] << 8 | pBase->macAddr[3];
Luis R. Rodriguez49101672010-04-15 17:39:13 -0400184 case EEP_MAC_MSW:
Sujithb5aec952009-08-07 09:45:15 +0530185 return pBase->macAddr[4] << 8 | pBase->macAddr[5];
186 case EEP_REG_0:
187 return pBase->regDmn[0];
188 case EEP_REG_1:
189 return pBase->regDmn[1];
190 case EEP_OP_CAP:
191 return pBase->deviceCap;
192 case EEP_OP_MODE:
193 return pBase->opCapFlags;
194 case EEP_RF_SILENT:
195 return pBase->rfSilent;
196 case EEP_MINOR_REV:
197 return ver_minor;
198 case EEP_TX_MASK:
199 return pBase->txMask;
200 case EEP_RX_MASK:
201 return pBase->rxMask;
202 case EEP_DEV_TYPE:
203 return pBase->deviceType;
204 case EEP_OL_PWRCTRL:
205 return pBase->openLoopPwrCntl;
206 case EEP_TEMPSENSE_SLOPE:
207 if (ver_minor >= AR9287_EEP_MINOR_VER_2)
208 return pBase->tempSensSlope;
209 else
210 return 0;
211 case EEP_TEMPSENSE_SLOPE_PAL_ON:
212 if (ver_minor >= AR9287_EEP_MINOR_VER_3)
213 return pBase->tempSensSlopePalOn;
214 else
215 return 0;
216 default:
217 return 0;
218 }
219}
220
Sujith16c94ac2010-06-01 15:14:04 +0530221static void ath9k_hw_get_ar9287_gain_boundaries_pdadcs(struct ath_hw *ah,
222 struct ath9k_channel *chan,
223 struct cal_data_per_freq_ar9287 *pRawDataSet,
224 u8 *bChans, u16 availPiers,
225 u16 tPdGainOverlap,
226 int16_t *pMinCalPower,
227 u16 *pPdGainBoundaries,
228 u8 *pPDADCValues,
229 u16 numXpdGains)
Sujithb5aec952009-08-07 09:45:15 +0530230{
Sujith16c94ac2010-06-01 15:14:04 +0530231#define TMP_VAL_VPD_TABLE \
Sujithb5aec952009-08-07 09:45:15 +0530232 ((vpdTableI[i][sizeCurrVpdTable - 1] + (ss - maxIndex + 1) * vpdStep));
233
Sujith16c94ac2010-06-01 15:14:04 +0530234 int i, j, k;
235 int16_t ss;
236 u16 idxL = 0, idxR = 0, numPiers;
237 u8 *pVpdL, *pVpdR, *pPwrL, *pPwrR;
238 u8 minPwrT4[AR9287_NUM_PD_GAINS];
239 u8 maxPwrT4[AR9287_NUM_PD_GAINS];
240 int16_t vpdStep;
241 int16_t tmpVal;
242 u16 sizeCurrVpdTable, maxIndex, tgtIndex;
243 bool match;
244 int16_t minDelta = 0;
Sujithb5aec952009-08-07 09:45:15 +0530245 struct chan_centers centers;
246 static u8 vpdTableL[AR5416_EEP4K_NUM_PD_GAINS]
247 [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
248 static u8 vpdTableR[AR5416_EEP4K_NUM_PD_GAINS]
249 [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
250 static u8 vpdTableI[AR5416_EEP4K_NUM_PD_GAINS]
251 [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
252
253 ath9k_hw_get_channel_centers(ah, chan, &centers);
254
255 for (numPiers = 0; numPiers < availPiers; numPiers++) {
256 if (bChans[numPiers] == AR9287_BCHAN_UNUSED)
257 break;
258 }
259
260 match = ath9k_hw_get_lower_upper_index(
Sujith16c94ac2010-06-01 15:14:04 +0530261 (u8)FREQ2FBIN(centers.synth_center, IS_CHAN_2GHZ(chan)),
262 bChans, numPiers, &idxL, &idxR);
Sujithb5aec952009-08-07 09:45:15 +0530263
264 if (match) {
265 for (i = 0; i < numXpdGains; i++) {
266 minPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][0];
267 maxPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][4];
268 ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
Sujith16c94ac2010-06-01 15:14:04 +0530269 pRawDataSet[idxL].pwrPdg[i],
270 pRawDataSet[idxL].vpdPdg[i],
271 AR9287_PD_GAIN_ICEPTS,
272 vpdTableI[i]);
Sujithb5aec952009-08-07 09:45:15 +0530273 }
274 } else {
275 for (i = 0; i < numXpdGains; i++) {
276 pVpdL = pRawDataSet[idxL].vpdPdg[i];
277 pPwrL = pRawDataSet[idxL].pwrPdg[i];
278 pVpdR = pRawDataSet[idxR].vpdPdg[i];
279 pPwrR = pRawDataSet[idxR].pwrPdg[i];
280
281 minPwrT4[i] = max(pPwrL[0], pPwrR[0]);
282
Sujith16c94ac2010-06-01 15:14:04 +0530283 maxPwrT4[i] = min(pPwrL[AR9287_PD_GAIN_ICEPTS - 1],
284 pPwrR[AR9287_PD_GAIN_ICEPTS - 1]);
Sujithb5aec952009-08-07 09:45:15 +0530285
286 ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
Sujith16c94ac2010-06-01 15:14:04 +0530287 pPwrL, pVpdL,
288 AR9287_PD_GAIN_ICEPTS,
289 vpdTableL[i]);
Sujithb5aec952009-08-07 09:45:15 +0530290 ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
Sujith16c94ac2010-06-01 15:14:04 +0530291 pPwrR, pVpdR,
292 AR9287_PD_GAIN_ICEPTS,
293 vpdTableR[i]);
Sujithb5aec952009-08-07 09:45:15 +0530294
295 for (j = 0; j <= (maxPwrT4[i] - minPwrT4[i]) / 2; j++) {
Sujith16c94ac2010-06-01 15:14:04 +0530296 vpdTableI[i][j] = (u8)(ath9k_hw_interpolate(
297 (u16)FREQ2FBIN(centers. synth_center,
298 IS_CHAN_2GHZ(chan)),
299 bChans[idxL], bChans[idxR],
300 vpdTableL[i][j], vpdTableR[i][j]));
Sujithb5aec952009-08-07 09:45:15 +0530301 }
302 }
303 }
Sujithb5aec952009-08-07 09:45:15 +0530304
Sujith16c94ac2010-06-01 15:14:04 +0530305 *pMinCalPower = (int16_t)(minPwrT4[0] / 2);
Sujithb5aec952009-08-07 09:45:15 +0530306 k = 0;
Sujith16c94ac2010-06-01 15:14:04 +0530307
Sujithb5aec952009-08-07 09:45:15 +0530308 for (i = 0; i < numXpdGains; i++) {
309 if (i == (numXpdGains - 1))
Sujith16c94ac2010-06-01 15:14:04 +0530310 pPdGainBoundaries[i] =
311 (u16)(maxPwrT4[i] / 2);
Sujithb5aec952009-08-07 09:45:15 +0530312 else
Sujith16c94ac2010-06-01 15:14:04 +0530313 pPdGainBoundaries[i] =
314 (u16)((maxPwrT4[i] + minPwrT4[i+1]) / 4);
Sujithb5aec952009-08-07 09:45:15 +0530315
316 pPdGainBoundaries[i] = min((u16)AR5416_MAX_RATE_POWER,
Sujith16c94ac2010-06-01 15:14:04 +0530317 pPdGainBoundaries[i]);
Sujithb5aec952009-08-07 09:45:15 +0530318
319
Sujitha55f8582010-06-01 15:14:07 +0530320 minDelta = 0;
Sujithb5aec952009-08-07 09:45:15 +0530321
322 if (i == 0) {
323 if (AR_SREV_9280_10_OR_LATER(ah))
324 ss = (int16_t)(0 - (minPwrT4[i] / 2));
325 else
326 ss = 0;
Sujitha55f8582010-06-01 15:14:07 +0530327 } else {
Sujithb5aec952009-08-07 09:45:15 +0530328 ss = (int16_t)((pPdGainBoundaries[i-1] -
Sujith16c94ac2010-06-01 15:14:04 +0530329 (minPwrT4[i] / 2)) -
Sujithb5aec952009-08-07 09:45:15 +0530330 tPdGainOverlap + 1 + minDelta);
Sujitha55f8582010-06-01 15:14:07 +0530331 }
Sujithb5aec952009-08-07 09:45:15 +0530332
333 vpdStep = (int16_t)(vpdTableI[i][1] - vpdTableI[i][0]);
334 vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
Sujith16c94ac2010-06-01 15:14:04 +0530335
Sujithb5aec952009-08-07 09:45:15 +0530336 while ((ss < 0) && (k < (AR9287_NUM_PDADC_VALUES - 1))) {
337 tmpVal = (int16_t)(vpdTableI[i][0] + ss * vpdStep);
338 pPDADCValues[k++] = (u8)((tmpVal < 0) ? 0 : tmpVal);
339 ss++;
340 }
341
342 sizeCurrVpdTable = (u8)((maxPwrT4[i] - minPwrT4[i]) / 2 + 1);
343 tgtIndex = (u8)(pPdGainBoundaries[i] +
344 tPdGainOverlap - (minPwrT4[i] / 2));
345 maxIndex = (tgtIndex < sizeCurrVpdTable) ?
346 tgtIndex : sizeCurrVpdTable;
347
348 while ((ss < maxIndex) && (k < (AR9287_NUM_PDADC_VALUES - 1)))
349 pPDADCValues[k++] = vpdTableI[i][ss++];
350
351 vpdStep = (int16_t)(vpdTableI[i][sizeCurrVpdTable - 1] -
352 vpdTableI[i][sizeCurrVpdTable - 2]);
353 vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
Sujith16c94ac2010-06-01 15:14:04 +0530354
Sujithb5aec952009-08-07 09:45:15 +0530355 if (tgtIndex > maxIndex) {
356 while ((ss <= tgtIndex) &&
357 (k < (AR9287_NUM_PDADC_VALUES - 1))) {
358 tmpVal = (int16_t) TMP_VAL_VPD_TABLE;
Sujith16c94ac2010-06-01 15:14:04 +0530359 pPDADCValues[k++] =
360 (u8)((tmpVal > 255) ? 255 : tmpVal);
Sujithb5aec952009-08-07 09:45:15 +0530361 ss++;
362 }
363 }
364 }
365
366 while (i < AR9287_PD_GAINS_IN_MASK) {
367 pPdGainBoundaries[i] = pPdGainBoundaries[i-1];
368 i++;
369 }
370
371 while (k < AR9287_NUM_PDADC_VALUES) {
372 pPDADCValues[k] = pPDADCValues[k-1];
373 k++;
374 }
375
376#undef TMP_VAL_VPD_TABLE
377}
378
379static void ar9287_eeprom_get_tx_gain_index(struct ath_hw *ah,
380 struct ath9k_channel *chan,
381 struct cal_data_op_loop_ar9287 *pRawDatasetOpLoop,
Sujith16c94ac2010-06-01 15:14:04 +0530382 u8 *pCalChans, u16 availPiers, int8_t *pPwr)
Sujithb5aec952009-08-07 09:45:15 +0530383{
Sujith16c94ac2010-06-01 15:14:04 +0530384 u16 idxL = 0, idxR = 0, numPiers;
Sujithb5aec952009-08-07 09:45:15 +0530385 bool match;
386 struct chan_centers centers;
387
388 ath9k_hw_get_channel_centers(ah, chan, &centers);
389
390 for (numPiers = 0; numPiers < availPiers; numPiers++) {
391 if (pCalChans[numPiers] == AR9287_BCHAN_UNUSED)
392 break;
393 }
394
395 match = ath9k_hw_get_lower_upper_index(
Sujitha55f8582010-06-01 15:14:07 +0530396 (u8)FREQ2FBIN(centers.synth_center, IS_CHAN_2GHZ(chan)),
397 pCalChans, numPiers, &idxL, &idxR);
Sujithb5aec952009-08-07 09:45:15 +0530398
399 if (match) {
Vivek Natarajand4fe5af2009-08-14 11:32:04 +0530400 *pPwr = (int8_t) pRawDatasetOpLoop[idxL].pwrPdg[0][0];
Sujithb5aec952009-08-07 09:45:15 +0530401 } else {
Vivek Natarajand4fe5af2009-08-14 11:32:04 +0530402 *pPwr = ((int8_t) pRawDatasetOpLoop[idxL].pwrPdg[0][0] +
Sujith16c94ac2010-06-01 15:14:04 +0530403 (int8_t) pRawDatasetOpLoop[idxR].pwrPdg[0][0])/2;
Sujithb5aec952009-08-07 09:45:15 +0530404 }
405
Sujithb5aec952009-08-07 09:45:15 +0530406}
407
408static void ar9287_eeprom_olpc_set_pdadcs(struct ath_hw *ah,
409 int32_t txPower, u16 chain)
410{
411 u32 tmpVal;
412 u32 a;
413
Sujith16c94ac2010-06-01 15:14:04 +0530414 /* Enable OLPC for chain 0 */
415
Sujithb5aec952009-08-07 09:45:15 +0530416 tmpVal = REG_READ(ah, 0xa270);
417 tmpVal = tmpVal & 0xFCFFFFFF;
418 tmpVal = tmpVal | (0x3 << 24);
419 REG_WRITE(ah, 0xa270, tmpVal);
420
Sujith16c94ac2010-06-01 15:14:04 +0530421 /* Enable OLPC for chain 1 */
422
Sujithb5aec952009-08-07 09:45:15 +0530423 tmpVal = REG_READ(ah, 0xb270);
424 tmpVal = tmpVal & 0xFCFFFFFF;
425 tmpVal = tmpVal | (0x3 << 24);
426 REG_WRITE(ah, 0xb270, tmpVal);
427
Sujith16c94ac2010-06-01 15:14:04 +0530428 /* Write the OLPC ref power for chain 0 */
429
Sujithb5aec952009-08-07 09:45:15 +0530430 if (chain == 0) {
431 tmpVal = REG_READ(ah, 0xa398);
432 tmpVal = tmpVal & 0xff00ffff;
433 a = (txPower)&0xff;
434 tmpVal = tmpVal | (a << 16);
435 REG_WRITE(ah, 0xa398, tmpVal);
436 }
437
Sujith16c94ac2010-06-01 15:14:04 +0530438 /* Write the OLPC ref power for chain 1 */
439
Sujithb5aec952009-08-07 09:45:15 +0530440 if (chain == 1) {
441 tmpVal = REG_READ(ah, 0xb398);
442 tmpVal = tmpVal & 0xff00ffff;
443 a = (txPower)&0xff;
444 tmpVal = tmpVal | (a << 16);
445 REG_WRITE(ah, 0xb398, tmpVal);
446 }
447}
448
Sujith16c94ac2010-06-01 15:14:04 +0530449static void ath9k_hw_set_ar9287_power_cal_table(struct ath_hw *ah,
Sujithb5aec952009-08-07 09:45:15 +0530450 struct ath9k_channel *chan,
451 int16_t *pTxPowerIndexOffset)
452{
453 struct cal_data_per_freq_ar9287 *pRawDataset;
454 struct cal_data_op_loop_ar9287 *pRawDatasetOpenLoop;
Sujith16c94ac2010-06-01 15:14:04 +0530455 u8 *pCalBChans = NULL;
Sujithb5aec952009-08-07 09:45:15 +0530456 u16 pdGainOverlap_t2;
Sujith16c94ac2010-06-01 15:14:04 +0530457 u8 pdadcValues[AR9287_NUM_PDADC_VALUES];
Sujithb5aec952009-08-07 09:45:15 +0530458 u16 gainBoundaries[AR9287_PD_GAINS_IN_MASK];
459 u16 numPiers = 0, i, j;
Sujith16c94ac2010-06-01 15:14:04 +0530460 int16_t tMinCalPower;
Sujithb5aec952009-08-07 09:45:15 +0530461 u16 numXpdGain, xpdMask;
462 u16 xpdGainValues[AR9287_NUM_PD_GAINS] = {0, 0, 0, 0};
Sujitha55f8582010-06-01 15:14:07 +0530463 u32 reg32, regOffset, regChainOffset, regval;
Sujith16c94ac2010-06-01 15:14:04 +0530464 int16_t modalIdx, diff = 0;
Sujithb5aec952009-08-07 09:45:15 +0530465 struct ar9287_eeprom *pEepData = &ah->eeprom.map9287;
Sujith16c94ac2010-06-01 15:14:04 +0530466
Sujithb5aec952009-08-07 09:45:15 +0530467 modalIdx = IS_CHAN_2GHZ(chan) ? 1 : 0;
468 xpdMask = pEepData->modalHeader.xpdGain;
Sujith16c94ac2010-06-01 15:14:04 +0530469
Sujithb5aec952009-08-07 09:45:15 +0530470 if ((pEepData->baseEepHeader.version & AR9287_EEP_VER_MINOR_MASK) >=
Sujitha55f8582010-06-01 15:14:07 +0530471 AR9287_EEP_MINOR_VER_2)
Sujithb5aec952009-08-07 09:45:15 +0530472 pdGainOverlap_t2 = pEepData->modalHeader.pdGainOverlap;
473 else
474 pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5),
475 AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
476
477 if (IS_CHAN_2GHZ(chan)) {
478 pCalBChans = pEepData->calFreqPier2G;
479 numPiers = AR9287_NUM_2G_CAL_PIERS;
Sujith16c94ac2010-06-01 15:14:04 +0530480 if (ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
Sujithb5aec952009-08-07 09:45:15 +0530481 pRawDatasetOpenLoop =
Sujitha55f8582010-06-01 15:14:07 +0530482 (struct cal_data_op_loop_ar9287 *)pEepData->calPierData2G[0];
Sujithb5aec952009-08-07 09:45:15 +0530483 ah->initPDADC = pRawDatasetOpenLoop->vpdPdg[0][0];
484 }
485 }
486
487 numXpdGain = 0;
Sujith16c94ac2010-06-01 15:14:04 +0530488
Sujitha55f8582010-06-01 15:14:07 +0530489 /* Calculate the value of xpdgains from the xpdGain Mask */
Sujithb5aec952009-08-07 09:45:15 +0530490 for (i = 1; i <= AR9287_PD_GAINS_IN_MASK; i++) {
491 if ((xpdMask >> (AR9287_PD_GAINS_IN_MASK - i)) & 1) {
492 if (numXpdGain >= AR9287_NUM_PD_GAINS)
493 break;
494 xpdGainValues[numXpdGain] =
495 (u16)(AR9287_PD_GAINS_IN_MASK-i);
496 numXpdGain++;
497 }
498 }
499
500 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
501 (numXpdGain - 1) & 0x3);
502 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,
503 xpdGainValues[0]);
504 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
505 xpdGainValues[1]);
506 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3,
507 xpdGainValues[2]);
508
509 for (i = 0; i < AR9287_MAX_CHAINS; i++) {
510 regChainOffset = i * 0x1000;
Sujitha55f8582010-06-01 15:14:07 +0530511
Sujithb5aec952009-08-07 09:45:15 +0530512 if (pEepData->baseEepHeader.txMask & (1 << i)) {
Sujitha55f8582010-06-01 15:14:07 +0530513 pRawDatasetOpenLoop =
514 (struct cal_data_op_loop_ar9287 *)pEepData->calPierData2G[i];
515
Sujith16c94ac2010-06-01 15:14:04 +0530516 if (ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
Sujithb5aec952009-08-07 09:45:15 +0530517 int8_t txPower;
518 ar9287_eeprom_get_tx_gain_index(ah, chan,
Sujitha55f8582010-06-01 15:14:07 +0530519 pRawDatasetOpenLoop,
520 pCalBChans, numPiers,
521 &txPower);
Sujithb5aec952009-08-07 09:45:15 +0530522 ar9287_eeprom_olpc_set_pdadcs(ah, txPower, i);
523 } else {
524 pRawDataset =
525 (struct cal_data_per_freq_ar9287 *)
526 pEepData->calPierData2G[i];
Sujitha55f8582010-06-01 15:14:07 +0530527
528 ath9k_hw_get_ar9287_gain_boundaries_pdadcs(ah, chan,
529 pRawDataset,
530 pCalBChans, numPiers,
531 pdGainOverlap_t2,
532 &tMinCalPower,
533 gainBoundaries,
534 pdadcValues,
535 numXpdGain);
Sujithb5aec952009-08-07 09:45:15 +0530536 }
537
538 if (i == 0) {
Sujitha55f8582010-06-01 15:14:07 +0530539 if (!ath9k_hw_ar9287_get_eeprom(ah,
540 EEP_OL_PWRCTRL)) {
541
542 regval = SM(pdGainOverlap_t2,
543 AR_PHY_TPCRG5_PD_GAIN_OVERLAP)
544 | SM(gainBoundaries[0],
545 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1)
546 | SM(gainBoundaries[1],
547 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2)
548 | SM(gainBoundaries[2],
549 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3)
550 | SM(gainBoundaries[3],
551 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4);
552
553 REG_WRITE(ah,
554 AR_PHY_TPCRG5 + regChainOffset,
555 regval);
Sujithb5aec952009-08-07 09:45:15 +0530556 }
557 }
558
559 if ((int32_t)AR9287_PWR_TABLE_OFFSET_DB !=
Sujitha55f8582010-06-01 15:14:07 +0530560 pEepData->baseEepHeader.pwrTableOffset) {
561 diff = (u16)(pEepData->baseEepHeader.pwrTableOffset -
562 (int32_t)AR9287_PWR_TABLE_OFFSET_DB);
Sujithb5aec952009-08-07 09:45:15 +0530563 diff *= 2;
564
Sujitha55f8582010-06-01 15:14:07 +0530565 for (j = 0; j < ((u16)AR9287_NUM_PDADC_VALUES-diff); j++)
Sujithb5aec952009-08-07 09:45:15 +0530566 pdadcValues[j] = pdadcValues[j+diff];
567
568 for (j = (u16)(AR9287_NUM_PDADC_VALUES-diff);
569 j < AR9287_NUM_PDADC_VALUES; j++)
570 pdadcValues[j] =
Sujitha55f8582010-06-01 15:14:07 +0530571 pdadcValues[AR9287_NUM_PDADC_VALUES-diff];
Sujithb5aec952009-08-07 09:45:15 +0530572 }
573
Sujith16c94ac2010-06-01 15:14:04 +0530574 if (!ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
Sujitha55f8582010-06-01 15:14:07 +0530575 regOffset = AR_PHY_BASE +
576 (672 << 2) + regChainOffset;
577
Sujithb5aec952009-08-07 09:45:15 +0530578 for (j = 0; j < 32; j++) {
Sujitha55f8582010-06-01 15:14:07 +0530579 reg32 = ((pdadcValues[4*j + 0] & 0xFF) << 0)
580 | ((pdadcValues[4*j + 1] & 0xFF) << 8)
581 | ((pdadcValues[4*j + 2] & 0xFF) << 16)
582 | ((pdadcValues[4*j + 3] & 0xFF) << 24);
583
Sujithb5aec952009-08-07 09:45:15 +0530584 REG_WRITE(ah, regOffset, reg32);
Sujithb5aec952009-08-07 09:45:15 +0530585 regOffset += 4;
586 }
587 }
588 }
589 }
590
591 *pTxPowerIndexOffset = 0;
592}
593
Sujith16c94ac2010-06-01 15:14:04 +0530594static void ath9k_hw_set_ar9287_power_per_rate_table(struct ath_hw *ah,
595 struct ath9k_channel *chan,
596 int16_t *ratesArray,
597 u16 cfgCtl,
598 u16 AntennaReduction,
599 u16 twiceMaxRegulatoryPower,
600 u16 powerLimit)
Sujithb5aec952009-08-07 09:45:15 +0530601{
Sujitha55f8582010-06-01 15:14:07 +0530602#define CMP_CTL \
603 (((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == \
604 pEepData->ctlIndex[i])
605
606#define CMP_NO_CTL \
607 (((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == \
608 ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL))
609
Sujithb5aec952009-08-07 09:45:15 +0530610#define REDUCE_SCALED_POWER_BY_TWO_CHAIN 6
611#define REDUCE_SCALED_POWER_BY_THREE_CHAIN 10
Sujith16c94ac2010-06-01 15:14:04 +0530612
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700613 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithb5aec952009-08-07 09:45:15 +0530614 u16 twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
615 static const u16 tpScaleReductionTable[5] =
616 { 0, 3, 6, 9, AR5416_MAX_RATE_POWER };
617 int i;
Sujith16c94ac2010-06-01 15:14:04 +0530618 int16_t twiceLargestAntenna;
Sujithb5aec952009-08-07 09:45:15 +0530619 struct cal_ctl_data_ar9287 *rep;
620 struct cal_target_power_leg targetPowerOfdm = {0, {0, 0, 0, 0} },
621 targetPowerCck = {0, {0, 0, 0, 0} };
622 struct cal_target_power_leg targetPowerOfdmExt = {0, {0, 0, 0, 0} },
623 targetPowerCckExt = {0, {0, 0, 0, 0} };
Sujith16c94ac2010-06-01 15:14:04 +0530624 struct cal_target_power_ht targetPowerHt20,
Sujithb5aec952009-08-07 09:45:15 +0530625 targetPowerHt40 = {0, {0, 0, 0, 0} };
626 u16 scaledPower = 0, minCtlPower, maxRegAllowedPower;
Sujitha55f8582010-06-01 15:14:07 +0530627 u16 ctlModesFor11g[] = {CTL_11B,
628 CTL_11G,
629 CTL_2GHT20,
630 CTL_11B_EXT,
631 CTL_11G_EXT,
632 CTL_2GHT40};
Sujithb5aec952009-08-07 09:45:15 +0530633 u16 numCtlModes = 0, *pCtlMode = NULL, ctlMode, freq;
634 struct chan_centers centers;
635 int tx_chainmask;
636 u16 twiceMinEdgePower;
637 struct ar9287_eeprom *pEepData = &ah->eeprom.map9287;
638 tx_chainmask = ah->txchainmask;
639
640 ath9k_hw_get_channel_centers(ah, chan, &centers);
641
Sujitha55f8582010-06-01 15:14:07 +0530642 /* Compute TxPower reduction due to Antenna Gain */
Sujithb5aec952009-08-07 09:45:15 +0530643 twiceLargestAntenna = max(pEepData->modalHeader.antennaGainCh[0],
644 pEepData->modalHeader.antennaGainCh[1]);
Sujith16c94ac2010-06-01 15:14:04 +0530645 twiceLargestAntenna = (int16_t)min((AntennaReduction) -
646 twiceLargestAntenna, 0);
Sujithb5aec952009-08-07 09:45:15 +0530647
Sujitha55f8582010-06-01 15:14:07 +0530648 /*
649 * scaledPower is the minimum of the user input power level
650 * and the regulatory allowed power level.
651 */
Sujithb5aec952009-08-07 09:45:15 +0530652 maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
Sujitha55f8582010-06-01 15:14:07 +0530653
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700654 if (regulatory->tp_scale != ATH9K_TP_SCALE_MAX)
Sujithb5aec952009-08-07 09:45:15 +0530655 maxRegAllowedPower -=
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700656 (tpScaleReductionTable[(regulatory->tp_scale)] * 2);
Sujithb5aec952009-08-07 09:45:15 +0530657
658 scaledPower = min(powerLimit, maxRegAllowedPower);
659
Sujitha55f8582010-06-01 15:14:07 +0530660 /*
661 * Reduce scaled Power by number of chains active
662 * to get the per chain tx power level.
663 */
Sujithb5aec952009-08-07 09:45:15 +0530664 switch (ar5416_get_ntxchains(tx_chainmask)) {
665 case 1:
666 break;
667 case 2:
668 scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN;
669 break;
670 case 3:
671 scaledPower -= REDUCE_SCALED_POWER_BY_THREE_CHAIN;
672 break;
673 }
674 scaledPower = max((u16)0, scaledPower);
675
Sujitha55f8582010-06-01 15:14:07 +0530676 /*
677 * Get TX power from EEPROM.
678 */
Sujithb5aec952009-08-07 09:45:15 +0530679 if (IS_CHAN_2GHZ(chan)) {
Sujitha55f8582010-06-01 15:14:07 +0530680 /* CTL_11B, CTL_11G, CTL_2GHT20 */
Sujithb5aec952009-08-07 09:45:15 +0530681 numCtlModes =
682 ARRAY_SIZE(ctlModesFor11g) - SUB_NUM_CTL_MODES_AT_2G_40;
Sujith16c94ac2010-06-01 15:14:04 +0530683
Sujithb5aec952009-08-07 09:45:15 +0530684 pCtlMode = ctlModesFor11g;
685
686 ath9k_hw_get_legacy_target_powers(ah, chan,
687 pEepData->calTargetPowerCck,
688 AR9287_NUM_2G_CCK_TARGET_POWERS,
689 &targetPowerCck, 4, false);
690 ath9k_hw_get_legacy_target_powers(ah, chan,
691 pEepData->calTargetPower2G,
692 AR9287_NUM_2G_20_TARGET_POWERS,
693 &targetPowerOfdm, 4, false);
694 ath9k_hw_get_target_powers(ah, chan,
695 pEepData->calTargetPower2GHT20,
696 AR9287_NUM_2G_20_TARGET_POWERS,
697 &targetPowerHt20, 8, false);
698
699 if (IS_CHAN_HT40(chan)) {
Sujitha55f8582010-06-01 15:14:07 +0530700 /* All 2G CTLs */
Sujithb5aec952009-08-07 09:45:15 +0530701 numCtlModes = ARRAY_SIZE(ctlModesFor11g);
702 ath9k_hw_get_target_powers(ah, chan,
703 pEepData->calTargetPower2GHT40,
704 AR9287_NUM_2G_40_TARGET_POWERS,
705 &targetPowerHt40, 8, true);
706 ath9k_hw_get_legacy_target_powers(ah, chan,
707 pEepData->calTargetPowerCck,
708 AR9287_NUM_2G_CCK_TARGET_POWERS,
709 &targetPowerCckExt, 4, true);
710 ath9k_hw_get_legacy_target_powers(ah, chan,
711 pEepData->calTargetPower2G,
712 AR9287_NUM_2G_20_TARGET_POWERS,
713 &targetPowerOfdmExt, 4, true);
714 }
715 }
716
717 for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
Sujitha55f8582010-06-01 15:14:07 +0530718 bool isHt40CtlMode =
719 (pCtlMode[ctlMode] == CTL_2GHT40) ? true : false;
720
Sujithb5aec952009-08-07 09:45:15 +0530721 if (isHt40CtlMode)
722 freq = centers.synth_center;
723 else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
724 freq = centers.ext_center;
725 else
726 freq = centers.ctl_center;
727
Sujitha55f8582010-06-01 15:14:07 +0530728 /* Walk through the CTL indices stored in EEPROM */
Sujithb5aec952009-08-07 09:45:15 +0530729 for (i = 0; (i < AR9287_NUM_CTLS) && pEepData->ctlIndex[i]; i++) {
Sujitha55f8582010-06-01 15:14:07 +0530730 struct cal_ctl_edges *pRdEdgesPower;
Sujithb5aec952009-08-07 09:45:15 +0530731
Sujitha55f8582010-06-01 15:14:07 +0530732 /*
733 * Compare test group from regulatory channel list
734 * with test mode from pCtlMode list
735 */
736 if (CMP_CTL || CMP_NO_CTL) {
Sujithb5aec952009-08-07 09:45:15 +0530737 rep = &(pEepData->ctlData[i]);
Sujitha55f8582010-06-01 15:14:07 +0530738 pRdEdgesPower =
739 rep->ctlEdges[ar5416_get_ntxchains(tx_chainmask) - 1];
Sujithb5aec952009-08-07 09:45:15 +0530740
Sujitha55f8582010-06-01 15:14:07 +0530741 twiceMinEdgePower = ath9k_hw_get_max_edge_power(freq,
742 pRdEdgesPower,
743 IS_CHAN_2GHZ(chan),
744 AR5416_NUM_BAND_EDGES);
745
746 if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {
747 twiceMaxEdgePower = min(twiceMaxEdgePower,
748 twiceMinEdgePower);
749 } else {
Sujithb5aec952009-08-07 09:45:15 +0530750 twiceMaxEdgePower = twiceMinEdgePower;
751 break;
752 }
753 }
754 }
755
756 minCtlPower = (u8)min(twiceMaxEdgePower, scaledPower);
757
Sujitha55f8582010-06-01 15:14:07 +0530758 /* Apply ctl mode to correct target power set */
Sujithb5aec952009-08-07 09:45:15 +0530759 switch (pCtlMode[ctlMode]) {
760 case CTL_11B:
Sujitha55f8582010-06-01 15:14:07 +0530761 for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x); i++) {
762 targetPowerCck.tPow2x[i] =
763 (u8)min((u16)targetPowerCck.tPow2x[i],
764 minCtlPower);
Sujithb5aec952009-08-07 09:45:15 +0530765 }
766 break;
767 case CTL_11A:
768 case CTL_11G:
Sujitha55f8582010-06-01 15:14:07 +0530769 for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x); i++) {
770 targetPowerOfdm.tPow2x[i] =
771 (u8)min((u16)targetPowerOfdm.tPow2x[i],
772 minCtlPower);
Sujithb5aec952009-08-07 09:45:15 +0530773 }
774 break;
775 case CTL_5GHT20:
776 case CTL_2GHT20:
Sujitha55f8582010-06-01 15:14:07 +0530777 for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) {
778 targetPowerHt20.tPow2x[i] =
779 (u8)min((u16)targetPowerHt20.tPow2x[i],
780 minCtlPower);
Sujithb5aec952009-08-07 09:45:15 +0530781 }
782 break;
783 case CTL_11B_EXT:
Sujitha55f8582010-06-01 15:14:07 +0530784 targetPowerCckExt.tPow2x[0] =
785 (u8)min((u16)targetPowerCckExt.tPow2x[0],
786 minCtlPower);
Sujithb5aec952009-08-07 09:45:15 +0530787 break;
788 case CTL_11A_EXT:
789 case CTL_11G_EXT:
Sujitha55f8582010-06-01 15:14:07 +0530790 targetPowerOfdmExt.tPow2x[0] =
791 (u8)min((u16)targetPowerOfdmExt.tPow2x[0],
792 minCtlPower);
Sujithb5aec952009-08-07 09:45:15 +0530793 break;
794 case CTL_5GHT40:
795 case CTL_2GHT40:
Sujitha55f8582010-06-01 15:14:07 +0530796 for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
797 targetPowerHt40.tPow2x[i] =
798 (u8)min((u16)targetPowerHt40.tPow2x[i],
799 minCtlPower);
Sujithb5aec952009-08-07 09:45:15 +0530800 }
801 break;
802 default:
803 break;
804 }
805 }
806
Sujitha55f8582010-06-01 15:14:07 +0530807 /* Now set the rates array */
808
Sujithb5aec952009-08-07 09:45:15 +0530809 ratesArray[rate6mb] =
810 ratesArray[rate9mb] =
811 ratesArray[rate12mb] =
812 ratesArray[rate18mb] =
Sujitha55f8582010-06-01 15:14:07 +0530813 ratesArray[rate24mb] = targetPowerOfdm.tPow2x[0];
Sujithb5aec952009-08-07 09:45:15 +0530814
815 ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1];
816 ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2];
817 ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3];
818 ratesArray[rateXr] = targetPowerOfdm.tPow2x[0];
819
820 for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++)
821 ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i];
822
823 if (IS_CHAN_2GHZ(chan)) {
824 ratesArray[rate1l] = targetPowerCck.tPow2x[0];
Sujitha55f8582010-06-01 15:14:07 +0530825 ratesArray[rate2s] =
826 ratesArray[rate2l] = targetPowerCck.tPow2x[1];
827 ratesArray[rate5_5s] =
828 ratesArray[rate5_5l] = targetPowerCck.tPow2x[2];
829 ratesArray[rate11s] =
830 ratesArray[rate11l] = targetPowerCck.tPow2x[3];
Sujithb5aec952009-08-07 09:45:15 +0530831 }
832 if (IS_CHAN_HT40(chan)) {
833 for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++)
834 ratesArray[rateHt40_0 + i] = targetPowerHt40.tPow2x[i];
835
836 ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0];
837 ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0];
838 ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0];
Sujitha55f8582010-06-01 15:14:07 +0530839
Sujithb5aec952009-08-07 09:45:15 +0530840 if (IS_CHAN_2GHZ(chan))
841 ratesArray[rateExtCck] = targetPowerCckExt.tPow2x[0];
842 }
843
Sujitha55f8582010-06-01 15:14:07 +0530844#undef CMP_CTL
845#undef CMP_NO_CTL
Sujithb5aec952009-08-07 09:45:15 +0530846#undef REDUCE_SCALED_POWER_BY_TWO_CHAIN
847#undef REDUCE_SCALED_POWER_BY_THREE_CHAIN
848}
849
Sujith16c94ac2010-06-01 15:14:04 +0530850static void ath9k_hw_ar9287_set_txpower(struct ath_hw *ah,
Sujithb5aec952009-08-07 09:45:15 +0530851 struct ath9k_channel *chan, u16 cfgCtl,
852 u8 twiceAntennaReduction,
853 u8 twiceMaxRegulatoryPower,
854 u8 powerLimit)
855{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700856 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithb5aec952009-08-07 09:45:15 +0530857 struct ar9287_eeprom *pEepData = &ah->eeprom.map9287;
858 struct modal_eep_ar9287_header *pModal = &pEepData->modalHeader;
859 int16_t ratesArray[Ar5416RateSize];
Sujith16c94ac2010-06-01 15:14:04 +0530860 int16_t txPowerIndexOffset = 0;
Sujithb5aec952009-08-07 09:45:15 +0530861 u8 ht40PowerIncForPdadc = 2;
862 int i;
863
864 memset(ratesArray, 0, sizeof(ratesArray));
865
866 if ((pEepData->baseEepHeader.version & AR9287_EEP_VER_MINOR_MASK) >=
867 AR9287_EEP_MINOR_VER_2)
868 ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
869
Sujith16c94ac2010-06-01 15:14:04 +0530870 ath9k_hw_set_ar9287_power_per_rate_table(ah, chan,
Sujithb5aec952009-08-07 09:45:15 +0530871 &ratesArray[0], cfgCtl,
872 twiceAntennaReduction,
873 twiceMaxRegulatoryPower,
874 powerLimit);
875
Sujith16c94ac2010-06-01 15:14:04 +0530876 ath9k_hw_set_ar9287_power_cal_table(ah, chan, &txPowerIndexOffset);
Sujithb5aec952009-08-07 09:45:15 +0530877
878 for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
879 ratesArray[i] = (int16_t)(txPowerIndexOffset + ratesArray[i]);
880 if (ratesArray[i] > AR9287_MAX_RATE_POWER)
881 ratesArray[i] = AR9287_MAX_RATE_POWER;
882 }
883
884 if (AR_SREV_9280_10_OR_LATER(ah)) {
885 for (i = 0; i < Ar5416RateSize; i++)
886 ratesArray[i] -= AR9287_PWR_TABLE_OFFSET_DB * 2;
887 }
888
Sujitha55f8582010-06-01 15:14:07 +0530889 /* OFDM power per rate */
Sujithb5aec952009-08-07 09:45:15 +0530890 REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
891 ATH9K_POW_SM(ratesArray[rate18mb], 24)
892 | ATH9K_POW_SM(ratesArray[rate12mb], 16)
893 | ATH9K_POW_SM(ratesArray[rate9mb], 8)
894 | ATH9K_POW_SM(ratesArray[rate6mb], 0));
895
896 REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
897 ATH9K_POW_SM(ratesArray[rate54mb], 24)
898 | ATH9K_POW_SM(ratesArray[rate48mb], 16)
899 | ATH9K_POW_SM(ratesArray[rate36mb], 8)
900 | ATH9K_POW_SM(ratesArray[rate24mb], 0));
901
Sujitha55f8582010-06-01 15:14:07 +0530902 /* CCK power per rate */
Sujithb5aec952009-08-07 09:45:15 +0530903 if (IS_CHAN_2GHZ(chan)) {
904 REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
905 ATH9K_POW_SM(ratesArray[rate2s], 24)
906 | ATH9K_POW_SM(ratesArray[rate2l], 16)
907 | ATH9K_POW_SM(ratesArray[rateXr], 8)
908 | ATH9K_POW_SM(ratesArray[rate1l], 0));
909 REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
910 ATH9K_POW_SM(ratesArray[rate11s], 24)
911 | ATH9K_POW_SM(ratesArray[rate11l], 16)
912 | ATH9K_POW_SM(ratesArray[rate5_5s], 8)
913 | ATH9K_POW_SM(ratesArray[rate5_5l], 0));
914 }
915
Sujitha55f8582010-06-01 15:14:07 +0530916 /* HT20 power per rate */
Sujithb5aec952009-08-07 09:45:15 +0530917 REG_WRITE(ah, AR_PHY_POWER_TX_RATE5,
918 ATH9K_POW_SM(ratesArray[rateHt20_3], 24)
919 | ATH9K_POW_SM(ratesArray[rateHt20_2], 16)
920 | ATH9K_POW_SM(ratesArray[rateHt20_1], 8)
921 | ATH9K_POW_SM(ratesArray[rateHt20_0], 0));
922
923 REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
924 ATH9K_POW_SM(ratesArray[rateHt20_7], 24)
925 | ATH9K_POW_SM(ratesArray[rateHt20_6], 16)
926 | ATH9K_POW_SM(ratesArray[rateHt20_5], 8)
927 | ATH9K_POW_SM(ratesArray[rateHt20_4], 0));
928
Sujitha55f8582010-06-01 15:14:07 +0530929 /* HT40 power per rate */
Sujithb5aec952009-08-07 09:45:15 +0530930 if (IS_CHAN_HT40(chan)) {
Sujith16c94ac2010-06-01 15:14:04 +0530931 if (ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
Sujithb5aec952009-08-07 09:45:15 +0530932 REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
933 ATH9K_POW_SM(ratesArray[rateHt40_3], 24)
934 | ATH9K_POW_SM(ratesArray[rateHt40_2], 16)
935 | ATH9K_POW_SM(ratesArray[rateHt40_1], 8)
936 | ATH9K_POW_SM(ratesArray[rateHt40_0], 0));
937
938 REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
939 ATH9K_POW_SM(ratesArray[rateHt40_7], 24)
940 | ATH9K_POW_SM(ratesArray[rateHt40_6], 16)
941 | ATH9K_POW_SM(ratesArray[rateHt40_5], 8)
942 | ATH9K_POW_SM(ratesArray[rateHt40_4], 0));
943 } else {
944 REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
945 ATH9K_POW_SM(ratesArray[rateHt40_3] +
946 ht40PowerIncForPdadc, 24)
947 | ATH9K_POW_SM(ratesArray[rateHt40_2] +
948 ht40PowerIncForPdadc, 16)
949 | ATH9K_POW_SM(ratesArray[rateHt40_1] +
950 ht40PowerIncForPdadc, 8)
951 | ATH9K_POW_SM(ratesArray[rateHt40_0] +
952 ht40PowerIncForPdadc, 0));
953
954 REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
955 ATH9K_POW_SM(ratesArray[rateHt40_7] +
956 ht40PowerIncForPdadc, 24)
957 | ATH9K_POW_SM(ratesArray[rateHt40_6] +
958 ht40PowerIncForPdadc, 16)
959 | ATH9K_POW_SM(ratesArray[rateHt40_5] +
960 ht40PowerIncForPdadc, 8)
961 | ATH9K_POW_SM(ratesArray[rateHt40_4] +
962 ht40PowerIncForPdadc, 0));
963 }
964
Sujitha55f8582010-06-01 15:14:07 +0530965 /* Dup/Ext power per rate */
Sujithb5aec952009-08-07 09:45:15 +0530966 REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
967 ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
968 | ATH9K_POW_SM(ratesArray[rateExtCck], 16)
969 | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
970 | ATH9K_POW_SM(ratesArray[rateDupCck], 0));
971 }
972
973 if (IS_CHAN_2GHZ(chan))
974 i = rate1l;
975 else
976 i = rate6mb;
977
978 if (AR_SREV_9280_10_OR_LATER(ah))
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700979 regulatory->max_power_level =
Sujithb5aec952009-08-07 09:45:15 +0530980 ratesArray[i] + AR9287_PWR_TABLE_OFFSET_DB * 2;
981 else
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700982 regulatory->max_power_level = ratesArray[i];
Sujithb5aec952009-08-07 09:45:15 +0530983}
984
Sujith16c94ac2010-06-01 15:14:04 +0530985static void ath9k_hw_ar9287_set_addac(struct ath_hw *ah,
Sujithb5aec952009-08-07 09:45:15 +0530986 struct ath9k_channel *chan)
987{
988}
989
Sujith16c94ac2010-06-01 15:14:04 +0530990static void ath9k_hw_ar9287_set_board_values(struct ath_hw *ah,
Sujithb5aec952009-08-07 09:45:15 +0530991 struct ath9k_channel *chan)
992{
993 struct ar9287_eeprom *eep = &ah->eeprom.map9287;
994 struct modal_eep_ar9287_header *pModal = &eep->modalHeader;
995 u16 antWrites[AR9287_ANT_16S];
Sujith79d7f4b2010-06-01 15:14:06 +0530996 u32 regChainOffset, regval;
Sujithb5aec952009-08-07 09:45:15 +0530997 u8 txRxAttenLocal;
998 int i, j, offset_num;
999
1000 pModal = &eep->modalHeader;
1001
1002 antWrites[0] = (u16)((pModal->antCtrlCommon >> 28) & 0xF);
1003 antWrites[1] = (u16)((pModal->antCtrlCommon >> 24) & 0xF);
1004 antWrites[2] = (u16)((pModal->antCtrlCommon >> 20) & 0xF);
1005 antWrites[3] = (u16)((pModal->antCtrlCommon >> 16) & 0xF);
1006 antWrites[4] = (u16)((pModal->antCtrlCommon >> 12) & 0xF);
1007 antWrites[5] = (u16)((pModal->antCtrlCommon >> 8) & 0xF);
1008 antWrites[6] = (u16)((pModal->antCtrlCommon >> 4) & 0xF);
1009 antWrites[7] = (u16)(pModal->antCtrlCommon & 0xF);
1010
1011 offset_num = 8;
1012
1013 for (i = 0, j = offset_num; i < AR9287_MAX_CHAINS; i++) {
1014 antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 28) & 0xf);
1015 antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 10) & 0x3);
1016 antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 8) & 0x3);
1017 antWrites[j++] = 0;
1018 antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 6) & 0x3);
1019 antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 4) & 0x3);
1020 antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 2) & 0x3);
1021 antWrites[j++] = (u16)(pModal->antCtrlChain[i] & 0x3);
1022 }
1023
1024 REG_WRITE(ah, AR_PHY_SWITCH_COM,
1025 ah->eep_ops->get_eeprom_antenna_cfg(ah, chan));
1026
1027 for (i = 0; i < AR9287_MAX_CHAINS; i++) {
1028 regChainOffset = i * 0x1000;
1029
1030 REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
1031 pModal->antCtrlChain[i]);
1032
1033 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
1034 (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset)
1035 & ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
1036 AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
1037 SM(pModal->iqCalICh[i],
1038 AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
1039 SM(pModal->iqCalQCh[i],
1040 AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
1041
1042 txRxAttenLocal = pModal->txRxAttenCh[i];
1043
1044 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
1045 AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN,
1046 pModal->bswMargin[i]);
1047 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
1048 AR_PHY_GAIN_2GHZ_XATTEN1_DB,
1049 pModal->bswAtten[i]);
1050 REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
1051 AR9280_PHY_RXGAIN_TXRX_ATTEN,
1052 txRxAttenLocal);
1053 REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
1054 AR9280_PHY_RXGAIN_TXRX_MARGIN,
1055 pModal->rxTxMarginCh[i]);
1056 }
1057
1058
1059 if (IS_CHAN_HT40(chan))
1060 REG_RMW_FIELD(ah, AR_PHY_SETTLING,
1061 AR_PHY_SETTLING_SWITCH, pModal->swSettleHt40);
1062 else
1063 REG_RMW_FIELD(ah, AR_PHY_SETTLING,
1064 AR_PHY_SETTLING_SWITCH, pModal->switchSettling);
1065
1066 REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
1067 AR_PHY_DESIRED_SZ_ADC, pModal->adcDesiredSize);
1068
1069 REG_WRITE(ah, AR_PHY_RF_CTL4,
1070 SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF)
1071 | SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAB_OFF)
1072 | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAA_ON)
1073 | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAB_ON));
1074
1075 REG_RMW_FIELD(ah, AR_PHY_RF_CTL3,
1076 AR_PHY_TX_END_TO_A2_RX_ON, pModal->txEndToRxOn);
1077
1078 REG_RMW_FIELD(ah, AR_PHY_CCA,
1079 AR9280_PHY_CCA_THRESH62, pModal->thresh62);
1080 REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0,
1081 AR_PHY_EXT_CCA0_THRESH62, pModal->thresh62);
1082
Sujith79d7f4b2010-06-01 15:14:06 +05301083 regval = REG_READ(ah, AR9287_AN_RF2G3_CH0);
1084 regval &= ~(AR9287_AN_RF2G3_DB1 |
1085 AR9287_AN_RF2G3_DB2 |
1086 AR9287_AN_RF2G3_OB_CCK |
1087 AR9287_AN_RF2G3_OB_PSK |
1088 AR9287_AN_RF2G3_OB_QAM |
1089 AR9287_AN_RF2G3_OB_PAL_OFF);
1090 regval |= (SM(pModal->db1, AR9287_AN_RF2G3_DB1) |
1091 SM(pModal->db2, AR9287_AN_RF2G3_DB2) |
1092 SM(pModal->ob_cck, AR9287_AN_RF2G3_OB_CCK) |
1093 SM(pModal->ob_psk, AR9287_AN_RF2G3_OB_PSK) |
1094 SM(pModal->ob_qam, AR9287_AN_RF2G3_OB_QAM) |
1095 SM(pModal->ob_pal_off, AR9287_AN_RF2G3_OB_PAL_OFF));
Sujithb5aec952009-08-07 09:45:15 +05301096
Sujith79d7f4b2010-06-01 15:14:06 +05301097 ath9k_hw_analog_shift_regwrite(ah, AR9287_AN_RF2G3_CH0, regval);
1098
1099 regval = REG_READ(ah, AR9287_AN_RF2G3_CH1);
1100 regval &= ~(AR9287_AN_RF2G3_DB1 |
1101 AR9287_AN_RF2G3_DB2 |
1102 AR9287_AN_RF2G3_OB_CCK |
1103 AR9287_AN_RF2G3_OB_PSK |
1104 AR9287_AN_RF2G3_OB_QAM |
1105 AR9287_AN_RF2G3_OB_PAL_OFF);
1106 regval |= (SM(pModal->db1, AR9287_AN_RF2G3_DB1) |
1107 SM(pModal->db2, AR9287_AN_RF2G3_DB2) |
1108 SM(pModal->ob_cck, AR9287_AN_RF2G3_OB_CCK) |
1109 SM(pModal->ob_psk, AR9287_AN_RF2G3_OB_PSK) |
1110 SM(pModal->ob_qam, AR9287_AN_RF2G3_OB_QAM) |
1111 SM(pModal->ob_pal_off, AR9287_AN_RF2G3_OB_PAL_OFF));
1112
1113 ath9k_hw_analog_shift_regwrite(ah, AR9287_AN_RF2G3_CH1, regval);
Sujithb5aec952009-08-07 09:45:15 +05301114
1115 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
1116 AR_PHY_TX_END_DATA_START, pModal->txFrameToDataStart);
1117 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
1118 AR_PHY_TX_END_PA_ON, pModal->txFrameToPaOn);
1119
1120 ath9k_hw_analog_shift_rmw(ah, AR9287_AN_TOP2,
1121 AR9287_AN_TOP2_XPABIAS_LVL,
1122 AR9287_AN_TOP2_XPABIAS_LVL_S,
1123 pModal->xpaBiasLvl);
1124}
1125
Sujith16c94ac2010-06-01 15:14:04 +05301126static u8 ath9k_hw_ar9287_get_num_ant_config(struct ath_hw *ah,
Sujithb5aec952009-08-07 09:45:15 +05301127 enum ieee80211_band freq_band)
1128{
1129 return 1;
1130}
1131
Sujith16c94ac2010-06-01 15:14:04 +05301132static u16 ath9k_hw_ar9287_get_eeprom_antenna_cfg(struct ath_hw *ah,
Sujithb5aec952009-08-07 09:45:15 +05301133 struct ath9k_channel *chan)
1134{
1135 struct ar9287_eeprom *eep = &ah->eeprom.map9287;
1136 struct modal_eep_ar9287_header *pModal = &eep->modalHeader;
1137
1138 return pModal->antCtrlCommon & 0xFFFF;
1139}
1140
Sujith16c94ac2010-06-01 15:14:04 +05301141static u16 ath9k_hw_ar9287_get_spur_channel(struct ath_hw *ah,
Sujithb5aec952009-08-07 09:45:15 +05301142 u16 i, bool is2GHz)
1143{
1144#define EEP_MAP9287_SPURCHAN \
1145 (ah->eeprom.map9287.modalHeader.spurChans[i].spurChan)
Sujith16c94ac2010-06-01 15:14:04 +05301146
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001147 struct ath_common *common = ath9k_hw_common(ah);
Sujithb5aec952009-08-07 09:45:15 +05301148 u16 spur_val = AR_NO_SPUR;
1149
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001150 ath_print(common, ATH_DBG_ANI,
1151 "Getting spur idx %d is2Ghz. %d val %x\n",
1152 i, is2GHz, ah->config.spurchans[i][is2GHz]);
Sujithb5aec952009-08-07 09:45:15 +05301153
1154 switch (ah->config.spurmode) {
1155 case SPUR_DISABLE:
1156 break;
1157 case SPUR_ENABLE_IOCTL:
1158 spur_val = ah->config.spurchans[i][is2GHz];
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001159 ath_print(common, ATH_DBG_ANI,
1160 "Getting spur val from new loc. %d\n", spur_val);
Sujithb5aec952009-08-07 09:45:15 +05301161 break;
1162 case SPUR_ENABLE_EEPROM:
1163 spur_val = EEP_MAP9287_SPURCHAN;
1164 break;
1165 }
1166
1167 return spur_val;
1168
1169#undef EEP_MAP9287_SPURCHAN
1170}
1171
Luis R. Rodriguez0b8f6f2b12010-04-15 17:39:12 -04001172const struct eeprom_ops eep_ar9287_ops = {
Sujith16c94ac2010-06-01 15:14:04 +05301173 .check_eeprom = ath9k_hw_ar9287_check_eeprom,
1174 .get_eeprom = ath9k_hw_ar9287_get_eeprom,
1175 .fill_eeprom = ath9k_hw_ar9287_fill_eeprom,
1176 .get_eeprom_ver = ath9k_hw_ar9287_get_eeprom_ver,
1177 .get_eeprom_rev = ath9k_hw_ar9287_get_eeprom_rev,
1178 .get_num_ant_config = ath9k_hw_ar9287_get_num_ant_config,
1179 .get_eeprom_antenna_cfg = ath9k_hw_ar9287_get_eeprom_antenna_cfg,
1180 .set_board_values = ath9k_hw_ar9287_set_board_values,
1181 .set_addac = ath9k_hw_ar9287_set_addac,
1182 .set_txpower = ath9k_hw_ar9287_set_txpower,
1183 .get_spur_channel = ath9k_hw_ar9287_get_spur_channel
Sujithb5aec952009-08-07 09:45:15 +05301184};