blob: 2f0712ea49a69c97287888ecc53dc84e7d8b51f4 [file] [log] [blame]
Sujithb5aec952009-08-07 09:45:15 +05301/*
2 * Copyright (c) 2008-2009 Atheros Communications Inc.
3 *
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
7 *
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070017#include "hw.h"
Luis R. Rodriguez8fe65362010-04-15 17:38:14 -040018#include "ar9002_phy.h"
Sujithb5aec952009-08-07 09:45:15 +053019
Sujith Manoharan04cf53f2011-01-04 13:17:28 +053020#define SIZE_EEPROM_AR9287 (sizeof(struct ar9287_eeprom) / sizeof(u16))
Sujith16c94ac2010-06-01 15:14:04 +053021
22static int ath9k_hw_ar9287_get_eeprom_ver(struct ath_hw *ah)
Sujithb5aec952009-08-07 09:45:15 +053023{
24 return (ah->eeprom.map9287.baseEepHeader.version >> 12) & 0xF;
25}
26
Sujith16c94ac2010-06-01 15:14:04 +053027static int ath9k_hw_ar9287_get_eeprom_rev(struct ath_hw *ah)
Sujithb5aec952009-08-07 09:45:15 +053028{
29 return (ah->eeprom.map9287.baseEepHeader.version) & 0xFFF;
30}
31
Sujith Manoharan04cf53f2011-01-04 13:17:28 +053032static bool __ath9k_hw_ar9287_fill_eeprom(struct ath_hw *ah)
Sujithb5aec952009-08-07 09:45:15 +053033{
34 struct ar9287_eeprom *eep = &ah->eeprom.map9287;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070035 struct ath_common *common = ath9k_hw_common(ah);
Sujithb5aec952009-08-07 09:45:15 +053036 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++) {
Sujith16c94ac2010-06-01 15:14:04 +053041 if (!ath9k_hw_nvram_read(common, addr + eep_start_loc,
42 eep_data)) {
Joe Perches226afe62010-12-02 19:12:37 -080043 ath_dbg(common, ATH_DBG_EEPROM,
44 "Unable to read eeprom region\n");
Sujithb5aec952009-08-07 09:45:15 +053045 return false;
46 }
47 eep_data++;
48 }
Sujith16c94ac2010-06-01 15:14:04 +053049
Sujithb5aec952009-08-07 09:45:15 +053050 return true;
51}
52
Sujith Manoharan04cf53f2011-01-04 13:17:28 +053053static bool __ath9k_hw_usb_ar9287_fill_eeprom(struct ath_hw *ah)
54{
55 u16 *eep_data = (u16 *)&ah->eeprom.map9287;
56
57 ath9k_hw_usb_gen_fill_eeprom(ah, eep_data,
58 AR9287_HTC_EEP_START_LOC,
59 SIZE_EEPROM_AR9287);
60 return true;
61}
62
63static bool ath9k_hw_ar9287_fill_eeprom(struct ath_hw *ah)
64{
65 struct ath_common *common = ath9k_hw_common(ah);
66
67 if (!ath9k_hw_use_flash(ah)) {
68 ath_dbg(common, ATH_DBG_EEPROM,
69 "Reading from EEPROM, not flash\n");
70 }
71
72 if (common->bus_ops->ath_bus_type == ATH_USB)
73 return __ath9k_hw_usb_ar9287_fill_eeprom(ah);
74 else
75 return __ath9k_hw_ar9287_fill_eeprom(ah);
76}
77
Sujith16c94ac2010-06-01 15:14:04 +053078static int ath9k_hw_ar9287_check_eeprom(struct ath_hw *ah)
Sujithb5aec952009-08-07 09:45:15 +053079{
80 u32 sum = 0, el, integer;
81 u16 temp, word, magic, magic2, *eepdata;
82 int i, addr;
83 bool need_swap = false;
84 struct ar9287_eeprom *eep = &ah->eeprom.map9287;
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -070085 struct ath_common *common = ath9k_hw_common(ah);
Sujithb5aec952009-08-07 09:45:15 +053086
87 if (!ath9k_hw_use_flash(ah)) {
Sujith16c94ac2010-06-01 15:14:04 +053088 if (!ath9k_hw_nvram_read(common, AR5416_EEPROM_MAGIC_OFFSET,
89 &magic)) {
Joe Perches38002762010-12-02 19:12:36 -080090 ath_err(common, "Reading Magic # failed\n");
Sujithb5aec952009-08-07 09:45:15 +053091 return false;
92 }
93
Joe Perches226afe62010-12-02 19:12:37 -080094 ath_dbg(common, ATH_DBG_EEPROM,
95 "Read Magic = 0x%04X\n", magic);
Sujith16c94ac2010-06-01 15:14:04 +053096
Sujithb5aec952009-08-07 09:45:15 +053097 if (magic != AR5416_EEPROM_MAGIC) {
98 magic2 = swab16(magic);
99
100 if (magic2 == AR5416_EEPROM_MAGIC) {
101 need_swap = true;
102 eepdata = (u16 *)(&ah->eeprom);
103
Sujith Manoharan04cf53f2011-01-04 13:17:28 +0530104 for (addr = 0; addr < SIZE_EEPROM_AR9287; addr++) {
Sujithb5aec952009-08-07 09:45:15 +0530105 temp = swab16(*eepdata);
106 *eepdata = temp;
107 eepdata++;
108 }
109 } else {
Joe Perches38002762010-12-02 19:12:36 -0800110 ath_err(common,
111 "Invalid EEPROM Magic. Endianness mismatch.\n");
Sujithb5aec952009-08-07 09:45:15 +0530112 return -EINVAL;
113 }
114 }
115 }
Sujith16c94ac2010-06-01 15:14:04 +0530116
Joe Perches226afe62010-12-02 19:12:37 -0800117 ath_dbg(common, ATH_DBG_EEPROM, "need_swap = %s.\n",
118 need_swap ? "True" : "False");
Sujithb5aec952009-08-07 09:45:15 +0530119
120 if (need_swap)
121 el = swab16(ah->eeprom.map9287.baseEepHeader.length);
122 else
123 el = ah->eeprom.map9287.baseEepHeader.length;
124
125 if (el > sizeof(struct ar9287_eeprom))
126 el = sizeof(struct ar9287_eeprom) / sizeof(u16);
127 else
128 el = el / sizeof(u16);
129
130 eepdata = (u16 *)(&ah->eeprom);
Sujith16c94ac2010-06-01 15:14:04 +0530131
Sujithb5aec952009-08-07 09:45:15 +0530132 for (i = 0; i < el; i++)
133 sum ^= *eepdata++;
134
135 if (need_swap) {
136 word = swab16(eep->baseEepHeader.length);
137 eep->baseEepHeader.length = word;
138
139 word = swab16(eep->baseEepHeader.checksum);
140 eep->baseEepHeader.checksum = word;
141
142 word = swab16(eep->baseEepHeader.version);
143 eep->baseEepHeader.version = word;
144
145 word = swab16(eep->baseEepHeader.regDmn[0]);
146 eep->baseEepHeader.regDmn[0] = word;
147
148 word = swab16(eep->baseEepHeader.regDmn[1]);
149 eep->baseEepHeader.regDmn[1] = word;
150
151 word = swab16(eep->baseEepHeader.rfSilent);
152 eep->baseEepHeader.rfSilent = word;
153
154 word = swab16(eep->baseEepHeader.blueToothOptions);
155 eep->baseEepHeader.blueToothOptions = word;
156
157 word = swab16(eep->baseEepHeader.deviceCap);
158 eep->baseEepHeader.deviceCap = word;
159
160 integer = swab32(eep->modalHeader.antCtrlCommon);
161 eep->modalHeader.antCtrlCommon = integer;
162
163 for (i = 0; i < AR9287_MAX_CHAINS; i++) {
164 integer = swab32(eep->modalHeader.antCtrlChain[i]);
165 eep->modalHeader.antCtrlChain[i] = integer;
166 }
167
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100168 for (i = 0; i < AR_EEPROM_MODAL_SPURS; i++) {
Sujithb5aec952009-08-07 09:45:15 +0530169 word = swab16(eep->modalHeader.spurChans[i].spurChan);
170 eep->modalHeader.spurChans[i].spurChan = word;
171 }
172 }
173
174 if (sum != 0xffff || ah->eep_ops->get_eeprom_ver(ah) != AR9287_EEP_VER
175 || ah->eep_ops->get_eeprom_rev(ah) < AR5416_EEP_NO_BACK_VER) {
Joe Perches38002762010-12-02 19:12:36 -0800176 ath_err(common, "Bad EEPROM checksum 0x%x or revision 0x%04x\n",
177 sum, ah->eep_ops->get_eeprom_ver(ah));
Sujithb5aec952009-08-07 09:45:15 +0530178 return -EINVAL;
179 }
180
181 return 0;
182}
183
Sujith16c94ac2010-06-01 15:14:04 +0530184static u32 ath9k_hw_ar9287_get_eeprom(struct ath_hw *ah,
Sujithb5aec952009-08-07 09:45:15 +0530185 enum eeprom_param param)
186{
187 struct ar9287_eeprom *eep = &ah->eeprom.map9287;
188 struct modal_eep_ar9287_header *pModal = &eep->modalHeader;
189 struct base_eep_ar9287_header *pBase = &eep->baseEepHeader;
190 u16 ver_minor;
191
192 ver_minor = pBase->version & AR9287_EEP_VER_MINOR_MASK;
Sujith16c94ac2010-06-01 15:14:04 +0530193
Sujithb5aec952009-08-07 09:45:15 +0530194 switch (param) {
195 case EEP_NFTHRESH_2:
196 return pModal->noiseFloorThreshCh[0];
Luis R. Rodriguez49101672010-04-15 17:39:13 -0400197 case EEP_MAC_LSW:
Sujithb5aec952009-08-07 09:45:15 +0530198 return pBase->macAddr[0] << 8 | pBase->macAddr[1];
Luis R. Rodriguez49101672010-04-15 17:39:13 -0400199 case EEP_MAC_MID:
Sujithb5aec952009-08-07 09:45:15 +0530200 return pBase->macAddr[2] << 8 | pBase->macAddr[3];
Luis R. Rodriguez49101672010-04-15 17:39:13 -0400201 case EEP_MAC_MSW:
Sujithb5aec952009-08-07 09:45:15 +0530202 return pBase->macAddr[4] << 8 | pBase->macAddr[5];
203 case EEP_REG_0:
204 return pBase->regDmn[0];
205 case EEP_REG_1:
206 return pBase->regDmn[1];
207 case EEP_OP_CAP:
208 return pBase->deviceCap;
209 case EEP_OP_MODE:
210 return pBase->opCapFlags;
211 case EEP_RF_SILENT:
212 return pBase->rfSilent;
213 case EEP_MINOR_REV:
214 return ver_minor;
215 case EEP_TX_MASK:
216 return pBase->txMask;
217 case EEP_RX_MASK:
218 return pBase->rxMask;
219 case EEP_DEV_TYPE:
220 return pBase->deviceType;
221 case EEP_OL_PWRCTRL:
222 return pBase->openLoopPwrCntl;
223 case EEP_TEMPSENSE_SLOPE:
224 if (ver_minor >= AR9287_EEP_MINOR_VER_2)
225 return pBase->tempSensSlope;
226 else
227 return 0;
228 case EEP_TEMPSENSE_SLOPE_PAL_ON:
229 if (ver_minor >= AR9287_EEP_MINOR_VER_3)
230 return pBase->tempSensSlopePalOn;
231 else
232 return 0;
233 default:
234 return 0;
235 }
236}
237
Sujithb5aec952009-08-07 09:45:15 +0530238static void ar9287_eeprom_get_tx_gain_index(struct ath_hw *ah,
239 struct ath9k_channel *chan,
240 struct cal_data_op_loop_ar9287 *pRawDatasetOpLoop,
Sujith16c94ac2010-06-01 15:14:04 +0530241 u8 *pCalChans, u16 availPiers, int8_t *pPwr)
Sujithb5aec952009-08-07 09:45:15 +0530242{
Sujith16c94ac2010-06-01 15:14:04 +0530243 u16 idxL = 0, idxR = 0, numPiers;
Sujithb5aec952009-08-07 09:45:15 +0530244 bool match;
245 struct chan_centers centers;
246
247 ath9k_hw_get_channel_centers(ah, chan, &centers);
248
249 for (numPiers = 0; numPiers < availPiers; numPiers++) {
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100250 if (pCalChans[numPiers] == AR5416_BCHAN_UNUSED)
Sujithb5aec952009-08-07 09:45:15 +0530251 break;
252 }
253
254 match = ath9k_hw_get_lower_upper_index(
Sujitha55f8582010-06-01 15:14:07 +0530255 (u8)FREQ2FBIN(centers.synth_center, IS_CHAN_2GHZ(chan)),
256 pCalChans, numPiers, &idxL, &idxR);
Sujithb5aec952009-08-07 09:45:15 +0530257
258 if (match) {
Vivek Natarajand4fe5af2009-08-14 11:32:04 +0530259 *pPwr = (int8_t) pRawDatasetOpLoop[idxL].pwrPdg[0][0];
Sujithb5aec952009-08-07 09:45:15 +0530260 } else {
Vivek Natarajand4fe5af2009-08-14 11:32:04 +0530261 *pPwr = ((int8_t) pRawDatasetOpLoop[idxL].pwrPdg[0][0] +
Sujith16c94ac2010-06-01 15:14:04 +0530262 (int8_t) pRawDatasetOpLoop[idxR].pwrPdg[0][0])/2;
Sujithb5aec952009-08-07 09:45:15 +0530263 }
264
Sujithb5aec952009-08-07 09:45:15 +0530265}
266
267static void ar9287_eeprom_olpc_set_pdadcs(struct ath_hw *ah,
268 int32_t txPower, u16 chain)
269{
270 u32 tmpVal;
271 u32 a;
272
Sujith16c94ac2010-06-01 15:14:04 +0530273 /* Enable OLPC for chain 0 */
274
Sujithb5aec952009-08-07 09:45:15 +0530275 tmpVal = REG_READ(ah, 0xa270);
276 tmpVal = tmpVal & 0xFCFFFFFF;
277 tmpVal = tmpVal | (0x3 << 24);
278 REG_WRITE(ah, 0xa270, tmpVal);
279
Sujith16c94ac2010-06-01 15:14:04 +0530280 /* Enable OLPC for chain 1 */
281
Sujithb5aec952009-08-07 09:45:15 +0530282 tmpVal = REG_READ(ah, 0xb270);
283 tmpVal = tmpVal & 0xFCFFFFFF;
284 tmpVal = tmpVal | (0x3 << 24);
285 REG_WRITE(ah, 0xb270, tmpVal);
286
Sujith16c94ac2010-06-01 15:14:04 +0530287 /* Write the OLPC ref power for chain 0 */
288
Sujithb5aec952009-08-07 09:45:15 +0530289 if (chain == 0) {
290 tmpVal = REG_READ(ah, 0xa398);
291 tmpVal = tmpVal & 0xff00ffff;
292 a = (txPower)&0xff;
293 tmpVal = tmpVal | (a << 16);
294 REG_WRITE(ah, 0xa398, tmpVal);
295 }
296
Sujith16c94ac2010-06-01 15:14:04 +0530297 /* Write the OLPC ref power for chain 1 */
298
Sujithb5aec952009-08-07 09:45:15 +0530299 if (chain == 1) {
300 tmpVal = REG_READ(ah, 0xb398);
301 tmpVal = tmpVal & 0xff00ffff;
302 a = (txPower)&0xff;
303 tmpVal = tmpVal | (a << 16);
304 REG_WRITE(ah, 0xb398, tmpVal);
305 }
306}
307
Sujith16c94ac2010-06-01 15:14:04 +0530308static void ath9k_hw_set_ar9287_power_cal_table(struct ath_hw *ah,
Sujithb5aec952009-08-07 09:45:15 +0530309 struct ath9k_channel *chan,
310 int16_t *pTxPowerIndexOffset)
311{
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;
Sujith16c94ac2010-06-01 15:14:04 +0530322 int16_t modalIdx, 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 modalIdx = IS_CHAN_2GHZ(chan) ? 1 : 0;
326 xpdMask = pEepData->modalHeader.xpdGain;
Sujith16c94ac2010-06-01 15:14:04 +0530327
Sujithb5aec952009-08-07 09:45:15 +0530328 if ((pEepData->baseEepHeader.version & AR9287_EEP_VER_MINOR_MASK) >=
Sujitha55f8582010-06-01 15:14:07 +0530329 AR9287_EEP_MINOR_VER_2)
Sujithb5aec952009-08-07 09:45:15 +0530330 pdGainOverlap_t2 = pEepData->modalHeader.pdGainOverlap;
331 else
332 pdGainOverlap_t2 = (u16)(MS(REG_READ(ah, AR_PHY_TPCRG5),
333 AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
334
335 if (IS_CHAN_2GHZ(chan)) {
336 pCalBChans = pEepData->calFreqPier2G;
337 numPiers = AR9287_NUM_2G_CAL_PIERS;
Sujith16c94ac2010-06-01 15:14:04 +0530338 if (ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
Sujithb5aec952009-08-07 09:45:15 +0530339 pRawDatasetOpenLoop =
Sujitha55f8582010-06-01 15:14:07 +0530340 (struct cal_data_op_loop_ar9287 *)pEepData->calPierData2G[0];
Sujithb5aec952009-08-07 09:45:15 +0530341 ah->initPDADC = pRawDatasetOpenLoop->vpdPdg[0][0];
342 }
343 }
344
345 numXpdGain = 0;
Sujith16c94ac2010-06-01 15:14:04 +0530346
Sujitha55f8582010-06-01 15:14:07 +0530347 /* Calculate the value of xpdgains from the xpdGain Mask */
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100348 for (i = 1; i <= AR5416_PD_GAINS_IN_MASK; i++) {
349 if ((xpdMask >> (AR5416_PD_GAINS_IN_MASK - i)) & 1) {
350 if (numXpdGain >= AR5416_NUM_PD_GAINS)
Sujithb5aec952009-08-07 09:45:15 +0530351 break;
352 xpdGainValues[numXpdGain] =
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100353 (u16)(AR5416_PD_GAINS_IN_MASK-i);
Sujithb5aec952009-08-07 09:45:15 +0530354 numXpdGain++;
355 }
356 }
357
358 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
359 (numXpdGain - 1) & 0x3);
360 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,
361 xpdGainValues[0]);
362 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
363 xpdGainValues[1]);
364 REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3,
365 xpdGainValues[2]);
366
367 for (i = 0; i < AR9287_MAX_CHAINS; i++) {
368 regChainOffset = i * 0x1000;
Sujitha55f8582010-06-01 15:14:07 +0530369
Sujithb5aec952009-08-07 09:45:15 +0530370 if (pEepData->baseEepHeader.txMask & (1 << i)) {
Sujitha55f8582010-06-01 15:14:07 +0530371 pRawDatasetOpenLoop =
372 (struct cal_data_op_loop_ar9287 *)pEepData->calPierData2G[i];
373
Sujith16c94ac2010-06-01 15:14:04 +0530374 if (ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
Sujithb5aec952009-08-07 09:45:15 +0530375 int8_t txPower;
376 ar9287_eeprom_get_tx_gain_index(ah, chan,
Sujitha55f8582010-06-01 15:14:07 +0530377 pRawDatasetOpenLoop,
378 pCalBChans, numPiers,
379 &txPower);
Sujithb5aec952009-08-07 09:45:15 +0530380 ar9287_eeprom_olpc_set_pdadcs(ah, txPower, i);
381 } else {
382 pRawDataset =
383 (struct cal_data_per_freq_ar9287 *)
384 pEepData->calPierData2G[i];
Sujitha55f8582010-06-01 15:14:07 +0530385
Felix Fietkau940cd2c2010-12-12 00:51:10 +0100386 ath9k_hw_get_gain_boundaries_pdadcs(ah, chan,
Sujitha55f8582010-06-01 15:14:07 +0530387 pRawDataset,
388 pCalBChans, numPiers,
389 pdGainOverlap_t2,
Sujitha55f8582010-06-01 15:14:07 +0530390 gainBoundaries,
391 pdadcValues,
392 numXpdGain);
Sujithb5aec952009-08-07 09:45:15 +0530393 }
394
Rajkumar Manoharane7fc6332011-03-15 23:11:35 +0530395 ENABLE_REGWRITE_BUFFER(ah);
396
Sujithb5aec952009-08-07 09:45:15 +0530397 if (i == 0) {
Sujitha55f8582010-06-01 15:14:07 +0530398 if (!ath9k_hw_ar9287_get_eeprom(ah,
399 EEP_OL_PWRCTRL)) {
400
401 regval = SM(pdGainOverlap_t2,
402 AR_PHY_TPCRG5_PD_GAIN_OVERLAP)
403 | SM(gainBoundaries[0],
404 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1)
405 | SM(gainBoundaries[1],
406 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2)
407 | SM(gainBoundaries[2],
408 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3)
409 | SM(gainBoundaries[3],
410 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4);
411
412 REG_WRITE(ah,
413 AR_PHY_TPCRG5 + regChainOffset,
414 regval);
Sujithb5aec952009-08-07 09:45:15 +0530415 }
416 }
417
418 if ((int32_t)AR9287_PWR_TABLE_OFFSET_DB !=
Sujitha55f8582010-06-01 15:14:07 +0530419 pEepData->baseEepHeader.pwrTableOffset) {
420 diff = (u16)(pEepData->baseEepHeader.pwrTableOffset -
421 (int32_t)AR9287_PWR_TABLE_OFFSET_DB);
Sujithb5aec952009-08-07 09:45:15 +0530422 diff *= 2;
423
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100424 for (j = 0; j < ((u16)AR5416_NUM_PDADC_VALUES-diff); j++)
Sujithb5aec952009-08-07 09:45:15 +0530425 pdadcValues[j] = pdadcValues[j+diff];
426
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100427 for (j = (u16)(AR5416_NUM_PDADC_VALUES-diff);
428 j < AR5416_NUM_PDADC_VALUES; j++)
Sujithb5aec952009-08-07 09:45:15 +0530429 pdadcValues[j] =
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100430 pdadcValues[AR5416_NUM_PDADC_VALUES-diff];
Sujithb5aec952009-08-07 09:45:15 +0530431 }
432
Sujith16c94ac2010-06-01 15:14:04 +0530433 if (!ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
Sujitha55f8582010-06-01 15:14:07 +0530434 regOffset = AR_PHY_BASE +
435 (672 << 2) + regChainOffset;
436
Sujithb5aec952009-08-07 09:45:15 +0530437 for (j = 0; j < 32; j++) {
Sujitha55f8582010-06-01 15:14:07 +0530438 reg32 = ((pdadcValues[4*j + 0] & 0xFF) << 0)
439 | ((pdadcValues[4*j + 1] & 0xFF) << 8)
440 | ((pdadcValues[4*j + 2] & 0xFF) << 16)
441 | ((pdadcValues[4*j + 3] & 0xFF) << 24);
442
Sujithb5aec952009-08-07 09:45:15 +0530443 REG_WRITE(ah, regOffset, reg32);
Sujithb5aec952009-08-07 09:45:15 +0530444 regOffset += 4;
445 }
446 }
Rajkumar Manoharane7fc6332011-03-15 23:11:35 +0530447 REGWRITE_BUFFER_FLUSH(ah);
Sujithb5aec952009-08-07 09:45:15 +0530448 }
449 }
450
451 *pTxPowerIndexOffset = 0;
452}
453
Sujith16c94ac2010-06-01 15:14:04 +0530454static void ath9k_hw_set_ar9287_power_per_rate_table(struct ath_hw *ah,
455 struct ath9k_channel *chan,
456 int16_t *ratesArray,
457 u16 cfgCtl,
458 u16 AntennaReduction,
459 u16 twiceMaxRegulatoryPower,
460 u16 powerLimit)
Sujithb5aec952009-08-07 09:45:15 +0530461{
Sujitha55f8582010-06-01 15:14:07 +0530462#define CMP_CTL \
463 (((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == \
464 pEepData->ctlIndex[i])
465
466#define CMP_NO_CTL \
467 (((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == \
468 ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL))
469
Sujithb5aec952009-08-07 09:45:15 +0530470#define REDUCE_SCALED_POWER_BY_TWO_CHAIN 6
471#define REDUCE_SCALED_POWER_BY_THREE_CHAIN 10
Sujith16c94ac2010-06-01 15:14:04 +0530472
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700473 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100474 u16 twiceMaxEdgePower = MAX_RATE_POWER;
Sujithb5aec952009-08-07 09:45:15 +0530475 static const u16 tpScaleReductionTable[5] =
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100476 { 0, 3, 6, 9, MAX_RATE_POWER };
Sujithb5aec952009-08-07 09:45:15 +0530477 int i;
Sujith16c94ac2010-06-01 15:14:04 +0530478 int16_t twiceLargestAntenna;
Sujithb5aec952009-08-07 09:45:15 +0530479 struct cal_ctl_data_ar9287 *rep;
480 struct cal_target_power_leg targetPowerOfdm = {0, {0, 0, 0, 0} },
481 targetPowerCck = {0, {0, 0, 0, 0} };
482 struct cal_target_power_leg targetPowerOfdmExt = {0, {0, 0, 0, 0} },
483 targetPowerCckExt = {0, {0, 0, 0, 0} };
Sujith16c94ac2010-06-01 15:14:04 +0530484 struct cal_target_power_ht targetPowerHt20,
Sujithb5aec952009-08-07 09:45:15 +0530485 targetPowerHt40 = {0, {0, 0, 0, 0} };
486 u16 scaledPower = 0, minCtlPower, maxRegAllowedPower;
Joe Perches07b2fa52010-11-20 18:38:53 -0800487 static const u16 ctlModesFor11g[] = {
488 CTL_11B, CTL_11G, CTL_2GHT20,
489 CTL_11B_EXT, CTL_11G_EXT, CTL_2GHT40
490 };
491 u16 numCtlModes = 0;
492 const u16 *pCtlMode = NULL;
493 u16 ctlMode, freq;
Sujithb5aec952009-08-07 09:45:15 +0530494 struct chan_centers centers;
495 int tx_chainmask;
496 u16 twiceMinEdgePower;
497 struct ar9287_eeprom *pEepData = &ah->eeprom.map9287;
498 tx_chainmask = ah->txchainmask;
499
500 ath9k_hw_get_channel_centers(ah, chan, &centers);
501
Sujitha55f8582010-06-01 15:14:07 +0530502 /* Compute TxPower reduction due to Antenna Gain */
Sujithb5aec952009-08-07 09:45:15 +0530503 twiceLargestAntenna = max(pEepData->modalHeader.antennaGainCh[0],
504 pEepData->modalHeader.antennaGainCh[1]);
Sujith16c94ac2010-06-01 15:14:04 +0530505 twiceLargestAntenna = (int16_t)min((AntennaReduction) -
506 twiceLargestAntenna, 0);
Sujithb5aec952009-08-07 09:45:15 +0530507
Sujitha55f8582010-06-01 15:14:07 +0530508 /*
509 * scaledPower is the minimum of the user input power level
510 * and the regulatory allowed power level.
511 */
Sujithb5aec952009-08-07 09:45:15 +0530512 maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
Sujitha55f8582010-06-01 15:14:07 +0530513
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700514 if (regulatory->tp_scale != ATH9K_TP_SCALE_MAX)
Sujithb5aec952009-08-07 09:45:15 +0530515 maxRegAllowedPower -=
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700516 (tpScaleReductionTable[(regulatory->tp_scale)] * 2);
Sujithb5aec952009-08-07 09:45:15 +0530517
518 scaledPower = min(powerLimit, maxRegAllowedPower);
519
Sujitha55f8582010-06-01 15:14:07 +0530520 /*
521 * Reduce scaled Power by number of chains active
522 * to get the per chain tx power level.
523 */
Sujithb5aec952009-08-07 09:45:15 +0530524 switch (ar5416_get_ntxchains(tx_chainmask)) {
525 case 1:
526 break;
527 case 2:
528 scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN;
529 break;
530 case 3:
531 scaledPower -= REDUCE_SCALED_POWER_BY_THREE_CHAIN;
532 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];
Sujith16c94ac2010-06-01 15:14:04 +0530720 int16_t txPowerIndexOffset = 0;
Sujithb5aec952009-08-07 09:45:15 +0530721 u8 ht40PowerIncForPdadc = 2;
722 int i;
723
724 memset(ratesArray, 0, sizeof(ratesArray));
725
726 if ((pEepData->baseEepHeader.version & AR9287_EEP_VER_MINOR_MASK) >=
727 AR9287_EEP_MINOR_VER_2)
728 ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
729
Sujith16c94ac2010-06-01 15:14:04 +0530730 ath9k_hw_set_ar9287_power_per_rate_table(ah, chan,
Sujithb5aec952009-08-07 09:45:15 +0530731 &ratesArray[0], cfgCtl,
732 twiceAntennaReduction,
733 twiceMaxRegulatoryPower,
734 powerLimit);
735
Sujith16c94ac2010-06-01 15:14:04 +0530736 ath9k_hw_set_ar9287_power_cal_table(ah, chan, &txPowerIndexOffset);
Sujithb5aec952009-08-07 09:45:15 +0530737
Felix Fietkaude40f312010-10-20 03:08:53 +0200738 regulatory->max_power_level = 0;
Sujithb5aec952009-08-07 09:45:15 +0530739 for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
740 ratesArray[i] = (int16_t)(txPowerIndexOffset + ratesArray[i]);
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100741 if (ratesArray[i] > MAX_RATE_POWER)
742 ratesArray[i] = MAX_RATE_POWER;
Felix Fietkaude40f312010-10-20 03:08:53 +0200743
744 if (ratesArray[i] > regulatory->max_power_level)
745 regulatory->max_power_level = ratesArray[i];
Sujithb5aec952009-08-07 09:45:15 +0530746 }
747
Felix Fietkaude40f312010-10-20 03:08:53 +0200748 if (test)
749 return;
750
751 if (IS_CHAN_2GHZ(chan))
752 i = rate1l;
753 else
754 i = rate6mb;
755
756 regulatory->max_power_level = ratesArray[i];
757
Felix Fietkau7a370812010-09-22 12:34:52 +0200758 if (AR_SREV_9280_20_OR_LATER(ah)) {
Sujithb5aec952009-08-07 09:45:15 +0530759 for (i = 0; i < Ar5416RateSize; i++)
760 ratesArray[i] -= AR9287_PWR_TABLE_OFFSET_DB * 2;
761 }
762
Rajkumar Manoharane7fc6332011-03-15 23:11:35 +0530763 ENABLE_REGWRITE_BUFFER(ah);
764
Sujitha55f8582010-06-01 15:14:07 +0530765 /* OFDM power per rate */
Sujithb5aec952009-08-07 09:45:15 +0530766 REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
767 ATH9K_POW_SM(ratesArray[rate18mb], 24)
768 | ATH9K_POW_SM(ratesArray[rate12mb], 16)
769 | ATH9K_POW_SM(ratesArray[rate9mb], 8)
770 | ATH9K_POW_SM(ratesArray[rate6mb], 0));
771
772 REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
773 ATH9K_POW_SM(ratesArray[rate54mb], 24)
774 | ATH9K_POW_SM(ratesArray[rate48mb], 16)
775 | ATH9K_POW_SM(ratesArray[rate36mb], 8)
776 | ATH9K_POW_SM(ratesArray[rate24mb], 0));
777
Sujitha55f8582010-06-01 15:14:07 +0530778 /* CCK power per rate */
Sujithb5aec952009-08-07 09:45:15 +0530779 if (IS_CHAN_2GHZ(chan)) {
780 REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
781 ATH9K_POW_SM(ratesArray[rate2s], 24)
782 | ATH9K_POW_SM(ratesArray[rate2l], 16)
783 | ATH9K_POW_SM(ratesArray[rateXr], 8)
784 | ATH9K_POW_SM(ratesArray[rate1l], 0));
785 REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
786 ATH9K_POW_SM(ratesArray[rate11s], 24)
787 | ATH9K_POW_SM(ratesArray[rate11l], 16)
788 | ATH9K_POW_SM(ratesArray[rate5_5s], 8)
789 | ATH9K_POW_SM(ratesArray[rate5_5l], 0));
790 }
791
Sujitha55f8582010-06-01 15:14:07 +0530792 /* HT20 power per rate */
Sujithb5aec952009-08-07 09:45:15 +0530793 REG_WRITE(ah, AR_PHY_POWER_TX_RATE5,
794 ATH9K_POW_SM(ratesArray[rateHt20_3], 24)
795 | ATH9K_POW_SM(ratesArray[rateHt20_2], 16)
796 | ATH9K_POW_SM(ratesArray[rateHt20_1], 8)
797 | ATH9K_POW_SM(ratesArray[rateHt20_0], 0));
798
799 REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
800 ATH9K_POW_SM(ratesArray[rateHt20_7], 24)
801 | ATH9K_POW_SM(ratesArray[rateHt20_6], 16)
802 | ATH9K_POW_SM(ratesArray[rateHt20_5], 8)
803 | ATH9K_POW_SM(ratesArray[rateHt20_4], 0));
804
Sujitha55f8582010-06-01 15:14:07 +0530805 /* HT40 power per rate */
Sujithb5aec952009-08-07 09:45:15 +0530806 if (IS_CHAN_HT40(chan)) {
Sujith16c94ac2010-06-01 15:14:04 +0530807 if (ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
Sujithb5aec952009-08-07 09:45:15 +0530808 REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
809 ATH9K_POW_SM(ratesArray[rateHt40_3], 24)
810 | ATH9K_POW_SM(ratesArray[rateHt40_2], 16)
811 | ATH9K_POW_SM(ratesArray[rateHt40_1], 8)
812 | ATH9K_POW_SM(ratesArray[rateHt40_0], 0));
813
814 REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
815 ATH9K_POW_SM(ratesArray[rateHt40_7], 24)
816 | ATH9K_POW_SM(ratesArray[rateHt40_6], 16)
817 | ATH9K_POW_SM(ratesArray[rateHt40_5], 8)
818 | ATH9K_POW_SM(ratesArray[rateHt40_4], 0));
819 } else {
820 REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
821 ATH9K_POW_SM(ratesArray[rateHt40_3] +
822 ht40PowerIncForPdadc, 24)
823 | ATH9K_POW_SM(ratesArray[rateHt40_2] +
824 ht40PowerIncForPdadc, 16)
825 | ATH9K_POW_SM(ratesArray[rateHt40_1] +
826 ht40PowerIncForPdadc, 8)
827 | ATH9K_POW_SM(ratesArray[rateHt40_0] +
828 ht40PowerIncForPdadc, 0));
829
830 REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
831 ATH9K_POW_SM(ratesArray[rateHt40_7] +
832 ht40PowerIncForPdadc, 24)
833 | ATH9K_POW_SM(ratesArray[rateHt40_6] +
834 ht40PowerIncForPdadc, 16)
835 | ATH9K_POW_SM(ratesArray[rateHt40_5] +
836 ht40PowerIncForPdadc, 8)
837 | ATH9K_POW_SM(ratesArray[rateHt40_4] +
838 ht40PowerIncForPdadc, 0));
839 }
840
Sujitha55f8582010-06-01 15:14:07 +0530841 /* Dup/Ext power per rate */
Sujithb5aec952009-08-07 09:45:15 +0530842 REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
843 ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
844 | ATH9K_POW_SM(ratesArray[rateExtCck], 16)
845 | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
846 | ATH9K_POW_SM(ratesArray[rateDupCck], 0));
847 }
Rajkumar Manoharane7fc6332011-03-15 23:11:35 +0530848 REGWRITE_BUFFER_FLUSH(ah);
Sujithb5aec952009-08-07 09:45:15 +0530849}
850
Sujith16c94ac2010-06-01 15:14:04 +0530851static void ath9k_hw_ar9287_set_addac(struct ath_hw *ah,
Sujithb5aec952009-08-07 09:45:15 +0530852 struct ath9k_channel *chan)
853{
854}
855
Sujith16c94ac2010-06-01 15:14:04 +0530856static void ath9k_hw_ar9287_set_board_values(struct ath_hw *ah,
Sujithb5aec952009-08-07 09:45:15 +0530857 struct ath9k_channel *chan)
858{
859 struct ar9287_eeprom *eep = &ah->eeprom.map9287;
860 struct modal_eep_ar9287_header *pModal = &eep->modalHeader;
861 u16 antWrites[AR9287_ANT_16S];
Sujith79d7f4b2010-06-01 15:14:06 +0530862 u32 regChainOffset, regval;
Sujithb5aec952009-08-07 09:45:15 +0530863 u8 txRxAttenLocal;
864 int i, j, offset_num;
865
866 pModal = &eep->modalHeader;
867
868 antWrites[0] = (u16)((pModal->antCtrlCommon >> 28) & 0xF);
869 antWrites[1] = (u16)((pModal->antCtrlCommon >> 24) & 0xF);
870 antWrites[2] = (u16)((pModal->antCtrlCommon >> 20) & 0xF);
871 antWrites[3] = (u16)((pModal->antCtrlCommon >> 16) & 0xF);
872 antWrites[4] = (u16)((pModal->antCtrlCommon >> 12) & 0xF);
873 antWrites[5] = (u16)((pModal->antCtrlCommon >> 8) & 0xF);
874 antWrites[6] = (u16)((pModal->antCtrlCommon >> 4) & 0xF);
875 antWrites[7] = (u16)(pModal->antCtrlCommon & 0xF);
876
877 offset_num = 8;
878
879 for (i = 0, j = offset_num; i < AR9287_MAX_CHAINS; i++) {
880 antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 28) & 0xf);
881 antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 10) & 0x3);
882 antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 8) & 0x3);
883 antWrites[j++] = 0;
884 antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 6) & 0x3);
885 antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 4) & 0x3);
886 antWrites[j++] = (u16)((pModal->antCtrlChain[i] >> 2) & 0x3);
887 antWrites[j++] = (u16)(pModal->antCtrlChain[i] & 0x3);
888 }
889
Felix Fietkaudf3c8b22010-12-12 00:51:11 +0100890 REG_WRITE(ah, AR_PHY_SWITCH_COM, pModal->antCtrlCommon);
Sujithb5aec952009-08-07 09:45:15 +0530891
892 for (i = 0; i < AR9287_MAX_CHAINS; i++) {
893 regChainOffset = i * 0x1000;
894
895 REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
896 pModal->antCtrlChain[i]);
897
898 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
899 (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset)
900 & ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
901 AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
902 SM(pModal->iqCalICh[i],
903 AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
904 SM(pModal->iqCalQCh[i],
905 AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
906
907 txRxAttenLocal = pModal->txRxAttenCh[i];
908
909 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
910 AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN,
911 pModal->bswMargin[i]);
912 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
913 AR_PHY_GAIN_2GHZ_XATTEN1_DB,
914 pModal->bswAtten[i]);
915 REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
916 AR9280_PHY_RXGAIN_TXRX_ATTEN,
917 txRxAttenLocal);
918 REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
919 AR9280_PHY_RXGAIN_TXRX_MARGIN,
920 pModal->rxTxMarginCh[i]);
921 }
922
923
924 if (IS_CHAN_HT40(chan))
925 REG_RMW_FIELD(ah, AR_PHY_SETTLING,
926 AR_PHY_SETTLING_SWITCH, pModal->swSettleHt40);
927 else
928 REG_RMW_FIELD(ah, AR_PHY_SETTLING,
929 AR_PHY_SETTLING_SWITCH, pModal->switchSettling);
930
931 REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
932 AR_PHY_DESIRED_SZ_ADC, pModal->adcDesiredSize);
933
934 REG_WRITE(ah, AR_PHY_RF_CTL4,
935 SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF)
936 | SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAB_OFF)
937 | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAA_ON)
938 | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAB_ON));
939
940 REG_RMW_FIELD(ah, AR_PHY_RF_CTL3,
941 AR_PHY_TX_END_TO_A2_RX_ON, pModal->txEndToRxOn);
942
943 REG_RMW_FIELD(ah, AR_PHY_CCA,
944 AR9280_PHY_CCA_THRESH62, pModal->thresh62);
945 REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0,
946 AR_PHY_EXT_CCA0_THRESH62, pModal->thresh62);
947
Sujith79d7f4b2010-06-01 15:14:06 +0530948 regval = REG_READ(ah, AR9287_AN_RF2G3_CH0);
949 regval &= ~(AR9287_AN_RF2G3_DB1 |
950 AR9287_AN_RF2G3_DB2 |
951 AR9287_AN_RF2G3_OB_CCK |
952 AR9287_AN_RF2G3_OB_PSK |
953 AR9287_AN_RF2G3_OB_QAM |
954 AR9287_AN_RF2G3_OB_PAL_OFF);
955 regval |= (SM(pModal->db1, AR9287_AN_RF2G3_DB1) |
956 SM(pModal->db2, AR9287_AN_RF2G3_DB2) |
957 SM(pModal->ob_cck, AR9287_AN_RF2G3_OB_CCK) |
958 SM(pModal->ob_psk, AR9287_AN_RF2G3_OB_PSK) |
959 SM(pModal->ob_qam, AR9287_AN_RF2G3_OB_QAM) |
960 SM(pModal->ob_pal_off, AR9287_AN_RF2G3_OB_PAL_OFF));
Sujithb5aec952009-08-07 09:45:15 +0530961
Sujith79d7f4b2010-06-01 15:14:06 +0530962 ath9k_hw_analog_shift_regwrite(ah, AR9287_AN_RF2G3_CH0, regval);
963
964 regval = REG_READ(ah, AR9287_AN_RF2G3_CH1);
965 regval &= ~(AR9287_AN_RF2G3_DB1 |
966 AR9287_AN_RF2G3_DB2 |
967 AR9287_AN_RF2G3_OB_CCK |
968 AR9287_AN_RF2G3_OB_PSK |
969 AR9287_AN_RF2G3_OB_QAM |
970 AR9287_AN_RF2G3_OB_PAL_OFF);
971 regval |= (SM(pModal->db1, AR9287_AN_RF2G3_DB1) |
972 SM(pModal->db2, AR9287_AN_RF2G3_DB2) |
973 SM(pModal->ob_cck, AR9287_AN_RF2G3_OB_CCK) |
974 SM(pModal->ob_psk, AR9287_AN_RF2G3_OB_PSK) |
975 SM(pModal->ob_qam, AR9287_AN_RF2G3_OB_QAM) |
976 SM(pModal->ob_pal_off, AR9287_AN_RF2G3_OB_PAL_OFF));
977
978 ath9k_hw_analog_shift_regwrite(ah, AR9287_AN_RF2G3_CH1, regval);
Sujithb5aec952009-08-07 09:45:15 +0530979
980 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
981 AR_PHY_TX_END_DATA_START, pModal->txFrameToDataStart);
982 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
983 AR_PHY_TX_END_PA_ON, pModal->txFrameToPaOn);
984
985 ath9k_hw_analog_shift_rmw(ah, AR9287_AN_TOP2,
986 AR9287_AN_TOP2_XPABIAS_LVL,
987 AR9287_AN_TOP2_XPABIAS_LVL_S,
988 pModal->xpaBiasLvl);
989}
990
Sujith16c94ac2010-06-01 15:14:04 +0530991static u16 ath9k_hw_ar9287_get_spur_channel(struct ath_hw *ah,
Sujithb5aec952009-08-07 09:45:15 +0530992 u16 i, bool is2GHz)
993{
994#define EEP_MAP9287_SPURCHAN \
995 (ah->eeprom.map9287.modalHeader.spurChans[i].spurChan)
Sujith16c94ac2010-06-01 15:14:04 +0530996
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700997 struct ath_common *common = ath9k_hw_common(ah);
Sujithb5aec952009-08-07 09:45:15 +0530998 u16 spur_val = AR_NO_SPUR;
999
Joe Perches226afe62010-12-02 19:12:37 -08001000 ath_dbg(common, ATH_DBG_ANI,
1001 "Getting spur idx:%d is2Ghz:%d val:%x\n",
1002 i, is2GHz, ah->config.spurchans[i][is2GHz]);
Sujithb5aec952009-08-07 09:45:15 +05301003
1004 switch (ah->config.spurmode) {
1005 case SPUR_DISABLE:
1006 break;
1007 case SPUR_ENABLE_IOCTL:
1008 spur_val = ah->config.spurchans[i][is2GHz];
Joe Perches226afe62010-12-02 19:12:37 -08001009 ath_dbg(common, ATH_DBG_ANI,
1010 "Getting spur val from new loc. %d\n", spur_val);
Sujithb5aec952009-08-07 09:45:15 +05301011 break;
1012 case SPUR_ENABLE_EEPROM:
1013 spur_val = EEP_MAP9287_SPURCHAN;
1014 break;
1015 }
1016
1017 return spur_val;
1018
1019#undef EEP_MAP9287_SPURCHAN
1020}
1021
Luis R. Rodriguez0b8f6f2b12010-04-15 17:39:12 -04001022const struct eeprom_ops eep_ar9287_ops = {
Sujith16c94ac2010-06-01 15:14:04 +05301023 .check_eeprom = ath9k_hw_ar9287_check_eeprom,
1024 .get_eeprom = ath9k_hw_ar9287_get_eeprom,
1025 .fill_eeprom = ath9k_hw_ar9287_fill_eeprom,
1026 .get_eeprom_ver = ath9k_hw_ar9287_get_eeprom_ver,
1027 .get_eeprom_rev = ath9k_hw_ar9287_get_eeprom_rev,
Sujith16c94ac2010-06-01 15:14:04 +05301028 .set_board_values = ath9k_hw_ar9287_set_board_values,
1029 .set_addac = ath9k_hw_ar9287_set_addac,
1030 .set_txpower = ath9k_hw_ar9287_set_txpower,
1031 .get_spur_channel = ath9k_hw_ar9287_get_spur_channel
Sujithb5aec952009-08-07 09:45:15 +05301032};