2 * Copyright (c) 2008-2009 Atheros Communications Inc.
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.
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.
18 #include "ar9002_phy.h"
20 static int ath9k_hw_4k_get_eeprom_ver(struct ath_hw
*ah
)
22 return ((ah
->eeprom
.map4k
.baseEepHeader
.version
>> 12) & 0xF);
25 static int ath9k_hw_4k_get_eeprom_rev(struct ath_hw
*ah
)
27 return ((ah
->eeprom
.map4k
.baseEepHeader
.version
) & 0xFFF);
30 #define SIZE_EEPROM_4K (sizeof(struct ar5416_eeprom_4k) / sizeof(u16))
32 static bool __ath9k_hw_4k_fill_eeprom(struct ath_hw
*ah
)
34 struct ath_common
*common
= ath9k_hw_common(ah
);
35 u16
*eep_data
= (u16
*)&ah
->eeprom
.map4k
;
36 int addr
, eep_start_loc
= 64;
38 for (addr
= 0; addr
< SIZE_EEPROM_4K
; addr
++) {
39 if (!ath9k_hw_nvram_read(common
, addr
+ eep_start_loc
, eep_data
)) {
40 ath_dbg(common
, ATH_DBG_EEPROM
,
41 "Unable to read eeprom region\n");
50 static bool __ath9k_hw_usb_4k_fill_eeprom(struct ath_hw
*ah
)
52 u16
*eep_data
= (u16
*)&ah
->eeprom
.map4k
;
54 ath9k_hw_usb_gen_fill_eeprom(ah
, eep_data
, 64, SIZE_EEPROM_4K
);
59 static bool ath9k_hw_4k_fill_eeprom(struct ath_hw
*ah
)
61 struct ath_common
*common
= ath9k_hw_common(ah
);
63 if (!ath9k_hw_use_flash(ah
)) {
64 ath_dbg(common
, ATH_DBG_EEPROM
,
65 "Reading from EEPROM, not flash\n");
68 if (common
->bus_ops
->ath_bus_type
== ATH_USB
)
69 return __ath9k_hw_usb_4k_fill_eeprom(ah
);
71 return __ath9k_hw_4k_fill_eeprom(ah
);
76 static int ath9k_hw_4k_check_eeprom(struct ath_hw
*ah
)
78 #define EEPROM_4K_SIZE (sizeof(struct ar5416_eeprom_4k) / sizeof(u16))
79 struct ath_common
*common
= ath9k_hw_common(ah
);
80 struct ar5416_eeprom_4k
*eep
=
81 (struct ar5416_eeprom_4k
*) &ah
->eeprom
.map4k
;
82 u16
*eepdata
, temp
, magic
, magic2
;
84 bool need_swap
= false;
88 if (!ath9k_hw_use_flash(ah
)) {
89 if (!ath9k_hw_nvram_read(common
, AR5416_EEPROM_MAGIC_OFFSET
,
91 ath_err(common
, "Reading Magic # failed\n");
95 ath_dbg(common
, ATH_DBG_EEPROM
,
96 "Read Magic = 0x%04X\n", magic
);
98 if (magic
!= AR5416_EEPROM_MAGIC
) {
99 magic2
= swab16(magic
);
101 if (magic2
== AR5416_EEPROM_MAGIC
) {
103 eepdata
= (u16
*) (&ah
->eeprom
);
105 for (addr
= 0; addr
< EEPROM_4K_SIZE
; addr
++) {
106 temp
= swab16(*eepdata
);
112 "Invalid EEPROM Magic. Endianness mismatch.\n");
118 ath_dbg(common
, ATH_DBG_EEPROM
, "need_swap = %s.\n",
119 need_swap
? "True" : "False");
122 el
= swab16(ah
->eeprom
.map4k
.baseEepHeader
.length
);
124 el
= ah
->eeprom
.map4k
.baseEepHeader
.length
;
126 if (el
> sizeof(struct ar5416_eeprom_4k
))
127 el
= sizeof(struct ar5416_eeprom_4k
) / sizeof(u16
);
129 el
= el
/ sizeof(u16
);
131 eepdata
= (u16
*)(&ah
->eeprom
);
133 for (i
= 0; i
< el
; i
++)
140 ath_dbg(common
, ATH_DBG_EEPROM
,
141 "EEPROM Endianness is not native.. Changing\n");
143 word
= swab16(eep
->baseEepHeader
.length
);
144 eep
->baseEepHeader
.length
= word
;
146 word
= swab16(eep
->baseEepHeader
.checksum
);
147 eep
->baseEepHeader
.checksum
= word
;
149 word
= swab16(eep
->baseEepHeader
.version
);
150 eep
->baseEepHeader
.version
= word
;
152 word
= swab16(eep
->baseEepHeader
.regDmn
[0]);
153 eep
->baseEepHeader
.regDmn
[0] = word
;
155 word
= swab16(eep
->baseEepHeader
.regDmn
[1]);
156 eep
->baseEepHeader
.regDmn
[1] = word
;
158 word
= swab16(eep
->baseEepHeader
.rfSilent
);
159 eep
->baseEepHeader
.rfSilent
= word
;
161 word
= swab16(eep
->baseEepHeader
.blueToothOptions
);
162 eep
->baseEepHeader
.blueToothOptions
= word
;
164 word
= swab16(eep
->baseEepHeader
.deviceCap
);
165 eep
->baseEepHeader
.deviceCap
= word
;
167 integer
= swab32(eep
->modalHeader
.antCtrlCommon
);
168 eep
->modalHeader
.antCtrlCommon
= integer
;
170 for (i
= 0; i
< AR5416_EEP4K_MAX_CHAINS
; i
++) {
171 integer
= swab32(eep
->modalHeader
.antCtrlChain
[i
]);
172 eep
->modalHeader
.antCtrlChain
[i
] = integer
;
175 for (i
= 0; i
< AR_EEPROM_MODAL_SPURS
; i
++) {
176 word
= swab16(eep
->modalHeader
.spurChans
[i
].spurChan
);
177 eep
->modalHeader
.spurChans
[i
].spurChan
= word
;
181 if (sum
!= 0xffff || ah
->eep_ops
->get_eeprom_ver(ah
) != AR5416_EEP_VER
||
182 ah
->eep_ops
->get_eeprom_rev(ah
) < AR5416_EEP_NO_BACK_VER
) {
183 ath_err(common
, "Bad EEPROM checksum 0x%x or revision 0x%04x\n",
184 sum
, ah
->eep_ops
->get_eeprom_ver(ah
));
189 #undef EEPROM_4K_SIZE
192 static u32
ath9k_hw_4k_get_eeprom(struct ath_hw
*ah
,
193 enum eeprom_param param
)
195 struct ar5416_eeprom_4k
*eep
= &ah
->eeprom
.map4k
;
196 struct modal_eep_4k_header
*pModal
= &eep
->modalHeader
;
197 struct base_eep_header_4k
*pBase
= &eep
->baseEepHeader
;
200 ver_minor
= pBase
->version
& AR5416_EEP_VER_MINOR_MASK
;
204 return pModal
->noiseFloorThreshCh
[0];
206 return pBase
->macAddr
[0] << 8 | pBase
->macAddr
[1];
208 return pBase
->macAddr
[2] << 8 | pBase
->macAddr
[3];
210 return pBase
->macAddr
[4] << 8 | pBase
->macAddr
[5];
212 return pBase
->regDmn
[0];
214 return pBase
->regDmn
[1];
216 return pBase
->deviceCap
;
218 return pBase
->opCapFlags
;
220 return pBase
->rfSilent
;
224 return pModal
->db1_1
;
228 return pBase
->txMask
;
230 return pBase
->rxMask
;
233 case EEP_PWR_TABLE_OFFSET
:
234 return AR5416_PWR_TABLE_OFFSET_DB
;
236 return pModal
->version
;
237 case EEP_ANT_DIV_CTL1
:
238 return pModal
->antdiv_ctl1
;
239 case EEP_TXGAIN_TYPE
:
240 if (ver_minor
>= AR5416_EEP_MINOR_VER_19
)
241 return pBase
->txGainType
;
243 return AR5416_EEP_TXGAIN_ORIGINAL
;
249 static void ath9k_hw_set_4k_power_cal_table(struct ath_hw
*ah
,
250 struct ath9k_channel
*chan
,
251 int16_t *pTxPowerIndexOffset
)
253 struct ath_common
*common
= ath9k_hw_common(ah
);
254 struct ar5416_eeprom_4k
*pEepData
= &ah
->eeprom
.map4k
;
255 struct cal_data_per_freq_4k
*pRawDataset
;
256 u8
*pCalBChans
= NULL
;
257 u16 pdGainOverlap_t2
;
258 static u8 pdadcValues
[AR5416_NUM_PDADC_VALUES
];
259 u16 gainBoundaries
[AR5416_PD_GAINS_IN_MASK
];
261 u16 numXpdGain
, xpdMask
;
262 u16 xpdGainValues
[AR5416_EEP4K_NUM_PD_GAINS
] = { 0, 0 };
263 u32 reg32
, regOffset
, regChainOffset
;
265 xpdMask
= pEepData
->modalHeader
.xpdGain
;
267 if ((pEepData
->baseEepHeader
.version
& AR5416_EEP_VER_MINOR_MASK
) >=
268 AR5416_EEP_MINOR_VER_2
) {
270 pEepData
->modalHeader
.pdGainOverlap
;
272 pdGainOverlap_t2
= (u16
)(MS(REG_READ(ah
, AR_PHY_TPCRG5
),
273 AR_PHY_TPCRG5_PD_GAIN_OVERLAP
));
276 pCalBChans
= pEepData
->calFreqPier2G
;
277 numPiers
= AR5416_EEP4K_NUM_2G_CAL_PIERS
;
281 for (i
= 1; i
<= AR5416_PD_GAINS_IN_MASK
; i
++) {
282 if ((xpdMask
>> (AR5416_PD_GAINS_IN_MASK
- i
)) & 1) {
283 if (numXpdGain
>= AR5416_EEP4K_NUM_PD_GAINS
)
285 xpdGainValues
[numXpdGain
] =
286 (u16
)(AR5416_PD_GAINS_IN_MASK
- i
);
291 REG_RMW_FIELD(ah
, AR_PHY_TPCRG1
, AR_PHY_TPCRG1_NUM_PD_GAIN
,
292 (numXpdGain
- 1) & 0x3);
293 REG_RMW_FIELD(ah
, AR_PHY_TPCRG1
, AR_PHY_TPCRG1_PD_GAIN_1
,
295 REG_RMW_FIELD(ah
, AR_PHY_TPCRG1
, AR_PHY_TPCRG1_PD_GAIN_2
,
297 REG_RMW_FIELD(ah
, AR_PHY_TPCRG1
, AR_PHY_TPCRG1_PD_GAIN_3
, 0);
299 for (i
= 0; i
< AR5416_EEP4K_MAX_CHAINS
; i
++) {
300 if (AR_SREV_5416_20_OR_LATER(ah
) &&
301 (ah
->rxchainmask
== 5 || ah
->txchainmask
== 5) &&
303 regChainOffset
= (i
== 1) ? 0x2000 : 0x1000;
305 regChainOffset
= i
* 0x1000;
307 if (pEepData
->baseEepHeader
.txMask
& (1 << i
)) {
308 pRawDataset
= pEepData
->calPierData2G
[i
];
310 ath9k_hw_get_gain_boundaries_pdadcs(ah
, chan
,
311 pRawDataset
, pCalBChans
,
312 numPiers
, pdGainOverlap_t2
,
314 pdadcValues
, numXpdGain
);
316 ENABLE_REGWRITE_BUFFER(ah
);
318 if ((i
== 0) || AR_SREV_5416_20_OR_LATER(ah
)) {
319 REG_WRITE(ah
, AR_PHY_TPCRG5
+ regChainOffset
,
321 AR_PHY_TPCRG5_PD_GAIN_OVERLAP
)
322 | SM(gainBoundaries
[0],
323 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1
)
324 | SM(gainBoundaries
[1],
325 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2
)
326 | SM(gainBoundaries
[2],
327 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3
)
328 | SM(gainBoundaries
[3],
329 AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4
));
332 regOffset
= AR_PHY_BASE
+ (672 << 2) + regChainOffset
;
333 for (j
= 0; j
< 32; j
++) {
334 reg32
= ((pdadcValues
[4 * j
+ 0] & 0xFF) << 0) |
335 ((pdadcValues
[4 * j
+ 1] & 0xFF) << 8) |
336 ((pdadcValues
[4 * j
+ 2] & 0xFF) << 16)|
337 ((pdadcValues
[4 * j
+ 3] & 0xFF) << 24);
338 REG_WRITE(ah
, regOffset
, reg32
);
340 ath_dbg(common
, ATH_DBG_EEPROM
,
341 "PDADC (%d,%4x): %4.4x %8.8x\n",
342 i
, regChainOffset
, regOffset
,
344 ath_dbg(common
, ATH_DBG_EEPROM
,
346 "PDADC %3d Value %3d | "
347 "PDADC %3d Value %3d | "
348 "PDADC %3d Value %3d | "
349 "PDADC %3d Value %3d |\n",
350 i
, 4 * j
, pdadcValues
[4 * j
],
351 4 * j
+ 1, pdadcValues
[4 * j
+ 1],
352 4 * j
+ 2, pdadcValues
[4 * j
+ 2],
353 4 * j
+ 3, pdadcValues
[4 * j
+ 3]);
358 REGWRITE_BUFFER_FLUSH(ah
);
362 *pTxPowerIndexOffset
= 0;
365 static void ath9k_hw_set_4k_power_per_rate_table(struct ath_hw
*ah
,
366 struct ath9k_channel
*chan
,
369 u16 AntennaReduction
,
370 u16 twiceMaxRegulatoryPower
,
373 #define CMP_TEST_GRP \
374 (((cfgCtl & ~CTL_MODE_M)| (pCtlMode[ctlMode] & CTL_MODE_M)) == \
375 pEepData->ctlIndex[i]) \
376 || (((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == \
377 ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL))
379 struct ath_regulatory
*regulatory
= ath9k_hw_regulatory(ah
);
381 int16_t twiceLargestAntenna
;
382 u16 twiceMinEdgePower
;
383 u16 twiceMaxEdgePower
= MAX_RATE_POWER
;
384 u16 scaledPower
= 0, minCtlPower
, maxRegAllowedPower
;
388 struct chan_centers centers
;
389 struct cal_ctl_data_4k
*rep
;
390 struct ar5416_eeprom_4k
*pEepData
= &ah
->eeprom
.map4k
;
391 static const u16 tpScaleReductionTable
[5] =
392 { 0, 3, 6, 9, MAX_RATE_POWER
};
393 struct cal_target_power_leg targetPowerOfdm
, targetPowerCck
= {
396 struct cal_target_power_leg targetPowerOfdmExt
= {
397 0, { 0, 0, 0, 0} }, targetPowerCckExt
= {
400 struct cal_target_power_ht targetPowerHt20
, targetPowerHt40
= {
403 static const u16 ctlModesFor11g
[] = {
404 CTL_11B
, CTL_11G
, CTL_2GHT20
,
405 CTL_11B_EXT
, CTL_11G_EXT
, CTL_2GHT40
408 ath9k_hw_get_channel_centers(ah
, chan
, ¢ers
);
410 twiceLargestAntenna
= pEepData
->modalHeader
.antennaGainCh
[0];
411 twiceLargestAntenna
= (int16_t)min(AntennaReduction
-
412 twiceLargestAntenna
, 0);
414 maxRegAllowedPower
= twiceMaxRegulatoryPower
+ twiceLargestAntenna
;
415 if (regulatory
->tp_scale
!= ATH9K_TP_SCALE_MAX
) {
416 maxRegAllowedPower
-=
417 (tpScaleReductionTable
[(regulatory
->tp_scale
)] * 2);
420 scaledPower
= min(powerLimit
, maxRegAllowedPower
);
421 scaledPower
= max((u16
)0, scaledPower
);
423 numCtlModes
= ARRAY_SIZE(ctlModesFor11g
) - SUB_NUM_CTL_MODES_AT_2G_40
;
424 pCtlMode
= ctlModesFor11g
;
426 ath9k_hw_get_legacy_target_powers(ah
, chan
,
427 pEepData
->calTargetPowerCck
,
428 AR5416_NUM_2G_CCK_TARGET_POWERS
,
429 &targetPowerCck
, 4, false);
430 ath9k_hw_get_legacy_target_powers(ah
, chan
,
431 pEepData
->calTargetPower2G
,
432 AR5416_NUM_2G_20_TARGET_POWERS
,
433 &targetPowerOfdm
, 4, false);
434 ath9k_hw_get_target_powers(ah
, chan
,
435 pEepData
->calTargetPower2GHT20
,
436 AR5416_NUM_2G_20_TARGET_POWERS
,
437 &targetPowerHt20
, 8, false);
439 if (IS_CHAN_HT40(chan
)) {
440 numCtlModes
= ARRAY_SIZE(ctlModesFor11g
);
441 ath9k_hw_get_target_powers(ah
, chan
,
442 pEepData
->calTargetPower2GHT40
,
443 AR5416_NUM_2G_40_TARGET_POWERS
,
444 &targetPowerHt40
, 8, true);
445 ath9k_hw_get_legacy_target_powers(ah
, chan
,
446 pEepData
->calTargetPowerCck
,
447 AR5416_NUM_2G_CCK_TARGET_POWERS
,
448 &targetPowerCckExt
, 4, true);
449 ath9k_hw_get_legacy_target_powers(ah
, chan
,
450 pEepData
->calTargetPower2G
,
451 AR5416_NUM_2G_20_TARGET_POWERS
,
452 &targetPowerOfdmExt
, 4, true);
455 for (ctlMode
= 0; ctlMode
< numCtlModes
; ctlMode
++) {
456 bool isHt40CtlMode
= (pCtlMode
[ctlMode
] == CTL_5GHT40
) ||
457 (pCtlMode
[ctlMode
] == CTL_2GHT40
);
460 freq
= centers
.synth_center
;
461 else if (pCtlMode
[ctlMode
] & EXT_ADDITIVE
)
462 freq
= centers
.ext_center
;
464 freq
= centers
.ctl_center
;
466 if (ah
->eep_ops
->get_eeprom_ver(ah
) == 14 &&
467 ah
->eep_ops
->get_eeprom_rev(ah
) <= 2)
468 twiceMaxEdgePower
= MAX_RATE_POWER
;
470 for (i
= 0; (i
< AR5416_EEP4K_NUM_CTLS
) &&
471 pEepData
->ctlIndex
[i
]; i
++) {
474 rep
= &(pEepData
->ctlData
[i
]);
476 twiceMinEdgePower
= ath9k_hw_get_max_edge_power(
479 ar5416_get_ntxchains(ah
->txchainmask
) - 1],
481 AR5416_EEP4K_NUM_BAND_EDGES
);
483 if ((cfgCtl
& ~CTL_MODE_M
) == SD_NO_CTL
) {
485 min(twiceMaxEdgePower
,
488 twiceMaxEdgePower
= twiceMinEdgePower
;
494 minCtlPower
= (u8
)min(twiceMaxEdgePower
, scaledPower
);
496 switch (pCtlMode
[ctlMode
]) {
498 for (i
= 0; i
< ARRAY_SIZE(targetPowerCck
.tPow2x
); i
++) {
499 targetPowerCck
.tPow2x
[i
] =
500 min((u16
)targetPowerCck
.tPow2x
[i
],
505 for (i
= 0; i
< ARRAY_SIZE(targetPowerOfdm
.tPow2x
); i
++) {
506 targetPowerOfdm
.tPow2x
[i
] =
507 min((u16
)targetPowerOfdm
.tPow2x
[i
],
512 for (i
= 0; i
< ARRAY_SIZE(targetPowerHt20
.tPow2x
); i
++) {
513 targetPowerHt20
.tPow2x
[i
] =
514 min((u16
)targetPowerHt20
.tPow2x
[i
],
519 targetPowerCckExt
.tPow2x
[0] =
520 min((u16
)targetPowerCckExt
.tPow2x
[0],
524 targetPowerOfdmExt
.tPow2x
[0] =
525 min((u16
)targetPowerOfdmExt
.tPow2x
[0],
529 for (i
= 0; i
< ARRAY_SIZE(targetPowerHt40
.tPow2x
); i
++) {
530 targetPowerHt40
.tPow2x
[i
] =
531 min((u16
)targetPowerHt40
.tPow2x
[i
],
540 ratesArray
[rate6mb
] =
541 ratesArray
[rate9mb
] =
542 ratesArray
[rate12mb
] =
543 ratesArray
[rate18mb
] =
544 ratesArray
[rate24mb
] =
545 targetPowerOfdm
.tPow2x
[0];
547 ratesArray
[rate36mb
] = targetPowerOfdm
.tPow2x
[1];
548 ratesArray
[rate48mb
] = targetPowerOfdm
.tPow2x
[2];
549 ratesArray
[rate54mb
] = targetPowerOfdm
.tPow2x
[3];
550 ratesArray
[rateXr
] = targetPowerOfdm
.tPow2x
[0];
552 for (i
= 0; i
< ARRAY_SIZE(targetPowerHt20
.tPow2x
); i
++)
553 ratesArray
[rateHt20_0
+ i
] = targetPowerHt20
.tPow2x
[i
];
555 ratesArray
[rate1l
] = targetPowerCck
.tPow2x
[0];
556 ratesArray
[rate2s
] = ratesArray
[rate2l
] = targetPowerCck
.tPow2x
[1];
557 ratesArray
[rate5_5s
] = ratesArray
[rate5_5l
] = targetPowerCck
.tPow2x
[2];
558 ratesArray
[rate11s
] = ratesArray
[rate11l
] = targetPowerCck
.tPow2x
[3];
560 if (IS_CHAN_HT40(chan
)) {
561 for (i
= 0; i
< ARRAY_SIZE(targetPowerHt40
.tPow2x
); i
++) {
562 ratesArray
[rateHt40_0
+ i
] =
563 targetPowerHt40
.tPow2x
[i
];
565 ratesArray
[rateDupOfdm
] = targetPowerHt40
.tPow2x
[0];
566 ratesArray
[rateDupCck
] = targetPowerHt40
.tPow2x
[0];
567 ratesArray
[rateExtOfdm
] = targetPowerOfdmExt
.tPow2x
[0];
568 ratesArray
[rateExtCck
] = targetPowerCckExt
.tPow2x
[0];
574 static void ath9k_hw_4k_set_txpower(struct ath_hw
*ah
,
575 struct ath9k_channel
*chan
,
577 u8 twiceAntennaReduction
,
578 u8 twiceMaxRegulatoryPower
,
579 u8 powerLimit
, bool test
)
581 struct ath_regulatory
*regulatory
= ath9k_hw_regulatory(ah
);
582 struct ar5416_eeprom_4k
*pEepData
= &ah
->eeprom
.map4k
;
583 struct modal_eep_4k_header
*pModal
= &pEepData
->modalHeader
;
584 int16_t ratesArray
[Ar5416RateSize
];
585 int16_t txPowerIndexOffset
= 0;
586 u8 ht40PowerIncForPdadc
= 2;
589 memset(ratesArray
, 0, sizeof(ratesArray
));
591 if ((pEepData
->baseEepHeader
.version
& AR5416_EEP_VER_MINOR_MASK
) >=
592 AR5416_EEP_MINOR_VER_2
) {
593 ht40PowerIncForPdadc
= pModal
->ht40PowerIncForPdadc
;
596 ath9k_hw_set_4k_power_per_rate_table(ah
, chan
,
597 &ratesArray
[0], cfgCtl
,
598 twiceAntennaReduction
,
599 twiceMaxRegulatoryPower
,
602 ath9k_hw_set_4k_power_cal_table(ah
, chan
, &txPowerIndexOffset
);
604 regulatory
->max_power_level
= 0;
605 for (i
= 0; i
< ARRAY_SIZE(ratesArray
); i
++) {
606 ratesArray
[i
] = (int16_t)(txPowerIndexOffset
+ ratesArray
[i
]);
607 if (ratesArray
[i
] > MAX_RATE_POWER
)
608 ratesArray
[i
] = MAX_RATE_POWER
;
610 if (ratesArray
[i
] > regulatory
->max_power_level
)
611 regulatory
->max_power_level
= ratesArray
[i
];
617 /* Update regulatory */
619 if (IS_CHAN_HT40(chan
))
621 else if (IS_CHAN_HT20(chan
))
624 regulatory
->max_power_level
= ratesArray
[i
];
626 if (AR_SREV_9280_20_OR_LATER(ah
)) {
627 for (i
= 0; i
< Ar5416RateSize
; i
++)
628 ratesArray
[i
] -= AR5416_PWR_TABLE_OFFSET_DB
* 2;
631 ENABLE_REGWRITE_BUFFER(ah
);
633 /* OFDM power per rate */
634 REG_WRITE(ah
, AR_PHY_POWER_TX_RATE1
,
635 ATH9K_POW_SM(ratesArray
[rate18mb
], 24)
636 | ATH9K_POW_SM(ratesArray
[rate12mb
], 16)
637 | ATH9K_POW_SM(ratesArray
[rate9mb
], 8)
638 | ATH9K_POW_SM(ratesArray
[rate6mb
], 0));
639 REG_WRITE(ah
, AR_PHY_POWER_TX_RATE2
,
640 ATH9K_POW_SM(ratesArray
[rate54mb
], 24)
641 | ATH9K_POW_SM(ratesArray
[rate48mb
], 16)
642 | ATH9K_POW_SM(ratesArray
[rate36mb
], 8)
643 | ATH9K_POW_SM(ratesArray
[rate24mb
], 0));
645 /* CCK power per rate */
646 REG_WRITE(ah
, AR_PHY_POWER_TX_RATE3
,
647 ATH9K_POW_SM(ratesArray
[rate2s
], 24)
648 | ATH9K_POW_SM(ratesArray
[rate2l
], 16)
649 | ATH9K_POW_SM(ratesArray
[rateXr
], 8)
650 | ATH9K_POW_SM(ratesArray
[rate1l
], 0));
651 REG_WRITE(ah
, AR_PHY_POWER_TX_RATE4
,
652 ATH9K_POW_SM(ratesArray
[rate11s
], 24)
653 | ATH9K_POW_SM(ratesArray
[rate11l
], 16)
654 | ATH9K_POW_SM(ratesArray
[rate5_5s
], 8)
655 | ATH9K_POW_SM(ratesArray
[rate5_5l
], 0));
657 /* HT20 power per rate */
658 REG_WRITE(ah
, AR_PHY_POWER_TX_RATE5
,
659 ATH9K_POW_SM(ratesArray
[rateHt20_3
], 24)
660 | ATH9K_POW_SM(ratesArray
[rateHt20_2
], 16)
661 | ATH9K_POW_SM(ratesArray
[rateHt20_1
], 8)
662 | ATH9K_POW_SM(ratesArray
[rateHt20_0
], 0));
663 REG_WRITE(ah
, AR_PHY_POWER_TX_RATE6
,
664 ATH9K_POW_SM(ratesArray
[rateHt20_7
], 24)
665 | ATH9K_POW_SM(ratesArray
[rateHt20_6
], 16)
666 | ATH9K_POW_SM(ratesArray
[rateHt20_5
], 8)
667 | ATH9K_POW_SM(ratesArray
[rateHt20_4
], 0));
669 /* HT40 power per rate */
670 if (IS_CHAN_HT40(chan
)) {
671 REG_WRITE(ah
, AR_PHY_POWER_TX_RATE7
,
672 ATH9K_POW_SM(ratesArray
[rateHt40_3
] +
673 ht40PowerIncForPdadc
, 24)
674 | ATH9K_POW_SM(ratesArray
[rateHt40_2
] +
675 ht40PowerIncForPdadc
, 16)
676 | ATH9K_POW_SM(ratesArray
[rateHt40_1
] +
677 ht40PowerIncForPdadc
, 8)
678 | ATH9K_POW_SM(ratesArray
[rateHt40_0
] +
679 ht40PowerIncForPdadc
, 0));
680 REG_WRITE(ah
, AR_PHY_POWER_TX_RATE8
,
681 ATH9K_POW_SM(ratesArray
[rateHt40_7
] +
682 ht40PowerIncForPdadc
, 24)
683 | ATH9K_POW_SM(ratesArray
[rateHt40_6
] +
684 ht40PowerIncForPdadc
, 16)
685 | ATH9K_POW_SM(ratesArray
[rateHt40_5
] +
686 ht40PowerIncForPdadc
, 8)
687 | ATH9K_POW_SM(ratesArray
[rateHt40_4
] +
688 ht40PowerIncForPdadc
, 0));
689 REG_WRITE(ah
, AR_PHY_POWER_TX_RATE9
,
690 ATH9K_POW_SM(ratesArray
[rateExtOfdm
], 24)
691 | ATH9K_POW_SM(ratesArray
[rateExtCck
], 16)
692 | ATH9K_POW_SM(ratesArray
[rateDupOfdm
], 8)
693 | ATH9K_POW_SM(ratesArray
[rateDupCck
], 0));
696 REGWRITE_BUFFER_FLUSH(ah
);
699 static void ath9k_hw_4k_set_addac(struct ath_hw
*ah
,
700 struct ath9k_channel
*chan
)
702 struct modal_eep_4k_header
*pModal
;
703 struct ar5416_eeprom_4k
*eep
= &ah
->eeprom
.map4k
;
706 if (ah
->hw_version
.macVersion
!= AR_SREV_VERSION_9160
)
709 if (ah
->eep_ops
->get_eeprom_rev(ah
) < AR5416_EEP_MINOR_VER_7
)
712 pModal
= &eep
->modalHeader
;
714 if (pModal
->xpaBiasLvl
!= 0xff) {
715 biaslevel
= pModal
->xpaBiasLvl
;
716 INI_RA(&ah
->iniAddac
, 7, 1) =
717 (INI_RA(&ah
->iniAddac
, 7, 1) & (~0x18)) | biaslevel
<< 3;
721 static void ath9k_hw_4k_set_gain(struct ath_hw
*ah
,
722 struct modal_eep_4k_header
*pModal
,
723 struct ar5416_eeprom_4k
*eep
,
726 REG_WRITE(ah
, AR_PHY_SWITCH_CHAIN_0
,
727 pModal
->antCtrlChain
[0]);
729 REG_WRITE(ah
, AR_PHY_TIMING_CTRL4(0),
730 (REG_READ(ah
, AR_PHY_TIMING_CTRL4(0)) &
731 ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF
|
732 AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF
)) |
733 SM(pModal
->iqCalICh
[0], AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF
) |
734 SM(pModal
->iqCalQCh
[0], AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF
));
736 if ((eep
->baseEepHeader
.version
& AR5416_EEP_VER_MINOR_MASK
) >=
737 AR5416_EEP_MINOR_VER_3
) {
738 txRxAttenLocal
= pModal
->txRxAttenCh
[0];
740 REG_RMW_FIELD(ah
, AR_PHY_GAIN_2GHZ
,
741 AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN
, pModal
->bswMargin
[0]);
742 REG_RMW_FIELD(ah
, AR_PHY_GAIN_2GHZ
,
743 AR_PHY_GAIN_2GHZ_XATTEN1_DB
, pModal
->bswAtten
[0]);
744 REG_RMW_FIELD(ah
, AR_PHY_GAIN_2GHZ
,
745 AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN
,
746 pModal
->xatten2Margin
[0]);
747 REG_RMW_FIELD(ah
, AR_PHY_GAIN_2GHZ
,
748 AR_PHY_GAIN_2GHZ_XATTEN2_DB
, pModal
->xatten2Db
[0]);
750 /* Set the block 1 value to block 0 value */
751 REG_RMW_FIELD(ah
, AR_PHY_GAIN_2GHZ
+ 0x1000,
752 AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN
,
753 pModal
->bswMargin
[0]);
754 REG_RMW_FIELD(ah
, AR_PHY_GAIN_2GHZ
+ 0x1000,
755 AR_PHY_GAIN_2GHZ_XATTEN1_DB
, pModal
->bswAtten
[0]);
756 REG_RMW_FIELD(ah
, AR_PHY_GAIN_2GHZ
+ 0x1000,
757 AR_PHY_GAIN_2GHZ_XATTEN2_MARGIN
,
758 pModal
->xatten2Margin
[0]);
759 REG_RMW_FIELD(ah
, AR_PHY_GAIN_2GHZ
+ 0x1000,
760 AR_PHY_GAIN_2GHZ_XATTEN2_DB
,
761 pModal
->xatten2Db
[0]);
764 REG_RMW_FIELD(ah
, AR_PHY_RXGAIN
,
765 AR9280_PHY_RXGAIN_TXRX_ATTEN
, txRxAttenLocal
);
766 REG_RMW_FIELD(ah
, AR_PHY_RXGAIN
,
767 AR9280_PHY_RXGAIN_TXRX_MARGIN
, pModal
->rxTxMarginCh
[0]);
769 REG_RMW_FIELD(ah
, AR_PHY_RXGAIN
+ 0x1000,
770 AR9280_PHY_RXGAIN_TXRX_ATTEN
, txRxAttenLocal
);
771 REG_RMW_FIELD(ah
, AR_PHY_RXGAIN
+ 0x1000,
772 AR9280_PHY_RXGAIN_TXRX_MARGIN
, pModal
->rxTxMarginCh
[0]);
776 * Read EEPROM header info and program the device for correct operation
777 * given the channel value.
779 static void ath9k_hw_4k_set_board_values(struct ath_hw
*ah
,
780 struct ath9k_channel
*chan
)
782 struct modal_eep_4k_header
*pModal
;
783 struct ar5416_eeprom_4k
*eep
= &ah
->eeprom
.map4k
;
784 struct base_eep_header_4k
*pBase
= &eep
->baseEepHeader
;
786 u8 ob
[5], db1
[5], db2
[5];
787 u8 ant_div_control1
, ant_div_control2
;
790 pModal
= &eep
->modalHeader
;
793 REG_WRITE(ah
, AR_PHY_SWITCH_COM
, pModal
->antCtrlCommon
);
795 /* Single chain for 4K EEPROM*/
796 ath9k_hw_4k_set_gain(ah
, pModal
, eep
, txRxAttenLocal
);
798 /* Initialize Ant Diversity settings from EEPROM */
799 if (pModal
->version
>= 3) {
800 ant_div_control1
= pModal
->antdiv_ctl1
;
801 ant_div_control2
= pModal
->antdiv_ctl2
;
803 regVal
= REG_READ(ah
, AR_PHY_MULTICHAIN_GAIN_CTL
);
804 regVal
&= (~(AR_PHY_9285_ANT_DIV_CTL_ALL
));
806 regVal
|= SM(ant_div_control1
,
807 AR_PHY_9285_ANT_DIV_CTL
);
808 regVal
|= SM(ant_div_control2
,
809 AR_PHY_9285_ANT_DIV_ALT_LNACONF
);
810 regVal
|= SM((ant_div_control2
>> 2),
811 AR_PHY_9285_ANT_DIV_MAIN_LNACONF
);
812 regVal
|= SM((ant_div_control1
>> 1),
813 AR_PHY_9285_ANT_DIV_ALT_GAINTB
);
814 regVal
|= SM((ant_div_control1
>> 2),
815 AR_PHY_9285_ANT_DIV_MAIN_GAINTB
);
818 REG_WRITE(ah
, AR_PHY_MULTICHAIN_GAIN_CTL
, regVal
);
819 regVal
= REG_READ(ah
, AR_PHY_MULTICHAIN_GAIN_CTL
);
820 regVal
= REG_READ(ah
, AR_PHY_CCK_DETECT
);
821 regVal
&= (~AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV
);
822 regVal
|= SM((ant_div_control1
>> 3),
823 AR_PHY_CCK_DETECT_BB_ENABLE_ANT_FAST_DIV
);
825 REG_WRITE(ah
, AR_PHY_CCK_DETECT
, regVal
);
826 regVal
= REG_READ(ah
, AR_PHY_CCK_DETECT
);
829 if (pModal
->version
>= 2) {
830 ob
[0] = pModal
->ob_0
;
831 ob
[1] = pModal
->ob_1
;
832 ob
[2] = pModal
->ob_2
;
833 ob
[3] = pModal
->ob_3
;
834 ob
[4] = pModal
->ob_4
;
836 db1
[0] = pModal
->db1_0
;
837 db1
[1] = pModal
->db1_1
;
838 db1
[2] = pModal
->db1_2
;
839 db1
[3] = pModal
->db1_3
;
840 db1
[4] = pModal
->db1_4
;
842 db2
[0] = pModal
->db2_0
;
843 db2
[1] = pModal
->db2_1
;
844 db2
[2] = pModal
->db2_2
;
845 db2
[3] = pModal
->db2_3
;
846 db2
[4] = pModal
->db2_4
;
847 } else if (pModal
->version
== 1) {
848 ob
[0] = pModal
->ob_0
;
849 ob
[1] = ob
[2] = ob
[3] = ob
[4] = pModal
->ob_1
;
850 db1
[0] = pModal
->db1_0
;
851 db1
[1] = db1
[2] = db1
[3] = db1
[4] = pModal
->db1_1
;
852 db2
[0] = pModal
->db2_0
;
853 db2
[1] = db2
[2] = db2
[3] = db2
[4] = pModal
->db2_1
;
857 for (i
= 0; i
< 5; i
++) {
858 ob
[i
] = pModal
->ob_0
;
859 db1
[i
] = pModal
->db1_0
;
860 db2
[i
] = pModal
->db1_0
;
864 if (AR_SREV_9271(ah
)) {
865 ath9k_hw_analog_shift_rmw(ah
,
867 AR9271_AN_RF2G3_OB_cck
,
868 AR9271_AN_RF2G3_OB_cck_S
,
870 ath9k_hw_analog_shift_rmw(ah
,
872 AR9271_AN_RF2G3_OB_psk
,
873 AR9271_AN_RF2G3_OB_psk_S
,
875 ath9k_hw_analog_shift_rmw(ah
,
877 AR9271_AN_RF2G3_OB_qam
,
878 AR9271_AN_RF2G3_OB_qam_S
,
880 ath9k_hw_analog_shift_rmw(ah
,
882 AR9271_AN_RF2G3_DB_1
,
883 AR9271_AN_RF2G3_DB_1_S
,
885 ath9k_hw_analog_shift_rmw(ah
,
887 AR9271_AN_RF2G4_DB_2
,
888 AR9271_AN_RF2G4_DB_2_S
,
891 ath9k_hw_analog_shift_rmw(ah
,
893 AR9285_AN_RF2G3_OB_0
,
894 AR9285_AN_RF2G3_OB_0_S
,
896 ath9k_hw_analog_shift_rmw(ah
,
898 AR9285_AN_RF2G3_OB_1
,
899 AR9285_AN_RF2G3_OB_1_S
,
901 ath9k_hw_analog_shift_rmw(ah
,
903 AR9285_AN_RF2G3_OB_2
,
904 AR9285_AN_RF2G3_OB_2_S
,
906 ath9k_hw_analog_shift_rmw(ah
,
908 AR9285_AN_RF2G3_OB_3
,
909 AR9285_AN_RF2G3_OB_3_S
,
911 ath9k_hw_analog_shift_rmw(ah
,
913 AR9285_AN_RF2G3_OB_4
,
914 AR9285_AN_RF2G3_OB_4_S
,
917 ath9k_hw_analog_shift_rmw(ah
,
919 AR9285_AN_RF2G3_DB1_0
,
920 AR9285_AN_RF2G3_DB1_0_S
,
922 ath9k_hw_analog_shift_rmw(ah
,
924 AR9285_AN_RF2G3_DB1_1
,
925 AR9285_AN_RF2G3_DB1_1_S
,
927 ath9k_hw_analog_shift_rmw(ah
,
929 AR9285_AN_RF2G3_DB1_2
,
930 AR9285_AN_RF2G3_DB1_2_S
,
932 ath9k_hw_analog_shift_rmw(ah
,
934 AR9285_AN_RF2G4_DB1_3
,
935 AR9285_AN_RF2G4_DB1_3_S
,
937 ath9k_hw_analog_shift_rmw(ah
,
939 AR9285_AN_RF2G4_DB1_4
,
940 AR9285_AN_RF2G4_DB1_4_S
, db1
[4]);
942 ath9k_hw_analog_shift_rmw(ah
,
944 AR9285_AN_RF2G4_DB2_0
,
945 AR9285_AN_RF2G4_DB2_0_S
,
947 ath9k_hw_analog_shift_rmw(ah
,
949 AR9285_AN_RF2G4_DB2_1
,
950 AR9285_AN_RF2G4_DB2_1_S
,
952 ath9k_hw_analog_shift_rmw(ah
,
954 AR9285_AN_RF2G4_DB2_2
,
955 AR9285_AN_RF2G4_DB2_2_S
,
957 ath9k_hw_analog_shift_rmw(ah
,
959 AR9285_AN_RF2G4_DB2_3
,
960 AR9285_AN_RF2G4_DB2_3_S
,
962 ath9k_hw_analog_shift_rmw(ah
,
964 AR9285_AN_RF2G4_DB2_4
,
965 AR9285_AN_RF2G4_DB2_4_S
,
970 REG_RMW_FIELD(ah
, AR_PHY_SETTLING
, AR_PHY_SETTLING_SWITCH
,
971 pModal
->switchSettling
);
972 REG_RMW_FIELD(ah
, AR_PHY_DESIRED_SZ
, AR_PHY_DESIRED_SZ_ADC
,
973 pModal
->adcDesiredSize
);
975 REG_WRITE(ah
, AR_PHY_RF_CTL4
,
976 SM(pModal
->txEndToXpaOff
, AR_PHY_RF_CTL4_TX_END_XPAA_OFF
) |
977 SM(pModal
->txEndToXpaOff
, AR_PHY_RF_CTL4_TX_END_XPAB_OFF
) |
978 SM(pModal
->txFrameToXpaOn
, AR_PHY_RF_CTL4_FRAME_XPAA_ON
) |
979 SM(pModal
->txFrameToXpaOn
, AR_PHY_RF_CTL4_FRAME_XPAB_ON
));
981 REG_RMW_FIELD(ah
, AR_PHY_RF_CTL3
, AR_PHY_TX_END_TO_A2_RX_ON
,
982 pModal
->txEndToRxOn
);
984 if (AR_SREV_9271_10(ah
))
985 REG_RMW_FIELD(ah
, AR_PHY_RF_CTL3
, AR_PHY_TX_END_TO_A2_RX_ON
,
986 pModal
->txEndToRxOn
);
987 REG_RMW_FIELD(ah
, AR_PHY_CCA
, AR9280_PHY_CCA_THRESH62
,
989 REG_RMW_FIELD(ah
, AR_PHY_EXT_CCA0
, AR_PHY_EXT_CCA0_THRESH62
,
992 if ((eep
->baseEepHeader
.version
& AR5416_EEP_VER_MINOR_MASK
) >=
993 AR5416_EEP_MINOR_VER_2
) {
994 REG_RMW_FIELD(ah
, AR_PHY_RF_CTL2
, AR_PHY_TX_END_DATA_START
,
995 pModal
->txFrameToDataStart
);
996 REG_RMW_FIELD(ah
, AR_PHY_RF_CTL2
, AR_PHY_TX_END_PA_ON
,
997 pModal
->txFrameToPaOn
);
1000 if ((eep
->baseEepHeader
.version
& AR5416_EEP_VER_MINOR_MASK
) >=
1001 AR5416_EEP_MINOR_VER_3
) {
1002 if (IS_CHAN_HT40(chan
))
1003 REG_RMW_FIELD(ah
, AR_PHY_SETTLING
,
1004 AR_PHY_SETTLING_SWITCH
,
1005 pModal
->swSettleHt40
);
1007 if (AR_SREV_9271(ah
) || AR_SREV_9285(ah
)) {
1008 u8 bb_desired_scale
= (pModal
->bb_scale_smrt_antenna
&
1009 EEP_4K_BB_DESIRED_SCALE_MASK
);
1010 if ((pBase
->txGainType
== 0) && (bb_desired_scale
!= 0)) {
1011 u32 pwrctrl
, mask
, clr
;
1013 mask
= BIT(0)|BIT(5)|BIT(10)|BIT(15)|BIT(20)|BIT(25);
1014 pwrctrl
= mask
* bb_desired_scale
;
1016 REG_RMW(ah
, AR_PHY_TX_PWRCTRL8
, pwrctrl
, clr
);
1017 REG_RMW(ah
, AR_PHY_TX_PWRCTRL10
, pwrctrl
, clr
);
1018 REG_RMW(ah
, AR_PHY_CH0_TX_PWRCTRL12
, pwrctrl
, clr
);
1020 mask
= BIT(0)|BIT(5)|BIT(15);
1021 pwrctrl
= mask
* bb_desired_scale
;
1023 REG_RMW(ah
, AR_PHY_TX_PWRCTRL9
, pwrctrl
, clr
);
1025 mask
= BIT(0)|BIT(5);
1026 pwrctrl
= mask
* bb_desired_scale
;
1028 REG_RMW(ah
, AR_PHY_CH0_TX_PWRCTRL11
, pwrctrl
, clr
);
1029 REG_RMW(ah
, AR_PHY_CH0_TX_PWRCTRL13
, pwrctrl
, clr
);
1034 static u16
ath9k_hw_4k_get_spur_channel(struct ath_hw
*ah
, u16 i
, bool is2GHz
)
1036 #define EEP_MAP4K_SPURCHAN \
1037 (ah->eeprom.map4k.modalHeader.spurChans[i].spurChan)
1038 struct ath_common
*common
= ath9k_hw_common(ah
);
1040 u16 spur_val
= AR_NO_SPUR
;
1042 ath_dbg(common
, ATH_DBG_ANI
,
1043 "Getting spur idx:%d is2Ghz:%d val:%x\n",
1044 i
, is2GHz
, ah
->config
.spurchans
[i
][is2GHz
]);
1046 switch (ah
->config
.spurmode
) {
1049 case SPUR_ENABLE_IOCTL
:
1050 spur_val
= ah
->config
.spurchans
[i
][is2GHz
];
1051 ath_dbg(common
, ATH_DBG_ANI
,
1052 "Getting spur val from new loc. %d\n", spur_val
);
1054 case SPUR_ENABLE_EEPROM
:
1055 spur_val
= EEP_MAP4K_SPURCHAN
;
1061 #undef EEP_MAP4K_SPURCHAN
1064 const struct eeprom_ops eep_4k_ops
= {
1065 .check_eeprom
= ath9k_hw_4k_check_eeprom
,
1066 .get_eeprom
= ath9k_hw_4k_get_eeprom
,
1067 .fill_eeprom
= ath9k_hw_4k_fill_eeprom
,
1068 .get_eeprom_ver
= ath9k_hw_4k_get_eeprom_ver
,
1069 .get_eeprom_rev
= ath9k_hw_4k_get_eeprom_rev
,
1070 .set_board_values
= ath9k_hw_4k_set_board_values
,
1071 .set_addac
= ath9k_hw_4k_set_addac
,
1072 .set_txpower
= ath9k_hw_4k_set_txpower
,
1073 .get_spur_channel
= ath9k_hw_4k_get_spur_channel