blob: 21f180db23810dddf52ffd2eed2364d75e3cb82d [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;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070036 struct ath_common *common = ath9k_hw_common(ah);
Sujithb5aec952009-08-07 09:45:15 +053037 u16 *eep_data;
Sujith Manoharan04cf53f2011-01-04 13:17:28 +053038 int addr, eep_start_loc = AR9287_EEP_START_LOC;
Sujithb5aec952009-08-07 09:45:15 +053039 eep_data = (u16 *)eep;
40
Sujith Manoharan04cf53f2011-01-04 13:17:28 +053041 for (addr = 0; addr < SIZE_EEPROM_AR9287; addr++) {
Sujith16c94ac2010-06-01 15:14:04 +053042 if (!ath9k_hw_nvram_read(common, addr + eep_start_loc,
43 eep_data)) {
Joe Perches226afe62010-12-02 19:12:37 -080044 ath_dbg(common, ATH_DBG_EEPROM,
45 "Unable to read eeprom region\n");
Sujithb5aec952009-08-07 09:45:15 +053046 return false;
47 }
48 eep_data++;
49 }
Sujith16c94ac2010-06-01 15:14:04 +053050
Sujithb5aec952009-08-07 09:45:15 +053051 return true;
52}
53
Sujith Manoharan04cf53f2011-01-04 13:17:28 +053054static bool __ath9k_hw_usb_ar9287_fill_eeprom(struct ath_hw *ah)
55{
56 u16 *eep_data = (u16 *)&ah->eeprom.map9287;
57
58 ath9k_hw_usb_gen_fill_eeprom(ah, eep_data,
59 AR9287_HTC_EEP_START_LOC,
60 SIZE_EEPROM_AR9287);
61 return true;
62}
63
64static bool ath9k_hw_ar9287_fill_eeprom(struct ath_hw *ah)
65{
66 struct ath_common *common = ath9k_hw_common(ah);
67
68 if (!ath9k_hw_use_flash(ah)) {
69 ath_dbg(common, ATH_DBG_EEPROM,
70 "Reading from EEPROM, not flash\n");
71 }
72
73 if (common->bus_ops->ath_bus_type == ATH_USB)
74 return __ath9k_hw_usb_ar9287_fill_eeprom(ah);
75 else
76 return __ath9k_hw_ar9287_fill_eeprom(ah);
77}
78
Rajkumar Manoharan49c995202011-07-29 17:38:10 +053079#if defined(CONFIG_ATH9K_DEBUGFS) || defined(CONFIG_ATH9K_HTC_DEBUGFS)
80static u32 ar9287_dump_modal_eeprom(char *buf, u32 len, u32 size,
81 struct modal_eep_ar9287_header *modal_hdr)
82{
83 PR_EEP("Chain0 Ant. Control", modal_hdr->antCtrlChain[0]);
84 PR_EEP("Chain1 Ant. Control", modal_hdr->antCtrlChain[1]);
85 PR_EEP("Ant. Common Control", modal_hdr->antCtrlCommon);
86 PR_EEP("Chain0 Ant. Gain", modal_hdr->antennaGainCh[0]);
87 PR_EEP("Chain1 Ant. Gain", modal_hdr->antennaGainCh[1]);
88 PR_EEP("Switch Settle", modal_hdr->switchSettling);
89 PR_EEP("Chain0 TxRxAtten", modal_hdr->txRxAttenCh[0]);
90 PR_EEP("Chain1 TxRxAtten", modal_hdr->txRxAttenCh[1]);
91 PR_EEP("Chain0 RxTxMargin", modal_hdr->rxTxMarginCh[0]);
92 PR_EEP("Chain1 RxTxMargin", modal_hdr->rxTxMarginCh[1]);
93 PR_EEP("ADC Desired size", modal_hdr->adcDesiredSize);
94 PR_EEP("txEndToXpaOff", modal_hdr->txEndToXpaOff);
95 PR_EEP("txEndToRxOn", modal_hdr->txEndToRxOn);
96 PR_EEP("txFrameToXpaOn", modal_hdr->txFrameToXpaOn);
97 PR_EEP("CCA Threshold)", modal_hdr->thresh62);
98 PR_EEP("Chain0 NF Threshold", modal_hdr->noiseFloorThreshCh[0]);
99 PR_EEP("Chain1 NF Threshold", modal_hdr->noiseFloorThreshCh[1]);
100 PR_EEP("xpdGain", modal_hdr->xpdGain);
101 PR_EEP("External PD", modal_hdr->xpd);
102 PR_EEP("Chain0 I Coefficient", modal_hdr->iqCalICh[0]);
103 PR_EEP("Chain1 I Coefficient", modal_hdr->iqCalICh[1]);
104 PR_EEP("Chain0 Q Coefficient", modal_hdr->iqCalQCh[0]);
105 PR_EEP("Chain1 Q Coefficient", modal_hdr->iqCalQCh[1]);
106 PR_EEP("pdGainOverlap", modal_hdr->pdGainOverlap);
107 PR_EEP("xPA Bias Level", modal_hdr->xpaBiasLvl);
108 PR_EEP("txFrameToDataStart", modal_hdr->txFrameToDataStart);
109 PR_EEP("txFrameToPaOn", modal_hdr->txFrameToPaOn);
110 PR_EEP("HT40 Power Inc.", modal_hdr->ht40PowerIncForPdadc);
111 PR_EEP("Chain0 bswAtten", modal_hdr->bswAtten[0]);
112 PR_EEP("Chain1 bswAtten", modal_hdr->bswAtten[1]);
113 PR_EEP("Chain0 bswMargin", modal_hdr->bswMargin[0]);
114 PR_EEP("Chain1 bswMargin", modal_hdr->bswMargin[1]);
115 PR_EEP("HT40 Switch Settle", modal_hdr->swSettleHt40);
116 PR_EEP("AR92x7 Version", modal_hdr->version);
117 PR_EEP("DriverBias1", modal_hdr->db1);
118 PR_EEP("DriverBias2", modal_hdr->db1);
119 PR_EEP("CCK OutputBias", modal_hdr->ob_cck);
120 PR_EEP("PSK OutputBias", modal_hdr->ob_psk);
121 PR_EEP("QAM OutputBias", modal_hdr->ob_qam);
122 PR_EEP("PAL_OFF OutputBias", modal_hdr->ob_pal_off);
123
124 return len;
125}
126
127static u32 ath9k_hw_ar9287_dump_eeprom(struct ath_hw *ah, bool dump_base_hdr,
128 u8 *buf, u32 len, u32 size)
129{
130 struct ar9287_eeprom *eep = &ah->eeprom.map9287;
131 struct base_eep_ar9287_header *pBase = &eep->baseEepHeader;
132
133 if (!dump_base_hdr) {
134 len += snprintf(buf + len, size - len,
135 "%20s :\n", "2GHz modal Header");
136 len += ar9287_dump_modal_eeprom(buf, len, size,
137 &eep->modalHeader);
138 goto out;
139 }
140
141 PR_EEP("Major Version", pBase->version >> 12);
142 PR_EEP("Minor Version", pBase->version & 0xFFF);
143 PR_EEP("Checksum", pBase->checksum);
144 PR_EEP("Length", pBase->length);
145 PR_EEP("RegDomain1", pBase->regDmn[0]);
146 PR_EEP("RegDomain2", pBase->regDmn[1]);
147 PR_EEP("TX Mask", pBase->txMask);
148 PR_EEP("RX Mask", pBase->rxMask);
149 PR_EEP("Allow 5GHz", !!(pBase->opCapFlags & AR5416_OPFLAGS_11A));
150 PR_EEP("Allow 2GHz", !!(pBase->opCapFlags & AR5416_OPFLAGS_11G));
151 PR_EEP("Disable 2GHz HT20", !!(pBase->opCapFlags &
152 AR5416_OPFLAGS_N_2G_HT20));
153 PR_EEP("Disable 2GHz HT40", !!(pBase->opCapFlags &
154 AR5416_OPFLAGS_N_2G_HT40));
155 PR_EEP("Disable 5Ghz HT20", !!(pBase->opCapFlags &
156 AR5416_OPFLAGS_N_5G_HT20));
157 PR_EEP("Disable 5Ghz HT40", !!(pBase->opCapFlags &
158 AR5416_OPFLAGS_N_5G_HT40));
159 PR_EEP("Big Endian", !!(pBase->eepMisc & 0x01));
160 PR_EEP("Cal Bin Major Ver", (pBase->binBuildNumber >> 24) & 0xFF);
161 PR_EEP("Cal Bin Minor Ver", (pBase->binBuildNumber >> 16) & 0xFF);
162 PR_EEP("Cal Bin Build", (pBase->binBuildNumber >> 8) & 0xFF);
163 PR_EEP("Power Table Offset", pBase->pwrTableOffset);
164 PR_EEP("OpenLoop Power Ctrl", pBase->openLoopPwrCntl);
165
166 len += snprintf(buf + len, size - len, "%20s : %pM\n", "MacAddress",
167 pBase->macAddr);
168
169out:
170 if (len > size)
171 len = size;
172
173 return len;
174}
175#else
176static u32 ath9k_hw_ar9287_dump_eeprom(struct ath_hw *ah, bool dump_base_hdr,
177 u8 *buf, u32 len, u32 size)
178{
179 return 0;
180}
181#endif
182
183
Sujith16c94ac2010-06-01 15:14:04 +0530184static int ath9k_hw_ar9287_check_eeprom(struct ath_hw *ah)
Sujithb5aec952009-08-07 09:45:15 +0530185{
186 u32 sum = 0, el, integer;
187 u16 temp, word, magic, magic2, *eepdata;
188 int i, addr;
189 bool need_swap = false;
190 struct ar9287_eeprom *eep = &ah->eeprom.map9287;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700191 struct ath_common *common = ath9k_hw_common(ah);
Sujithb5aec952009-08-07 09:45:15 +0530192
193 if (!ath9k_hw_use_flash(ah)) {
Sujith16c94ac2010-06-01 15:14:04 +0530194 if (!ath9k_hw_nvram_read(common, AR5416_EEPROM_MAGIC_OFFSET,
195 &magic)) {
Joe Perches38002762010-12-02 19:12:36 -0800196 ath_err(common, "Reading Magic # failed\n");
Sujithb5aec952009-08-07 09:45:15 +0530197 return false;
198 }
199
Joe Perches226afe62010-12-02 19:12:37 -0800200 ath_dbg(common, ATH_DBG_EEPROM,
201 "Read Magic = 0x%04X\n", magic);
Sujith16c94ac2010-06-01 15:14:04 +0530202
Sujithb5aec952009-08-07 09:45:15 +0530203 if (magic != AR5416_EEPROM_MAGIC) {
204 magic2 = swab16(magic);
205
206 if (magic2 == AR5416_EEPROM_MAGIC) {
207 need_swap = true;
208 eepdata = (u16 *)(&ah->eeprom);
209
Sujith Manoharan04cf53f2011-01-04 13:17:28 +0530210 for (addr = 0; addr < SIZE_EEPROM_AR9287; addr++) {
Sujithb5aec952009-08-07 09:45:15 +0530211 temp = swab16(*eepdata);
212 *eepdata = temp;
213 eepdata++;
214 }
215 } else {
Joe Perches38002762010-12-02 19:12:36 -0800216 ath_err(common,
217 "Invalid EEPROM Magic. Endianness mismatch.\n");
Sujithb5aec952009-08-07 09:45:15 +0530218 return -EINVAL;
219 }
220 }
221 }
Sujith16c94ac2010-06-01 15:14:04 +0530222
Joe Perches226afe62010-12-02 19:12:37 -0800223 ath_dbg(common, ATH_DBG_EEPROM, "need_swap = %s.\n",
224 need_swap ? "True" : "False");
Sujithb5aec952009-08-07 09:45:15 +0530225
226 if (need_swap)
227 el = swab16(ah->eeprom.map9287.baseEepHeader.length);
228 else
229 el = ah->eeprom.map9287.baseEepHeader.length;
230
231 if (el > sizeof(struct ar9287_eeprom))
232 el = sizeof(struct ar9287_eeprom) / sizeof(u16);
233 else
234 el = el / sizeof(u16);
235
236 eepdata = (u16 *)(&ah->eeprom);
Sujith16c94ac2010-06-01 15:14:04 +0530237
Sujithb5aec952009-08-07 09:45:15 +0530238 for (i = 0; i < el; i++)
239 sum ^= *eepdata++;
240
241 if (need_swap) {
242 word = swab16(eep->baseEepHeader.length);
243 eep->baseEepHeader.length = word;
244
245 word = swab16(eep->baseEepHeader.checksum);
246 eep->baseEepHeader.checksum = word;
247
248 word = swab16(eep->baseEepHeader.version);
249 eep->baseEepHeader.version = word;
250
251 word = swab16(eep->baseEepHeader.regDmn[0]);
252 eep->baseEepHeader.regDmn[0] = word;
253
254 word = swab16(eep->baseEepHeader.regDmn[1]);
255 eep->baseEepHeader.regDmn[1] = word;
256
257 word = swab16(eep->baseEepHeader.rfSilent);
258 eep->baseEepHeader.rfSilent = word;
259
260 word = swab16(eep->baseEepHeader.blueToothOptions);
261 eep->baseEepHeader.blueToothOptions = word;
262
263 word = swab16(eep->baseEepHeader.deviceCap);
264 eep->baseEepHeader.deviceCap = word;
265
266 integer = swab32(eep->modalHeader.antCtrlCommon);
267 eep->modalHeader.antCtrlCommon = integer;
268
269 for (i = 0; i < AR9287_MAX_CHAINS; i++) {
270 integer = swab32(eep->modalHeader.antCtrlChain[i]);
271 eep->modalHeader.antCtrlChain[i] = integer;
272 }
273
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100274 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujithb5aec952009-08-07 09:45:15 +0530275 word = swab16(eep->modalHeader.spurChans[i].spurChan);
276 eep->modalHeader.spurChans[i].spurChan = word;
277 }
278 }
279
280 if (sum != 0xffff || ah->eep_ops->get_eeprom_ver(ah) != AR9287_EEP_VER
281 || ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_NO_BACK_VER) {
Joe Perches38002762010-12-02 19:12:36 -0800282 ath_err(common, "Bad EEPROM checksum 0x%x or revision 0x%04x\n",
283 sum, ah->eep_ops->get_eeprom_ver(ah));
Sujithb5aec952009-08-07 09:45:15 +0530284 return -EINVAL;
285 }
286
287 return 0;
288}
289
Sujith16c94ac2010-06-01 15:14:04 +0530290static u32 ath9k_hw_ar9287_get_eeprom(struct ath_hw *ah,
Sujithb5aec952009-08-07 09:45:15 +0530291 enum eeprom_param param)
292{
293 struct ar9287_eeprom *eep = &ah->eeprom.map9287;
294 struct modal_eep_ar9287_header *pModal = &eep->modalHeader;
295 struct base_eep_ar9287_header *pBase = &eep->baseEepHeader;
296 u16 ver_minor;
297
298 ver_minor = pBase->version & AR9287_EEP_VER_MINOR_MASK;
Sujith16c94ac2010-06-01 15:14:04 +0530299
Sujithb5aec952009-08-07 09:45:15 +0530300 switch (param) {
301 case EEP_NFTHRESH_2:
302 return pModal->noiseFloorThreshCh[0];
Luis R. Rodriguez49101672010-04-15 17:39:13 -0400303 case EEP_MAC_LSW:
Pavel Roskin78fa99a2011-07-15 19:06:33 -0400304 return get_unaligned_be16(pBase->macAddr);
Luis R. Rodriguez49101672010-04-15 17:39:13 -0400305 case EEP_MAC_MID:
Pavel Roskin78fa99a2011-07-15 19:06:33 -0400306 return get_unaligned_be16(pBase->macAddr + 2);
Luis R. Rodriguez49101672010-04-15 17:39:13 -0400307 case EEP_MAC_MSW:
Pavel Roskin78fa99a2011-07-15 19:06:33 -0400308 return get_unaligned_be16(pBase->macAddr + 4);
Sujithb5aec952009-08-07 09:45:15 +0530309 case EEP_REG_0:
310 return pBase->regDmn[0];
311 case EEP_REG_1:
312 return pBase->regDmn[1];
313 case EEP_OP_CAP:
314 return pBase->deviceCap;
315 case EEP_OP_MODE:
316 return pBase->opCapFlags;
317 case EEP_RF_SILENT:
318 return pBase->rfSilent;
319 case EEP_MINOR_REV:
320 return ver_minor;
321 case EEP_TX_MASK:
322 return pBase->txMask;
323 case EEP_RX_MASK:
324 return pBase->rxMask;
325 case EEP_DEV_TYPE:
326 return pBase->deviceType;
327 case EEP_OL_PWRCTRL:
328 return pBase->openLoopPwrCntl;
329 case EEP_TEMPSENSE_SLOPE:
330 if (ver_minor >= AR9287_EEP_MINOR_VER_2)
331 return pBase->tempSensSlope;
332 else
333 return 0;
334 case EEP_TEMPSENSE_SLOPE_PAL_ON:
335 if (ver_minor >= AR9287_EEP_MINOR_VER_3)
336 return pBase->tempSensSlopePalOn;
337 else
338 return 0;
339 default:
340 return 0;
341 }
342}
343
Sujithb5aec952009-08-07 09:45:15 +0530344static void ar9287_eeprom_get_tx_gain_index(struct ath_hw *ah,
345 struct ath9k_channel *chan,
346 struct cal_data_op_loop_ar9287 *pRawDatasetOpLoop,
Sujith16c94ac2010-06-01 15:14:04 +0530347 u8 *pCalChans, u16 availPiers, int8_t *pPwr)
Sujithb5aec952009-08-07 09:45:15 +0530348{
Sujith16c94ac2010-06-01 15:14:04 +0530349 u16 idxL = 0, idxR = 0, numPiers;
Sujithb5aec952009-08-07 09:45:15 +0530350 bool match;
351 struct chan_centers centers;
352
353 ath9k_hw_get_channel_centers(ah, chan, &centers);
354
355 for (numPiers = 0; numPiers < availPiers; numPiers++) {
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100356 if (pCalChans[numPiers] == AR5416_BCHAN_UNUSED)
Sujithb5aec952009-08-07 09:45:15 +0530357 break;
358 }
359
360 match = ath9k_hw_get_lower_upper_index(
Sujitha55f8582010-06-01 15:14:07 +0530361 (u8)FREQ2FBIN(centers.synth_center, IS_CHAN_2GHZ(chan)),
362 pCalChans, numPiers, &idxL, &idxR);
Sujithb5aec952009-08-07 09:45:15 +0530363
364 if (match) {
Vivek Natarajand4fe5af2009-08-14 11:32:04 +0530365 *pPwr = (int8_t) pRawDatasetOpLoop[idxL].pwrPdg[0][0];
Sujithb5aec952009-08-07 09:45:15 +0530366 } else {
Vivek Natarajand4fe5af2009-08-14 11:32:04 +0530367 *pPwr = ((int8_t) pRawDatasetOpLoop[idxL].pwrPdg[0][0] +
Sujith16c94ac2010-06-01 15:14:04 +0530368 (int8_t) pRawDatasetOpLoop[idxR].pwrPdg[0][0])/2;
Sujithb5aec952009-08-07 09:45:15 +0530369 }
370
Sujithb5aec952009-08-07 09:45:15 +0530371}
372
373static void ar9287_eeprom_olpc_set_pdadcs(struct ath_hw *ah,
374 int32_t txPower, u16 chain)
375{
376 u32 tmpVal;
377 u32 a;
378
Sujith16c94ac2010-06-01 15:14:04 +0530379 /* Enable OLPC for chain 0 */
380
Sujithb5aec952009-08-07 09:45:15 +0530381 tmpVal = REG_READ(ah, 0xa270);
382 tmpVal = tmpVal & 0xFCFFFFFF;
383 tmpVal = tmpVal | (0x3 << 24);
384 REG_WRITE(ah, 0xa270, tmpVal);
385
Sujith16c94ac2010-06-01 15:14:04 +0530386 /* Enable OLPC for chain 1 */
387
Sujithb5aec952009-08-07 09:45:15 +0530388 tmpVal = REG_READ(ah, 0xb270);
389 tmpVal = tmpVal & 0xFCFFFFFF;
390 tmpVal = tmpVal | (0x3 << 24);
391 REG_WRITE(ah, 0xb270, tmpVal);
392
Sujith16c94ac2010-06-01 15:14:04 +0530393 /* Write the OLPC ref power for chain 0 */
394
Sujithb5aec952009-08-07 09:45:15 +0530395 if (chain == 0) {
396 tmpVal = REG_READ(ah, 0xa398);
397 tmpVal = tmpVal & 0xff00ffff;
398 a = (txPower)&0xff;
399 tmpVal = tmpVal | (a << 16);
400 REG_WRITE(ah, 0xa398, tmpVal);
401 }
402
Sujith16c94ac2010-06-01 15:14:04 +0530403 /* Write the OLPC ref power for chain 1 */
404
Sujithb5aec952009-08-07 09:45:15 +0530405 if (chain == 1) {
406 tmpVal = REG_READ(ah, 0xb398);
407 tmpVal = tmpVal & 0xff00ffff;
408 a = (txPower)&0xff;
409 tmpVal = tmpVal | (a << 16);
410 REG_WRITE(ah, 0xb398, tmpVal);
411 }
412}
413
Sujith16c94ac2010-06-01 15:14:04 +0530414static void ath9k_hw_set_ar9287_power_cal_table(struct ath_hw *ah,
Felix Fietkaue832bf12011-07-27 15:01:03 +0200415 struct ath9k_channel *chan)
Sujithb5aec952009-08-07 09:45:15 +0530416{
417 struct cal_data_per_freq_ar9287 *pRawDataset;
418 struct cal_data_op_loop_ar9287 *pRawDatasetOpenLoop;
Sujith16c94ac2010-06-01 15:14:04 +0530419 u8 *pCalBChans = NULL;
Sujithb5aec952009-08-07 09:45:15 +0530420 u16 pdGainOverlap_t2;
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100421 u8 pdadcValues[AR5416_NUM_PDADC_VALUES];
422 u16 gainBoundaries[AR5416_PD_GAINS_IN_MASK];
Sujithb5aec952009-08-07 09:45:15 +0530423 u16 numPiers = 0, i, j;
Sujithb5aec952009-08-07 09:45:15 +0530424 u16 numXpdGain, xpdMask;
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100425 u16 xpdGainValues[AR5416_NUM_PD_GAINS] = {0, 0, 0, 0};
Sujitha55f8582010-06-01 15:14:07 +0530426 u32 reg32, regOffset, regChainOffset, regval;
Sujith Manoharan0ff2b5c2011-04-20 11:00:34 +0530427 int16_t diff = 0;
Sujithb5aec952009-08-07 09:45:15 +0530428 struct ar9287_eeprom *pEepData = &ah->eeprom.map9287;
Sujith16c94ac2010-06-01 15:14:04 +0530429
Sujithb5aec952009-08-07 09:45:15 +0530430 xpdMask = pEepData->modalHeader.xpdGain;
Sujith16c94ac2010-06-01 15:14:04 +0530431
Sujithb5aec952009-08-07 09:45:15 +0530432 if ((pEepData->baseEepHeader.version & AR9287_EEP_VER_MINOR_MASK) >=
Sujitha55f8582010-06-01 15:14:07 +0530433 AR9287_EEP_MINOR_VER_2)
Sujithb5aec952009-08-07 09:45:15 +0530434 pdGainOverlap_t2 = pEepData->modalHeader.pdGainOverlap;
435 else
436 pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5),
437 AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
438
439 if (IS_CHAN_2GHZ(chan)) {
440 pCalBChans = pEepData->calFreqPier2G;
441 numPiers = AR9287_NUM_2G_CAL_PIERS;
Sujith16c94ac2010-06-01 15:14:04 +0530442 if (ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
Sujithb5aec952009-08-07 09:45:15 +0530443 pRawDatasetOpenLoop =
Sujitha55f8582010-06-01 15:14:07 +0530444 (struct cal_data_op_loop_ar9287 *)pEepData->calPierData2G[0];
Sujithb5aec952009-08-07 09:45:15 +0530445 ah->initPDADC = pRawDatasetOpenLoop->vpdPdg[0][0];
446 }
447 }
448
449 numXpdGain = 0;
Sujith16c94ac2010-06-01 15:14:04 +0530450
Sujitha55f8582010-06-01 15:14:07 +0530451 /* Calculate the value of xpdgains from the xpdGain Mask */
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100452 for (i = 1; i <= AR5416_PD_GAINS_IN_MASK; i++) {
453 if ((xpdMask >> (AR5416_PD_GAINS_IN_MASK - i)) & 1) {
454 if (numXpdGain >= AR5416_NUM_PD_GAINS)
Sujithb5aec952009-08-07 09:45:15 +0530455 break;
456 xpdGainValues[numXpdGain] =
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100457 (u16)(AR5416_PD_GAINS_IN_MASK-i);
Sujithb5aec952009-08-07 09:45:15 +0530458 numXpdGain++;
459 }
460 }
461
462 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
463 (numXpdGain - 1) & 0x3);
464 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,
465 xpdGainValues[0]);
466 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
467 xpdGainValues[1]);
468 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3,
469 xpdGainValues[2]);
470
471 for (i = 0; i < AR9287_MAX_CHAINS; i++) {
472 regChainOffset = i * 0x1000;
Sujitha55f8582010-06-01 15:14:07 +0530473
Sujithb5aec952009-08-07 09:45:15 +0530474 if (pEepData->baseEepHeader.txMask & (1 << i)) {
Sujitha55f8582010-06-01 15:14:07 +0530475 pRawDatasetOpenLoop =
476 (struct cal_data_op_loop_ar9287 *)pEepData->calPierData2G[i];
477
Sujith16c94ac2010-06-01 15:14:04 +0530478 if (ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
Sujithb5aec952009-08-07 09:45:15 +0530479 int8_t txPower;
480 ar9287_eeprom_get_tx_gain_index(ah, chan,
Sujitha55f8582010-06-01 15:14:07 +0530481 pRawDatasetOpenLoop,
482 pCalBChans, numPiers,
483 &txPower);
Sujithb5aec952009-08-07 09:45:15 +0530484 ar9287_eeprom_olpc_set_pdadcs(ah, txPower, i);
485 } else {
486 pRawDataset =
487 (struct cal_data_per_freq_ar9287 *)
488 pEepData->calPierData2G[i];
Sujitha55f8582010-06-01 15:14:07 +0530489
Felix Fietkau940cd2c2010-12-12 00:51:10 +0100490 ath9k_hw_get_gain_boundaries_pdadcs(ah, chan,
Sujitha55f8582010-06-01 15:14:07 +0530491 pRawDataset,
492 pCalBChans, numPiers,
493 pdGainOverlap_t2,
Sujitha55f8582010-06-01 15:14:07 +0530494 gainBoundaries,
495 pdadcValues,
496 numXpdGain);
Sujithb5aec952009-08-07 09:45:15 +0530497 }
498
Rajkumar Manoharane7fc6332011-03-15 23:11:35 +0530499 ENABLE_REGWRITE_BUFFER(ah);
500
Sujithb5aec952009-08-07 09:45:15 +0530501 if (i == 0) {
Sujitha55f8582010-06-01 15:14:07 +0530502 if (!ath9k_hw_ar9287_get_eeprom(ah,
503 EEP_OL_PWRCTRL)) {
504
505 regval = SM(pdGainOverlap_t2,
506 AR_PHY_TPCRG5_PD_GAIN_OVERLAP)
507 | SM(gainBoundaries[0],
508 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1)
509 | SM(gainBoundaries[1],
510 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2)
511 | SM(gainBoundaries[2],
512 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3)
513 | SM(gainBoundaries[3],
514 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4);
515
516 REG_WRITE(ah,
517 AR_PHY_TPCRG5 + regChainOffset,
518 regval);
Sujithb5aec952009-08-07 09:45:15 +0530519 }
520 }
521
522 if ((int32_t)AR9287_PWR_TABLE_OFFSET_DB !=
Sujitha55f8582010-06-01 15:14:07 +0530523 pEepData->baseEepHeader.pwrTableOffset) {
524 diff = (u16)(pEepData->baseEepHeader.pwrTableOffset -
525 (int32_t)AR9287_PWR_TABLE_OFFSET_DB);
Sujithb5aec952009-08-07 09:45:15 +0530526 diff *= 2;
527
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100528 for (j = 0; j < ((u16)AR5416_NUM_PDADC_VALUES-diff); j++)
Sujithb5aec952009-08-07 09:45:15 +0530529 pdadcValues[j] = pdadcValues[j+diff];
530
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100531 for (j = (u16)(AR5416_NUM_PDADC_VALUES-diff);
532 j < AR5416_NUM_PDADC_VALUES; j++)
Sujithb5aec952009-08-07 09:45:15 +0530533 pdadcValues[j] =
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100534 pdadcValues[AR5416_NUM_PDADC_VALUES-diff];
Sujithb5aec952009-08-07 09:45:15 +0530535 }
536
Sujith16c94ac2010-06-01 15:14:04 +0530537 if (!ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
Sujitha55f8582010-06-01 15:14:07 +0530538 regOffset = AR_PHY_BASE +
539 (672 << 2) + regChainOffset;
540
Sujithb5aec952009-08-07 09:45:15 +0530541 for (j = 0; j < 32; j++) {
Pavel Roskin78fa99a2011-07-15 19:06:33 -0400542 reg32 = get_unaligned_le32(&pdadcValues[4 * j]);
Sujitha55f8582010-06-01 15:14:07 +0530543
Sujithb5aec952009-08-07 09:45:15 +0530544 REG_WRITE(ah, regOffset, reg32);
Sujithb5aec952009-08-07 09:45:15 +0530545 regOffset += 4;
546 }
547 }
Rajkumar Manoharane7fc6332011-03-15 23:11:35 +0530548 REGWRITE_BUFFER_FLUSH(ah);
Sujithb5aec952009-08-07 09:45:15 +0530549 }
550 }
Sujithb5aec952009-08-07 09:45:15 +0530551}
552
Sujith16c94ac2010-06-01 15:14:04 +0530553static void ath9k_hw_set_ar9287_power_per_rate_table(struct ath_hw *ah,
554 struct ath9k_channel *chan,
555 int16_t *ratesArray,
556 u16 cfgCtl,
557 u16 AntennaReduction,
558 u16 twiceMaxRegulatoryPower,
559 u16 powerLimit)
Sujithb5aec952009-08-07 09:45:15 +0530560{
Sujitha55f8582010-06-01 15:14:07 +0530561#define CMP_CTL \
562 (((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == \
563 pEepData->ctlIndex[i])
564
565#define CMP_NO_CTL \
566 (((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == \
567 ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL))
568
Sujithb5aec952009-08-07 09:45:15 +0530569#define REDUCE_SCALED_POWER_BY_TWO_CHAIN 6
570#define REDUCE_SCALED_POWER_BY_THREE_CHAIN 10
Sujith16c94ac2010-06-01 15:14:04 +0530571
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700572 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100573 u16 twiceMaxEdgePower = MAX_RATE_POWER;
Sujithb5aec952009-08-07 09:45:15 +0530574 static const u16 tpScaleReductionTable[5] =
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100575 { 0, 3, 6, 9, MAX_RATE_POWER };
Sujithb5aec952009-08-07 09:45:15 +0530576 int i;
Sujith16c94ac2010-06-01 15:14:04 +0530577 int16_t twiceLargestAntenna;
Sujithb5aec952009-08-07 09:45:15 +0530578 struct cal_ctl_data_ar9287 *rep;
579 struct cal_target_power_leg targetPowerOfdm = {0, {0, 0, 0, 0} },
580 targetPowerCck = {0, {0, 0, 0, 0} };
581 struct cal_target_power_leg targetPowerOfdmExt = {0, {0, 0, 0, 0} },
582 targetPowerCckExt = {0, {0, 0, 0, 0} };
Sujith16c94ac2010-06-01 15:14:04 +0530583 struct cal_target_power_ht targetPowerHt20,
Sujithb5aec952009-08-07 09:45:15 +0530584 targetPowerHt40 = {0, {0, 0, 0, 0} };
585 u16 scaledPower = 0, minCtlPower, maxRegAllowedPower;
Joe Perches07b2fa52010-11-20 18:38:53 -0800586 static const u16 ctlModesFor11g[] = {
587 CTL_11B, CTL_11G, CTL_2GHT20,
588 CTL_11B_EXT, CTL_11G_EXT, CTL_2GHT40
589 };
590 u16 numCtlModes = 0;
591 const u16 *pCtlMode = NULL;
592 u16 ctlMode, freq;
Sujithb5aec952009-08-07 09:45:15 +0530593 struct chan_centers centers;
594 int tx_chainmask;
595 u16 twiceMinEdgePower;
596 struct ar9287_eeprom *pEepData = &ah->eeprom.map9287;
597 tx_chainmask = ah->txchainmask;
598
599 ath9k_hw_get_channel_centers(ah, chan, &centers);
600
Sujitha55f8582010-06-01 15:14:07 +0530601 /* Compute TxPower reduction due to Antenna Gain */
Sujithb5aec952009-08-07 09:45:15 +0530602 twiceLargestAntenna = max(pEepData->modalHeader.antennaGainCh[0],
603 pEepData->modalHeader.antennaGainCh[1]);
Sujith16c94ac2010-06-01 15:14:04 +0530604 twiceLargestAntenna = (int16_t)min((AntennaReduction) -
605 twiceLargestAntenna, 0);
Sujithb5aec952009-08-07 09:45:15 +0530606
Sujitha55f8582010-06-01 15:14:07 +0530607 /*
608 * scaledPower is the minimum of the user input power level
609 * and the regulatory allowed power level.
610 */
Sujithb5aec952009-08-07 09:45:15 +0530611 maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
Sujitha55f8582010-06-01 15:14:07 +0530612
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700613 if (regulatory->tp_scale != ATH9K_TP_SCALE_MAX)
Sujithb5aec952009-08-07 09:45:15 +0530614 maxRegAllowedPower -=
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700615 (tpScaleReductionTable[(regulatory->tp_scale)] * 2);
Sujithb5aec952009-08-07 09:45:15 +0530616
617 scaledPower = min(powerLimit, maxRegAllowedPower);
618
Sujitha55f8582010-06-01 15:14:07 +0530619 /*
620 * Reduce scaled Power by number of chains active
621 * to get the per chain tx power level.
622 */
Sujithb5aec952009-08-07 09:45:15 +0530623 switch (ar5416_get_ntxchains(tx_chainmask)) {
624 case 1:
625 break;
626 case 2:
Daniel Halperin21fdc872011-05-31 11:59:30 -0700627 if (scaledPower > REDUCE_SCALED_POWER_BY_TWO_CHAIN)
628 scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN;
629 else
630 scaledPower = 0;
Sujithb5aec952009-08-07 09:45:15 +0530631 break;
632 case 3:
Daniel Halperin21fdc872011-05-31 11:59:30 -0700633 if (scaledPower > REDUCE_SCALED_POWER_BY_THREE_CHAIN)
634 scaledPower -= REDUCE_SCALED_POWER_BY_THREE_CHAIN;
635 else
636 scaledPower = 0;
Sujithb5aec952009-08-07 09:45:15 +0530637 break;
638 }
639 scaledPower = max((u16)0, scaledPower);
640
Sujitha55f8582010-06-01 15:14:07 +0530641 /*
642 * Get TX power from EEPROM.
643 */
Sujithb5aec952009-08-07 09:45:15 +0530644 if (IS_CHAN_2GHZ(chan)) {
Sujitha55f8582010-06-01 15:14:07 +0530645 /* CTL_11B, CTL_11G, CTL_2GHT20 */
Sujithb5aec952009-08-07 09:45:15 +0530646 numCtlModes =
647 ARRAY_SIZE(ctlModesFor11g) - SUB_NUM_CTL_MODES_AT_2G_40;
Sujith16c94ac2010-06-01 15:14:04 +0530648
Sujithb5aec952009-08-07 09:45:15 +0530649 pCtlMode = ctlModesFor11g;
650
651 ath9k_hw_get_legacy_target_powers(ah, chan,
652 pEepData->calTargetPowerCck,
653 AR9287_NUM_2G_CCK_TARGET_POWERS,
654 &targetPowerCck, 4, false);
655 ath9k_hw_get_legacy_target_powers(ah, chan,
656 pEepData->calTargetPower2G,
657 AR9287_NUM_2G_20_TARGET_POWERS,
658 &targetPowerOfdm, 4, false);
659 ath9k_hw_get_target_powers(ah, chan,
660 pEepData->calTargetPower2GHT20,
661 AR9287_NUM_2G_20_TARGET_POWERS,
662 &targetPowerHt20, 8, false);
663
664 if (IS_CHAN_HT40(chan)) {
Sujitha55f8582010-06-01 15:14:07 +0530665 /* All 2G CTLs */
Sujithb5aec952009-08-07 09:45:15 +0530666 numCtlModes = ARRAY_SIZE(ctlModesFor11g);
667 ath9k_hw_get_target_powers(ah, chan,
668 pEepData->calTargetPower2GHT40,
669 AR9287_NUM_2G_40_TARGET_POWERS,
670 &targetPowerHt40, 8, true);
671 ath9k_hw_get_legacy_target_powers(ah, chan,
672 pEepData->calTargetPowerCck,
673 AR9287_NUM_2G_CCK_TARGET_POWERS,
674 &targetPowerCckExt, 4, true);
675 ath9k_hw_get_legacy_target_powers(ah, chan,
676 pEepData->calTargetPower2G,
677 AR9287_NUM_2G_20_TARGET_POWERS,
678 &targetPowerOfdmExt, 4, true);
679 }
680 }
681
682 for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
Sujitha55f8582010-06-01 15:14:07 +0530683 bool isHt40CtlMode =
684 (pCtlMode[ctlMode] == CTL_2GHT40) ? true : false;
685
Sujithb5aec952009-08-07 09:45:15 +0530686 if (isHt40CtlMode)
687 freq = centers.synth_center;
688 else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
689 freq = centers.ext_center;
690 else
691 freq = centers.ctl_center;
692
Sujitha55f8582010-06-01 15:14:07 +0530693 /* Walk through the CTL indices stored in EEPROM */
Sujithb5aec952009-08-07 09:45:15 +0530694 for (i = 0; (i < AR9287_NUM_CTLS) && pEepData->ctlIndex[i]; i++) {
Sujitha55f8582010-06-01 15:14:07 +0530695 struct cal_ctl_edges *pRdEdgesPower;
Sujithb5aec952009-08-07 09:45:15 +0530696
Sujitha55f8582010-06-01 15:14:07 +0530697 /*
698 * Compare test group from regulatory channel list
699 * with test mode from pCtlMode list
700 */
701 if (CMP_CTL || CMP_NO_CTL) {
Sujithb5aec952009-08-07 09:45:15 +0530702 rep = &(pEepData->ctlData[i]);
Sujitha55f8582010-06-01 15:14:07 +0530703 pRdEdgesPower =
704 rep->ctlEdges[ar5416_get_ntxchains(tx_chainmask) - 1];
Sujithb5aec952009-08-07 09:45:15 +0530705
Sujitha55f8582010-06-01 15:14:07 +0530706 twiceMinEdgePower = ath9k_hw_get_max_edge_power(freq,
707 pRdEdgesPower,
708 IS_CHAN_2GHZ(chan),
709 AR5416_NUM_BAND_EDGES);
710
711 if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {
712 twiceMaxEdgePower = min(twiceMaxEdgePower,
713 twiceMinEdgePower);
714 } else {
Sujithb5aec952009-08-07 09:45:15 +0530715 twiceMaxEdgePower = twiceMinEdgePower;
716 break;
717 }
718 }
719 }
720
721 minCtlPower = (u8)min(twiceMaxEdgePower, scaledPower);
722
Sujitha55f8582010-06-01 15:14:07 +0530723 /* Apply ctl mode to correct target power set */
Sujithb5aec952009-08-07 09:45:15 +0530724 switch (pCtlMode[ctlMode]) {
725 case CTL_11B:
Sujitha55f8582010-06-01 15:14:07 +0530726 for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x); i++) {
727 targetPowerCck.tPow2x[i] =
728 (u8)min((u16)targetPowerCck.tPow2x[i],
729 minCtlPower);
Sujithb5aec952009-08-07 09:45:15 +0530730 }
731 break;
732 case CTL_11A:
733 case CTL_11G:
Sujitha55f8582010-06-01 15:14:07 +0530734 for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x); i++) {
735 targetPowerOfdm.tPow2x[i] =
736 (u8)min((u16)targetPowerOfdm.tPow2x[i],
737 minCtlPower);
Sujithb5aec952009-08-07 09:45:15 +0530738 }
739 break;
740 case CTL_5GHT20:
741 case CTL_2GHT20:
Sujitha55f8582010-06-01 15:14:07 +0530742 for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) {
743 targetPowerHt20.tPow2x[i] =
744 (u8)min((u16)targetPowerHt20.tPow2x[i],
745 minCtlPower);
Sujithb5aec952009-08-07 09:45:15 +0530746 }
747 break;
748 case CTL_11B_EXT:
Sujitha55f8582010-06-01 15:14:07 +0530749 targetPowerCckExt.tPow2x[0] =
750 (u8)min((u16)targetPowerCckExt.tPow2x[0],
751 minCtlPower);
Sujithb5aec952009-08-07 09:45:15 +0530752 break;
753 case CTL_11A_EXT:
754 case CTL_11G_EXT:
Sujitha55f8582010-06-01 15:14:07 +0530755 targetPowerOfdmExt.tPow2x[0] =
756 (u8)min((u16)targetPowerOfdmExt.tPow2x[0],
757 minCtlPower);
Sujithb5aec952009-08-07 09:45:15 +0530758 break;
759 case CTL_5GHT40:
760 case CTL_2GHT40:
Sujitha55f8582010-06-01 15:14:07 +0530761 for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
762 targetPowerHt40.tPow2x[i] =
763 (u8)min((u16)targetPowerHt40.tPow2x[i],
764 minCtlPower);
Sujithb5aec952009-08-07 09:45:15 +0530765 }
766 break;
767 default:
768 break;
769 }
770 }
771
Sujitha55f8582010-06-01 15:14:07 +0530772 /* Now set the rates array */
773
Sujithb5aec952009-08-07 09:45:15 +0530774 ratesArray[rate6mb] =
775 ratesArray[rate9mb] =
776 ratesArray[rate12mb] =
777 ratesArray[rate18mb] =
Sujitha55f8582010-06-01 15:14:07 +0530778 ratesArray[rate24mb] = targetPowerOfdm.tPow2x[0];
Sujithb5aec952009-08-07 09:45:15 +0530779
780 ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1];
781 ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2];
782 ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3];
783 ratesArray[rateXr] = targetPowerOfdm.tPow2x[0];
784
785 for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++)
786 ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i];
787
788 if (IS_CHAN_2GHZ(chan)) {
789 ratesArray[rate1l] = targetPowerCck.tPow2x[0];
Sujitha55f8582010-06-01 15:14:07 +0530790 ratesArray[rate2s] =
791 ratesArray[rate2l] = targetPowerCck.tPow2x[1];
792 ratesArray[rate5_5s] =
793 ratesArray[rate5_5l] = targetPowerCck.tPow2x[2];
794 ratesArray[rate11s] =
795 ratesArray[rate11l] = targetPowerCck.tPow2x[3];
Sujithb5aec952009-08-07 09:45:15 +0530796 }
797 if (IS_CHAN_HT40(chan)) {
798 for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++)
799 ratesArray[rateHt40_0 + i] = targetPowerHt40.tPow2x[i];
800
801 ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0];
802 ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0];
803 ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0];
Sujitha55f8582010-06-01 15:14:07 +0530804
Sujithb5aec952009-08-07 09:45:15 +0530805 if (IS_CHAN_2GHZ(chan))
806 ratesArray[rateExtCck] = targetPowerCckExt.tPow2x[0];
807 }
808
Sujitha55f8582010-06-01 15:14:07 +0530809#undef CMP_CTL
810#undef CMP_NO_CTL
Sujithb5aec952009-08-07 09:45:15 +0530811#undef REDUCE_SCALED_POWER_BY_TWO_CHAIN
812#undef REDUCE_SCALED_POWER_BY_THREE_CHAIN
813}
814
Sujith16c94ac2010-06-01 15:14:04 +0530815static void ath9k_hw_ar9287_set_txpower(struct ath_hw *ah,
Sujithb5aec952009-08-07 09:45:15 +0530816 struct ath9k_channel *chan, u16 cfgCtl,
817 u8 twiceAntennaReduction,
818 u8 twiceMaxRegulatoryPower,
Felix Fietkaude40f312010-10-20 03:08:53 +0200819 u8 powerLimit, bool test)
Sujithb5aec952009-08-07 09:45:15 +0530820{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700821 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithb5aec952009-08-07 09:45:15 +0530822 struct ar9287_eeprom *pEepData = &ah->eeprom.map9287;
823 struct modal_eep_ar9287_header *pModal = &pEepData->modalHeader;
824 int16_t ratesArray[Ar5416RateSize];
Sujithb5aec952009-08-07 09:45:15 +0530825 u8 ht40PowerIncForPdadc = 2;
826 int i;
827
828 memset(ratesArray, 0, sizeof(ratesArray));
829
830 if ((pEepData->baseEepHeader.version & AR9287_EEP_VER_MINOR_MASK) >=
831 AR9287_EEP_MINOR_VER_2)
832 ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
833
Sujith16c94ac2010-06-01 15:14:04 +0530834 ath9k_hw_set_ar9287_power_per_rate_table(ah, chan,
Sujithb5aec952009-08-07 09:45:15 +0530835 &ratesArray[0], cfgCtl,
836 twiceAntennaReduction,
837 twiceMaxRegulatoryPower,
838 powerLimit);
839
Felix Fietkaue832bf12011-07-27 15:01:03 +0200840 ath9k_hw_set_ar9287_power_cal_table(ah, chan);
Sujithb5aec952009-08-07 09:45:15 +0530841
Felix Fietkaude40f312010-10-20 03:08:53 +0200842 regulatory->max_power_level = 0;
Sujithb5aec952009-08-07 09:45:15 +0530843 for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100844 if (ratesArray[i] > MAX_RATE_POWER)
845 ratesArray[i] = MAX_RATE_POWER;
Felix Fietkaude40f312010-10-20 03:08:53 +0200846
847 if (ratesArray[i] > regulatory->max_power_level)
848 regulatory->max_power_level = ratesArray[i];
Sujithb5aec952009-08-07 09:45:15 +0530849 }
850
Felix Fietkaude40f312010-10-20 03:08:53 +0200851 if (test)
852 return;
853
Felix Fietkau7a370812010-09-22 12:34:52 +0200854 if (AR_SREV_9280_20_OR_LATER(ah)) {
Sujithb5aec952009-08-07 09:45:15 +0530855 for (i = 0; i < Ar5416RateSize; i++)
856 ratesArray[i] -= AR9287_PWR_TABLE_OFFSET_DB * 2;
857 }
858
Rajkumar Manoharane7fc6332011-03-15 23:11:35 +0530859 ENABLE_REGWRITE_BUFFER(ah);
860
Sujitha55f8582010-06-01 15:14:07 +0530861 /* OFDM power per rate */
Sujithb5aec952009-08-07 09:45:15 +0530862 REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
863 ATH9K_POW_SM(ratesArray[rate18mb], 24)
864 | ATH9K_POW_SM(ratesArray[rate12mb], 16)
865 | ATH9K_POW_SM(ratesArray[rate9mb], 8)
866 | ATH9K_POW_SM(ratesArray[rate6mb], 0));
867
868 REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
869 ATH9K_POW_SM(ratesArray[rate54mb], 24)
870 | ATH9K_POW_SM(ratesArray[rate48mb], 16)
871 | ATH9K_POW_SM(ratesArray[rate36mb], 8)
872 | ATH9K_POW_SM(ratesArray[rate24mb], 0));
873
Sujitha55f8582010-06-01 15:14:07 +0530874 /* CCK power per rate */
Sujithb5aec952009-08-07 09:45:15 +0530875 if (IS_CHAN_2GHZ(chan)) {
876 REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
877 ATH9K_POW_SM(ratesArray[rate2s], 24)
878 | ATH9K_POW_SM(ratesArray[rate2l], 16)
879 | ATH9K_POW_SM(ratesArray[rateXr], 8)
880 | ATH9K_POW_SM(ratesArray[rate1l], 0));
881 REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
882 ATH9K_POW_SM(ratesArray[rate11s], 24)
883 | ATH9K_POW_SM(ratesArray[rate11l], 16)
884 | ATH9K_POW_SM(ratesArray[rate5_5s], 8)
885 | ATH9K_POW_SM(ratesArray[rate5_5l], 0));
886 }
887
Sujitha55f8582010-06-01 15:14:07 +0530888 /* HT20 power per rate */
Sujithb5aec952009-08-07 09:45:15 +0530889 REG_WRITE(ah, AR_PHY_POWER_TX_RATE5,
890 ATH9K_POW_SM(ratesArray[rateHt20_3], 24)
891 | ATH9K_POW_SM(ratesArray[rateHt20_2], 16)
892 | ATH9K_POW_SM(ratesArray[rateHt20_1], 8)
893 | ATH9K_POW_SM(ratesArray[rateHt20_0], 0));
894
895 REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
896 ATH9K_POW_SM(ratesArray[rateHt20_7], 24)
897 | ATH9K_POW_SM(ratesArray[rateHt20_6], 16)
898 | ATH9K_POW_SM(ratesArray[rateHt20_5], 8)
899 | ATH9K_POW_SM(ratesArray[rateHt20_4], 0));
900
Sujitha55f8582010-06-01 15:14:07 +0530901 /* HT40 power per rate */
Sujithb5aec952009-08-07 09:45:15 +0530902 if (IS_CHAN_HT40(chan)) {
Sujith16c94ac2010-06-01 15:14:04 +0530903 if (ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
Sujithb5aec952009-08-07 09:45:15 +0530904 REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
905 ATH9K_POW_SM(ratesArray[rateHt40_3], 24)
906 | ATH9K_POW_SM(ratesArray[rateHt40_2], 16)
907 | ATH9K_POW_SM(ratesArray[rateHt40_1], 8)
908 | ATH9K_POW_SM(ratesArray[rateHt40_0], 0));
909
910 REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
911 ATH9K_POW_SM(ratesArray[rateHt40_7], 24)
912 | ATH9K_POW_SM(ratesArray[rateHt40_6], 16)
913 | ATH9K_POW_SM(ratesArray[rateHt40_5], 8)
914 | ATH9K_POW_SM(ratesArray[rateHt40_4], 0));
915 } else {
916 REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
917 ATH9K_POW_SM(ratesArray[rateHt40_3] +
918 ht40PowerIncForPdadc, 24)
919 | ATH9K_POW_SM(ratesArray[rateHt40_2] +
920 ht40PowerIncForPdadc, 16)
921 | ATH9K_POW_SM(ratesArray[rateHt40_1] +
922 ht40PowerIncForPdadc, 8)
923 | ATH9K_POW_SM(ratesArray[rateHt40_0] +
924 ht40PowerIncForPdadc, 0));
925
926 REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
927 ATH9K_POW_SM(ratesArray[rateHt40_7] +
928 ht40PowerIncForPdadc, 24)
929 | ATH9K_POW_SM(ratesArray[rateHt40_6] +
930 ht40PowerIncForPdadc, 16)
931 | ATH9K_POW_SM(ratesArray[rateHt40_5] +
932 ht40PowerIncForPdadc, 8)
933 | ATH9K_POW_SM(ratesArray[rateHt40_4] +
934 ht40PowerIncForPdadc, 0));
935 }
936
Sujitha55f8582010-06-01 15:14:07 +0530937 /* Dup/Ext power per rate */
Sujithb5aec952009-08-07 09:45:15 +0530938 REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
939 ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
940 | ATH9K_POW_SM(ratesArray[rateExtCck], 16)
941 | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
942 | ATH9K_POW_SM(ratesArray[rateDupCck], 0));
943 }
Rajkumar Manoharane7fc6332011-03-15 23:11:35 +0530944 REGWRITE_BUFFER_FLUSH(ah);
Sujithb5aec952009-08-07 09:45:15 +0530945}
946
Sujith16c94ac2010-06-01 15:14:04 +0530947static void ath9k_hw_ar9287_set_addac(struct ath_hw *ah,
Sujithb5aec952009-08-07 09:45:15 +0530948 struct ath9k_channel *chan)
949{
950}
951
Sujith16c94ac2010-06-01 15:14:04 +0530952static void ath9k_hw_ar9287_set_board_values(struct ath_hw *ah,
Sujithb5aec952009-08-07 09:45:15 +0530953 struct ath9k_channel *chan)
954{
955 struct ar9287_eeprom *eep = &ah->eeprom.map9287;
956 struct modal_eep_ar9287_header *pModal = &eep->modalHeader;
Sujith79d7f4b2010-06-01 15:14:06 +0530957 u32 regChainOffset, regval;
Sujithb5aec952009-08-07 09:45:15 +0530958 u8 txRxAttenLocal;
Rajkumar Manoharan2d05a0c2011-04-11 20:22:28 +0530959 int i;
Sujithb5aec952009-08-07 09:45:15 +0530960
961 pModal = &eep->modalHeader;
962
Felix Fietkaudf3c8b22010-12-12 00:51:11 +0100963 REG_WRITE(ah, AR_PHY_SWITCH_COM, pModal->antCtrlCommon);
Sujithb5aec952009-08-07 09:45:15 +0530964
965 for (i = 0; i < AR9287_MAX_CHAINS; i++) {
966 regChainOffset = i * 0x1000;
967
968 REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
969 pModal->antCtrlChain[i]);
970
971 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
972 (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset)
973 & ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
974 AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
975 SM(pModal->iqCalICh[i],
976 AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
977 SM(pModal->iqCalQCh[i],
978 AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
979
980 txRxAttenLocal = pModal->txRxAttenCh[i];
981
982 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
983 AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN,
984 pModal->bswMargin[i]);
985 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
986 AR_PHY_GAIN_2GHZ_XATTEN1_DB,
987 pModal->bswAtten[i]);
988 REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
989 AR9280_PHY_RXGAIN_TXRX_ATTEN,
990 txRxAttenLocal);
991 REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
992 AR9280_PHY_RXGAIN_TXRX_MARGIN,
993 pModal->rxTxMarginCh[i]);
994 }
995
996
997 if (IS_CHAN_HT40(chan))
998 REG_RMW_FIELD(ah, AR_PHY_SETTLING,
999 AR_PHY_SETTLING_SWITCH, pModal->swSettleHt40);
1000 else
1001 REG_RMW_FIELD(ah, AR_PHY_SETTLING,
1002 AR_PHY_SETTLING_SWITCH, pModal->switchSettling);
1003
1004 REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
1005 AR_PHY_DESIRED_SZ_ADC, pModal->adcDesiredSize);
1006
1007 REG_WRITE(ah, AR_PHY_RF_CTL4,
1008 SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF)
1009 | SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAB_OFF)
1010 | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAA_ON)
1011 | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAB_ON));
1012
1013 REG_RMW_FIELD(ah, AR_PHY_RF_CTL3,
1014 AR_PHY_TX_END_TO_A2_RX_ON, pModal->txEndToRxOn);
1015
1016 REG_RMW_FIELD(ah, AR_PHY_CCA,
1017 AR9280_PHY_CCA_THRESH62, pModal->thresh62);
1018 REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0,
1019 AR_PHY_EXT_CCA0_THRESH62, pModal->thresh62);
1020
Sujith79d7f4b2010-06-01 15:14:06 +05301021 regval = REG_READ(ah, AR9287_AN_RF2G3_CH0);
1022 regval &= ~(AR9287_AN_RF2G3_DB1 |
1023 AR9287_AN_RF2G3_DB2 |
1024 AR9287_AN_RF2G3_OB_CCK |
1025 AR9287_AN_RF2G3_OB_PSK |
1026 AR9287_AN_RF2G3_OB_QAM |
1027 AR9287_AN_RF2G3_OB_PAL_OFF);
1028 regval |= (SM(pModal->db1, AR9287_AN_RF2G3_DB1) |
1029 SM(pModal->db2, AR9287_AN_RF2G3_DB2) |
1030 SM(pModal->ob_cck, AR9287_AN_RF2G3_OB_CCK) |
1031 SM(pModal->ob_psk, AR9287_AN_RF2G3_OB_PSK) |
1032 SM(pModal->ob_qam, AR9287_AN_RF2G3_OB_QAM) |
1033 SM(pModal->ob_pal_off, AR9287_AN_RF2G3_OB_PAL_OFF));
Sujithb5aec952009-08-07 09:45:15 +05301034
Sujith79d7f4b2010-06-01 15:14:06 +05301035 ath9k_hw_analog_shift_regwrite(ah, AR9287_AN_RF2G3_CH0, regval);
1036
1037 regval = REG_READ(ah, AR9287_AN_RF2G3_CH1);
1038 regval &= ~(AR9287_AN_RF2G3_DB1 |
1039 AR9287_AN_RF2G3_DB2 |
1040 AR9287_AN_RF2G3_OB_CCK |
1041 AR9287_AN_RF2G3_OB_PSK |
1042 AR9287_AN_RF2G3_OB_QAM |
1043 AR9287_AN_RF2G3_OB_PAL_OFF);
1044 regval |= (SM(pModal->db1, AR9287_AN_RF2G3_DB1) |
1045 SM(pModal->db2, AR9287_AN_RF2G3_DB2) |
1046 SM(pModal->ob_cck, AR9287_AN_RF2G3_OB_CCK) |
1047 SM(pModal->ob_psk, AR9287_AN_RF2G3_OB_PSK) |
1048 SM(pModal->ob_qam, AR9287_AN_RF2G3_OB_QAM) |
1049 SM(pModal->ob_pal_off, AR9287_AN_RF2G3_OB_PAL_OFF));
1050
1051 ath9k_hw_analog_shift_regwrite(ah, AR9287_AN_RF2G3_CH1, regval);
Sujithb5aec952009-08-07 09:45:15 +05301052
1053 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
1054 AR_PHY_TX_END_DATA_START, pModal->txFrameToDataStart);
1055 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
1056 AR_PHY_TX_END_PA_ON, pModal->txFrameToPaOn);
1057
1058 ath9k_hw_analog_shift_rmw(ah, AR9287_AN_TOP2,
1059 AR9287_AN_TOP2_XPABIAS_LVL,
1060 AR9287_AN_TOP2_XPABIAS_LVL_S,
1061 pModal->xpaBiasLvl);
1062}
1063
Sujith16c94ac2010-06-01 15:14:04 +05301064static u16 ath9k_hw_ar9287_get_spur_channel(struct ath_hw *ah,
Sujithb5aec952009-08-07 09:45:15 +05301065 u16 i, bool is2GHz)
1066{
1067#define EEP_MAP9287_SPURCHAN \
1068 (ah->eeprom.map9287.modalHeader.spurChans[i].spurChan)
Sujith16c94ac2010-06-01 15:14:04 +05301069
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -07001070 struct ath_common *common = ath9k_hw_common(ah);
Sujithb5aec952009-08-07 09:45:15 +05301071 u16 spur_val = AR_NO_SPUR;
1072
Joe Perches226afe62010-12-02 19:12:37 -08001073 ath_dbg(common, ATH_DBG_ANI,
1074 "Getting spur idx:%d is2Ghz:%d val:%x\n",
1075 i, is2GHz, ah->config.spurchans[i][is2GHz]);
Sujithb5aec952009-08-07 09:45:15 +05301076
1077 switch (ah->config.spurmode) {
1078 case SPUR_DISABLE:
1079 break;
1080 case SPUR_ENABLE_IOCTL:
1081 spur_val = ah->config.spurchans[i][is2GHz];
Joe Perches226afe62010-12-02 19:12:37 -08001082 ath_dbg(common, ATH_DBG_ANI,
1083 "Getting spur val from new loc. %d\n", spur_val);
Sujithb5aec952009-08-07 09:45:15 +05301084 break;
1085 case SPUR_ENABLE_EEPROM:
1086 spur_val = EEP_MAP9287_SPURCHAN;
1087 break;
1088 }
1089
1090 return spur_val;
1091
1092#undef EEP_MAP9287_SPURCHAN
1093}
1094
Luis R. Rodriguez0b8f6f2b12010-04-15 17:39:12 -04001095const struct eeprom_ops eep_ar9287_ops = {
Sujith16c94ac2010-06-01 15:14:04 +05301096 .check_eeprom = ath9k_hw_ar9287_check_eeprom,
1097 .get_eeprom = ath9k_hw_ar9287_get_eeprom,
1098 .fill_eeprom = ath9k_hw_ar9287_fill_eeprom,
Rajkumar Manoharan49c995202011-07-29 17:38:10 +05301099 .dump_eeprom = ath9k_hw_ar9287_dump_eeprom,
Sujith16c94ac2010-06-01 15:14:04 +05301100 .get_eeprom_ver = ath9k_hw_ar9287_get_eeprom_ver,
1101 .get_eeprom_rev = ath9k_hw_ar9287_get_eeprom_rev,
Sujith16c94ac2010-06-01 15:14:04 +05301102 .set_board_values = ath9k_hw_ar9287_set_board_values,
1103 .set_addac = ath9k_hw_ar9287_set_addac,
1104 .set_txpower = ath9k_hw_ar9287_set_txpower,
1105 .get_spur_channel = ath9k_hw_ar9287_get_spur_channel
Sujithb5aec952009-08-07 09:45:15 +05301106};