blob: 2384a9f4f5fb481b5ca0cb1fc005ddc1e3b4014a [file] [log] [blame]
Sujithb5aec952009-08-07 09:45:15 +05301/*
2 * Copyright (c) 2008-2009 Atheros Communications Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070017#include "hw.h"
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -040018#include "ar9002_phy.h"
Sujithb5aec952009-08-07 09:45:15 +053019
20static int ath9k_hw_4k_get_eeprom_ver(struct ath_hw *ah)
21{
22 return ((ah->eeprom.map4k.baseEepHeader.version >> 12) & 0xF);
23}
24
25static int ath9k_hw_4k_get_eeprom_rev(struct ath_hw *ah)
26{
27 return ((ah->eeprom.map4k.baseEepHeader.version) & 0xFFF);
28}
29
30static bool ath9k_hw_4k_fill_eeprom(struct ath_hw *ah)
31{
32#define SIZE_EEPROM_4K (sizeof(struct ar5416_eeprom_4k) / sizeof(u16))
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070033 struct ath_common *common = ath9k_hw_common(ah);
Sujithb5aec952009-08-07 09:45:15 +053034 u16 *eep_data = (u16 *)&ah->eeprom.map4k;
35 int addr, eep_start_loc = 0;
36
37 eep_start_loc = 64;
38
39 if (!ath9k_hw_use_flash(ah)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070040 ath_print(common, ATH_DBG_EEPROM,
41 "Reading from EEPROM, not flash\n");
Sujithb5aec952009-08-07 09:45:15 +053042 }
43
44 for (addr = 0; addr < SIZE_EEPROM_4K; addr++) {
Luis R. Rodriguez5bb12792009-09-14 00:55:09 -070045 if (!ath9k_hw_nvram_read(common, addr + eep_start_loc, eep_data)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070046 ath_print(common, ATH_DBG_EEPROM,
Frans Pop60ece402010-03-24 19:46:30 +010047 "Unable to read eeprom region\n");
Sujithb5aec952009-08-07 09:45:15 +053048 return false;
49 }
50 eep_data++;
51 }
52
53 return true;
54#undef SIZE_EEPROM_4K
55}
56
57static int ath9k_hw_4k_check_eeprom(struct ath_hw *ah)
58{
59#define EEPROM_4K_SIZE (sizeof(struct ar5416_eeprom_4k) / sizeof(u16))
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070060 struct ath_common *common = ath9k_hw_common(ah);
Sujithb5aec952009-08-07 09:45:15 +053061 struct ar5416_eeprom_4k *eep =
62 (struct ar5416_eeprom_4k *) &ah->eeprom.map4k;
63 u16 *eepdata, temp, magic, magic2;
64 u32 sum = 0, el;
65 bool need_swap = false;
66 int i, addr;
67
68
69 if (!ath9k_hw_use_flash(ah)) {
Luis R. Rodriguez5bb12792009-09-14 00:55:09 -070070 if (!ath9k_hw_nvram_read(common, AR5416_EEPROM_MAGIC_OFFSET,
Sujithb5aec952009-08-07 09:45:15 +053071 &magic)) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070072 ath_print(common, ATH_DBG_FATAL,
73 "Reading Magic # failed\n");
Sujithb5aec952009-08-07 09:45:15 +053074 return false;
75 }
76
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070077 ath_print(common, ATH_DBG_EEPROM,
78 "Read Magic = 0x%04X\n", magic);
Sujithb5aec952009-08-07 09:45:15 +053079
80 if (magic != AR5416_EEPROM_MAGIC) {
81 magic2 = swab16(magic);
82
83 if (magic2 == AR5416_EEPROM_MAGIC) {
84 need_swap = true;
85 eepdata = (u16 *) (&ah->eeprom);
86
87 for (addr = 0; addr < EEPROM_4K_SIZE; addr++) {
88 temp = swab16(*eepdata);
89 *eepdata = temp;
90 eepdata++;
91 }
92 } else {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070093 ath_print(common, ATH_DBG_FATAL,
94 "Invalid EEPROM Magic. "
95 "endianness mismatch.\n");
Sujithb5aec952009-08-07 09:45:15 +053096 return -EINVAL;
97 }
98 }
99 }
100
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700101 ath_print(common, ATH_DBG_EEPROM, "need_swap = %s.\n",
102 need_swap ? "True" : "False");
Sujithb5aec952009-08-07 09:45:15 +0530103
104 if (need_swap)
105 el = swab16(ah->eeprom.map4k.baseEepHeader.length);
106 else
107 el = ah->eeprom.map4k.baseEepHeader.length;
108
109 if (el > sizeof(struct ar5416_eeprom_4k))
110 el = sizeof(struct ar5416_eeprom_4k) / sizeof(u16);
111 else
112 el = el / sizeof(u16);
113
114 eepdata = (u16 *)(&ah->eeprom);
115
116 for (i = 0; i < el; i++)
117 sum ^= *eepdata++;
118
119 if (need_swap) {
120 u32 integer;
121 u16 word;
122
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700123 ath_print(common, ATH_DBG_EEPROM,
124 "EEPROM Endianness is not native.. Changing\n");
Sujithb5aec952009-08-07 09:45:15 +0530125
126 word = swab16(eep->baseEepHeader.length);
127 eep->baseEepHeader.length = word;
128
129 word = swab16(eep->baseEepHeader.checksum);
130 eep->baseEepHeader.checksum = word;
131
132 word = swab16(eep->baseEepHeader.version);
133 eep->baseEepHeader.version = word;
134
135 word = swab16(eep->baseEepHeader.regDmn[0]);
136 eep->baseEepHeader.regDmn[0] = word;
137
138 word = swab16(eep->baseEepHeader.regDmn[1]);
139 eep->baseEepHeader.regDmn[1] = word;
140
141 word = swab16(eep->baseEepHeader.rfSilent);
142 eep->baseEepHeader.rfSilent = word;
143
144 word = swab16(eep->baseEepHeader.blueToothOptions);
145 eep->baseEepHeader.blueToothOptions = word;
146
147 word = swab16(eep->baseEepHeader.deviceCap);
148 eep->baseEepHeader.deviceCap = word;
149
150 integer = swab32(eep->modalHeader.antCtrlCommon);
151 eep->modalHeader.antCtrlCommon = integer;
152
153 for (i = 0; i < AR5416_EEP4K_MAX_CHAINS; i++) {
154 integer = swab32(eep->modalHeader.antCtrlChain[i]);
155 eep->modalHeader.antCtrlChain[i] = integer;
156 }
157
158 for (i = 0; i < AR5416_EEPROM_MODAL_SPURS; i++) {
159 word = swab16(eep->modalHeader.spurChans[i].spurChan);
160 eep->modalHeader.spurChans[i].spurChan = word;
161 }
162 }
163
164 if (sum != 0xffff || ah->eep_ops->get_eeprom_ver(ah) != AR5416_EEP_VER ||
165 ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_NO_BACK_VER) {
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700166 ath_print(common, ATH_DBG_FATAL,
167 "Bad EEPROM checksum 0x%x or revision 0x%04x\n",
168 sum, ah->eep_ops->get_eeprom_ver(ah));
Sujithb5aec952009-08-07 09:45:15 +0530169 return -EINVAL;
170 }
171
172 return 0;
173#undef EEPROM_4K_SIZE
174}
175
176static u32 ath9k_hw_4k_get_eeprom(struct ath_hw *ah,
177 enum eeprom_param param)
178{
179 struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k;
180 struct modal_eep_4k_header *pModal = &eep->modalHeader;
181 struct base_eep_header_4k *pBase = &eep->baseEepHeader;
182
183 switch (param) {
184 case EEP_NFTHRESH_2:
185 return pModal->noiseFloorThreshCh[0];
Luis R. Rodriguez49101672010-04-15 17:39:13 -0400186 case EEP_MAC_LSW:
Sujithb5aec952009-08-07 09:45:15 +0530187 return pBase->macAddr[0] << 8 | pBase->macAddr[1];
Luis R. Rodriguez49101672010-04-15 17:39:13 -0400188 case EEP_MAC_MID:
Sujithb5aec952009-08-07 09:45:15 +0530189 return pBase->macAddr[2] << 8 | pBase->macAddr[3];
Luis R. Rodriguez49101672010-04-15 17:39:13 -0400190 case EEP_MAC_MSW:
Sujithb5aec952009-08-07 09:45:15 +0530191 return pBase->macAddr[4] << 8 | pBase->macAddr[5];
192 case EEP_REG_0:
193 return pBase->regDmn[0];
194 case EEP_REG_1:
195 return pBase->regDmn[1];
196 case EEP_OP_CAP:
197 return pBase->deviceCap;
198 case EEP_OP_MODE:
199 return pBase->opCapFlags;
200 case EEP_RF_SILENT:
201 return pBase->rfSilent;
202 case EEP_OB_2:
Sujith7f638452009-08-07 09:45:23 +0530203 return pModal->ob_0;
Sujithb5aec952009-08-07 09:45:15 +0530204 case EEP_DB_2:
Sujith7f638452009-08-07 09:45:23 +0530205 return pModal->db1_1;
Sujithb5aec952009-08-07 09:45:15 +0530206 case EEP_MINOR_REV:
207 return pBase->version & AR5416_EEP_VER_MINOR_MASK;
208 case EEP_TX_MASK:
209 return pBase->txMask;
210 case EEP_RX_MASK:
211 return pBase->rxMask;
212 case EEP_FRAC_N_5G:
213 return 0;
Senthil Balasubramaniane41f0bf2009-09-18 15:08:20 +0530214 case EEP_PWR_TABLE_OFFSET:
215 return AR5416_PWR_TABLE_OFFSET_DB;
Sujithb5aec952009-08-07 09:45:15 +0530216 default:
217 return 0;
218 }
219}
220
221static void ath9k_hw_get_4k_gain_boundaries_pdadcs(struct ath_hw *ah,
222 struct ath9k_channel *chan,
223 struct cal_data_per_freq_4k *pRawDataSet,
224 u8 *bChans, u16 availPiers,
225 u16 tPdGainOverlap, int16_t *pMinCalPower,
226 u16 *pPdGainBoundaries, u8 *pPDADCValues,
227 u16 numXpdGains)
228{
229#define TMP_VAL_VPD_TABLE \
230 ((vpdTableI[i][sizeCurrVpdTable - 1] + (ss - maxIndex + 1) * vpdStep));
231 int i, j, k;
232 int16_t ss;
233 u16 idxL = 0, idxR = 0, numPiers;
234 static u8 vpdTableL[AR5416_EEP4K_NUM_PD_GAINS]
235 [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
236 static u8 vpdTableR[AR5416_EEP4K_NUM_PD_GAINS]
237 [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
238 static u8 vpdTableI[AR5416_EEP4K_NUM_PD_GAINS]
239 [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
240
241 u8 *pVpdL, *pVpdR, *pPwrL, *pPwrR;
242 u8 minPwrT4[AR5416_EEP4K_NUM_PD_GAINS];
243 u8 maxPwrT4[AR5416_EEP4K_NUM_PD_GAINS];
244 int16_t vpdStep;
245 int16_t tmpVal;
246 u16 sizeCurrVpdTable, maxIndex, tgtIndex;
247 bool match;
248 int16_t minDelta = 0;
249 struct chan_centers centers;
250#define PD_GAIN_BOUNDARY_DEFAULT 58;
251
252 ath9k_hw_get_channel_centers(ah, chan, &centers);
253
254 for (numPiers = 0; numPiers < availPiers; numPiers++) {
255 if (bChans[numPiers] == AR5416_BCHAN_UNUSED)
256 break;
257 }
258
259 match = ath9k_hw_get_lower_upper_index(
260 (u8)FREQ2FBIN(centers.synth_center,
261 IS_CHAN_2GHZ(chan)), bChans, numPiers,
262 &idxL, &idxR);
263
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],
269 pRawDataSet[idxL].pwrPdg[i],
270 pRawDataSet[idxL].vpdPdg[i],
271 AR5416_EEP4K_PD_GAIN_ICEPTS,
272 vpdTableI[i]);
273 }
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
283 maxPwrT4[i] =
284 min(pPwrL[AR5416_EEP4K_PD_GAIN_ICEPTS - 1],
285 pPwrR[AR5416_EEP4K_PD_GAIN_ICEPTS - 1]);
286
287
288 ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
289 pPwrL, pVpdL,
290 AR5416_EEP4K_PD_GAIN_ICEPTS,
291 vpdTableL[i]);
292 ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
293 pPwrR, pVpdR,
294 AR5416_EEP4K_PD_GAIN_ICEPTS,
295 vpdTableR[i]);
296
297 for (j = 0; j <= (maxPwrT4[i] - minPwrT4[i]) / 2; j++) {
298 vpdTableI[i][j] =
299 (u8)(ath9k_hw_interpolate((u16)
300 FREQ2FBIN(centers.
301 synth_center,
302 IS_CHAN_2GHZ
303 (chan)),
304 bChans[idxL], bChans[idxR],
305 vpdTableL[i][j], vpdTableR[i][j]));
306 }
307 }
308 }
309
310 *pMinCalPower = (int16_t)(minPwrT4[0] / 2);
311
312 k = 0;
313
314 for (i = 0; i < numXpdGains; i++) {
315 if (i == (numXpdGains - 1))
316 pPdGainBoundaries[i] =
317 (u16)(maxPwrT4[i] / 2);
318 else
319 pPdGainBoundaries[i] =
320 (u16)((maxPwrT4[i] + minPwrT4[i + 1]) / 4);
321
322 pPdGainBoundaries[i] =
323 min((u16)AR5416_MAX_RATE_POWER, pPdGainBoundaries[i]);
324
325 if ((i == 0) && !AR_SREV_5416_20_OR_LATER(ah)) {
326 minDelta = pPdGainBoundaries[0] - 23;
327 pPdGainBoundaries[0] = 23;
328 } else {
329 minDelta = 0;
330 }
331
332 if (i == 0) {
333 if (AR_SREV_9280_10_OR_LATER(ah))
334 ss = (int16_t)(0 - (minPwrT4[i] / 2));
335 else
336 ss = 0;
337 } else {
338 ss = (int16_t)((pPdGainBoundaries[i - 1] -
339 (minPwrT4[i] / 2)) -
340 tPdGainOverlap + 1 + minDelta);
341 }
342 vpdStep = (int16_t)(vpdTableI[i][1] - vpdTableI[i][0]);
343 vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
344
345 while ((ss < 0) && (k < (AR5416_NUM_PDADC_VALUES - 1))) {
346 tmpVal = (int16_t)(vpdTableI[i][0] + ss * vpdStep);
347 pPDADCValues[k++] = (u8)((tmpVal < 0) ? 0 : tmpVal);
348 ss++;
349 }
350
351 sizeCurrVpdTable = (u8) ((maxPwrT4[i] - minPwrT4[i]) / 2 + 1);
352 tgtIndex = (u8)(pPdGainBoundaries[i] + tPdGainOverlap -
353 (minPwrT4[i] / 2));
354 maxIndex = (tgtIndex < sizeCurrVpdTable) ?
355 tgtIndex : sizeCurrVpdTable;
356
357 while ((ss < maxIndex) && (k < (AR5416_NUM_PDADC_VALUES - 1)))
358 pPDADCValues[k++] = vpdTableI[i][ss++];
359
360 vpdStep = (int16_t)(vpdTableI[i][sizeCurrVpdTable - 1] -
361 vpdTableI[i][sizeCurrVpdTable - 2]);
362 vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
363
364 if (tgtIndex >= maxIndex) {
365 while ((ss <= tgtIndex) &&
366 (k < (AR5416_NUM_PDADC_VALUES - 1))) {
367 tmpVal = (int16_t) TMP_VAL_VPD_TABLE;
368 pPDADCValues[k++] = (u8)((tmpVal > 255) ?
369 255 : tmpVal);
370 ss++;
371 }
372 }
373 }
374
375 while (i < AR5416_EEP4K_PD_GAINS_IN_MASK) {
376 pPdGainBoundaries[i] = PD_GAIN_BOUNDARY_DEFAULT;
377 i++;
378 }
379
380 while (k < AR5416_NUM_PDADC_VALUES) {
381 pPDADCValues[k] = pPDADCValues[k - 1];
382 k++;
383 }
384
385 return;
386#undef TMP_VAL_VPD_TABLE
387}
388
389static void ath9k_hw_set_4k_power_cal_table(struct ath_hw *ah,
390 struct ath9k_channel *chan,
391 int16_t *pTxPowerIndexOffset)
392{
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700393 struct ath_common *common = ath9k_hw_common(ah);
Sujithb5aec952009-08-07 09:45:15 +0530394 struct ar5416_eeprom_4k *pEepData = &ah->eeprom.map4k;
395 struct cal_data_per_freq_4k *pRawDataset;
396 u8 *pCalBChans = NULL;
397 u16 pdGainOverlap_t2;
398 static u8 pdadcValues[AR5416_NUM_PDADC_VALUES];
399 u16 gainBoundaries[AR5416_EEP4K_PD_GAINS_IN_MASK];
400 u16 numPiers, i, j;
401 int16_t tMinCalPower;
402 u16 numXpdGain, xpdMask;
403 u16 xpdGainValues[AR5416_EEP4K_NUM_PD_GAINS] = { 0, 0 };
404 u32 reg32, regOffset, regChainOffset;
405
406 xpdMask = pEepData->modalHeader.xpdGain;
407
408 if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
409 AR5416_EEP_MINOR_VER_2) {
410 pdGainOverlap_t2 =
411 pEepData->modalHeader.pdGainOverlap;
412 } else {
413 pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5),
414 AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
415 }
416
417 pCalBChans = pEepData->calFreqPier2G;
418 numPiers = AR5416_EEP4K_NUM_2G_CAL_PIERS;
419
420 numXpdGain = 0;
421
422 for (i = 1; i <= AR5416_EEP4K_PD_GAINS_IN_MASK; i++) {
423 if ((xpdMask >> (AR5416_EEP4K_PD_GAINS_IN_MASK - i)) & 1) {
424 if (numXpdGain >= AR5416_EEP4K_NUM_PD_GAINS)
425 break;
426 xpdGainValues[numXpdGain] =
427 (u16)(AR5416_EEP4K_PD_GAINS_IN_MASK - i);
428 numXpdGain++;
429 }
430 }
431
432 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
433 (numXpdGain - 1) & 0x3);
434 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,
435 xpdGainValues[0]);
436 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
437 xpdGainValues[1]);
438 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3, 0);
439
440 for (i = 0; i < AR5416_EEP4K_MAX_CHAINS; i++) {
441 if (AR_SREV_5416_20_OR_LATER(ah) &&
442 (ah->rxchainmask == 5 || ah->txchainmask == 5) &&
443 (i != 0)) {
444 regChainOffset = (i == 1) ? 0x2000 : 0x1000;
445 } else
446 regChainOffset = i * 0x1000;
447
448 if (pEepData->baseEepHeader.txMask & (1 << i)) {
449 pRawDataset = pEepData->calPierData2G[i];
450
451 ath9k_hw_get_4k_gain_boundaries_pdadcs(ah, chan,
452 pRawDataset, pCalBChans,
453 numPiers, pdGainOverlap_t2,
454 &tMinCalPower, gainBoundaries,
455 pdadcValues, numXpdGain);
456
457 if ((i == 0) || AR_SREV_5416_20_OR_LATER(ah)) {
458 REG_WRITE(ah, AR_PHY_TPCRG5 + regChainOffset,
459 SM(pdGainOverlap_t2,
460 AR_PHY_TPCRG5_PD_GAIN_OVERLAP)
461 | SM(gainBoundaries[0],
462 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1)
463 | SM(gainBoundaries[1],
464 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2)
465 | SM(gainBoundaries[2],
466 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3)
467 | SM(gainBoundaries[3],
468 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4));
469 }
470
471 regOffset = AR_PHY_BASE + (672 << 2) + regChainOffset;
472 for (j = 0; j < 32; j++) {
473 reg32 = ((pdadcValues[4 * j + 0] & 0xFF) << 0) |
474 ((pdadcValues[4 * j + 1] & 0xFF) << 8) |
475 ((pdadcValues[4 * j + 2] & 0xFF) << 16)|
476 ((pdadcValues[4 * j + 3] & 0xFF) << 24);
477 REG_WRITE(ah, regOffset, reg32);
478
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700479 ath_print(common, ATH_DBG_EEPROM,
480 "PDADC (%d,%4x): %4.4x %8.8x\n",
481 i, regChainOffset, regOffset,
482 reg32);
483 ath_print(common, ATH_DBG_EEPROM,
484 "PDADC: Chain %d | "
485 "PDADC %3d Value %3d | "
486 "PDADC %3d Value %3d | "
487 "PDADC %3d Value %3d | "
488 "PDADC %3d Value %3d |\n",
489 i, 4 * j, pdadcValues[4 * j],
490 4 * j + 1, pdadcValues[4 * j + 1],
491 4 * j + 2, pdadcValues[4 * j + 2],
492 4 * j + 3,
493 pdadcValues[4 * j + 3]);
Sujithb5aec952009-08-07 09:45:15 +0530494
495 regOffset += 4;
496 }
497 }
498 }
499
500 *pTxPowerIndexOffset = 0;
501}
502
503static void ath9k_hw_set_4k_power_per_rate_table(struct ath_hw *ah,
504 struct ath9k_channel *chan,
505 int16_t *ratesArray,
506 u16 cfgCtl,
507 u16 AntennaReduction,
508 u16 twiceMaxRegulatoryPower,
509 u16 powerLimit)
510{
Sujith180d674b2009-08-07 09:45:33 +0530511#define CMP_TEST_GRP \
512 (((cfgCtl & ~CTL_MODE_M)| (pCtlMode[ctlMode] & CTL_MODE_M)) == \
513 pEepData->ctlIndex[i]) \
514 || (((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == \
515 ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL))
Sujithb5aec952009-08-07 09:45:15 +0530516
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700517 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithb5aec952009-08-07 09:45:15 +0530518 int i;
519 int16_t twiceLargestAntenna;
Sujith180d674b2009-08-07 09:45:33 +0530520 u16 twiceMinEdgePower;
521 u16 twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
522 u16 scaledPower = 0, minCtlPower, maxRegAllowedPower;
523 u16 numCtlModes, *pCtlMode, ctlMode, freq;
524 struct chan_centers centers;
Sujithb5aec952009-08-07 09:45:15 +0530525 struct cal_ctl_data_4k *rep;
Sujith180d674b2009-08-07 09:45:33 +0530526 struct ar5416_eeprom_4k *pEepData = &ah->eeprom.map4k;
527 static const u16 tpScaleReductionTable[5] =
528 { 0, 3, 6, 9, AR5416_MAX_RATE_POWER };
Sujithb5aec952009-08-07 09:45:15 +0530529 struct cal_target_power_leg targetPowerOfdm, targetPowerCck = {
530 0, { 0, 0, 0, 0}
531 };
532 struct cal_target_power_leg targetPowerOfdmExt = {
533 0, { 0, 0, 0, 0} }, targetPowerCckExt = {
534 0, { 0, 0, 0, 0 }
535 };
536 struct cal_target_power_ht targetPowerHt20, targetPowerHt40 = {
537 0, {0, 0, 0, 0}
538 };
Sujithb5aec952009-08-07 09:45:15 +0530539 u16 ctlModesFor11g[] =
540 { CTL_11B, CTL_11G, CTL_2GHT20, CTL_11B_EXT, CTL_11G_EXT,
541 CTL_2GHT40
542 };
Sujithb5aec952009-08-07 09:45:15 +0530543
544 ath9k_hw_get_channel_centers(ah, chan, &centers);
545
546 twiceLargestAntenna = pEepData->modalHeader.antennaGainCh[0];
Sujithb5aec952009-08-07 09:45:15 +0530547 twiceLargestAntenna = (int16_t)min(AntennaReduction -
548 twiceLargestAntenna, 0);
549
550 maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700551 if (regulatory->tp_scale != ATH9K_TP_SCALE_MAX) {
Sujithb5aec952009-08-07 09:45:15 +0530552 maxRegAllowedPower -=
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700553 (tpScaleReductionTable[(regulatory->tp_scale)] * 2);
Sujithb5aec952009-08-07 09:45:15 +0530554 }
555
556 scaledPower = min(powerLimit, maxRegAllowedPower);
557 scaledPower = max((u16)0, scaledPower);
558
559 numCtlModes = ARRAY_SIZE(ctlModesFor11g) - SUB_NUM_CTL_MODES_AT_2G_40;
560 pCtlMode = ctlModesFor11g;
561
562 ath9k_hw_get_legacy_target_powers(ah, chan,
563 pEepData->calTargetPowerCck,
564 AR5416_NUM_2G_CCK_TARGET_POWERS,
565 &targetPowerCck, 4, false);
566 ath9k_hw_get_legacy_target_powers(ah, chan,
567 pEepData->calTargetPower2G,
568 AR5416_NUM_2G_20_TARGET_POWERS,
569 &targetPowerOfdm, 4, false);
570 ath9k_hw_get_target_powers(ah, chan,
571 pEepData->calTargetPower2GHT20,
572 AR5416_NUM_2G_20_TARGET_POWERS,
573 &targetPowerHt20, 8, false);
574
575 if (IS_CHAN_HT40(chan)) {
576 numCtlModes = ARRAY_SIZE(ctlModesFor11g);
577 ath9k_hw_get_target_powers(ah, chan,
578 pEepData->calTargetPower2GHT40,
579 AR5416_NUM_2G_40_TARGET_POWERS,
580 &targetPowerHt40, 8, true);
581 ath9k_hw_get_legacy_target_powers(ah, chan,
582 pEepData->calTargetPowerCck,
583 AR5416_NUM_2G_CCK_TARGET_POWERS,
584 &targetPowerCckExt, 4, true);
585 ath9k_hw_get_legacy_target_powers(ah, chan,
586 pEepData->calTargetPower2G,
587 AR5416_NUM_2G_20_TARGET_POWERS,
588 &targetPowerOfdmExt, 4, true);
589 }
590
591 for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
592 bool isHt40CtlMode = (pCtlMode[ctlMode] == CTL_5GHT40) ||
593 (pCtlMode[ctlMode] == CTL_2GHT40);
Sujith180d674b2009-08-07 09:45:33 +0530594
Sujithb5aec952009-08-07 09:45:15 +0530595 if (isHt40CtlMode)
596 freq = centers.synth_center;
597 else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
598 freq = centers.ext_center;
599 else
600 freq = centers.ctl_center;
601
602 if (ah->eep_ops->get_eeprom_ver(ah) == 14 &&
603 ah->eep_ops->get_eeprom_rev(ah) <= 2)
604 twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
605
606 for (i = 0; (i < AR5416_EEP4K_NUM_CTLS) &&
Sujith180d674b2009-08-07 09:45:33 +0530607 pEepData->ctlIndex[i]; i++) {
608
609 if (CMP_TEST_GRP) {
Sujithb5aec952009-08-07 09:45:15 +0530610 rep = &(pEepData->ctlData[i]);
611
Sujith180d674b2009-08-07 09:45:33 +0530612 twiceMinEdgePower = ath9k_hw_get_max_edge_power(
613 freq,
614 rep->ctlEdges[
615 ar5416_get_ntxchains(ah->txchainmask) - 1],
616 IS_CHAN_2GHZ(chan),
617 AR5416_EEP4K_NUM_BAND_EDGES);
Sujithb5aec952009-08-07 09:45:15 +0530618
619 if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {
620 twiceMaxEdgePower =
621 min(twiceMaxEdgePower,
622 twiceMinEdgePower);
623 } else {
624 twiceMaxEdgePower = twiceMinEdgePower;
625 break;
626 }
627 }
628 }
629
630 minCtlPower = (u8)min(twiceMaxEdgePower, scaledPower);
631
632 switch (pCtlMode[ctlMode]) {
633 case CTL_11B:
Sujith180d674b2009-08-07 09:45:33 +0530634 for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x); i++) {
Sujithb5aec952009-08-07 09:45:15 +0530635 targetPowerCck.tPow2x[i] =
636 min((u16)targetPowerCck.tPow2x[i],
637 minCtlPower);
638 }
639 break;
640 case CTL_11G:
Sujith180d674b2009-08-07 09:45:33 +0530641 for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x); i++) {
Sujithb5aec952009-08-07 09:45:15 +0530642 targetPowerOfdm.tPow2x[i] =
643 min((u16)targetPowerOfdm.tPow2x[i],
644 minCtlPower);
645 }
646 break;
647 case CTL_2GHT20:
Sujith180d674b2009-08-07 09:45:33 +0530648 for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) {
Sujithb5aec952009-08-07 09:45:15 +0530649 targetPowerHt20.tPow2x[i] =
650 min((u16)targetPowerHt20.tPow2x[i],
651 minCtlPower);
652 }
653 break;
654 case CTL_11B_EXT:
Sujith180d674b2009-08-07 09:45:33 +0530655 targetPowerCckExt.tPow2x[0] =
656 min((u16)targetPowerCckExt.tPow2x[0],
657 minCtlPower);
Sujithb5aec952009-08-07 09:45:15 +0530658 break;
659 case CTL_11G_EXT:
Sujith180d674b2009-08-07 09:45:33 +0530660 targetPowerOfdmExt.tPow2x[0] =
661 min((u16)targetPowerOfdmExt.tPow2x[0],
662 minCtlPower);
Sujithb5aec952009-08-07 09:45:15 +0530663 break;
664 case CTL_2GHT40:
Sujith180d674b2009-08-07 09:45:33 +0530665 for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
Sujithb5aec952009-08-07 09:45:15 +0530666 targetPowerHt40.tPow2x[i] =
667 min((u16)targetPowerHt40.tPow2x[i],
668 minCtlPower);
669 }
670 break;
671 default:
672 break;
673 }
674 }
675
Sujith180d674b2009-08-07 09:45:33 +0530676 ratesArray[rate6mb] =
677 ratesArray[rate9mb] =
678 ratesArray[rate12mb] =
679 ratesArray[rate18mb] =
680 ratesArray[rate24mb] =
681 targetPowerOfdm.tPow2x[0];
682
Sujithb5aec952009-08-07 09:45:15 +0530683 ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1];
684 ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2];
685 ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3];
686 ratesArray[rateXr] = targetPowerOfdm.tPow2x[0];
687
688 for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++)
689 ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i];
690
691 ratesArray[rate1l] = targetPowerCck.tPow2x[0];
692 ratesArray[rate2s] = ratesArray[rate2l] = targetPowerCck.tPow2x[1];
693 ratesArray[rate5_5s] = ratesArray[rate5_5l] = targetPowerCck.tPow2x[2];
694 ratesArray[rate11s] = ratesArray[rate11l] = targetPowerCck.tPow2x[3];
695
696 if (IS_CHAN_HT40(chan)) {
697 for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
698 ratesArray[rateHt40_0 + i] =
699 targetPowerHt40.tPow2x[i];
700 }
701 ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0];
702 ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0];
703 ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0];
704 ratesArray[rateExtCck] = targetPowerCckExt.tPow2x[0];
705 }
Sujith180d674b2009-08-07 09:45:33 +0530706
707#undef CMP_TEST_GRP
Sujithb5aec952009-08-07 09:45:15 +0530708}
709
710static void ath9k_hw_4k_set_txpower(struct ath_hw *ah,
Sujithbf466fb2009-08-07 09:45:30 +0530711 struct ath9k_channel *chan,
712 u16 cfgCtl,
713 u8 twiceAntennaReduction,
714 u8 twiceMaxRegulatoryPower,
715 u8 powerLimit)
Sujithb5aec952009-08-07 09:45:15 +0530716{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700717 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithb5aec952009-08-07 09:45:15 +0530718 struct ar5416_eeprom_4k *pEepData = &ah->eeprom.map4k;
719 struct modal_eep_4k_header *pModal = &pEepData->modalHeader;
720 int16_t ratesArray[Ar5416RateSize];
721 int16_t txPowerIndexOffset = 0;
722 u8 ht40PowerIncForPdadc = 2;
723 int i;
724
725 memset(ratesArray, 0, sizeof(ratesArray));
726
727 if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
728 AR5416_EEP_MINOR_VER_2) {
729 ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
730 }
731
732 ath9k_hw_set_4k_power_per_rate_table(ah, chan,
Sujithbf466fb2009-08-07 09:45:30 +0530733 &ratesArray[0], cfgCtl,
734 twiceAntennaReduction,
735 twiceMaxRegulatoryPower,
736 powerLimit);
Sujithb5aec952009-08-07 09:45:15 +0530737
738 ath9k_hw_set_4k_power_cal_table(ah, chan, &txPowerIndexOffset);
739
740 for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
741 ratesArray[i] = (int16_t)(txPowerIndexOffset + ratesArray[i]);
742 if (ratesArray[i] > AR5416_MAX_RATE_POWER)
743 ratesArray[i] = AR5416_MAX_RATE_POWER;
744 }
745
Sujithbf466fb2009-08-07 09:45:30 +0530746
747 /* Update regulatory */
748
749 i = rate6mb;
750 if (IS_CHAN_HT40(chan))
751 i = rateHt40_0;
752 else if (IS_CHAN_HT20(chan))
753 i = rateHt20_0;
754
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700755 regulatory->max_power_level = ratesArray[i];
Sujithbf466fb2009-08-07 09:45:30 +0530756
Sujithb5aec952009-08-07 09:45:15 +0530757 if (AR_SREV_9280_10_OR_LATER(ah)) {
758 for (i = 0; i < Ar5416RateSize; i++)
Senthil Balasubramaniane41f0bf2009-09-18 15:08:20 +0530759 ratesArray[i] -= AR5416_PWR_TABLE_OFFSET_DB * 2;
Sujithb5aec952009-08-07 09:45:15 +0530760 }
761
Sujithbf466fb2009-08-07 09:45:30 +0530762 /* OFDM power per rate */
Sujithb5aec952009-08-07 09:45:15 +0530763 REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
764 ATH9K_POW_SM(ratesArray[rate18mb], 24)
765 | ATH9K_POW_SM(ratesArray[rate12mb], 16)
766 | ATH9K_POW_SM(ratesArray[rate9mb], 8)
767 | ATH9K_POW_SM(ratesArray[rate6mb], 0));
768 REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
769 ATH9K_POW_SM(ratesArray[rate54mb], 24)
770 | ATH9K_POW_SM(ratesArray[rate48mb], 16)
771 | ATH9K_POW_SM(ratesArray[rate36mb], 8)
772 | ATH9K_POW_SM(ratesArray[rate24mb], 0));
773
Sujithbf466fb2009-08-07 09:45:30 +0530774 /* CCK power per rate */
775 REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
776 ATH9K_POW_SM(ratesArray[rate2s], 24)
777 | ATH9K_POW_SM(ratesArray[rate2l], 16)
778 | ATH9K_POW_SM(ratesArray[rateXr], 8)
779 | ATH9K_POW_SM(ratesArray[rate1l], 0));
780 REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
781 ATH9K_POW_SM(ratesArray[rate11s], 24)
782 | ATH9K_POW_SM(ratesArray[rate11l], 16)
783 | ATH9K_POW_SM(ratesArray[rate5_5s], 8)
784 | ATH9K_POW_SM(ratesArray[rate5_5l], 0));
Sujithb5aec952009-08-07 09:45:15 +0530785
Sujithbf466fb2009-08-07 09:45:30 +0530786 /* HT20 power per rate */
Sujithb5aec952009-08-07 09:45:15 +0530787 REG_WRITE(ah, AR_PHY_POWER_TX_RATE5,
788 ATH9K_POW_SM(ratesArray[rateHt20_3], 24)
789 | ATH9K_POW_SM(ratesArray[rateHt20_2], 16)
790 | ATH9K_POW_SM(ratesArray[rateHt20_1], 8)
791 | ATH9K_POW_SM(ratesArray[rateHt20_0], 0));
792 REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
793 ATH9K_POW_SM(ratesArray[rateHt20_7], 24)
794 | ATH9K_POW_SM(ratesArray[rateHt20_6], 16)
795 | ATH9K_POW_SM(ratesArray[rateHt20_5], 8)
796 | ATH9K_POW_SM(ratesArray[rateHt20_4], 0));
797
Sujithbf466fb2009-08-07 09:45:30 +0530798 /* HT40 power per rate */
Sujithb5aec952009-08-07 09:45:15 +0530799 if (IS_CHAN_HT40(chan)) {
800 REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
801 ATH9K_POW_SM(ratesArray[rateHt40_3] +
802 ht40PowerIncForPdadc, 24)
803 | ATH9K_POW_SM(ratesArray[rateHt40_2] +
804 ht40PowerIncForPdadc, 16)
805 | ATH9K_POW_SM(ratesArray[rateHt40_1] +
806 ht40PowerIncForPdadc, 8)
807 | ATH9K_POW_SM(ratesArray[rateHt40_0] +
808 ht40PowerIncForPdadc, 0));
809 REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
810 ATH9K_POW_SM(ratesArray[rateHt40_7] +
811 ht40PowerIncForPdadc, 24)
812 | ATH9K_POW_SM(ratesArray[rateHt40_6] +
813 ht40PowerIncForPdadc, 16)
814 | ATH9K_POW_SM(ratesArray[rateHt40_5] +
815 ht40PowerIncForPdadc, 8)
816 | ATH9K_POW_SM(ratesArray[rateHt40_4] +
817 ht40PowerIncForPdadc, 0));
Sujithb5aec952009-08-07 09:45:15 +0530818 REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
819 ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
820 | ATH9K_POW_SM(ratesArray[rateExtCck], 16)
821 | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
822 | ATH9K_POW_SM(ratesArray[rateDupCck], 0));
823 }
Sujithb5aec952009-08-07 09:45:15 +0530824}
825
826static void ath9k_hw_4k_set_addac(struct ath_hw *ah,
827 struct ath9k_channel *chan)
828{
829 struct modal_eep_4k_header *pModal;
830 struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k;
831 u8 biaslevel;
832
833 if (ah->hw_version.macVersion != AR_SREV_VERSION_9160)
834 return;
835
836 if (ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_MINOR_VER_7)
837 return;
838
839 pModal = &eep->modalHeader;
840
841 if (pModal->xpaBiasLvl != 0xff) {
842 biaslevel = pModal->xpaBiasLvl;
843 INI_RA(&ah->iniAddac, 7, 1) =
844 (INI_RA(&ah->iniAddac, 7, 1) & (~0x18)) | biaslevel << 3;
845 }
846}
847
848static void ath9k_hw_4k_set_gain(struct ath_hw *ah,
849 struct modal_eep_4k_header *pModal,
850 struct ar5416_eeprom_4k *eep,
Sujitha37414a2009-08-07 09:45:19 +0530851 u8 txRxAttenLocal)
Sujithb5aec952009-08-07 09:45:15 +0530852{
Sujitha37414a2009-08-07 09:45:19 +0530853 REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0,
Sujithb5aec952009-08-07 09:45:15 +0530854 pModal->antCtrlChain[0]);
855
Sujitha37414a2009-08-07 09:45:19 +0530856 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0),
857 (REG_READ(ah, AR_PHY_TIMING_CTRL4(0)) &
Sujithb5aec952009-08-07 09:45:15 +0530858 ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
859 AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
860 SM(pModal->iqCalICh[0], AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
861 SM(pModal->iqCalQCh[0], AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
862
863 if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
864 AR5416_EEP_MINOR_VER_3) {
865 txRxAttenLocal = pModal->txRxAttenCh[0];
866
Sujitha37414a2009-08-07 09:45:19 +0530867 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ,
Sujithb5aec952009-08-07 09:45:15 +0530868 AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN, pModal->bswMargin[0]);
Sujitha37414a2009-08-07 09:45:19 +0530869 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ,
Sujithb5aec952009-08-07 09:45:15 +0530870 AR_PHY_GAIN_2GHZ_XATTEN1_DB, pModal->bswAtten[0]);
Sujitha37414a2009-08-07 09:45:19 +0530871 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ,
Sujithb5aec952009-08-07 09:45:15 +0530872 AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN,
873 pModal->xatten2Margin[0]);
Sujitha37414a2009-08-07 09:45:19 +0530874 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ,
Sujithb5aec952009-08-07 09:45:15 +0530875 AR_PHY_GAIN_2GHZ_XATTEN2_DB, pModal->xatten2Db[0]);
876
877 /* Set the block 1 value to block 0 value */
878 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + 0x1000,
879 AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN,
880 pModal->bswMargin[0]);
881 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + 0x1000,
882 AR_PHY_GAIN_2GHZ_XATTEN1_DB, pModal->bswAtten[0]);
883 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + 0x1000,
884 AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN,
885 pModal->xatten2Margin[0]);
886 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + 0x1000,
887 AR_PHY_GAIN_2GHZ_XATTEN2_DB,
888 pModal->xatten2Db[0]);
889 }
890
Sujitha37414a2009-08-07 09:45:19 +0530891 REG_RMW_FIELD(ah, AR_PHY_RXGAIN,
Sujithb5aec952009-08-07 09:45:15 +0530892 AR9280_PHY_RXGAIN_TXRX_ATTEN, txRxAttenLocal);
Sujitha37414a2009-08-07 09:45:19 +0530893 REG_RMW_FIELD(ah, AR_PHY_RXGAIN,
Sujithb5aec952009-08-07 09:45:15 +0530894 AR9280_PHY_RXGAIN_TXRX_MARGIN, pModal->rxTxMarginCh[0]);
895
896 REG_RMW_FIELD(ah, AR_PHY_RXGAIN + 0x1000,
897 AR9280_PHY_RXGAIN_TXRX_ATTEN, txRxAttenLocal);
898 REG_RMW_FIELD(ah, AR_PHY_RXGAIN + 0x1000,
899 AR9280_PHY_RXGAIN_TXRX_MARGIN, pModal->rxTxMarginCh[0]);
900
901 if (AR_SREV_9285_11(ah))
902 REG_WRITE(ah, AR9285_AN_TOP4, (AR9285_AN_TOP4_DEFAULT | 0x14));
903}
904
905/*
906 * Read EEPROM header info and program the device for correct operation
907 * given the channel value.
908 */
909static void ath9k_hw_4k_set_board_values(struct ath_hw *ah,
910 struct ath9k_channel *chan)
911{
912 struct modal_eep_4k_header *pModal;
913 struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k;
914 u8 txRxAttenLocal;
915 u8 ob[5], db1[5], db2[5];
916 u8 ant_div_control1, ant_div_control2;
917 u32 regVal;
918
919 pModal = &eep->modalHeader;
920 txRxAttenLocal = 23;
921
922 REG_WRITE(ah, AR_PHY_SWITCH_COM,
923 ah->eep_ops->get_eeprom_antenna_cfg(ah, chan));
924
925 /* Single chain for 4K EEPROM*/
Sujitha37414a2009-08-07 09:45:19 +0530926 ath9k_hw_4k_set_gain(ah, pModal, eep, txRxAttenLocal);
Sujithb5aec952009-08-07 09:45:15 +0530927
928 /* Initialize Ant Diversity settings from EEPROM */
929 if (pModal->version >= 3) {
Sujith7f638452009-08-07 09:45:23 +0530930 ant_div_control1 = pModal->antdiv_ctl1;
931 ant_div_control2 = pModal->antdiv_ctl2;
932
933 regVal = REG_READ(ah, AR_PHY_MULTICHAIN_GAIN_CTL);
934 regVal &= (~(AR_PHY_9285_ANT_DIV_CTL_ALL));
935
936 regVal |= SM(ant_div_control1,
937 AR_PHY_9285_ANT_DIV_CTL);
938 regVal |= SM(ant_div_control2,
939 AR_PHY_9285_ANT_DIV_ALT_LNACONF);
940 regVal |= SM((ant_div_control2 >> 2),
941 AR_PHY_9285_ANT_DIV_MAIN_LNACONF);
942 regVal |= SM((ant_div_control1 >> 1),
943 AR_PHY_9285_ANT_DIV_ALT_GAINTB);
944 regVal |= SM((ant_div_control1 >> 2),
945 AR_PHY_9285_ANT_DIV_MAIN_GAINTB);
946
947
948 REG_WRITE(ah, AR_PHY_MULTICHAIN_GAIN_CTL, regVal);
949 regVal = REG_READ(ah, AR_PHY_MULTICHAIN_GAIN_CTL);
950 regVal = REG_READ(ah, AR_PHY_CCK_DETECT);
951 regVal &= (~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV);
952 regVal |= SM((ant_div_control1 >> 3),
953 AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV);
954
955 REG_WRITE(ah, AR_PHY_CCK_DETECT, regVal);
956 regVal = REG_READ(ah, AR_PHY_CCK_DETECT);
Sujithb5aec952009-08-07 09:45:15 +0530957 }
958
959 if (pModal->version >= 2) {
Sujith7f638452009-08-07 09:45:23 +0530960 ob[0] = pModal->ob_0;
961 ob[1] = pModal->ob_1;
962 ob[2] = pModal->ob_2;
963 ob[3] = pModal->ob_3;
964 ob[4] = pModal->ob_4;
Sujithb5aec952009-08-07 09:45:15 +0530965
Sujith7f638452009-08-07 09:45:23 +0530966 db1[0] = pModal->db1_0;
967 db1[1] = pModal->db1_1;
968 db1[2] = pModal->db1_2;
969 db1[3] = pModal->db1_3;
970 db1[4] = pModal->db1_4;
Sujithb5aec952009-08-07 09:45:15 +0530971
Sujith7f638452009-08-07 09:45:23 +0530972 db2[0] = pModal->db2_0;
973 db2[1] = pModal->db2_1;
974 db2[2] = pModal->db2_2;
975 db2[3] = pModal->db2_3;
976 db2[4] = pModal->db2_4;
Sujithb5aec952009-08-07 09:45:15 +0530977 } else if (pModal->version == 1) {
Sujith7f638452009-08-07 09:45:23 +0530978 ob[0] = pModal->ob_0;
979 ob[1] = ob[2] = ob[3] = ob[4] = pModal->ob_1;
980 db1[0] = pModal->db1_0;
981 db1[1] = db1[2] = db1[3] = db1[4] = pModal->db1_1;
982 db2[0] = pModal->db2_0;
983 db2[1] = db2[2] = db2[3] = db2[4] = pModal->db2_1;
Sujithb5aec952009-08-07 09:45:15 +0530984 } else {
985 int i;
Sujith7f638452009-08-07 09:45:23 +0530986
Sujithb5aec952009-08-07 09:45:15 +0530987 for (i = 0; i < 5; i++) {
Sujith7f638452009-08-07 09:45:23 +0530988 ob[i] = pModal->ob_0;
989 db1[i] = pModal->db1_0;
990 db2[i] = pModal->db1_0;
Sujithb5aec952009-08-07 09:45:15 +0530991 }
992 }
993
994 if (AR_SREV_9271(ah)) {
995 ath9k_hw_analog_shift_rmw(ah,
996 AR9285_AN_RF2G3,
997 AR9271_AN_RF2G3_OB_cck,
998 AR9271_AN_RF2G3_OB_cck_S,
999 ob[0]);
1000 ath9k_hw_analog_shift_rmw(ah,
1001 AR9285_AN_RF2G3,
1002 AR9271_AN_RF2G3_OB_psk,
1003 AR9271_AN_RF2G3_OB_psk_S,
1004 ob[1]);
1005 ath9k_hw_analog_shift_rmw(ah,
1006 AR9285_AN_RF2G3,
1007 AR9271_AN_RF2G3_OB_qam,
1008 AR9271_AN_RF2G3_OB_qam_S,
1009 ob[2]);
1010 ath9k_hw_analog_shift_rmw(ah,
1011 AR9285_AN_RF2G3,
1012 AR9271_AN_RF2G3_DB_1,
1013 AR9271_AN_RF2G3_DB_1_S,
1014 db1[0]);
1015 ath9k_hw_analog_shift_rmw(ah,
1016 AR9285_AN_RF2G4,
1017 AR9271_AN_RF2G4_DB_2,
1018 AR9271_AN_RF2G4_DB_2_S,
1019 db2[0]);
1020 } else {
1021 ath9k_hw_analog_shift_rmw(ah,
1022 AR9285_AN_RF2G3,
1023 AR9285_AN_RF2G3_OB_0,
1024 AR9285_AN_RF2G3_OB_0_S,
1025 ob[0]);
1026 ath9k_hw_analog_shift_rmw(ah,
1027 AR9285_AN_RF2G3,
1028 AR9285_AN_RF2G3_OB_1,
1029 AR9285_AN_RF2G3_OB_1_S,
1030 ob[1]);
1031 ath9k_hw_analog_shift_rmw(ah,
1032 AR9285_AN_RF2G3,
1033 AR9285_AN_RF2G3_OB_2,
1034 AR9285_AN_RF2G3_OB_2_S,
1035 ob[2]);
1036 ath9k_hw_analog_shift_rmw(ah,
1037 AR9285_AN_RF2G3,
1038 AR9285_AN_RF2G3_OB_3,
1039 AR9285_AN_RF2G3_OB_3_S,
1040 ob[3]);
1041 ath9k_hw_analog_shift_rmw(ah,
1042 AR9285_AN_RF2G3,
1043 AR9285_AN_RF2G3_OB_4,
1044 AR9285_AN_RF2G3_OB_4_S,
1045 ob[4]);
1046
1047 ath9k_hw_analog_shift_rmw(ah,
1048 AR9285_AN_RF2G3,
1049 AR9285_AN_RF2G3_DB1_0,
1050 AR9285_AN_RF2G3_DB1_0_S,
1051 db1[0]);
1052 ath9k_hw_analog_shift_rmw(ah,
1053 AR9285_AN_RF2G3,
1054 AR9285_AN_RF2G3_DB1_1,
1055 AR9285_AN_RF2G3_DB1_1_S,
1056 db1[1]);
1057 ath9k_hw_analog_shift_rmw(ah,
1058 AR9285_AN_RF2G3,
1059 AR9285_AN_RF2G3_DB1_2,
1060 AR9285_AN_RF2G3_DB1_2_S,
1061 db1[2]);
1062 ath9k_hw_analog_shift_rmw(ah,
1063 AR9285_AN_RF2G4,
1064 AR9285_AN_RF2G4_DB1_3,
1065 AR9285_AN_RF2G4_DB1_3_S,
1066 db1[3]);
1067 ath9k_hw_analog_shift_rmw(ah,
1068 AR9285_AN_RF2G4,
1069 AR9285_AN_RF2G4_DB1_4,
1070 AR9285_AN_RF2G4_DB1_4_S, db1[4]);
1071
1072 ath9k_hw_analog_shift_rmw(ah,
1073 AR9285_AN_RF2G4,
1074 AR9285_AN_RF2G4_DB2_0,
1075 AR9285_AN_RF2G4_DB2_0_S,
1076 db2[0]);
1077 ath9k_hw_analog_shift_rmw(ah,
1078 AR9285_AN_RF2G4,
1079 AR9285_AN_RF2G4_DB2_1,
1080 AR9285_AN_RF2G4_DB2_1_S,
1081 db2[1]);
1082 ath9k_hw_analog_shift_rmw(ah,
1083 AR9285_AN_RF2G4,
1084 AR9285_AN_RF2G4_DB2_2,
1085 AR9285_AN_RF2G4_DB2_2_S,
1086 db2[2]);
1087 ath9k_hw_analog_shift_rmw(ah,
1088 AR9285_AN_RF2G4,
1089 AR9285_AN_RF2G4_DB2_3,
1090 AR9285_AN_RF2G4_DB2_3_S,
1091 db2[3]);
1092 ath9k_hw_analog_shift_rmw(ah,
1093 AR9285_AN_RF2G4,
1094 AR9285_AN_RF2G4_DB2_4,
1095 AR9285_AN_RF2G4_DB2_4_S,
1096 db2[4]);
1097 }
1098
1099
1100 if (AR_SREV_9285_11(ah))
1101 REG_WRITE(ah, AR9285_AN_TOP4, AR9285_AN_TOP4_DEFAULT);
1102
1103 REG_RMW_FIELD(ah, AR_PHY_SETTLING, AR_PHY_SETTLING_SWITCH,
1104 pModal->switchSettling);
1105 REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ, AR_PHY_DESIRED_SZ_ADC,
1106 pModal->adcDesiredSize);
1107
1108 REG_WRITE(ah, AR_PHY_RF_CTL4,
1109 SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF) |
1110 SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAB_OFF) |
1111 SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAA_ON) |
1112 SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAB_ON));
1113
1114 REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON,
1115 pModal->txEndToRxOn);
Luis R. Rodriguez0cab6552009-10-19 02:33:32 -04001116
1117 if (AR_SREV_9271_10(ah))
1118 REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON,
1119 pModal->txEndToRxOn);
Sujithb5aec952009-08-07 09:45:15 +05301120 REG_RMW_FIELD(ah, AR_PHY_CCA, AR9280_PHY_CCA_THRESH62,
1121 pModal->thresh62);
1122 REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0, AR_PHY_EXT_CCA0_THRESH62,
1123 pModal->thresh62);
1124
1125 if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
1126 AR5416_EEP_MINOR_VER_2) {
1127 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_DATA_START,
1128 pModal->txFrameToDataStart);
1129 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_PA_ON,
1130 pModal->txFrameToPaOn);
1131 }
1132
1133 if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
1134 AR5416_EEP_MINOR_VER_3) {
1135 if (IS_CHAN_HT40(chan))
1136 REG_RMW_FIELD(ah, AR_PHY_SETTLING,
1137 AR_PHY_SETTLING_SWITCH,
1138 pModal->swSettleHt40);
1139 }
1140}
1141
1142static u16 ath9k_hw_4k_get_eeprom_antenna_cfg(struct ath_hw *ah,
1143 struct ath9k_channel *chan)
1144{
1145 struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k;
1146 struct modal_eep_4k_header *pModal = &eep->modalHeader;
1147
1148 return pModal->antCtrlCommon & 0xFFFF;
1149}
1150
1151static u8 ath9k_hw_4k_get_num_ant_config(struct ath_hw *ah,
1152 enum ieee80211_band freq_band)
1153{
1154 return 1;
1155}
1156
1157static u16 ath9k_hw_4k_get_spur_channel(struct ath_hw *ah, u16 i, bool is2GHz)
1158{
1159#define EEP_MAP4K_SPURCHAN \
1160 (ah->eeprom.map4k.modalHeader.spurChans[i].spurChan)
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001161 struct ath_common *common = ath9k_hw_common(ah);
Sujithb5aec952009-08-07 09:45:15 +05301162
1163 u16 spur_val = AR_NO_SPUR;
1164
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001165 ath_print(common, ATH_DBG_ANI,
1166 "Getting spur idx %d is2Ghz. %d val %x\n",
1167 i, is2GHz, ah->config.spurchans[i][is2GHz]);
Sujithb5aec952009-08-07 09:45:15 +05301168
1169 switch (ah->config.spurmode) {
1170 case SPUR_DISABLE:
1171 break;
1172 case SPUR_ENABLE_IOCTL:
1173 spur_val = ah->config.spurchans[i][is2GHz];
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001174 ath_print(common, ATH_DBG_ANI,
1175 "Getting spur val from new loc. %d\n", spur_val);
Sujithb5aec952009-08-07 09:45:15 +05301176 break;
1177 case SPUR_ENABLE_EEPROM:
1178 spur_val = EEP_MAP4K_SPURCHAN;
1179 break;
1180 }
1181
1182 return spur_val;
1183
1184#undef EEP_MAP4K_SPURCHAN
1185}
1186
1187const struct eeprom_ops eep_4k_ops = {
1188 .check_eeprom = ath9k_hw_4k_check_eeprom,
1189 .get_eeprom = ath9k_hw_4k_get_eeprom,
1190 .fill_eeprom = ath9k_hw_4k_fill_eeprom,
1191 .get_eeprom_ver = ath9k_hw_4k_get_eeprom_ver,
1192 .get_eeprom_rev = ath9k_hw_4k_get_eeprom_rev,
1193 .get_num_ant_config = ath9k_hw_4k_get_num_ant_config,
1194 .get_eeprom_antenna_cfg = ath9k_hw_4k_get_eeprom_antenna_cfg,
1195 .set_board_values = ath9k_hw_4k_set_board_values,
1196 .set_addac = ath9k_hw_4k_set_addac,
1197 .set_txpower = ath9k_hw_4k_set_txpower,
1198 .get_spur_channel = ath9k_hw_4k_get_spur_channel
1199};