blob: c3bb1968bb5ea55156a85b4eb07562ef942c074c [file] [log] [blame]
Sujithf1dc5602008-10-29 10:16:30 +05301/*
2 * Copyright (c) 2008 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
Sujith394cf0a2009-02-09 13:26:54 +053017#include "ath9k.h"
Sujithf1dc5602008-10-29 10:16:30 +053018
Sujithcbe61d82009-02-09 13:27:12 +053019static void ath9k_hw_analog_shift_rmw(struct ath_hw *ah,
Sujithf1dc5602008-10-29 10:16:30 +053020 u32 reg, u32 mask,
21 u32 shift, u32 val)
22{
23 u32 regVal;
24
25 regVal = REG_READ(ah, reg) & ~mask;
26 regVal |= (val << shift) & mask;
27
28 REG_WRITE(ah, reg, regVal);
29
Sujith2660b812009-02-09 13:27:26 +053030 if (ah->config.analog_shiftreg)
Sujithf1dc5602008-10-29 10:16:30 +053031 udelay(100);
32
33 return;
34}
35
36static inline u16 ath9k_hw_fbin2freq(u8 fbin, bool is2GHz)
37{
38
39 if (fbin == AR5416_BCHAN_UNUSED)
40 return fbin;
41
42 return (u16) ((is2GHz) ? (2300 + fbin) : (4800 + 5 * fbin));
43}
44
45static inline int16_t ath9k_hw_interpolate(u16 target,
46 u16 srcLeft, u16 srcRight,
47 int16_t targetLeft,
48 int16_t targetRight)
49{
50 int16_t rv;
51
52 if (srcRight == srcLeft) {
53 rv = targetLeft;
54 } else {
55 rv = (int16_t) (((target - srcLeft) * targetRight +
56 (srcRight - target) * targetLeft) /
57 (srcRight - srcLeft));
58 }
59 return rv;
60}
61
62static inline bool ath9k_hw_get_lower_upper_index(u8 target, u8 *pList,
63 u16 listSize, u16 *indexL,
64 u16 *indexR)
65{
66 u16 i;
67
68 if (target <= pList[0]) {
69 *indexL = *indexR = 0;
70 return true;
71 }
72 if (target >= pList[listSize - 1]) {
73 *indexL = *indexR = (u16) (listSize - 1);
74 return true;
75 }
76
77 for (i = 0; i < listSize - 1; i++) {
78 if (pList[i] == target) {
79 *indexL = *indexR = i;
80 return true;
81 }
82 if (target < pList[i + 1]) {
83 *indexL = i;
84 *indexR = (u16) (i + 1);
85 return false;
86 }
87 }
88 return false;
89}
90
Sujithcbe61d82009-02-09 13:27:12 +053091static inline bool ath9k_hw_nvram_read(struct ath_hw *ah, u32 off, u16 *data)
Sujithf1dc5602008-10-29 10:16:30 +053092{
Gabor Juhos9dbeb912009-01-14 20:17:08 +010093 struct ath_softc *sc = ah->ah_sc;
94
95 return sc->bus_ops->eeprom_read(ah, off, data);
Sujithf1dc5602008-10-29 10:16:30 +053096}
97
Sujithf74df6f2009-02-09 13:27:24 +053098static inline bool ath9k_hw_fill_vpd_table(u8 pwrMin, u8 pwrMax, u8 *pPwrList,
99 u8 *pVpdList, u16 numIntercepts,
100 u8 *pRetVpdList)
101{
102 u16 i, k;
103 u8 currPwr = pwrMin;
104 u16 idxL = 0, idxR = 0;
105
106 for (i = 0; i <= (pwrMax - pwrMin) / 2; i++) {
107 ath9k_hw_get_lower_upper_index(currPwr, pPwrList,
108 numIntercepts, &(idxL),
109 &(idxR));
110 if (idxR < 1)
111 idxR = 1;
112 if (idxL == numIntercepts - 1)
113 idxL = (u16) (numIntercepts - 2);
114 if (pPwrList[idxL] == pPwrList[idxR])
115 k = pVpdList[idxL];
116 else
117 k = (u16)(((currPwr - pPwrList[idxL]) * pVpdList[idxR] +
118 (pPwrList[idxR] - currPwr) * pVpdList[idxL]) /
119 (pPwrList[idxR] - pPwrList[idxL]));
120 pRetVpdList[i] = (u8) k;
121 currPwr += 2;
122 }
123
124 return true;
125}
126
127static void ath9k_hw_get_legacy_target_powers(struct ath_hw *ah,
128 struct ath9k_channel *chan,
129 struct cal_target_power_leg *powInfo,
130 u16 numChannels,
131 struct cal_target_power_leg *pNewPower,
132 u16 numRates, bool isExtTarget)
133{
134 struct chan_centers centers;
135 u16 clo, chi;
136 int i;
137 int matchIndex = -1, lowIndex = -1;
138 u16 freq;
139
140 ath9k_hw_get_channel_centers(ah, chan, &centers);
141 freq = (isExtTarget) ? centers.ext_center : centers.ctl_center;
142
143 if (freq <= ath9k_hw_fbin2freq(powInfo[0].bChannel,
144 IS_CHAN_2GHZ(chan))) {
145 matchIndex = 0;
146 } else {
147 for (i = 0; (i < numChannels) &&
148 (powInfo[i].bChannel != AR5416_BCHAN_UNUSED); i++) {
149 if (freq == ath9k_hw_fbin2freq(powInfo[i].bChannel,
150 IS_CHAN_2GHZ(chan))) {
151 matchIndex = i;
152 break;
153 } else if ((freq < ath9k_hw_fbin2freq(powInfo[i].bChannel,
154 IS_CHAN_2GHZ(chan))) &&
155 (freq > ath9k_hw_fbin2freq(powInfo[i - 1].bChannel,
156 IS_CHAN_2GHZ(chan)))) {
157 lowIndex = i - 1;
158 break;
159 }
160 }
161 if ((matchIndex == -1) && (lowIndex == -1))
162 matchIndex = i - 1;
163 }
164
165 if (matchIndex != -1) {
166 *pNewPower = powInfo[matchIndex];
167 } else {
168 clo = ath9k_hw_fbin2freq(powInfo[lowIndex].bChannel,
169 IS_CHAN_2GHZ(chan));
170 chi = ath9k_hw_fbin2freq(powInfo[lowIndex + 1].bChannel,
171 IS_CHAN_2GHZ(chan));
172
173 for (i = 0; i < numRates; i++) {
174 pNewPower->tPow2x[i] =
175 (u8)ath9k_hw_interpolate(freq, clo, chi,
176 powInfo[lowIndex].tPow2x[i],
177 powInfo[lowIndex + 1].tPow2x[i]);
178 }
179 }
180}
181
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +0530182static void ath9k_get_txgain_index(struct ath_hw *ah,
183 struct ath9k_channel *chan,
184 struct calDataPerFreqOpLoop *rawDatasetOpLoop,
185 u8 *calChans, u16 availPiers, u8 *pwr, u8 *pcdacIdx)
186{
187 u8 pcdac, i = 0;
188 u16 idxL = 0, idxR = 0, numPiers;
189 bool match;
190 struct chan_centers centers;
191
192 ath9k_hw_get_channel_centers(ah, chan, &centers);
193
194 for (numPiers = 0; numPiers < availPiers; numPiers++)
195 if (calChans[numPiers] == AR5416_BCHAN_UNUSED)
196 break;
197
198 match = ath9k_hw_get_lower_upper_index(
199 (u8)FREQ2FBIN(centers.synth_center, IS_CHAN_2GHZ(chan)),
200 calChans, numPiers, &idxL, &idxR);
201 if (match) {
202 pcdac = rawDatasetOpLoop[idxL].pcdac[0][0];
203 *pwr = rawDatasetOpLoop[idxL].pwrPdg[0][0];
204 } else {
205 pcdac = rawDatasetOpLoop[idxR].pcdac[0][0];
206 *pwr = (rawDatasetOpLoop[idxL].pwrPdg[0][0] +
207 rawDatasetOpLoop[idxR].pwrPdg[0][0])/2;
208 }
209
210 while (pcdac > ah->originalGain[i] &&
211 i < (AR9280_TX_GAIN_TABLE_SIZE - 1))
212 i++;
213
214 *pcdacIdx = i;
215 return;
216}
217
218static void ath9k_olc_get_pdadcs(struct ath_hw *ah,
219 u32 initTxGain,
220 int txPower,
221 u8 *pPDADCValues)
222{
223 u32 i;
224 u32 offset;
225
226 REG_RMW_FIELD(ah, AR_PHY_TX_PWRCTRL6_0,
227 AR_PHY_TX_PWRCTRL_ERR_EST_MODE, 3);
228 REG_RMW_FIELD(ah, AR_PHY_TX_PWRCTRL6_1,
229 AR_PHY_TX_PWRCTRL_ERR_EST_MODE, 3);
230
231 REG_RMW_FIELD(ah, AR_PHY_TX_PWRCTRL7,
232 AR_PHY_TX_PWRCTRL_INIT_TX_GAIN, initTxGain);
233
234 offset = txPower;
235 for (i = 0; i < AR5416_NUM_PDADC_VALUES; i++)
236 if (i < offset)
237 pPDADCValues[i] = 0x0;
238 else
239 pPDADCValues[i] = 0xFF;
240}
241
242
243
244
Sujithf74df6f2009-02-09 13:27:24 +0530245static void ath9k_hw_get_target_powers(struct ath_hw *ah,
246 struct ath9k_channel *chan,
247 struct cal_target_power_ht *powInfo,
248 u16 numChannels,
249 struct cal_target_power_ht *pNewPower,
250 u16 numRates, bool isHt40Target)
251{
252 struct chan_centers centers;
253 u16 clo, chi;
254 int i;
255 int matchIndex = -1, lowIndex = -1;
256 u16 freq;
257
258 ath9k_hw_get_channel_centers(ah, chan, &centers);
259 freq = isHt40Target ? centers.synth_center : centers.ctl_center;
260
261 if (freq <= ath9k_hw_fbin2freq(powInfo[0].bChannel, IS_CHAN_2GHZ(chan))) {
262 matchIndex = 0;
263 } else {
264 for (i = 0; (i < numChannels) &&
265 (powInfo[i].bChannel != AR5416_BCHAN_UNUSED); i++) {
266 if (freq == ath9k_hw_fbin2freq(powInfo[i].bChannel,
267 IS_CHAN_2GHZ(chan))) {
268 matchIndex = i;
269 break;
270 } else
271 if ((freq < ath9k_hw_fbin2freq(powInfo[i].bChannel,
272 IS_CHAN_2GHZ(chan))) &&
273 (freq > ath9k_hw_fbin2freq(powInfo[i - 1].bChannel,
274 IS_CHAN_2GHZ(chan)))) {
275 lowIndex = i - 1;
276 break;
277 }
278 }
279 if ((matchIndex == -1) && (lowIndex == -1))
280 matchIndex = i - 1;
281 }
282
283 if (matchIndex != -1) {
284 *pNewPower = powInfo[matchIndex];
285 } else {
286 clo = ath9k_hw_fbin2freq(powInfo[lowIndex].bChannel,
287 IS_CHAN_2GHZ(chan));
288 chi = ath9k_hw_fbin2freq(powInfo[lowIndex + 1].bChannel,
289 IS_CHAN_2GHZ(chan));
290
291 for (i = 0; i < numRates; i++) {
292 pNewPower->tPow2x[i] = (u8)ath9k_hw_interpolate(freq,
293 clo, chi,
294 powInfo[lowIndex].tPow2x[i],
295 powInfo[lowIndex + 1].tPow2x[i]);
296 }
297 }
298}
299
300static u16 ath9k_hw_get_max_edge_power(u16 freq,
301 struct cal_ctl_edges *pRdEdgesPower,
302 bool is2GHz, int num_band_edges)
303{
304 u16 twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
305 int i;
306
307 for (i = 0; (i < num_band_edges) &&
308 (pRdEdgesPower[i].bChannel != AR5416_BCHAN_UNUSED); i++) {
309 if (freq == ath9k_hw_fbin2freq(pRdEdgesPower[i].bChannel, is2GHz)) {
310 twiceMaxEdgePower = pRdEdgesPower[i].tPower;
311 break;
312 } else if ((i > 0) &&
313 (freq < ath9k_hw_fbin2freq(pRdEdgesPower[i].bChannel,
314 is2GHz))) {
315 if (ath9k_hw_fbin2freq(pRdEdgesPower[i - 1].bChannel,
316 is2GHz) < freq &&
317 pRdEdgesPower[i - 1].flag) {
318 twiceMaxEdgePower =
319 pRdEdgesPower[i - 1].tPower;
320 }
321 break;
322 }
323 }
324
325 return twiceMaxEdgePower;
326}
327
328/****************************************/
329/* EEPROM Operations for 4K sized cards */
330/****************************************/
331
332static int ath9k_hw_4k_get_eeprom_ver(struct ath_hw *ah)
333{
Sujith2660b812009-02-09 13:27:26 +0530334 return ((ah->eeprom.map4k.baseEepHeader.version >> 12) & 0xF);
Sujithf74df6f2009-02-09 13:27:24 +0530335}
336
337static int ath9k_hw_4k_get_eeprom_rev(struct ath_hw *ah)
338{
Sujith2660b812009-02-09 13:27:26 +0530339 return ((ah->eeprom.map4k.baseEepHeader.version) & 0xFFF);
Sujithf74df6f2009-02-09 13:27:24 +0530340}
341
342static bool ath9k_hw_4k_fill_eeprom(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530343{
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530344#define SIZE_EEPROM_4K (sizeof(struct ar5416_eeprom_4k) / sizeof(u16))
Sujith7d01b222009-03-13 08:55:55 +0530345 u16 *eep_data = (u16 *)&ah->eeprom.map4k;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530346 int addr, eep_start_loc = 0;
347
348 eep_start_loc = 64;
Sujithf1dc5602008-10-29 10:16:30 +0530349
350 if (!ath9k_hw_use_flash(ah)) {
351 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
Sujith04bd46382008-11-28 22:18:05 +0530352 "Reading from EEPROM, not flash\n");
Sujithf1dc5602008-10-29 10:16:30 +0530353 }
354
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530355 for (addr = 0; addr < SIZE_EEPROM_4K; addr++) {
356 if (!ath9k_hw_nvram_read(ah, addr + eep_start_loc, eep_data)) {
Sujithf1dc5602008-10-29 10:16:30 +0530357 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530358 "Unable to read eeprom region \n");
Sujithf1dc5602008-10-29 10:16:30 +0530359 return false;
360 }
361 eep_data++;
362 }
Sujith7d01b222009-03-13 08:55:55 +0530363
Sujithf1dc5602008-10-29 10:16:30 +0530364 return true;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530365#undef SIZE_EEPROM_4K
Sujithf1dc5602008-10-29 10:16:30 +0530366}
367
Sujithf74df6f2009-02-09 13:27:24 +0530368static int ath9k_hw_4k_check_eeprom(struct ath_hw *ah)
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530369{
370#define EEPROM_4K_SIZE (sizeof(struct ar5416_eeprom_4k) / sizeof(u16))
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530371 struct ar5416_eeprom_4k *eep =
Sujith2660b812009-02-09 13:27:26 +0530372 (struct ar5416_eeprom_4k *) &ah->eeprom.map4k;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530373 u16 *eepdata, temp, magic, magic2;
374 u32 sum = 0, el;
375 bool need_swap = false;
376 int i, addr;
377
378
379 if (!ath9k_hw_use_flash(ah)) {
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530380 if (!ath9k_hw_nvram_read(ah, AR5416_EEPROM_MAGIC_OFFSET,
381 &magic)) {
Sujith7d01b222009-03-13 08:55:55 +0530382 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530383 "Reading Magic # failed\n");
384 return false;
385 }
386
387 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
Sujith7d01b222009-03-13 08:55:55 +0530388 "Read Magic = 0x%04X\n", magic);
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530389
390 if (magic != AR5416_EEPROM_MAGIC) {
391 magic2 = swab16(magic);
392
393 if (magic2 == AR5416_EEPROM_MAGIC) {
394 need_swap = true;
Sujith2660b812009-02-09 13:27:26 +0530395 eepdata = (u16 *) (&ah->eeprom);
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530396
397 for (addr = 0; addr < EEPROM_4K_SIZE; addr++) {
398 temp = swab16(*eepdata);
399 *eepdata = temp;
400 eepdata++;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530401 }
402 } else {
Sujith7d01b222009-03-13 08:55:55 +0530403 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530404 "Invalid EEPROM Magic. "
405 "endianness mismatch.\n");
406 return -EINVAL;
407 }
408 }
409 }
410
411 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, "need_swap = %s.\n",
412 need_swap ? "True" : "False");
413
414 if (need_swap)
Sujith2660b812009-02-09 13:27:26 +0530415 el = swab16(ah->eeprom.map4k.baseEepHeader.length);
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530416 else
Sujith2660b812009-02-09 13:27:26 +0530417 el = ah->eeprom.map4k.baseEepHeader.length;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530418
419 if (el > sizeof(struct ar5416_eeprom_def))
420 el = sizeof(struct ar5416_eeprom_4k) / sizeof(u16);
421 else
422 el = el / sizeof(u16);
423
Sujith2660b812009-02-09 13:27:26 +0530424 eepdata = (u16 *)(&ah->eeprom);
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530425
426 for (i = 0; i < el; i++)
427 sum ^= *eepdata++;
428
429 if (need_swap) {
430 u32 integer;
431 u16 word;
432
433 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
Sujith7d01b222009-03-13 08:55:55 +0530434 "EEPROM Endianness is not native.. Changing\n");
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530435
436 word = swab16(eep->baseEepHeader.length);
437 eep->baseEepHeader.length = word;
438
439 word = swab16(eep->baseEepHeader.checksum);
440 eep->baseEepHeader.checksum = word;
441
442 word = swab16(eep->baseEepHeader.version);
443 eep->baseEepHeader.version = word;
444
445 word = swab16(eep->baseEepHeader.regDmn[0]);
446 eep->baseEepHeader.regDmn[0] = word;
447
448 word = swab16(eep->baseEepHeader.regDmn[1]);
449 eep->baseEepHeader.regDmn[1] = word;
450
451 word = swab16(eep->baseEepHeader.rfSilent);
452 eep->baseEepHeader.rfSilent = word;
453
454 word = swab16(eep->baseEepHeader.blueToothOptions);
455 eep->baseEepHeader.blueToothOptions = word;
456
457 word = swab16(eep->baseEepHeader.deviceCap);
458 eep->baseEepHeader.deviceCap = word;
459
460 integer = swab32(eep->modalHeader.antCtrlCommon);
461 eep->modalHeader.antCtrlCommon = integer;
462
463 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
464 integer = swab32(eep->modalHeader.antCtrlChain[i]);
465 eep->modalHeader.antCtrlChain[i] = integer;
466 }
467
468 for (i = 0; i < AR5416_EEPROM_MODAL_SPURS; i++) {
469 word = swab16(eep->modalHeader.spurChans[i].spurChan);
470 eep->modalHeader.spurChans[i].spurChan = word;
471 }
472 }
473
Sujithf74df6f2009-02-09 13:27:24 +0530474 if (sum != 0xffff || ah->eep_ops->get_eeprom_ver(ah) != AR5416_EEP_VER ||
475 ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_NO_BACK_VER) {
Sujith7d01b222009-03-13 08:55:55 +0530476 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530477 "Bad EEPROM checksum 0x%x or revision 0x%04x\n",
Sujithf74df6f2009-02-09 13:27:24 +0530478 sum, ah->eep_ops->get_eeprom_ver(ah));
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530479 return -EINVAL;
480 }
481
482 return 0;
483#undef EEPROM_4K_SIZE
484}
485
Sujithf74df6f2009-02-09 13:27:24 +0530486static u32 ath9k_hw_4k_get_eeprom(struct ath_hw *ah,
487 enum eeprom_param param)
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530488{
Sujith2660b812009-02-09 13:27:26 +0530489 struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k;
Sujithf74df6f2009-02-09 13:27:24 +0530490 struct modal_eep_4k_header *pModal = &eep->modalHeader;
491 struct base_eep_header_4k *pBase = &eep->baseEepHeader;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530492
Sujithf74df6f2009-02-09 13:27:24 +0530493 switch (param) {
494 case EEP_NFTHRESH_2:
Sujith668158a2009-02-12 10:06:52 +0530495 return pModal->noiseFloorThreshCh[0];
Sujithf74df6f2009-02-09 13:27:24 +0530496 case AR_EEPROM_MAC(0):
497 return pBase->macAddr[0] << 8 | pBase->macAddr[1];
498 case AR_EEPROM_MAC(1):
499 return pBase->macAddr[2] << 8 | pBase->macAddr[3];
500 case AR_EEPROM_MAC(2):
501 return pBase->macAddr[4] << 8 | pBase->macAddr[5];
502 case EEP_REG_0:
503 return pBase->regDmn[0];
504 case EEP_REG_1:
505 return pBase->regDmn[1];
506 case EEP_OP_CAP:
507 return pBase->deviceCap;
508 case EEP_OP_MODE:
509 return pBase->opCapFlags;
510 case EEP_RF_SILENT:
511 return pBase->rfSilent;
512 case EEP_OB_2:
513 return pModal->ob_01;
514 case EEP_DB_2:
515 return pModal->db1_01;
516 case EEP_MINOR_REV:
517 return pBase->version & AR5416_EEP_VER_MINOR_MASK;
518 case EEP_TX_MASK:
519 return pBase->txMask;
520 case EEP_RX_MASK:
521 return pBase->rxMask;
Sujith06d0f062009-02-12 10:06:45 +0530522 case EEP_FRAC_N_5G:
523 return 0;
Sujithf74df6f2009-02-09 13:27:24 +0530524 default:
525 return 0;
Sujithf1dc5602008-10-29 10:16:30 +0530526 }
Sujithf1dc5602008-10-29 10:16:30 +0530527}
528
Sujithcbe61d82009-02-09 13:27:12 +0530529static void ath9k_hw_get_4k_gain_boundaries_pdadcs(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530530 struct ath9k_channel *chan,
531 struct cal_data_per_freq_4k *pRawDataSet,
532 u8 *bChans, u16 availPiers,
533 u16 tPdGainOverlap, int16_t *pMinCalPower,
534 u16 *pPdGainBoundaries, u8 *pPDADCValues,
535 u16 numXpdGains)
536{
537#define TMP_VAL_VPD_TABLE \
538 ((vpdTableI[i][sizeCurrVpdTable - 1] + (ss - maxIndex + 1) * vpdStep));
539 int i, j, k;
540 int16_t ss;
541 u16 idxL = 0, idxR = 0, numPiers;
542 static u8 vpdTableL[AR5416_EEP4K_NUM_PD_GAINS]
543 [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
544 static u8 vpdTableR[AR5416_EEP4K_NUM_PD_GAINS]
545 [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
546 static u8 vpdTableI[AR5416_EEP4K_NUM_PD_GAINS]
547 [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
548
549 u8 *pVpdL, *pVpdR, *pPwrL, *pPwrR;
550 u8 minPwrT4[AR5416_EEP4K_NUM_PD_GAINS];
551 u8 maxPwrT4[AR5416_EEP4K_NUM_PD_GAINS];
552 int16_t vpdStep;
553 int16_t tmpVal;
554 u16 sizeCurrVpdTable, maxIndex, tgtIndex;
555 bool match;
556 int16_t minDelta = 0;
557 struct chan_centers centers;
558#define PD_GAIN_BOUNDARY_DEFAULT 58;
559
560 ath9k_hw_get_channel_centers(ah, chan, &centers);
561
562 for (numPiers = 0; numPiers < availPiers; numPiers++) {
563 if (bChans[numPiers] == AR5416_BCHAN_UNUSED)
564 break;
565 }
566
567 match = ath9k_hw_get_lower_upper_index(
568 (u8)FREQ2FBIN(centers.synth_center,
569 IS_CHAN_2GHZ(chan)), bChans, numPiers,
570 &idxL, &idxR);
571
572 if (match) {
573 for (i = 0; i < numXpdGains; i++) {
574 minPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][0];
575 maxPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][4];
576 ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
577 pRawDataSet[idxL].pwrPdg[i],
578 pRawDataSet[idxL].vpdPdg[i],
579 AR5416_EEP4K_PD_GAIN_ICEPTS,
580 vpdTableI[i]);
581 }
582 } else {
583 for (i = 0; i < numXpdGains; i++) {
584 pVpdL = pRawDataSet[idxL].vpdPdg[i];
585 pPwrL = pRawDataSet[idxL].pwrPdg[i];
586 pVpdR = pRawDataSet[idxR].vpdPdg[i];
587 pPwrR = pRawDataSet[idxR].pwrPdg[i];
588
589 minPwrT4[i] = max(pPwrL[0], pPwrR[0]);
590
591 maxPwrT4[i] =
592 min(pPwrL[AR5416_EEP4K_PD_GAIN_ICEPTS - 1],
593 pPwrR[AR5416_EEP4K_PD_GAIN_ICEPTS - 1]);
594
595
596 ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
597 pPwrL, pVpdL,
598 AR5416_EEP4K_PD_GAIN_ICEPTS,
599 vpdTableL[i]);
600 ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
601 pPwrR, pVpdR,
602 AR5416_EEP4K_PD_GAIN_ICEPTS,
603 vpdTableR[i]);
604
605 for (j = 0; j <= (maxPwrT4[i] - minPwrT4[i]) / 2; j++) {
606 vpdTableI[i][j] =
607 (u8)(ath9k_hw_interpolate((u16)
608 FREQ2FBIN(centers.
609 synth_center,
610 IS_CHAN_2GHZ
611 (chan)),
612 bChans[idxL], bChans[idxR],
613 vpdTableL[i][j], vpdTableR[i][j]));
614 }
615 }
616 }
617
618 *pMinCalPower = (int16_t)(minPwrT4[0] / 2);
619
620 k = 0;
621
622 for (i = 0; i < numXpdGains; i++) {
623 if (i == (numXpdGains - 1))
624 pPdGainBoundaries[i] =
625 (u16)(maxPwrT4[i] / 2);
626 else
627 pPdGainBoundaries[i] =
628 (u16)((maxPwrT4[i] + minPwrT4[i + 1]) / 4);
629
630 pPdGainBoundaries[i] =
631 min((u16)AR5416_MAX_RATE_POWER, pPdGainBoundaries[i]);
632
Gabor Juhosa8c96d32009-03-06 09:08:51 +0100633 if ((i == 0) && !AR_SREV_5416_20_OR_LATER(ah)) {
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530634 minDelta = pPdGainBoundaries[0] - 23;
635 pPdGainBoundaries[0] = 23;
636 } else {
637 minDelta = 0;
638 }
639
640 if (i == 0) {
641 if (AR_SREV_9280_10_OR_LATER(ah))
642 ss = (int16_t)(0 - (minPwrT4[i] / 2));
643 else
644 ss = 0;
645 } else {
646 ss = (int16_t)((pPdGainBoundaries[i - 1] -
647 (minPwrT4[i] / 2)) -
648 tPdGainOverlap + 1 + minDelta);
649 }
650 vpdStep = (int16_t)(vpdTableI[i][1] - vpdTableI[i][0]);
651 vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
652
653 while ((ss < 0) && (k < (AR5416_NUM_PDADC_VALUES - 1))) {
654 tmpVal = (int16_t)(vpdTableI[i][0] + ss * vpdStep);
655 pPDADCValues[k++] = (u8)((tmpVal < 0) ? 0 : tmpVal);
656 ss++;
657 }
658
659 sizeCurrVpdTable = (u8) ((maxPwrT4[i] - minPwrT4[i]) / 2 + 1);
660 tgtIndex = (u8)(pPdGainBoundaries[i] + tPdGainOverlap -
661 (minPwrT4[i] / 2));
662 maxIndex = (tgtIndex < sizeCurrVpdTable) ?
663 tgtIndex : sizeCurrVpdTable;
664
665 while ((ss < maxIndex) && (k < (AR5416_NUM_PDADC_VALUES - 1)))
666 pPDADCValues[k++] = vpdTableI[i][ss++];
667
668 vpdStep = (int16_t)(vpdTableI[i][sizeCurrVpdTable - 1] -
669 vpdTableI[i][sizeCurrVpdTable - 2]);
670 vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
671
Vasanthakumar Thiagarajanbe1b08a2009-03-06 20:38:36 +0530672 if (tgtIndex >= maxIndex) {
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530673 while ((ss <= tgtIndex) &&
674 (k < (AR5416_NUM_PDADC_VALUES - 1))) {
675 tmpVal = (int16_t) TMP_VAL_VPD_TABLE;
676 pPDADCValues[k++] = (u8)((tmpVal > 255) ?
677 255 : tmpVal);
678 ss++;
679 }
680 }
681 }
682
683 while (i < AR5416_EEP4K_PD_GAINS_IN_MASK) {
684 pPdGainBoundaries[i] = PD_GAIN_BOUNDARY_DEFAULT;
685 i++;
686 }
687
688 while (k < AR5416_NUM_PDADC_VALUES) {
689 pPDADCValues[k] = pPDADCValues[k - 1];
690 k++;
691 }
692
693 return;
694#undef TMP_VAL_VPD_TABLE
695}
696
Sujithcbe61d82009-02-09 13:27:12 +0530697static bool ath9k_hw_set_4k_power_cal_table(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530698 struct ath9k_channel *chan,
699 int16_t *pTxPowerIndexOffset)
700{
Sujith2660b812009-02-09 13:27:26 +0530701 struct ar5416_eeprom_4k *pEepData = &ah->eeprom.map4k;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530702 struct cal_data_per_freq_4k *pRawDataset;
703 u8 *pCalBChans = NULL;
704 u16 pdGainOverlap_t2;
705 static u8 pdadcValues[AR5416_NUM_PDADC_VALUES];
Vasanthakumar Thiagarajanbe1b08a2009-03-06 20:38:36 +0530706 u16 gainBoundaries[AR5416_EEP4K_PD_GAINS_IN_MASK];
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530707 u16 numPiers, i, j;
708 int16_t tMinCalPower;
709 u16 numXpdGain, xpdMask;
Vasanthakumar Thiagarajanbe1b08a2009-03-06 20:38:36 +0530710 u16 xpdGainValues[AR5416_EEP4K_NUM_PD_GAINS] = { 0, 0 };
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530711 u32 reg32, regOffset, regChainOffset;
712
713 xpdMask = pEepData->modalHeader.xpdGain;
714
715 if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
716 AR5416_EEP_MINOR_VER_2) {
717 pdGainOverlap_t2 =
718 pEepData->modalHeader.pdGainOverlap;
719 } else {
720 pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5),
721 AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
722 }
723
724 pCalBChans = pEepData->calFreqPier2G;
Vasanthakumar Thiagarajanbe1b08a2009-03-06 20:38:36 +0530725 numPiers = AR5416_EEP4K_NUM_2G_CAL_PIERS;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530726
727 numXpdGain = 0;
728
Vasanthakumar Thiagarajanbe1b08a2009-03-06 20:38:36 +0530729 for (i = 1; i <= AR5416_EEP4K_PD_GAINS_IN_MASK; i++) {
730 if ((xpdMask >> (AR5416_EEP4K_PD_GAINS_IN_MASK - i)) & 1) {
731 if (numXpdGain >= AR5416_EEP4K_NUM_PD_GAINS)
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530732 break;
733 xpdGainValues[numXpdGain] =
Vasanthakumar Thiagarajanbe1b08a2009-03-06 20:38:36 +0530734 (u16)(AR5416_EEP4K_PD_GAINS_IN_MASK - i);
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530735 numXpdGain++;
736 }
737 }
738
739 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
740 (numXpdGain - 1) & 0x3);
741 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,
742 xpdGainValues[0]);
743 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
744 xpdGainValues[1]);
Vasanthakumar Thiagarajanf40154e2009-02-25 10:28:22 +0530745 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3, 0);
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530746
Vasanthakumar Thiagarajanbe1b08a2009-03-06 20:38:36 +0530747 for (i = 0; i < AR5416_EEP4K_MAX_CHAINS; i++) {
Gabor Juhosa8c96d32009-03-06 09:08:51 +0100748 if (AR_SREV_5416_20_OR_LATER(ah) &&
Sujith2660b812009-02-09 13:27:26 +0530749 (ah->rxchainmask == 5 || ah->txchainmask == 5) &&
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530750 (i != 0)) {
751 regChainOffset = (i == 1) ? 0x2000 : 0x1000;
752 } else
753 regChainOffset = i * 0x1000;
754
755 if (pEepData->baseEepHeader.txMask & (1 << i)) {
756 pRawDataset = pEepData->calPierData2G[i];
757
758 ath9k_hw_get_4k_gain_boundaries_pdadcs(ah, chan,
759 pRawDataset, pCalBChans,
760 numPiers, pdGainOverlap_t2,
761 &tMinCalPower, gainBoundaries,
762 pdadcValues, numXpdGain);
763
Gabor Juhosa8c96d32009-03-06 09:08:51 +0100764 if ((i == 0) || AR_SREV_5416_20_OR_LATER(ah)) {
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530765 REG_WRITE(ah, AR_PHY_TPCRG5 + regChainOffset,
766 SM(pdGainOverlap_t2,
767 AR_PHY_TPCRG5_PD_GAIN_OVERLAP)
768 | SM(gainBoundaries[0],
769 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1)
770 | SM(gainBoundaries[1],
771 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2)
772 | SM(gainBoundaries[2],
773 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3)
774 | SM(gainBoundaries[3],
775 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4));
776 }
777
778 regOffset = AR_PHY_BASE + (672 << 2) + regChainOffset;
779 for (j = 0; j < 32; j++) {
780 reg32 = ((pdadcValues[4 * j + 0] & 0xFF) << 0) |
781 ((pdadcValues[4 * j + 1] & 0xFF) << 8) |
782 ((pdadcValues[4 * j + 2] & 0xFF) << 16)|
783 ((pdadcValues[4 * j + 3] & 0xFF) << 24);
784 REG_WRITE(ah, regOffset, reg32);
785
786 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
787 "PDADC (%d,%4x): %4.4x %8.8x\n",
788 i, regChainOffset, regOffset,
789 reg32);
790 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
791 "PDADC: Chain %d | "
792 "PDADC %3d Value %3d | "
793 "PDADC %3d Value %3d | "
794 "PDADC %3d Value %3d | "
795 "PDADC %3d Value %3d |\n",
796 i, 4 * j, pdadcValues[4 * j],
797 4 * j + 1, pdadcValues[4 * j + 1],
798 4 * j + 2, pdadcValues[4 * j + 2],
799 4 * j + 3,
800 pdadcValues[4 * j + 3]);
801
802 regOffset += 4;
803 }
804 }
805 }
806
807 *pTxPowerIndexOffset = 0;
808
809 return true;
810}
811
Sujithcbe61d82009-02-09 13:27:12 +0530812static bool ath9k_hw_set_4k_power_per_rate_table(struct ath_hw *ah,
Hannes Ederbf512bc2008-12-26 00:13:29 -0800813 struct ath9k_channel *chan,
814 int16_t *ratesArray,
815 u16 cfgCtl,
816 u16 AntennaReduction,
817 u16 twiceMaxRegulatoryPower,
818 u16 powerLimit)
Sujithf1dc5602008-10-29 10:16:30 +0530819{
Sujith2660b812009-02-09 13:27:26 +0530820 struct ar5416_eeprom_4k *pEepData = &ah->eeprom.map4k;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530821 u16 twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
822 static const u16 tpScaleReductionTable[5] =
823 { 0, 3, 6, 9, AR5416_MAX_RATE_POWER };
Sujithf1dc5602008-10-29 10:16:30 +0530824
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530825 int i;
826 int16_t twiceLargestAntenna;
827 struct cal_ctl_data_4k *rep;
828 struct cal_target_power_leg targetPowerOfdm, targetPowerCck = {
829 0, { 0, 0, 0, 0}
830 };
831 struct cal_target_power_leg targetPowerOfdmExt = {
832 0, { 0, 0, 0, 0} }, targetPowerCckExt = {
833 0, { 0, 0, 0, 0 }
834 };
835 struct cal_target_power_ht targetPowerHt20, targetPowerHt40 = {
836 0, {0, 0, 0, 0}
837 };
838 u16 scaledPower = 0, minCtlPower, maxRegAllowedPower;
839 u16 ctlModesFor11g[] =
840 { CTL_11B, CTL_11G, CTL_2GHT20, CTL_11B_EXT, CTL_11G_EXT,
841 CTL_2GHT40
842 };
843 u16 numCtlModes, *pCtlMode, ctlMode, freq;
844 struct chan_centers centers;
845 int tx_chainmask;
846 u16 twiceMinEdgePower;
Sujithf1dc5602008-10-29 10:16:30 +0530847
Sujith2660b812009-02-09 13:27:26 +0530848 tx_chainmask = ah->txchainmask;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530849
850 ath9k_hw_get_channel_centers(ah, chan, &centers);
851
852 twiceLargestAntenna = pEepData->modalHeader.antennaGainCh[0];
853
854 twiceLargestAntenna = (int16_t)min(AntennaReduction -
855 twiceLargestAntenna, 0);
856
857 maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
858
Sujithd6bad492009-02-09 13:27:08 +0530859 if (ah->regulatory.tp_scale != ATH9K_TP_SCALE_MAX) {
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530860 maxRegAllowedPower -=
Sujithd6bad492009-02-09 13:27:08 +0530861 (tpScaleReductionTable[(ah->regulatory.tp_scale)] * 2);
Sujithf1dc5602008-10-29 10:16:30 +0530862 }
863
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530864 scaledPower = min(powerLimit, maxRegAllowedPower);
865 scaledPower = max((u16)0, scaledPower);
866
867 numCtlModes = ARRAY_SIZE(ctlModesFor11g) - SUB_NUM_CTL_MODES_AT_2G_40;
868 pCtlMode = ctlModesFor11g;
869
870 ath9k_hw_get_legacy_target_powers(ah, chan,
871 pEepData->calTargetPowerCck,
872 AR5416_NUM_2G_CCK_TARGET_POWERS,
873 &targetPowerCck, 4, false);
874 ath9k_hw_get_legacy_target_powers(ah, chan,
875 pEepData->calTargetPower2G,
876 AR5416_NUM_2G_20_TARGET_POWERS,
877 &targetPowerOfdm, 4, false);
878 ath9k_hw_get_target_powers(ah, chan,
879 pEepData->calTargetPower2GHT20,
880 AR5416_NUM_2G_20_TARGET_POWERS,
881 &targetPowerHt20, 8, false);
882
883 if (IS_CHAN_HT40(chan)) {
884 numCtlModes = ARRAY_SIZE(ctlModesFor11g);
885 ath9k_hw_get_target_powers(ah, chan,
886 pEepData->calTargetPower2GHT40,
887 AR5416_NUM_2G_40_TARGET_POWERS,
888 &targetPowerHt40, 8, true);
889 ath9k_hw_get_legacy_target_powers(ah, chan,
890 pEepData->calTargetPowerCck,
891 AR5416_NUM_2G_CCK_TARGET_POWERS,
892 &targetPowerCckExt, 4, true);
893 ath9k_hw_get_legacy_target_powers(ah, chan,
894 pEepData->calTargetPower2G,
895 AR5416_NUM_2G_20_TARGET_POWERS,
896 &targetPowerOfdmExt, 4, true);
Sujithf1dc5602008-10-29 10:16:30 +0530897 }
898
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530899 for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
900 bool isHt40CtlMode = (pCtlMode[ctlMode] == CTL_5GHT40) ||
901 (pCtlMode[ctlMode] == CTL_2GHT40);
902 if (isHt40CtlMode)
903 freq = centers.synth_center;
904 else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
905 freq = centers.ext_center;
906 else
907 freq = centers.ctl_center;
Sujithf1dc5602008-10-29 10:16:30 +0530908
Sujithf74df6f2009-02-09 13:27:24 +0530909 if (ah->eep_ops->get_eeprom_ver(ah) == 14 &&
910 ah->eep_ops->get_eeprom_rev(ah) <= 2)
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530911 twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
912
913 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
914 "LOOP-Mode ctlMode %d < %d, isHt40CtlMode %d, "
915 "EXT_ADDITIVE %d\n",
916 ctlMode, numCtlModes, isHt40CtlMode,
917 (pCtlMode[ctlMode] & EXT_ADDITIVE));
918
919 for (i = 0; (i < AR5416_NUM_CTLS) &&
920 pEepData->ctlIndex[i]; i++) {
921 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
922 " LOOP-Ctlidx %d: cfgCtl 0x%2.2x "
923 "pCtlMode 0x%2.2x ctlIndex 0x%2.2x "
924 "chan %d\n",
925 i, cfgCtl, pCtlMode[ctlMode],
926 pEepData->ctlIndex[i], chan->channel);
927
928 if ((((cfgCtl & ~CTL_MODE_M) |
929 (pCtlMode[ctlMode] & CTL_MODE_M)) ==
930 pEepData->ctlIndex[i]) ||
931 (((cfgCtl & ~CTL_MODE_M) |
932 (pCtlMode[ctlMode] & CTL_MODE_M)) ==
933 ((pEepData->ctlIndex[i] & CTL_MODE_M) |
934 SD_NO_CTL))) {
935 rep = &(pEepData->ctlData[i]);
936
937 twiceMinEdgePower =
938 ath9k_hw_get_max_edge_power(freq,
939 rep->ctlEdges[ar5416_get_ntxchains
940 (tx_chainmask) - 1],
941 IS_CHAN_2GHZ(chan),
942 AR5416_EEP4K_NUM_BAND_EDGES);
943
944 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
945 " MATCH-EE_IDX %d: ch %d is2 %d "
946 "2xMinEdge %d chainmask %d chains %d\n",
947 i, freq, IS_CHAN_2GHZ(chan),
948 twiceMinEdgePower, tx_chainmask,
949 ar5416_get_ntxchains
950 (tx_chainmask));
951 if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {
952 twiceMaxEdgePower =
953 min(twiceMaxEdgePower,
954 twiceMinEdgePower);
955 } else {
956 twiceMaxEdgePower = twiceMinEdgePower;
957 break;
958 }
959 }
960 }
961
962 minCtlPower = (u8)min(twiceMaxEdgePower, scaledPower);
963
964 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
965 " SEL-Min ctlMode %d pCtlMode %d "
966 "2xMaxEdge %d sP %d minCtlPwr %d\n",
967 ctlMode, pCtlMode[ctlMode], twiceMaxEdgePower,
968 scaledPower, minCtlPower);
969
970 switch (pCtlMode[ctlMode]) {
971 case CTL_11B:
972 for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x);
973 i++) {
974 targetPowerCck.tPow2x[i] =
975 min((u16)targetPowerCck.tPow2x[i],
976 minCtlPower);
977 }
978 break;
979 case CTL_11G:
980 for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x);
981 i++) {
982 targetPowerOfdm.tPow2x[i] =
983 min((u16)targetPowerOfdm.tPow2x[i],
984 minCtlPower);
985 }
986 break;
987 case CTL_2GHT20:
988 for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x);
989 i++) {
990 targetPowerHt20.tPow2x[i] =
991 min((u16)targetPowerHt20.tPow2x[i],
992 minCtlPower);
993 }
994 break;
995 case CTL_11B_EXT:
996 targetPowerCckExt.tPow2x[0] = min((u16)
997 targetPowerCckExt.tPow2x[0],
998 minCtlPower);
999 break;
1000 case CTL_11G_EXT:
1001 targetPowerOfdmExt.tPow2x[0] = min((u16)
1002 targetPowerOfdmExt.tPow2x[0],
1003 minCtlPower);
1004 break;
1005 case CTL_2GHT40:
1006 for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x);
1007 i++) {
1008 targetPowerHt40.tPow2x[i] =
1009 min((u16)targetPowerHt40.tPow2x[i],
1010 minCtlPower);
1011 }
1012 break;
1013 default:
1014 break;
Sujithf1dc5602008-10-29 10:16:30 +05301015 }
1016 }
1017
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301018 ratesArray[rate6mb] = ratesArray[rate9mb] = ratesArray[rate12mb] =
1019 ratesArray[rate18mb] = ratesArray[rate24mb] =
1020 targetPowerOfdm.tPow2x[0];
1021 ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1];
1022 ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2];
1023 ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3];
1024 ratesArray[rateXr] = targetPowerOfdm.tPow2x[0];
Sujithf1dc5602008-10-29 10:16:30 +05301025
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301026 for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++)
1027 ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i];
Sujithf1dc5602008-10-29 10:16:30 +05301028
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301029 ratesArray[rate1l] = targetPowerCck.tPow2x[0];
1030 ratesArray[rate2s] = ratesArray[rate2l] = targetPowerCck.tPow2x[1];
1031 ratesArray[rate5_5s] = ratesArray[rate5_5l] = targetPowerCck.tPow2x[2];
1032 ratesArray[rate11s] = ratesArray[rate11l] = targetPowerCck.tPow2x[3];
Sujithf1dc5602008-10-29 10:16:30 +05301033
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301034 if (IS_CHAN_HT40(chan)) {
1035 for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
1036 ratesArray[rateHt40_0 + i] =
1037 targetPowerHt40.tPow2x[i];
Sujithf1dc5602008-10-29 10:16:30 +05301038 }
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301039 ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0];
1040 ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0];
1041 ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0];
1042 ratesArray[rateExtCck] = targetPowerCckExt.tPow2x[0];
Sujithf1dc5602008-10-29 10:16:30 +05301043 }
Sujithf1dc5602008-10-29 10:16:30 +05301044 return true;
1045}
1046
Sujithcbe61d82009-02-09 13:27:12 +05301047static int ath9k_hw_4k_set_txpower(struct ath_hw *ah,
Sujithf74df6f2009-02-09 13:27:24 +05301048 struct ath9k_channel *chan,
1049 u16 cfgCtl,
1050 u8 twiceAntennaReduction,
1051 u8 twiceMaxRegulatoryPower,
1052 u8 powerLimit)
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301053{
Sujith2660b812009-02-09 13:27:26 +05301054 struct ar5416_eeprom_4k *pEepData = &ah->eeprom.map4k;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301055 struct modal_eep_4k_header *pModal = &pEepData->modalHeader;
1056 int16_t ratesArray[Ar5416RateSize];
1057 int16_t txPowerIndexOffset = 0;
1058 u8 ht40PowerIncForPdadc = 2;
1059 int i;
1060
1061 memset(ratesArray, 0, sizeof(ratesArray));
1062
1063 if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
1064 AR5416_EEP_MINOR_VER_2) {
1065 ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
1066 }
1067
1068 if (!ath9k_hw_set_4k_power_per_rate_table(ah, chan,
1069 &ratesArray[0], cfgCtl,
1070 twiceAntennaReduction,
1071 twiceMaxRegulatoryPower,
1072 powerLimit)) {
1073 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
1074 "ath9k_hw_set_txpower: unable to set "
1075 "tx power per rate table\n");
1076 return -EIO;
1077 }
1078
1079 if (!ath9k_hw_set_4k_power_cal_table(ah, chan, &txPowerIndexOffset)) {
1080 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
1081 "ath9k_hw_set_txpower: unable to set power table\n");
1082 return -EIO;
1083 }
1084
1085 for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
1086 ratesArray[i] = (int16_t)(txPowerIndexOffset + ratesArray[i]);
1087 if (ratesArray[i] > AR5416_MAX_RATE_POWER)
1088 ratesArray[i] = AR5416_MAX_RATE_POWER;
1089 }
1090
1091 if (AR_SREV_9280_10_OR_LATER(ah)) {
1092 for (i = 0; i < Ar5416RateSize; i++)
1093 ratesArray[i] -= AR5416_PWR_TABLE_OFFSET * 2;
1094 }
1095
1096 REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
1097 ATH9K_POW_SM(ratesArray[rate18mb], 24)
1098 | ATH9K_POW_SM(ratesArray[rate12mb], 16)
1099 | ATH9K_POW_SM(ratesArray[rate9mb], 8)
1100 | ATH9K_POW_SM(ratesArray[rate6mb], 0));
1101 REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
1102 ATH9K_POW_SM(ratesArray[rate54mb], 24)
1103 | ATH9K_POW_SM(ratesArray[rate48mb], 16)
1104 | ATH9K_POW_SM(ratesArray[rate36mb], 8)
1105 | ATH9K_POW_SM(ratesArray[rate24mb], 0));
1106
1107 if (IS_CHAN_2GHZ(chan)) {
1108 REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
1109 ATH9K_POW_SM(ratesArray[rate2s], 24)
1110 | ATH9K_POW_SM(ratesArray[rate2l], 16)
1111 | ATH9K_POW_SM(ratesArray[rateXr], 8)
1112 | ATH9K_POW_SM(ratesArray[rate1l], 0));
1113 REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
1114 ATH9K_POW_SM(ratesArray[rate11s], 24)
1115 | ATH9K_POW_SM(ratesArray[rate11l], 16)
1116 | ATH9K_POW_SM(ratesArray[rate5_5s], 8)
1117 | ATH9K_POW_SM(ratesArray[rate5_5l], 0));
1118 }
1119
1120 REG_WRITE(ah, AR_PHY_POWER_TX_RATE5,
1121 ATH9K_POW_SM(ratesArray[rateHt20_3], 24)
1122 | ATH9K_POW_SM(ratesArray[rateHt20_2], 16)
1123 | ATH9K_POW_SM(ratesArray[rateHt20_1], 8)
1124 | ATH9K_POW_SM(ratesArray[rateHt20_0], 0));
1125 REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
1126 ATH9K_POW_SM(ratesArray[rateHt20_7], 24)
1127 | ATH9K_POW_SM(ratesArray[rateHt20_6], 16)
1128 | ATH9K_POW_SM(ratesArray[rateHt20_5], 8)
1129 | ATH9K_POW_SM(ratesArray[rateHt20_4], 0));
1130
1131 if (IS_CHAN_HT40(chan)) {
1132 REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
1133 ATH9K_POW_SM(ratesArray[rateHt40_3] +
1134 ht40PowerIncForPdadc, 24)
1135 | ATH9K_POW_SM(ratesArray[rateHt40_2] +
1136 ht40PowerIncForPdadc, 16)
1137 | ATH9K_POW_SM(ratesArray[rateHt40_1] +
1138 ht40PowerIncForPdadc, 8)
1139 | ATH9K_POW_SM(ratesArray[rateHt40_0] +
1140 ht40PowerIncForPdadc, 0));
1141 REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
1142 ATH9K_POW_SM(ratesArray[rateHt40_7] +
1143 ht40PowerIncForPdadc, 24)
1144 | ATH9K_POW_SM(ratesArray[rateHt40_6] +
1145 ht40PowerIncForPdadc, 16)
1146 | ATH9K_POW_SM(ratesArray[rateHt40_5] +
1147 ht40PowerIncForPdadc, 8)
1148 | ATH9K_POW_SM(ratesArray[rateHt40_4] +
1149 ht40PowerIncForPdadc, 0));
1150
1151 REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
1152 ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
1153 | ATH9K_POW_SM(ratesArray[rateExtCck], 16)
1154 | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
1155 | ATH9K_POW_SM(ratesArray[rateDupCck], 0));
1156 }
1157
1158 i = rate6mb;
1159
1160 if (IS_CHAN_HT40(chan))
1161 i = rateHt40_0;
1162 else if (IS_CHAN_HT20(chan))
1163 i = rateHt20_0;
1164
1165 if (AR_SREV_9280_10_OR_LATER(ah))
Sujithd6bad492009-02-09 13:27:08 +05301166 ah->regulatory.max_power_level =
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301167 ratesArray[i] + AR5416_PWR_TABLE_OFFSET * 2;
1168 else
Sujithd6bad492009-02-09 13:27:08 +05301169 ah->regulatory.max_power_level = ratesArray[i];
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301170
1171 return 0;
1172}
1173
Sujithf74df6f2009-02-09 13:27:24 +05301174static void ath9k_hw_4k_set_addac(struct ath_hw *ah,
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301175 struct ath9k_channel *chan)
1176{
1177 struct modal_eep_4k_header *pModal;
Sujith2660b812009-02-09 13:27:26 +05301178 struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301179 u8 biaslevel;
1180
Sujithd535a422009-02-09 13:27:06 +05301181 if (ah->hw_version.macVersion != AR_SREV_VERSION_9160)
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301182 return;
1183
Sujithf74df6f2009-02-09 13:27:24 +05301184 if (ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_MINOR_VER_7)
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301185 return;
1186
1187 pModal = &eep->modalHeader;
1188
1189 if (pModal->xpaBiasLvl != 0xff) {
1190 biaslevel = pModal->xpaBiasLvl;
Sujith2660b812009-02-09 13:27:26 +05301191 INI_RA(&ah->iniAddac, 7, 1) =
1192 (INI_RA(&ah->iniAddac, 7, 1) & (~0x18)) | biaslevel << 3;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301193 }
1194}
1195
Sujitha83615d2009-03-13 08:56:04 +05301196static void ath9k_hw_4k_set_gain(struct ath_hw *ah,
1197 struct modal_eep_4k_header *pModal,
1198 struct ar5416_eeprom_4k *eep,
1199 u8 txRxAttenLocal, int regChainOffset)
1200{
1201 REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
1202 pModal->antCtrlChain[0]);
1203
1204 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
1205 (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset) &
1206 ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
1207 AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
1208 SM(pModal->iqCalICh[0], AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
1209 SM(pModal->iqCalQCh[0], AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
1210
1211 if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
1212 AR5416_EEP_MINOR_VER_3) {
1213 txRxAttenLocal = pModal->txRxAttenCh[0];
1214
1215 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
1216 AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN, pModal->bswMargin[0]);
1217 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
1218 AR_PHY_GAIN_2GHZ_XATTEN1_DB, pModal->bswAtten[0]);
1219 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
1220 AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN,
1221 pModal->xatten2Margin[0]);
1222 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
1223 AR_PHY_GAIN_2GHZ_XATTEN2_DB, pModal->xatten2Db[0]);
1224 }
1225
1226 REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
1227 AR9280_PHY_RXGAIN_TXRX_ATTEN, txRxAttenLocal);
1228 REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
1229 AR9280_PHY_RXGAIN_TXRX_MARGIN, pModal->rxTxMarginCh[0]);
1230
1231 if (AR_SREV_9285_11(ah))
1232 REG_WRITE(ah, AR9285_AN_TOP4, (AR9285_AN_TOP4_DEFAULT | 0x14));
1233}
1234
Sujithf74df6f2009-02-09 13:27:24 +05301235static bool ath9k_hw_4k_set_board_values(struct ath_hw *ah,
1236 struct ath9k_channel *chan)
1237{
1238 struct modal_eep_4k_header *pModal;
Sujith2660b812009-02-09 13:27:26 +05301239 struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k;
Sujithf74df6f2009-02-09 13:27:24 +05301240 u8 txRxAttenLocal;
1241 u8 ob[5], db1[5], db2[5];
1242 u8 ant_div_control1, ant_div_control2;
1243 u32 regVal;
1244
Sujithf74df6f2009-02-09 13:27:24 +05301245 pModal = &eep->modalHeader;
Sujithf74df6f2009-02-09 13:27:24 +05301246 txRxAttenLocal = 23;
1247
1248 REG_WRITE(ah, AR_PHY_SWITCH_COM,
1249 ah->eep_ops->get_eeprom_antenna_cfg(ah, chan));
1250
Sujitha83615d2009-03-13 08:56:04 +05301251 /* Single chain for 4K EEPROM*/
1252 ath9k_hw_4k_set_gain(ah, pModal, eep, txRxAttenLocal, 0);
Sujithf74df6f2009-02-09 13:27:24 +05301253
1254 /* Initialize Ant Diversity settings from EEPROM */
1255 if (pModal->version == 3) {
1256 ant_div_control1 = ((pModal->ob_234 >> 12) & 0xf);
1257 ant_div_control2 = ((pModal->db1_234 >> 12) & 0xf);
1258 regVal = REG_READ(ah, 0x99ac);
1259 regVal &= (~(0x7f000000));
1260 regVal |= ((ant_div_control1 & 0x1) << 24);
1261 regVal |= (((ant_div_control1 >> 1) & 0x1) << 29);
1262 regVal |= (((ant_div_control1 >> 2) & 0x1) << 30);
1263 regVal |= ((ant_div_control2 & 0x3) << 25);
1264 regVal |= (((ant_div_control2 >> 2) & 0x3) << 27);
1265 REG_WRITE(ah, 0x99ac, regVal);
1266 regVal = REG_READ(ah, 0x99ac);
1267 regVal = REG_READ(ah, 0xa208);
1268 regVal &= (~(0x1 << 13));
1269 regVal |= (((ant_div_control1 >> 3) & 0x1) << 13);
1270 REG_WRITE(ah, 0xa208, regVal);
1271 regVal = REG_READ(ah, 0xa208);
1272 }
1273
1274 if (pModal->version >= 2) {
1275 ob[0] = (pModal->ob_01 & 0xf);
1276 ob[1] = (pModal->ob_01 >> 4) & 0xf;
1277 ob[2] = (pModal->ob_234 & 0xf);
1278 ob[3] = ((pModal->ob_234 >> 4) & 0xf);
1279 ob[4] = ((pModal->ob_234 >> 8) & 0xf);
1280
1281 db1[0] = (pModal->db1_01 & 0xf);
1282 db1[1] = ((pModal->db1_01 >> 4) & 0xf);
1283 db1[2] = (pModal->db1_234 & 0xf);
1284 db1[3] = ((pModal->db1_234 >> 4) & 0xf);
1285 db1[4] = ((pModal->db1_234 >> 8) & 0xf);
1286
1287 db2[0] = (pModal->db2_01 & 0xf);
1288 db2[1] = ((pModal->db2_01 >> 4) & 0xf);
1289 db2[2] = (pModal->db2_234 & 0xf);
1290 db2[3] = ((pModal->db2_234 >> 4) & 0xf);
1291 db2[4] = ((pModal->db2_234 >> 8) & 0xf);
1292
1293 } else if (pModal->version == 1) {
Sujithf74df6f2009-02-09 13:27:24 +05301294 ob[0] = (pModal->ob_01 & 0xf);
1295 ob[1] = ob[2] = ob[3] = ob[4] = (pModal->ob_01 >> 4) & 0xf;
1296 db1[0] = (pModal->db1_01 & 0xf);
1297 db1[1] = db1[2] = db1[3] =
1298 db1[4] = ((pModal->db1_01 >> 4) & 0xf);
1299 db2[0] = (pModal->db2_01 & 0xf);
1300 db2[1] = db2[2] = db2[3] =
1301 db2[4] = ((pModal->db2_01 >> 4) & 0xf);
1302 } else {
1303 int i;
1304 for (i = 0; i < 5; i++) {
1305 ob[i] = pModal->ob_01;
1306 db1[i] = pModal->db1_01;
1307 db2[i] = pModal->db1_01;
1308 }
1309 }
1310
1311 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
1312 AR9285_AN_RF2G3_OB_0, AR9285_AN_RF2G3_OB_0_S, ob[0]);
1313 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
1314 AR9285_AN_RF2G3_OB_1, AR9285_AN_RF2G3_OB_1_S, ob[1]);
1315 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
1316 AR9285_AN_RF2G3_OB_2, AR9285_AN_RF2G3_OB_2_S, ob[2]);
1317 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
1318 AR9285_AN_RF2G3_OB_3, AR9285_AN_RF2G3_OB_3_S, ob[3]);
1319 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
1320 AR9285_AN_RF2G3_OB_4, AR9285_AN_RF2G3_OB_4_S, ob[4]);
1321
1322 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
1323 AR9285_AN_RF2G3_DB1_0, AR9285_AN_RF2G3_DB1_0_S, db1[0]);
1324 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
1325 AR9285_AN_RF2G3_DB1_1, AR9285_AN_RF2G3_DB1_1_S, db1[1]);
1326 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
1327 AR9285_AN_RF2G3_DB1_2, AR9285_AN_RF2G3_DB1_2_S, db1[2]);
1328 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
1329 AR9285_AN_RF2G4_DB1_3, AR9285_AN_RF2G4_DB1_3_S, db1[3]);
1330 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
1331 AR9285_AN_RF2G4_DB1_4, AR9285_AN_RF2G4_DB1_4_S, db1[4]);
1332
1333 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
1334 AR9285_AN_RF2G4_DB2_0, AR9285_AN_RF2G4_DB2_0_S, db2[0]);
1335 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
1336 AR9285_AN_RF2G4_DB2_1, AR9285_AN_RF2G4_DB2_1_S, db2[1]);
1337 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
1338 AR9285_AN_RF2G4_DB2_2, AR9285_AN_RF2G4_DB2_2_S, db2[2]);
1339 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
1340 AR9285_AN_RF2G4_DB2_3, AR9285_AN_RF2G4_DB2_3_S, db2[3]);
1341 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
1342 AR9285_AN_RF2G4_DB2_4, AR9285_AN_RF2G4_DB2_4_S, db2[4]);
1343
1344
1345 if (AR_SREV_9285_11(ah))
1346 REG_WRITE(ah, AR9285_AN_TOP4, AR9285_AN_TOP4_DEFAULT);
1347
1348 REG_RMW_FIELD(ah, AR_PHY_SETTLING, AR_PHY_SETTLING_SWITCH,
1349 pModal->switchSettling);
1350 REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ, AR_PHY_DESIRED_SZ_ADC,
1351 pModal->adcDesiredSize);
1352
1353 REG_WRITE(ah, AR_PHY_RF_CTL4,
1354 SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF) |
1355 SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAB_OFF) |
1356 SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAA_ON) |
1357 SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAB_ON));
1358
1359 REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON,
1360 pModal->txEndToRxOn);
1361 REG_RMW_FIELD(ah, AR_PHY_CCA, AR9280_PHY_CCA_THRESH62,
1362 pModal->thresh62);
1363 REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0, AR_PHY_EXT_CCA0_THRESH62,
1364 pModal->thresh62);
1365
1366 if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
1367 AR5416_EEP_MINOR_VER_2) {
1368 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_DATA_START,
1369 pModal->txFrameToDataStart);
1370 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_PA_ON,
1371 pModal->txFrameToPaOn);
1372 }
1373
1374 if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
1375 AR5416_EEP_MINOR_VER_3) {
1376 if (IS_CHAN_HT40(chan))
1377 REG_RMW_FIELD(ah, AR_PHY_SETTLING,
1378 AR_PHY_SETTLING_SWITCH,
1379 pModal->swSettleHt40);
1380 }
1381
1382 return true;
1383}
1384
1385static u16 ath9k_hw_4k_get_eeprom_antenna_cfg(struct ath_hw *ah,
1386 struct ath9k_channel *chan)
1387{
Sujith2660b812009-02-09 13:27:26 +05301388 struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k;
Sujithf74df6f2009-02-09 13:27:24 +05301389 struct modal_eep_4k_header *pModal = &eep->modalHeader;
1390
1391 return pModal->antCtrlCommon & 0xFFFF;
1392}
1393
1394static u8 ath9k_hw_4k_get_num_ant_config(struct ath_hw *ah,
1395 enum ieee80211_band freq_band)
1396{
1397 return 1;
1398}
1399
Hannes Eder93f726a2009-02-14 11:49:48 +00001400static u16 ath9k_hw_4k_get_spur_channel(struct ath_hw *ah, u16 i, bool is2GHz)
Sujithf74df6f2009-02-09 13:27:24 +05301401{
1402#define EEP_MAP4K_SPURCHAN \
Sujith2660b812009-02-09 13:27:26 +05301403 (ah->eeprom.map4k.modalHeader.spurChans[i].spurChan)
Sujithf74df6f2009-02-09 13:27:24 +05301404
1405 u16 spur_val = AR_NO_SPUR;
1406
1407 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
1408 "Getting spur idx %d is2Ghz. %d val %x\n",
Sujith2660b812009-02-09 13:27:26 +05301409 i, is2GHz, ah->config.spurchans[i][is2GHz]);
Sujithf74df6f2009-02-09 13:27:24 +05301410
Sujith2660b812009-02-09 13:27:26 +05301411 switch (ah->config.spurmode) {
Sujithf74df6f2009-02-09 13:27:24 +05301412 case SPUR_DISABLE:
1413 break;
1414 case SPUR_ENABLE_IOCTL:
Sujith2660b812009-02-09 13:27:26 +05301415 spur_val = ah->config.spurchans[i][is2GHz];
Sujithf74df6f2009-02-09 13:27:24 +05301416 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
1417 "Getting spur val from new loc. %d\n", spur_val);
1418 break;
1419 case SPUR_ENABLE_EEPROM:
1420 spur_val = EEP_MAP4K_SPURCHAN;
1421 break;
1422 }
1423
1424 return spur_val;
1425
1426#undef EEP_MAP4K_SPURCHAN
1427}
1428
Hannes Eder93f726a2009-02-14 11:49:48 +00001429static struct eeprom_ops eep_4k_ops = {
Sujithf74df6f2009-02-09 13:27:24 +05301430 .check_eeprom = ath9k_hw_4k_check_eeprom,
1431 .get_eeprom = ath9k_hw_4k_get_eeprom,
1432 .fill_eeprom = ath9k_hw_4k_fill_eeprom,
1433 .get_eeprom_ver = ath9k_hw_4k_get_eeprom_ver,
1434 .get_eeprom_rev = ath9k_hw_4k_get_eeprom_rev,
1435 .get_num_ant_config = ath9k_hw_4k_get_num_ant_config,
1436 .get_eeprom_antenna_cfg = ath9k_hw_4k_get_eeprom_antenna_cfg,
1437 .set_board_values = ath9k_hw_4k_set_board_values,
1438 .set_addac = ath9k_hw_4k_set_addac,
1439 .set_txpower = ath9k_hw_4k_set_txpower,
1440 .get_spur_channel = ath9k_hw_4k_get_spur_channel
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301441};
1442
Sujithf74df6f2009-02-09 13:27:24 +05301443/************************************************/
1444/* EEPROM Operations for non-4K (Default) cards */
1445/************************************************/
1446
1447static int ath9k_hw_def_get_eeprom_ver(struct ath_hw *ah)
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301448{
Sujith2660b812009-02-09 13:27:26 +05301449 return ((ah->eeprom.def.baseEepHeader.version >> 12) & 0xF);
Sujithf74df6f2009-02-09 13:27:24 +05301450}
1451
1452static int ath9k_hw_def_get_eeprom_rev(struct ath_hw *ah)
1453{
Sujith2660b812009-02-09 13:27:26 +05301454 return ((ah->eeprom.def.baseEepHeader.version) & 0xFFF);
Sujithf74df6f2009-02-09 13:27:24 +05301455}
1456
1457static bool ath9k_hw_def_fill_eeprom(struct ath_hw *ah)
1458{
1459#define SIZE_EEPROM_DEF (sizeof(struct ar5416_eeprom_def) / sizeof(u16))
Sujith7d01b222009-03-13 08:55:55 +05301460 u16 *eep_data = (u16 *)&ah->eeprom.def;
Sujithf74df6f2009-02-09 13:27:24 +05301461 int addr, ar5416_eep_start_loc = 0x100;
1462
Sujithf74df6f2009-02-09 13:27:24 +05301463 for (addr = 0; addr < SIZE_EEPROM_DEF; addr++) {
1464 if (!ath9k_hw_nvram_read(ah, addr + ar5416_eep_start_loc,
1465 eep_data)) {
Sujith7d01b222009-03-13 08:55:55 +05301466 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
Sujithf74df6f2009-02-09 13:27:24 +05301467 "Unable to read eeprom region\n");
1468 return false;
1469 }
1470 eep_data++;
1471 }
1472 return true;
1473#undef SIZE_EEPROM_DEF
1474}
1475
1476static int ath9k_hw_def_check_eeprom(struct ath_hw *ah)
1477{
1478 struct ar5416_eeprom_def *eep =
Sujith2660b812009-02-09 13:27:26 +05301479 (struct ar5416_eeprom_def *) &ah->eeprom.def;
Sujithf74df6f2009-02-09 13:27:24 +05301480 u16 *eepdata, temp, magic, magic2;
1481 u32 sum = 0, el;
1482 bool need_swap = false;
1483 int i, addr, size;
1484
Sujith7d01b222009-03-13 08:55:55 +05301485 if (!ath9k_hw_nvram_read(ah, AR5416_EEPROM_MAGIC_OFFSET, &magic)) {
1486 DPRINTF(ah->ah_sc, ATH_DBG_FATAL, "Reading Magic # failed\n");
Sujithf74df6f2009-02-09 13:27:24 +05301487 return false;
1488 }
1489
1490 if (!ath9k_hw_use_flash(ah)) {
Sujithf74df6f2009-02-09 13:27:24 +05301491 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
Sujith7d01b222009-03-13 08:55:55 +05301492 "Read Magic = 0x%04X\n", magic);
Sujithf74df6f2009-02-09 13:27:24 +05301493
1494 if (magic != AR5416_EEPROM_MAGIC) {
1495 magic2 = swab16(magic);
1496
1497 if (magic2 == AR5416_EEPROM_MAGIC) {
1498 size = sizeof(struct ar5416_eeprom_def);
1499 need_swap = true;
Sujith2660b812009-02-09 13:27:26 +05301500 eepdata = (u16 *) (&ah->eeprom);
Sujithf74df6f2009-02-09 13:27:24 +05301501
1502 for (addr = 0; addr < size / sizeof(u16); addr++) {
1503 temp = swab16(*eepdata);
1504 *eepdata = temp;
1505 eepdata++;
Sujithf74df6f2009-02-09 13:27:24 +05301506 }
1507 } else {
Sujith7d01b222009-03-13 08:55:55 +05301508 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
Sujithf74df6f2009-02-09 13:27:24 +05301509 "Invalid EEPROM Magic. "
Sujith7d01b222009-03-13 08:55:55 +05301510 "Endianness mismatch.\n");
Sujithf74df6f2009-02-09 13:27:24 +05301511 return -EINVAL;
1512 }
1513 }
1514 }
1515
1516 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, "need_swap = %s.\n",
1517 need_swap ? "True" : "False");
1518
1519 if (need_swap)
Sujith2660b812009-02-09 13:27:26 +05301520 el = swab16(ah->eeprom.def.baseEepHeader.length);
Sujithf74df6f2009-02-09 13:27:24 +05301521 else
Sujith2660b812009-02-09 13:27:26 +05301522 el = ah->eeprom.def.baseEepHeader.length;
Sujithf74df6f2009-02-09 13:27:24 +05301523
1524 if (el > sizeof(struct ar5416_eeprom_def))
1525 el = sizeof(struct ar5416_eeprom_def) / sizeof(u16);
1526 else
1527 el = el / sizeof(u16);
1528
Sujith2660b812009-02-09 13:27:26 +05301529 eepdata = (u16 *)(&ah->eeprom);
Sujithf74df6f2009-02-09 13:27:24 +05301530
1531 for (i = 0; i < el; i++)
1532 sum ^= *eepdata++;
1533
1534 if (need_swap) {
1535 u32 integer, j;
1536 u16 word;
1537
1538 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
Sujith7d01b222009-03-13 08:55:55 +05301539 "EEPROM Endianness is not native.. Changing.\n");
Sujithf74df6f2009-02-09 13:27:24 +05301540
1541 word = swab16(eep->baseEepHeader.length);
1542 eep->baseEepHeader.length = word;
1543
1544 word = swab16(eep->baseEepHeader.checksum);
1545 eep->baseEepHeader.checksum = word;
1546
1547 word = swab16(eep->baseEepHeader.version);
1548 eep->baseEepHeader.version = word;
1549
1550 word = swab16(eep->baseEepHeader.regDmn[0]);
1551 eep->baseEepHeader.regDmn[0] = word;
1552
1553 word = swab16(eep->baseEepHeader.regDmn[1]);
1554 eep->baseEepHeader.regDmn[1] = word;
1555
1556 word = swab16(eep->baseEepHeader.rfSilent);
1557 eep->baseEepHeader.rfSilent = word;
1558
1559 word = swab16(eep->baseEepHeader.blueToothOptions);
1560 eep->baseEepHeader.blueToothOptions = word;
1561
1562 word = swab16(eep->baseEepHeader.deviceCap);
1563 eep->baseEepHeader.deviceCap = word;
1564
1565 for (j = 0; j < ARRAY_SIZE(eep->modalHeader); j++) {
1566 struct modal_eep_header *pModal =
1567 &eep->modalHeader[j];
1568 integer = swab32(pModal->antCtrlCommon);
1569 pModal->antCtrlCommon = integer;
1570
1571 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
1572 integer = swab32(pModal->antCtrlChain[i]);
1573 pModal->antCtrlChain[i] = integer;
1574 }
1575
1576 for (i = 0; i < AR5416_EEPROM_MODAL_SPURS; i++) {
1577 word = swab16(pModal->spurChans[i].spurChan);
1578 pModal->spurChans[i].spurChan = word;
1579 }
1580 }
1581 }
1582
1583 if (sum != 0xffff || ah->eep_ops->get_eeprom_ver(ah) != AR5416_EEP_VER ||
1584 ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_NO_BACK_VER) {
Sujith7d01b222009-03-13 08:55:55 +05301585 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
Sujithf74df6f2009-02-09 13:27:24 +05301586 "Bad EEPROM checksum 0x%x or revision 0x%04x\n",
1587 sum, ah->eep_ops->get_eeprom_ver(ah));
1588 return -EINVAL;
1589 }
1590
1591 return 0;
1592}
1593
1594static u32 ath9k_hw_def_get_eeprom(struct ath_hw *ah,
1595 enum eeprom_param param)
1596{
Sujith2660b812009-02-09 13:27:26 +05301597 struct ar5416_eeprom_def *eep = &ah->eeprom.def;
Sujithf74df6f2009-02-09 13:27:24 +05301598 struct modal_eep_header *pModal = eep->modalHeader;
1599 struct base_eep_header *pBase = &eep->baseEepHeader;
1600
1601 switch (param) {
1602 case EEP_NFTHRESH_5:
1603 return pModal[0].noiseFloorThreshCh[0];
1604 case EEP_NFTHRESH_2:
1605 return pModal[1].noiseFloorThreshCh[0];
1606 case AR_EEPROM_MAC(0):
1607 return pBase->macAddr[0] << 8 | pBase->macAddr[1];
1608 case AR_EEPROM_MAC(1):
1609 return pBase->macAddr[2] << 8 | pBase->macAddr[3];
1610 case AR_EEPROM_MAC(2):
1611 return pBase->macAddr[4] << 8 | pBase->macAddr[5];
1612 case EEP_REG_0:
1613 return pBase->regDmn[0];
1614 case EEP_REG_1:
1615 return pBase->regDmn[1];
1616 case EEP_OP_CAP:
1617 return pBase->deviceCap;
1618 case EEP_OP_MODE:
1619 return pBase->opCapFlags;
1620 case EEP_RF_SILENT:
1621 return pBase->rfSilent;
1622 case EEP_OB_5:
1623 return pModal[0].ob;
1624 case EEP_DB_5:
1625 return pModal[0].db;
1626 case EEP_OB_2:
1627 return pModal[1].ob;
1628 case EEP_DB_2:
1629 return pModal[1].db;
1630 case EEP_MINOR_REV:
1631 return AR5416_VER_MASK;
1632 case EEP_TX_MASK:
1633 return pBase->txMask;
1634 case EEP_RX_MASK:
1635 return pBase->rxMask;
1636 case EEP_RXGAIN_TYPE:
1637 return pBase->rxGainType;
1638 case EEP_TXGAIN_TYPE:
1639 return pBase->txGainType;
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301640 case EEP_OL_PWRCTRL:
1641 if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
1642 return pBase->openLoopPwrCntl ? true : false;
1643 else
1644 return false;
1645 case EEP_RC_CHAIN_MASK:
1646 if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
1647 return pBase->rcChainMask;
1648 else
1649 return 0;
Sujithf74df6f2009-02-09 13:27:24 +05301650 case EEP_DAC_HPWR_5G:
1651 if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_20)
1652 return pBase->dacHiPwrMode_5G;
1653 else
1654 return 0;
Sujith06d0f062009-02-12 10:06:45 +05301655 case EEP_FRAC_N_5G:
1656 if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_22)
1657 return pBase->frac_n_5g;
1658 else
1659 return 0;
Sujithf74df6f2009-02-09 13:27:24 +05301660 default:
1661 return 0;
1662 }
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301663}
1664
Sujitha83615d2009-03-13 08:56:04 +05301665static void ath9k_hw_def_set_gain(struct ath_hw *ah,
1666 struct modal_eep_header *pModal,
1667 struct ar5416_eeprom_def *eep,
1668 u8 txRxAttenLocal, int regChainOffset, int i)
1669{
1670 if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_3) {
1671 txRxAttenLocal = pModal->txRxAttenCh[i];
1672
1673 if (AR_SREV_9280_10_OR_LATER(ah)) {
1674 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
1675 AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN,
1676 pModal->bswMargin[i]);
1677 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
1678 AR_PHY_GAIN_2GHZ_XATTEN1_DB,
1679 pModal->bswAtten[i]);
1680 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
1681 AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN,
1682 pModal->xatten2Margin[i]);
1683 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
1684 AR_PHY_GAIN_2GHZ_XATTEN2_DB,
1685 pModal->xatten2Db[i]);
1686 } else {
1687 REG_WRITE(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
1688 (REG_READ(ah, AR_PHY_GAIN_2GHZ + regChainOffset) &
1689 ~AR_PHY_GAIN_2GHZ_BSW_MARGIN)
1690 | SM(pModal-> bswMargin[i],
1691 AR_PHY_GAIN_2GHZ_BSW_MARGIN));
1692 REG_WRITE(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
1693 (REG_READ(ah, AR_PHY_GAIN_2GHZ + regChainOffset) &
1694 ~AR_PHY_GAIN_2GHZ_BSW_ATTEN)
1695 | SM(pModal->bswAtten[i],
1696 AR_PHY_GAIN_2GHZ_BSW_ATTEN));
1697 }
1698 }
1699
1700 if (AR_SREV_9280_10_OR_LATER(ah)) {
1701 REG_RMW_FIELD(ah,
1702 AR_PHY_RXGAIN + regChainOffset,
1703 AR9280_PHY_RXGAIN_TXRX_ATTEN, txRxAttenLocal);
1704 REG_RMW_FIELD(ah,
1705 AR_PHY_RXGAIN + regChainOffset,
1706 AR9280_PHY_RXGAIN_TXRX_MARGIN, pModal->rxTxMarginCh[i]);
1707 } else {
1708 REG_WRITE(ah,
1709 AR_PHY_RXGAIN + regChainOffset,
1710 (REG_READ(ah, AR_PHY_RXGAIN + regChainOffset) &
1711 ~AR_PHY_RXGAIN_TXRX_ATTEN)
1712 | SM(txRxAttenLocal, AR_PHY_RXGAIN_TXRX_ATTEN));
1713 REG_WRITE(ah,
1714 AR_PHY_GAIN_2GHZ + regChainOffset,
1715 (REG_READ(ah, AR_PHY_GAIN_2GHZ + regChainOffset) &
1716 ~AR_PHY_GAIN_2GHZ_RXTX_MARGIN) |
1717 SM(pModal->rxTxMarginCh[i], AR_PHY_GAIN_2GHZ_RXTX_MARGIN));
1718 }
1719}
1720
Sujithf74df6f2009-02-09 13:27:24 +05301721static bool ath9k_hw_def_set_board_values(struct ath_hw *ah,
1722 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301723{
1724 struct modal_eep_header *pModal;
Sujith2660b812009-02-09 13:27:26 +05301725 struct ar5416_eeprom_def *eep = &ah->eeprom.def;
Sujithf1dc5602008-10-29 10:16:30 +05301726 int i, regChainOffset;
1727 u8 txRxAttenLocal;
Sujithf1dc5602008-10-29 10:16:30 +05301728
1729 pModal = &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
Sujithf1dc5602008-10-29 10:16:30 +05301730 txRxAttenLocal = IS_CHAN_2GHZ(chan) ? 23 : 44;
1731
Vasanthakumar Thiagarajan81b1e192009-01-23 14:40:37 +05301732 REG_WRITE(ah, AR_PHY_SWITCH_COM,
Sujithf74df6f2009-02-09 13:27:24 +05301733 ah->eep_ops->get_eeprom_antenna_cfg(ah, chan));
Sujithf1dc5602008-10-29 10:16:30 +05301734
1735 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
1736 if (AR_SREV_9280(ah)) {
1737 if (i >= 2)
1738 break;
1739 }
1740
Gabor Juhosa8c96d32009-03-06 09:08:51 +01001741 if (AR_SREV_5416_20_OR_LATER(ah) &&
Sujitha83615d2009-03-13 08:56:04 +05301742 (ah->rxchainmask == 5 || ah->txchainmask == 5) && (i != 0))
Sujithf1dc5602008-10-29 10:16:30 +05301743 regChainOffset = (i == 1) ? 0x2000 : 0x1000;
1744 else
1745 regChainOffset = i * 0x1000;
1746
1747 REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
1748 pModal->antCtrlChain[i]);
1749
1750 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
Sujitha83615d2009-03-13 08:56:04 +05301751 (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset) &
Sujithf1dc5602008-10-29 10:16:30 +05301752 ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
1753 AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
1754 SM(pModal->iqCalICh[i],
1755 AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
1756 SM(pModal->iqCalQCh[i],
1757 AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
1758
Sujitha83615d2009-03-13 08:56:04 +05301759 if ((i == 0) || AR_SREV_5416_20_OR_LATER(ah))
1760 ath9k_hw_def_set_gain(ah, pModal, eep, txRxAttenLocal,
1761 regChainOffset, i);
Sujithf1dc5602008-10-29 10:16:30 +05301762 }
1763
1764 if (AR_SREV_9280_10_OR_LATER(ah)) {
1765 if (IS_CHAN_2GHZ(chan)) {
1766 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH0,
1767 AR_AN_RF2G1_CH0_OB,
1768 AR_AN_RF2G1_CH0_OB_S,
1769 pModal->ob);
1770 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH0,
1771 AR_AN_RF2G1_CH0_DB,
1772 AR_AN_RF2G1_CH0_DB_S,
1773 pModal->db);
1774 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH1,
1775 AR_AN_RF2G1_CH1_OB,
1776 AR_AN_RF2G1_CH1_OB_S,
1777 pModal->ob_ch1);
1778 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH1,
1779 AR_AN_RF2G1_CH1_DB,
1780 AR_AN_RF2G1_CH1_DB_S,
1781 pModal->db_ch1);
1782 } else {
1783 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH0,
1784 AR_AN_RF5G1_CH0_OB5,
1785 AR_AN_RF5G1_CH0_OB5_S,
1786 pModal->ob);
1787 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH0,
1788 AR_AN_RF5G1_CH0_DB5,
1789 AR_AN_RF5G1_CH0_DB5_S,
1790 pModal->db);
1791 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH1,
1792 AR_AN_RF5G1_CH1_OB5,
1793 AR_AN_RF5G1_CH1_OB5_S,
1794 pModal->ob_ch1);
1795 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH1,
1796 AR_AN_RF5G1_CH1_DB5,
1797 AR_AN_RF5G1_CH1_DB5_S,
1798 pModal->db_ch1);
1799 }
1800 ath9k_hw_analog_shift_rmw(ah, AR_AN_TOP2,
1801 AR_AN_TOP2_XPABIAS_LVL,
1802 AR_AN_TOP2_XPABIAS_LVL_S,
1803 pModal->xpaBiasLvl);
1804 ath9k_hw_analog_shift_rmw(ah, AR_AN_TOP2,
1805 AR_AN_TOP2_LOCALBIAS,
1806 AR_AN_TOP2_LOCALBIAS_S,
1807 pModal->local_bias);
Sujithf1dc5602008-10-29 10:16:30 +05301808 REG_RMW_FIELD(ah, AR_PHY_XPA_CFG, AR_PHY_FORCE_XPA_CFG,
1809 pModal->force_xpaon);
1810 }
1811
1812 REG_RMW_FIELD(ah, AR_PHY_SETTLING, AR_PHY_SETTLING_SWITCH,
1813 pModal->switchSettling);
1814 REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ, AR_PHY_DESIRED_SZ_ADC,
1815 pModal->adcDesiredSize);
1816
1817 if (!AR_SREV_9280_10_OR_LATER(ah))
1818 REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
1819 AR_PHY_DESIRED_SZ_PGA,
1820 pModal->pgaDesiredSize);
1821
1822 REG_WRITE(ah, AR_PHY_RF_CTL4,
1823 SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF)
1824 | SM(pModal->txEndToXpaOff,
1825 AR_PHY_RF_CTL4_TX_END_XPAB_OFF)
1826 | SM(pModal->txFrameToXpaOn,
1827 AR_PHY_RF_CTL4_FRAME_XPAA_ON)
1828 | SM(pModal->txFrameToXpaOn,
1829 AR_PHY_RF_CTL4_FRAME_XPAB_ON));
1830
1831 REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON,
1832 pModal->txEndToRxOn);
Sujith7d01b222009-03-13 08:55:55 +05301833
Sujithf1dc5602008-10-29 10:16:30 +05301834 if (AR_SREV_9280_10_OR_LATER(ah)) {
1835 REG_RMW_FIELD(ah, AR_PHY_CCA, AR9280_PHY_CCA_THRESH62,
1836 pModal->thresh62);
1837 REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0,
1838 AR_PHY_EXT_CCA0_THRESH62,
1839 pModal->thresh62);
1840 } else {
1841 REG_RMW_FIELD(ah, AR_PHY_CCA, AR_PHY_CCA_THRESH62,
1842 pModal->thresh62);
1843 REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
1844 AR_PHY_EXT_CCA_THRESH62,
1845 pModal->thresh62);
1846 }
1847
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05301848 if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_2) {
Sujithf1dc5602008-10-29 10:16:30 +05301849 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
1850 AR_PHY_TX_END_DATA_START,
1851 pModal->txFrameToDataStart);
1852 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_PA_ON,
1853 pModal->txFrameToPaOn);
1854 }
1855
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05301856 if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_3) {
Sujithf1dc5602008-10-29 10:16:30 +05301857 if (IS_CHAN_HT40(chan))
1858 REG_RMW_FIELD(ah, AR_PHY_SETTLING,
1859 AR_PHY_SETTLING_SWITCH,
1860 pModal->swSettleHt40);
1861 }
1862
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301863 if (AR_SREV_9280_20_OR_LATER(ah) &&
Sujith7d01b222009-03-13 08:55:55 +05301864 AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301865 REG_RMW_FIELD(ah, AR_PHY_CCK_TX_CTRL,
Sujith7d01b222009-03-13 08:55:55 +05301866 AR_PHY_CCK_TX_CTRL_TX_DAC_SCALE_CCK,
1867 pModal->miscBits);
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301868
1869
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05301870 if (AR_SREV_9280_20(ah) && AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_20) {
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301871 if (IS_CHAN_2GHZ(chan))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05301872 REG_RMW_FIELD(ah, AR_AN_TOP1, AR_AN_TOP1_DACIPMODE,
1873 eep->baseEepHeader.dacLpMode);
1874 else if (eep->baseEepHeader.dacHiPwrMode_5G)
1875 REG_RMW_FIELD(ah, AR_AN_TOP1, AR_AN_TOP1_DACIPMODE, 0);
1876 else
1877 REG_RMW_FIELD(ah, AR_AN_TOP1, AR_AN_TOP1_DACIPMODE,
Sujith7d01b222009-03-13 08:55:55 +05301878 eep->baseEepHeader.dacLpMode);
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05301879
1880 REG_RMW_FIELD(ah, AR_PHY_FRAME_CTL, AR_PHY_FRAME_CTL_TX_CLIP,
Sujith7d01b222009-03-13 08:55:55 +05301881 pModal->miscBits >> 2);
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301882
1883 REG_RMW_FIELD(ah, AR_PHY_TX_PWRCTRL9,
Sujith7d01b222009-03-13 08:55:55 +05301884 AR_PHY_TX_DESIRED_SCALE_CCK,
1885 eep->baseEepHeader.desiredScaleCCK);
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05301886 }
1887
Sujithf1dc5602008-10-29 10:16:30 +05301888 return true;
1889}
1890
Sujithf74df6f2009-02-09 13:27:24 +05301891static void ath9k_hw_def_set_addac(struct ath_hw *ah,
1892 struct ath9k_channel *chan)
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301893{
Sujithf74df6f2009-02-09 13:27:24 +05301894#define XPA_LVL_FREQ(cnt) (pModal->xpaBiasLvlFreq[cnt])
1895 struct modal_eep_header *pModal;
Sujith2660b812009-02-09 13:27:26 +05301896 struct ar5416_eeprom_def *eep = &ah->eeprom.def;
Sujithf74df6f2009-02-09 13:27:24 +05301897 u8 biaslevel;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301898
Sujithf74df6f2009-02-09 13:27:24 +05301899 if (ah->hw_version.macVersion != AR_SREV_VERSION_9160)
1900 return;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301901
Sujithf74df6f2009-02-09 13:27:24 +05301902 if (ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_MINOR_VER_7)
1903 return;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301904
Sujithf74df6f2009-02-09 13:27:24 +05301905 pModal = &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301906
Sujithf74df6f2009-02-09 13:27:24 +05301907 if (pModal->xpaBiasLvl != 0xff) {
1908 biaslevel = pModal->xpaBiasLvl;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301909 } else {
Sujithf74df6f2009-02-09 13:27:24 +05301910 u16 resetFreqBin, freqBin, freqCount = 0;
1911 struct chan_centers centers;
1912
1913 ath9k_hw_get_channel_centers(ah, chan, &centers);
1914
1915 resetFreqBin = FREQ2FBIN(centers.synth_center,
1916 IS_CHAN_2GHZ(chan));
1917 freqBin = XPA_LVL_FREQ(0) & 0xff;
1918 biaslevel = (u8) (XPA_LVL_FREQ(0) >> 14);
1919
1920 freqCount++;
1921
1922 while (freqCount < 3) {
1923 if (XPA_LVL_FREQ(freqCount) == 0x0)
1924 break;
1925
1926 freqBin = XPA_LVL_FREQ(freqCount) & 0xff;
1927 if (resetFreqBin >= freqBin)
1928 biaslevel = (u8)(XPA_LVL_FREQ(freqCount) >> 14);
1929 else
1930 break;
1931 freqCount++;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301932 }
1933 }
1934
Sujithf74df6f2009-02-09 13:27:24 +05301935 if (IS_CHAN_2GHZ(chan)) {
Sujith2660b812009-02-09 13:27:26 +05301936 INI_RA(&ah->iniAddac, 7, 1) = (INI_RA(&ah->iniAddac,
Sujithf74df6f2009-02-09 13:27:24 +05301937 7, 1) & (~0x18)) | biaslevel << 3;
1938 } else {
Sujith2660b812009-02-09 13:27:26 +05301939 INI_RA(&ah->iniAddac, 6, 1) = (INI_RA(&ah->iniAddac,
Sujithf74df6f2009-02-09 13:27:24 +05301940 6, 1) & (~0xc0)) | biaslevel << 6;
1941 }
1942#undef XPA_LVL_FREQ
1943}
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301944
Sujithf74df6f2009-02-09 13:27:24 +05301945static void ath9k_hw_get_def_gain_boundaries_pdadcs(struct ath_hw *ah,
1946 struct ath9k_channel *chan,
1947 struct cal_data_per_freq *pRawDataSet,
1948 u8 *bChans, u16 availPiers,
1949 u16 tPdGainOverlap, int16_t *pMinCalPower,
1950 u16 *pPdGainBoundaries, u8 *pPDADCValues,
1951 u16 numXpdGains)
1952{
1953 int i, j, k;
1954 int16_t ss;
1955 u16 idxL = 0, idxR = 0, numPiers;
1956 static u8 vpdTableL[AR5416_NUM_PD_GAINS]
1957 [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
1958 static u8 vpdTableR[AR5416_NUM_PD_GAINS]
1959 [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
1960 static u8 vpdTableI[AR5416_NUM_PD_GAINS]
1961 [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301962
Sujithf74df6f2009-02-09 13:27:24 +05301963 u8 *pVpdL, *pVpdR, *pPwrL, *pPwrR;
1964 u8 minPwrT4[AR5416_NUM_PD_GAINS];
1965 u8 maxPwrT4[AR5416_NUM_PD_GAINS];
1966 int16_t vpdStep;
1967 int16_t tmpVal;
1968 u16 sizeCurrVpdTable, maxIndex, tgtIndex;
1969 bool match;
1970 int16_t minDelta = 0;
1971 struct chan_centers centers;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301972
Sujithf74df6f2009-02-09 13:27:24 +05301973 ath9k_hw_get_channel_centers(ah, chan, &centers);
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301974
Sujithf74df6f2009-02-09 13:27:24 +05301975 for (numPiers = 0; numPiers < availPiers; numPiers++) {
1976 if (bChans[numPiers] == AR5416_BCHAN_UNUSED)
1977 break;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301978 }
1979
Sujithf74df6f2009-02-09 13:27:24 +05301980 match = ath9k_hw_get_lower_upper_index((u8)FREQ2FBIN(centers.synth_center,
1981 IS_CHAN_2GHZ(chan)),
1982 bChans, numPiers, &idxL, &idxR);
1983
1984 if (match) {
1985 for (i = 0; i < numXpdGains; i++) {
1986 minPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][0];
1987 maxPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][4];
1988 ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
1989 pRawDataSet[idxL].pwrPdg[i],
1990 pRawDataSet[idxL].vpdPdg[i],
1991 AR5416_PD_GAIN_ICEPTS,
1992 vpdTableI[i]);
1993 }
1994 } else {
1995 for (i = 0; i < numXpdGains; i++) {
1996 pVpdL = pRawDataSet[idxL].vpdPdg[i];
1997 pPwrL = pRawDataSet[idxL].pwrPdg[i];
1998 pVpdR = pRawDataSet[idxR].vpdPdg[i];
1999 pPwrR = pRawDataSet[idxR].pwrPdg[i];
2000
2001 minPwrT4[i] = max(pPwrL[0], pPwrR[0]);
2002
2003 maxPwrT4[i] =
2004 min(pPwrL[AR5416_PD_GAIN_ICEPTS - 1],
2005 pPwrR[AR5416_PD_GAIN_ICEPTS - 1]);
2006
2007
2008 ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
2009 pPwrL, pVpdL,
2010 AR5416_PD_GAIN_ICEPTS,
2011 vpdTableL[i]);
2012 ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
2013 pPwrR, pVpdR,
2014 AR5416_PD_GAIN_ICEPTS,
2015 vpdTableR[i]);
2016
2017 for (j = 0; j <= (maxPwrT4[i] - minPwrT4[i]) / 2; j++) {
2018 vpdTableI[i][j] =
2019 (u8)(ath9k_hw_interpolate((u16)
2020 FREQ2FBIN(centers.
2021 synth_center,
2022 IS_CHAN_2GHZ
2023 (chan)),
2024 bChans[idxL], bChans[idxR],
2025 vpdTableL[i][j], vpdTableR[i][j]));
2026 }
2027 }
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302028 }
2029
Sujithf74df6f2009-02-09 13:27:24 +05302030 *pMinCalPower = (int16_t)(minPwrT4[0] / 2);
2031
2032 k = 0;
2033
2034 for (i = 0; i < numXpdGains; i++) {
2035 if (i == (numXpdGains - 1))
2036 pPdGainBoundaries[i] =
2037 (u16)(maxPwrT4[i] / 2);
2038 else
2039 pPdGainBoundaries[i] =
2040 (u16)((maxPwrT4[i] + minPwrT4[i + 1]) / 4);
2041
2042 pPdGainBoundaries[i] =
2043 min((u16)AR5416_MAX_RATE_POWER, pPdGainBoundaries[i]);
2044
Gabor Juhosa8c96d32009-03-06 09:08:51 +01002045 if ((i == 0) && !AR_SREV_5416_20_OR_LATER(ah)) {
Sujithf74df6f2009-02-09 13:27:24 +05302046 minDelta = pPdGainBoundaries[0] - 23;
2047 pPdGainBoundaries[0] = 23;
2048 } else {
2049 minDelta = 0;
2050 }
2051
2052 if (i == 0) {
2053 if (AR_SREV_9280_10_OR_LATER(ah))
2054 ss = (int16_t)(0 - (minPwrT4[i] / 2));
2055 else
2056 ss = 0;
2057 } else {
2058 ss = (int16_t)((pPdGainBoundaries[i - 1] -
2059 (minPwrT4[i] / 2)) -
2060 tPdGainOverlap + 1 + minDelta);
2061 }
2062 vpdStep = (int16_t)(vpdTableI[i][1] - vpdTableI[i][0]);
2063 vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
2064
2065 while ((ss < 0) && (k < (AR5416_NUM_PDADC_VALUES - 1))) {
2066 tmpVal = (int16_t)(vpdTableI[i][0] + ss * vpdStep);
2067 pPDADCValues[k++] = (u8)((tmpVal < 0) ? 0 : tmpVal);
2068 ss++;
2069 }
2070
2071 sizeCurrVpdTable = (u8) ((maxPwrT4[i] - minPwrT4[i]) / 2 + 1);
2072 tgtIndex = (u8)(pPdGainBoundaries[i] + tPdGainOverlap -
2073 (minPwrT4[i] / 2));
2074 maxIndex = (tgtIndex < sizeCurrVpdTable) ?
2075 tgtIndex : sizeCurrVpdTable;
2076
2077 while ((ss < maxIndex) && (k < (AR5416_NUM_PDADC_VALUES - 1))) {
2078 pPDADCValues[k++] = vpdTableI[i][ss++];
2079 }
2080
2081 vpdStep = (int16_t)(vpdTableI[i][sizeCurrVpdTable - 1] -
2082 vpdTableI[i][sizeCurrVpdTable - 2]);
2083 vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
2084
2085 if (tgtIndex > maxIndex) {
2086 while ((ss <= tgtIndex) &&
2087 (k < (AR5416_NUM_PDADC_VALUES - 1))) {
2088 tmpVal = (int16_t)((vpdTableI[i][sizeCurrVpdTable - 1] +
2089 (ss - maxIndex + 1) * vpdStep));
2090 pPDADCValues[k++] = (u8)((tmpVal > 255) ?
2091 255 : tmpVal);
2092 ss++;
2093 }
2094 }
2095 }
2096
2097 while (i < AR5416_PD_GAINS_IN_MASK) {
2098 pPdGainBoundaries[i] = pPdGainBoundaries[i - 1];
2099 i++;
2100 }
2101
2102 while (k < AR5416_NUM_PDADC_VALUES) {
2103 pPDADCValues[k] = pPDADCValues[k - 1];
2104 k++;
2105 }
2106
2107 return;
2108}
2109
2110static bool ath9k_hw_set_def_power_cal_table(struct ath_hw *ah,
2111 struct ath9k_channel *chan,
2112 int16_t *pTxPowerIndexOffset)
2113{
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05302114#define SM_PD_GAIN(x) SM(0x38, AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_##x)
2115#define SM_PDGAIN_B(x, y) \
2116 SM((gainBoundaries[x]), AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_##y)
2117
Sujith2660b812009-02-09 13:27:26 +05302118 struct ar5416_eeprom_def *pEepData = &ah->eeprom.def;
Sujithf74df6f2009-02-09 13:27:24 +05302119 struct cal_data_per_freq *pRawDataset;
2120 u8 *pCalBChans = NULL;
2121 u16 pdGainOverlap_t2;
2122 static u8 pdadcValues[AR5416_NUM_PDADC_VALUES];
2123 u16 gainBoundaries[AR5416_PD_GAINS_IN_MASK];
2124 u16 numPiers, i, j;
2125 int16_t tMinCalPower;
2126 u16 numXpdGain, xpdMask;
2127 u16 xpdGainValues[AR5416_NUM_PD_GAINS] = { 0, 0, 0, 0 };
2128 u32 reg32, regOffset, regChainOffset;
2129 int16_t modalIdx;
2130
2131 modalIdx = IS_CHAN_2GHZ(chan) ? 1 : 0;
2132 xpdMask = pEepData->modalHeader[modalIdx].xpdGain;
2133
2134 if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
2135 AR5416_EEP_MINOR_VER_2) {
2136 pdGainOverlap_t2 =
2137 pEepData->modalHeader[modalIdx].pdGainOverlap;
2138 } else {
2139 pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5),
2140 AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
2141 }
2142
2143 if (IS_CHAN_2GHZ(chan)) {
2144 pCalBChans = pEepData->calFreqPier2G;
2145 numPiers = AR5416_NUM_2G_CAL_PIERS;
2146 } else {
2147 pCalBChans = pEepData->calFreqPier5G;
2148 numPiers = AR5416_NUM_5G_CAL_PIERS;
2149 }
2150
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05302151 if (OLC_FOR_AR9280_20_LATER && IS_CHAN_2GHZ(chan)) {
2152 pRawDataset = pEepData->calPierData2G[0];
2153 ah->initPDADC = ((struct calDataPerFreqOpLoop *)
2154 pRawDataset)->vpdPdg[0][0];
2155 }
2156
Sujithf74df6f2009-02-09 13:27:24 +05302157 numXpdGain = 0;
2158
2159 for (i = 1; i <= AR5416_PD_GAINS_IN_MASK; i++) {
2160 if ((xpdMask >> (AR5416_PD_GAINS_IN_MASK - i)) & 1) {
2161 if (numXpdGain >= AR5416_NUM_PD_GAINS)
2162 break;
2163 xpdGainValues[numXpdGain] =
2164 (u16)(AR5416_PD_GAINS_IN_MASK - i);
2165 numXpdGain++;
2166 }
2167 }
2168
2169 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
2170 (numXpdGain - 1) & 0x3);
2171 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,
2172 xpdGainValues[0]);
2173 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
2174 xpdGainValues[1]);
2175 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3,
2176 xpdGainValues[2]);
2177
2178 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
Gabor Juhosa8c96d32009-03-06 09:08:51 +01002179 if (AR_SREV_5416_20_OR_LATER(ah) &&
Sujith2660b812009-02-09 13:27:26 +05302180 (ah->rxchainmask == 5 || ah->txchainmask == 5) &&
Sujithf74df6f2009-02-09 13:27:24 +05302181 (i != 0)) {
2182 regChainOffset = (i == 1) ? 0x2000 : 0x1000;
2183 } else
2184 regChainOffset = i * 0x1000;
2185
2186 if (pEepData->baseEepHeader.txMask & (1 << i)) {
2187 if (IS_CHAN_2GHZ(chan))
2188 pRawDataset = pEepData->calPierData2G[i];
2189 else
2190 pRawDataset = pEepData->calPierData5G[i];
2191
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05302192
2193 if (OLC_FOR_AR9280_20_LATER) {
2194 u8 pcdacIdx;
2195 u8 txPower;
2196
2197 ath9k_get_txgain_index(ah, chan,
2198 (struct calDataPerFreqOpLoop *)pRawDataset,
2199 pCalBChans, numPiers, &txPower, &pcdacIdx);
2200 ath9k_olc_get_pdadcs(ah, pcdacIdx,
2201 txPower/2, pdadcValues);
2202 } else {
2203 ath9k_hw_get_def_gain_boundaries_pdadcs(ah,
2204 chan, pRawDataset,
2205 pCalBChans, numPiers,
2206 pdGainOverlap_t2,
2207 &tMinCalPower,
2208 gainBoundaries,
2209 pdadcValues,
2210 numXpdGain);
2211 }
Sujithf74df6f2009-02-09 13:27:24 +05302212
Gabor Juhosa8c96d32009-03-06 09:08:51 +01002213 if ((i == 0) || AR_SREV_5416_20_OR_LATER(ah)) {
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05302214 if (OLC_FOR_AR9280_20_LATER) {
2215 REG_WRITE(ah,
2216 AR_PHY_TPCRG5 + regChainOffset,
2217 SM(0x6,
2218 AR_PHY_TPCRG5_PD_GAIN_OVERLAP) |
2219 SM_PD_GAIN(1) | SM_PD_GAIN(2) |
2220 SM_PD_GAIN(3) | SM_PD_GAIN(4));
2221 } else {
2222 REG_WRITE(ah,
2223 AR_PHY_TPCRG5 + regChainOffset,
2224 SM(pdGainOverlap_t2,
2225 AR_PHY_TPCRG5_PD_GAIN_OVERLAP)|
2226 SM_PDGAIN_B(0, 1) |
2227 SM_PDGAIN_B(1, 2) |
2228 SM_PDGAIN_B(2, 3) |
2229 SM_PDGAIN_B(3, 4));
2230 }
Sujithf74df6f2009-02-09 13:27:24 +05302231 }
2232
2233 regOffset = AR_PHY_BASE + (672 << 2) + regChainOffset;
2234 for (j = 0; j < 32; j++) {
2235 reg32 = ((pdadcValues[4 * j + 0] & 0xFF) << 0) |
2236 ((pdadcValues[4 * j + 1] & 0xFF) << 8) |
2237 ((pdadcValues[4 * j + 2] & 0xFF) << 16)|
2238 ((pdadcValues[4 * j + 3] & 0xFF) << 24);
2239 REG_WRITE(ah, regOffset, reg32);
2240
2241 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
2242 "PDADC (%d,%4x): %4.4x %8.8x\n",
2243 i, regChainOffset, regOffset,
2244 reg32);
2245 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
2246 "PDADC: Chain %d | PDADC %3d "
2247 "Value %3d | PDADC %3d Value %3d | "
2248 "PDADC %3d Value %3d | PDADC %3d "
2249 "Value %3d |\n",
2250 i, 4 * j, pdadcValues[4 * j],
2251 4 * j + 1, pdadcValues[4 * j + 1],
2252 4 * j + 2, pdadcValues[4 * j + 2],
2253 4 * j + 3,
2254 pdadcValues[4 * j + 3]);
2255
2256 regOffset += 4;
2257 }
2258 }
2259 }
2260
2261 *pTxPowerIndexOffset = 0;
2262
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302263 return true;
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05302264#undef SM_PD_GAIN
2265#undef SM_PDGAIN_B
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302266}
2267
Sujithf74df6f2009-02-09 13:27:24 +05302268static bool ath9k_hw_set_def_power_per_rate_table(struct ath_hw *ah,
2269 struct ath9k_channel *chan,
2270 int16_t *ratesArray,
2271 u16 cfgCtl,
2272 u16 AntennaReduction,
2273 u16 twiceMaxRegulatoryPower,
2274 u16 powerLimit)
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302275{
Sujithf74df6f2009-02-09 13:27:24 +05302276#define REDUCE_SCALED_POWER_BY_TWO_CHAIN 6 /* 10*log10(2)*2 */
2277#define REDUCE_SCALED_POWER_BY_THREE_CHAIN 10 /* 10*log10(3)*2 */
2278
Sujith2660b812009-02-09 13:27:26 +05302279 struct ar5416_eeprom_def *pEepData = &ah->eeprom.def;
Sujithf74df6f2009-02-09 13:27:24 +05302280 u16 twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
2281 static const u16 tpScaleReductionTable[5] =
2282 { 0, 3, 6, 9, AR5416_MAX_RATE_POWER };
2283
2284 int i;
2285 int16_t twiceLargestAntenna;
2286 struct cal_ctl_data *rep;
2287 struct cal_target_power_leg targetPowerOfdm, targetPowerCck = {
2288 0, { 0, 0, 0, 0}
2289 };
2290 struct cal_target_power_leg targetPowerOfdmExt = {
2291 0, { 0, 0, 0, 0} }, targetPowerCckExt = {
2292 0, { 0, 0, 0, 0 }
2293 };
2294 struct cal_target_power_ht targetPowerHt20, targetPowerHt40 = {
2295 0, {0, 0, 0, 0}
2296 };
2297 u16 scaledPower = 0, minCtlPower, maxRegAllowedPower;
2298 u16 ctlModesFor11a[] =
2299 { CTL_11A, CTL_5GHT20, CTL_11A_EXT, CTL_5GHT40 };
2300 u16 ctlModesFor11g[] =
2301 { CTL_11B, CTL_11G, CTL_2GHT20, CTL_11B_EXT, CTL_11G_EXT,
2302 CTL_2GHT40
2303 };
2304 u16 numCtlModes, *pCtlMode, ctlMode, freq;
2305 struct chan_centers centers;
2306 int tx_chainmask;
2307 u16 twiceMinEdgePower;
2308
Sujith2660b812009-02-09 13:27:26 +05302309 tx_chainmask = ah->txchainmask;
Sujithf74df6f2009-02-09 13:27:24 +05302310
2311 ath9k_hw_get_channel_centers(ah, chan, &centers);
2312
2313 twiceLargestAntenna = max(
2314 pEepData->modalHeader
2315 [IS_CHAN_2GHZ(chan)].antennaGainCh[0],
2316 pEepData->modalHeader
2317 [IS_CHAN_2GHZ(chan)].antennaGainCh[1]);
2318
2319 twiceLargestAntenna = max((u8)twiceLargestAntenna,
2320 pEepData->modalHeader
2321 [IS_CHAN_2GHZ(chan)].antennaGainCh[2]);
2322
2323 twiceLargestAntenna = (int16_t)min(AntennaReduction -
2324 twiceLargestAntenna, 0);
2325
2326 maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
2327
2328 if (ah->regulatory.tp_scale != ATH9K_TP_SCALE_MAX) {
2329 maxRegAllowedPower -=
2330 (tpScaleReductionTable[(ah->regulatory.tp_scale)] * 2);
2331 }
2332
2333 scaledPower = min(powerLimit, maxRegAllowedPower);
2334
2335 switch (ar5416_get_ntxchains(tx_chainmask)) {
2336 case 1:
2337 break;
2338 case 2:
2339 scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN;
2340 break;
2341 case 3:
2342 scaledPower -= REDUCE_SCALED_POWER_BY_THREE_CHAIN;
2343 break;
2344 }
2345
2346 scaledPower = max((u16)0, scaledPower);
2347
2348 if (IS_CHAN_2GHZ(chan)) {
2349 numCtlModes = ARRAY_SIZE(ctlModesFor11g) -
2350 SUB_NUM_CTL_MODES_AT_2G_40;
2351 pCtlMode = ctlModesFor11g;
2352
2353 ath9k_hw_get_legacy_target_powers(ah, chan,
2354 pEepData->calTargetPowerCck,
2355 AR5416_NUM_2G_CCK_TARGET_POWERS,
2356 &targetPowerCck, 4, false);
2357 ath9k_hw_get_legacy_target_powers(ah, chan,
2358 pEepData->calTargetPower2G,
2359 AR5416_NUM_2G_20_TARGET_POWERS,
2360 &targetPowerOfdm, 4, false);
2361 ath9k_hw_get_target_powers(ah, chan,
2362 pEepData->calTargetPower2GHT20,
2363 AR5416_NUM_2G_20_TARGET_POWERS,
2364 &targetPowerHt20, 8, false);
2365
2366 if (IS_CHAN_HT40(chan)) {
2367 numCtlModes = ARRAY_SIZE(ctlModesFor11g);
2368 ath9k_hw_get_target_powers(ah, chan,
2369 pEepData->calTargetPower2GHT40,
2370 AR5416_NUM_2G_40_TARGET_POWERS,
2371 &targetPowerHt40, 8, true);
2372 ath9k_hw_get_legacy_target_powers(ah, chan,
2373 pEepData->calTargetPowerCck,
2374 AR5416_NUM_2G_CCK_TARGET_POWERS,
2375 &targetPowerCckExt, 4, true);
2376 ath9k_hw_get_legacy_target_powers(ah, chan,
2377 pEepData->calTargetPower2G,
2378 AR5416_NUM_2G_20_TARGET_POWERS,
2379 &targetPowerOfdmExt, 4, true);
2380 }
2381 } else {
2382 numCtlModes = ARRAY_SIZE(ctlModesFor11a) -
2383 SUB_NUM_CTL_MODES_AT_5G_40;
2384 pCtlMode = ctlModesFor11a;
2385
2386 ath9k_hw_get_legacy_target_powers(ah, chan,
2387 pEepData->calTargetPower5G,
2388 AR5416_NUM_5G_20_TARGET_POWERS,
2389 &targetPowerOfdm, 4, false);
2390 ath9k_hw_get_target_powers(ah, chan,
2391 pEepData->calTargetPower5GHT20,
2392 AR5416_NUM_5G_20_TARGET_POWERS,
2393 &targetPowerHt20, 8, false);
2394
2395 if (IS_CHAN_HT40(chan)) {
2396 numCtlModes = ARRAY_SIZE(ctlModesFor11a);
2397 ath9k_hw_get_target_powers(ah, chan,
2398 pEepData->calTargetPower5GHT40,
2399 AR5416_NUM_5G_40_TARGET_POWERS,
2400 &targetPowerHt40, 8, true);
2401 ath9k_hw_get_legacy_target_powers(ah, chan,
2402 pEepData->calTargetPower5G,
2403 AR5416_NUM_5G_20_TARGET_POWERS,
2404 &targetPowerOfdmExt, 4, true);
2405 }
2406 }
2407
2408 for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
2409 bool isHt40CtlMode = (pCtlMode[ctlMode] == CTL_5GHT40) ||
2410 (pCtlMode[ctlMode] == CTL_2GHT40);
2411 if (isHt40CtlMode)
2412 freq = centers.synth_center;
2413 else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
2414 freq = centers.ext_center;
2415 else
2416 freq = centers.ctl_center;
2417
2418 if (ah->eep_ops->get_eeprom_ver(ah) == 14 &&
2419 ah->eep_ops->get_eeprom_rev(ah) <= 2)
2420 twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
2421
2422 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
2423 "LOOP-Mode ctlMode %d < %d, isHt40CtlMode %d, "
2424 "EXT_ADDITIVE %d\n",
2425 ctlMode, numCtlModes, isHt40CtlMode,
2426 (pCtlMode[ctlMode] & EXT_ADDITIVE));
2427
2428 for (i = 0; (i < AR5416_NUM_CTLS) && pEepData->ctlIndex[i]; i++) {
2429 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
2430 " LOOP-Ctlidx %d: cfgCtl 0x%2.2x "
2431 "pCtlMode 0x%2.2x ctlIndex 0x%2.2x "
2432 "chan %d\n",
2433 i, cfgCtl, pCtlMode[ctlMode],
2434 pEepData->ctlIndex[i], chan->channel);
2435
2436 if ((((cfgCtl & ~CTL_MODE_M) |
2437 (pCtlMode[ctlMode] & CTL_MODE_M)) ==
2438 pEepData->ctlIndex[i]) ||
2439 (((cfgCtl & ~CTL_MODE_M) |
2440 (pCtlMode[ctlMode] & CTL_MODE_M)) ==
2441 ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL))) {
2442 rep = &(pEepData->ctlData[i]);
2443
2444 twiceMinEdgePower = ath9k_hw_get_max_edge_power(freq,
2445 rep->ctlEdges[ar5416_get_ntxchains(tx_chainmask) - 1],
2446 IS_CHAN_2GHZ(chan), AR5416_NUM_BAND_EDGES);
2447
2448 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
2449 " MATCH-EE_IDX %d: ch %d is2 %d "
2450 "2xMinEdge %d chainmask %d chains %d\n",
2451 i, freq, IS_CHAN_2GHZ(chan),
2452 twiceMinEdgePower, tx_chainmask,
2453 ar5416_get_ntxchains
2454 (tx_chainmask));
2455 if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {
2456 twiceMaxEdgePower = min(twiceMaxEdgePower,
2457 twiceMinEdgePower);
2458 } else {
2459 twiceMaxEdgePower = twiceMinEdgePower;
2460 break;
2461 }
2462 }
2463 }
2464
2465 minCtlPower = min(twiceMaxEdgePower, scaledPower);
2466
2467 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
2468 " SEL-Min ctlMode %d pCtlMode %d "
2469 "2xMaxEdge %d sP %d minCtlPwr %d\n",
2470 ctlMode, pCtlMode[ctlMode], twiceMaxEdgePower,
2471 scaledPower, minCtlPower);
2472
2473 switch (pCtlMode[ctlMode]) {
2474 case CTL_11B:
2475 for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x); i++) {
2476 targetPowerCck.tPow2x[i] =
2477 min((u16)targetPowerCck.tPow2x[i],
2478 minCtlPower);
2479 }
2480 break;
2481 case CTL_11A:
2482 case CTL_11G:
2483 for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x); i++) {
2484 targetPowerOfdm.tPow2x[i] =
2485 min((u16)targetPowerOfdm.tPow2x[i],
2486 minCtlPower);
2487 }
2488 break;
2489 case CTL_5GHT20:
2490 case CTL_2GHT20:
2491 for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) {
2492 targetPowerHt20.tPow2x[i] =
2493 min((u16)targetPowerHt20.tPow2x[i],
2494 minCtlPower);
2495 }
2496 break;
2497 case CTL_11B_EXT:
2498 targetPowerCckExt.tPow2x[0] = min((u16)
2499 targetPowerCckExt.tPow2x[0],
2500 minCtlPower);
2501 break;
2502 case CTL_11A_EXT:
2503 case CTL_11G_EXT:
2504 targetPowerOfdmExt.tPow2x[0] = min((u16)
2505 targetPowerOfdmExt.tPow2x[0],
2506 minCtlPower);
2507 break;
2508 case CTL_5GHT40:
2509 case CTL_2GHT40:
2510 for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
2511 targetPowerHt40.tPow2x[i] =
2512 min((u16)targetPowerHt40.tPow2x[i],
2513 minCtlPower);
2514 }
2515 break;
2516 default:
2517 break;
2518 }
2519 }
2520
2521 ratesArray[rate6mb] = ratesArray[rate9mb] = ratesArray[rate12mb] =
2522 ratesArray[rate18mb] = ratesArray[rate24mb] =
2523 targetPowerOfdm.tPow2x[0];
2524 ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1];
2525 ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2];
2526 ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3];
2527 ratesArray[rateXr] = targetPowerOfdm.tPow2x[0];
2528
2529 for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++)
2530 ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i];
2531
2532 if (IS_CHAN_2GHZ(chan)) {
2533 ratesArray[rate1l] = targetPowerCck.tPow2x[0];
2534 ratesArray[rate2s] = ratesArray[rate2l] =
2535 targetPowerCck.tPow2x[1];
2536 ratesArray[rate5_5s] = ratesArray[rate5_5l] =
2537 targetPowerCck.tPow2x[2];
2538 ;
2539 ratesArray[rate11s] = ratesArray[rate11l] =
2540 targetPowerCck.tPow2x[3];
2541 ;
2542 }
2543 if (IS_CHAN_HT40(chan)) {
2544 for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
2545 ratesArray[rateHt40_0 + i] =
2546 targetPowerHt40.tPow2x[i];
2547 }
2548 ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0];
2549 ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0];
2550 ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0];
2551 if (IS_CHAN_2GHZ(chan)) {
2552 ratesArray[rateExtCck] =
2553 targetPowerCckExt.tPow2x[0];
2554 }
2555 }
2556 return true;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302557}
2558
Sujithf74df6f2009-02-09 13:27:24 +05302559static int ath9k_hw_def_set_txpower(struct ath_hw *ah,
2560 struct ath9k_channel *chan,
2561 u16 cfgCtl,
2562 u8 twiceAntennaReduction,
2563 u8 twiceMaxRegulatoryPower,
2564 u8 powerLimit)
Sujithf1dc5602008-10-29 10:16:30 +05302565{
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05302566#define RT_AR_DELTA(x) (ratesArray[x] - cck_ofdm_delta)
Sujith2660b812009-02-09 13:27:26 +05302567 struct ar5416_eeprom_def *pEepData = &ah->eeprom.def;
Sujithf1dc5602008-10-29 10:16:30 +05302568 struct modal_eep_header *pModal =
Sujithf74df6f2009-02-09 13:27:24 +05302569 &(pEepData->modalHeader[IS_CHAN_2GHZ(chan)]);
2570 int16_t ratesArray[Ar5416RateSize];
2571 int16_t txPowerIndexOffset = 0;
2572 u8 ht40PowerIncForPdadc = 2;
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05302573 int i, cck_ofdm_delta = 0;
Sujithf1dc5602008-10-29 10:16:30 +05302574
Sujithf74df6f2009-02-09 13:27:24 +05302575 memset(ratesArray, 0, sizeof(ratesArray));
2576
2577 if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
2578 AR5416_EEP_MINOR_VER_2) {
2579 ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
2580 }
2581
2582 if (!ath9k_hw_set_def_power_per_rate_table(ah, chan,
2583 &ratesArray[0], cfgCtl,
2584 twiceAntennaReduction,
2585 twiceMaxRegulatoryPower,
2586 powerLimit)) {
2587 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
2588 "ath9k_hw_set_txpower: unable to set "
2589 "tx power per rate table\n");
2590 return -EIO;
2591 }
2592
2593 if (!ath9k_hw_set_def_power_cal_table(ah, chan, &txPowerIndexOffset)) {
2594 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
2595 "ath9k_hw_set_txpower: unable to set power table\n");
2596 return -EIO;
2597 }
2598
2599 for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
2600 ratesArray[i] = (int16_t)(txPowerIndexOffset + ratesArray[i]);
2601 if (ratesArray[i] > AR5416_MAX_RATE_POWER)
2602 ratesArray[i] = AR5416_MAX_RATE_POWER;
2603 }
2604
2605 if (AR_SREV_9280_10_OR_LATER(ah)) {
2606 for (i = 0; i < Ar5416RateSize; i++)
2607 ratesArray[i] -= AR5416_PWR_TABLE_OFFSET * 2;
2608 }
2609
2610 REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
2611 ATH9K_POW_SM(ratesArray[rate18mb], 24)
2612 | ATH9K_POW_SM(ratesArray[rate12mb], 16)
2613 | ATH9K_POW_SM(ratesArray[rate9mb], 8)
2614 | ATH9K_POW_SM(ratesArray[rate6mb], 0));
2615 REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
2616 ATH9K_POW_SM(ratesArray[rate54mb], 24)
2617 | ATH9K_POW_SM(ratesArray[rate48mb], 16)
2618 | ATH9K_POW_SM(ratesArray[rate36mb], 8)
2619 | ATH9K_POW_SM(ratesArray[rate24mb], 0));
2620
2621 if (IS_CHAN_2GHZ(chan)) {
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05302622 if (OLC_FOR_AR9280_20_LATER) {
2623 cck_ofdm_delta = 2;
2624 REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
2625 ATH9K_POW_SM(RT_AR_DELTA(rate2s), 24)
2626 | ATH9K_POW_SM(RT_AR_DELTA(rate2l), 16)
2627 | ATH9K_POW_SM(ratesArray[rateXr], 8)
2628 | ATH9K_POW_SM(RT_AR_DELTA(rate1l), 0));
2629 REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
2630 ATH9K_POW_SM(RT_AR_DELTA(rate11s), 24)
2631 | ATH9K_POW_SM(RT_AR_DELTA(rate11l), 16)
2632 | ATH9K_POW_SM(RT_AR_DELTA(rate5_5s), 8)
2633 | ATH9K_POW_SM(RT_AR_DELTA(rate5_5l), 0));
2634 } else {
2635 REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
2636 ATH9K_POW_SM(ratesArray[rate2s], 24)
2637 | ATH9K_POW_SM(ratesArray[rate2l], 16)
2638 | ATH9K_POW_SM(ratesArray[rateXr], 8)
2639 | ATH9K_POW_SM(ratesArray[rate1l], 0));
2640 REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
2641 ATH9K_POW_SM(ratesArray[rate11s], 24)
2642 | ATH9K_POW_SM(ratesArray[rate11l], 16)
2643 | ATH9K_POW_SM(ratesArray[rate5_5s], 8)
2644 | ATH9K_POW_SM(ratesArray[rate5_5l], 0));
2645 }
Sujithf74df6f2009-02-09 13:27:24 +05302646 }
2647
2648 REG_WRITE(ah, AR_PHY_POWER_TX_RATE5,
2649 ATH9K_POW_SM(ratesArray[rateHt20_3], 24)
2650 | ATH9K_POW_SM(ratesArray[rateHt20_2], 16)
2651 | ATH9K_POW_SM(ratesArray[rateHt20_1], 8)
2652 | ATH9K_POW_SM(ratesArray[rateHt20_0], 0));
2653 REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
2654 ATH9K_POW_SM(ratesArray[rateHt20_7], 24)
2655 | ATH9K_POW_SM(ratesArray[rateHt20_6], 16)
2656 | ATH9K_POW_SM(ratesArray[rateHt20_5], 8)
2657 | ATH9K_POW_SM(ratesArray[rateHt20_4], 0));
2658
2659 if (IS_CHAN_HT40(chan)) {
2660 REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
2661 ATH9K_POW_SM(ratesArray[rateHt40_3] +
2662 ht40PowerIncForPdadc, 24)
2663 | ATH9K_POW_SM(ratesArray[rateHt40_2] +
2664 ht40PowerIncForPdadc, 16)
2665 | ATH9K_POW_SM(ratesArray[rateHt40_1] +
2666 ht40PowerIncForPdadc, 8)
2667 | ATH9K_POW_SM(ratesArray[rateHt40_0] +
2668 ht40PowerIncForPdadc, 0));
2669 REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
2670 ATH9K_POW_SM(ratesArray[rateHt40_7] +
2671 ht40PowerIncForPdadc, 24)
2672 | ATH9K_POW_SM(ratesArray[rateHt40_6] +
2673 ht40PowerIncForPdadc, 16)
2674 | ATH9K_POW_SM(ratesArray[rateHt40_5] +
2675 ht40PowerIncForPdadc, 8)
2676 | ATH9K_POW_SM(ratesArray[rateHt40_4] +
2677 ht40PowerIncForPdadc, 0));
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05302678 if (OLC_FOR_AR9280_20_LATER) {
2679 REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
2680 ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
2681 | ATH9K_POW_SM(RT_AR_DELTA(rateExtCck), 16)
2682 | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
2683 | ATH9K_POW_SM(RT_AR_DELTA(rateDupCck), 0));
2684 } else {
2685 REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
2686 ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
2687 | ATH9K_POW_SM(ratesArray[rateExtCck], 16)
2688 | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
2689 | ATH9K_POW_SM(ratesArray[rateDupCck], 0));
2690 }
Sujithf74df6f2009-02-09 13:27:24 +05302691 }
2692
2693 REG_WRITE(ah, AR_PHY_POWER_TX_SUB,
2694 ATH9K_POW_SM(pModal->pwrDecreaseFor3Chain, 6)
2695 | ATH9K_POW_SM(pModal->pwrDecreaseFor2Chain, 0));
2696
2697 i = rate6mb;
2698
2699 if (IS_CHAN_HT40(chan))
2700 i = rateHt40_0;
2701 else if (IS_CHAN_HT20(chan))
2702 i = rateHt20_0;
2703
2704 if (AR_SREV_9280_10_OR_LATER(ah))
2705 ah->regulatory.max_power_level =
2706 ratesArray[i] + AR5416_PWR_TABLE_OFFSET * 2;
2707 else
2708 ah->regulatory.max_power_level = ratesArray[i];
2709
Sujithe421c7b2009-02-12 10:06:36 +05302710 switch(ar5416_get_ntxchains(ah->txchainmask)) {
2711 case 1:
2712 break;
2713 case 2:
2714 ah->regulatory.max_power_level += INCREASE_MAXPOW_BY_TWO_CHAIN;
2715 break;
2716 case 3:
2717 ah->regulatory.max_power_level += INCREASE_MAXPOW_BY_THREE_CHAIN;
2718 break;
2719 default:
2720 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
2721 "Invalid chainmask configuration\n");
2722 break;
2723 }
2724
Sujithf74df6f2009-02-09 13:27:24 +05302725 return 0;
Sujithf1dc5602008-10-29 10:16:30 +05302726}
2727
Sujithf74df6f2009-02-09 13:27:24 +05302728static u8 ath9k_hw_def_get_num_ant_config(struct ath_hw *ah,
Hannes Ederbf512bc2008-12-26 00:13:29 -08002729 enum ieee80211_band freq_band)
Sujithf1dc5602008-10-29 10:16:30 +05302730{
Sujith2660b812009-02-09 13:27:26 +05302731 struct ar5416_eeprom_def *eep = &ah->eeprom.def;
Sujithf1dc5602008-10-29 10:16:30 +05302732 struct modal_eep_header *pModal =
Senthil Balasubramanian2df1bff2008-12-08 19:43:49 +05302733 &(eep->modalHeader[ATH9K_HAL_FREQ_BAND_2GHZ == freq_band]);
Sujithf1dc5602008-10-29 10:16:30 +05302734 struct base_eep_header *pBase = &eep->baseEepHeader;
2735 u8 num_ant_config;
2736
2737 num_ant_config = 1;
2738
2739 if (pBase->version >= 0x0E0D)
2740 if (pModal->useAnt1)
2741 num_ant_config += 1;
2742
2743 return num_ant_config;
2744}
2745
Sujithf74df6f2009-02-09 13:27:24 +05302746static u16 ath9k_hw_def_get_eeprom_antenna_cfg(struct ath_hw *ah,
2747 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05302748{
Sujith2660b812009-02-09 13:27:26 +05302749 struct ar5416_eeprom_def *eep = &ah->eeprom.def;
Sujithf74df6f2009-02-09 13:27:24 +05302750 struct modal_eep_header *pModal =
2751 &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
2752
2753 return pModal->antCtrlCommon & 0xFFFF;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302754}
2755
Hannes Eder93f726a2009-02-14 11:49:48 +00002756static u16 ath9k_hw_def_get_spur_channel(struct ath_hw *ah, u16 i, bool is2GHz)
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302757{
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302758#define EEP_DEF_SPURCHAN \
Sujith2660b812009-02-09 13:27:26 +05302759 (ah->eeprom.def.modalHeader[is2GHz].spurChans[i].spurChan)
Sujithf74df6f2009-02-09 13:27:24 +05302760
Sujithf1dc5602008-10-29 10:16:30 +05302761 u16 spur_val = AR_NO_SPUR;
2762
2763 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
2764 "Getting spur idx %d is2Ghz. %d val %x\n",
Sujith2660b812009-02-09 13:27:26 +05302765 i, is2GHz, ah->config.spurchans[i][is2GHz]);
Sujithf1dc5602008-10-29 10:16:30 +05302766
Sujith2660b812009-02-09 13:27:26 +05302767 switch (ah->config.spurmode) {
Sujithf1dc5602008-10-29 10:16:30 +05302768 case SPUR_DISABLE:
2769 break;
2770 case SPUR_ENABLE_IOCTL:
Sujith2660b812009-02-09 13:27:26 +05302771 spur_val = ah->config.spurchans[i][is2GHz];
Sujithf1dc5602008-10-29 10:16:30 +05302772 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
2773 "Getting spur val from new loc. %d\n", spur_val);
2774 break;
2775 case SPUR_ENABLE_EEPROM:
Sujithf74df6f2009-02-09 13:27:24 +05302776 spur_val = EEP_DEF_SPURCHAN;
Sujithf1dc5602008-10-29 10:16:30 +05302777 break;
Sujithf1dc5602008-10-29 10:16:30 +05302778 }
2779
2780 return spur_val;
Sujithf74df6f2009-02-09 13:27:24 +05302781
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302782#undef EEP_DEF_SPURCHAN
Sujithf1dc5602008-10-29 10:16:30 +05302783}
2784
Hannes Eder93f726a2009-02-14 11:49:48 +00002785static struct eeprom_ops eep_def_ops = {
Sujithf74df6f2009-02-09 13:27:24 +05302786 .check_eeprom = ath9k_hw_def_check_eeprom,
2787 .get_eeprom = ath9k_hw_def_get_eeprom,
2788 .fill_eeprom = ath9k_hw_def_fill_eeprom,
2789 .get_eeprom_ver = ath9k_hw_def_get_eeprom_ver,
2790 .get_eeprom_rev = ath9k_hw_def_get_eeprom_rev,
2791 .get_num_ant_config = ath9k_hw_def_get_num_ant_config,
2792 .get_eeprom_antenna_cfg = ath9k_hw_def_get_eeprom_antenna_cfg,
2793 .set_board_values = ath9k_hw_def_set_board_values,
2794 .set_addac = ath9k_hw_def_set_addac,
2795 .set_txpower = ath9k_hw_def_set_txpower,
2796 .get_spur_channel = ath9k_hw_def_get_spur_channel
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302797};
2798
Sujithcbe61d82009-02-09 13:27:12 +05302799int ath9k_hw_eeprom_attach(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302800{
2801 int status;
2802
Sujithf74df6f2009-02-09 13:27:24 +05302803 if (AR_SREV_9285(ah)) {
Sujith2660b812009-02-09 13:27:26 +05302804 ah->eep_map = EEP_MAP_4KBITS;
Sujithf74df6f2009-02-09 13:27:24 +05302805 ah->eep_ops = &eep_4k_ops;
2806 } else {
Sujith2660b812009-02-09 13:27:26 +05302807 ah->eep_map = EEP_MAP_DEFAULT;
Sujithf74df6f2009-02-09 13:27:24 +05302808 ah->eep_ops = &eep_def_ops;
2809 }
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302810
Sujithf74df6f2009-02-09 13:27:24 +05302811 if (!ah->eep_ops->fill_eeprom(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302812 return -EIO;
2813
Sujithf74df6f2009-02-09 13:27:24 +05302814 status = ah->eep_ops->check_eeprom(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302815
2816 return status;
2817}