blob: 1a019a39eda1048fdf07e969338de768616a97b9 [file] [log] [blame]
Sujithb5aec952009-08-07 09:45:15 +05301/*
Sujith Manoharan5b681382011-05-17 13:36:18 +05302 * Copyright (c) 2008-2011 Atheros Communications Inc.
Sujithb5aec952009-08-07 09:45:15 +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
Pavel Roskin78fa99a2011-07-15 19:06:33 -040017#include <asm/unaligned.h>
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070018#include "hw.h"
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -040019#include "ar9002_phy.h"
Sujithb5aec952009-08-07 09:45:15 +053020
Sujith Manoharan04cf53f2011-01-04 13:17:28 +053021#define SIZE_EEPROM_AR9287 (sizeof(struct ar9287_eeprom) / sizeof(u16))
Sujith16c94ac2010-06-01 15:14:04 +053022
23static int ath9k_hw_ar9287_get_eeprom_ver(struct ath_hw *ah)
Sujithb5aec952009-08-07 09:45:15 +053024{
25 return (ah->eeprom.map9287.baseEepHeader.version >> 12) & 0xF;
26}
27
Sujith16c94ac2010-06-01 15:14:04 +053028static int ath9k_hw_ar9287_get_eeprom_rev(struct ath_hw *ah)
Sujithb5aec952009-08-07 09:45:15 +053029{
30 return (ah->eeprom.map9287.baseEepHeader.version) & 0xFFF;
31}
32
Sujith Manoharan04cf53f2011-01-04 13:17:28 +053033static bool __ath9k_hw_ar9287_fill_eeprom(struct ath_hw *ah)
Sujithb5aec952009-08-07 09:45:15 +053034{
35 struct ar9287_eeprom *eep = &ah->eeprom.map9287;
36 u16 *eep_data;
Sujith Manoharan04cf53f2011-01-04 13:17:28 +053037 int addr, eep_start_loc = AR9287_EEP_START_LOC;
Sujithb5aec952009-08-07 09:45:15 +053038 eep_data = (u16 *)eep;
39
Sujith Manoharan04cf53f2011-01-04 13:17:28 +053040 for (addr = 0; addr < SIZE_EEPROM_AR9287; addr++) {
Gabor Juhos0e4b9f22012-12-10 15:30:27 +010041 if (!ath9k_hw_nvram_read(ah, addr + eep_start_loc, eep_data))
Sujithb5aec952009-08-07 09:45:15 +053042 return false;
Sujithb5aec952009-08-07 09:45:15 +053043 eep_data++;
44 }
Sujith16c94ac2010-06-01 15:14:04 +053045
Sujithb5aec952009-08-07 09:45:15 +053046 return true;
47}
48
Sujith Manoharan04cf53f2011-01-04 13:17:28 +053049static bool __ath9k_hw_usb_ar9287_fill_eeprom(struct ath_hw *ah)
50{
51 u16 *eep_data = (u16 *)&ah->eeprom.map9287;
52
53 ath9k_hw_usb_gen_fill_eeprom(ah, eep_data,
54 AR9287_HTC_EEP_START_LOC,
55 SIZE_EEPROM_AR9287);
56 return true;
57}
58
59static bool ath9k_hw_ar9287_fill_eeprom(struct ath_hw *ah)
60{
61 struct ath_common *common = ath9k_hw_common(ah);
62
63 if (!ath9k_hw_use_flash(ah)) {
Joe Perchesd2182b62011-12-15 14:55:53 -080064 ath_dbg(common, EEPROM, "Reading from EEPROM, not flash\n");
Sujith Manoharan04cf53f2011-01-04 13:17:28 +053065 }
66
67 if (common->bus_ops->ath_bus_type == ATH_USB)
68 return __ath9k_hw_usb_ar9287_fill_eeprom(ah);
69 else
70 return __ath9k_hw_ar9287_fill_eeprom(ah);
71}
72
Rajkumar Manoharan49c995202011-07-29 17:38:10 +053073#if defined(CONFIG_ATH9K_DEBUGFS) || defined(CONFIG_ATH9K_HTC_DEBUGFS)
74static u32 ar9287_dump_modal_eeprom(char *buf, u32 len, u32 size,
75 struct modal_eep_ar9287_header *modal_hdr)
76{
77 PR_EEP("Chain0 Ant. Control", modal_hdr->antCtrlChain[0]);
78 PR_EEP("Chain1 Ant. Control", modal_hdr->antCtrlChain[1]);
79 PR_EEP("Ant. Common Control", modal_hdr->antCtrlCommon);
80 PR_EEP("Chain0 Ant. Gain", modal_hdr->antennaGainCh[0]);
81 PR_EEP("Chain1 Ant. Gain", modal_hdr->antennaGainCh[1]);
82 PR_EEP("Switch Settle", modal_hdr->switchSettling);
83 PR_EEP("Chain0 TxRxAtten", modal_hdr->txRxAttenCh[0]);
84 PR_EEP("Chain1 TxRxAtten", modal_hdr->txRxAttenCh[1]);
85 PR_EEP("Chain0 RxTxMargin", modal_hdr->rxTxMarginCh[0]);
86 PR_EEP("Chain1 RxTxMargin", modal_hdr->rxTxMarginCh[1]);
87 PR_EEP("ADC Desired size", modal_hdr->adcDesiredSize);
88 PR_EEP("txEndToXpaOff", modal_hdr->txEndToXpaOff);
89 PR_EEP("txEndToRxOn", modal_hdr->txEndToRxOn);
90 PR_EEP("txFrameToXpaOn", modal_hdr->txFrameToXpaOn);
91 PR_EEP("CCA Threshold)", modal_hdr->thresh62);
92 PR_EEP("Chain0 NF Threshold", modal_hdr->noiseFloorThreshCh[0]);
93 PR_EEP("Chain1 NF Threshold", modal_hdr->noiseFloorThreshCh[1]);
94 PR_EEP("xpdGain", modal_hdr->xpdGain);
95 PR_EEP("External PD", modal_hdr->xpd);
96 PR_EEP("Chain0 I Coefficient", modal_hdr->iqCalICh[0]);
97 PR_EEP("Chain1 I Coefficient", modal_hdr->iqCalICh[1]);
98 PR_EEP("Chain0 Q Coefficient", modal_hdr->iqCalQCh[0]);
99 PR_EEP("Chain1 Q Coefficient", modal_hdr->iqCalQCh[1]);
100 PR_EEP("pdGainOverlap", modal_hdr->pdGainOverlap);
101 PR_EEP("xPA Bias Level", modal_hdr->xpaBiasLvl);
102 PR_EEP("txFrameToDataStart", modal_hdr->txFrameToDataStart);
103 PR_EEP("txFrameToPaOn", modal_hdr->txFrameToPaOn);
104 PR_EEP("HT40 Power Inc.", modal_hdr->ht40PowerIncForPdadc);
105 PR_EEP("Chain0 bswAtten", modal_hdr->bswAtten[0]);
106 PR_EEP("Chain1 bswAtten", modal_hdr->bswAtten[1]);
107 PR_EEP("Chain0 bswMargin", modal_hdr->bswMargin[0]);
108 PR_EEP("Chain1 bswMargin", modal_hdr->bswMargin[1]);
109 PR_EEP("HT40 Switch Settle", modal_hdr->swSettleHt40);
110 PR_EEP("AR92x7 Version", modal_hdr->version);
111 PR_EEP("DriverBias1", modal_hdr->db1);
112 PR_EEP("DriverBias2", modal_hdr->db1);
113 PR_EEP("CCK OutputBias", modal_hdr->ob_cck);
114 PR_EEP("PSK OutputBias", modal_hdr->ob_psk);
115 PR_EEP("QAM OutputBias", modal_hdr->ob_qam);
116 PR_EEP("PAL_OFF OutputBias", modal_hdr->ob_pal_off);
117
118 return len;
119}
120
121static u32 ath9k_hw_ar9287_dump_eeprom(struct ath_hw *ah, bool dump_base_hdr,
122 u8 *buf, u32 len, u32 size)
123{
124 struct ar9287_eeprom *eep = &ah->eeprom.map9287;
125 struct base_eep_ar9287_header *pBase = &eep->baseEepHeader;
126
127 if (!dump_base_hdr) {
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200128 len += scnprintf(buf + len, size - len,
129 "%20s :\n", "2GHz modal Header");
Mohammed Shafi Shajakhand25360b2012-05-15 15:24:47 +0530130 len = ar9287_dump_modal_eeprom(buf, len, size,
Rajkumar Manoharan49c995202011-07-29 17:38:10 +0530131 &eep->modalHeader);
132 goto out;
133 }
134
135 PR_EEP("Major Version", pBase->version >> 12);
136 PR_EEP("Minor Version", pBase->version & 0xFFF);
137 PR_EEP("Checksum", pBase->checksum);
138 PR_EEP("Length", pBase->length);
139 PR_EEP("RegDomain1", pBase->regDmn[0]);
140 PR_EEP("RegDomain2", pBase->regDmn[1]);
141 PR_EEP("TX Mask", pBase->txMask);
142 PR_EEP("RX Mask", pBase->rxMask);
143 PR_EEP("Allow 5GHz", !!(pBase->opCapFlags & AR5416_OPFLAGS_11A));
144 PR_EEP("Allow 2GHz", !!(pBase->opCapFlags & AR5416_OPFLAGS_11G));
145 PR_EEP("Disable 2GHz HT20", !!(pBase->opCapFlags &
146 AR5416_OPFLAGS_N_2G_HT20));
147 PR_EEP("Disable 2GHz HT40", !!(pBase->opCapFlags &
148 AR5416_OPFLAGS_N_2G_HT40));
149 PR_EEP("Disable 5Ghz HT20", !!(pBase->opCapFlags &
150 AR5416_OPFLAGS_N_5G_HT20));
151 PR_EEP("Disable 5Ghz HT40", !!(pBase->opCapFlags &
152 AR5416_OPFLAGS_N_5G_HT40));
153 PR_EEP("Big Endian", !!(pBase->eepMisc & 0x01));
154 PR_EEP("Cal Bin Major Ver", (pBase->binBuildNumber >> 24) & 0xFF);
155 PR_EEP("Cal Bin Minor Ver", (pBase->binBuildNumber >> 16) & 0xFF);
156 PR_EEP("Cal Bin Build", (pBase->binBuildNumber >> 8) & 0xFF);
157 PR_EEP("Power Table Offset", pBase->pwrTableOffset);
158 PR_EEP("OpenLoop Power Ctrl", pBase->openLoopPwrCntl);
159
Zefir Kurtisi5e88ba62013-09-05 14:11:57 +0200160 len += scnprintf(buf + len, size - len, "%20s : %pM\n", "MacAddress",
161 pBase->macAddr);
Rajkumar Manoharan49c995202011-07-29 17:38:10 +0530162
163out:
164 if (len > size)
165 len = size;
166
167 return len;
168}
169#else
170static u32 ath9k_hw_ar9287_dump_eeprom(struct ath_hw *ah, bool dump_base_hdr,
171 u8 *buf, u32 len, u32 size)
172{
173 return 0;
174}
175#endif
176
177
Sujith16c94ac2010-06-01 15:14:04 +0530178static int ath9k_hw_ar9287_check_eeprom(struct ath_hw *ah)
Sujithb5aec952009-08-07 09:45:15 +0530179{
Martin Blumenstingl6fa658f2015-10-31 13:57:32 +0100180 u32 el, integer;
181 u16 word;
182 int i, err;
183 bool need_swap;
Sujithb5aec952009-08-07 09:45:15 +0530184 struct ar9287_eeprom *eep = &ah->eeprom.map9287;
185
Martin Blumenstingl6fa658f2015-10-31 13:57:32 +0100186 err = ath9k_hw_nvram_swap_data(ah, &need_swap, SIZE_EEPROM_AR9287);
187 if (err)
188 return err;
Sujithb5aec952009-08-07 09:45:15 +0530189
190 if (need_swap)
Martin Blumenstingl6fa658f2015-10-31 13:57:32 +0100191 el = swab16(eep->baseEepHeader.length);
Sujithb5aec952009-08-07 09:45:15 +0530192 else
Martin Blumenstingl6fa658f2015-10-31 13:57:32 +0100193 el = eep->baseEepHeader.length;
Sujithb5aec952009-08-07 09:45:15 +0530194
Martin Blumenstingl6fa658f2015-10-31 13:57:32 +0100195 el = min(el / sizeof(u16), SIZE_EEPROM_AR9287);
196 if (!ath9k_hw_nvram_validate_checksum(ah, el))
197 return -EINVAL;
Sujithb5aec952009-08-07 09:45:15 +0530198
199 if (need_swap) {
200 word = swab16(eep->baseEepHeader.length);
201 eep->baseEepHeader.length = word;
202
203 word = swab16(eep->baseEepHeader.checksum);
204 eep->baseEepHeader.checksum = word;
205
206 word = swab16(eep->baseEepHeader.version);
207 eep->baseEepHeader.version = word;
208
209 word = swab16(eep->baseEepHeader.regDmn[0]);
210 eep->baseEepHeader.regDmn[0] = word;
211
212 word = swab16(eep->baseEepHeader.regDmn[1]);
213 eep->baseEepHeader.regDmn[1] = word;
214
215 word = swab16(eep->baseEepHeader.rfSilent);
216 eep->baseEepHeader.rfSilent = word;
217
218 word = swab16(eep->baseEepHeader.blueToothOptions);
219 eep->baseEepHeader.blueToothOptions = word;
220
221 word = swab16(eep->baseEepHeader.deviceCap);
222 eep->baseEepHeader.deviceCap = word;
223
224 integer = swab32(eep->modalHeader.antCtrlCommon);
225 eep->modalHeader.antCtrlCommon = integer;
226
227 for (i = 0; i < AR9287_MAX_CHAINS; i++) {
228 integer = swab32(eep->modalHeader.antCtrlChain[i]);
229 eep->modalHeader.antCtrlChain[i] = integer;
230 }
231
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100232 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujithb5aec952009-08-07 09:45:15 +0530233 word = swab16(eep->modalHeader.spurChans[i].spurChan);
234 eep->modalHeader.spurChans[i].spurChan = word;
235 }
236 }
237
Martin Blumenstingl6fa658f2015-10-31 13:57:32 +0100238 if (!ath9k_hw_nvram_check_version(ah, AR9287_EEP_VER,
239 AR5416_EEP_NO_BACK_VER))
Sujithb5aec952009-08-07 09:45:15 +0530240 return -EINVAL;
Sujithb5aec952009-08-07 09:45:15 +0530241
242 return 0;
243}
244
Martin Blumenstingl6fa658f2015-10-31 13:57:32 +0100245#undef SIZE_EEPROM_AR9287
246
Sujith16c94ac2010-06-01 15:14:04 +0530247static u32 ath9k_hw_ar9287_get_eeprom(struct ath_hw *ah,
Sujithb5aec952009-08-07 09:45:15 +0530248 enum eeprom_param param)
249{
250 struct ar9287_eeprom *eep = &ah->eeprom.map9287;
251 struct modal_eep_ar9287_header *pModal = &eep->modalHeader;
252 struct base_eep_ar9287_header *pBase = &eep->baseEepHeader;
253 u16 ver_minor;
254
255 ver_minor = pBase->version & AR9287_EEP_VER_MINOR_MASK;
Sujith16c94ac2010-06-01 15:14:04 +0530256
Sujithb5aec952009-08-07 09:45:15 +0530257 switch (param) {
258 case EEP_NFTHRESH_2:
259 return pModal->noiseFloorThreshCh[0];
Luis R. Rodriguez49101672010-04-15 17:39:13 -0400260 case EEP_MAC_LSW:
Pavel Roskin78fa99a2011-07-15 19:06:33 -0400261 return get_unaligned_be16(pBase->macAddr);
Luis R. Rodriguez49101672010-04-15 17:39:13 -0400262 case EEP_MAC_MID:
Pavel Roskin78fa99a2011-07-15 19:06:33 -0400263 return get_unaligned_be16(pBase->macAddr + 2);
Luis R. Rodriguez49101672010-04-15 17:39:13 -0400264 case EEP_MAC_MSW:
Pavel Roskin78fa99a2011-07-15 19:06:33 -0400265 return get_unaligned_be16(pBase->macAddr + 4);
Sujithb5aec952009-08-07 09:45:15 +0530266 case EEP_REG_0:
267 return pBase->regDmn[0];
Sujithb5aec952009-08-07 09:45:15 +0530268 case EEP_OP_CAP:
269 return pBase->deviceCap;
270 case EEP_OP_MODE:
271 return pBase->opCapFlags;
272 case EEP_RF_SILENT:
273 return pBase->rfSilent;
274 case EEP_MINOR_REV:
275 return ver_minor;
276 case EEP_TX_MASK:
277 return pBase->txMask;
278 case EEP_RX_MASK:
279 return pBase->rxMask;
280 case EEP_DEV_TYPE:
281 return pBase->deviceType;
282 case EEP_OL_PWRCTRL:
283 return pBase->openLoopPwrCntl;
284 case EEP_TEMPSENSE_SLOPE:
285 if (ver_minor >= AR9287_EEP_MINOR_VER_2)
286 return pBase->tempSensSlope;
287 else
288 return 0;
289 case EEP_TEMPSENSE_SLOPE_PAL_ON:
290 if (ver_minor >= AR9287_EEP_MINOR_VER_3)
291 return pBase->tempSensSlopePalOn;
292 else
293 return 0;
Felix Fietkauca2c68c2011-10-08 20:06:20 +0200294 case EEP_ANTENNA_GAIN_2G:
295 return max_t(u8, pModal->antennaGainCh[0],
296 pModal->antennaGainCh[1]);
Sujithb5aec952009-08-07 09:45:15 +0530297 default:
298 return 0;
299 }
300}
301
Sujithb5aec952009-08-07 09:45:15 +0530302static void ar9287_eeprom_get_tx_gain_index(struct ath_hw *ah,
303 struct ath9k_channel *chan,
304 struct cal_data_op_loop_ar9287 *pRawDatasetOpLoop,
Sujith16c94ac2010-06-01 15:14:04 +0530305 u8 *pCalChans, u16 availPiers, int8_t *pPwr)
Sujithb5aec952009-08-07 09:45:15 +0530306{
Sujith16c94ac2010-06-01 15:14:04 +0530307 u16 idxL = 0, idxR = 0, numPiers;
Sujithb5aec952009-08-07 09:45:15 +0530308 bool match;
309 struct chan_centers centers;
310
311 ath9k_hw_get_channel_centers(ah, chan, &centers);
312
313 for (numPiers = 0; numPiers < availPiers; numPiers++) {
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100314 if (pCalChans[numPiers] == AR5416_BCHAN_UNUSED)
Sujithb5aec952009-08-07 09:45:15 +0530315 break;
316 }
317
318 match = ath9k_hw_get_lower_upper_index(
Sujitha55f8582010-06-01 15:14:07 +0530319 (u8)FREQ2FBIN(centers.synth_center, IS_CHAN_2GHZ(chan)),
320 pCalChans, numPiers, &idxL, &idxR);
Sujithb5aec952009-08-07 09:45:15 +0530321
322 if (match) {
Vivek Natarajand4fe5af2009-08-14 11:32:04 +0530323 *pPwr = (int8_t) pRawDatasetOpLoop[idxL].pwrPdg[0][0];
Sujithb5aec952009-08-07 09:45:15 +0530324 } else {
Vivek Natarajand4fe5af2009-08-14 11:32:04 +0530325 *pPwr = ((int8_t) pRawDatasetOpLoop[idxL].pwrPdg[0][0] +
Sujith16c94ac2010-06-01 15:14:04 +0530326 (int8_t) pRawDatasetOpLoop[idxR].pwrPdg[0][0])/2;
Sujithb5aec952009-08-07 09:45:15 +0530327 }
328
Sujithb5aec952009-08-07 09:45:15 +0530329}
330
331static void ar9287_eeprom_olpc_set_pdadcs(struct ath_hw *ah,
332 int32_t txPower, u16 chain)
333{
334 u32 tmpVal;
335 u32 a;
336
Sujith16c94ac2010-06-01 15:14:04 +0530337 /* Enable OLPC for chain 0 */
338
Sujithb5aec952009-08-07 09:45:15 +0530339 tmpVal = REG_READ(ah, 0xa270);
340 tmpVal = tmpVal & 0xFCFFFFFF;
341 tmpVal = tmpVal | (0x3 << 24);
342 REG_WRITE(ah, 0xa270, tmpVal);
343
Sujith16c94ac2010-06-01 15:14:04 +0530344 /* Enable OLPC for chain 1 */
345
Sujithb5aec952009-08-07 09:45:15 +0530346 tmpVal = REG_READ(ah, 0xb270);
347 tmpVal = tmpVal & 0xFCFFFFFF;
348 tmpVal = tmpVal | (0x3 << 24);
349 REG_WRITE(ah, 0xb270, tmpVal);
350
Sujith16c94ac2010-06-01 15:14:04 +0530351 /* Write the OLPC ref power for chain 0 */
352
Sujithb5aec952009-08-07 09:45:15 +0530353 if (chain == 0) {
354 tmpVal = REG_READ(ah, 0xa398);
355 tmpVal = tmpVal & 0xff00ffff;
356 a = (txPower)&0xff;
357 tmpVal = tmpVal | (a << 16);
358 REG_WRITE(ah, 0xa398, tmpVal);
359 }
360
Sujith16c94ac2010-06-01 15:14:04 +0530361 /* Write the OLPC ref power for chain 1 */
362
Sujithb5aec952009-08-07 09:45:15 +0530363 if (chain == 1) {
364 tmpVal = REG_READ(ah, 0xb398);
365 tmpVal = tmpVal & 0xff00ffff;
366 a = (txPower)&0xff;
367 tmpVal = tmpVal | (a << 16);
368 REG_WRITE(ah, 0xb398, tmpVal);
369 }
370}
371
Sujith16c94ac2010-06-01 15:14:04 +0530372static void ath9k_hw_set_ar9287_power_cal_table(struct ath_hw *ah,
Felix Fietkaue832bf12011-07-27 15:01:03 +0200373 struct ath9k_channel *chan)
Sujithb5aec952009-08-07 09:45:15 +0530374{
375 struct cal_data_per_freq_ar9287 *pRawDataset;
376 struct cal_data_op_loop_ar9287 *pRawDatasetOpenLoop;
Sujith16c94ac2010-06-01 15:14:04 +0530377 u8 *pCalBChans = NULL;
Sujithb5aec952009-08-07 09:45:15 +0530378 u16 pdGainOverlap_t2;
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100379 u8 pdadcValues[AR5416_NUM_PDADC_VALUES];
380 u16 gainBoundaries[AR5416_PD_GAINS_IN_MASK];
Sujithb5aec952009-08-07 09:45:15 +0530381 u16 numPiers = 0, i, j;
Sujithb5aec952009-08-07 09:45:15 +0530382 u16 numXpdGain, xpdMask;
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100383 u16 xpdGainValues[AR5416_NUM_PD_GAINS] = {0, 0, 0, 0};
Sujitha55f8582010-06-01 15:14:07 +0530384 u32 reg32, regOffset, regChainOffset, regval;
Sujith Manoharan0ff2b5c2011-04-20 11:00:34 +0530385 int16_t diff = 0;
Sujithb5aec952009-08-07 09:45:15 +0530386 struct ar9287_eeprom *pEepData = &ah->eeprom.map9287;
Sujith16c94ac2010-06-01 15:14:04 +0530387
Sujithb5aec952009-08-07 09:45:15 +0530388 xpdMask = pEepData->modalHeader.xpdGain;
Sujith16c94ac2010-06-01 15:14:04 +0530389
Sujithb5aec952009-08-07 09:45:15 +0530390 if ((pEepData->baseEepHeader.version & AR9287_EEP_VER_MINOR_MASK) >=
Sujitha55f8582010-06-01 15:14:07 +0530391 AR9287_EEP_MINOR_VER_2)
Sujithb5aec952009-08-07 09:45:15 +0530392 pdGainOverlap_t2 = pEepData->modalHeader.pdGainOverlap;
393 else
394 pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5),
395 AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
396
397 if (IS_CHAN_2GHZ(chan)) {
398 pCalBChans = pEepData->calFreqPier2G;
399 numPiers = AR9287_NUM_2G_CAL_PIERS;
Sujith16c94ac2010-06-01 15:14:04 +0530400 if (ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
Sujithb5aec952009-08-07 09:45:15 +0530401 pRawDatasetOpenLoop =
Sujitha55f8582010-06-01 15:14:07 +0530402 (struct cal_data_op_loop_ar9287 *)pEepData->calPierData2G[0];
Sujithb5aec952009-08-07 09:45:15 +0530403 ah->initPDADC = pRawDatasetOpenLoop->vpdPdg[0][0];
404 }
405 }
406
407 numXpdGain = 0;
Sujith16c94ac2010-06-01 15:14:04 +0530408
Sujitha55f8582010-06-01 15:14:07 +0530409 /* Calculate the value of xpdgains from the xpdGain Mask */
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100410 for (i = 1; i <= AR5416_PD_GAINS_IN_MASK; i++) {
411 if ((xpdMask >> (AR5416_PD_GAINS_IN_MASK - i)) & 1) {
412 if (numXpdGain >= AR5416_NUM_PD_GAINS)
Sujithb5aec952009-08-07 09:45:15 +0530413 break;
414 xpdGainValues[numXpdGain] =
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100415 (u16)(AR5416_PD_GAINS_IN_MASK-i);
Sujithb5aec952009-08-07 09:45:15 +0530416 numXpdGain++;
417 }
418 }
419
420 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
421 (numXpdGain - 1) & 0x3);
422 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,
423 xpdGainValues[0]);
424 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
425 xpdGainValues[1]);
426 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3,
427 xpdGainValues[2]);
428
429 for (i = 0; i < AR9287_MAX_CHAINS; i++) {
430 regChainOffset = i * 0x1000;
Sujitha55f8582010-06-01 15:14:07 +0530431
Sujithb5aec952009-08-07 09:45:15 +0530432 if (pEepData->baseEepHeader.txMask & (1 << i)) {
Sujitha55f8582010-06-01 15:14:07 +0530433 pRawDatasetOpenLoop =
434 (struct cal_data_op_loop_ar9287 *)pEepData->calPierData2G[i];
435
Sujith16c94ac2010-06-01 15:14:04 +0530436 if (ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
Sujithb5aec952009-08-07 09:45:15 +0530437 int8_t txPower;
438 ar9287_eeprom_get_tx_gain_index(ah, chan,
Sujitha55f8582010-06-01 15:14:07 +0530439 pRawDatasetOpenLoop,
440 pCalBChans, numPiers,
441 &txPower);
Sujithb5aec952009-08-07 09:45:15 +0530442 ar9287_eeprom_olpc_set_pdadcs(ah, txPower, i);
443 } else {
444 pRawDataset =
445 (struct cal_data_per_freq_ar9287 *)
446 pEepData->calPierData2G[i];
Sujitha55f8582010-06-01 15:14:07 +0530447
Felix Fietkau940cd2c2010-12-12 00:51:10 +0100448 ath9k_hw_get_gain_boundaries_pdadcs(ah, chan,
Sujitha55f8582010-06-01 15:14:07 +0530449 pRawDataset,
450 pCalBChans, numPiers,
451 pdGainOverlap_t2,
Sujitha55f8582010-06-01 15:14:07 +0530452 gainBoundaries,
453 pdadcValues,
454 numXpdGain);
Sujithb5aec952009-08-07 09:45:15 +0530455 }
456
Rajkumar Manoharane7fc6332011-03-15 23:11:35 +0530457 ENABLE_REGWRITE_BUFFER(ah);
458
Sujithb5aec952009-08-07 09:45:15 +0530459 if (i == 0) {
Sujitha55f8582010-06-01 15:14:07 +0530460 if (!ath9k_hw_ar9287_get_eeprom(ah,
461 EEP_OL_PWRCTRL)) {
462
463 regval = SM(pdGainOverlap_t2,
464 AR_PHY_TPCRG5_PD_GAIN_OVERLAP)
465 | SM(gainBoundaries[0],
466 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1)
467 | SM(gainBoundaries[1],
468 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2)
469 | SM(gainBoundaries[2],
470 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3)
471 | SM(gainBoundaries[3],
472 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4);
473
474 REG_WRITE(ah,
475 AR_PHY_TPCRG5 + regChainOffset,
476 regval);
Sujithb5aec952009-08-07 09:45:15 +0530477 }
478 }
479
480 if ((int32_t)AR9287_PWR_TABLE_OFFSET_DB !=
Sujitha55f8582010-06-01 15:14:07 +0530481 pEepData->baseEepHeader.pwrTableOffset) {
482 diff = (u16)(pEepData->baseEepHeader.pwrTableOffset -
483 (int32_t)AR9287_PWR_TABLE_OFFSET_DB);
Sujithb5aec952009-08-07 09:45:15 +0530484 diff *= 2;
485
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100486 for (j = 0; j < ((u16)AR5416_NUM_PDADC_VALUES-diff); j++)
Sujithb5aec952009-08-07 09:45:15 +0530487 pdadcValues[j] = pdadcValues[j+diff];
488
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100489 for (j = (u16)(AR5416_NUM_PDADC_VALUES-diff);
490 j < AR5416_NUM_PDADC_VALUES; j++)
Sujithb5aec952009-08-07 09:45:15 +0530491 pdadcValues[j] =
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100492 pdadcValues[AR5416_NUM_PDADC_VALUES-diff];
Sujithb5aec952009-08-07 09:45:15 +0530493 }
494
Sujith16c94ac2010-06-01 15:14:04 +0530495 if (!ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
Sujitha55f8582010-06-01 15:14:07 +0530496 regOffset = AR_PHY_BASE +
497 (672 << 2) + regChainOffset;
498
Sujithb5aec952009-08-07 09:45:15 +0530499 for (j = 0; j < 32; j++) {
Pavel Roskin78fa99a2011-07-15 19:06:33 -0400500 reg32 = get_unaligned_le32(&pdadcValues[4 * j]);
Sujitha55f8582010-06-01 15:14:07 +0530501
Sujithb5aec952009-08-07 09:45:15 +0530502 REG_WRITE(ah, regOffset, reg32);
Sujithb5aec952009-08-07 09:45:15 +0530503 regOffset += 4;
504 }
505 }
Rajkumar Manoharane7fc6332011-03-15 23:11:35 +0530506 REGWRITE_BUFFER_FLUSH(ah);
Sujithb5aec952009-08-07 09:45:15 +0530507 }
508 }
Sujithb5aec952009-08-07 09:45:15 +0530509}
510
Sujith16c94ac2010-06-01 15:14:04 +0530511static void ath9k_hw_set_ar9287_power_per_rate_table(struct ath_hw *ah,
512 struct ath9k_channel *chan,
513 int16_t *ratesArray,
514 u16 cfgCtl,
Felix Fietkauca2c68c2011-10-08 20:06:20 +0200515 u16 antenna_reduction,
Sujith16c94ac2010-06-01 15:14:04 +0530516 u16 powerLimit)
Sujithb5aec952009-08-07 09:45:15 +0530517{
Sujitha55f8582010-06-01 15:14:07 +0530518#define CMP_CTL \
519 (((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == \
520 pEepData->ctlIndex[i])
521
522#define CMP_NO_CTL \
523 (((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == \
524 ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL))
525
Rajkumar Manoharana261f0e2011-11-22 18:52:00 +0530526 u16 twiceMaxEdgePower;
Sujithb5aec952009-08-07 09:45:15 +0530527 int i;
Sujithb5aec952009-08-07 09:45:15 +0530528 struct cal_ctl_data_ar9287 *rep;
529 struct cal_target_power_leg targetPowerOfdm = {0, {0, 0, 0, 0} },
530 targetPowerCck = {0, {0, 0, 0, 0} };
531 struct cal_target_power_leg targetPowerOfdmExt = {0, {0, 0, 0, 0} },
532 targetPowerCckExt = {0, {0, 0, 0, 0} };
Sujith16c94ac2010-06-01 15:14:04 +0530533 struct cal_target_power_ht targetPowerHt20,
Sujithb5aec952009-08-07 09:45:15 +0530534 targetPowerHt40 = {0, {0, 0, 0, 0} };
Felix Fietkauca2c68c2011-10-08 20:06:20 +0200535 u16 scaledPower = 0, minCtlPower;
Joe Perches07b2fa52010-11-20 18:38:53 -0800536 static const u16 ctlModesFor11g[] = {
537 CTL_11B, CTL_11G, CTL_2GHT20,
538 CTL_11B_EXT, CTL_11G_EXT, CTL_2GHT40
539 };
540 u16 numCtlModes = 0;
541 const u16 *pCtlMode = NULL;
542 u16 ctlMode, freq;
Sujithb5aec952009-08-07 09:45:15 +0530543 struct chan_centers centers;
544 int tx_chainmask;
545 u16 twiceMinEdgePower;
546 struct ar9287_eeprom *pEepData = &ah->eeprom.map9287;
547 tx_chainmask = ah->txchainmask;
548
549 ath9k_hw_get_channel_centers(ah, chan, &centers);
Gabor Juhosea6f7922012-04-14 22:01:58 +0200550 scaledPower = ath9k_hw_get_scaled_power(ah, powerLimit,
551 antenna_reduction);
Sujithb5aec952009-08-07 09:45:15 +0530552
Sujitha55f8582010-06-01 15:14:07 +0530553 /*
554 * Get TX power from EEPROM.
555 */
Sujithb5aec952009-08-07 09:45:15 +0530556 if (IS_CHAN_2GHZ(chan)) {
Sujitha55f8582010-06-01 15:14:07 +0530557 /* CTL_11B, CTL_11G, CTL_2GHT20 */
Sujithb5aec952009-08-07 09:45:15 +0530558 numCtlModes =
559 ARRAY_SIZE(ctlModesFor11g) - SUB_NUM_CTL_MODES_AT_2G_40;
Sujith16c94ac2010-06-01 15:14:04 +0530560
Sujithb5aec952009-08-07 09:45:15 +0530561 pCtlMode = ctlModesFor11g;
562
563 ath9k_hw_get_legacy_target_powers(ah, chan,
564 pEepData->calTargetPowerCck,
565 AR9287_NUM_2G_CCK_TARGET_POWERS,
566 &targetPowerCck, 4, false);
567 ath9k_hw_get_legacy_target_powers(ah, chan,
568 pEepData->calTargetPower2G,
569 AR9287_NUM_2G_20_TARGET_POWERS,
570 &targetPowerOfdm, 4, false);
571 ath9k_hw_get_target_powers(ah, chan,
572 pEepData->calTargetPower2GHT20,
573 AR9287_NUM_2G_20_TARGET_POWERS,
574 &targetPowerHt20, 8, false);
575
576 if (IS_CHAN_HT40(chan)) {
Sujitha55f8582010-06-01 15:14:07 +0530577 /* All 2G CTLs */
Sujithb5aec952009-08-07 09:45:15 +0530578 numCtlModes = ARRAY_SIZE(ctlModesFor11g);
579 ath9k_hw_get_target_powers(ah, chan,
580 pEepData->calTargetPower2GHT40,
581 AR9287_NUM_2G_40_TARGET_POWERS,
582 &targetPowerHt40, 8, true);
583 ath9k_hw_get_legacy_target_powers(ah, chan,
584 pEepData->calTargetPowerCck,
585 AR9287_NUM_2G_CCK_TARGET_POWERS,
586 &targetPowerCckExt, 4, true);
587 ath9k_hw_get_legacy_target_powers(ah, chan,
588 pEepData->calTargetPower2G,
589 AR9287_NUM_2G_20_TARGET_POWERS,
590 &targetPowerOfdmExt, 4, true);
591 }
592 }
593
594 for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
Sujitha55f8582010-06-01 15:14:07 +0530595 bool isHt40CtlMode =
596 (pCtlMode[ctlMode] == CTL_2GHT40) ? true : false;
597
Sujithb5aec952009-08-07 09:45:15 +0530598 if (isHt40CtlMode)
599 freq = centers.synth_center;
600 else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
601 freq = centers.ext_center;
602 else
603 freq = centers.ctl_center;
604
Rajkumar Manoharana261f0e2011-11-22 18:52:00 +0530605 twiceMaxEdgePower = MAX_RATE_POWER;
Sujitha55f8582010-06-01 15:14:07 +0530606 /* Walk through the CTL indices stored in EEPROM */
Sujithb5aec952009-08-07 09:45:15 +0530607 for (i = 0; (i < AR9287_NUM_CTLS) && pEepData->ctlIndex[i]; i++) {
Sujitha55f8582010-06-01 15:14:07 +0530608 struct cal_ctl_edges *pRdEdgesPower;
Sujithb5aec952009-08-07 09:45:15 +0530609
Sujitha55f8582010-06-01 15:14:07 +0530610 /*
611 * Compare test group from regulatory channel list
612 * with test mode from pCtlMode list
613 */
614 if (CMP_CTL || CMP_NO_CTL) {
Sujithb5aec952009-08-07 09:45:15 +0530615 rep = &(pEepData->ctlData[i]);
Sujitha55f8582010-06-01 15:14:07 +0530616 pRdEdgesPower =
617 rep->ctlEdges[ar5416_get_ntxchains(tx_chainmask) - 1];
Sujithb5aec952009-08-07 09:45:15 +0530618
Sujitha55f8582010-06-01 15:14:07 +0530619 twiceMinEdgePower = ath9k_hw_get_max_edge_power(freq,
620 pRdEdgesPower,
621 IS_CHAN_2GHZ(chan),
622 AR5416_NUM_BAND_EDGES);
623
624 if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {
625 twiceMaxEdgePower = min(twiceMaxEdgePower,
626 twiceMinEdgePower);
627 } else {
Sujithb5aec952009-08-07 09:45:15 +0530628 twiceMaxEdgePower = twiceMinEdgePower;
629 break;
630 }
631 }
632 }
633
634 minCtlPower = (u8)min(twiceMaxEdgePower, scaledPower);
635
Sujitha55f8582010-06-01 15:14:07 +0530636 /* Apply ctl mode to correct target power set */
Sujithb5aec952009-08-07 09:45:15 +0530637 switch (pCtlMode[ctlMode]) {
638 case CTL_11B:
Sujitha55f8582010-06-01 15:14:07 +0530639 for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x); i++) {
640 targetPowerCck.tPow2x[i] =
641 (u8)min((u16)targetPowerCck.tPow2x[i],
642 minCtlPower);
Sujithb5aec952009-08-07 09:45:15 +0530643 }
644 break;
645 case CTL_11A:
646 case CTL_11G:
Sujitha55f8582010-06-01 15:14:07 +0530647 for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x); i++) {
648 targetPowerOfdm.tPow2x[i] =
649 (u8)min((u16)targetPowerOfdm.tPow2x[i],
650 minCtlPower);
Sujithb5aec952009-08-07 09:45:15 +0530651 }
652 break;
653 case CTL_5GHT20:
654 case CTL_2GHT20:
Sujitha55f8582010-06-01 15:14:07 +0530655 for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) {
656 targetPowerHt20.tPow2x[i] =
657 (u8)min((u16)targetPowerHt20.tPow2x[i],
658 minCtlPower);
Sujithb5aec952009-08-07 09:45:15 +0530659 }
660 break;
661 case CTL_11B_EXT:
Sujitha55f8582010-06-01 15:14:07 +0530662 targetPowerCckExt.tPow2x[0] =
663 (u8)min((u16)targetPowerCckExt.tPow2x[0],
664 minCtlPower);
Sujithb5aec952009-08-07 09:45:15 +0530665 break;
666 case CTL_11A_EXT:
667 case CTL_11G_EXT:
Sujitha55f8582010-06-01 15:14:07 +0530668 targetPowerOfdmExt.tPow2x[0] =
669 (u8)min((u16)targetPowerOfdmExt.tPow2x[0],
670 minCtlPower);
Sujithb5aec952009-08-07 09:45:15 +0530671 break;
672 case CTL_5GHT40:
673 case CTL_2GHT40:
Sujitha55f8582010-06-01 15:14:07 +0530674 for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
675 targetPowerHt40.tPow2x[i] =
676 (u8)min((u16)targetPowerHt40.tPow2x[i],
677 minCtlPower);
Sujithb5aec952009-08-07 09:45:15 +0530678 }
679 break;
680 default:
681 break;
682 }
683 }
684
Sujitha55f8582010-06-01 15:14:07 +0530685 /* Now set the rates array */
686
Sujithb5aec952009-08-07 09:45:15 +0530687 ratesArray[rate6mb] =
688 ratesArray[rate9mb] =
689 ratesArray[rate12mb] =
690 ratesArray[rate18mb] =
Sujitha55f8582010-06-01 15:14:07 +0530691 ratesArray[rate24mb] = targetPowerOfdm.tPow2x[0];
Sujithb5aec952009-08-07 09:45:15 +0530692
693 ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1];
694 ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2];
695 ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3];
696 ratesArray[rateXr] = targetPowerOfdm.tPow2x[0];
697
698 for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++)
699 ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i];
700
701 if (IS_CHAN_2GHZ(chan)) {
702 ratesArray[rate1l] = targetPowerCck.tPow2x[0];
Sujitha55f8582010-06-01 15:14:07 +0530703 ratesArray[rate2s] =
704 ratesArray[rate2l] = targetPowerCck.tPow2x[1];
705 ratesArray[rate5_5s] =
706 ratesArray[rate5_5l] = targetPowerCck.tPow2x[2];
707 ratesArray[rate11s] =
708 ratesArray[rate11l] = targetPowerCck.tPow2x[3];
Sujithb5aec952009-08-07 09:45:15 +0530709 }
710 if (IS_CHAN_HT40(chan)) {
711 for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++)
712 ratesArray[rateHt40_0 + i] = targetPowerHt40.tPow2x[i];
713
714 ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0];
715 ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0];
716 ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0];
Sujitha55f8582010-06-01 15:14:07 +0530717
Sujithb5aec952009-08-07 09:45:15 +0530718 if (IS_CHAN_2GHZ(chan))
719 ratesArray[rateExtCck] = targetPowerCckExt.tPow2x[0];
720 }
721
Sujitha55f8582010-06-01 15:14:07 +0530722#undef CMP_CTL
723#undef CMP_NO_CTL
Sujithb5aec952009-08-07 09:45:15 +0530724}
725
Sujith16c94ac2010-06-01 15:14:04 +0530726static void ath9k_hw_ar9287_set_txpower(struct ath_hw *ah,
Sujithb5aec952009-08-07 09:45:15 +0530727 struct ath9k_channel *chan, u16 cfgCtl,
728 u8 twiceAntennaReduction,
Felix Fietkaude40f312010-10-20 03:08:53 +0200729 u8 powerLimit, bool test)
Sujithb5aec952009-08-07 09:45:15 +0530730{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700731 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithb5aec952009-08-07 09:45:15 +0530732 struct ar9287_eeprom *pEepData = &ah->eeprom.map9287;
733 struct modal_eep_ar9287_header *pModal = &pEepData->modalHeader;
734 int16_t ratesArray[Ar5416RateSize];
Sujithb5aec952009-08-07 09:45:15 +0530735 u8 ht40PowerIncForPdadc = 2;
736 int i;
737
738 memset(ratesArray, 0, sizeof(ratesArray));
739
740 if ((pEepData->baseEepHeader.version & AR9287_EEP_VER_MINOR_MASK) >=
741 AR9287_EEP_MINOR_VER_2)
742 ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
743
Sujith16c94ac2010-06-01 15:14:04 +0530744 ath9k_hw_set_ar9287_power_per_rate_table(ah, chan,
Sujithb5aec952009-08-07 09:45:15 +0530745 &ratesArray[0], cfgCtl,
746 twiceAntennaReduction,
Sujithb5aec952009-08-07 09:45:15 +0530747 powerLimit);
748
Felix Fietkaue832bf12011-07-27 15:01:03 +0200749 ath9k_hw_set_ar9287_power_cal_table(ah, chan);
Sujithb5aec952009-08-07 09:45:15 +0530750
Felix Fietkaude40f312010-10-20 03:08:53 +0200751 regulatory->max_power_level = 0;
Sujithb5aec952009-08-07 09:45:15 +0530752 for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100753 if (ratesArray[i] > MAX_RATE_POWER)
754 ratesArray[i] = MAX_RATE_POWER;
Felix Fietkaude40f312010-10-20 03:08:53 +0200755
756 if (ratesArray[i] > regulatory->max_power_level)
757 regulatory->max_power_level = ratesArray[i];
Sujithb5aec952009-08-07 09:45:15 +0530758 }
759
Gabor Juhos83722bd2012-04-15 20:38:06 +0200760 ath9k_hw_update_regulatory_maxpower(ah);
761
Felix Fietkaude40f312010-10-20 03:08:53 +0200762 if (test)
763 return;
764
Felix Fietkau1b8714f2011-09-15 14:25:35 +0200765 for (i = 0; i < Ar5416RateSize; i++)
766 ratesArray[i] -= AR9287_PWR_TABLE_OFFSET_DB * 2;
Sujithb5aec952009-08-07 09:45:15 +0530767
Rajkumar Manoharane7fc6332011-03-15 23:11:35 +0530768 ENABLE_REGWRITE_BUFFER(ah);
769
Sujitha55f8582010-06-01 15:14:07 +0530770 /* OFDM power per rate */
Sujithb5aec952009-08-07 09:45:15 +0530771 REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
772 ATH9K_POW_SM(ratesArray[rate18mb], 24)
773 | ATH9K_POW_SM(ratesArray[rate12mb], 16)
774 | ATH9K_POW_SM(ratesArray[rate9mb], 8)
775 | ATH9K_POW_SM(ratesArray[rate6mb], 0));
776
777 REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
778 ATH9K_POW_SM(ratesArray[rate54mb], 24)
779 | ATH9K_POW_SM(ratesArray[rate48mb], 16)
780 | ATH9K_POW_SM(ratesArray[rate36mb], 8)
781 | ATH9K_POW_SM(ratesArray[rate24mb], 0));
782
Sujitha55f8582010-06-01 15:14:07 +0530783 /* CCK power per rate */
Sujithb5aec952009-08-07 09:45:15 +0530784 if (IS_CHAN_2GHZ(chan)) {
785 REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
786 ATH9K_POW_SM(ratesArray[rate2s], 24)
787 | ATH9K_POW_SM(ratesArray[rate2l], 16)
788 | ATH9K_POW_SM(ratesArray[rateXr], 8)
789 | ATH9K_POW_SM(ratesArray[rate1l], 0));
790 REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
791 ATH9K_POW_SM(ratesArray[rate11s], 24)
792 | ATH9K_POW_SM(ratesArray[rate11l], 16)
793 | ATH9K_POW_SM(ratesArray[rate5_5s], 8)
794 | ATH9K_POW_SM(ratesArray[rate5_5l], 0));
795 }
796
Sujitha55f8582010-06-01 15:14:07 +0530797 /* HT20 power per rate */
Sujithb5aec952009-08-07 09:45:15 +0530798 REG_WRITE(ah, AR_PHY_POWER_TX_RATE5,
799 ATH9K_POW_SM(ratesArray[rateHt20_3], 24)
800 | ATH9K_POW_SM(ratesArray[rateHt20_2], 16)
801 | ATH9K_POW_SM(ratesArray[rateHt20_1], 8)
802 | ATH9K_POW_SM(ratesArray[rateHt20_0], 0));
803
804 REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
805 ATH9K_POW_SM(ratesArray[rateHt20_7], 24)
806 | ATH9K_POW_SM(ratesArray[rateHt20_6], 16)
807 | ATH9K_POW_SM(ratesArray[rateHt20_5], 8)
808 | ATH9K_POW_SM(ratesArray[rateHt20_4], 0));
809
Sujitha55f8582010-06-01 15:14:07 +0530810 /* HT40 power per rate */
Sujithb5aec952009-08-07 09:45:15 +0530811 if (IS_CHAN_HT40(chan)) {
Sujith16c94ac2010-06-01 15:14:04 +0530812 if (ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
Sujithb5aec952009-08-07 09:45:15 +0530813 REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
814 ATH9K_POW_SM(ratesArray[rateHt40_3], 24)
815 | ATH9K_POW_SM(ratesArray[rateHt40_2], 16)
816 | ATH9K_POW_SM(ratesArray[rateHt40_1], 8)
817 | ATH9K_POW_SM(ratesArray[rateHt40_0], 0));
818
819 REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
820 ATH9K_POW_SM(ratesArray[rateHt40_7], 24)
821 | ATH9K_POW_SM(ratesArray[rateHt40_6], 16)
822 | ATH9K_POW_SM(ratesArray[rateHt40_5], 8)
823 | ATH9K_POW_SM(ratesArray[rateHt40_4], 0));
824 } else {
825 REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
826 ATH9K_POW_SM(ratesArray[rateHt40_3] +
827 ht40PowerIncForPdadc, 24)
828 | ATH9K_POW_SM(ratesArray[rateHt40_2] +
829 ht40PowerIncForPdadc, 16)
830 | ATH9K_POW_SM(ratesArray[rateHt40_1] +
831 ht40PowerIncForPdadc, 8)
832 | ATH9K_POW_SM(ratesArray[rateHt40_0] +
833 ht40PowerIncForPdadc, 0));
834
835 REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
836 ATH9K_POW_SM(ratesArray[rateHt40_7] +
837 ht40PowerIncForPdadc, 24)
838 | ATH9K_POW_SM(ratesArray[rateHt40_6] +
839 ht40PowerIncForPdadc, 16)
840 | ATH9K_POW_SM(ratesArray[rateHt40_5] +
841 ht40PowerIncForPdadc, 8)
842 | ATH9K_POW_SM(ratesArray[rateHt40_4] +
843 ht40PowerIncForPdadc, 0));
844 }
845
Sujitha55f8582010-06-01 15:14:07 +0530846 /* Dup/Ext power per rate */
Sujithb5aec952009-08-07 09:45:15 +0530847 REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
848 ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
849 | ATH9K_POW_SM(ratesArray[rateExtCck], 16)
850 | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
851 | ATH9K_POW_SM(ratesArray[rateDupCck], 0));
852 }
Lorenzo Bianconic08267d2014-12-30 23:10:18 +0100853
854 /* TPC initializations */
855 if (ah->tpc_enabled) {
856 int ht40_delta;
857
858 ht40_delta = (IS_CHAN_HT40(chan)) ? ht40PowerIncForPdadc : 0;
859 ar5008_hw_init_rate_txpower(ah, ratesArray, chan, ht40_delta);
860 /* Enable TPC */
861 REG_WRITE(ah, AR_PHY_POWER_TX_RATE_MAX,
862 MAX_RATE_POWER | AR_PHY_POWER_TX_RATE_MAX_TPC_ENABLE);
863 } else {
864 /* Disable TPC */
865 REG_WRITE(ah, AR_PHY_POWER_TX_RATE_MAX, MAX_RATE_POWER);
866 }
867
Rajkumar Manoharane7fc6332011-03-15 23:11:35 +0530868 REGWRITE_BUFFER_FLUSH(ah);
Sujithb5aec952009-08-07 09:45:15 +0530869}
870
Sujith16c94ac2010-06-01 15:14:04 +0530871static void ath9k_hw_ar9287_set_board_values(struct ath_hw *ah,
Sujithb5aec952009-08-07 09:45:15 +0530872 struct ath9k_channel *chan)
873{
874 struct ar9287_eeprom *eep = &ah->eeprom.map9287;
875 struct modal_eep_ar9287_header *pModal = &eep->modalHeader;
Sujith79d7f4b2010-06-01 15:14:06 +0530876 u32 regChainOffset, regval;
Sujithb5aec952009-08-07 09:45:15 +0530877 u8 txRxAttenLocal;
Rajkumar Manoharan2d05a0c2011-04-11 20:22:28 +0530878 int i;
Sujithb5aec952009-08-07 09:45:15 +0530879
880 pModal = &eep->modalHeader;
881
Felix Fietkaudf3c8b22010-12-12 00:51:11 +0100882 REG_WRITE(ah, AR_PHY_SWITCH_COM, pModal->antCtrlCommon);
Sujithb5aec952009-08-07 09:45:15 +0530883
884 for (i = 0; i < AR9287_MAX_CHAINS; i++) {
885 regChainOffset = i * 0x1000;
886
887 REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
888 pModal->antCtrlChain[i]);
889
890 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
891 (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset)
892 & ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
893 AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
894 SM(pModal->iqCalICh[i],
895 AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
896 SM(pModal->iqCalQCh[i],
897 AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
898
899 txRxAttenLocal = pModal->txRxAttenCh[i];
900
901 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
902 AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN,
903 pModal->bswMargin[i]);
904 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
905 AR_PHY_GAIN_2GHZ_XATTEN1_DB,
906 pModal->bswAtten[i]);
907 REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
908 AR9280_PHY_RXGAIN_TXRX_ATTEN,
909 txRxAttenLocal);
910 REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
911 AR9280_PHY_RXGAIN_TXRX_MARGIN,
912 pModal->rxTxMarginCh[i]);
913 }
914
915
916 if (IS_CHAN_HT40(chan))
917 REG_RMW_FIELD(ah, AR_PHY_SETTLING,
918 AR_PHY_SETTLING_SWITCH, pModal->swSettleHt40);
919 else
920 REG_RMW_FIELD(ah, AR_PHY_SETTLING,
921 AR_PHY_SETTLING_SWITCH, pModal->switchSettling);
922
923 REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
924 AR_PHY_DESIRED_SZ_ADC, pModal->adcDesiredSize);
925
926 REG_WRITE(ah, AR_PHY_RF_CTL4,
927 SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF)
928 | SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAB_OFF)
929 | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAA_ON)
930 | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAB_ON));
931
932 REG_RMW_FIELD(ah, AR_PHY_RF_CTL3,
933 AR_PHY_TX_END_TO_A2_RX_ON, pModal->txEndToRxOn);
934
935 REG_RMW_FIELD(ah, AR_PHY_CCA,
936 AR9280_PHY_CCA_THRESH62, pModal->thresh62);
937 REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0,
938 AR_PHY_EXT_CCA0_THRESH62, pModal->thresh62);
939
Sujith79d7f4b2010-06-01 15:14:06 +0530940 regval = REG_READ(ah, AR9287_AN_RF2G3_CH0);
941 regval &= ~(AR9287_AN_RF2G3_DB1 |
942 AR9287_AN_RF2G3_DB2 |
943 AR9287_AN_RF2G3_OB_CCK |
944 AR9287_AN_RF2G3_OB_PSK |
945 AR9287_AN_RF2G3_OB_QAM |
946 AR9287_AN_RF2G3_OB_PAL_OFF);
947 regval |= (SM(pModal->db1, AR9287_AN_RF2G3_DB1) |
948 SM(pModal->db2, AR9287_AN_RF2G3_DB2) |
949 SM(pModal->ob_cck, AR9287_AN_RF2G3_OB_CCK) |
950 SM(pModal->ob_psk, AR9287_AN_RF2G3_OB_PSK) |
951 SM(pModal->ob_qam, AR9287_AN_RF2G3_OB_QAM) |
952 SM(pModal->ob_pal_off, AR9287_AN_RF2G3_OB_PAL_OFF));
Sujithb5aec952009-08-07 09:45:15 +0530953
Sujith79d7f4b2010-06-01 15:14:06 +0530954 ath9k_hw_analog_shift_regwrite(ah, AR9287_AN_RF2G3_CH0, regval);
955
956 regval = REG_READ(ah, AR9287_AN_RF2G3_CH1);
957 regval &= ~(AR9287_AN_RF2G3_DB1 |
958 AR9287_AN_RF2G3_DB2 |
959 AR9287_AN_RF2G3_OB_CCK |
960 AR9287_AN_RF2G3_OB_PSK |
961 AR9287_AN_RF2G3_OB_QAM |
962 AR9287_AN_RF2G3_OB_PAL_OFF);
963 regval |= (SM(pModal->db1, AR9287_AN_RF2G3_DB1) |
964 SM(pModal->db2, AR9287_AN_RF2G3_DB2) |
965 SM(pModal->ob_cck, AR9287_AN_RF2G3_OB_CCK) |
966 SM(pModal->ob_psk, AR9287_AN_RF2G3_OB_PSK) |
967 SM(pModal->ob_qam, AR9287_AN_RF2G3_OB_QAM) |
968 SM(pModal->ob_pal_off, AR9287_AN_RF2G3_OB_PAL_OFF));
969
970 ath9k_hw_analog_shift_regwrite(ah, AR9287_AN_RF2G3_CH1, regval);
Sujithb5aec952009-08-07 09:45:15 +0530971
972 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
973 AR_PHY_TX_END_DATA_START, pModal->txFrameToDataStart);
974 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
975 AR_PHY_TX_END_PA_ON, pModal->txFrameToPaOn);
976
977 ath9k_hw_analog_shift_rmw(ah, AR9287_AN_TOP2,
978 AR9287_AN_TOP2_XPABIAS_LVL,
979 AR9287_AN_TOP2_XPABIAS_LVL_S,
980 pModal->xpaBiasLvl);
981}
982
Sujith16c94ac2010-06-01 15:14:04 +0530983static u16 ath9k_hw_ar9287_get_spur_channel(struct ath_hw *ah,
Sujithb5aec952009-08-07 09:45:15 +0530984 u16 i, bool is2GHz)
985{
Felix Fietkauae0c4032013-12-14 18:03:41 +0100986 return ah->eeprom.map9287.modalHeader.spurChans[i].spurChan;
Sujithb5aec952009-08-07 09:45:15 +0530987}
988
Luis R. Rodriguez0b8f6f2b12010-04-15 17:39:12 -0400989const struct eeprom_ops eep_ar9287_ops = {
Sujith16c94ac2010-06-01 15:14:04 +0530990 .check_eeprom = ath9k_hw_ar9287_check_eeprom,
991 .get_eeprom = ath9k_hw_ar9287_get_eeprom,
992 .fill_eeprom = ath9k_hw_ar9287_fill_eeprom,
Rajkumar Manoharan49c995202011-07-29 17:38:10 +0530993 .dump_eeprom = ath9k_hw_ar9287_dump_eeprom,
Sujith16c94ac2010-06-01 15:14:04 +0530994 .get_eeprom_ver = ath9k_hw_ar9287_get_eeprom_ver,
995 .get_eeprom_rev = ath9k_hw_ar9287_get_eeprom_rev,
Sujith16c94ac2010-06-01 15:14:04 +0530996 .set_board_values = ath9k_hw_ar9287_set_board_values,
Sujith16c94ac2010-06-01 15:14:04 +0530997 .set_txpower = ath9k_hw_ar9287_set_txpower,
998 .get_spur_channel = ath9k_hw_ar9287_get_spur_channel
Sujithb5aec952009-08-07 09:45:15 +0530999};