blob: 9457825c2c7cd9ecefb51255da34654a7cb6da08 [file] [log] [blame]
Sujithf1dc5602008-10-29 10:16:30 +05301/*
Sujith Manoharan5b681382011-05-17 13:36:18 +05302 * Copyright (c) 2008-2011 Atheros Communications Inc.
Sujithf1dc5602008-10-29 10:16:30 +05303 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
Luis R. Rodriguez5bb12792009-09-14 00:55:09 -070017#include "hw.h"
Sujithf1dc5602008-10-29 10:16:30 +053018
Sujithb5aec952009-08-07 09:45:15 +053019static inline u16 ath9k_hw_fbin2freq(u8 fbin, bool is2GHz)
20{
21 if (fbin == AR5416_BCHAN_UNUSED)
22 return fbin;
23
24 return (u16) ((is2GHz) ? (2300 + fbin) : (4800 + 5 * fbin));
25}
26
Sujith79d7f4b2010-06-01 15:14:06 +053027void ath9k_hw_analog_shift_regwrite(struct ath_hw *ah, u32 reg, u32 val)
28{
29 REG_WRITE(ah, reg, val);
30
31 if (ah->config.analog_shiftreg)
32 udelay(100);
33}
34
Sujithb5aec952009-08-07 09:45:15 +053035void ath9k_hw_analog_shift_rmw(struct ath_hw *ah, u32 reg, u32 mask,
36 u32 shift, u32 val)
Sujithf1dc5602008-10-29 10:16:30 +053037{
38 u32 regVal;
39
40 regVal = REG_READ(ah, reg) & ~mask;
41 regVal |= (val << shift) & mask;
42
43 REG_WRITE(ah, reg, regVal);
44
Sujith2660b812009-02-09 13:27:26 +053045 if (ah->config.analog_shiftreg)
Sujithf1dc5602008-10-29 10:16:30 +053046 udelay(100);
Sujithf1dc5602008-10-29 10:16:30 +053047}
48
Sujithb5aec952009-08-07 09:45:15 +053049int16_t ath9k_hw_interpolate(u16 target, u16 srcLeft, u16 srcRight,
50 int16_t targetLeft, int16_t targetRight)
Sujithf1dc5602008-10-29 10:16:30 +053051{
52 int16_t rv;
53
54 if (srcRight == srcLeft) {
55 rv = targetLeft;
56 } else {
57 rv = (int16_t) (((target - srcLeft) * targetRight +
58 (srcRight - target) * targetLeft) /
59 (srcRight - srcLeft));
60 }
61 return rv;
62}
63
Sujithb5aec952009-08-07 09:45:15 +053064bool ath9k_hw_get_lower_upper_index(u8 target, u8 *pList, u16 listSize,
65 u16 *indexL, u16 *indexR)
Sujithf1dc5602008-10-29 10:16:30 +053066{
67 u16 i;
68
69 if (target <= pList[0]) {
70 *indexL = *indexR = 0;
71 return true;
72 }
73 if (target >= pList[listSize - 1]) {
74 *indexL = *indexR = (u16) (listSize - 1);
75 return true;
76 }
77
78 for (i = 0; i < listSize - 1; i++) {
79 if (pList[i] == target) {
80 *indexL = *indexR = i;
81 return true;
82 }
83 if (target < pList[i + 1]) {
84 *indexL = i;
85 *indexR = (u16) (i + 1);
86 return false;
87 }
88 }
89 return false;
90}
91
Sujith Manoharan04cf53f2011-01-04 13:17:28 +053092void ath9k_hw_usb_gen_fill_eeprom(struct ath_hw *ah, u16 *eep_data,
93 int eep_start_loc, int size)
94{
95 int i = 0, j, addr;
96 u32 addrdata[8];
97 u32 data[8];
98
99 for (addr = 0; addr < size; addr++) {
100 addrdata[i] = AR5416_EEPROM_OFFSET +
101 ((addr + eep_start_loc) << AR5416_EEPROM_S);
102 i++;
103 if (i == 8) {
104 REG_READ_MULTI(ah, addrdata, data, i);
105
106 for (j = 0; j < i; j++) {
107 *eep_data = data[j];
108 eep_data++;
109 }
110 i = 0;
111 }
112 }
113
114 if (i != 0) {
115 REG_READ_MULTI(ah, addrdata, data, i);
116
117 for (j = 0; j < i; j++) {
118 *eep_data = data[j];
119 eep_data++;
120 }
121 }
122}
123
Luis R. Rodriguez5bb12792009-09-14 00:55:09 -0700124bool ath9k_hw_nvram_read(struct ath_common *common, u32 off, u16 *data)
Sujithf1dc5602008-10-29 10:16:30 +0530125{
Luis R. Rodriguez5bb12792009-09-14 00:55:09 -0700126 return common->bus_ops->eeprom_read(common, off, data);
Sujithf1dc5602008-10-29 10:16:30 +0530127}
128
Sujithb5aec952009-08-07 09:45:15 +0530129void ath9k_hw_fill_vpd_table(u8 pwrMin, u8 pwrMax, u8 *pPwrList,
130 u8 *pVpdList, u16 numIntercepts,
131 u8 *pRetVpdList)
Sujithf74df6f2009-02-09 13:27:24 +0530132{
133 u16 i, k;
134 u8 currPwr = pwrMin;
135 u16 idxL = 0, idxR = 0;
136
137 for (i = 0; i <= (pwrMax - pwrMin) / 2; i++) {
138 ath9k_hw_get_lower_upper_index(currPwr, pPwrList,
139 numIntercepts, &(idxL),
140 &(idxR));
141 if (idxR < 1)
142 idxR = 1;
143 if (idxL == numIntercepts - 1)
144 idxL = (u16) (numIntercepts - 2);
145 if (pPwrList[idxL] == pPwrList[idxR])
146 k = pVpdList[idxL];
147 else
148 k = (u16)(((currPwr - pPwrList[idxL]) * pVpdList[idxR] +
149 (pPwrList[idxR] - currPwr) * pVpdList[idxL]) /
150 (pPwrList[idxR] - pPwrList[idxL]));
151 pRetVpdList[i] = (u8) k;
152 currPwr += 2;
153 }
Sujithf74df6f2009-02-09 13:27:24 +0530154}
155
Sujithb5aec952009-08-07 09:45:15 +0530156void ath9k_hw_get_legacy_target_powers(struct ath_hw *ah,
157 struct ath9k_channel *chan,
158 struct cal_target_power_leg *powInfo,
159 u16 numChannels,
160 struct cal_target_power_leg *pNewPower,
161 u16 numRates, bool isExtTarget)
Sujithf74df6f2009-02-09 13:27:24 +0530162{
163 struct chan_centers centers;
164 u16 clo, chi;
165 int i;
166 int matchIndex = -1, lowIndex = -1;
167 u16 freq;
168
169 ath9k_hw_get_channel_centers(ah, chan, &centers);
170 freq = (isExtTarget) ? centers.ext_center : centers.ctl_center;
171
172 if (freq <= ath9k_hw_fbin2freq(powInfo[0].bChannel,
173 IS_CHAN_2GHZ(chan))) {
174 matchIndex = 0;
175 } else {
176 for (i = 0; (i < numChannels) &&
177 (powInfo[i].bChannel != AR5416_BCHAN_UNUSED); i++) {
178 if (freq == ath9k_hw_fbin2freq(powInfo[i].bChannel,
179 IS_CHAN_2GHZ(chan))) {
180 matchIndex = i;
181 break;
Roel Kluin73f57f82009-08-07 23:50:00 +0200182 } else if (freq < ath9k_hw_fbin2freq(powInfo[i].bChannel,
183 IS_CHAN_2GHZ(chan)) && i > 0 &&
184 freq > ath9k_hw_fbin2freq(powInfo[i - 1].bChannel,
185 IS_CHAN_2GHZ(chan))) {
Sujithf74df6f2009-02-09 13:27:24 +0530186 lowIndex = i - 1;
187 break;
188 }
189 }
190 if ((matchIndex == -1) && (lowIndex == -1))
191 matchIndex = i - 1;
192 }
193
194 if (matchIndex != -1) {
195 *pNewPower = powInfo[matchIndex];
196 } else {
197 clo = ath9k_hw_fbin2freq(powInfo[lowIndex].bChannel,
198 IS_CHAN_2GHZ(chan));
199 chi = ath9k_hw_fbin2freq(powInfo[lowIndex + 1].bChannel,
200 IS_CHAN_2GHZ(chan));
201
202 for (i = 0; i < numRates; i++) {
203 pNewPower->tPow2x[i] =
204 (u8)ath9k_hw_interpolate(freq, clo, chi,
205 powInfo[lowIndex].tPow2x[i],
206 powInfo[lowIndex + 1].tPow2x[i]);
207 }
208 }
209}
210
Sujithb5aec952009-08-07 09:45:15 +0530211void ath9k_hw_get_target_powers(struct ath_hw *ah,
212 struct ath9k_channel *chan,
213 struct cal_target_power_ht *powInfo,
214 u16 numChannels,
215 struct cal_target_power_ht *pNewPower,
216 u16 numRates, bool isHt40Target)
Sujithf74df6f2009-02-09 13:27:24 +0530217{
218 struct chan_centers centers;
219 u16 clo, chi;
220 int i;
221 int matchIndex = -1, lowIndex = -1;
222 u16 freq;
223
224 ath9k_hw_get_channel_centers(ah, chan, &centers);
225 freq = isHt40Target ? centers.synth_center : centers.ctl_center;
226
227 if (freq <= ath9k_hw_fbin2freq(powInfo[0].bChannel, IS_CHAN_2GHZ(chan))) {
228 matchIndex = 0;
229 } else {
230 for (i = 0; (i < numChannels) &&
231 (powInfo[i].bChannel != AR5416_BCHAN_UNUSED); i++) {
232 if (freq == ath9k_hw_fbin2freq(powInfo[i].bChannel,
233 IS_CHAN_2GHZ(chan))) {
234 matchIndex = i;
235 break;
236 } else
Roel Kluin73f57f82009-08-07 23:50:00 +0200237 if (freq < ath9k_hw_fbin2freq(powInfo[i].bChannel,
238 IS_CHAN_2GHZ(chan)) && i > 0 &&
239 freq > ath9k_hw_fbin2freq(powInfo[i - 1].bChannel,
240 IS_CHAN_2GHZ(chan))) {
Sujithf74df6f2009-02-09 13:27:24 +0530241 lowIndex = i - 1;
242 break;
243 }
244 }
245 if ((matchIndex == -1) && (lowIndex == -1))
246 matchIndex = i - 1;
247 }
248
249 if (matchIndex != -1) {
250 *pNewPower = powInfo[matchIndex];
251 } else {
252 clo = ath9k_hw_fbin2freq(powInfo[lowIndex].bChannel,
253 IS_CHAN_2GHZ(chan));
254 chi = ath9k_hw_fbin2freq(powInfo[lowIndex + 1].bChannel,
255 IS_CHAN_2GHZ(chan));
256
257 for (i = 0; i < numRates; i++) {
258 pNewPower->tPow2x[i] = (u8)ath9k_hw_interpolate(freq,
259 clo, chi,
260 powInfo[lowIndex].tPow2x[i],
261 powInfo[lowIndex + 1].tPow2x[i]);
262 }
263 }
264}
265
Sujithb5aec952009-08-07 09:45:15 +0530266u16 ath9k_hw_get_max_edge_power(u16 freq, struct cal_ctl_edges *pRdEdgesPower,
267 bool is2GHz, int num_band_edges)
Sujithf74df6f2009-02-09 13:27:24 +0530268{
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100269 u16 twiceMaxEdgePower = MAX_RATE_POWER;
Sujithf74df6f2009-02-09 13:27:24 +0530270 int i;
271
272 for (i = 0; (i < num_band_edges) &&
273 (pRdEdgesPower[i].bChannel != AR5416_BCHAN_UNUSED); i++) {
274 if (freq == ath9k_hw_fbin2freq(pRdEdgesPower[i].bChannel, is2GHz)) {
Felix Fietkaue702ba12010-12-01 19:07:46 +0100275 twiceMaxEdgePower = CTL_EDGE_TPOWER(pRdEdgesPower[i].ctl);
Sujithf74df6f2009-02-09 13:27:24 +0530276 break;
277 } else if ((i > 0) &&
278 (freq < ath9k_hw_fbin2freq(pRdEdgesPower[i].bChannel,
279 is2GHz))) {
280 if (ath9k_hw_fbin2freq(pRdEdgesPower[i - 1].bChannel,
281 is2GHz) < freq &&
Felix Fietkaue702ba12010-12-01 19:07:46 +0100282 CTL_EDGE_FLAGS(pRdEdgesPower[i - 1].ctl)) {
Sujithf74df6f2009-02-09 13:27:24 +0530283 twiceMaxEdgePower =
Felix Fietkaue702ba12010-12-01 19:07:46 +0100284 CTL_EDGE_TPOWER(pRdEdgesPower[i - 1].ctl);
Sujithf74df6f2009-02-09 13:27:24 +0530285 }
286 break;
287 }
288 }
289
290 return twiceMaxEdgePower;
291}
292
Gabor Juhosea6f7922012-04-14 22:01:58 +0200293u16 ath9k_hw_get_scaled_power(struct ath_hw *ah, u16 power_limit,
294 u8 antenna_reduction)
295{
Gabor Juhos8f942b92012-04-14 22:01:59 +0200296 u16 reduction = antenna_reduction;
Gabor Juhosea6f7922012-04-14 22:01:58 +0200297
298 /*
299 * Reduce scaled Power by number of chains active
300 * to get the per chain tx power level.
301 */
302 switch (ar5416_get_ntxchains(ah->txchainmask)) {
303 case 1:
304 break;
305 case 2:
Gabor Juhos6010e722012-04-16 22:22:49 +0200306 reduction += POWER_CORRECTION_FOR_TWO_CHAIN;
Gabor Juhosea6f7922012-04-14 22:01:58 +0200307 break;
308 case 3:
Gabor Juhos6010e722012-04-16 22:22:49 +0200309 reduction += POWER_CORRECTION_FOR_THREE_CHAIN;
Gabor Juhosea6f7922012-04-14 22:01:58 +0200310 break;
311 }
312
Gabor Juhos8f942b92012-04-14 22:01:59 +0200313 if (power_limit > reduction)
314 power_limit -= reduction;
315 else
316 power_limit = 0;
Gabor Juhosea6f7922012-04-14 22:01:58 +0200317
Gabor Juhos8f942b92012-04-14 22:01:59 +0200318 return power_limit;
Gabor Juhosea6f7922012-04-14 22:01:58 +0200319}
320
Sujitha55f8582010-06-01 15:14:07 +0530321void ath9k_hw_update_regulatory_maxpower(struct ath_hw *ah)
322{
323 struct ath_common *common = ath9k_hw_common(ah);
324 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
325
326 switch (ar5416_get_ntxchains(ah->txchainmask)) {
327 case 1:
328 break;
329 case 2:
Gabor Juhos6010e722012-04-16 22:22:49 +0200330 regulatory->max_power_level += POWER_CORRECTION_FOR_TWO_CHAIN;
Sujitha55f8582010-06-01 15:14:07 +0530331 break;
332 case 3:
Gabor Juhos6010e722012-04-16 22:22:49 +0200333 regulatory->max_power_level += POWER_CORRECTION_FOR_THREE_CHAIN;
Sujitha55f8582010-06-01 15:14:07 +0530334 break;
335 default:
Joe Perchesd2182b62011-12-15 14:55:53 -0800336 ath_dbg(common, EEPROM, "Invalid chainmask configuration\n");
Sujitha55f8582010-06-01 15:14:07 +0530337 break;
338 }
339}
340
Felix Fietkau115277a2010-12-12 00:51:09 +0100341void ath9k_hw_get_gain_boundaries_pdadcs(struct ath_hw *ah,
342 struct ath9k_channel *chan,
343 void *pRawDataSet,
344 u8 *bChans, u16 availPiers,
345 u16 tPdGainOverlap,
346 u16 *pPdGainBoundaries, u8 *pPDADCValues,
347 u16 numXpdGains)
348{
349 int i, j, k;
350 int16_t ss;
351 u16 idxL = 0, idxR = 0, numPiers;
352 static u8 vpdTableL[AR5416_NUM_PD_GAINS]
353 [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
354 static u8 vpdTableR[AR5416_NUM_PD_GAINS]
355 [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
356 static u8 vpdTableI[AR5416_NUM_PD_GAINS]
357 [AR5416_MAX_PWR_RANGE_IN_HALF_DB];
358
359 u8 *pVpdL, *pVpdR, *pPwrL, *pPwrR;
360 u8 minPwrT4[AR5416_NUM_PD_GAINS];
361 u8 maxPwrT4[AR5416_NUM_PD_GAINS];
362 int16_t vpdStep;
363 int16_t tmpVal;
364 u16 sizeCurrVpdTable, maxIndex, tgtIndex;
365 bool match;
366 int16_t minDelta = 0;
367 struct chan_centers centers;
368 int pdgain_boundary_default;
369 struct cal_data_per_freq *data_def = pRawDataSet;
370 struct cal_data_per_freq_4k *data_4k = pRawDataSet;
Felix Fietkau940cd2c2010-12-12 00:51:10 +0100371 struct cal_data_per_freq_ar9287 *data_9287 = pRawDataSet;
Felix Fietkau115277a2010-12-12 00:51:09 +0100372 bool eeprom_4k = AR_SREV_9285(ah) || AR_SREV_9271(ah);
Felix Fietkau940cd2c2010-12-12 00:51:10 +0100373 int intercepts;
374
375 if (AR_SREV_9287(ah))
376 intercepts = AR9287_PD_GAIN_ICEPTS;
377 else
378 intercepts = AR5416_PD_GAIN_ICEPTS;
Felix Fietkau115277a2010-12-12 00:51:09 +0100379
380 memset(&minPwrT4, 0, AR5416_NUM_PD_GAINS);
381 ath9k_hw_get_channel_centers(ah, chan, &centers);
382
383 for (numPiers = 0; numPiers < availPiers; numPiers++) {
384 if (bChans[numPiers] == AR5416_BCHAN_UNUSED)
385 break;
386 }
387
388 match = ath9k_hw_get_lower_upper_index((u8)FREQ2FBIN(centers.synth_center,
389 IS_CHAN_2GHZ(chan)),
390 bChans, numPiers, &idxL, &idxR);
391
392 if (match) {
Felix Fietkau940cd2c2010-12-12 00:51:10 +0100393 if (AR_SREV_9287(ah)) {
394 /* FIXME: array overrun? */
395 for (i = 0; i < numXpdGains; i++) {
396 minPwrT4[i] = data_9287[idxL].pwrPdg[i][0];
397 maxPwrT4[i] = data_9287[idxL].pwrPdg[i][4];
398 ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
399 data_9287[idxL].pwrPdg[i],
400 data_9287[idxL].vpdPdg[i],
401 intercepts,
402 vpdTableI[i]);
403 }
404 } else if (eeprom_4k) {
Felix Fietkau115277a2010-12-12 00:51:09 +0100405 for (i = 0; i < numXpdGains; i++) {
406 minPwrT4[i] = data_4k[idxL].pwrPdg[i][0];
407 maxPwrT4[i] = data_4k[idxL].pwrPdg[i][4];
408 ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
409 data_4k[idxL].pwrPdg[i],
410 data_4k[idxL].vpdPdg[i],
Felix Fietkau940cd2c2010-12-12 00:51:10 +0100411 intercepts,
Felix Fietkau115277a2010-12-12 00:51:09 +0100412 vpdTableI[i]);
413 }
414 } else {
415 for (i = 0; i < numXpdGains; i++) {
416 minPwrT4[i] = data_def[idxL].pwrPdg[i][0];
417 maxPwrT4[i] = data_def[idxL].pwrPdg[i][4];
418 ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
419 data_def[idxL].pwrPdg[i],
420 data_def[idxL].vpdPdg[i],
Felix Fietkau940cd2c2010-12-12 00:51:10 +0100421 intercepts,
Felix Fietkau115277a2010-12-12 00:51:09 +0100422 vpdTableI[i]);
423 }
424 }
425 } else {
426 for (i = 0; i < numXpdGains; i++) {
Felix Fietkau940cd2c2010-12-12 00:51:10 +0100427 if (AR_SREV_9287(ah)) {
428 pVpdL = data_9287[idxL].vpdPdg[i];
429 pPwrL = data_9287[idxL].pwrPdg[i];
430 pVpdR = data_9287[idxR].vpdPdg[i];
431 pPwrR = data_9287[idxR].pwrPdg[i];
432 } else if (eeprom_4k) {
Felix Fietkau115277a2010-12-12 00:51:09 +0100433 pVpdL = data_4k[idxL].vpdPdg[i];
434 pPwrL = data_4k[idxL].pwrPdg[i];
435 pVpdR = data_4k[idxR].vpdPdg[i];
436 pPwrR = data_4k[idxR].pwrPdg[i];
437 } else {
438 pVpdL = data_def[idxL].vpdPdg[i];
439 pPwrL = data_def[idxL].pwrPdg[i];
440 pVpdR = data_def[idxR].vpdPdg[i];
441 pPwrR = data_def[idxR].pwrPdg[i];
442 }
443
444 minPwrT4[i] = max(pPwrL[0], pPwrR[0]);
445
446 maxPwrT4[i] =
Felix Fietkau940cd2c2010-12-12 00:51:10 +0100447 min(pPwrL[intercepts - 1],
448 pPwrR[intercepts - 1]);
Felix Fietkau115277a2010-12-12 00:51:09 +0100449
450
451 ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
452 pPwrL, pVpdL,
Felix Fietkau940cd2c2010-12-12 00:51:10 +0100453 intercepts,
Felix Fietkau115277a2010-12-12 00:51:09 +0100454 vpdTableL[i]);
455 ath9k_hw_fill_vpd_table(minPwrT4[i], maxPwrT4[i],
456 pPwrR, pVpdR,
Felix Fietkau940cd2c2010-12-12 00:51:10 +0100457 intercepts,
Felix Fietkau115277a2010-12-12 00:51:09 +0100458 vpdTableR[i]);
459
460 for (j = 0; j <= (maxPwrT4[i] - minPwrT4[i]) / 2; j++) {
461 vpdTableI[i][j] =
462 (u8)(ath9k_hw_interpolate((u16)
463 FREQ2FBIN(centers.
464 synth_center,
465 IS_CHAN_2GHZ
466 (chan)),
467 bChans[idxL], bChans[idxR],
468 vpdTableL[i][j], vpdTableR[i][j]));
469 }
470 }
471 }
472
473 k = 0;
474
475 for (i = 0; i < numXpdGains; i++) {
476 if (i == (numXpdGains - 1))
477 pPdGainBoundaries[i] =
478 (u16)(maxPwrT4[i] / 2);
479 else
480 pPdGainBoundaries[i] =
481 (u16)((maxPwrT4[i] + minPwrT4[i + 1]) / 4);
482
483 pPdGainBoundaries[i] =
484 min((u16)MAX_RATE_POWER, pPdGainBoundaries[i]);
485
Felix Fietkau1b8714f2011-09-15 14:25:35 +0200486 minDelta = 0;
Felix Fietkau115277a2010-12-12 00:51:09 +0100487
488 if (i == 0) {
489 if (AR_SREV_9280_20_OR_LATER(ah))
490 ss = (int16_t)(0 - (minPwrT4[i] / 2));
491 else
492 ss = 0;
493 } else {
494 ss = (int16_t)((pPdGainBoundaries[i - 1] -
495 (minPwrT4[i] / 2)) -
496 tPdGainOverlap + 1 + minDelta);
497 }
498 vpdStep = (int16_t)(vpdTableI[i][1] - vpdTableI[i][0]);
499 vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
500
501 while ((ss < 0) && (k < (AR5416_NUM_PDADC_VALUES - 1))) {
502 tmpVal = (int16_t)(vpdTableI[i][0] + ss * vpdStep);
503 pPDADCValues[k++] = (u8)((tmpVal < 0) ? 0 : tmpVal);
504 ss++;
505 }
506
507 sizeCurrVpdTable = (u8) ((maxPwrT4[i] - minPwrT4[i]) / 2 + 1);
508 tgtIndex = (u8)(pPdGainBoundaries[i] + tPdGainOverlap -
509 (minPwrT4[i] / 2));
510 maxIndex = (tgtIndex < sizeCurrVpdTable) ?
511 tgtIndex : sizeCurrVpdTable;
512
513 while ((ss < maxIndex) && (k < (AR5416_NUM_PDADC_VALUES - 1))) {
514 pPDADCValues[k++] = vpdTableI[i][ss++];
515 }
516
517 vpdStep = (int16_t)(vpdTableI[i][sizeCurrVpdTable - 1] -
518 vpdTableI[i][sizeCurrVpdTable - 2]);
519 vpdStep = (int16_t)((vpdStep < 1) ? 1 : vpdStep);
520
521 if (tgtIndex >= maxIndex) {
522 while ((ss <= tgtIndex) &&
523 (k < (AR5416_NUM_PDADC_VALUES - 1))) {
524 tmpVal = (int16_t)((vpdTableI[i][sizeCurrVpdTable - 1] +
525 (ss - maxIndex + 1) * vpdStep));
526 pPDADCValues[k++] = (u8)((tmpVal > 255) ?
527 255 : tmpVal);
528 ss++;
529 }
530 }
531 }
532
533 if (eeprom_4k)
534 pdgain_boundary_default = 58;
535 else
536 pdgain_boundary_default = pPdGainBoundaries[i - 1];
537
538 while (i < AR5416_PD_GAINS_IN_MASK) {
539 pPdGainBoundaries[i] = pdgain_boundary_default;
540 i++;
541 }
542
543 while (k < AR5416_NUM_PDADC_VALUES) {
544 pPDADCValues[k] = pPDADCValues[k - 1];
545 k++;
546 }
547}
548
Luis R. Rodriguezf637cfd2009-08-03 12:24:46 -0700549int ath9k_hw_eeprom_init(struct ath_hw *ah)
Sujithf1dc5602008-10-29 10:16:30 +0530550{
551 int status;
Sujithc16c9d02009-08-07 09:45:11 +0530552
Senthil Balasubramanian15c9ee72010-04-15 17:39:14 -0400553 if (AR_SREV_9300_20_OR_LATER(ah))
554 ah->eep_ops = &eep_ar9300_ops;
555 else if (AR_SREV_9287(ah)) {
Luis R. Rodriguez0b8f6f2b12010-04-15 17:39:12 -0400556 ah->eep_ops = &eep_ar9287_ops;
Luis R. Rodriguezd7e7d222009-08-03 23:14:12 -0400557 } else if (AR_SREV_9285(ah) || AR_SREV_9271(ah)) {
Sujithf74df6f2009-02-09 13:27:24 +0530558 ah->eep_ops = &eep_4k_ops;
559 } else {
Sujithf74df6f2009-02-09 13:27:24 +0530560 ah->eep_ops = &eep_def_ops;
561 }
Senthil Balasubramaniane7594072008-12-08 19:43:48 +0530562
Sujithf74df6f2009-02-09 13:27:24 +0530563 if (!ah->eep_ops->fill_eeprom(ah))
Sujithf1dc5602008-10-29 10:16:30 +0530564 return -EIO;
565
Sujithf74df6f2009-02-09 13:27:24 +0530566 status = ah->eep_ops->check_eeprom(ah);
Sujithf1dc5602008-10-29 10:16:30 +0530567
568 return status;
569}