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