blob: d6f6b192f4507008df5b2feee95183bb6413b07f [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,
Sujithb5aec952009-08-07 09:45:15 +0530310 struct ath9k_channel *chan,
311 int16_t *pTxPowerIndexOffset)
312{
313 struct cal_data_per_freq_ar9287 *pRawDataset;
314 struct cal_data_op_loop_ar9287 *pRawDatasetOpenLoop;
Sujith16c94ac2010-06-01 15:14:04 +0530315 u8 *pCalBChans = NULL;
Sujithb5aec952009-08-07 09:45:15 +0530316 u16 pdGainOverlap_t2;
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100317 u8 pdadcValues[AR5416_NUM_PDADC_VALUES];
318 u16 gainBoundaries[AR5416_PD_GAINS_IN_MASK];
Sujithb5aec952009-08-07 09:45:15 +0530319 u16 numPiers = 0, i, j;
Sujithb5aec952009-08-07 09:45:15 +0530320 u16 numXpdGain, xpdMask;
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100321 u16 xpdGainValues[AR5416_NUM_PD_GAINS] = {0, 0, 0, 0};
Sujitha55f8582010-06-01 15:14:07 +0530322 u32 reg32, regOffset, regChainOffset, regval;
Sujith Manoharan0ff2b5c2011-04-20 11:00:34 +0530323 int16_t diff = 0;
Sujithb5aec952009-08-07 09:45:15 +0530324 struct ar9287_eeprom *pEepData = &ah->eeprom.map9287;
Sujith16c94ac2010-06-01 15:14:04 +0530325
Sujithb5aec952009-08-07 09:45:15 +0530326 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++) {
Pavel Roskin78fa99a2011-07-15 19:06:33 -0400438 reg32 = get_unaligned_le32(&pdadcValues[4 * j]);
Sujitha55f8582010-06-01 15:14:07 +0530439
Sujithb5aec952009-08-07 09:45:15 +0530440 REG_WRITE(ah, regOffset, reg32);
Sujithb5aec952009-08-07 09:45:15 +0530441 regOffset += 4;
442 }
443 }
Rajkumar Manoharane7fc6332011-03-15 23:11:35 +0530444 REGWRITE_BUFFER_FLUSH(ah);
Sujithb5aec952009-08-07 09:45:15 +0530445 }
446 }
447
448 *pTxPowerIndexOffset = 0;
449}
450
Sujith16c94ac2010-06-01 15:14:04 +0530451static void ath9k_hw_set_ar9287_power_per_rate_table(struct ath_hw *ah,
452 struct ath9k_channel *chan,
453 int16_t *ratesArray,
454 u16 cfgCtl,
455 u16 AntennaReduction,
456 u16 twiceMaxRegulatoryPower,
457 u16 powerLimit)
Sujithb5aec952009-08-07 09:45:15 +0530458{
Sujitha55f8582010-06-01 15:14:07 +0530459#define CMP_CTL \
460 (((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == \
461 pEepData->ctlIndex[i])
462
463#define CMP_NO_CTL \
464 (((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == \
465 ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL))
466
Sujithb5aec952009-08-07 09:45:15 +0530467#define REDUCE_SCALED_POWER_BY_TWO_CHAIN 6
468#define REDUCE_SCALED_POWER_BY_THREE_CHAIN 10
Sujith16c94ac2010-06-01 15:14:04 +0530469
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700470 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100471 u16 twiceMaxEdgePower = MAX_RATE_POWER;
Sujithb5aec952009-08-07 09:45:15 +0530472 static const u16 tpScaleReductionTable[5] =
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100473 { 0, 3, 6, 9, MAX_RATE_POWER };
Sujithb5aec952009-08-07 09:45:15 +0530474 int i;
Sujith16c94ac2010-06-01 15:14:04 +0530475 int16_t twiceLargestAntenna;
Sujithb5aec952009-08-07 09:45:15 +0530476 struct cal_ctl_data_ar9287 *rep;
477 struct cal_target_power_leg targetPowerOfdm = {0, {0, 0, 0, 0} },
478 targetPowerCck = {0, {0, 0, 0, 0} };
479 struct cal_target_power_leg targetPowerOfdmExt = {0, {0, 0, 0, 0} },
480 targetPowerCckExt = {0, {0, 0, 0, 0} };
Sujith16c94ac2010-06-01 15:14:04 +0530481 struct cal_target_power_ht targetPowerHt20,
Sujithb5aec952009-08-07 09:45:15 +0530482 targetPowerHt40 = {0, {0, 0, 0, 0} };
483 u16 scaledPower = 0, minCtlPower, maxRegAllowedPower;
Joe Perches07b2fa52010-11-20 18:38:53 -0800484 static const u16 ctlModesFor11g[] = {
485 CTL_11B, CTL_11G, CTL_2GHT20,
486 CTL_11B_EXT, CTL_11G_EXT, CTL_2GHT40
487 };
488 u16 numCtlModes = 0;
489 const u16 *pCtlMode = NULL;
490 u16 ctlMode, freq;
Sujithb5aec952009-08-07 09:45:15 +0530491 struct chan_centers centers;
492 int tx_chainmask;
493 u16 twiceMinEdgePower;
494 struct ar9287_eeprom *pEepData = &ah->eeprom.map9287;
495 tx_chainmask = ah->txchainmask;
496
497 ath9k_hw_get_channel_centers(ah, chan, &centers);
498
Sujitha55f8582010-06-01 15:14:07 +0530499 /* Compute TxPower reduction due to Antenna Gain */
Sujithb5aec952009-08-07 09:45:15 +0530500 twiceLargestAntenna = max(pEepData->modalHeader.antennaGainCh[0],
501 pEepData->modalHeader.antennaGainCh[1]);
Sujith16c94ac2010-06-01 15:14:04 +0530502 twiceLargestAntenna = (int16_t)min((AntennaReduction) -
503 twiceLargestAntenna, 0);
Sujithb5aec952009-08-07 09:45:15 +0530504
Sujitha55f8582010-06-01 15:14:07 +0530505 /*
506 * scaledPower is the minimum of the user input power level
507 * and the regulatory allowed power level.
508 */
Sujithb5aec952009-08-07 09:45:15 +0530509 maxRegAllowedPower = twiceMaxRegulatoryPower + twiceLargestAntenna;
Sujitha55f8582010-06-01 15:14:07 +0530510
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700511 if (regulatory->tp_scale != ATH9K_TP_SCALE_MAX)
Sujithb5aec952009-08-07 09:45:15 +0530512 maxRegAllowedPower -=
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700513 (tpScaleReductionTable[(regulatory->tp_scale)] * 2);
Sujithb5aec952009-08-07 09:45:15 +0530514
515 scaledPower = min(powerLimit, maxRegAllowedPower);
516
Sujitha55f8582010-06-01 15:14:07 +0530517 /*
518 * Reduce scaled Power by number of chains active
519 * to get the per chain tx power level.
520 */
Sujithb5aec952009-08-07 09:45:15 +0530521 switch (ar5416_get_ntxchains(tx_chainmask)) {
522 case 1:
523 break;
524 case 2:
Daniel Halperin21fdc872011-05-31 11:59:30 -0700525 if (scaledPower > REDUCE_SCALED_POWER_BY_TWO_CHAIN)
526 scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN;
527 else
528 scaledPower = 0;
Sujithb5aec952009-08-07 09:45:15 +0530529 break;
530 case 3:
Daniel Halperin21fdc872011-05-31 11:59:30 -0700531 if (scaledPower > REDUCE_SCALED_POWER_BY_THREE_CHAIN)
532 scaledPower -= REDUCE_SCALED_POWER_BY_THREE_CHAIN;
533 else
534 scaledPower = 0;
Sujithb5aec952009-08-07 09:45:15 +0530535 break;
536 }
537 scaledPower = max((u16)0, scaledPower);
538
Sujitha55f8582010-06-01 15:14:07 +0530539 /*
540 * Get TX power from EEPROM.
541 */
Sujithb5aec952009-08-07 09:45:15 +0530542 if (IS_CHAN_2GHZ(chan)) {
Sujitha55f8582010-06-01 15:14:07 +0530543 /* CTL_11B, CTL_11G, CTL_2GHT20 */
Sujithb5aec952009-08-07 09:45:15 +0530544 numCtlModes =
545 ARRAY_SIZE(ctlModesFor11g) - SUB_NUM_CTL_MODES_AT_2G_40;
Sujith16c94ac2010-06-01 15:14:04 +0530546
Sujithb5aec952009-08-07 09:45:15 +0530547 pCtlMode = ctlModesFor11g;
548
549 ath9k_hw_get_legacy_target_powers(ah, chan,
550 pEepData->calTargetPowerCck,
551 AR9287_NUM_2G_CCK_TARGET_POWERS,
552 &targetPowerCck, 4, false);
553 ath9k_hw_get_legacy_target_powers(ah, chan,
554 pEepData->calTargetPower2G,
555 AR9287_NUM_2G_20_TARGET_POWERS,
556 &targetPowerOfdm, 4, false);
557 ath9k_hw_get_target_powers(ah, chan,
558 pEepData->calTargetPower2GHT20,
559 AR9287_NUM_2G_20_TARGET_POWERS,
560 &targetPowerHt20, 8, false);
561
562 if (IS_CHAN_HT40(chan)) {
Sujitha55f8582010-06-01 15:14:07 +0530563 /* All 2G CTLs */
Sujithb5aec952009-08-07 09:45:15 +0530564 numCtlModes = ARRAY_SIZE(ctlModesFor11g);
565 ath9k_hw_get_target_powers(ah, chan,
566 pEepData->calTargetPower2GHT40,
567 AR9287_NUM_2G_40_TARGET_POWERS,
568 &targetPowerHt40, 8, true);
569 ath9k_hw_get_legacy_target_powers(ah, chan,
570 pEepData->calTargetPowerCck,
571 AR9287_NUM_2G_CCK_TARGET_POWERS,
572 &targetPowerCckExt, 4, true);
573 ath9k_hw_get_legacy_target_powers(ah, chan,
574 pEepData->calTargetPower2G,
575 AR9287_NUM_2G_20_TARGET_POWERS,
576 &targetPowerOfdmExt, 4, true);
577 }
578 }
579
580 for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
Sujitha55f8582010-06-01 15:14:07 +0530581 bool isHt40CtlMode =
582 (pCtlMode[ctlMode] == CTL_2GHT40) ? true : false;
583
Sujithb5aec952009-08-07 09:45:15 +0530584 if (isHt40CtlMode)
585 freq = centers.synth_center;
586 else if (pCtlMode[ctlMode] & EXT_ADDITIVE)
587 freq = centers.ext_center;
588 else
589 freq = centers.ctl_center;
590
Sujitha55f8582010-06-01 15:14:07 +0530591 /* Walk through the CTL indices stored in EEPROM */
Sujithb5aec952009-08-07 09:45:15 +0530592 for (i = 0; (i < AR9287_NUM_CTLS) && pEepData->ctlIndex[i]; i++) {
Sujitha55f8582010-06-01 15:14:07 +0530593 struct cal_ctl_edges *pRdEdgesPower;
Sujithb5aec952009-08-07 09:45:15 +0530594
Sujitha55f8582010-06-01 15:14:07 +0530595 /*
596 * Compare test group from regulatory channel list
597 * with test mode from pCtlMode list
598 */
599 if (CMP_CTL || CMP_NO_CTL) {
Sujithb5aec952009-08-07 09:45:15 +0530600 rep = &(pEepData->ctlData[i]);
Sujitha55f8582010-06-01 15:14:07 +0530601 pRdEdgesPower =
602 rep->ctlEdges[ar5416_get_ntxchains(tx_chainmask) - 1];
Sujithb5aec952009-08-07 09:45:15 +0530603
Sujitha55f8582010-06-01 15:14:07 +0530604 twiceMinEdgePower = ath9k_hw_get_max_edge_power(freq,
605 pRdEdgesPower,
606 IS_CHAN_2GHZ(chan),
607 AR5416_NUM_BAND_EDGES);
608
609 if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {
610 twiceMaxEdgePower = min(twiceMaxEdgePower,
611 twiceMinEdgePower);
612 } else {
Sujithb5aec952009-08-07 09:45:15 +0530613 twiceMaxEdgePower = twiceMinEdgePower;
614 break;
615 }
616 }
617 }
618
619 minCtlPower = (u8)min(twiceMaxEdgePower, scaledPower);
620
Sujitha55f8582010-06-01 15:14:07 +0530621 /* Apply ctl mode to correct target power set */
Sujithb5aec952009-08-07 09:45:15 +0530622 switch (pCtlMode[ctlMode]) {
623 case CTL_11B:
Sujitha55f8582010-06-01 15:14:07 +0530624 for (i = 0; i < ARRAY_SIZE(targetPowerCck.tPow2x); i++) {
625 targetPowerCck.tPow2x[i] =
626 (u8)min((u16)targetPowerCck.tPow2x[i],
627 minCtlPower);
Sujithb5aec952009-08-07 09:45:15 +0530628 }
629 break;
630 case CTL_11A:
631 case CTL_11G:
Sujitha55f8582010-06-01 15:14:07 +0530632 for (i = 0; i < ARRAY_SIZE(targetPowerOfdm.tPow2x); i++) {
633 targetPowerOfdm.tPow2x[i] =
634 (u8)min((u16)targetPowerOfdm.tPow2x[i],
635 minCtlPower);
Sujithb5aec952009-08-07 09:45:15 +0530636 }
637 break;
638 case CTL_5GHT20:
639 case CTL_2GHT20:
Sujitha55f8582010-06-01 15:14:07 +0530640 for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++) {
641 targetPowerHt20.tPow2x[i] =
642 (u8)min((u16)targetPowerHt20.tPow2x[i],
643 minCtlPower);
Sujithb5aec952009-08-07 09:45:15 +0530644 }
645 break;
646 case CTL_11B_EXT:
Sujitha55f8582010-06-01 15:14:07 +0530647 targetPowerCckExt.tPow2x[0] =
648 (u8)min((u16)targetPowerCckExt.tPow2x[0],
649 minCtlPower);
Sujithb5aec952009-08-07 09:45:15 +0530650 break;
651 case CTL_11A_EXT:
652 case CTL_11G_EXT:
Sujitha55f8582010-06-01 15:14:07 +0530653 targetPowerOfdmExt.tPow2x[0] =
654 (u8)min((u16)targetPowerOfdmExt.tPow2x[0],
655 minCtlPower);
Sujithb5aec952009-08-07 09:45:15 +0530656 break;
657 case CTL_5GHT40:
658 case CTL_2GHT40:
Sujitha55f8582010-06-01 15:14:07 +0530659 for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++) {
660 targetPowerHt40.tPow2x[i] =
661 (u8)min((u16)targetPowerHt40.tPow2x[i],
662 minCtlPower);
Sujithb5aec952009-08-07 09:45:15 +0530663 }
664 break;
665 default:
666 break;
667 }
668 }
669
Sujitha55f8582010-06-01 15:14:07 +0530670 /* Now set the rates array */
671
Sujithb5aec952009-08-07 09:45:15 +0530672 ratesArray[rate6mb] =
673 ratesArray[rate9mb] =
674 ratesArray[rate12mb] =
675 ratesArray[rate18mb] =
Sujitha55f8582010-06-01 15:14:07 +0530676 ratesArray[rate24mb] = targetPowerOfdm.tPow2x[0];
Sujithb5aec952009-08-07 09:45:15 +0530677
678 ratesArray[rate36mb] = targetPowerOfdm.tPow2x[1];
679 ratesArray[rate48mb] = targetPowerOfdm.tPow2x[2];
680 ratesArray[rate54mb] = targetPowerOfdm.tPow2x[3];
681 ratesArray[rateXr] = targetPowerOfdm.tPow2x[0];
682
683 for (i = 0; i < ARRAY_SIZE(targetPowerHt20.tPow2x); i++)
684 ratesArray[rateHt20_0 + i] = targetPowerHt20.tPow2x[i];
685
686 if (IS_CHAN_2GHZ(chan)) {
687 ratesArray[rate1l] = targetPowerCck.tPow2x[0];
Sujitha55f8582010-06-01 15:14:07 +0530688 ratesArray[rate2s] =
689 ratesArray[rate2l] = targetPowerCck.tPow2x[1];
690 ratesArray[rate5_5s] =
691 ratesArray[rate5_5l] = targetPowerCck.tPow2x[2];
692 ratesArray[rate11s] =
693 ratesArray[rate11l] = targetPowerCck.tPow2x[3];
Sujithb5aec952009-08-07 09:45:15 +0530694 }
695 if (IS_CHAN_HT40(chan)) {
696 for (i = 0; i < ARRAY_SIZE(targetPowerHt40.tPow2x); i++)
697 ratesArray[rateHt40_0 + i] = targetPowerHt40.tPow2x[i];
698
699 ratesArray[rateDupOfdm] = targetPowerHt40.tPow2x[0];
700 ratesArray[rateDupCck] = targetPowerHt40.tPow2x[0];
701 ratesArray[rateExtOfdm] = targetPowerOfdmExt.tPow2x[0];
Sujitha55f8582010-06-01 15:14:07 +0530702
Sujithb5aec952009-08-07 09:45:15 +0530703 if (IS_CHAN_2GHZ(chan))
704 ratesArray[rateExtCck] = targetPowerCckExt.tPow2x[0];
705 }
706
Sujitha55f8582010-06-01 15:14:07 +0530707#undef CMP_CTL
708#undef CMP_NO_CTL
Sujithb5aec952009-08-07 09:45:15 +0530709#undef REDUCE_SCALED_POWER_BY_TWO_CHAIN
710#undef REDUCE_SCALED_POWER_BY_THREE_CHAIN
711}
712
Sujith16c94ac2010-06-01 15:14:04 +0530713static void ath9k_hw_ar9287_set_txpower(struct ath_hw *ah,
Sujithb5aec952009-08-07 09:45:15 +0530714 struct ath9k_channel *chan, u16 cfgCtl,
715 u8 twiceAntennaReduction,
716 u8 twiceMaxRegulatoryPower,
Felix Fietkaude40f312010-10-20 03:08:53 +0200717 u8 powerLimit, bool test)
Sujithb5aec952009-08-07 09:45:15 +0530718{
Luis R. Rodriguez608b88c2009-08-17 18:07:23 -0700719 struct ath_regulatory *regulatory = ath9k_hw_regulatory(ah);
Sujithb5aec952009-08-07 09:45:15 +0530720 struct ar9287_eeprom *pEepData = &ah->eeprom.map9287;
721 struct modal_eep_ar9287_header *pModal = &pEepData->modalHeader;
722 int16_t ratesArray[Ar5416RateSize];
Sujith16c94ac2010-06-01 15:14:04 +0530723 int16_t txPowerIndexOffset = 0;
Sujithb5aec952009-08-07 09:45:15 +0530724 u8 ht40PowerIncForPdadc = 2;
725 int i;
726
727 memset(ratesArray, 0, sizeof(ratesArray));
728
729 if ((pEepData->baseEepHeader.version & AR9287_EEP_VER_MINOR_MASK) >=
730 AR9287_EEP_MINOR_VER_2)
731 ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
732
Sujith16c94ac2010-06-01 15:14:04 +0530733 ath9k_hw_set_ar9287_power_per_rate_table(ah, chan,
Sujithb5aec952009-08-07 09:45:15 +0530734 &ratesArray[0], cfgCtl,
735 twiceAntennaReduction,
736 twiceMaxRegulatoryPower,
737 powerLimit);
738
Sujith16c94ac2010-06-01 15:14:04 +0530739 ath9k_hw_set_ar9287_power_cal_table(ah, chan, &txPowerIndexOffset);
Sujithb5aec952009-08-07 09:45:15 +0530740
Felix Fietkaude40f312010-10-20 03:08:53 +0200741 regulatory->max_power_level = 0;
Sujithb5aec952009-08-07 09:45:15 +0530742 for (i = 0; i < ARRAY_SIZE(ratesArray); i++) {
743 ratesArray[i] = (int16_t)(txPowerIndexOffset + ratesArray[i]);
Felix Fietkau4ddfcd72010-12-12 00:51:08 +0100744 if (ratesArray[i] > MAX_RATE_POWER)
745 ratesArray[i] = MAX_RATE_POWER;
Felix Fietkaude40f312010-10-20 03:08:53 +0200746
747 if (ratesArray[i] > regulatory->max_power_level)
748 regulatory->max_power_level = ratesArray[i];
Sujithb5aec952009-08-07 09:45:15 +0530749 }
750
Felix Fietkaude40f312010-10-20 03:08:53 +0200751 if (test)
752 return;
753
754 if (IS_CHAN_2GHZ(chan))
755 i = rate1l;
756 else
757 i = rate6mb;
758
759 regulatory->max_power_level = ratesArray[i];
760
Felix Fietkau7a370812010-09-22 12:34:52 +0200761 if (AR_SREV_9280_20_OR_LATER(ah)) {
Sujithb5aec952009-08-07 09:45:15 +0530762 for (i = 0; i < Ar5416RateSize; i++)
763 ratesArray[i] -= AR9287_PWR_TABLE_OFFSET_DB * 2;
764 }
765
Rajkumar Manoharane7fc6332011-03-15 23:11:35 +0530766 ENABLE_REGWRITE_BUFFER(ah);
767
Sujitha55f8582010-06-01 15:14:07 +0530768 /* OFDM power per rate */
Sujithb5aec952009-08-07 09:45:15 +0530769 REG_WRITE(ah, AR_PHY_POWER_TX_RATE1,
770 ATH9K_POW_SM(ratesArray[rate18mb], 24)
771 | ATH9K_POW_SM(ratesArray[rate12mb], 16)
772 | ATH9K_POW_SM(ratesArray[rate9mb], 8)
773 | ATH9K_POW_SM(ratesArray[rate6mb], 0));
774
775 REG_WRITE(ah, AR_PHY_POWER_TX_RATE2,
776 ATH9K_POW_SM(ratesArray[rate54mb], 24)
777 | ATH9K_POW_SM(ratesArray[rate48mb], 16)
778 | ATH9K_POW_SM(ratesArray[rate36mb], 8)
779 | ATH9K_POW_SM(ratesArray[rate24mb], 0));
780
Sujitha55f8582010-06-01 15:14:07 +0530781 /* CCK power per rate */
Sujithb5aec952009-08-07 09:45:15 +0530782 if (IS_CHAN_2GHZ(chan)) {
783 REG_WRITE(ah, AR_PHY_POWER_TX_RATE3,
784 ATH9K_POW_SM(ratesArray[rate2s], 24)
785 | ATH9K_POW_SM(ratesArray[rate2l], 16)
786 | ATH9K_POW_SM(ratesArray[rateXr], 8)
787 | ATH9K_POW_SM(ratesArray[rate1l], 0));
788 REG_WRITE(ah, AR_PHY_POWER_TX_RATE4,
789 ATH9K_POW_SM(ratesArray[rate11s], 24)
790 | ATH9K_POW_SM(ratesArray[rate11l], 16)
791 | ATH9K_POW_SM(ratesArray[rate5_5s], 8)
792 | ATH9K_POW_SM(ratesArray[rate5_5l], 0));
793 }
794
Sujitha55f8582010-06-01 15:14:07 +0530795 /* HT20 power per rate */
Sujithb5aec952009-08-07 09:45:15 +0530796 REG_WRITE(ah, AR_PHY_POWER_TX_RATE5,
797 ATH9K_POW_SM(ratesArray[rateHt20_3], 24)
798 | ATH9K_POW_SM(ratesArray[rateHt20_2], 16)
799 | ATH9K_POW_SM(ratesArray[rateHt20_1], 8)
800 | ATH9K_POW_SM(ratesArray[rateHt20_0], 0));
801
802 REG_WRITE(ah, AR_PHY_POWER_TX_RATE6,
803 ATH9K_POW_SM(ratesArray[rateHt20_7], 24)
804 | ATH9K_POW_SM(ratesArray[rateHt20_6], 16)
805 | ATH9K_POW_SM(ratesArray[rateHt20_5], 8)
806 | ATH9K_POW_SM(ratesArray[rateHt20_4], 0));
807
Sujitha55f8582010-06-01 15:14:07 +0530808 /* HT40 power per rate */
Sujithb5aec952009-08-07 09:45:15 +0530809 if (IS_CHAN_HT40(chan)) {
Sujith16c94ac2010-06-01 15:14:04 +0530810 if (ath9k_hw_ar9287_get_eeprom(ah, EEP_OL_PWRCTRL)) {
Sujithb5aec952009-08-07 09:45:15 +0530811 REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
812 ATH9K_POW_SM(ratesArray[rateHt40_3], 24)
813 | ATH9K_POW_SM(ratesArray[rateHt40_2], 16)
814 | ATH9K_POW_SM(ratesArray[rateHt40_1], 8)
815 | ATH9K_POW_SM(ratesArray[rateHt40_0], 0));
816
817 REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
818 ATH9K_POW_SM(ratesArray[rateHt40_7], 24)
819 | ATH9K_POW_SM(ratesArray[rateHt40_6], 16)
820 | ATH9K_POW_SM(ratesArray[rateHt40_5], 8)
821 | ATH9K_POW_SM(ratesArray[rateHt40_4], 0));
822 } else {
823 REG_WRITE(ah, AR_PHY_POWER_TX_RATE7,
824 ATH9K_POW_SM(ratesArray[rateHt40_3] +
825 ht40PowerIncForPdadc, 24)
826 | ATH9K_POW_SM(ratesArray[rateHt40_2] +
827 ht40PowerIncForPdadc, 16)
828 | ATH9K_POW_SM(ratesArray[rateHt40_1] +
829 ht40PowerIncForPdadc, 8)
830 | ATH9K_POW_SM(ratesArray[rateHt40_0] +
831 ht40PowerIncForPdadc, 0));
832
833 REG_WRITE(ah, AR_PHY_POWER_TX_RATE8,
834 ATH9K_POW_SM(ratesArray[rateHt40_7] +
835 ht40PowerIncForPdadc, 24)
836 | ATH9K_POW_SM(ratesArray[rateHt40_6] +
837 ht40PowerIncForPdadc, 16)
838 | ATH9K_POW_SM(ratesArray[rateHt40_5] +
839 ht40PowerIncForPdadc, 8)
840 | ATH9K_POW_SM(ratesArray[rateHt40_4] +
841 ht40PowerIncForPdadc, 0));
842 }
843
Sujitha55f8582010-06-01 15:14:07 +0530844 /* Dup/Ext power per rate */
Sujithb5aec952009-08-07 09:45:15 +0530845 REG_WRITE(ah, AR_PHY_POWER_TX_RATE9,
846 ATH9K_POW_SM(ratesArray[rateExtOfdm], 24)
847 | ATH9K_POW_SM(ratesArray[rateExtCck], 16)
848 | ATH9K_POW_SM(ratesArray[rateDupOfdm], 8)
849 | ATH9K_POW_SM(ratesArray[rateDupCck], 0));
850 }
Rajkumar Manoharane7fc6332011-03-15 23:11:35 +0530851 REGWRITE_BUFFER_FLUSH(ah);
Sujithb5aec952009-08-07 09:45:15 +0530852}
853
Sujith16c94ac2010-06-01 15:14:04 +0530854static void ath9k_hw_ar9287_set_addac(struct ath_hw *ah,
Sujithb5aec952009-08-07 09:45:15 +0530855 struct ath9k_channel *chan)
856{
857}
858
Sujith16c94ac2010-06-01 15:14:04 +0530859static void ath9k_hw_ar9287_set_board_values(struct ath_hw *ah,
Sujithb5aec952009-08-07 09:45:15 +0530860 struct ath9k_channel *chan)
861{
862 struct ar9287_eeprom *eep = &ah->eeprom.map9287;
863 struct modal_eep_ar9287_header *pModal = &eep->modalHeader;
Sujith79d7f4b2010-06-01 15:14:06 +0530864 u32 regChainOffset, regval;
Sujithb5aec952009-08-07 09:45:15 +0530865 u8 txRxAttenLocal;
Rajkumar Manoharan2d05a0c2011-04-11 20:22:28 +0530866 int i;
Sujithb5aec952009-08-07 09:45:15 +0530867
868 pModal = &eep->modalHeader;
869
Felix Fietkaudf3c8b22010-12-12 00:51:11 +0100870 REG_WRITE(ah, AR_PHY_SWITCH_COM, pModal->antCtrlCommon);
Sujithb5aec952009-08-07 09:45:15 +0530871
872 for (i = 0; i < AR9287_MAX_CHAINS; i++) {
873 regChainOffset = i * 0x1000;
874
875 REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
876 pModal->antCtrlChain[i]);
877
878 REG_WRITE(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset,
879 (REG_READ(ah, AR_PHY_TIMING_CTRL4(0) + regChainOffset)
880 & ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
881 AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
882 SM(pModal->iqCalICh[i],
883 AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
884 SM(pModal->iqCalQCh[i],
885 AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
886
887 txRxAttenLocal = pModal->txRxAttenCh[i];
888
889 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
890 AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN,
891 pModal->bswMargin[i]);
892 REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
893 AR_PHY_GAIN_2GHZ_XATTEN1_DB,
894 pModal->bswAtten[i]);
895 REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
896 AR9280_PHY_RXGAIN_TXRX_ATTEN,
897 txRxAttenLocal);
898 REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
899 AR9280_PHY_RXGAIN_TXRX_MARGIN,
900 pModal->rxTxMarginCh[i]);
901 }
902
903
904 if (IS_CHAN_HT40(chan))
905 REG_RMW_FIELD(ah, AR_PHY_SETTLING,
906 AR_PHY_SETTLING_SWITCH, pModal->swSettleHt40);
907 else
908 REG_RMW_FIELD(ah, AR_PHY_SETTLING,
909 AR_PHY_SETTLING_SWITCH, pModal->switchSettling);
910
911 REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
912 AR_PHY_DESIRED_SZ_ADC, pModal->adcDesiredSize);
913
914 REG_WRITE(ah, AR_PHY_RF_CTL4,
915 SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF)
916 | SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAB_OFF)
917 | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAA_ON)
918 | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAB_ON));
919
920 REG_RMW_FIELD(ah, AR_PHY_RF_CTL3,
921 AR_PHY_TX_END_TO_A2_RX_ON, pModal->txEndToRxOn);
922
923 REG_RMW_FIELD(ah, AR_PHY_CCA,
924 AR9280_PHY_CCA_THRESH62, pModal->thresh62);
925 REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0,
926 AR_PHY_EXT_CCA0_THRESH62, pModal->thresh62);
927
Sujith79d7f4b2010-06-01 15:14:06 +0530928 regval = REG_READ(ah, AR9287_AN_RF2G3_CH0);
929 regval &= ~(AR9287_AN_RF2G3_DB1 |
930 AR9287_AN_RF2G3_DB2 |
931 AR9287_AN_RF2G3_OB_CCK |
932 AR9287_AN_RF2G3_OB_PSK |
933 AR9287_AN_RF2G3_OB_QAM |
934 AR9287_AN_RF2G3_OB_PAL_OFF);
935 regval |= (SM(pModal->db1, AR9287_AN_RF2G3_DB1) |
936 SM(pModal->db2, AR9287_AN_RF2G3_DB2) |
937 SM(pModal->ob_cck, AR9287_AN_RF2G3_OB_CCK) |
938 SM(pModal->ob_psk, AR9287_AN_RF2G3_OB_PSK) |
939 SM(pModal->ob_qam, AR9287_AN_RF2G3_OB_QAM) |
940 SM(pModal->ob_pal_off, AR9287_AN_RF2G3_OB_PAL_OFF));
Sujithb5aec952009-08-07 09:45:15 +0530941
Sujith79d7f4b2010-06-01 15:14:06 +0530942 ath9k_hw_analog_shift_regwrite(ah, AR9287_AN_RF2G3_CH0, regval);
943
944 regval = REG_READ(ah, AR9287_AN_RF2G3_CH1);
945 regval &= ~(AR9287_AN_RF2G3_DB1 |
946 AR9287_AN_RF2G3_DB2 |
947 AR9287_AN_RF2G3_OB_CCK |
948 AR9287_AN_RF2G3_OB_PSK |
949 AR9287_AN_RF2G3_OB_QAM |
950 AR9287_AN_RF2G3_OB_PAL_OFF);
951 regval |= (SM(pModal->db1, AR9287_AN_RF2G3_DB1) |
952 SM(pModal->db2, AR9287_AN_RF2G3_DB2) |
953 SM(pModal->ob_cck, AR9287_AN_RF2G3_OB_CCK) |
954 SM(pModal->ob_psk, AR9287_AN_RF2G3_OB_PSK) |
955 SM(pModal->ob_qam, AR9287_AN_RF2G3_OB_QAM) |
956 SM(pModal->ob_pal_off, AR9287_AN_RF2G3_OB_PAL_OFF));
957
958 ath9k_hw_analog_shift_regwrite(ah, AR9287_AN_RF2G3_CH1, regval);
Sujithb5aec952009-08-07 09:45:15 +0530959
960 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
961 AR_PHY_TX_END_DATA_START, pModal->txFrameToDataStart);
962 REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
963 AR_PHY_TX_END_PA_ON, pModal->txFrameToPaOn);
964
965 ath9k_hw_analog_shift_rmw(ah, AR9287_AN_TOP2,
966 AR9287_AN_TOP2_XPABIAS_LVL,
967 AR9287_AN_TOP2_XPABIAS_LVL_S,
968 pModal->xpaBiasLvl);
969}
970
Sujith16c94ac2010-06-01 15:14:04 +0530971static u16 ath9k_hw_ar9287_get_spur_channel(struct ath_hw *ah,
Sujithb5aec952009-08-07 09:45:15 +0530972 u16 i, bool is2GHz)
973{
974#define EEP_MAP9287_SPURCHAN \
975 (ah->eeprom.map9287.modalHeader.spurChans[i].spurChan)
Sujith16c94ac2010-06-01 15:14:04 +0530976
Luis R. Rodriguezc46917b2009-09-13 02:42:02 -0700977 struct ath_common *common = ath9k_hw_common(ah);
Sujithb5aec952009-08-07 09:45:15 +0530978 u16 spur_val = AR_NO_SPUR;
979
Joe Perches226afe62010-12-02 19:12:37 -0800980 ath_dbg(common, ATH_DBG_ANI,
981 "Getting spur idx:%d is2Ghz:%d val:%x\n",
982 i, is2GHz, ah->config.spurchans[i][is2GHz]);
Sujithb5aec952009-08-07 09:45:15 +0530983
984 switch (ah->config.spurmode) {
985 case SPUR_DISABLE:
986 break;
987 case SPUR_ENABLE_IOCTL:
988 spur_val = ah->config.spurchans[i][is2GHz];
Joe Perches226afe62010-12-02 19:12:37 -0800989 ath_dbg(common, ATH_DBG_ANI,
990 "Getting spur val from new loc. %d\n", spur_val);
Sujithb5aec952009-08-07 09:45:15 +0530991 break;
992 case SPUR_ENABLE_EEPROM:
993 spur_val = EEP_MAP9287_SPURCHAN;
994 break;
995 }
996
997 return spur_val;
998
999#undef EEP_MAP9287_SPURCHAN
1000}
1001
Luis R. Rodriguez0b8f6f2b12010-04-15 17:39:12 -04001002const struct eeprom_ops eep_ar9287_ops = {
Sujith16c94ac2010-06-01 15:14:04 +05301003 .check_eeprom = ath9k_hw_ar9287_check_eeprom,
1004 .get_eeprom = ath9k_hw_ar9287_get_eeprom,
1005 .fill_eeprom = ath9k_hw_ar9287_fill_eeprom,
1006 .get_eeprom_ver = ath9k_hw_ar9287_get_eeprom_ver,
1007 .get_eeprom_rev = ath9k_hw_ar9287_get_eeprom_rev,
Sujith16c94ac2010-06-01 15:14:04 +05301008 .set_board_values = ath9k_hw_ar9287_set_board_values,
1009 .set_addac = ath9k_hw_ar9287_set_addac,
1010 .set_txpower = ath9k_hw_ar9287_set_txpower,
1011 .get_spur_channel = ath9k_hw_ar9287_get_spur_channel
Sujithb5aec952009-08-07 09:45:15 +05301012};