Path: blob/main/sys/dev/ath/ath_hal/ar9002/ar9287_reset.c
39566 views
/*-1* SPDX-License-Identifier: ISC2*3* Copyright (c) 2002-2009 Sam Leffler, Errno Consulting4* Copyright (c) 2002-2008 Atheros Communications, Inc.5*6* Permission to use, copy, modify, and/or distribute this software for any7* purpose with or without fee is hereby granted, provided that the above8* copyright notice and this permission notice appear in all copies.9*10* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES11* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF12* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR13* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES14* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN15* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF16* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.17*/1819#include "opt_ah.h"2021#include "ah.h"22#include "ah_internal.h"23#include "ah_devid.h"2425#include "ah_eeprom_v14.h"26#include "ah_eeprom_9287.h"2728#include "ar5416/ar5416.h"29#include "ar5416/ar5416reg.h"30#include "ar5416/ar5416phy.h"3132#include "ar9002/ar9287phy.h"33#include "ar9002/ar9287an.h"3435#include "ar9002/ar9287_olc.h"36#include "ar9002/ar9287_reset.h"3738/*39* Set the TX power calibration table per-chain.40*41* This only supports open-loop TX power control for the AR9287.42*/43static void44ar9287SetPowerCalTable(struct ath_hal *ah,45const struct ieee80211_channel *chan, int16_t *pTxPowerIndexOffset)46{47struct cal_data_op_loop_ar9287 *pRawDatasetOpenLoop;48uint8_t *pCalBChans = NULL;49uint16_t pdGainOverlap_t2;50uint16_t numPiers = 0, i;51uint16_t numXpdGain, xpdMask;52uint16_t xpdGainValues[AR5416_NUM_PD_GAINS] = {0, 0, 0, 0};53uint32_t regChainOffset;54HAL_EEPROM_9287 *ee = AH_PRIVATE(ah)->ah_eeprom;55struct ar9287_eeprom *pEepData = &ee->ee_base;5657xpdMask = pEepData->modalHeader.xpdGain;5859if ((pEepData->baseEepHeader.version & AR9287_EEP_VER_MINOR_MASK) >=60AR9287_EEP_MINOR_VER_2)61pdGainOverlap_t2 = pEepData->modalHeader.pdGainOverlap;62else63pdGainOverlap_t2 = (uint16_t)(MS(OS_REG_READ(ah, AR_PHY_TPCRG5),64AR_PHY_TPCRG5_PD_GAIN_OVERLAP));6566/* Note: Kiwi should only be 2ghz.. */67if (IEEE80211_IS_CHAN_2GHZ(chan)) {68pCalBChans = pEepData->calFreqPier2G;69numPiers = AR9287_NUM_2G_CAL_PIERS;70pRawDatasetOpenLoop = (struct cal_data_op_loop_ar9287 *)pEepData->calPierData2G[0];71AH5416(ah)->initPDADC = pRawDatasetOpenLoop->vpdPdg[0][0];72}73numXpdGain = 0;7475/* Calculate the value of xpdgains from the xpdGain Mask */76for (i = 1; i <= AR5416_PD_GAINS_IN_MASK; i++) {77if ((xpdMask >> (AR5416_PD_GAINS_IN_MASK - i)) & 1) {78if (numXpdGain >= AR5416_NUM_PD_GAINS)79break;80xpdGainValues[numXpdGain] =81(uint16_t)(AR5416_PD_GAINS_IN_MASK-i);82numXpdGain++;83}84}8586OS_REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,87(numXpdGain - 1) & 0x3);88OS_REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,89xpdGainValues[0]);90OS_REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,91xpdGainValues[1]);92OS_REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3,93xpdGainValues[2]);9495for (i = 0; i < AR9287_MAX_CHAINS; i++) {96regChainOffset = i * 0x1000;9798if (pEepData->baseEepHeader.txMask & (1 << i)) {99int8_t txPower;100pRawDatasetOpenLoop =101(struct cal_data_op_loop_ar9287 *)pEepData->calPierData2G[i];102ar9287olcGetTxGainIndex(ah, chan,103pRawDatasetOpenLoop,104pCalBChans, numPiers,105&txPower);106ar9287olcSetPDADCs(ah, txPower, i);107}108}109110*pTxPowerIndexOffset = 0;111}112113/* XXX hard-coded values? */114#define REDUCE_SCALED_POWER_BY_TWO_CHAIN 6115116/*117* ar9287SetPowerPerRateTable118*119* Sets the transmit power in the baseband for the given120* operating channel and mode.121*122* This is like the v14 EEPROM table except the 5GHz code.123*/124static HAL_BOOL125ar9287SetPowerPerRateTable(struct ath_hal *ah,126struct ar9287_eeprom *pEepData,127const struct ieee80211_channel *chan,128int16_t *ratesArray, uint16_t cfgCtl,129uint16_t AntennaReduction,130uint16_t twiceMaxRegulatoryPower,131uint16_t powerLimit)132{133#define N(a) (sizeof(a)/sizeof(a[0]))134/* Local defines to distinguish between extension and control CTL's */135#define EXT_ADDITIVE (0x8000)136#define CTL_11A_EXT (CTL_11A | EXT_ADDITIVE)137#define CTL_11G_EXT (CTL_11G | EXT_ADDITIVE)138#define CTL_11B_EXT (CTL_11B | EXT_ADDITIVE)139140uint16_t twiceMaxEdgePower = AR5416_MAX_RATE_POWER;141int i;142int16_t twiceLargestAntenna;143struct cal_ctl_data_ar9287 *rep;144CAL_TARGET_POWER_LEG targetPowerOfdm;145CAL_TARGET_POWER_LEG targetPowerCck = {0, {0, 0, 0, 0}};146CAL_TARGET_POWER_LEG targetPowerOfdmExt = {0, {0, 0, 0, 0}};147CAL_TARGET_POWER_LEG targetPowerCckExt = {0, {0, 0, 0, 0}};148CAL_TARGET_POWER_HT targetPowerHt20;149CAL_TARGET_POWER_HT targetPowerHt40 = {0, {0, 0, 0, 0}};150int16_t scaledPower, minCtlPower;151152#define SUB_NUM_CTL_MODES_AT_2G_40 3 /* excluding HT40, EXT-OFDM, EXT-CCK */153static const uint16_t ctlModesFor11g[] = {154CTL_11B, CTL_11G, CTL_2GHT20, CTL_11B_EXT, CTL_11G_EXT, CTL_2GHT40155};156const uint16_t *pCtlMode;157uint16_t numCtlModes, ctlMode, freq;158CHAN_CENTERS centers;159160ar5416GetChannelCenters(ah, chan, ¢ers);161162/* Compute TxPower reduction due to Antenna Gain */163164twiceLargestAntenna = AH_MAX(165pEepData->modalHeader.antennaGainCh[0],166pEepData->modalHeader.antennaGainCh[1]);167168twiceLargestAntenna = (int16_t)AH_MIN((AntennaReduction) - twiceLargestAntenna, 0);169170/* XXX setup for 5212 use (really used?) */171ath_hal_eepromSet(ah, AR_EEP_ANTGAINMAX_2, twiceLargestAntenna);172173/*174* scaledPower is the minimum of the user input power level and175* the regulatory allowed power level176*/177scaledPower = AH_MIN(powerLimit, twiceMaxRegulatoryPower + twiceLargestAntenna);178179/* Reduce scaled Power by number of chains active to get to per chain tx power level */180/* TODO: better value than these? */181switch (owl_get_ntxchains(AH5416(ah)->ah_tx_chainmask)) {182case 1:183break;184case 2:185scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN;186break;187default:188return AH_FALSE; /* Unsupported number of chains */189}190191scaledPower = AH_MAX(0, scaledPower);192193/* Get target powers from EEPROM - our baseline for TX Power */194/* XXX assume channel is 2ghz */195if (1) {196/* Setup for CTL modes */197numCtlModes = N(ctlModesFor11g) - SUB_NUM_CTL_MODES_AT_2G_40; /* CTL_11B, CTL_11G, CTL_2GHT20 */198pCtlMode = ctlModesFor11g;199200ar5416GetTargetPowersLeg(ah, chan, pEepData->calTargetPowerCck,201AR9287_NUM_2G_CCK_TARGET_POWERS, &targetPowerCck, 4, AH_FALSE);202ar5416GetTargetPowersLeg(ah, chan, pEepData->calTargetPower2G,203AR9287_NUM_2G_20_TARGET_POWERS, &targetPowerOfdm, 4, AH_FALSE);204ar5416GetTargetPowers(ah, chan, pEepData->calTargetPower2GHT20,205AR9287_NUM_2G_20_TARGET_POWERS, &targetPowerHt20, 8, AH_FALSE);206207if (IEEE80211_IS_CHAN_HT40(chan)) {208numCtlModes = N(ctlModesFor11g); /* All 2G CTL's */209210ar5416GetTargetPowers(ah, chan, pEepData->calTargetPower2GHT40,211AR9287_NUM_2G_40_TARGET_POWERS, &targetPowerHt40, 8, AH_TRUE);212/* Get target powers for extension channels */213ar5416GetTargetPowersLeg(ah, chan, pEepData->calTargetPowerCck,214AR9287_NUM_2G_CCK_TARGET_POWERS, &targetPowerCckExt, 4, AH_TRUE);215ar5416GetTargetPowersLeg(ah, chan, pEepData->calTargetPower2G,216AR9287_NUM_2G_20_TARGET_POWERS, &targetPowerOfdmExt, 4, AH_TRUE);217}218}219220/*221* For MIMO, need to apply regulatory caps individually across dynamically222* running modes: CCK, OFDM, HT20, HT40223*224* The outer loop walks through each possible applicable runtime mode.225* The inner loop walks through each ctlIndex entry in EEPROM.226* The ctl value is encoded as [7:4] == test group, [3:0] == test mode.227*228*/229for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {230HAL_BOOL isHt40CtlMode = (pCtlMode[ctlMode] == CTL_5GHT40) ||231(pCtlMode[ctlMode] == CTL_2GHT40);232if (isHt40CtlMode) {233freq = centers.ctl_center;234} else if (pCtlMode[ctlMode] & EXT_ADDITIVE) {235freq = centers.ext_center;236} else {237freq = centers.ctl_center;238}239240/* walk through each CTL index stored in EEPROM */241for (i = 0; (i < AR9287_NUM_CTLS) && pEepData->ctlIndex[i]; i++) {242uint16_t twiceMinEdgePower;243244/* compare test group from regulatory channel list with test mode from pCtlMode list */245if ((((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == pEepData->ctlIndex[i]) ||246(((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) ==247((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL))) {248rep = &(pEepData->ctlData[i]);249twiceMinEdgePower = ar5416GetMaxEdgePower(freq,250rep->ctlEdges[owl_get_ntxchains(AH5416(ah)->ah_tx_chainmask) - 1],251IEEE80211_IS_CHAN_2GHZ(chan));252if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {253/* Find the minimum of all CTL edge powers that apply to this channel */254twiceMaxEdgePower = AH_MIN(twiceMaxEdgePower, twiceMinEdgePower);255} else {256/* specific */257twiceMaxEdgePower = twiceMinEdgePower;258break;259}260}261}262minCtlPower = (uint8_t)AH_MIN(twiceMaxEdgePower, scaledPower);263/* Apply ctl mode to correct target power set */264switch(pCtlMode[ctlMode]) {265case CTL_11B:266for (i = 0; i < N(targetPowerCck.tPow2x); i++) {267targetPowerCck.tPow2x[i] = (uint8_t)AH_MIN(targetPowerCck.tPow2x[i], minCtlPower);268}269break;270case CTL_11A:271case CTL_11G:272for (i = 0; i < N(targetPowerOfdm.tPow2x); i++) {273targetPowerOfdm.tPow2x[i] = (uint8_t)AH_MIN(targetPowerOfdm.tPow2x[i], minCtlPower);274}275break;276case CTL_5GHT20:277case CTL_2GHT20:278for (i = 0; i < N(targetPowerHt20.tPow2x); i++) {279targetPowerHt20.tPow2x[i] = (uint8_t)AH_MIN(targetPowerHt20.tPow2x[i], minCtlPower);280}281break;282case CTL_11B_EXT:283targetPowerCckExt.tPow2x[0] = (uint8_t)AH_MIN(targetPowerCckExt.tPow2x[0], minCtlPower);284break;285case CTL_11A_EXT:286case CTL_11G_EXT:287targetPowerOfdmExt.tPow2x[0] = (uint8_t)AH_MIN(targetPowerOfdmExt.tPow2x[0], minCtlPower);288break;289case CTL_5GHT40:290case CTL_2GHT40:291for (i = 0; i < N(targetPowerHt40.tPow2x); i++) {292targetPowerHt40.tPow2x[i] = (uint8_t)AH_MIN(targetPowerHt40.tPow2x[i], minCtlPower);293}294break;295default:296return AH_FALSE;297break;298}299} /* end ctl mode checking */300301/* Set rates Array from collected data */302ar5416SetRatesArrayFromTargetPower(ah, chan, ratesArray,303&targetPowerCck,304&targetPowerCckExt,305&targetPowerOfdm,306&targetPowerOfdmExt,307&targetPowerHt20,308&targetPowerHt40);309return AH_TRUE;310#undef EXT_ADDITIVE311#undef CTL_11A_EXT312#undef CTL_11G_EXT313#undef CTL_11B_EXT314#undef SUB_NUM_CTL_MODES_AT_5G_40315#undef SUB_NUM_CTL_MODES_AT_2G_40316#undef N317}318319#undef REDUCE_SCALED_POWER_BY_TWO_CHAIN320321/*322* This is based off of the AR5416/AR9285 code and likely could323* be unified in the future.324*/325HAL_BOOL326ar9287SetTransmitPower(struct ath_hal *ah,327const struct ieee80211_channel *chan, uint16_t *rfXpdGain)328{329#define POW_SM(_r, _s) (((_r) & 0x3f) << (_s))330#define N(a) (sizeof (a) / sizeof (a[0]))331332const struct modal_eep_ar9287_header *pModal;333struct ath_hal_5212 *ahp = AH5212(ah);334int16_t txPowerIndexOffset = 0;335int i;336337uint16_t cfgCtl;338uint16_t powerLimit;339uint16_t twiceAntennaReduction;340uint16_t twiceMaxRegulatoryPower;341int16_t maxPower;342HAL_EEPROM_9287 *ee = AH_PRIVATE(ah)->ah_eeprom;343struct ar9287_eeprom *pEepData = &ee->ee_base;344345AH5416(ah)->ah_ht40PowerIncForPdadc = 2;346347/* Setup info for the actual eeprom */348OS_MEMZERO(AH5416(ah)->ah_ratesArray,349sizeof(AH5416(ah)->ah_ratesArray));350cfgCtl = ath_hal_getctl(ah, chan);351powerLimit = chan->ic_maxregpower * 2;352twiceAntennaReduction = chan->ic_maxantgain;353twiceMaxRegulatoryPower = AH_MIN(MAX_RATE_POWER,354AH_PRIVATE(ah)->ah_powerLimit);355pModal = &pEepData->modalHeader;356HALDEBUG(ah, HAL_DEBUG_RESET, "%s Channel=%u CfgCtl=%u\n",357__func__,chan->ic_freq, cfgCtl );358359/* XXX Assume Minor is v2 or later */360AH5416(ah)->ah_ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;361362/* Fetch per-rate power table for the given channel */363if (! ar9287SetPowerPerRateTable(ah, pEepData, chan,364&AH5416(ah)->ah_ratesArray[0],365cfgCtl,366twiceAntennaReduction,367twiceMaxRegulatoryPower, powerLimit)) {368HALDEBUG(ah, HAL_DEBUG_ANY,369"%s: unable to set tx power per rate table\n", __func__);370return AH_FALSE;371}372373/* Set TX power control calibration curves for each TX chain */374ar9287SetPowerCalTable(ah, chan, &txPowerIndexOffset);375376/* Calculate maximum power level */377maxPower = AH_MAX(AH5416(ah)->ah_ratesArray[rate6mb],378AH5416(ah)->ah_ratesArray[rateHt20_0]);379maxPower = AH_MAX(maxPower,380AH5416(ah)->ah_ratesArray[rate1l]);381382if (IEEE80211_IS_CHAN_HT40(chan))383maxPower = AH_MAX(maxPower,384AH5416(ah)->ah_ratesArray[rateHt40_0]);385386ahp->ah_tx6PowerInHalfDbm = maxPower;387AH_PRIVATE(ah)->ah_maxPowerLevel = maxPower;388ahp->ah_txPowerIndexOffset = txPowerIndexOffset;389390/*391* txPowerIndexOffset is set by the SetPowerTable() call -392* adjust the rate table (0 offset if rates EEPROM not loaded)393*/394/* XXX what about the pwrTableOffset? */395for (i = 0; i < N(AH5416(ah)->ah_ratesArray); i++) {396AH5416(ah)->ah_ratesArray[i] =397(int16_t)(txPowerIndexOffset +398AH5416(ah)->ah_ratesArray[i]);399/* -5 dBm offset for Merlin and later; this includes Kiwi */400AH5416(ah)->ah_ratesArray[i] -= AR5416_PWR_TABLE_OFFSET_DB * 2;401if (AH5416(ah)->ah_ratesArray[i] > AR5416_MAX_RATE_POWER)402AH5416(ah)->ah_ratesArray[i] = AR5416_MAX_RATE_POWER;403if (AH5416(ah)->ah_ratesArray[i] < 0)404AH5416(ah)->ah_ratesArray[i] = 0;405}406407#ifdef AH_EEPROM_DUMP408ar5416PrintPowerPerRate(ah, AH5416(ah)->ah_ratesArray);409#endif410411/*412* Adjust the HT40 power to meet the correct target TX power413* for 40MHz mode, based on TX power curves that are established414* for 20MHz mode.415*416* XXX handle overflow/too high power level?417*/418if (IEEE80211_IS_CHAN_HT40(chan)) {419AH5416(ah)->ah_ratesArray[rateHt40_0] +=420AH5416(ah)->ah_ht40PowerIncForPdadc;421AH5416(ah)->ah_ratesArray[rateHt40_1] +=422AH5416(ah)->ah_ht40PowerIncForPdadc;423AH5416(ah)->ah_ratesArray[rateHt40_2] +=424AH5416(ah)->ah_ht40PowerIncForPdadc;425AH5416(ah)->ah_ratesArray[rateHt40_3] +=426AH5416(ah)->ah_ht40PowerIncForPdadc;427AH5416(ah)->ah_ratesArray[rateHt40_4] +=428AH5416(ah)->ah_ht40PowerIncForPdadc;429AH5416(ah)->ah_ratesArray[rateHt40_5] +=430AH5416(ah)->ah_ht40PowerIncForPdadc;431AH5416(ah)->ah_ratesArray[rateHt40_6] +=432AH5416(ah)->ah_ht40PowerIncForPdadc;433AH5416(ah)->ah_ratesArray[rateHt40_7] +=434AH5416(ah)->ah_ht40PowerIncForPdadc;435}436437/* Write the TX power rate registers */438ar5416WriteTxPowerRateRegisters(ah, chan, AH5416(ah)->ah_ratesArray);439440return AH_TRUE;441#undef POW_SM442#undef N443}444445/*446* Read EEPROM header info and program the device for correct operation447* given the channel value.448*/449HAL_BOOL450ar9287SetBoardValues(struct ath_hal *ah, const struct ieee80211_channel *chan)451{452const HAL_EEPROM_9287 *ee = AH_PRIVATE(ah)->ah_eeprom;453const struct ar9287_eeprom *eep = &ee->ee_base;454const struct modal_eep_ar9287_header *pModal = &eep->modalHeader;455uint16_t antWrites[AR9287_ANT_16S];456uint32_t regChainOffset, regval;457uint8_t txRxAttenLocal;458int i, j, offset_num;459460pModal = &eep->modalHeader;461462antWrites[0] = (uint16_t)((pModal->antCtrlCommon >> 28) & 0xF);463antWrites[1] = (uint16_t)((pModal->antCtrlCommon >> 24) & 0xF);464antWrites[2] = (uint16_t)((pModal->antCtrlCommon >> 20) & 0xF);465antWrites[3] = (uint16_t)((pModal->antCtrlCommon >> 16) & 0xF);466antWrites[4] = (uint16_t)((pModal->antCtrlCommon >> 12) & 0xF);467antWrites[5] = (uint16_t)((pModal->antCtrlCommon >> 8) & 0xF);468antWrites[6] = (uint16_t)((pModal->antCtrlCommon >> 4) & 0xF);469antWrites[7] = (uint16_t)(pModal->antCtrlCommon & 0xF);470471offset_num = 8;472473for (i = 0, j = offset_num; i < AR9287_MAX_CHAINS; i++) {474antWrites[j++] = (uint16_t)((pModal->antCtrlChain[i] >> 28) & 0xf);475antWrites[j++] = (uint16_t)((pModal->antCtrlChain[i] >> 10) & 0x3);476antWrites[j++] = (uint16_t)((pModal->antCtrlChain[i] >> 8) & 0x3);477antWrites[j++] = 0;478antWrites[j++] = (uint16_t)((pModal->antCtrlChain[i] >> 6) & 0x3);479antWrites[j++] = (uint16_t)((pModal->antCtrlChain[i] >> 4) & 0x3);480antWrites[j++] = (uint16_t)((pModal->antCtrlChain[i] >> 2) & 0x3);481antWrites[j++] = (uint16_t)(pModal->antCtrlChain[i] & 0x3);482}483484OS_REG_WRITE(ah, AR_PHY_SWITCH_COM, pModal->antCtrlCommon);485486for (i = 0; i < AR9287_MAX_CHAINS; i++) {487regChainOffset = i * 0x1000;488489OS_REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,490pModal->antCtrlChain[i]);491492OS_REG_WRITE(ah, AR_PHY_TIMING_CTRL4_CHAIN(0) + regChainOffset,493(OS_REG_READ(ah, AR_PHY_TIMING_CTRL4_CHAIN(0)494+ regChainOffset)495& ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |496AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |497SM(pModal->iqCalICh[i],498AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |499SM(pModal->iqCalQCh[i],500AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));501502txRxAttenLocal = pModal->txRxAttenCh[i];503504OS_REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,505AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN,506pModal->bswMargin[i]);507OS_REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,508AR_PHY_GAIN_2GHZ_XATTEN1_DB,509pModal->bswAtten[i]);510OS_REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,511AR9280_PHY_RXGAIN_TXRX_ATTEN,512txRxAttenLocal);513OS_REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,514AR9280_PHY_RXGAIN_TXRX_MARGIN,515pModal->rxTxMarginCh[i]);516}517518if (IEEE80211_IS_CHAN_HT40(chan))519OS_REG_RMW_FIELD(ah, AR_PHY_SETTLING,520AR_PHY_SETTLING_SWITCH, pModal->swSettleHt40);521else522OS_REG_RMW_FIELD(ah, AR_PHY_SETTLING,523AR_PHY_SETTLING_SWITCH, pModal->switchSettling);524525OS_REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,526AR_PHY_DESIRED_SZ_ADC, pModal->adcDesiredSize);527528OS_REG_WRITE(ah, AR_PHY_RF_CTL4,529SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF)530| SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAB_OFF)531| SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAA_ON)532| SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAB_ON));533534OS_REG_RMW_FIELD(ah, AR_PHY_RF_CTL3,535AR_PHY_TX_END_TO_A2_RX_ON, pModal->txEndToRxOn);536537OS_REG_RMW_FIELD(ah, AR_PHY_CCA,538AR9280_PHY_CCA_THRESH62, pModal->thresh62);539OS_REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0,540AR_PHY_EXT_CCA0_THRESH62, pModal->thresh62);541542regval = OS_REG_READ(ah, AR9287_AN_RF2G3_CH0);543regval &= ~(AR9287_AN_RF2G3_DB1 |544AR9287_AN_RF2G3_DB2 |545AR9287_AN_RF2G3_OB_CCK |546AR9287_AN_RF2G3_OB_PSK |547AR9287_AN_RF2G3_OB_QAM |548AR9287_AN_RF2G3_OB_PAL_OFF);549regval |= (SM(pModal->db1, AR9287_AN_RF2G3_DB1) |550SM(pModal->db2, AR9287_AN_RF2G3_DB2) |551SM(pModal->ob_cck, AR9287_AN_RF2G3_OB_CCK) |552SM(pModal->ob_psk, AR9287_AN_RF2G3_OB_PSK) |553SM(pModal->ob_qam, AR9287_AN_RF2G3_OB_QAM) |554SM(pModal->ob_pal_off, AR9287_AN_RF2G3_OB_PAL_OFF));555556/* Analog write - requires a 100usec delay */557OS_A_REG_WRITE(ah, AR9287_AN_RF2G3_CH0, regval);558559regval = OS_REG_READ(ah, AR9287_AN_RF2G3_CH1);560regval &= ~(AR9287_AN_RF2G3_DB1 |561AR9287_AN_RF2G3_DB2 |562AR9287_AN_RF2G3_OB_CCK |563AR9287_AN_RF2G3_OB_PSK |564AR9287_AN_RF2G3_OB_QAM |565AR9287_AN_RF2G3_OB_PAL_OFF);566regval |= (SM(pModal->db1, AR9287_AN_RF2G3_DB1) |567SM(pModal->db2, AR9287_AN_RF2G3_DB2) |568SM(pModal->ob_cck, AR9287_AN_RF2G3_OB_CCK) |569SM(pModal->ob_psk, AR9287_AN_RF2G3_OB_PSK) |570SM(pModal->ob_qam, AR9287_AN_RF2G3_OB_QAM) |571SM(pModal->ob_pal_off, AR9287_AN_RF2G3_OB_PAL_OFF));572573OS_A_REG_WRITE(ah, AR9287_AN_RF2G3_CH1, regval);574575OS_REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,576AR_PHY_TX_FRAME_TO_DATA_START, pModal->txFrameToDataStart);577OS_REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,578AR_PHY_TX_FRAME_TO_PA_ON, pModal->txFrameToPaOn);579580OS_A_REG_RMW_FIELD(ah, AR9287_AN_TOP2,581AR9287_AN_TOP2_XPABIAS_LVL, pModal->xpaBiasLvl);582583return AH_TRUE;584}585586587