blob: 604312cfe8cb046a435225868428d6c84424421c [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
Sujith16c94ac2010-06-01 15:14:04 +053079static int ath9k_hw_ar9287_check_eeprom(struct ath_hw *ah)
Sujithb5aec952009-08-07 09:45:15 +053080{
81 u32 sum = 0, el, integer;
82 u16 temp, word, magic, magic2, *eepdata;
83 int i, addr;
84 bool need_swap = false;
85 struct ar9287_eeprom *eep = &ah->eeprom.map9287;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070086 struct ath_common *common = ath9k_hw_common(ah);
Sujithb5aec952009-08-07 09:45:15 +053087
88 if (!ath9k_hw_use_flash(ah)) {
Sujith16c94ac2010-06-01 15:14:04 +053089 if (!ath9k_hw_nvram_read(common, AR5416_EEPROM_MAGIC_OFFSET,
90 &magic)) {
Joe Perches38002762010-12-02 19:12:36 -080091 ath_err(common, "Reading Magic # failed\n");
Sujithb5aec952009-08-07 09:45:15 +053092 return false;
93 }
94
Joe Perches226afe62010-12-02 19:12:37 -080095 ath_dbg(common, ATH_DBG_EEPROM,
96 "Read Magic = 0x%04X\n", magic);
Sujith16c94ac2010-06-01 15:14:04 +053097
Sujithb5aec952009-08-07 09:45:15 +053098 if (magic != AR5416_EEPROM_MAGIC) {
99 magic2 = swab16(magic);
100
101 if (magic2 == AR5416_EEPROM_MAGIC) {
102 need_swap = true;
103 eepdata = (u16 *)(&ah->eeprom);
104
Sujith Manoharan04cf53f2011-01-04 13:17:28 +0530105 for (addr = 0; addr < SIZE_EEPROM_AR9287; addr++) {
Sujithb5aec952009-08-07 09:45:15 +0530106 temp = swab16(*eepdata);
107 *eepdata = temp;
108 eepdata++;
109 }
110 } else {
Joe Perches38002762010-12-02 19:12:36 -0800111 ath_err(common,
112 "Invalid EEPROM Magic. Endianness mismatch.\n");
Sujithb5aec952009-08-07 09:45:15 +0530113 return -EINVAL;
114 }
115 }
116 }
Sujith16c94ac2010-06-01 15:14:04 +0530117
Joe Perches226afe62010-12-02 19:12:37 -0800118 ath_dbg(common, ATH_DBG_EEPROM, "need_swap = %s.\n",
119 need_swap ? "True" : "False");
Sujithb5aec952009-08-07 09:45:15 +0530120
121 if (need_swap)
122 el = swab16(ah->eeprom.map9287.baseEepHeader.length);
123 else
124 el = ah->eeprom.map9287.baseEepHeader.length;
125
126 if (el > sizeof(struct ar9287_eeprom))
127 el = sizeof(struct ar9287_eeprom) / sizeof(u16);
128 else
129 el = el / sizeof(u16);
130
131 eepdata = (u16 *)(&ah->eeprom);
Sujith16c94ac2010-06-01 15:14:04 +0530132
Sujithb5aec952009-08-07 09:45:15 +0530133 for (i = 0; i < el; i++)
134 sum ^= *eepdata++;
135
136 if (need_swap) {
137 word = swab16(eep->baseEepHeader.length);
138 eep->baseEepHeader.length = word;
139
140 word = swab16(eep->baseEepHeader.checksum);
141 eep->baseEepHeader.checksum = word;
142
143 word = swab16(eep->baseEepHeader.version);
144 eep->baseEepHeader.version = word;
145
146 word = swab16(eep->baseEepHeader.regDmn[0]);
147 eep->baseEepHeader.regDmn[0] = word;
148
149 word = swab16(eep->baseEepHeader.regDmn[1]);
150 eep->baseEepHeader.regDmn[1] = word;
151
152 word = swab16(eep->baseEepHeader.rfSilent);
153 eep->baseEepHeader.rfSilent = word;
154
155 word = swab16(eep->baseEepHeader.blueToothOptions);
156 eep->baseEepHeader.blueToothOptions = word;
157
158 word = swab16(eep->baseEepHeader.deviceCap);
159 eep->baseEepHeader.deviceCap = word;
160
161 integer = swab32(eep->modalHeader.antCtrlCommon);
162 eep->modalHeader.antCtrlCommon = integer;
163
164 for (i = 0; i < AR9287_MAX_CHAINS; i++) {
165 integer = swab32(eep->modalHeader.antCtrlChain[i]);
166 eep->modalHeader.antCtrlChain[i] = integer;
167 }
168
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100169 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujithb5aec952009-08-07 09:45:15 +0530170 word = swab16(eep->modalHeader.spurChans[i].spurChan);
171 eep->modalHeader.spurChans[i].spurChan = word;
172 }
173 }
174
175 if (sum != 0xffff || ah->eep_ops->get_eeprom_ver(ah) != AR9287_EEP_VER
176 || ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_NO_BACK_VER) {
Joe Perches38002762010-12-02 19:12:36 -0800177 ath_err(common, "Bad EEPROM checksum 0x%x or revision 0x%04x\n",
178 sum, ah->eep_ops->get_eeprom_ver(ah));
Sujithb5aec952009-08-07 09:45:15 +0530179 return -EINVAL;
180 }
181
182 return 0;
183}
184
Sujith16c94ac2010-06-01 15:14:04 +0530185static u32 ath9k_hw_ar9287_get_eeprom(struct ath_hw *ah,
Sujithb5aec952009-08-07 09:45:15 +0530186 enum eeprom_param param)
187{
188 struct ar9287_eeprom *eep = &ah->eeprom.map9287;
189 struct modal_eep_ar9287_header *pModal = &eep->modalHeader;
190 struct base_eep_ar9287_header *pBase = &eep->baseEepHeader;
191 u16 ver_minor;
192
193 ver_minor = pBase->version & AR9287_EEP_VER_MINOR_MASK;
Sujith16c94ac2010-06-01 15:14:04 +0530194
Sujithb5aec952009-08-07 09:45:15 +0530195 switch (param) {
196 case EEP_NFTHRESH_2:
197 return pModal->noiseFloorThreshCh[0];
Luis R. Rodriguez49101672010-04-15 17:39:13 -0400198 case EEP_MAC_LSW:
Pavel Roskin78fa99a2011-07-15 19:06:33 -0400199 return get_unaligned_be16(pBase->macAddr);
Luis R. Rodriguez49101672010-04-15 17:39:13 -0400200 case EEP_MAC_MID:
Pavel Roskin78fa99a2011-07-15 19:06:33 -0400201 return get_unaligned_be16(pBase->macAddr + 2);
Luis R. Rodriguez49101672010-04-15 17:39:13 -0400202 case EEP_MAC_MSW:
Pavel Roskin78fa99a2011-07-15 19:06:33 -0400203 return get_unaligned_be16(pBase->macAddr + 4);
Sujithb5aec952009-08-07 09:45:15 +0530204 case EEP_REG_0:
205 return pBase->regDmn[0];
206 case EEP_REG_1:
207 return pBase->regDmn[1];
208 case EEP_OP_CAP:
209 return pBase->deviceCap;
210 case EEP_OP_MODE:
211 return pBase->opCapFlags;
212 case EEP_RF_SILENT:
213 return pBase->rfSilent;
214 case EEP_MINOR_REV:
215 return ver_minor;
216 case EEP_TX_MASK:
217 return pBase->txMask;
218 case EEP_RX_MASK:
219 return pBase->rxMask;
220 case EEP_DEV_TYPE:
221 return pBase->deviceType;
222 case EEP_OL_PWRCTRL:
223 return pBase->openLoopPwrCntl;
224 case EEP_TEMPSENSE_SLOPE:
225 if (ver_minor >= AR9287_EEP_MINOR_VER_2)
226 return pBase->tempSensSlope;
227 else
228 return 0;
229 case EEP_TEMPSENSE_SLOPE_PAL_ON:
230 if (ver_minor >= AR9287_EEP_MINOR_VER_3)
231 return pBase->tempSensSlopePalOn;
232 else
233 return 0;
234 default:
235 return 0;
236 }
237}
238
Sujithb5aec952009-08-07 09:45:15 +0530239static void ar9287_eeprom_get_tx_gain_index(struct ath_hw *ah,
240 struct ath9k_channel *chan,
241 struct cal_data_op_loop_ar9287 *pRawDatasetOpLoop,
Sujith16c94ac2010-06-01 15:14:04 +0530242 u8 *pCalChans, u16 availPiers, int8_t *pPwr)
Sujithb5aec952009-08-07 09:45:15 +0530243{
Sujith16c94ac2010-06-01 15:14:04 +0530244 u16 idxL = 0, idxR = 0, numPiers;
Sujithb5aec952009-08-07 09:45:15 +0530245 bool match;
246 struct chan_centers centers;
247
248 ath9k_hw_get_channel_centers(ah, chan, &centers);
249
250 for (numPiers = 0; numPiers < availPiers; numPiers++) {
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100251 if (pCalChans[numPiers] == AR5416_BCHAN_UNUSED)
Sujithb5aec952009-08-07 09:45:15 +0530252 break;
253 }
254
255 match = ath9k_hw_get_lower_upper_index(
Sujitha55f8582010-06-01 15:14:07 +0530256 (u8)FREQ2FBIN(centers.synth_center, IS_CHAN_2GHZ(chan)),
257 pCalChans, numPiers, &idxL, &idxR);
Sujithb5aec952009-08-07 09:45:15 +0530258
259 if (match) {
Vivek Natarajand4fe5af2009-08-14 11:32:04 +0530260 *pPwr = (int8_t) pRawDatasetOpLoop[idxL].pwrPdg[0][0];
Sujithb5aec952009-08-07 09:45:15 +0530261 } else {
Vivek Natarajand4fe5af2009-08-14 11:32:04 +0530262 *pPwr = ((int8_t) pRawDatasetOpLoop[idxL].pwrPdg[0][0] +
Sujith16c94ac2010-06-01 15:14:04 +0530263 (int8_t) pRawDatasetOpLoop[idxR].pwrPdg[0][0])/2;
Sujithb5aec952009-08-07 09:45:15 +0530264 }
265
Sujithb5aec952009-08-07 09:45:15 +0530266}
267
268static void ar9287_eeprom_olpc_set_pdadcs(struct ath_hw *ah,
269 int32_t txPower, u16 chain)
270{
271 u32 tmpVal;
272 u32 a;
273
Sujith16c94ac2010-06-01 15:14:04 +0530274 /* Enable OLPC for chain 0 */
275
Sujithb5aec952009-08-07 09:45:15 +0530276 tmpVal = REG_READ(ah, 0xa270);
277 tmpVal = tmpVal & 0xFCFFFFFF;
278 tmpVal = tmpVal | (0x3 << 24);
279 REG_WRITE(ah, 0xa270, tmpVal);
280
Sujith16c94ac2010-06-01 15:14:04 +0530281 /* Enable OLPC for chain 1 */
282
Sujithb5aec952009-08-07 09:45:15 +0530283 tmpVal = REG_READ(ah, 0xb270);
284 tmpVal = tmpVal & 0xFCFFFFFF;
285 tmpVal = tmpVal | (0x3 << 24);
286 REG_WRITE(ah, 0xb270, tmpVal);
287
Sujith16c94ac2010-06-01 15:14:04 +0530288 /* Write the OLPC ref power for chain 0 */
289
Sujithb5aec952009-08-07 09:45:15 +0530290 if (chain == 0) {
291 tmpVal = REG_READ(ah, 0xa398);
292 tmpVal = tmpVal & 0xff00ffff;
293 a = (txPower)&0xff;
294 tmpVal = tmpVal | (a << 16);
295 REG_WRITE(ah, 0xa398, tmpVal);
296 }
297
Sujith16c94ac2010-06-01 15:14:04 +0530298 /* Write the OLPC ref power for chain 1 */
299
Sujithb5aec952009-08-07 09:45:15 +0530300 if (chain == 1) {
301 tmpVal = REG_READ(ah, 0xb398);
302 tmpVal = tmpVal & 0xff00ffff;
303 a = (txPower)&0xff;
304 tmpVal = tmpVal | (a << 16);
305 REG_WRITE(ah, 0xb398, tmpVal);
306 }
307}
308
Sujith16c94ac2010-06-01 15:14:04 +0530309static void ath9k_hw_set_ar9287_power_cal_table(struct ath_hw *ah,
Felix Fietkaue832bf12011-07-27 15:01:03 +0200310 struct ath9k_channel *chan)
Sujithb5aec952009-08-07 09:45:15 +0530311{
312 struct cal_data_per_freq_ar9287 *pRawDataset;
313 struct cal_data_op_loop_ar9287 *pRawDatasetOpenLoop;
Sujith16c94ac2010-06-01 15:14:04 +0530314 u8 *pCalBChans = NULL;
Sujithb5aec952009-08-07 09:45:15 +0530315 u16 pdGainOverlap_t2;
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100316 u8 pdadcValues[AR5416_NUM_PDADC_VALUES];
317 u16 gainBoundaries[AR5416_PD_GAINS_IN_MASK];
Sujithb5aec952009-08-07 09:45:15 +0530318 u16 numPiers = 0, i, j;
Sujithb5aec952009-08-07 09:45:15 +0530319 u16 numXpdGain, xpdMask;
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100320 u16 xpdGainValues[AR5416_NUM_PD_GAINS] = {0, 0, 0, 0};
Sujitha55f8582010-06-01 15:14:07 +0530321 u32 reg32, regOffset, regChainOffset, regval;
Sujith Manoharan0ff2b5c2011-04-20 11:00:34 +0530322 int16_t diff = 0;
Sujithb5aec952009-08-07 09:45:15 +0530323 struct ar9287_eeprom *pEepData = &ah->eeprom.map9287;
Sujith16c94ac2010-06-01 15:14:04 +0530324
Sujithb5aec952009-08-07 09:45:15 +0530325 xpdMask = pEepData->modalHeader.xpdGain;
Sujith16c94ac2010-06-01 15:14:04 +0530326
Sujithb5aec952009-08-07 09:45:15 +0530327 if ((pEepData->baseEepHeader.version & AR9287_EEP_VER_MINOR_MASK) >=
Sujitha55f8582010-06-01 15:14:07 +0530328 AR9287_EEP_MINOR_VER_2)
Sujithb5aec952009-08-07 09:45:15 +0530329 pdGainOverlap_t2 = pEepData->modalHeader.pdGainOverlap;
330 else
331 pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5),
332 AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
333
334 if (IS_CHAN_2GHZ(chan)) {
335 pCalBChans = pEepData->calFreqPier2G;
336 numPiers = AR9287_NUM_2G_CAL_PIERS;
Sujith16c94ac2010-06-01 15:14:04 +0530337 if (ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
Sujithb5aec952009-08-07 09:45:15 +0530338 pRawDatasetOpenLoop =
Sujitha55f8582010-06-01 15:14:07 +0530339 (struct cal_data_op_loop_ar9287 *)pEepData->calPierData2G[0];
Sujithb5aec952009-08-07 09:45:15 +0530340 ah->initPDADC = pRawDatasetOpenLoop->vpdPdg[0][0];
341 }
342 }
343
344 numXpdGain = 0;
Sujith16c94ac2010-06-01 15:14:04 +0530345
Sujitha55f8582010-06-01 15:14:07 +0530346 /* Calculate the value of xpdgains from the xpdGain Mask */
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100347 for (i = 1; i <= AR5416_PD_GAINS_IN_MASK; i++) {
348 if ((xpdMask >> (AR5416_PD_GAINS_IN_MASK - i)) & 1) {
349 if (numXpdGain >= AR5416_NUM_PD_GAINS)
Sujithb5aec952009-08-07 09:45:15 +0530350 break;
351 xpdGainValues[numXpdGain] =
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100352 (u16)(AR5416_PD_GAINS_IN_MASK-i);
Sujithb5aec952009-08-07 09:45:15 +0530353 numXpdGain++;
354 }
355 }
356
357 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
358 (numXpdGain - 1) & 0x3);
359 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,
360 xpdGainValues[0]);
361 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
362 xpdGainValues[1]);
363 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3,
364 xpdGainValues[2]);
365
366 for (i = 0; i < AR9287_MAX_CHAINS; i++) {
367 regChainOffset = i * 0x1000;
Sujitha55f8582010-06-01 15:14:07 +0530368
Sujithb5aec952009-08-07 09:45:15 +0530369 if (pEepData->baseEepHeader.txMask & (1 << i)) {
Sujitha55f8582010-06-01 15:14:07 +0530370 pRawDatasetOpenLoop =
371 (struct cal_data_op_loop_ar9287 *)pEepData->calPierData2G[i];
372
Sujith16c94ac2010-06-01 15:14:04 +0530373 if (ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
Sujithb5aec952009-08-07 09:45:15 +0530374 int8_t txPower;
375 ar9287_eeprom_get_tx_gain_index(ah, chan,
Sujitha55f8582010-06-01 15:14:07 +0530376 pRawDatasetOpenLoop,
377 pCalBChans, numPiers,
378 &txPower);
Sujithb5aec952009-08-07 09:45:15 +0530379 ar9287_eeprom_olpc_set_pdadcs(ah, txPower, i);
380 } else {
381 pRawDataset =
382 (struct cal_data_per_freq_ar9287 *)
383 pEepData->calPierData2G[i];
Sujitha55f8582010-06-01 15:14:07 +0530384
Felix Fietkau940cd2c2010-12-12 00:51:10 +0100385 ath9k_hw_get_gain_boundaries_pdadcs(ah, chan,
Sujitha55f8582010-06-01 15:14:07 +0530386 pRawDataset,
387 pCalBChans, numPiers,
388 pdGainOverlap_t2,
Sujitha55f8582010-06-01 15:14:07 +0530389 gainBoundaries,
390 pdadcValues,
391 numXpdGain);
Sujithb5aec952009-08-07 09:45:15 +0530392 }
393
Rajkumar Manoharane7fc6332011-03-15 23:11:35 +0530394 ENABLE_REGWRITE_BUFFER(ah);
395
Sujithb5aec952009-08-07 09:45:15 +0530396 if (i == 0) {
Sujitha55f8582010-06-01 15:14:07 +0530397 if (!ath9k_hw_ar9287_get_eeprom(ah,
398 EEP_OL_PWRCTRL)) {
399
400 regval = SM(pdGainOverlap_t2,
401 AR_PHY_TPCRG5_PD_GAIN_OVERLAP)
402 | SM(gainBoundaries[0],
403 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1)
404 | SM(gainBoundaries[1],
405 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2)
406 | SM(gainBoundaries[2],
407 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3)
408 | SM(gainBoundaries[3],
409 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4);
410
411 REG_WRITE(ah,
412 AR_PHY_TPCRG5 + regChainOffset,
413 regval);
Sujithb5aec952009-08-07 09:45:15 +0530414 }
415 }
416
417 if ((int32_t)AR9287_PWR_TABLE_OFFSET_DB !=
Sujitha55f8582010-06-01 15:14:07 +0530418 pEepData->baseEepHeader.pwrTableOffset) {
419 diff = (u16)(pEepData->baseEepHeader.pwrTableOffset -
420 (int32_t)AR9287_PWR_TABLE_OFFSET_DB);
Sujithb5aec952009-08-07 09:45:15 +0530421 diff *= 2;
422
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100423 for (j = 0; j < ((u16)AR5416_NUM_PDADC_VALUES-diff); j++)
Sujithb5aec952009-08-07 09:45:15 +0530424 pdadcValues[j] = pdadcValues[j+diff];
425
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100426 for (j = (u16)(AR5416_NUM_PDADC_VALUES-diff);
427 j < AR5416_NUM_PDADC_VALUES; j++)
Sujithb5aec952009-08-07 09:45:15 +0530428 pdadcValues[j] =
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100429 pdadcValues[AR5416_NUM_PDADC_VALUES-diff];
Sujithb5aec952009-08-07 09:45:15 +0530430 }
431
Sujith16c94ac2010-06-01 15:14:04 +0530432 if (!ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
Sujitha55f8582010-06-01 15:14:07 +0530433 regOffset = AR_PHY_BASE +
434 (672 << 2) + regChainOffset;
435
Sujithb5aec952009-08-07 09:45:15 +0530436 for (j = 0; j < 32; j++) {
Pavel Roskin78fa99a2011-07-15 19:06:33 -0400437 reg32 = get_unaligned_le32(&pdadcValues[4 * j]);
Sujitha55f8582010-06-01 15:14:07 +0530438
Sujithb5aec952009-08-07 09:45:15 +0530439 REG_WRITE(ah, regOffset, reg32);
Sujithb5aec952009-08-07 09:45:15 +0530440 regOffset += 4;
441 }
442 }
Rajkumar Manoharane7fc6332011-03-15 23:11:35 +0530443 REGWRITE_BUFFER_FLUSH(ah);
Sujithb5aec952009-08-07 09:45:15 +0530444 }
445 }
Sujithb5aec952009-08-07 09:45:15 +0530446}
447
Sujith16c94ac2010-06-01 15:14:04 +0530448static void ath9k_hw_set_ar9287_power_per_rate_table(struct ath_hw *ah,
449 struct ath9k_channel *chan,
450 int16_t *ratesArray,
451 u16 cfgCtl,
452 u16 AntennaReduction,
453 u16 twiceMaxRegulatoryPower,
454 u16 powerLimit)
Sujithb5aec952009-08-07 09:45:15 +0530455{
Sujitha55f8582010-06-01 15:14:07 +0530456#define CMP_CTL \
457 (((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == \
458 pEepData->ctlIndex[i])
459
460#define CMP_NO_CTL \
461 (((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == \
462 ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL))
463
Sujithb5aec952009-08-07 09:45:15 +0530464#define REDUCE_SCALED_POWER_BY_TWO_CHAIN 6
465#define REDUCE_SCALED_POWER_BY_THREE_CHAIN 10
Sujith16c94ac2010-06-01 15:14:04 +0530466
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700467 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100468 u16 twiceMaxEdgePower = MAX_RATE_POWER;
Sujithb5aec952009-08-07 09:45:15 +0530469 static const u16 tpScaleReductionTable[5] =
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100470 { 0, 3, 6, 9, MAX_RATE_POWER };
Sujithb5aec952009-08-07 09:45:15 +0530471 int i;
Sujith16c94ac2010-06-01 15:14:04 +0530472 int16_t twiceLargestAntenna;
Sujithb5aec952009-08-07 09:45:15 +0530473 struct cal_ctl_data_ar9287 *rep;
474 struct cal_target_power_leg targetPowerOfdm = {0, {0, 0, 0, 0} },
475 targetPowerCck = {0, {0, 0, 0, 0} };
476 struct cal_target_power_leg targetPowerOfdmExt = {0, {0, 0, 0, 0} },
477 targetPowerCckExt = {0, {0, 0, 0, 0} };
Sujith16c94ac2010-06-01 15:14:04 +0530478 struct cal_target_power_ht targetPowerHt20,
Sujithb5aec952009-08-07 09:45:15 +0530479 targetPowerHt40 = {0, {0, 0, 0, 0} };
480 u16 scaledPower = 0, minCtlPower, maxRegAllowedPower;
Joe Perches07b2fa52010-11-20 18:38:53 -0800481 static const u16 ctlModesFor11g[] = {
482 CTL_11B, CTL_11G, CTL_2GHT20,
483 CTL_11B_EXT, CTL_11G_EXT, CTL_2GHT40
484 };
485 u16 numCtlModes = 0;
486 const u16 *pCtlMode = NULL;
487 u16 ctlMode, freq;
Sujithb5aec952009-08-07 09:45:15 +0530488 struct chan_centers centers;
489 int tx_chainmask;
490 u16 twiceMinEdgePower;
491 struct ar9287_eeprom *pEepData = &ah->eeprom.map9287;
492 tx_chainmask = ah->txchainmask;
493
494 ath9k_hw_get_channel_centers(ah, chan, &centers);
495
Sujitha55f8582010-06-01 15:14:07 +0530496 /* Compute TxPower reduction due to Antenna Gain */
Sujithb5aec952009-08-07 09:45:15 +0530497 twiceLargestAntenna = max(pEepData->modalHeader.antennaGainCh[0],
498 pEepData->modalHeader.antennaGainCh[1]);
Sujith16c94ac2010-06-01 15:14:04 +0530499 twiceLargestAntenna = (int16_t)min((AntennaReduction) -
500 twiceLargestAntenna, 0);
Sujithb5aec952009-08-07 09:45:15 +0530501
Sujitha55f8582010-06-01 15:14:07 +0530502 /*
503 * scaledPower is the minimum of the user input power level
504 * and the regulatory allowed power level.
505 */
Sujithb5aec952009-08-07 09:45:15 +0530506 maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
Sujitha55f8582010-06-01 15:14:07 +0530507
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700508 if (regulatory->tp_scale != ATH9K_TP_SCALE_MAX)
Sujithb5aec952009-08-07 09:45:15 +0530509 maxRegAllowedPower -=
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700510 (tpScaleReductionTable[(regulatory->tp_scale)] * 2);
Sujithb5aec952009-08-07 09:45:15 +0530511
512 scaledPower = min(powerLimit, maxRegAllowedPower);
513
Sujitha55f8582010-06-01 15:14:07 +0530514 /*
515 * Reduce scaled Power by number of chains active
516 * to get the per chain tx power level.
517 */
Sujithb5aec952009-08-07 09:45:15 +0530518 switch (ar5416_get_ntxchains(tx_chainmask)) {
519 case 1:
520 break;
521 case 2:
Daniel Halperin21fdc872011-05-31 11:59:30 -0700522 if (scaledPower > REDUCE_SCALED_POWER_BY_TWO_CHAIN)
523 scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN;
524 else
525 scaledPower = 0;
Sujithb5aec952009-08-07 09:45:15 +0530526 break;
527 case 3:
Daniel Halperin21fdc872011-05-31 11:59:30 -0700528 if (scaledPower > REDUCE_SCALED_POWER_BY_THREE_CHAIN)
529 scaledPower -= REDUCE_SCALED_POWER_BY_THREE_CHAIN;
530 else
531 scaledPower = 0;
Sujithb5aec952009-08-07 09:45:15 +0530532 break;
533 }
534 scaledPower = max((u16)0, scaledPower);
535
Sujitha55f8582010-06-01 15:14:07 +0530536 /*
537 * Get TX power from EEPROM.
538 */
Sujithb5aec952009-08-07 09:45:15 +0530539 if (IS_CHAN_2GHZ(chan)) {
Sujitha55f8582010-06-01 15:14:07 +0530540 /* CTL_11B, CTL_11G, CTL_2GHT20 */
Sujithb5aec952009-08-07 09:45:15 +0530541 numCtlModes =
542 ARRAY_SIZE(ctlModesFor11g) - SUB_NUM_CTL_MODES_AT_2G_40;
Sujith16c94ac2010-06-01 15:14:04 +0530543
Sujithb5aec952009-08-07 09:45:15 +0530544 pCtlMode = ctlModesFor11g;
545
546 ath9k_hw_get_legacy_target_powers(ah, chan,
547 pEepData->calTargetPowerCck,
548 AR9287_NUM_2G_CCK_TARGET_POWERS,
549 &targetPowerCck, 4, false);
550 ath9k_hw_get_legacy_target_powers(ah, chan,
551 pEepData->calTargetPower2G,
552 AR9287_NUM_2G_20_TARGET_POWERS,
553 &targetPowerOfdm, 4, false);
554 ath9k_hw_get_target_powers(ah, chan,
555 pEepData->calTargetPower2GHT20,
556 AR9287_NUM_2G_20_TARGET_POWERS,
557 &targetPowerHt20, 8, false);
558
559 if (IS_CHAN_HT40(chan)) {
Sujitha55f8582010-06-01 15:14:07 +0530560 /* All 2G CTLs */
Sujithb5aec952009-08-07 09:45:15 +0530561 numCtlModes = ARRAY_SIZE(ctlModesFor11g);
562 ath9k_hw_get_target_powers(ah, chan,
563 pEepData->calTargetPower2GHT40,
564 AR9287_NUM_2G_40_TARGET_POWERS,
565 &targetPowerHt40, 8, true);
566 ath9k_hw_get_legacy_target_powers(ah, chan,
567 pEepData->calTargetPowerCck,
568 AR9287_NUM_2G_CCK_TARGET_POWERS,
569 &targetPowerCckExt, 4, true);
570 ath9k_hw_get_legacy_target_powers(ah, chan,
571 pEepData->calTargetPower2G,
572 AR9287_NUM_2G_20_TARGET_POWERS,
573 &targetPowerOfdmExt, 4, true);
574 }
575 }
576
577 for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
Sujitha55f8582010-06-01 15:14:07 +0530578 bool isHt40CtlMode =
579 (pCtlMode[ctlMode] == CTL_2GHT40) ? true : false;
580
Sujithb5aec952009-08-07 09:45:15 +0530581 if (isHt40CtlMode)
582 freq = centers.synth_center;
583 else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
584 freq = centers.ext_center;
585 else
586 freq = centers.ctl_center;
587
Sujitha55f8582010-06-01 15:14:07 +0530588 /* Walk through the CTL indices stored in EEPROM */
Sujithb5aec952009-08-07 09:45:15 +0530589 for (i = 0; (i < AR9287_NUM_CTLS) && pEepData->ctlIndex[i]; i++) {
Sujitha55f8582010-06-01 15:14:07 +0530590 struct cal_ctl_edges *pRdEdgesPower;
Sujithb5aec952009-08-07 09:45:15 +0530591
Sujitha55f8582010-06-01 15:14:07 +0530592 /*
593 * Compare test group from regulatory channel list
594 * with test mode from pCtlMode list
595 */
596 if (CMP_CTL || CMP_NO_CTL) {
Sujithb5aec952009-08-07 09:45:15 +0530597 rep = &(pEepData->ctlData[i]);
Sujitha55f8582010-06-01 15:14:07 +0530598 pRdEdgesPower =
599 rep->ctlEdges[ar5416_get_ntxchains(tx_chainmask) - 1];
Sujithb5aec952009-08-07 09:45:15 +0530600
Sujitha55f8582010-06-01 15:14:07 +0530601 twiceMinEdgePower = ath9k_hw_get_max_edge_power(freq,
602 pRdEdgesPower,
603 IS_CHAN_2GHZ(chan),
604 AR5416_NUM_BAND_EDGES);
605
606 if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {
607 twiceMaxEdgePower = min(twiceMaxEdgePower,
608 twiceMinEdgePower);
609 } else {
Sujithb5aec952009-08-07 09:45:15 +0530610 twiceMaxEdgePower = twiceMinEdgePower;
611 break;
612 }
613 }
614 }
615
616 minCtlPower = (u8)min(twiceMaxEdgePower, scaledPower);
617
Sujitha55f8582010-06-01 15:14:07 +0530618 /* Apply ctl mode to correct target power set */
Sujithb5aec952009-08-07 09:45:15 +0530619 switch (pCtlMode[ctlMode]) {
620 case CTL_11B:
Sujitha55f8582010-06-01 15:14:07 +0530621 for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x); i++) {
622 targetPowerCck.tPow2x[i] =
623 (u8)min((u16)targetPowerCck.tPow2x[i],
624 minCtlPower);
Sujithb5aec952009-08-07 09:45:15 +0530625 }
626 break;
627 case CTL_11A:
628 case CTL_11G:
Sujitha55f8582010-06-01 15:14:07 +0530629 for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x); i++) {
630 targetPowerOfdm.tPow2x[i] =
631 (u8)min((u16)targetPowerOfdm.tPow2x[i],
632 minCtlPower);
Sujithb5aec952009-08-07 09:45:15 +0530633 }
634 break;
635 case CTL_5GHT20:
636 case CTL_2GHT20:
Sujitha55f8582010-06-01 15:14:07 +0530637 for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) {
638 targetPowerHt20.tPow2x[i] =
639 (u8)min((u16)targetPowerHt20.tPow2x[i],
640 minCtlPower);
Sujithb5aec952009-08-07 09:45:15 +0530641 }
642 break;
643 case CTL_11B_EXT:
Sujitha55f8582010-06-01 15:14:07 +0530644 targetPowerCckExt.tPow2x[0] =
645 (u8)min((u16)targetPowerCckExt.tPow2x[0],
646 minCtlPower);
Sujithb5aec952009-08-07 09:45:15 +0530647 break;
648 case CTL_11A_EXT:
649 case CTL_11G_EXT:
Sujitha55f8582010-06-01 15:14:07 +0530650 targetPowerOfdmExt.tPow2x[0] =
651 (u8)min((u16)targetPowerOfdmExt.tPow2x[0],
652 minCtlPower);
Sujithb5aec952009-08-07 09:45:15 +0530653 break;
654 case CTL_5GHT40:
655 case CTL_2GHT40:
Sujitha55f8582010-06-01 15:14:07 +0530656 for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
657 targetPowerHt40.tPow2x[i] =
658 (u8)min((u16)targetPowerHt40.tPow2x[i],
659 minCtlPower);
Sujithb5aec952009-08-07 09:45:15 +0530660 }
661 break;
662 default:
663 break;
664 }
665 }
666
Sujitha55f8582010-06-01 15:14:07 +0530667 /* Now set the rates array */
668
Sujithb5aec952009-08-07 09:45:15 +0530669 ratesArray[rate6mb] =
670 ratesArray[rate9mb] =
671 ratesArray[rate12mb] =
672 ratesArray[rate18mb] =
Sujitha55f8582010-06-01 15:14:07 +0530673 ratesArray[rate24mb] = targetPowerOfdm.tPow2x[0];
Sujithb5aec952009-08-07 09:45:15 +0530674
675 ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1];
676 ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2];
677 ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3];
678 ratesArray[rateXr] = targetPowerOfdm.tPow2x[0];
679
680 for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++)
681 ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i];
682
683 if (IS_CHAN_2GHZ(chan)) {
684 ratesArray[rate1l] = targetPowerCck.tPow2x[0];
Sujitha55f8582010-06-01 15:14:07 +0530685 ratesArray[rate2s] =
686 ratesArray[rate2l] = targetPowerCck.tPow2x[1];
687 ratesArray[rate5_5s] =
688 ratesArray[rate5_5l] = targetPowerCck.tPow2x[2];
689 ratesArray[rate11s] =
690 ratesArray[rate11l] = targetPowerCck.tPow2x[3];
Sujithb5aec952009-08-07 09:45:15 +0530691 }
692 if (IS_CHAN_HT40(chan)) {
693 for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++)
694 ratesArray[rateHt40_0 + i] = targetPowerHt40.tPow2x[i];
695
696 ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0];
697 ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0];
698 ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0];
Sujitha55f8582010-06-01 15:14:07 +0530699
Sujithb5aec952009-08-07 09:45:15 +0530700 if (IS_CHAN_2GHZ(chan))
701 ratesArray[rateExtCck] = targetPowerCckExt.tPow2x[0];
702 }
703
Sujitha55f8582010-06-01 15:14:07 +0530704#undef CMP_CTL
705#undef CMP_NO_CTL
Sujithb5aec952009-08-07 09:45:15 +0530706#undef REDUCE_SCALED_POWER_BY_TWO_CHAIN
707#undef REDUCE_SCALED_POWER_BY_THREE_CHAIN
708}
709
Sujith16c94ac2010-06-01 15:14:04 +0530710static void ath9k_hw_ar9287_set_txpower(struct ath_hw *ah,
Sujithb5aec952009-08-07 09:45:15 +0530711 struct ath9k_channel *chan, u16 cfgCtl,
712 u8 twiceAntennaReduction,
713 u8 twiceMaxRegulatoryPower,
Felix Fietkaude40f312010-10-20 03:08:53 +0200714 u8 powerLimit, bool test)
Sujithb5aec952009-08-07 09:45:15 +0530715{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700716 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithb5aec952009-08-07 09:45:15 +0530717 struct ar9287_eeprom *pEepData = &ah->eeprom.map9287;
718 struct modal_eep_ar9287_header *pModal = &pEepData->modalHeader;
719 int16_t ratesArray[Ar5416RateSize];
Sujithb5aec952009-08-07 09:45:15 +0530720 u8 ht40PowerIncForPdadc = 2;
721 int i;
722
723 memset(ratesArray, 0, sizeof(ratesArray));
724
725 if ((pEepData->baseEepHeader.version & AR9287_EEP_VER_MINOR_MASK) >=
726 AR9287_EEP_MINOR_VER_2)
727 ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
728
Sujith16c94ac2010-06-01 15:14:04 +0530729 ath9k_hw_set_ar9287_power_per_rate_table(ah, chan,
Sujithb5aec952009-08-07 09:45:15 +0530730 &ratesArray[0], cfgCtl,
731 twiceAntennaReduction,
732 twiceMaxRegulatoryPower,
733 powerLimit);
734
Felix Fietkaue832bf12011-07-27 15:01:03 +0200735 ath9k_hw_set_ar9287_power_cal_table(ah, chan);
Sujithb5aec952009-08-07 09:45:15 +0530736
Felix Fietkaude40f312010-10-20 03:08:53 +0200737 regulatory->max_power_level = 0;
Sujithb5aec952009-08-07 09:45:15 +0530738 for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100739 if (ratesArray[i] > MAX_RATE_POWER)
740 ratesArray[i] = MAX_RATE_POWER;
Felix Fietkaude40f312010-10-20 03:08:53 +0200741
742 if (ratesArray[i] > regulatory->max_power_level)
743 regulatory->max_power_level = ratesArray[i];
Sujithb5aec952009-08-07 09:45:15 +0530744 }
745
Felix Fietkaude40f312010-10-20 03:08:53 +0200746 if (test)
747 return;
748
Felix Fietkau7a370812010-09-22 12:34:52 +0200749 if (AR_SREV_9280_20_OR_LATER(ah)) {
Sujithb5aec952009-08-07 09:45:15 +0530750 for (i = 0; i < Ar5416RateSize; i++)
751 ratesArray[i] -= AR9287_PWR_TABLE_OFFSET_DB * 2;
752 }
753
Rajkumar Manoharane7fc6332011-03-15 23:11:35 +0530754 ENABLE_REGWRITE_BUFFER(ah);
755
Sujitha55f8582010-06-01 15:14:07 +0530756 /* OFDM power per rate */
Sujithb5aec952009-08-07 09:45:15 +0530757 REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
758 ATH9K_POW_SM(ratesArray[rate18mb], 24)
759 | ATH9K_POW_SM(ratesArray[rate12mb], 16)
760 | ATH9K_POW_SM(ratesArray[rate9mb], 8)
761 | ATH9K_POW_SM(ratesArray[rate6mb], 0));
762
763 REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
764 ATH9K_POW_SM(ratesArray[rate54mb], 24)
765 | ATH9K_POW_SM(ratesArray[rate48mb], 16)
766 | ATH9K_POW_SM(ratesArray[rate36mb], 8)
767 | ATH9K_POW_SM(ratesArray[rate24mb], 0));
768
Sujitha55f8582010-06-01 15:14:07 +0530769 /* CCK power per rate */
Sujithb5aec952009-08-07 09:45:15 +0530770 if (IS_CHAN_2GHZ(chan)) {
771 REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
772 ATH9K_POW_SM(ratesArray[rate2s], 24)
773 | ATH9K_POW_SM(ratesArray[rate2l], 16)
774 | ATH9K_POW_SM(ratesArray[rateXr], 8)
775 | ATH9K_POW_SM(ratesArray[rate1l], 0));
776 REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
777 ATH9K_POW_SM(ratesArray[rate11s], 24)
778 | ATH9K_POW_SM(ratesArray[rate11l], 16)
779 | ATH9K_POW_SM(ratesArray[rate5_5s], 8)
780 | ATH9K_POW_SM(ratesArray[rate5_5l], 0));
781 }
782
Sujitha55f8582010-06-01 15:14:07 +0530783 /* HT20 power per rate */
Sujithb5aec952009-08-07 09:45:15 +0530784 REG_WRITE(ah, AR_PHY_POWER_TX_RATE5,
785 ATH9K_POW_SM(ratesArray[rateHt20_3], 24)
786 | ATH9K_POW_SM(ratesArray[rateHt20_2], 16)
787 | ATH9K_POW_SM(ratesArray[rateHt20_1], 8)
788 | ATH9K_POW_SM(ratesArray[rateHt20_0], 0));
789
790 REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
791 ATH9K_POW_SM(ratesArray[rateHt20_7], 24)
792 | ATH9K_POW_SM(ratesArray[rateHt20_6], 16)
793 | ATH9K_POW_SM(ratesArray[rateHt20_5], 8)
794 | ATH9K_POW_SM(ratesArray[rateHt20_4], 0));
795
Sujitha55f8582010-06-01 15:14:07 +0530796 /* HT40 power per rate */
Sujithb5aec952009-08-07 09:45:15 +0530797 if (IS_CHAN_HT40(chan)) {
Sujith16c94ac2010-06-01 15:14:04 +0530798 if (ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
Sujithb5aec952009-08-07 09:45:15 +0530799 REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
800 ATH9K_POW_SM(ratesArray[rateHt40_3], 24)
801 | ATH9K_POW_SM(ratesArray[rateHt40_2], 16)
802 | ATH9K_POW_SM(ratesArray[rateHt40_1], 8)
803 | ATH9K_POW_SM(ratesArray[rateHt40_0], 0));
804
805 REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
806 ATH9K_POW_SM(ratesArray[rateHt40_7], 24)
807 | ATH9K_POW_SM(ratesArray[rateHt40_6], 16)
808 | ATH9K_POW_SM(ratesArray[rateHt40_5], 8)
809 | ATH9K_POW_SM(ratesArray[rateHt40_4], 0));
810 } else {
811 REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
812 ATH9K_POW_SM(ratesArray[rateHt40_3] +
813 ht40PowerIncForPdadc, 24)
814 | ATH9K_POW_SM(ratesArray[rateHt40_2] +
815 ht40PowerIncForPdadc, 16)
816 | ATH9K_POW_SM(ratesArray[rateHt40_1] +
817 ht40PowerIncForPdadc, 8)
818 | ATH9K_POW_SM(ratesArray[rateHt40_0] +
819 ht40PowerIncForPdadc, 0));
820
821 REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
822 ATH9K_POW_SM(ratesArray[rateHt40_7] +
823 ht40PowerIncForPdadc, 24)
824 | ATH9K_POW_SM(ratesArray[rateHt40_6] +
825 ht40PowerIncForPdadc, 16)
826 | ATH9K_POW_SM(ratesArray[rateHt40_5] +
827 ht40PowerIncForPdadc, 8)
828 | ATH9K_POW_SM(ratesArray[rateHt40_4] +
829 ht40PowerIncForPdadc, 0));
830 }
831
Sujitha55f8582010-06-01 15:14:07 +0530832 /* Dup/Ext power per rate */
Sujithb5aec952009-08-07 09:45:15 +0530833 REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
834 ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
835 | ATH9K_POW_SM(ratesArray[rateExtCck], 16)
836 | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
837 | ATH9K_POW_SM(ratesArray[rateDupCck], 0));
838 }
Rajkumar Manoharane7fc6332011-03-15 23:11:35 +0530839 REGWRITE_BUFFER_FLUSH(ah);
Sujithb5aec952009-08-07 09:45:15 +0530840}
841
Sujith16c94ac2010-06-01 15:14:04 +0530842static void ath9k_hw_ar9287_set_addac(struct ath_hw *ah,
Sujithb5aec952009-08-07 09:45:15 +0530843 struct ath9k_channel *chan)
844{
845}
846
Sujith16c94ac2010-06-01 15:14:04 +0530847static void ath9k_hw_ar9287_set_board_values(struct ath_hw *ah,
Sujithb5aec952009-08-07 09:45:15 +0530848 struct ath9k_channel *chan)
849{
850 struct ar9287_eeprom *eep = &ah->eeprom.map9287;
851 struct modal_eep_ar9287_header *pModal = &eep->modalHeader;
Sujith79d7f4b2010-06-01 15:14:06 +0530852 u32 regChainOffset, regval;
Sujithb5aec952009-08-07 09:45:15 +0530853 u8 txRxAttenLocal;
Rajkumar Manoharan2d05a0c2011-04-11 20:22:28 +0530854 int i;
Sujithb5aec952009-08-07 09:45:15 +0530855
856 pModal = &eep->modalHeader;
857
Felix Fietkaudf3c8b22010-12-12 00:51:11 +0100858 REG_WRITE(ah, AR_PHY_SWITCH_COM, pModal->antCtrlCommon);
Sujithb5aec952009-08-07 09:45:15 +0530859
860 for (i = 0; i < AR9287_MAX_CHAINS; i++) {
861 regChainOffset = i * 0x1000;
862
863 REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
864 pModal->antCtrlChain[i]);
865
866 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
867 (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset)
868 & ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
869 AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
870 SM(pModal->iqCalICh[i],
871 AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
872 SM(pModal->iqCalQCh[i],
873 AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
874
875 txRxAttenLocal = pModal->txRxAttenCh[i];
876
877 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
878 AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN,
879 pModal->bswMargin[i]);
880 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
881 AR_PHY_GAIN_2GHZ_XATTEN1_DB,
882 pModal->bswAtten[i]);
883 REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
884 AR9280_PHY_RXGAIN_TXRX_ATTEN,
885 txRxAttenLocal);
886 REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
887 AR9280_PHY_RXGAIN_TXRX_MARGIN,
888 pModal->rxTxMarginCh[i]);
889 }
890
891
892 if (IS_CHAN_HT40(chan))
893 REG_RMW_FIELD(ah, AR_PHY_SETTLING,
894 AR_PHY_SETTLING_SWITCH, pModal->swSettleHt40);
895 else
896 REG_RMW_FIELD(ah, AR_PHY_SETTLING,
897 AR_PHY_SETTLING_SWITCH, pModal->switchSettling);
898
899 REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
900 AR_PHY_DESIRED_SZ_ADC, pModal->adcDesiredSize);
901
902 REG_WRITE(ah, AR_PHY_RF_CTL4,
903 SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF)
904 | SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAB_OFF)
905 | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAA_ON)
906 | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAB_ON));
907
908 REG_RMW_FIELD(ah, AR_PHY_RF_CTL3,
909 AR_PHY_TX_END_TO_A2_RX_ON, pModal->txEndToRxOn);
910
911 REG_RMW_FIELD(ah, AR_PHY_CCA,
912 AR9280_PHY_CCA_THRESH62, pModal->thresh62);
913 REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0,
914 AR_PHY_EXT_CCA0_THRESH62, pModal->thresh62);
915
Sujith79d7f4b2010-06-01 15:14:06 +0530916 regval = REG_READ(ah, AR9287_AN_RF2G3_CH0);
917 regval &= ~(AR9287_AN_RF2G3_DB1 |
918 AR9287_AN_RF2G3_DB2 |
919 AR9287_AN_RF2G3_OB_CCK |
920 AR9287_AN_RF2G3_OB_PSK |
921 AR9287_AN_RF2G3_OB_QAM |
922 AR9287_AN_RF2G3_OB_PAL_OFF);
923 regval |= (SM(pModal->db1, AR9287_AN_RF2G3_DB1) |
924 SM(pModal->db2, AR9287_AN_RF2G3_DB2) |
925 SM(pModal->ob_cck, AR9287_AN_RF2G3_OB_CCK) |
926 SM(pModal->ob_psk, AR9287_AN_RF2G3_OB_PSK) |
927 SM(pModal->ob_qam, AR9287_AN_RF2G3_OB_QAM) |
928 SM(pModal->ob_pal_off, AR9287_AN_RF2G3_OB_PAL_OFF));
Sujithb5aec952009-08-07 09:45:15 +0530929
Sujith79d7f4b2010-06-01 15:14:06 +0530930 ath9k_hw_analog_shift_regwrite(ah, AR9287_AN_RF2G3_CH0, regval);
931
932 regval = REG_READ(ah, AR9287_AN_RF2G3_CH1);
933 regval &= ~(AR9287_AN_RF2G3_DB1 |
934 AR9287_AN_RF2G3_DB2 |
935 AR9287_AN_RF2G3_OB_CCK |
936 AR9287_AN_RF2G3_OB_PSK |
937 AR9287_AN_RF2G3_OB_QAM |
938 AR9287_AN_RF2G3_OB_PAL_OFF);
939 regval |= (SM(pModal->db1, AR9287_AN_RF2G3_DB1) |
940 SM(pModal->db2, AR9287_AN_RF2G3_DB2) |
941 SM(pModal->ob_cck, AR9287_AN_RF2G3_OB_CCK) |
942 SM(pModal->ob_psk, AR9287_AN_RF2G3_OB_PSK) |
943 SM(pModal->ob_qam, AR9287_AN_RF2G3_OB_QAM) |
944 SM(pModal->ob_pal_off, AR9287_AN_RF2G3_OB_PAL_OFF));
945
946 ath9k_hw_analog_shift_regwrite(ah, AR9287_AN_RF2G3_CH1, regval);
Sujithb5aec952009-08-07 09:45:15 +0530947
948 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
949 AR_PHY_TX_END_DATA_START, pModal->txFrameToDataStart);
950 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
951 AR_PHY_TX_END_PA_ON, pModal->txFrameToPaOn);
952
953 ath9k_hw_analog_shift_rmw(ah, AR9287_AN_TOP2,
954 AR9287_AN_TOP2_XPABIAS_LVL,
955 AR9287_AN_TOP2_XPABIAS_LVL_S,
956 pModal->xpaBiasLvl);
957}
958
Sujith16c94ac2010-06-01 15:14:04 +0530959static u16 ath9k_hw_ar9287_get_spur_channel(struct ath_hw *ah,
Sujithb5aec952009-08-07 09:45:15 +0530960 u16 i, bool is2GHz)
961{
962#define EEP_MAP9287_SPURCHAN \
963 (ah->eeprom.map9287.modalHeader.spurChans[i].spurChan)
Sujith16c94ac2010-06-01 15:14:04 +0530964
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700965 struct ath_common *common = ath9k_hw_common(ah);
Sujithb5aec952009-08-07 09:45:15 +0530966 u16 spur_val = AR_NO_SPUR;
967
Joe Perches226afe62010-12-02 19:12:37 -0800968 ath_dbg(common, ATH_DBG_ANI,
969 "Getting spur idx:%d is2Ghz:%d val:%x\n",
970 i, is2GHz, ah->config.spurchans[i][is2GHz]);
Sujithb5aec952009-08-07 09:45:15 +0530971
972 switch (ah->config.spurmode) {
973 case SPUR_DISABLE:
974 break;
975 case SPUR_ENABLE_IOCTL:
976 spur_val = ah->config.spurchans[i][is2GHz];
Joe Perches226afe62010-12-02 19:12:37 -0800977 ath_dbg(common, ATH_DBG_ANI,
978 "Getting spur val from new loc. %d\n", spur_val);
Sujithb5aec952009-08-07 09:45:15 +0530979 break;
980 case SPUR_ENABLE_EEPROM:
981 spur_val = EEP_MAP9287_SPURCHAN;
982 break;
983 }
984
985 return spur_val;
986
987#undef EEP_MAP9287_SPURCHAN
988}
989
Luis R. Rodriguez0b8f6f2b12010-04-15 17:39:12 -0400990const struct eeprom_ops eep_ar9287_ops = {
Sujith16c94ac2010-06-01 15:14:04 +0530991 .check_eeprom = ath9k_hw_ar9287_check_eeprom,
992 .get_eeprom = ath9k_hw_ar9287_get_eeprom,
993 .fill_eeprom = ath9k_hw_ar9287_fill_eeprom,
994 .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,
997 .set_addac = ath9k_hw_ar9287_set_addac,
998 .set_txpower = ath9k_hw_ar9287_set_txpower,
999 .get_spur_channel = ath9k_hw_ar9287_get_spur_channel
Sujithb5aec952009-08-07 09:45:15 +05301000};