blob: 6c9bc5fdb04a33e009473aaeea1446b9463c55d2 [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
Sujithf74df6f2009-02-09 13:27:24 +05301196static bool ath9k_hw_4k_set_board_values(struct ath_hw *ah,
1197 struct ath9k_channel *chan)
1198{
1199 struct modal_eep_4k_header *pModal;
Sujith2660b812009-02-09 13:27:26 +05301200 struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k;
Sujithf74df6f2009-02-09 13:27:24 +05301201 int regChainOffset;
1202 u8 txRxAttenLocal;
1203 u8 ob[5], db1[5], db2[5];
1204 u8 ant_div_control1, ant_div_control2;
1205 u32 regVal;
1206
1207
1208 pModal = &eep->modalHeader;
1209
1210 txRxAttenLocal = 23;
1211
1212 REG_WRITE(ah, AR_PHY_SWITCH_COM,
1213 ah->eep_ops->get_eeprom_antenna_cfg(ah, chan));
1214
1215 regChainOffset = 0;
1216 REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
1217 pModal->antCtrlChain[0]);
1218
1219 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
1220 (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset) &
1221 ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
1222 AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
1223 SM(pModal->iqCalICh[0], AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
1224 SM(pModal->iqCalQCh[0], AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
1225
1226 if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
1227 AR5416_EEP_MINOR_VER_3) {
1228 txRxAttenLocal = pModal->txRxAttenCh[0];
1229 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
1230 AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN, pModal->bswMargin[0]);
1231 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
1232 AR_PHY_GAIN_2GHZ_XATTEN1_DB, pModal->bswAtten[0]);
1233 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
1234 AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN,
1235 pModal->xatten2Margin[0]);
1236 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
1237 AR_PHY_GAIN_2GHZ_XATTEN2_DB, pModal->xatten2Db[0]);
1238 }
1239
1240 REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
1241 AR9280_PHY_RXGAIN_TXRX_ATTEN, txRxAttenLocal);
1242 REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
1243 AR9280_PHY_RXGAIN_TXRX_MARGIN, pModal->rxTxMarginCh[0]);
1244
1245 if (AR_SREV_9285_11(ah))
1246 REG_WRITE(ah, AR9285_AN_TOP4, (AR9285_AN_TOP4_DEFAULT | 0x14));
1247
1248 /* Initialize Ant Diversity settings from EEPROM */
1249 if (pModal->version == 3) {
1250 ant_div_control1 = ((pModal->ob_234 >> 12) & 0xf);
1251 ant_div_control2 = ((pModal->db1_234 >> 12) & 0xf);
1252 regVal = REG_READ(ah, 0x99ac);
1253 regVal &= (~(0x7f000000));
1254 regVal |= ((ant_div_control1 & 0x1) << 24);
1255 regVal |= (((ant_div_control1 >> 1) & 0x1) << 29);
1256 regVal |= (((ant_div_control1 >> 2) & 0x1) << 30);
1257 regVal |= ((ant_div_control2 & 0x3) << 25);
1258 regVal |= (((ant_div_control2 >> 2) & 0x3) << 27);
1259 REG_WRITE(ah, 0x99ac, regVal);
1260 regVal = REG_READ(ah, 0x99ac);
1261 regVal = REG_READ(ah, 0xa208);
1262 regVal &= (~(0x1 << 13));
1263 regVal |= (((ant_div_control1 >> 3) & 0x1) << 13);
1264 REG_WRITE(ah, 0xa208, regVal);
1265 regVal = REG_READ(ah, 0xa208);
1266 }
1267
1268 if (pModal->version >= 2) {
1269 ob[0] = (pModal->ob_01 & 0xf);
1270 ob[1] = (pModal->ob_01 >> 4) & 0xf;
1271 ob[2] = (pModal->ob_234 & 0xf);
1272 ob[3] = ((pModal->ob_234 >> 4) & 0xf);
1273 ob[4] = ((pModal->ob_234 >> 8) & 0xf);
1274
1275 db1[0] = (pModal->db1_01 & 0xf);
1276 db1[1] = ((pModal->db1_01 >> 4) & 0xf);
1277 db1[2] = (pModal->db1_234 & 0xf);
1278 db1[3] = ((pModal->db1_234 >> 4) & 0xf);
1279 db1[4] = ((pModal->db1_234 >> 8) & 0xf);
1280
1281 db2[0] = (pModal->db2_01 & 0xf);
1282 db2[1] = ((pModal->db2_01 >> 4) & 0xf);
1283 db2[2] = (pModal->db2_234 & 0xf);
1284 db2[3] = ((pModal->db2_234 >> 4) & 0xf);
1285 db2[4] = ((pModal->db2_234 >> 8) & 0xf);
1286
1287 } else if (pModal->version == 1) {
Sujithf74df6f2009-02-09 13:27:24 +05301288 ob[0] = (pModal->ob_01 & 0xf);
1289 ob[1] = ob[2] = ob[3] = ob[4] = (pModal->ob_01 >> 4) & 0xf;
1290 db1[0] = (pModal->db1_01 & 0xf);
1291 db1[1] = db1[2] = db1[3] =
1292 db1[4] = ((pModal->db1_01 >> 4) & 0xf);
1293 db2[0] = (pModal->db2_01 & 0xf);
1294 db2[1] = db2[2] = db2[3] =
1295 db2[4] = ((pModal->db2_01 >> 4) & 0xf);
1296 } else {
1297 int i;
1298 for (i = 0; i < 5; i++) {
1299 ob[i] = pModal->ob_01;
1300 db1[i] = pModal->db1_01;
1301 db2[i] = pModal->db1_01;
1302 }
1303 }
1304
1305 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
1306 AR9285_AN_RF2G3_OB_0, AR9285_AN_RF2G3_OB_0_S, ob[0]);
1307 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
1308 AR9285_AN_RF2G3_OB_1, AR9285_AN_RF2G3_OB_1_S, ob[1]);
1309 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
1310 AR9285_AN_RF2G3_OB_2, AR9285_AN_RF2G3_OB_2_S, ob[2]);
1311 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
1312 AR9285_AN_RF2G3_OB_3, AR9285_AN_RF2G3_OB_3_S, ob[3]);
1313 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
1314 AR9285_AN_RF2G3_OB_4, AR9285_AN_RF2G3_OB_4_S, ob[4]);
1315
1316 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
1317 AR9285_AN_RF2G3_DB1_0, AR9285_AN_RF2G3_DB1_0_S, db1[0]);
1318 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
1319 AR9285_AN_RF2G3_DB1_1, AR9285_AN_RF2G3_DB1_1_S, db1[1]);
1320 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G3,
1321 AR9285_AN_RF2G3_DB1_2, AR9285_AN_RF2G3_DB1_2_S, db1[2]);
1322 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
1323 AR9285_AN_RF2G4_DB1_3, AR9285_AN_RF2G4_DB1_3_S, db1[3]);
1324 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
1325 AR9285_AN_RF2G4_DB1_4, AR9285_AN_RF2G4_DB1_4_S, db1[4]);
1326
1327 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
1328 AR9285_AN_RF2G4_DB2_0, AR9285_AN_RF2G4_DB2_0_S, db2[0]);
1329 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
1330 AR9285_AN_RF2G4_DB2_1, AR9285_AN_RF2G4_DB2_1_S, db2[1]);
1331 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
1332 AR9285_AN_RF2G4_DB2_2, AR9285_AN_RF2G4_DB2_2_S, db2[2]);
1333 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
1334 AR9285_AN_RF2G4_DB2_3, AR9285_AN_RF2G4_DB2_3_S, db2[3]);
1335 ath9k_hw_analog_shift_rmw(ah, AR9285_AN_RF2G4,
1336 AR9285_AN_RF2G4_DB2_4, AR9285_AN_RF2G4_DB2_4_S, db2[4]);
1337
1338
1339 if (AR_SREV_9285_11(ah))
1340 REG_WRITE(ah, AR9285_AN_TOP4, AR9285_AN_TOP4_DEFAULT);
1341
1342 REG_RMW_FIELD(ah, AR_PHY_SETTLING, AR_PHY_SETTLING_SWITCH,
1343 pModal->switchSettling);
1344 REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ, AR_PHY_DESIRED_SZ_ADC,
1345 pModal->adcDesiredSize);
1346
1347 REG_WRITE(ah, AR_PHY_RF_CTL4,
1348 SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF) |
1349 SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAB_OFF) |
1350 SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAA_ON) |
1351 SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAB_ON));
1352
1353 REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON,
1354 pModal->txEndToRxOn);
1355 REG_RMW_FIELD(ah, AR_PHY_CCA, AR9280_PHY_CCA_THRESH62,
1356 pModal->thresh62);
1357 REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0, AR_PHY_EXT_CCA0_THRESH62,
1358 pModal->thresh62);
1359
1360 if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
1361 AR5416_EEP_MINOR_VER_2) {
1362 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_DATA_START,
1363 pModal->txFrameToDataStart);
1364 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_PA_ON,
1365 pModal->txFrameToPaOn);
1366 }
1367
1368 if ((eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
1369 AR5416_EEP_MINOR_VER_3) {
1370 if (IS_CHAN_HT40(chan))
1371 REG_RMW_FIELD(ah, AR_PHY_SETTLING,
1372 AR_PHY_SETTLING_SWITCH,
1373 pModal->swSettleHt40);
1374 }
1375
1376 return true;
1377}
1378
1379static u16 ath9k_hw_4k_get_eeprom_antenna_cfg(struct ath_hw *ah,
1380 struct ath9k_channel *chan)
1381{
Sujith2660b812009-02-09 13:27:26 +05301382 struct ar5416_eeprom_4k *eep = &ah->eeprom.map4k;
Sujithf74df6f2009-02-09 13:27:24 +05301383 struct modal_eep_4k_header *pModal = &eep->modalHeader;
1384
1385 return pModal->antCtrlCommon & 0xFFFF;
1386}
1387
1388static u8 ath9k_hw_4k_get_num_ant_config(struct ath_hw *ah,
1389 enum ieee80211_band freq_band)
1390{
1391 return 1;
1392}
1393
Hannes Eder93f726a2009-02-14 11:49:48 +00001394static u16 ath9k_hw_4k_get_spur_channel(struct ath_hw *ah, u16 i, bool is2GHz)
Sujithf74df6f2009-02-09 13:27:24 +05301395{
1396#define EEP_MAP4K_SPURCHAN \
Sujith2660b812009-02-09 13:27:26 +05301397 (ah->eeprom.map4k.modalHeader.spurChans[i].spurChan)
Sujithf74df6f2009-02-09 13:27:24 +05301398
1399 u16 spur_val = AR_NO_SPUR;
1400
1401 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
1402 "Getting spur idx %d is2Ghz. %d val %x\n",
Sujith2660b812009-02-09 13:27:26 +05301403 i, is2GHz, ah->config.spurchans[i][is2GHz]);
Sujithf74df6f2009-02-09 13:27:24 +05301404
Sujith2660b812009-02-09 13:27:26 +05301405 switch (ah->config.spurmode) {
Sujithf74df6f2009-02-09 13:27:24 +05301406 case SPUR_DISABLE:
1407 break;
1408 case SPUR_ENABLE_IOCTL:
Sujith2660b812009-02-09 13:27:26 +05301409 spur_val = ah->config.spurchans[i][is2GHz];
Sujithf74df6f2009-02-09 13:27:24 +05301410 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
1411 "Getting spur val from new loc. %d\n", spur_val);
1412 break;
1413 case SPUR_ENABLE_EEPROM:
1414 spur_val = EEP_MAP4K_SPURCHAN;
1415 break;
1416 }
1417
1418 return spur_val;
1419
1420#undef EEP_MAP4K_SPURCHAN
1421}
1422
Hannes Eder93f726a2009-02-14 11:49:48 +00001423static struct eeprom_ops eep_4k_ops = {
Sujithf74df6f2009-02-09 13:27:24 +05301424 .check_eeprom = ath9k_hw_4k_check_eeprom,
1425 .get_eeprom = ath9k_hw_4k_get_eeprom,
1426 .fill_eeprom = ath9k_hw_4k_fill_eeprom,
1427 .get_eeprom_ver = ath9k_hw_4k_get_eeprom_ver,
1428 .get_eeprom_rev = ath9k_hw_4k_get_eeprom_rev,
1429 .get_num_ant_config = ath9k_hw_4k_get_num_ant_config,
1430 .get_eeprom_antenna_cfg = ath9k_hw_4k_get_eeprom_antenna_cfg,
1431 .set_board_values = ath9k_hw_4k_set_board_values,
1432 .set_addac = ath9k_hw_4k_set_addac,
1433 .set_txpower = ath9k_hw_4k_set_txpower,
1434 .get_spur_channel = ath9k_hw_4k_get_spur_channel
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301435};
1436
Sujithf74df6f2009-02-09 13:27:24 +05301437/************************************************/
1438/* EEPROM Operations for non-4K (Default) cards */
1439/************************************************/
1440
1441static int ath9k_hw_def_get_eeprom_ver(struct ath_hw *ah)
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301442{
Sujith2660b812009-02-09 13:27:26 +05301443 return ((ah->eeprom.def.baseEepHeader.version >> 12) & 0xF);
Sujithf74df6f2009-02-09 13:27:24 +05301444}
1445
1446static int ath9k_hw_def_get_eeprom_rev(struct ath_hw *ah)
1447{
Sujith2660b812009-02-09 13:27:26 +05301448 return ((ah->eeprom.def.baseEepHeader.version) & 0xFFF);
Sujithf74df6f2009-02-09 13:27:24 +05301449}
1450
1451static bool ath9k_hw_def_fill_eeprom(struct ath_hw *ah)
1452{
1453#define SIZE_EEPROM_DEF (sizeof(struct ar5416_eeprom_def) / sizeof(u16))
Sujith7d01b222009-03-13 08:55:55 +05301454 u16 *eep_data = (u16 *)&ah->eeprom.def;
Sujithf74df6f2009-02-09 13:27:24 +05301455 int addr, ar5416_eep_start_loc = 0x100;
1456
Sujithf74df6f2009-02-09 13:27:24 +05301457 for (addr = 0; addr < SIZE_EEPROM_DEF; addr++) {
1458 if (!ath9k_hw_nvram_read(ah, addr + ar5416_eep_start_loc,
1459 eep_data)) {
Sujith7d01b222009-03-13 08:55:55 +05301460 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
Sujithf74df6f2009-02-09 13:27:24 +05301461 "Unable to read eeprom region\n");
1462 return false;
1463 }
1464 eep_data++;
1465 }
1466 return true;
1467#undef SIZE_EEPROM_DEF
1468}
1469
1470static int ath9k_hw_def_check_eeprom(struct ath_hw *ah)
1471{
1472 struct ar5416_eeprom_def *eep =
Sujith2660b812009-02-09 13:27:26 +05301473 (struct ar5416_eeprom_def *) &ah->eeprom.def;
Sujithf74df6f2009-02-09 13:27:24 +05301474 u16 *eepdata, temp, magic, magic2;
1475 u32 sum = 0, el;
1476 bool need_swap = false;
1477 int i, addr, size;
1478
Sujith7d01b222009-03-13 08:55:55 +05301479 if (!ath9k_hw_nvram_read(ah, AR5416_EEPROM_MAGIC_OFFSET, &magic)) {
1480 DPRINTF(ah->ah_sc, ATH_DBG_FATAL, "Reading Magic # failed\n");
Sujithf74df6f2009-02-09 13:27:24 +05301481 return false;
1482 }
1483
1484 if (!ath9k_hw_use_flash(ah)) {
Sujithf74df6f2009-02-09 13:27:24 +05301485 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
Sujith7d01b222009-03-13 08:55:55 +05301486 "Read Magic = 0x%04X\n", magic);
Sujithf74df6f2009-02-09 13:27:24 +05301487
1488 if (magic != AR5416_EEPROM_MAGIC) {
1489 magic2 = swab16(magic);
1490
1491 if (magic2 == AR5416_EEPROM_MAGIC) {
1492 size = sizeof(struct ar5416_eeprom_def);
1493 need_swap = true;
Sujith2660b812009-02-09 13:27:26 +05301494 eepdata = (u16 *) (&ah->eeprom);
Sujithf74df6f2009-02-09 13:27:24 +05301495
1496 for (addr = 0; addr < size / sizeof(u16); addr++) {
1497 temp = swab16(*eepdata);
1498 *eepdata = temp;
1499 eepdata++;
Sujithf74df6f2009-02-09 13:27:24 +05301500 }
1501 } else {
Sujith7d01b222009-03-13 08:55:55 +05301502 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
Sujithf74df6f2009-02-09 13:27:24 +05301503 "Invalid EEPROM Magic. "
Sujith7d01b222009-03-13 08:55:55 +05301504 "Endianness mismatch.\n");
Sujithf74df6f2009-02-09 13:27:24 +05301505 return -EINVAL;
1506 }
1507 }
1508 }
1509
1510 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM, "need_swap = %s.\n",
1511 need_swap ? "True" : "False");
1512
1513 if (need_swap)
Sujith2660b812009-02-09 13:27:26 +05301514 el = swab16(ah->eeprom.def.baseEepHeader.length);
Sujithf74df6f2009-02-09 13:27:24 +05301515 else
Sujith2660b812009-02-09 13:27:26 +05301516 el = ah->eeprom.def.baseEepHeader.length;
Sujithf74df6f2009-02-09 13:27:24 +05301517
1518 if (el > sizeof(struct ar5416_eeprom_def))
1519 el = sizeof(struct ar5416_eeprom_def) / sizeof(u16);
1520 else
1521 el = el / sizeof(u16);
1522
Sujith2660b812009-02-09 13:27:26 +05301523 eepdata = (u16 *)(&ah->eeprom);
Sujithf74df6f2009-02-09 13:27:24 +05301524
1525 for (i = 0; i < el; i++)
1526 sum ^= *eepdata++;
1527
1528 if (need_swap) {
1529 u32 integer, j;
1530 u16 word;
1531
1532 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
Sujith7d01b222009-03-13 08:55:55 +05301533 "EEPROM Endianness is not native.. Changing.\n");
Sujithf74df6f2009-02-09 13:27:24 +05301534
1535 word = swab16(eep->baseEepHeader.length);
1536 eep->baseEepHeader.length = word;
1537
1538 word = swab16(eep->baseEepHeader.checksum);
1539 eep->baseEepHeader.checksum = word;
1540
1541 word = swab16(eep->baseEepHeader.version);
1542 eep->baseEepHeader.version = word;
1543
1544 word = swab16(eep->baseEepHeader.regDmn[0]);
1545 eep->baseEepHeader.regDmn[0] = word;
1546
1547 word = swab16(eep->baseEepHeader.regDmn[1]);
1548 eep->baseEepHeader.regDmn[1] = word;
1549
1550 word = swab16(eep->baseEepHeader.rfSilent);
1551 eep->baseEepHeader.rfSilent = word;
1552
1553 word = swab16(eep->baseEepHeader.blueToothOptions);
1554 eep->baseEepHeader.blueToothOptions = word;
1555
1556 word = swab16(eep->baseEepHeader.deviceCap);
1557 eep->baseEepHeader.deviceCap = word;
1558
1559 for (j = 0; j < ARRAY_SIZE(eep->modalHeader); j++) {
1560 struct modal_eep_header *pModal =
1561 &eep->modalHeader[j];
1562 integer = swab32(pModal->antCtrlCommon);
1563 pModal->antCtrlCommon = integer;
1564
1565 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
1566 integer = swab32(pModal->antCtrlChain[i]);
1567 pModal->antCtrlChain[i] = integer;
1568 }
1569
1570 for (i = 0; i < AR5416_EEPROM_MODAL_SPURS; i++) {
1571 word = swab16(pModal->spurChans[i].spurChan);
1572 pModal->spurChans[i].spurChan = word;
1573 }
1574 }
1575 }
1576
1577 if (sum != 0xffff || ah->eep_ops->get_eeprom_ver(ah) != AR5416_EEP_VER ||
1578 ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_NO_BACK_VER) {
Sujith7d01b222009-03-13 08:55:55 +05301579 DPRINTF(ah->ah_sc, ATH_DBG_FATAL,
Sujithf74df6f2009-02-09 13:27:24 +05301580 "Bad EEPROM checksum 0x%x or revision 0x%04x\n",
1581 sum, ah->eep_ops->get_eeprom_ver(ah));
1582 return -EINVAL;
1583 }
1584
1585 return 0;
1586}
1587
1588static u32 ath9k_hw_def_get_eeprom(struct ath_hw *ah,
1589 enum eeprom_param param)
1590{
1591#define AR5416_VER_MASK (pBase->version & AR5416_EEP_VER_MINOR_MASK)
Sujith2660b812009-02-09 13:27:26 +05301592 struct ar5416_eeprom_def *eep = &ah->eeprom.def;
Sujithf74df6f2009-02-09 13:27:24 +05301593 struct modal_eep_header *pModal = eep->modalHeader;
1594 struct base_eep_header *pBase = &eep->baseEepHeader;
1595
1596 switch (param) {
1597 case EEP_NFTHRESH_5:
1598 return pModal[0].noiseFloorThreshCh[0];
1599 case EEP_NFTHRESH_2:
1600 return pModal[1].noiseFloorThreshCh[0];
1601 case AR_EEPROM_MAC(0):
1602 return pBase->macAddr[0] << 8 | pBase->macAddr[1];
1603 case AR_EEPROM_MAC(1):
1604 return pBase->macAddr[2] << 8 | pBase->macAddr[3];
1605 case AR_EEPROM_MAC(2):
1606 return pBase->macAddr[4] << 8 | pBase->macAddr[5];
1607 case EEP_REG_0:
1608 return pBase->regDmn[0];
1609 case EEP_REG_1:
1610 return pBase->regDmn[1];
1611 case EEP_OP_CAP:
1612 return pBase->deviceCap;
1613 case EEP_OP_MODE:
1614 return pBase->opCapFlags;
1615 case EEP_RF_SILENT:
1616 return pBase->rfSilent;
1617 case EEP_OB_5:
1618 return pModal[0].ob;
1619 case EEP_DB_5:
1620 return pModal[0].db;
1621 case EEP_OB_2:
1622 return pModal[1].ob;
1623 case EEP_DB_2:
1624 return pModal[1].db;
1625 case EEP_MINOR_REV:
1626 return AR5416_VER_MASK;
1627 case EEP_TX_MASK:
1628 return pBase->txMask;
1629 case EEP_RX_MASK:
1630 return pBase->rxMask;
1631 case EEP_RXGAIN_TYPE:
1632 return pBase->rxGainType;
1633 case EEP_TXGAIN_TYPE:
1634 return pBase->txGainType;
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301635 case EEP_OL_PWRCTRL:
1636 if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
1637 return pBase->openLoopPwrCntl ? true : false;
1638 else
1639 return false;
1640 case EEP_RC_CHAIN_MASK:
1641 if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
1642 return pBase->rcChainMask;
1643 else
1644 return 0;
Sujithf74df6f2009-02-09 13:27:24 +05301645 case EEP_DAC_HPWR_5G:
1646 if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_20)
1647 return pBase->dacHiPwrMode_5G;
1648 else
1649 return 0;
Sujith06d0f062009-02-12 10:06:45 +05301650 case EEP_FRAC_N_5G:
1651 if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_22)
1652 return pBase->frac_n_5g;
1653 else
1654 return 0;
Sujithf74df6f2009-02-09 13:27:24 +05301655 default:
1656 return 0;
1657 }
1658#undef AR5416_VER_MASK
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301659}
1660
Sujithf1dc5602008-10-29 10:16:30 +05301661/* XXX: Clean me up, make me more legible */
Sujithf74df6f2009-02-09 13:27:24 +05301662static bool ath9k_hw_def_set_board_values(struct ath_hw *ah,
1663 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05301664{
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05301665#define AR5416_VER_MASK (eep->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK)
Sujithf1dc5602008-10-29 10:16:30 +05301666 struct modal_eep_header *pModal;
Sujith2660b812009-02-09 13:27:26 +05301667 struct ar5416_eeprom_def *eep = &ah->eeprom.def;
Sujithf1dc5602008-10-29 10:16:30 +05301668 int i, regChainOffset;
1669 u8 txRxAttenLocal;
Sujithf1dc5602008-10-29 10:16:30 +05301670
1671 pModal = &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
1672
1673 txRxAttenLocal = IS_CHAN_2GHZ(chan) ? 23 : 44;
1674
Vasanthakumar Thiagarajan81b1e192009-01-23 14:40:37 +05301675 REG_WRITE(ah, AR_PHY_SWITCH_COM,
Sujithf74df6f2009-02-09 13:27:24 +05301676 ah->eep_ops->get_eeprom_antenna_cfg(ah, chan));
Sujithf1dc5602008-10-29 10:16:30 +05301677
1678 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
1679 if (AR_SREV_9280(ah)) {
1680 if (i >= 2)
1681 break;
1682 }
1683
Gabor Juhosa8c96d32009-03-06 09:08:51 +01001684 if (AR_SREV_5416_20_OR_LATER(ah) &&
Sujith2660b812009-02-09 13:27:26 +05301685 (ah->rxchainmask == 5 || ah->txchainmask == 5)
Sujithf1dc5602008-10-29 10:16:30 +05301686 && (i != 0))
1687 regChainOffset = (i == 1) ? 0x2000 : 0x1000;
1688 else
1689 regChainOffset = i * 0x1000;
1690
1691 REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
1692 pModal->antCtrlChain[i]);
1693
1694 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
1695 (REG_READ(ah,
1696 AR_PHY_TIMING_CTRL4(0) +
1697 regChainOffset) &
1698 ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
1699 AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
1700 SM(pModal->iqCalICh[i],
1701 AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
1702 SM(pModal->iqCalQCh[i],
1703 AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
1704
Gabor Juhosa8c96d32009-03-06 09:08:51 +01001705 if ((i == 0) || AR_SREV_5416_20_OR_LATER(ah)) {
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05301706 if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_3) {
Sujithf1dc5602008-10-29 10:16:30 +05301707 txRxAttenLocal = pModal->txRxAttenCh[i];
1708 if (AR_SREV_9280_10_OR_LATER(ah)) {
1709 REG_RMW_FIELD(ah,
1710 AR_PHY_GAIN_2GHZ +
1711 regChainOffset,
1712 AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN,
1713 pModal->
1714 bswMargin[i]);
1715 REG_RMW_FIELD(ah,
1716 AR_PHY_GAIN_2GHZ +
1717 regChainOffset,
1718 AR_PHY_GAIN_2GHZ_XATTEN1_DB,
1719 pModal->
1720 bswAtten[i]);
1721 REG_RMW_FIELD(ah,
1722 AR_PHY_GAIN_2GHZ +
1723 regChainOffset,
1724 AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN,
1725 pModal->
1726 xatten2Margin[i]);
1727 REG_RMW_FIELD(ah,
1728 AR_PHY_GAIN_2GHZ +
1729 regChainOffset,
1730 AR_PHY_GAIN_2GHZ_XATTEN2_DB,
1731 pModal->
1732 xatten2Db[i]);
1733 } else {
1734 REG_WRITE(ah,
1735 AR_PHY_GAIN_2GHZ +
1736 regChainOffset,
1737 (REG_READ(ah,
1738 AR_PHY_GAIN_2GHZ +
1739 regChainOffset) &
1740 ~AR_PHY_GAIN_2GHZ_BSW_MARGIN)
1741 | SM(pModal->
1742 bswMargin[i],
1743 AR_PHY_GAIN_2GHZ_BSW_MARGIN));
1744 REG_WRITE(ah,
1745 AR_PHY_GAIN_2GHZ +
1746 regChainOffset,
1747 (REG_READ(ah,
1748 AR_PHY_GAIN_2GHZ +
1749 regChainOffset) &
1750 ~AR_PHY_GAIN_2GHZ_BSW_ATTEN)
1751 | SM(pModal->bswAtten[i],
1752 AR_PHY_GAIN_2GHZ_BSW_ATTEN));
1753 }
1754 }
1755 if (AR_SREV_9280_10_OR_LATER(ah)) {
1756 REG_RMW_FIELD(ah,
1757 AR_PHY_RXGAIN +
1758 regChainOffset,
1759 AR9280_PHY_RXGAIN_TXRX_ATTEN,
1760 txRxAttenLocal);
1761 REG_RMW_FIELD(ah,
1762 AR_PHY_RXGAIN +
1763 regChainOffset,
1764 AR9280_PHY_RXGAIN_TXRX_MARGIN,
1765 pModal->rxTxMarginCh[i]);
1766 } else {
1767 REG_WRITE(ah,
1768 AR_PHY_RXGAIN + regChainOffset,
1769 (REG_READ(ah,
1770 AR_PHY_RXGAIN +
1771 regChainOffset) &
1772 ~AR_PHY_RXGAIN_TXRX_ATTEN) |
1773 SM(txRxAttenLocal,
1774 AR_PHY_RXGAIN_TXRX_ATTEN));
1775 REG_WRITE(ah,
1776 AR_PHY_GAIN_2GHZ +
1777 regChainOffset,
1778 (REG_READ(ah,
1779 AR_PHY_GAIN_2GHZ +
1780 regChainOffset) &
1781 ~AR_PHY_GAIN_2GHZ_RXTX_MARGIN) |
1782 SM(pModal->rxTxMarginCh[i],
1783 AR_PHY_GAIN_2GHZ_RXTX_MARGIN));
1784 }
1785 }
1786 }
1787
1788 if (AR_SREV_9280_10_OR_LATER(ah)) {
1789 if (IS_CHAN_2GHZ(chan)) {
1790 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH0,
1791 AR_AN_RF2G1_CH0_OB,
1792 AR_AN_RF2G1_CH0_OB_S,
1793 pModal->ob);
1794 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH0,
1795 AR_AN_RF2G1_CH0_DB,
1796 AR_AN_RF2G1_CH0_DB_S,
1797 pModal->db);
1798 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH1,
1799 AR_AN_RF2G1_CH1_OB,
1800 AR_AN_RF2G1_CH1_OB_S,
1801 pModal->ob_ch1);
1802 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF2G1_CH1,
1803 AR_AN_RF2G1_CH1_DB,
1804 AR_AN_RF2G1_CH1_DB_S,
1805 pModal->db_ch1);
1806 } else {
1807 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH0,
1808 AR_AN_RF5G1_CH0_OB5,
1809 AR_AN_RF5G1_CH0_OB5_S,
1810 pModal->ob);
1811 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH0,
1812 AR_AN_RF5G1_CH0_DB5,
1813 AR_AN_RF5G1_CH0_DB5_S,
1814 pModal->db);
1815 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH1,
1816 AR_AN_RF5G1_CH1_OB5,
1817 AR_AN_RF5G1_CH1_OB5_S,
1818 pModal->ob_ch1);
1819 ath9k_hw_analog_shift_rmw(ah, AR_AN_RF5G1_CH1,
1820 AR_AN_RF5G1_CH1_DB5,
1821 AR_AN_RF5G1_CH1_DB5_S,
1822 pModal->db_ch1);
1823 }
1824 ath9k_hw_analog_shift_rmw(ah, AR_AN_TOP2,
1825 AR_AN_TOP2_XPABIAS_LVL,
1826 AR_AN_TOP2_XPABIAS_LVL_S,
1827 pModal->xpaBiasLvl);
1828 ath9k_hw_analog_shift_rmw(ah, AR_AN_TOP2,
1829 AR_AN_TOP2_LOCALBIAS,
1830 AR_AN_TOP2_LOCALBIAS_S,
1831 pModal->local_bias);
Sujithf1dc5602008-10-29 10:16:30 +05301832 REG_RMW_FIELD(ah, AR_PHY_XPA_CFG, AR_PHY_FORCE_XPA_CFG,
1833 pModal->force_xpaon);
1834 }
1835
1836 REG_RMW_FIELD(ah, AR_PHY_SETTLING, AR_PHY_SETTLING_SWITCH,
1837 pModal->switchSettling);
1838 REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ, AR_PHY_DESIRED_SZ_ADC,
1839 pModal->adcDesiredSize);
1840
1841 if (!AR_SREV_9280_10_OR_LATER(ah))
1842 REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
1843 AR_PHY_DESIRED_SZ_PGA,
1844 pModal->pgaDesiredSize);
1845
1846 REG_WRITE(ah, AR_PHY_RF_CTL4,
1847 SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF)
1848 | SM(pModal->txEndToXpaOff,
1849 AR_PHY_RF_CTL4_TX_END_XPAB_OFF)
1850 | SM(pModal->txFrameToXpaOn,
1851 AR_PHY_RF_CTL4_FRAME_XPAA_ON)
1852 | SM(pModal->txFrameToXpaOn,
1853 AR_PHY_RF_CTL4_FRAME_XPAB_ON));
1854
1855 REG_RMW_FIELD(ah, AR_PHY_RF_CTL3, AR_PHY_TX_END_TO_A2_RX_ON,
1856 pModal->txEndToRxOn);
Sujith7d01b222009-03-13 08:55:55 +05301857
Sujithf1dc5602008-10-29 10:16:30 +05301858 if (AR_SREV_9280_10_OR_LATER(ah)) {
1859 REG_RMW_FIELD(ah, AR_PHY_CCA, AR9280_PHY_CCA_THRESH62,
1860 pModal->thresh62);
1861 REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0,
1862 AR_PHY_EXT_CCA0_THRESH62,
1863 pModal->thresh62);
1864 } else {
1865 REG_RMW_FIELD(ah, AR_PHY_CCA, AR_PHY_CCA_THRESH62,
1866 pModal->thresh62);
1867 REG_RMW_FIELD(ah, AR_PHY_EXT_CCA,
1868 AR_PHY_EXT_CCA_THRESH62,
1869 pModal->thresh62);
1870 }
1871
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05301872 if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_2) {
Sujithf1dc5602008-10-29 10:16:30 +05301873 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
1874 AR_PHY_TX_END_DATA_START,
1875 pModal->txFrameToDataStart);
1876 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2, AR_PHY_TX_END_PA_ON,
1877 pModal->txFrameToPaOn);
1878 }
1879
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05301880 if (AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_3) {
Sujithf1dc5602008-10-29 10:16:30 +05301881 if (IS_CHAN_HT40(chan))
1882 REG_RMW_FIELD(ah, AR_PHY_SETTLING,
1883 AR_PHY_SETTLING_SWITCH,
1884 pModal->swSettleHt40);
1885 }
1886
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301887 if (AR_SREV_9280_20_OR_LATER(ah) &&
Sujith7d01b222009-03-13 08:55:55 +05301888 AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_19)
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301889 REG_RMW_FIELD(ah, AR_PHY_CCK_TX_CTRL,
Sujith7d01b222009-03-13 08:55:55 +05301890 AR_PHY_CCK_TX_CTRL_TX_DAC_SCALE_CCK,
1891 pModal->miscBits);
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301892
1893
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05301894 if (AR_SREV_9280_20(ah) && AR5416_VER_MASK >= AR5416_EEP_MINOR_VER_20) {
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301895 if (IS_CHAN_2GHZ(chan))
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05301896 REG_RMW_FIELD(ah, AR_AN_TOP1, AR_AN_TOP1_DACIPMODE,
1897 eep->baseEepHeader.dacLpMode);
1898 else if (eep->baseEepHeader.dacHiPwrMode_5G)
1899 REG_RMW_FIELD(ah, AR_AN_TOP1, AR_AN_TOP1_DACIPMODE, 0);
1900 else
1901 REG_RMW_FIELD(ah, AR_AN_TOP1, AR_AN_TOP1_DACIPMODE,
Sujith7d01b222009-03-13 08:55:55 +05301902 eep->baseEepHeader.dacLpMode);
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05301903
1904 REG_RMW_FIELD(ah, AR_PHY_FRAME_CTL, AR_PHY_FRAME_CTL_TX_CLIP,
Sujith7d01b222009-03-13 08:55:55 +05301905 pModal->miscBits >> 2);
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05301906
1907 REG_RMW_FIELD(ah, AR_PHY_TX_PWRCTRL9,
Sujith7d01b222009-03-13 08:55:55 +05301908 AR_PHY_TX_DESIRED_SCALE_CCK,
1909 eep->baseEepHeader.desiredScaleCCK);
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05301910 }
1911
Sujithf1dc5602008-10-29 10:16:30 +05301912 return true;
Senthil Balasubramaniancb33c412008-12-24 18:03:58 +05301913#undef AR5416_VER_MASK
Sujithf1dc5602008-10-29 10:16:30 +05301914}
1915
Sujithf74df6f2009-02-09 13:27:24 +05301916static void ath9k_hw_def_set_addac(struct ath_hw *ah,
1917 struct ath9k_channel *chan)
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301918{
Sujithf74df6f2009-02-09 13:27:24 +05301919#define XPA_LVL_FREQ(cnt) (pModal->xpaBiasLvlFreq[cnt])
1920 struct modal_eep_header *pModal;
Sujith2660b812009-02-09 13:27:26 +05301921 struct ar5416_eeprom_def *eep = &ah->eeprom.def;
Sujithf74df6f2009-02-09 13:27:24 +05301922 u8 biaslevel;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301923
Sujithf74df6f2009-02-09 13:27:24 +05301924 if (ah->hw_version.macVersion != AR_SREV_VERSION_9160)
1925 return;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301926
Sujithf74df6f2009-02-09 13:27:24 +05301927 if (ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_MINOR_VER_7)
1928 return;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301929
Sujithf74df6f2009-02-09 13:27:24 +05301930 pModal = &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301931
Sujithf74df6f2009-02-09 13:27:24 +05301932 if (pModal->xpaBiasLvl != 0xff) {
1933 biaslevel = pModal->xpaBiasLvl;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301934 } else {
Sujithf74df6f2009-02-09 13:27:24 +05301935 u16 resetFreqBin, freqBin, freqCount = 0;
1936 struct chan_centers centers;
1937
1938 ath9k_hw_get_channel_centers(ah, chan, &centers);
1939
1940 resetFreqBin = FREQ2FBIN(centers.synth_center,
1941 IS_CHAN_2GHZ(chan));
1942 freqBin = XPA_LVL_FREQ(0) & 0xff;
1943 biaslevel = (u8) (XPA_LVL_FREQ(0) >> 14);
1944
1945 freqCount++;
1946
1947 while (freqCount < 3) {
1948 if (XPA_LVL_FREQ(freqCount) == 0x0)
1949 break;
1950
1951 freqBin = XPA_LVL_FREQ(freqCount) & 0xff;
1952 if (resetFreqBin >= freqBin)
1953 biaslevel = (u8)(XPA_LVL_FREQ(freqCount) >> 14);
1954 else
1955 break;
1956 freqCount++;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301957 }
1958 }
1959
Sujithf74df6f2009-02-09 13:27:24 +05301960 if (IS_CHAN_2GHZ(chan)) {
Sujith2660b812009-02-09 13:27:26 +05301961 INI_RA(&ah->iniAddac, 7, 1) = (INI_RA(&ah->iniAddac,
Sujithf74df6f2009-02-09 13:27:24 +05301962 7, 1) & (~0x18)) | biaslevel << 3;
1963 } else {
Sujith2660b812009-02-09 13:27:26 +05301964 INI_RA(&ah->iniAddac, 6, 1) = (INI_RA(&ah->iniAddac,
Sujithf74df6f2009-02-09 13:27:24 +05301965 6, 1) & (~0xc0)) | biaslevel << 6;
1966 }
1967#undef XPA_LVL_FREQ
1968}
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301969
Sujithf74df6f2009-02-09 13:27:24 +05301970static void ath9k_hw_get_def_gain_boundaries_pdadcs(struct ath_hw *ah,
1971 struct ath9k_channel *chan,
1972 struct cal_data_per_freq *pRawDataSet,
1973 u8 *bChans, u16 availPiers,
1974 u16 tPdGainOverlap, int16_t *pMinCalPower,
1975 u16 *pPdGainBoundaries, u8 *pPDADCValues,
1976 u16 numXpdGains)
1977{
1978 int i, j, k;
1979 int16_t ss;
1980 u16 idxL = 0, idxR = 0, numPiers;
1981 static u8 vpdTableL[AR5416_NUM_PD_GAINS]
1982 [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
1983 static u8 vpdTableR[AR5416_NUM_PD_GAINS]
1984 [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
1985 static u8 vpdTableI[AR5416_NUM_PD_GAINS]
1986 [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301987
Sujithf74df6f2009-02-09 13:27:24 +05301988 u8 *pVpdL, *pVpdR, *pPwrL, *pPwrR;
1989 u8 minPwrT4[AR5416_NUM_PD_GAINS];
1990 u8 maxPwrT4[AR5416_NUM_PD_GAINS];
1991 int16_t vpdStep;
1992 int16_t tmpVal;
1993 u16 sizeCurrVpdTable, maxIndex, tgtIndex;
1994 bool match;
1995 int16_t minDelta = 0;
1996 struct chan_centers centers;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301997
Sujithf74df6f2009-02-09 13:27:24 +05301998 ath9k_hw_get_channel_centers(ah, chan, &centers);
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05301999
Sujithf74df6f2009-02-09 13:27:24 +05302000 for (numPiers = 0; numPiers < availPiers; numPiers++) {
2001 if (bChans[numPiers] == AR5416_BCHAN_UNUSED)
2002 break;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302003 }
2004
Sujithf74df6f2009-02-09 13:27:24 +05302005 match = ath9k_hw_get_lower_upper_index((u8)FREQ2FBIN(centers.synth_center,
2006 IS_CHAN_2GHZ(chan)),
2007 bChans, numPiers, &idxL, &idxR);
2008
2009 if (match) {
2010 for (i = 0; i < numXpdGains; i++) {
2011 minPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][0];
2012 maxPwrT4[i] = pRawDataSet[idxL].pwrPdg[i][4];
2013 ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
2014 pRawDataSet[idxL].pwrPdg[i],
2015 pRawDataSet[idxL].vpdPdg[i],
2016 AR5416_PD_GAIN_ICEPTS,
2017 vpdTableI[i]);
2018 }
2019 } else {
2020 for (i = 0; i < numXpdGains; i++) {
2021 pVpdL = pRawDataSet[idxL].vpdPdg[i];
2022 pPwrL = pRawDataSet[idxL].pwrPdg[i];
2023 pVpdR = pRawDataSet[idxR].vpdPdg[i];
2024 pPwrR = pRawDataSet[idxR].pwrPdg[i];
2025
2026 minPwrT4[i] = max(pPwrL[0], pPwrR[0]);
2027
2028 maxPwrT4[i] =
2029 min(pPwrL[AR5416_PD_GAIN_ICEPTS - 1],
2030 pPwrR[AR5416_PD_GAIN_ICEPTS - 1]);
2031
2032
2033 ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
2034 pPwrL, pVpdL,
2035 AR5416_PD_GAIN_ICEPTS,
2036 vpdTableL[i]);
2037 ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
2038 pPwrR, pVpdR,
2039 AR5416_PD_GAIN_ICEPTS,
2040 vpdTableR[i]);
2041
2042 for (j = 0; j <= (maxPwrT4[i] - minPwrT4[i]) / 2; j++) {
2043 vpdTableI[i][j] =
2044 (u8)(ath9k_hw_interpolate((u16)
2045 FREQ2FBIN(centers.
2046 synth_center,
2047 IS_CHAN_2GHZ
2048 (chan)),
2049 bChans[idxL], bChans[idxR],
2050 vpdTableL[i][j], vpdTableR[i][j]));
2051 }
2052 }
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302053 }
2054
Sujithf74df6f2009-02-09 13:27:24 +05302055 *pMinCalPower = (int16_t)(minPwrT4[0] / 2);
2056
2057 k = 0;
2058
2059 for (i = 0; i < numXpdGains; i++) {
2060 if (i == (numXpdGains - 1))
2061 pPdGainBoundaries[i] =
2062 (u16)(maxPwrT4[i] / 2);
2063 else
2064 pPdGainBoundaries[i] =
2065 (u16)((maxPwrT4[i] + minPwrT4[i + 1]) / 4);
2066
2067 pPdGainBoundaries[i] =
2068 min((u16)AR5416_MAX_RATE_POWER, pPdGainBoundaries[i]);
2069
Gabor Juhosa8c96d32009-03-06 09:08:51 +01002070 if ((i == 0) && !AR_SREV_5416_20_OR_LATER(ah)) {
Sujithf74df6f2009-02-09 13:27:24 +05302071 minDelta = pPdGainBoundaries[0] - 23;
2072 pPdGainBoundaries[0] = 23;
2073 } else {
2074 minDelta = 0;
2075 }
2076
2077 if (i == 0) {
2078 if (AR_SREV_9280_10_OR_LATER(ah))
2079 ss = (int16_t)(0 - (minPwrT4[i] / 2));
2080 else
2081 ss = 0;
2082 } else {
2083 ss = (int16_t)((pPdGainBoundaries[i - 1] -
2084 (minPwrT4[i] / 2)) -
2085 tPdGainOverlap + 1 + minDelta);
2086 }
2087 vpdStep = (int16_t)(vpdTableI[i][1] - vpdTableI[i][0]);
2088 vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
2089
2090 while ((ss < 0) && (k < (AR5416_NUM_PDADC_VALUES - 1))) {
2091 tmpVal = (int16_t)(vpdTableI[i][0] + ss * vpdStep);
2092 pPDADCValues[k++] = (u8)((tmpVal < 0) ? 0 : tmpVal);
2093 ss++;
2094 }
2095
2096 sizeCurrVpdTable = (u8) ((maxPwrT4[i] - minPwrT4[i]) / 2 + 1);
2097 tgtIndex = (u8)(pPdGainBoundaries[i] + tPdGainOverlap -
2098 (minPwrT4[i] / 2));
2099 maxIndex = (tgtIndex < sizeCurrVpdTable) ?
2100 tgtIndex : sizeCurrVpdTable;
2101
2102 while ((ss < maxIndex) && (k < (AR5416_NUM_PDADC_VALUES - 1))) {
2103 pPDADCValues[k++] = vpdTableI[i][ss++];
2104 }
2105
2106 vpdStep = (int16_t)(vpdTableI[i][sizeCurrVpdTable - 1] -
2107 vpdTableI[i][sizeCurrVpdTable - 2]);
2108 vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
2109
2110 if (tgtIndex > maxIndex) {
2111 while ((ss <= tgtIndex) &&
2112 (k < (AR5416_NUM_PDADC_VALUES - 1))) {
2113 tmpVal = (int16_t)((vpdTableI[i][sizeCurrVpdTable - 1] +
2114 (ss - maxIndex + 1) * vpdStep));
2115 pPDADCValues[k++] = (u8)((tmpVal > 255) ?
2116 255 : tmpVal);
2117 ss++;
2118 }
2119 }
2120 }
2121
2122 while (i < AR5416_PD_GAINS_IN_MASK) {
2123 pPdGainBoundaries[i] = pPdGainBoundaries[i - 1];
2124 i++;
2125 }
2126
2127 while (k < AR5416_NUM_PDADC_VALUES) {
2128 pPDADCValues[k] = pPDADCValues[k - 1];
2129 k++;
2130 }
2131
2132 return;
2133}
2134
2135static bool ath9k_hw_set_def_power_cal_table(struct ath_hw *ah,
2136 struct ath9k_channel *chan,
2137 int16_t *pTxPowerIndexOffset)
2138{
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05302139#define SM_PD_GAIN(x) SM(0x38, AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_##x)
2140#define SM_PDGAIN_B(x, y) \
2141 SM((gainBoundaries[x]), AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_##y)
2142
Sujith2660b812009-02-09 13:27:26 +05302143 struct ar5416_eeprom_def *pEepData = &ah->eeprom.def;
Sujithf74df6f2009-02-09 13:27:24 +05302144 struct cal_data_per_freq *pRawDataset;
2145 u8 *pCalBChans = NULL;
2146 u16 pdGainOverlap_t2;
2147 static u8 pdadcValues[AR5416_NUM_PDADC_VALUES];
2148 u16 gainBoundaries[AR5416_PD_GAINS_IN_MASK];
2149 u16 numPiers, i, j;
2150 int16_t tMinCalPower;
2151 u16 numXpdGain, xpdMask;
2152 u16 xpdGainValues[AR5416_NUM_PD_GAINS] = { 0, 0, 0, 0 };
2153 u32 reg32, regOffset, regChainOffset;
2154 int16_t modalIdx;
2155
2156 modalIdx = IS_CHAN_2GHZ(chan) ? 1 : 0;
2157 xpdMask = pEepData->modalHeader[modalIdx].xpdGain;
2158
2159 if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
2160 AR5416_EEP_MINOR_VER_2) {
2161 pdGainOverlap_t2 =
2162 pEepData->modalHeader[modalIdx].pdGainOverlap;
2163 } else {
2164 pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5),
2165 AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
2166 }
2167
2168 if (IS_CHAN_2GHZ(chan)) {
2169 pCalBChans = pEepData->calFreqPier2G;
2170 numPiers = AR5416_NUM_2G_CAL_PIERS;
2171 } else {
2172 pCalBChans = pEepData->calFreqPier5G;
2173 numPiers = AR5416_NUM_5G_CAL_PIERS;
2174 }
2175
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05302176 if (OLC_FOR_AR9280_20_LATER && IS_CHAN_2GHZ(chan)) {
2177 pRawDataset = pEepData->calPierData2G[0];
2178 ah->initPDADC = ((struct calDataPerFreqOpLoop *)
2179 pRawDataset)->vpdPdg[0][0];
2180 }
2181
Sujithf74df6f2009-02-09 13:27:24 +05302182 numXpdGain = 0;
2183
2184 for (i = 1; i <= AR5416_PD_GAINS_IN_MASK; i++) {
2185 if ((xpdMask >> (AR5416_PD_GAINS_IN_MASK - i)) & 1) {
2186 if (numXpdGain >= AR5416_NUM_PD_GAINS)
2187 break;
2188 xpdGainValues[numXpdGain] =
2189 (u16)(AR5416_PD_GAINS_IN_MASK - i);
2190 numXpdGain++;
2191 }
2192 }
2193
2194 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
2195 (numXpdGain - 1) & 0x3);
2196 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,
2197 xpdGainValues[0]);
2198 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
2199 xpdGainValues[1]);
2200 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3,
2201 xpdGainValues[2]);
2202
2203 for (i = 0; i < AR5416_MAX_CHAINS; i++) {
Gabor Juhosa8c96d32009-03-06 09:08:51 +01002204 if (AR_SREV_5416_20_OR_LATER(ah) &&
Sujith2660b812009-02-09 13:27:26 +05302205 (ah->rxchainmask == 5 || ah->txchainmask == 5) &&
Sujithf74df6f2009-02-09 13:27:24 +05302206 (i != 0)) {
2207 regChainOffset = (i == 1) ? 0x2000 : 0x1000;
2208 } else
2209 regChainOffset = i * 0x1000;
2210
2211 if (pEepData->baseEepHeader.txMask & (1 << i)) {
2212 if (IS_CHAN_2GHZ(chan))
2213 pRawDataset = pEepData->calPierData2G[i];
2214 else
2215 pRawDataset = pEepData->calPierData5G[i];
2216
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05302217
2218 if (OLC_FOR_AR9280_20_LATER) {
2219 u8 pcdacIdx;
2220 u8 txPower;
2221
2222 ath9k_get_txgain_index(ah, chan,
2223 (struct calDataPerFreqOpLoop *)pRawDataset,
2224 pCalBChans, numPiers, &txPower, &pcdacIdx);
2225 ath9k_olc_get_pdadcs(ah, pcdacIdx,
2226 txPower/2, pdadcValues);
2227 } else {
2228 ath9k_hw_get_def_gain_boundaries_pdadcs(ah,
2229 chan, pRawDataset,
2230 pCalBChans, numPiers,
2231 pdGainOverlap_t2,
2232 &tMinCalPower,
2233 gainBoundaries,
2234 pdadcValues,
2235 numXpdGain);
2236 }
Sujithf74df6f2009-02-09 13:27:24 +05302237
Gabor Juhosa8c96d32009-03-06 09:08:51 +01002238 if ((i == 0) || AR_SREV_5416_20_OR_LATER(ah)) {
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05302239 if (OLC_FOR_AR9280_20_LATER) {
2240 REG_WRITE(ah,
2241 AR_PHY_TPCRG5 + regChainOffset,
2242 SM(0x6,
2243 AR_PHY_TPCRG5_PD_GAIN_OVERLAP) |
2244 SM_PD_GAIN(1) | SM_PD_GAIN(2) |
2245 SM_PD_GAIN(3) | SM_PD_GAIN(4));
2246 } else {
2247 REG_WRITE(ah,
2248 AR_PHY_TPCRG5 + regChainOffset,
2249 SM(pdGainOverlap_t2,
2250 AR_PHY_TPCRG5_PD_GAIN_OVERLAP)|
2251 SM_PDGAIN_B(0, 1) |
2252 SM_PDGAIN_B(1, 2) |
2253 SM_PDGAIN_B(2, 3) |
2254 SM_PDGAIN_B(3, 4));
2255 }
Sujithf74df6f2009-02-09 13:27:24 +05302256 }
2257
2258 regOffset = AR_PHY_BASE + (672 << 2) + regChainOffset;
2259 for (j = 0; j < 32; j++) {
2260 reg32 = ((pdadcValues[4 * j + 0] & 0xFF) << 0) |
2261 ((pdadcValues[4 * j + 1] & 0xFF) << 8) |
2262 ((pdadcValues[4 * j + 2] & 0xFF) << 16)|
2263 ((pdadcValues[4 * j + 3] & 0xFF) << 24);
2264 REG_WRITE(ah, regOffset, reg32);
2265
2266 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
2267 "PDADC (%d,%4x): %4.4x %8.8x\n",
2268 i, regChainOffset, regOffset,
2269 reg32);
2270 DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
2271 "PDADC: Chain %d | PDADC %3d "
2272 "Value %3d | PDADC %3d Value %3d | "
2273 "PDADC %3d Value %3d | PDADC %3d "
2274 "Value %3d |\n",
2275 i, 4 * j, pdadcValues[4 * j],
2276 4 * j + 1, pdadcValues[4 * j + 1],
2277 4 * j + 2, pdadcValues[4 * j + 2],
2278 4 * j + 3,
2279 pdadcValues[4 * j + 3]);
2280
2281 regOffset += 4;
2282 }
2283 }
2284 }
2285
2286 *pTxPowerIndexOffset = 0;
2287
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302288 return true;
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05302289#undef SM_PD_GAIN
2290#undef SM_PDGAIN_B
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302291}
2292
Sujithf74df6f2009-02-09 13:27:24 +05302293static bool ath9k_hw_set_def_power_per_rate_table(struct ath_hw *ah,
2294 struct ath9k_channel *chan,
2295 int16_t *ratesArray,
2296 u16 cfgCtl,
2297 u16 AntennaReduction,
2298 u16 twiceMaxRegulatoryPower,
2299 u16 powerLimit)
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302300{
Sujithf74df6f2009-02-09 13:27:24 +05302301#define REDUCE_SCALED_POWER_BY_TWO_CHAIN 6 /* 10*log10(2)*2 */
2302#define REDUCE_SCALED_POWER_BY_THREE_CHAIN 10 /* 10*log10(3)*2 */
2303
Sujith2660b812009-02-09 13:27:26 +05302304 struct ar5416_eeprom_def *pEepData = &ah->eeprom.def;
Sujithf74df6f2009-02-09 13:27:24 +05302305 u16 twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
2306 static const u16 tpScaleReductionTable[5] =
2307 { 0, 3, 6, 9, AR5416_MAX_RATE_POWER };
2308
2309 int i;
2310 int16_t twiceLargestAntenna;
2311 struct cal_ctl_data *rep;
2312 struct cal_target_power_leg targetPowerOfdm, targetPowerCck = {
2313 0, { 0, 0, 0, 0}
2314 };
2315 struct cal_target_power_leg targetPowerOfdmExt = {
2316 0, { 0, 0, 0, 0} }, targetPowerCckExt = {
2317 0, { 0, 0, 0, 0 }
2318 };
2319 struct cal_target_power_ht targetPowerHt20, targetPowerHt40 = {
2320 0, {0, 0, 0, 0}
2321 };
2322 u16 scaledPower = 0, minCtlPower, maxRegAllowedPower;
2323 u16 ctlModesFor11a[] =
2324 { CTL_11A, CTL_5GHT20, CTL_11A_EXT, CTL_5GHT40 };
2325 u16 ctlModesFor11g[] =
2326 { CTL_11B, CTL_11G, CTL_2GHT20, CTL_11B_EXT, CTL_11G_EXT,
2327 CTL_2GHT40
2328 };
2329 u16 numCtlModes, *pCtlMode, ctlMode, freq;
2330 struct chan_centers centers;
2331 int tx_chainmask;
2332 u16 twiceMinEdgePower;
2333
Sujith2660b812009-02-09 13:27:26 +05302334 tx_chainmask = ah->txchainmask;
Sujithf74df6f2009-02-09 13:27:24 +05302335
2336 ath9k_hw_get_channel_centers(ah, chan, &centers);
2337
2338 twiceLargestAntenna = max(
2339 pEepData->modalHeader
2340 [IS_CHAN_2GHZ(chan)].antennaGainCh[0],
2341 pEepData->modalHeader
2342 [IS_CHAN_2GHZ(chan)].antennaGainCh[1]);
2343
2344 twiceLargestAntenna = max((u8)twiceLargestAntenna,
2345 pEepData->modalHeader
2346 [IS_CHAN_2GHZ(chan)].antennaGainCh[2]);
2347
2348 twiceLargestAntenna = (int16_t)min(AntennaReduction -
2349 twiceLargestAntenna, 0);
2350
2351 maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
2352
2353 if (ah->regulatory.tp_scale != ATH9K_TP_SCALE_MAX) {
2354 maxRegAllowedPower -=
2355 (tpScaleReductionTable[(ah->regulatory.tp_scale)] * 2);
2356 }
2357
2358 scaledPower = min(powerLimit, maxRegAllowedPower);
2359
2360 switch (ar5416_get_ntxchains(tx_chainmask)) {
2361 case 1:
2362 break;
2363 case 2:
2364 scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN;
2365 break;
2366 case 3:
2367 scaledPower -= REDUCE_SCALED_POWER_BY_THREE_CHAIN;
2368 break;
2369 }
2370
2371 scaledPower = max((u16)0, scaledPower);
2372
2373 if (IS_CHAN_2GHZ(chan)) {
2374 numCtlModes = ARRAY_SIZE(ctlModesFor11g) -
2375 SUB_NUM_CTL_MODES_AT_2G_40;
2376 pCtlMode = ctlModesFor11g;
2377
2378 ath9k_hw_get_legacy_target_powers(ah, chan,
2379 pEepData->calTargetPowerCck,
2380 AR5416_NUM_2G_CCK_TARGET_POWERS,
2381 &targetPowerCck, 4, false);
2382 ath9k_hw_get_legacy_target_powers(ah, chan,
2383 pEepData->calTargetPower2G,
2384 AR5416_NUM_2G_20_TARGET_POWERS,
2385 &targetPowerOfdm, 4, false);
2386 ath9k_hw_get_target_powers(ah, chan,
2387 pEepData->calTargetPower2GHT20,
2388 AR5416_NUM_2G_20_TARGET_POWERS,
2389 &targetPowerHt20, 8, false);
2390
2391 if (IS_CHAN_HT40(chan)) {
2392 numCtlModes = ARRAY_SIZE(ctlModesFor11g);
2393 ath9k_hw_get_target_powers(ah, chan,
2394 pEepData->calTargetPower2GHT40,
2395 AR5416_NUM_2G_40_TARGET_POWERS,
2396 &targetPowerHt40, 8, true);
2397 ath9k_hw_get_legacy_target_powers(ah, chan,
2398 pEepData->calTargetPowerCck,
2399 AR5416_NUM_2G_CCK_TARGET_POWERS,
2400 &targetPowerCckExt, 4, true);
2401 ath9k_hw_get_legacy_target_powers(ah, chan,
2402 pEepData->calTargetPower2G,
2403 AR5416_NUM_2G_20_TARGET_POWERS,
2404 &targetPowerOfdmExt, 4, true);
2405 }
2406 } else {
2407 numCtlModes = ARRAY_SIZE(ctlModesFor11a) -
2408 SUB_NUM_CTL_MODES_AT_5G_40;
2409 pCtlMode = ctlModesFor11a;
2410
2411 ath9k_hw_get_legacy_target_powers(ah, chan,
2412 pEepData->calTargetPower5G,
2413 AR5416_NUM_5G_20_TARGET_POWERS,
2414 &targetPowerOfdm, 4, false);
2415 ath9k_hw_get_target_powers(ah, chan,
2416 pEepData->calTargetPower5GHT20,
2417 AR5416_NUM_5G_20_TARGET_POWERS,
2418 &targetPowerHt20, 8, false);
2419
2420 if (IS_CHAN_HT40(chan)) {
2421 numCtlModes = ARRAY_SIZE(ctlModesFor11a);
2422 ath9k_hw_get_target_powers(ah, chan,
2423 pEepData->calTargetPower5GHT40,
2424 AR5416_NUM_5G_40_TARGET_POWERS,
2425 &targetPowerHt40, 8, true);
2426 ath9k_hw_get_legacy_target_powers(ah, chan,
2427 pEepData->calTargetPower5G,
2428 AR5416_NUM_5G_20_TARGET_POWERS,
2429 &targetPowerOfdmExt, 4, true);
2430 }
2431 }
2432
2433 for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
2434 bool isHt40CtlMode = (pCtlMode[ctlMode] == CTL_5GHT40) ||
2435 (pCtlMode[ctlMode] == CTL_2GHT40);
2436 if (isHt40CtlMode)
2437 freq = centers.synth_center;
2438 else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
2439 freq = centers.ext_center;
2440 else
2441 freq = centers.ctl_center;
2442
2443 if (ah->eep_ops->get_eeprom_ver(ah) == 14 &&
2444 ah->eep_ops->get_eeprom_rev(ah) <= 2)
2445 twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
2446
2447 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
2448 "LOOP-Mode ctlMode %d < %d, isHt40CtlMode %d, "
2449 "EXT_ADDITIVE %d\n",
2450 ctlMode, numCtlModes, isHt40CtlMode,
2451 (pCtlMode[ctlMode] & EXT_ADDITIVE));
2452
2453 for (i = 0; (i < AR5416_NUM_CTLS) && pEepData->ctlIndex[i]; i++) {
2454 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
2455 " LOOP-Ctlidx %d: cfgCtl 0x%2.2x "
2456 "pCtlMode 0x%2.2x ctlIndex 0x%2.2x "
2457 "chan %d\n",
2458 i, cfgCtl, pCtlMode[ctlMode],
2459 pEepData->ctlIndex[i], chan->channel);
2460
2461 if ((((cfgCtl & ~CTL_MODE_M) |
2462 (pCtlMode[ctlMode] & CTL_MODE_M)) ==
2463 pEepData->ctlIndex[i]) ||
2464 (((cfgCtl & ~CTL_MODE_M) |
2465 (pCtlMode[ctlMode] & CTL_MODE_M)) ==
2466 ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL))) {
2467 rep = &(pEepData->ctlData[i]);
2468
2469 twiceMinEdgePower = ath9k_hw_get_max_edge_power(freq,
2470 rep->ctlEdges[ar5416_get_ntxchains(tx_chainmask) - 1],
2471 IS_CHAN_2GHZ(chan), AR5416_NUM_BAND_EDGES);
2472
2473 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
2474 " MATCH-EE_IDX %d: ch %d is2 %d "
2475 "2xMinEdge %d chainmask %d chains %d\n",
2476 i, freq, IS_CHAN_2GHZ(chan),
2477 twiceMinEdgePower, tx_chainmask,
2478 ar5416_get_ntxchains
2479 (tx_chainmask));
2480 if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {
2481 twiceMaxEdgePower = min(twiceMaxEdgePower,
2482 twiceMinEdgePower);
2483 } else {
2484 twiceMaxEdgePower = twiceMinEdgePower;
2485 break;
2486 }
2487 }
2488 }
2489
2490 minCtlPower = min(twiceMaxEdgePower, scaledPower);
2491
2492 DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
2493 " SEL-Min ctlMode %d pCtlMode %d "
2494 "2xMaxEdge %d sP %d minCtlPwr %d\n",
2495 ctlMode, pCtlMode[ctlMode], twiceMaxEdgePower,
2496 scaledPower, minCtlPower);
2497
2498 switch (pCtlMode[ctlMode]) {
2499 case CTL_11B:
2500 for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x); i++) {
2501 targetPowerCck.tPow2x[i] =
2502 min((u16)targetPowerCck.tPow2x[i],
2503 minCtlPower);
2504 }
2505 break;
2506 case CTL_11A:
2507 case CTL_11G:
2508 for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x); i++) {
2509 targetPowerOfdm.tPow2x[i] =
2510 min((u16)targetPowerOfdm.tPow2x[i],
2511 minCtlPower);
2512 }
2513 break;
2514 case CTL_5GHT20:
2515 case CTL_2GHT20:
2516 for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) {
2517 targetPowerHt20.tPow2x[i] =
2518 min((u16)targetPowerHt20.tPow2x[i],
2519 minCtlPower);
2520 }
2521 break;
2522 case CTL_11B_EXT:
2523 targetPowerCckExt.tPow2x[0] = min((u16)
2524 targetPowerCckExt.tPow2x[0],
2525 minCtlPower);
2526 break;
2527 case CTL_11A_EXT:
2528 case CTL_11G_EXT:
2529 targetPowerOfdmExt.tPow2x[0] = min((u16)
2530 targetPowerOfdmExt.tPow2x[0],
2531 minCtlPower);
2532 break;
2533 case CTL_5GHT40:
2534 case CTL_2GHT40:
2535 for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
2536 targetPowerHt40.tPow2x[i] =
2537 min((u16)targetPowerHt40.tPow2x[i],
2538 minCtlPower);
2539 }
2540 break;
2541 default:
2542 break;
2543 }
2544 }
2545
2546 ratesArray[rate6mb] = ratesArray[rate9mb] = ratesArray[rate12mb] =
2547 ratesArray[rate18mb] = ratesArray[rate24mb] =
2548 targetPowerOfdm.tPow2x[0];
2549 ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1];
2550 ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2];
2551 ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3];
2552 ratesArray[rateXr] = targetPowerOfdm.tPow2x[0];
2553
2554 for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++)
2555 ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i];
2556
2557 if (IS_CHAN_2GHZ(chan)) {
2558 ratesArray[rate1l] = targetPowerCck.tPow2x[0];
2559 ratesArray[rate2s] = ratesArray[rate2l] =
2560 targetPowerCck.tPow2x[1];
2561 ratesArray[rate5_5s] = ratesArray[rate5_5l] =
2562 targetPowerCck.tPow2x[2];
2563 ;
2564 ratesArray[rate11s] = ratesArray[rate11l] =
2565 targetPowerCck.tPow2x[3];
2566 ;
2567 }
2568 if (IS_CHAN_HT40(chan)) {
2569 for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
2570 ratesArray[rateHt40_0 + i] =
2571 targetPowerHt40.tPow2x[i];
2572 }
2573 ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0];
2574 ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0];
2575 ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0];
2576 if (IS_CHAN_2GHZ(chan)) {
2577 ratesArray[rateExtCck] =
2578 targetPowerCckExt.tPow2x[0];
2579 }
2580 }
2581 return true;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302582}
2583
Sujithf74df6f2009-02-09 13:27:24 +05302584static int ath9k_hw_def_set_txpower(struct ath_hw *ah,
2585 struct ath9k_channel *chan,
2586 u16 cfgCtl,
2587 u8 twiceAntennaReduction,
2588 u8 twiceMaxRegulatoryPower,
2589 u8 powerLimit)
Sujithf1dc5602008-10-29 10:16:30 +05302590{
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05302591#define RT_AR_DELTA(x) (ratesArray[x] - cck_ofdm_delta)
Sujith2660b812009-02-09 13:27:26 +05302592 struct ar5416_eeprom_def *pEepData = &ah->eeprom.def;
Sujithf1dc5602008-10-29 10:16:30 +05302593 struct modal_eep_header *pModal =
Sujithf74df6f2009-02-09 13:27:24 +05302594 &(pEepData->modalHeader[IS_CHAN_2GHZ(chan)]);
2595 int16_t ratesArray[Ar5416RateSize];
2596 int16_t txPowerIndexOffset = 0;
2597 u8 ht40PowerIncForPdadc = 2;
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05302598 int i, cck_ofdm_delta = 0;
Sujithf1dc5602008-10-29 10:16:30 +05302599
Sujithf74df6f2009-02-09 13:27:24 +05302600 memset(ratesArray, 0, sizeof(ratesArray));
2601
2602 if ((pEepData->baseEepHeader.version & AR5416_EEP_VER_MINOR_MASK) >=
2603 AR5416_EEP_MINOR_VER_2) {
2604 ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
2605 }
2606
2607 if (!ath9k_hw_set_def_power_per_rate_table(ah, chan,
2608 &ratesArray[0], cfgCtl,
2609 twiceAntennaReduction,
2610 twiceMaxRegulatoryPower,
2611 powerLimit)) {
2612 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
2613 "ath9k_hw_set_txpower: unable to set "
2614 "tx power per rate table\n");
2615 return -EIO;
2616 }
2617
2618 if (!ath9k_hw_set_def_power_cal_table(ah, chan, &txPowerIndexOffset)) {
2619 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
2620 "ath9k_hw_set_txpower: unable to set power table\n");
2621 return -EIO;
2622 }
2623
2624 for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
2625 ratesArray[i] = (int16_t)(txPowerIndexOffset + ratesArray[i]);
2626 if (ratesArray[i] > AR5416_MAX_RATE_POWER)
2627 ratesArray[i] = AR5416_MAX_RATE_POWER;
2628 }
2629
2630 if (AR_SREV_9280_10_OR_LATER(ah)) {
2631 for (i = 0; i < Ar5416RateSize; i++)
2632 ratesArray[i] -= AR5416_PWR_TABLE_OFFSET * 2;
2633 }
2634
2635 REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
2636 ATH9K_POW_SM(ratesArray[rate18mb], 24)
2637 | ATH9K_POW_SM(ratesArray[rate12mb], 16)
2638 | ATH9K_POW_SM(ratesArray[rate9mb], 8)
2639 | ATH9K_POW_SM(ratesArray[rate6mb], 0));
2640 REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
2641 ATH9K_POW_SM(ratesArray[rate54mb], 24)
2642 | ATH9K_POW_SM(ratesArray[rate48mb], 16)
2643 | ATH9K_POW_SM(ratesArray[rate36mb], 8)
2644 | ATH9K_POW_SM(ratesArray[rate24mb], 0));
2645
2646 if (IS_CHAN_2GHZ(chan)) {
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05302647 if (OLC_FOR_AR9280_20_LATER) {
2648 cck_ofdm_delta = 2;
2649 REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
2650 ATH9K_POW_SM(RT_AR_DELTA(rate2s), 24)
2651 | ATH9K_POW_SM(RT_AR_DELTA(rate2l), 16)
2652 | ATH9K_POW_SM(ratesArray[rateXr], 8)
2653 | ATH9K_POW_SM(RT_AR_DELTA(rate1l), 0));
2654 REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
2655 ATH9K_POW_SM(RT_AR_DELTA(rate11s), 24)
2656 | ATH9K_POW_SM(RT_AR_DELTA(rate11l), 16)
2657 | ATH9K_POW_SM(RT_AR_DELTA(rate5_5s), 8)
2658 | ATH9K_POW_SM(RT_AR_DELTA(rate5_5l), 0));
2659 } else {
2660 REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
2661 ATH9K_POW_SM(ratesArray[rate2s], 24)
2662 | ATH9K_POW_SM(ratesArray[rate2l], 16)
2663 | ATH9K_POW_SM(ratesArray[rateXr], 8)
2664 | ATH9K_POW_SM(ratesArray[rate1l], 0));
2665 REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
2666 ATH9K_POW_SM(ratesArray[rate11s], 24)
2667 | ATH9K_POW_SM(ratesArray[rate11l], 16)
2668 | ATH9K_POW_SM(ratesArray[rate5_5s], 8)
2669 | ATH9K_POW_SM(ratesArray[rate5_5l], 0));
2670 }
Sujithf74df6f2009-02-09 13:27:24 +05302671 }
2672
2673 REG_WRITE(ah, AR_PHY_POWER_TX_RATE5,
2674 ATH9K_POW_SM(ratesArray[rateHt20_3], 24)
2675 | ATH9K_POW_SM(ratesArray[rateHt20_2], 16)
2676 | ATH9K_POW_SM(ratesArray[rateHt20_1], 8)
2677 | ATH9K_POW_SM(ratesArray[rateHt20_0], 0));
2678 REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
2679 ATH9K_POW_SM(ratesArray[rateHt20_7], 24)
2680 | ATH9K_POW_SM(ratesArray[rateHt20_6], 16)
2681 | ATH9K_POW_SM(ratesArray[rateHt20_5], 8)
2682 | ATH9K_POW_SM(ratesArray[rateHt20_4], 0));
2683
2684 if (IS_CHAN_HT40(chan)) {
2685 REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
2686 ATH9K_POW_SM(ratesArray[rateHt40_3] +
2687 ht40PowerIncForPdadc, 24)
2688 | ATH9K_POW_SM(ratesArray[rateHt40_2] +
2689 ht40PowerIncForPdadc, 16)
2690 | ATH9K_POW_SM(ratesArray[rateHt40_1] +
2691 ht40PowerIncForPdadc, 8)
2692 | ATH9K_POW_SM(ratesArray[rateHt40_0] +
2693 ht40PowerIncForPdadc, 0));
2694 REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
2695 ATH9K_POW_SM(ratesArray[rateHt40_7] +
2696 ht40PowerIncForPdadc, 24)
2697 | ATH9K_POW_SM(ratesArray[rateHt40_6] +
2698 ht40PowerIncForPdadc, 16)
2699 | ATH9K_POW_SM(ratesArray[rateHt40_5] +
2700 ht40PowerIncForPdadc, 8)
2701 | ATH9K_POW_SM(ratesArray[rateHt40_4] +
2702 ht40PowerIncForPdadc, 0));
Senthil Balasubramanian8bd1d072009-02-12 13:57:03 +05302703 if (OLC_FOR_AR9280_20_LATER) {
2704 REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
2705 ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
2706 | ATH9K_POW_SM(RT_AR_DELTA(rateExtCck), 16)
2707 | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
2708 | ATH9K_POW_SM(RT_AR_DELTA(rateDupCck), 0));
2709 } else {
2710 REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
2711 ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
2712 | ATH9K_POW_SM(ratesArray[rateExtCck], 16)
2713 | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
2714 | ATH9K_POW_SM(ratesArray[rateDupCck], 0));
2715 }
Sujithf74df6f2009-02-09 13:27:24 +05302716 }
2717
2718 REG_WRITE(ah, AR_PHY_POWER_TX_SUB,
2719 ATH9K_POW_SM(pModal->pwrDecreaseFor3Chain, 6)
2720 | ATH9K_POW_SM(pModal->pwrDecreaseFor2Chain, 0));
2721
2722 i = rate6mb;
2723
2724 if (IS_CHAN_HT40(chan))
2725 i = rateHt40_0;
2726 else if (IS_CHAN_HT20(chan))
2727 i = rateHt20_0;
2728
2729 if (AR_SREV_9280_10_OR_LATER(ah))
2730 ah->regulatory.max_power_level =
2731 ratesArray[i] + AR5416_PWR_TABLE_OFFSET * 2;
2732 else
2733 ah->regulatory.max_power_level = ratesArray[i];
2734
Sujithe421c7b2009-02-12 10:06:36 +05302735 switch(ar5416_get_ntxchains(ah->txchainmask)) {
2736 case 1:
2737 break;
2738 case 2:
2739 ah->regulatory.max_power_level += INCREASE_MAXPOW_BY_TWO_CHAIN;
2740 break;
2741 case 3:
2742 ah->regulatory.max_power_level += INCREASE_MAXPOW_BY_THREE_CHAIN;
2743 break;
2744 default:
2745 DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
2746 "Invalid chainmask configuration\n");
2747 break;
2748 }
2749
Sujithf74df6f2009-02-09 13:27:24 +05302750 return 0;
Sujithf1dc5602008-10-29 10:16:30 +05302751}
2752
Sujithf74df6f2009-02-09 13:27:24 +05302753static u8 ath9k_hw_def_get_num_ant_config(struct ath_hw *ah,
Hannes Ederbf512bc2008-12-26 00:13:29 -08002754 enum ieee80211_band freq_band)
Sujithf1dc5602008-10-29 10:16:30 +05302755{
Sujith2660b812009-02-09 13:27:26 +05302756 struct ar5416_eeprom_def *eep = &ah->eeprom.def;
Sujithf1dc5602008-10-29 10:16:30 +05302757 struct modal_eep_header *pModal =
Senthil Balasubramanian2df1bff2008-12-08 19:43:49 +05302758 &(eep->modalHeader[ATH9K_HAL_FREQ_BAND_2GHZ == freq_band]);
Sujithf1dc5602008-10-29 10:16:30 +05302759 struct base_eep_header *pBase = &eep->baseEepHeader;
2760 u8 num_ant_config;
2761
2762 num_ant_config = 1;
2763
2764 if (pBase->version >= 0x0E0D)
2765 if (pModal->useAnt1)
2766 num_ant_config += 1;
2767
2768 return num_ant_config;
2769}
2770
Sujithf74df6f2009-02-09 13:27:24 +05302771static u16 ath9k_hw_def_get_eeprom_antenna_cfg(struct ath_hw *ah,
2772 struct ath9k_channel *chan)
Sujithf1dc5602008-10-29 10:16:30 +05302773{
Sujith2660b812009-02-09 13:27:26 +05302774 struct ar5416_eeprom_def *eep = &ah->eeprom.def;
Sujithf74df6f2009-02-09 13:27:24 +05302775 struct modal_eep_header *pModal =
2776 &(eep->modalHeader[IS_CHAN_2GHZ(chan)]);
2777
2778 return pModal->antCtrlCommon & 0xFFFF;
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302779}
2780
Hannes Eder93f726a2009-02-14 11:49:48 +00002781static u16 ath9k_hw_def_get_spur_channel(struct ath_hw *ah, u16 i, bool is2GHz)
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302782{
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302783#define EEP_DEF_SPURCHAN \
Sujith2660b812009-02-09 13:27:26 +05302784 (ah->eeprom.def.modalHeader[is2GHz].spurChans[i].spurChan)
Sujithf74df6f2009-02-09 13:27:24 +05302785
Sujithf1dc5602008-10-29 10:16:30 +05302786 u16 spur_val = AR_NO_SPUR;
2787
2788 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
2789 "Getting spur idx %d is2Ghz. %d val %x\n",
Sujith2660b812009-02-09 13:27:26 +05302790 i, is2GHz, ah->config.spurchans[i][is2GHz]);
Sujithf1dc5602008-10-29 10:16:30 +05302791
Sujith2660b812009-02-09 13:27:26 +05302792 switch (ah->config.spurmode) {
Sujithf1dc5602008-10-29 10:16:30 +05302793 case SPUR_DISABLE:
2794 break;
2795 case SPUR_ENABLE_IOCTL:
Sujith2660b812009-02-09 13:27:26 +05302796 spur_val = ah->config.spurchans[i][is2GHz];
Sujithf1dc5602008-10-29 10:16:30 +05302797 DPRINTF(ah->ah_sc, ATH_DBG_ANI,
2798 "Getting spur val from new loc. %d\n", spur_val);
2799 break;
2800 case SPUR_ENABLE_EEPROM:
Sujithf74df6f2009-02-09 13:27:24 +05302801 spur_val = EEP_DEF_SPURCHAN;
Sujithf1dc5602008-10-29 10:16:30 +05302802 break;
Sujithf1dc5602008-10-29 10:16:30 +05302803 }
2804
2805 return spur_val;
Sujithf74df6f2009-02-09 13:27:24 +05302806
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302807#undef EEP_DEF_SPURCHAN
Sujithf1dc5602008-10-29 10:16:30 +05302808}
2809
Hannes Eder93f726a2009-02-14 11:49:48 +00002810static struct eeprom_ops eep_def_ops = {
Sujithf74df6f2009-02-09 13:27:24 +05302811 .check_eeprom = ath9k_hw_def_check_eeprom,
2812 .get_eeprom = ath9k_hw_def_get_eeprom,
2813 .fill_eeprom = ath9k_hw_def_fill_eeprom,
2814 .get_eeprom_ver = ath9k_hw_def_get_eeprom_ver,
2815 .get_eeprom_rev = ath9k_hw_def_get_eeprom_rev,
2816 .get_num_ant_config = ath9k_hw_def_get_num_ant_config,
2817 .get_eeprom_antenna_cfg = ath9k_hw_def_get_eeprom_antenna_cfg,
2818 .set_board_values = ath9k_hw_def_set_board_values,
2819 .set_addac = ath9k_hw_def_set_addac,
2820 .set_txpower = ath9k_hw_def_set_txpower,
2821 .get_spur_channel = ath9k_hw_def_get_spur_channel
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302822};
2823
Sujithcbe61d82009-02-09 13:27:12 +05302824int ath9k_hw_eeprom_attach(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +05302825{
2826 int status;
2827
Sujithf74df6f2009-02-09 13:27:24 +05302828 if (AR_SREV_9285(ah)) {
Sujith2660b812009-02-09 13:27:26 +05302829 ah->eep_map = EEP_MAP_4KBITS;
Sujithf74df6f2009-02-09 13:27:24 +05302830 ah->eep_ops = &eep_4k_ops;
2831 } else {
Sujith2660b812009-02-09 13:27:26 +05302832 ah->eep_map = EEP_MAP_DEFAULT;
Sujithf74df6f2009-02-09 13:27:24 +05302833 ah->eep_ops = &eep_def_ops;
2834 }
Senthil Balasubramaniane7594072008-12-08 19:43:48 +05302835
Sujithf74df6f2009-02-09 13:27:24 +05302836 if (!ah->eep_ops->fill_eeprom(ah))
Sujithf1dc5602008-10-29 10:16:30 +05302837 return -EIO;
2838
Sujithf74df6f2009-02-09 13:27:24 +05302839 status = ah->eep_ops->check_eeprom(ah);
Sujithf1dc5602008-10-29 10:16:30 +05302840
2841 return status;
2842}