xref: /freebsd/sys/dev/ath/ath_hal/ar9002/ar9287_reset.c (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1*6e778a7eSPedro F. Giffuni /*-
2*6e778a7eSPedro F. Giffuni  * SPDX-License-Identifier: ISC
3*6e778a7eSPedro F. Giffuni  *
4d8daa2e3SAdrian Chadd  * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
5d8daa2e3SAdrian Chadd  * Copyright (c) 2002-2008 Atheros Communications, Inc.
6d8daa2e3SAdrian Chadd  *
7d8daa2e3SAdrian Chadd  * Permission to use, copy, modify, and/or distribute this software for any
8d8daa2e3SAdrian Chadd  * purpose with or without fee is hereby granted, provided that the above
9d8daa2e3SAdrian Chadd  * copyright notice and this permission notice appear in all copies.
10d8daa2e3SAdrian Chadd  *
11d8daa2e3SAdrian Chadd  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12d8daa2e3SAdrian Chadd  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13d8daa2e3SAdrian Chadd  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14d8daa2e3SAdrian Chadd  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15d8daa2e3SAdrian Chadd  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16d8daa2e3SAdrian Chadd  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17d8daa2e3SAdrian Chadd  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18d8daa2e3SAdrian Chadd  */
19d8daa2e3SAdrian Chadd 
20d8daa2e3SAdrian Chadd #include "opt_ah.h"
21d8daa2e3SAdrian Chadd 
22d8daa2e3SAdrian Chadd #include "ah.h"
23d8daa2e3SAdrian Chadd #include "ah_internal.h"
24d8daa2e3SAdrian Chadd #include "ah_devid.h"
25d8daa2e3SAdrian Chadd 
26d8daa2e3SAdrian Chadd #include "ah_eeprom_v14.h"
27d8daa2e3SAdrian Chadd #include "ah_eeprom_9287.h"
28d8daa2e3SAdrian Chadd 
29d8daa2e3SAdrian Chadd #include "ar5416/ar5416.h"
30d8daa2e3SAdrian Chadd #include "ar5416/ar5416reg.h"
31d8daa2e3SAdrian Chadd #include "ar5416/ar5416phy.h"
32d8daa2e3SAdrian Chadd 
33d8daa2e3SAdrian Chadd #include "ar9002/ar9287phy.h"
34d8daa2e3SAdrian Chadd #include "ar9002/ar9287an.h"
35d8daa2e3SAdrian Chadd 
364551052dSAdrian Chadd #include "ar9002/ar9287_olc.h"
37d8daa2e3SAdrian Chadd #include "ar9002/ar9287_reset.h"
38d8daa2e3SAdrian Chadd 
394551052dSAdrian Chadd /*
404551052dSAdrian Chadd  * Set the TX power calibration table per-chain.
414551052dSAdrian Chadd  *
424551052dSAdrian Chadd  * This only supports open-loop TX power control for the AR9287.
434551052dSAdrian Chadd  */
444551052dSAdrian Chadd static void
ar9287SetPowerCalTable(struct ath_hal * ah,const struct ieee80211_channel * chan,int16_t * pTxPowerIndexOffset)454551052dSAdrian Chadd ar9287SetPowerCalTable(struct ath_hal *ah,
464551052dSAdrian Chadd     const struct ieee80211_channel *chan, int16_t *pTxPowerIndexOffset)
474551052dSAdrian Chadd {
484551052dSAdrian Chadd 	struct cal_data_op_loop_ar9287 *pRawDatasetOpenLoop;
494551052dSAdrian Chadd 	uint8_t *pCalBChans = NULL;
504551052dSAdrian Chadd 	uint16_t pdGainOverlap_t2;
514551052dSAdrian Chadd 	uint16_t numPiers = 0, i;
524551052dSAdrian Chadd 	uint16_t numXpdGain, xpdMask;
534551052dSAdrian Chadd 	uint16_t xpdGainValues[AR5416_NUM_PD_GAINS] = {0, 0, 0, 0};
544551052dSAdrian Chadd 	uint32_t regChainOffset;
554551052dSAdrian Chadd 	HAL_EEPROM_9287 *ee = AH_PRIVATE(ah)->ah_eeprom;
564551052dSAdrian Chadd 	struct ar9287_eeprom *pEepData = &ee->ee_base;
574551052dSAdrian Chadd 
584551052dSAdrian Chadd 	xpdMask = pEepData->modalHeader.xpdGain;
594551052dSAdrian Chadd 
604551052dSAdrian Chadd 	if ((pEepData->baseEepHeader.version & AR9287_EEP_VER_MINOR_MASK) >=
614551052dSAdrian Chadd 	    AR9287_EEP_MINOR_VER_2)
624551052dSAdrian Chadd 		pdGainOverlap_t2 = pEepData->modalHeader.pdGainOverlap;
634551052dSAdrian Chadd 	else
644551052dSAdrian Chadd 		pdGainOverlap_t2 = (uint16_t)(MS(OS_REG_READ(ah, AR_PHY_TPCRG5),
654551052dSAdrian Chadd 					    AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
664551052dSAdrian Chadd 
674551052dSAdrian Chadd 	/* Note: Kiwi should only be 2ghz.. */
684551052dSAdrian Chadd 	if (IEEE80211_IS_CHAN_2GHZ(chan)) {
694551052dSAdrian Chadd 		pCalBChans = pEepData->calFreqPier2G;
704551052dSAdrian Chadd 		numPiers = AR9287_NUM_2G_CAL_PIERS;
714551052dSAdrian Chadd 		pRawDatasetOpenLoop = (struct cal_data_op_loop_ar9287 *)pEepData->calPierData2G[0];
724551052dSAdrian Chadd 		AH5416(ah)->initPDADC = pRawDatasetOpenLoop->vpdPdg[0][0];
734551052dSAdrian Chadd 	}
744551052dSAdrian Chadd 	numXpdGain = 0;
754551052dSAdrian Chadd 
764551052dSAdrian Chadd 	/* Calculate the value of xpdgains from the xpdGain Mask */
774551052dSAdrian Chadd 	for (i = 1; i <= AR5416_PD_GAINS_IN_MASK; i++) {
784551052dSAdrian Chadd 		if ((xpdMask >> (AR5416_PD_GAINS_IN_MASK - i)) & 1) {
794551052dSAdrian Chadd 			if (numXpdGain >= AR5416_NUM_PD_GAINS)
804551052dSAdrian Chadd 				break;
814551052dSAdrian Chadd 			xpdGainValues[numXpdGain] =
824551052dSAdrian Chadd 				(uint16_t)(AR5416_PD_GAINS_IN_MASK-i);
834551052dSAdrian Chadd 			numXpdGain++;
844551052dSAdrian Chadd 		}
854551052dSAdrian Chadd 	}
864551052dSAdrian Chadd 
874551052dSAdrian Chadd 	OS_REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
884551052dSAdrian Chadd 		      (numXpdGain - 1) & 0x3);
894551052dSAdrian Chadd 	OS_REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,
904551052dSAdrian Chadd 		      xpdGainValues[0]);
914551052dSAdrian Chadd 	OS_REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
924551052dSAdrian Chadd 		      xpdGainValues[1]);
934551052dSAdrian Chadd 	OS_REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3,
944551052dSAdrian Chadd 		      xpdGainValues[2]);
954551052dSAdrian Chadd 
964551052dSAdrian Chadd 	for (i = 0; i < AR9287_MAX_CHAINS; i++) {
974551052dSAdrian Chadd 		regChainOffset = i * 0x1000;
984551052dSAdrian Chadd 
994551052dSAdrian Chadd 		if (pEepData->baseEepHeader.txMask & (1 << i)) {
1004551052dSAdrian Chadd 			int8_t txPower;
1014551052dSAdrian Chadd 			pRawDatasetOpenLoop =
1024551052dSAdrian Chadd 			(struct cal_data_op_loop_ar9287 *)pEepData->calPierData2G[i];
1034551052dSAdrian Chadd 				ar9287olcGetTxGainIndex(ah, chan,
1044551052dSAdrian Chadd 				    pRawDatasetOpenLoop,
1054551052dSAdrian Chadd 				    pCalBChans, numPiers,
1064551052dSAdrian Chadd 				    &txPower);
1074551052dSAdrian Chadd 				ar9287olcSetPDADCs(ah, txPower, i);
1084551052dSAdrian Chadd 		}
1094551052dSAdrian Chadd 	}
1104551052dSAdrian Chadd 
1114551052dSAdrian Chadd 	*pTxPowerIndexOffset = 0;
1124551052dSAdrian Chadd }
1134551052dSAdrian Chadd 
114f1285519SAdrian Chadd /* XXX hard-coded values? */
115f1285519SAdrian Chadd #define REDUCE_SCALED_POWER_BY_TWO_CHAIN     6
116f1285519SAdrian Chadd 
117ea18ed26SAdrian Chadd /*
118f1285519SAdrian Chadd  * ar9287SetPowerPerRateTable
119ea18ed26SAdrian Chadd  *
120f1285519SAdrian Chadd  * Sets the transmit power in the baseband for the given
121f1285519SAdrian Chadd  * operating channel and mode.
122f1285519SAdrian Chadd  *
123f1285519SAdrian Chadd  * This is like the v14 EEPROM table except the 5GHz code.
124ea18ed26SAdrian Chadd  */
125ea18ed26SAdrian Chadd static HAL_BOOL
ar9287SetPowerPerRateTable(struct ath_hal * ah,struct ar9287_eeprom * pEepData,const struct ieee80211_channel * chan,int16_t * ratesArray,uint16_t cfgCtl,uint16_t AntennaReduction,uint16_t twiceMaxRegulatoryPower,uint16_t powerLimit)126f1285519SAdrian Chadd ar9287SetPowerPerRateTable(struct ath_hal *ah,
127ea18ed26SAdrian Chadd     struct ar9287_eeprom *pEepData,
128ea18ed26SAdrian Chadd     const struct ieee80211_channel *chan,
129ea18ed26SAdrian Chadd     int16_t *ratesArray, uint16_t cfgCtl,
130ea18ed26SAdrian Chadd     uint16_t AntennaReduction,
131ea18ed26SAdrian Chadd     uint16_t twiceMaxRegulatoryPower,
132ea18ed26SAdrian Chadd     uint16_t powerLimit)
133ea18ed26SAdrian Chadd {
134f1285519SAdrian Chadd #define	N(a)	(sizeof(a)/sizeof(a[0]))
135f1285519SAdrian Chadd /* Local defines to distinguish between extension and control CTL's */
136f1285519SAdrian Chadd #define EXT_ADDITIVE (0x8000)
137f1285519SAdrian Chadd #define CTL_11A_EXT (CTL_11A | EXT_ADDITIVE)
138f1285519SAdrian Chadd #define CTL_11G_EXT (CTL_11G | EXT_ADDITIVE)
139f1285519SAdrian Chadd #define CTL_11B_EXT (CTL_11B | EXT_ADDITIVE)
140f1285519SAdrian Chadd 
141f1285519SAdrian Chadd 	uint16_t twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
142ea18ed26SAdrian Chadd 	int i;
143f1285519SAdrian Chadd 	int16_t  twiceLargestAntenna;
144f1285519SAdrian Chadd 	struct cal_ctl_data_ar9287 *rep;
145f1285519SAdrian Chadd 	CAL_TARGET_POWER_LEG targetPowerOfdm;
146f1285519SAdrian Chadd 	CAL_TARGET_POWER_LEG targetPowerCck = {0, {0, 0, 0, 0}};
147f1285519SAdrian Chadd 	CAL_TARGET_POWER_LEG targetPowerOfdmExt = {0, {0, 0, 0, 0}};
148f1285519SAdrian Chadd 	CAL_TARGET_POWER_LEG targetPowerCckExt = {0, {0, 0, 0, 0}};
149f1285519SAdrian Chadd 	CAL_TARGET_POWER_HT  targetPowerHt20;
150f1285519SAdrian Chadd 	CAL_TARGET_POWER_HT  targetPowerHt40 = {0, {0, 0, 0, 0}};
151f1285519SAdrian Chadd 	int16_t scaledPower, minCtlPower;
152ea18ed26SAdrian Chadd 
153f1285519SAdrian Chadd #define SUB_NUM_CTL_MODES_AT_2G_40 3   /* excluding HT40, EXT-OFDM, EXT-CCK */
154f1285519SAdrian Chadd 	static const uint16_t ctlModesFor11g[] = {
155f1285519SAdrian Chadd 	   CTL_11B, CTL_11G, CTL_2GHT20, CTL_11B_EXT, CTL_11G_EXT, CTL_2GHT40
156f1285519SAdrian Chadd 	};
157f1285519SAdrian Chadd 	const uint16_t *pCtlMode;
158f1285519SAdrian Chadd 	uint16_t numCtlModes, ctlMode, freq;
159f1285519SAdrian Chadd 	CHAN_CENTERS centers;
160ea18ed26SAdrian Chadd 
161f1285519SAdrian Chadd 	ar5416GetChannelCenters(ah,  chan, &centers);
162f1285519SAdrian Chadd 
163f1285519SAdrian Chadd 	/* Compute TxPower reduction due to Antenna Gain */
164f1285519SAdrian Chadd 
165f1285519SAdrian Chadd 	twiceLargestAntenna = AH_MAX(
166f1285519SAdrian Chadd 	    pEepData->modalHeader.antennaGainCh[0],
167f1285519SAdrian Chadd 	    pEepData->modalHeader.antennaGainCh[1]);
168f1285519SAdrian Chadd 
169f1285519SAdrian Chadd 	twiceLargestAntenna = (int16_t)AH_MIN((AntennaReduction) - twiceLargestAntenna, 0);
170f1285519SAdrian Chadd 
171f1285519SAdrian Chadd 	/* XXX setup for 5212 use (really used?) */
172f1285519SAdrian Chadd 	ath_hal_eepromSet(ah, AR_EEP_ANTGAINMAX_2, twiceLargestAntenna);
173f1285519SAdrian Chadd 
174f1285519SAdrian Chadd 	/*
175f1285519SAdrian Chadd 	 * scaledPower is the minimum of the user input power level and
176f1285519SAdrian Chadd 	 * the regulatory allowed power level
177f1285519SAdrian Chadd 	 */
178f1285519SAdrian Chadd 	scaledPower = AH_MIN(powerLimit, twiceMaxRegulatoryPower + twiceLargestAntenna);
179f1285519SAdrian Chadd 
180f1285519SAdrian Chadd 	/* Reduce scaled Power by number of chains active to get to per chain tx power level */
181f1285519SAdrian Chadd 	/* TODO: better value than these? */
182f1285519SAdrian Chadd 	switch (owl_get_ntxchains(AH5416(ah)->ah_tx_chainmask)) {
183f1285519SAdrian Chadd 	case 1:
184f1285519SAdrian Chadd 		break;
185f1285519SAdrian Chadd 	case 2:
186f1285519SAdrian Chadd 		scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN;
187133cf74bSAdrian Chadd 		break;
188f1285519SAdrian Chadd 	default:
189f1285519SAdrian Chadd 		return AH_FALSE; /* Unsupported number of chains */
190ea18ed26SAdrian Chadd 	}
191ea18ed26SAdrian Chadd 
192f1285519SAdrian Chadd 	scaledPower = AH_MAX(0, scaledPower);
193f1285519SAdrian Chadd 
194f1285519SAdrian Chadd 	/* Get target powers from EEPROM - our baseline for TX Power */
195f1285519SAdrian Chadd 	/* XXX assume channel is 2ghz */
196f1285519SAdrian Chadd 	if (1) {
197f1285519SAdrian Chadd 		/* Setup for CTL modes */
198f1285519SAdrian Chadd 		numCtlModes = N(ctlModesFor11g) - SUB_NUM_CTL_MODES_AT_2G_40; /* CTL_11B, CTL_11G, CTL_2GHT20 */
199f1285519SAdrian Chadd 		pCtlMode = ctlModesFor11g;
200f1285519SAdrian Chadd 
201f1285519SAdrian Chadd 		ar5416GetTargetPowersLeg(ah,  chan, pEepData->calTargetPowerCck,
202f1285519SAdrian Chadd 				AR9287_NUM_2G_CCK_TARGET_POWERS, &targetPowerCck, 4, AH_FALSE);
203f1285519SAdrian Chadd 		ar5416GetTargetPowersLeg(ah,  chan, pEepData->calTargetPower2G,
204f1285519SAdrian Chadd 				AR9287_NUM_2G_20_TARGET_POWERS, &targetPowerOfdm, 4, AH_FALSE);
205f1285519SAdrian Chadd 		ar5416GetTargetPowers(ah,  chan, pEepData->calTargetPower2GHT20,
206f1285519SAdrian Chadd 				AR9287_NUM_2G_20_TARGET_POWERS, &targetPowerHt20, 8, AH_FALSE);
207f1285519SAdrian Chadd 
208f1285519SAdrian Chadd 		if (IEEE80211_IS_CHAN_HT40(chan)) {
209f1285519SAdrian Chadd 			numCtlModes = N(ctlModesFor11g);    /* All 2G CTL's */
210f1285519SAdrian Chadd 
211f1285519SAdrian Chadd 			ar5416GetTargetPowers(ah,  chan, pEepData->calTargetPower2GHT40,
212f1285519SAdrian Chadd 				AR9287_NUM_2G_40_TARGET_POWERS, &targetPowerHt40, 8, AH_TRUE);
213f1285519SAdrian Chadd 			/* Get target powers for extension channels */
214f1285519SAdrian Chadd 			ar5416GetTargetPowersLeg(ah,  chan, pEepData->calTargetPowerCck,
215f1285519SAdrian Chadd 				AR9287_NUM_2G_CCK_TARGET_POWERS, &targetPowerCckExt, 4, AH_TRUE);
216f1285519SAdrian Chadd 			ar5416GetTargetPowersLeg(ah,  chan, pEepData->calTargetPower2G,
217f1285519SAdrian Chadd 				AR9287_NUM_2G_20_TARGET_POWERS, &targetPowerOfdmExt, 4, AH_TRUE);
218f1285519SAdrian Chadd 		}
219f1285519SAdrian Chadd 	}
220f1285519SAdrian Chadd 
221f1285519SAdrian Chadd 	/*
222f1285519SAdrian Chadd 	 * For MIMO, need to apply regulatory caps individually across dynamically
223f1285519SAdrian Chadd 	 * running modes: CCK, OFDM, HT20, HT40
224f1285519SAdrian Chadd 	 *
225f1285519SAdrian Chadd 	 * The outer loop walks through each possible applicable runtime mode.
226f1285519SAdrian Chadd 	 * The inner loop walks through each ctlIndex entry in EEPROM.
227f1285519SAdrian Chadd 	 * The ctl value is encoded as [7:4] == test group, [3:0] == test mode.
228f1285519SAdrian Chadd 	 *
229f1285519SAdrian Chadd 	 */
230f1285519SAdrian Chadd 	for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
231f1285519SAdrian Chadd 		HAL_BOOL isHt40CtlMode = (pCtlMode[ctlMode] == CTL_5GHT40) ||
232f1285519SAdrian Chadd 		    (pCtlMode[ctlMode] == CTL_2GHT40);
233f1285519SAdrian Chadd 		if (isHt40CtlMode) {
234f1285519SAdrian Chadd 			freq = centers.ctl_center;
235f1285519SAdrian Chadd 		} else if (pCtlMode[ctlMode] & EXT_ADDITIVE) {
236f1285519SAdrian Chadd 			freq = centers.ext_center;
237f1285519SAdrian Chadd 		} else {
238f1285519SAdrian Chadd 			freq = centers.ctl_center;
239f1285519SAdrian Chadd 		}
240f1285519SAdrian Chadd 
241f1285519SAdrian Chadd 		/* walk through each CTL index stored in EEPROM */
242f1285519SAdrian Chadd 		for (i = 0; (i < AR9287_NUM_CTLS) && pEepData->ctlIndex[i]; i++) {
243f1285519SAdrian Chadd 			uint16_t twiceMinEdgePower;
244f1285519SAdrian Chadd 
245f1285519SAdrian Chadd 			/* compare test group from regulatory channel list with test mode from pCtlMode list */
246f1285519SAdrian Chadd 			if ((((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == pEepData->ctlIndex[i]) ||
247f1285519SAdrian Chadd 				(((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) ==
248f1285519SAdrian Chadd 				 ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL))) {
249f1285519SAdrian Chadd 				rep = &(pEepData->ctlData[i]);
250f1285519SAdrian Chadd 				twiceMinEdgePower = ar5416GetMaxEdgePower(freq,
251f1285519SAdrian Chadd 							rep->ctlEdges[owl_get_ntxchains(AH5416(ah)->ah_tx_chainmask) - 1],
252f1285519SAdrian Chadd 							IEEE80211_IS_CHAN_2GHZ(chan));
253f1285519SAdrian Chadd 				if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {
254f1285519SAdrian Chadd 					/* Find the minimum of all CTL edge powers that apply to this channel */
255f1285519SAdrian Chadd 					twiceMaxEdgePower = AH_MIN(twiceMaxEdgePower, twiceMinEdgePower);
256f1285519SAdrian Chadd 				} else {
257f1285519SAdrian Chadd 					/* specific */
258f1285519SAdrian Chadd 					twiceMaxEdgePower = twiceMinEdgePower;
259f1285519SAdrian Chadd 					break;
260f1285519SAdrian Chadd 				}
261f1285519SAdrian Chadd 			}
262f1285519SAdrian Chadd 		}
263f1285519SAdrian Chadd 		minCtlPower = (uint8_t)AH_MIN(twiceMaxEdgePower, scaledPower);
264f1285519SAdrian Chadd 		/* Apply ctl mode to correct target power set */
265f1285519SAdrian Chadd 		switch(pCtlMode[ctlMode]) {
266f1285519SAdrian Chadd 		case CTL_11B:
267f1285519SAdrian Chadd 			for (i = 0; i < N(targetPowerCck.tPow2x); i++) {
268f1285519SAdrian Chadd 				targetPowerCck.tPow2x[i] = (uint8_t)AH_MIN(targetPowerCck.tPow2x[i], minCtlPower);
269f1285519SAdrian Chadd 			}
270f1285519SAdrian Chadd 			break;
271f1285519SAdrian Chadd 		case CTL_11A:
272f1285519SAdrian Chadd 		case CTL_11G:
273f1285519SAdrian Chadd 			for (i = 0; i < N(targetPowerOfdm.tPow2x); i++) {
274f1285519SAdrian Chadd 				targetPowerOfdm.tPow2x[i] = (uint8_t)AH_MIN(targetPowerOfdm.tPow2x[i], minCtlPower);
275f1285519SAdrian Chadd 			}
276f1285519SAdrian Chadd 			break;
277f1285519SAdrian Chadd 		case CTL_5GHT20:
278f1285519SAdrian Chadd 		case CTL_2GHT20:
279f1285519SAdrian Chadd 			for (i = 0; i < N(targetPowerHt20.tPow2x); i++) {
280f1285519SAdrian Chadd 				targetPowerHt20.tPow2x[i] = (uint8_t)AH_MIN(targetPowerHt20.tPow2x[i], minCtlPower);
281f1285519SAdrian Chadd 			}
282f1285519SAdrian Chadd 			break;
283f1285519SAdrian Chadd 		case CTL_11B_EXT:
284f1285519SAdrian Chadd 			targetPowerCckExt.tPow2x[0] = (uint8_t)AH_MIN(targetPowerCckExt.tPow2x[0], minCtlPower);
285f1285519SAdrian Chadd 			break;
286f1285519SAdrian Chadd 		case CTL_11A_EXT:
287f1285519SAdrian Chadd 		case CTL_11G_EXT:
288f1285519SAdrian Chadd 			targetPowerOfdmExt.tPow2x[0] = (uint8_t)AH_MIN(targetPowerOfdmExt.tPow2x[0], minCtlPower);
289f1285519SAdrian Chadd 			break;
290f1285519SAdrian Chadd 		case CTL_5GHT40:
291f1285519SAdrian Chadd 		case CTL_2GHT40:
292f1285519SAdrian Chadd 			for (i = 0; i < N(targetPowerHt40.tPow2x); i++) {
293f1285519SAdrian Chadd 				targetPowerHt40.tPow2x[i] = (uint8_t)AH_MIN(targetPowerHt40.tPow2x[i], minCtlPower);
294f1285519SAdrian Chadd 			}
295f1285519SAdrian Chadd 			break;
296f1285519SAdrian Chadd 		default:
297f1285519SAdrian Chadd 			return AH_FALSE;
298f1285519SAdrian Chadd 			break;
299f1285519SAdrian Chadd 		}
300f1285519SAdrian Chadd 	} /* end ctl mode checking */
301f1285519SAdrian Chadd 
302f1285519SAdrian Chadd 	/* Set rates Array from collected data */
303f1285519SAdrian Chadd 	ar5416SetRatesArrayFromTargetPower(ah, chan, ratesArray,
304f1285519SAdrian Chadd 	    &targetPowerCck,
305f1285519SAdrian Chadd 	    &targetPowerCckExt,
306f1285519SAdrian Chadd 	    &targetPowerOfdm,
307f1285519SAdrian Chadd 	    &targetPowerOfdmExt,
308f1285519SAdrian Chadd 	    &targetPowerHt20,
309f1285519SAdrian Chadd 	    &targetPowerHt40);
310f1285519SAdrian Chadd 	return AH_TRUE;
311f1285519SAdrian Chadd #undef EXT_ADDITIVE
312f1285519SAdrian Chadd #undef CTL_11A_EXT
313f1285519SAdrian Chadd #undef CTL_11G_EXT
314f1285519SAdrian Chadd #undef CTL_11B_EXT
315f1285519SAdrian Chadd #undef SUB_NUM_CTL_MODES_AT_5G_40
316f1285519SAdrian Chadd #undef SUB_NUM_CTL_MODES_AT_2G_40
317f1285519SAdrian Chadd #undef N
318f1285519SAdrian Chadd }
319f1285519SAdrian Chadd 
320f1285519SAdrian Chadd #undef REDUCE_SCALED_POWER_BY_TWO_CHAIN
321f1285519SAdrian Chadd 
322ea18ed26SAdrian Chadd /*
323ea18ed26SAdrian Chadd  * This is based off of the AR5416/AR9285 code and likely could
324ea18ed26SAdrian Chadd  * be unified in the future.
325ea18ed26SAdrian Chadd  */
326d8daa2e3SAdrian Chadd HAL_BOOL
ar9287SetTransmitPower(struct ath_hal * ah,const struct ieee80211_channel * chan,uint16_t * rfXpdGain)327d8daa2e3SAdrian Chadd ar9287SetTransmitPower(struct ath_hal *ah,
328d8daa2e3SAdrian Chadd 	const struct ieee80211_channel *chan, uint16_t *rfXpdGain)
329d8daa2e3SAdrian Chadd {
330ea18ed26SAdrian Chadd #define	POW_SM(_r, _s)     (((_r) & 0x3f) << (_s))
331ea18ed26SAdrian Chadd #define	N(a)	    (sizeof (a) / sizeof (a[0]))
3324551052dSAdrian Chadd 
333ea18ed26SAdrian Chadd 	const struct modal_eep_ar9287_header *pModal;
334ea18ed26SAdrian Chadd 	struct ath_hal_5212 *ahp = AH5212(ah);
335ea18ed26SAdrian Chadd 	int16_t	     txPowerIndexOffset = 0;
336ea18ed26SAdrian Chadd 	int		 i;
337ea18ed26SAdrian Chadd 
338ea18ed26SAdrian Chadd 	uint16_t	    cfgCtl;
339ea18ed26SAdrian Chadd 	uint16_t	    powerLimit;
340ea18ed26SAdrian Chadd 	uint16_t	    twiceAntennaReduction;
341ea18ed26SAdrian Chadd 	uint16_t	    twiceMaxRegulatoryPower;
342ea18ed26SAdrian Chadd 	int16_t	     maxPower;
343ea18ed26SAdrian Chadd 	HAL_EEPROM_9287 *ee = AH_PRIVATE(ah)->ah_eeprom;
344ea18ed26SAdrian Chadd 	struct ar9287_eeprom *pEepData = &ee->ee_base;
345ea18ed26SAdrian Chadd 
34691046e9cSAdrian Chadd 	AH5416(ah)->ah_ht40PowerIncForPdadc = 2;
34791046e9cSAdrian Chadd 
348ea18ed26SAdrian Chadd 	/* Setup info for the actual eeprom */
34991046e9cSAdrian Chadd 	OS_MEMZERO(AH5416(ah)->ah_ratesArray,
35091046e9cSAdrian Chadd 	  sizeof(AH5416(ah)->ah_ratesArray));
351ea18ed26SAdrian Chadd 	cfgCtl = ath_hal_getctl(ah, chan);
352ea18ed26SAdrian Chadd 	powerLimit = chan->ic_maxregpower * 2;
353ea18ed26SAdrian Chadd 	twiceAntennaReduction = chan->ic_maxantgain;
3543acbfe72SAdrian Chadd 	twiceMaxRegulatoryPower = AH_MIN(MAX_RATE_POWER,
3553acbfe72SAdrian Chadd 	    AH_PRIVATE(ah)->ah_powerLimit);
356ea18ed26SAdrian Chadd 	pModal = &pEepData->modalHeader;
357ea18ed26SAdrian Chadd 	HALDEBUG(ah, HAL_DEBUG_RESET, "%s Channel=%u CfgCtl=%u\n",
358ea18ed26SAdrian Chadd 	    __func__,chan->ic_freq, cfgCtl );
359ea18ed26SAdrian Chadd 
360ea18ed26SAdrian Chadd 	/* XXX Assume Minor is v2 or later */
36191046e9cSAdrian Chadd 	AH5416(ah)->ah_ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
3624551052dSAdrian Chadd 
3634551052dSAdrian Chadd 	/* Fetch per-rate power table for the given channel */
364f1285519SAdrian Chadd 	if (! ar9287SetPowerPerRateTable(ah, pEepData,  chan,
36591046e9cSAdrian Chadd 	    &AH5416(ah)->ah_ratesArray[0],
36691046e9cSAdrian Chadd 	    cfgCtl,
367ea18ed26SAdrian Chadd 	    twiceAntennaReduction,
368ea18ed26SAdrian Chadd 	    twiceMaxRegulatoryPower, powerLimit)) {
369ea18ed26SAdrian Chadd 		HALDEBUG(ah, HAL_DEBUG_ANY,
370ea18ed26SAdrian Chadd 		    "%s: unable to set tx power per rate table\n", __func__);
371ea18ed26SAdrian Chadd 		return AH_FALSE;
372ea18ed26SAdrian Chadd 	}
3734551052dSAdrian Chadd 
374ea18ed26SAdrian Chadd 	/* Set TX power control calibration curves for each TX chain */
3754551052dSAdrian Chadd 	ar9287SetPowerCalTable(ah, chan, &txPowerIndexOffset);
3764551052dSAdrian Chadd 
377ea18ed26SAdrian Chadd 	/* Calculate maximum power level */
37891046e9cSAdrian Chadd 	maxPower = AH_MAX(AH5416(ah)->ah_ratesArray[rate6mb],
37991046e9cSAdrian Chadd 	    AH5416(ah)->ah_ratesArray[rateHt20_0]);
38091046e9cSAdrian Chadd 	maxPower = AH_MAX(maxPower,
38191046e9cSAdrian Chadd 	    AH5416(ah)->ah_ratesArray[rate1l]);
3824551052dSAdrian Chadd 
383ea18ed26SAdrian Chadd 	if (IEEE80211_IS_CHAN_HT40(chan))
38491046e9cSAdrian Chadd 		maxPower = AH_MAX(maxPower,
38591046e9cSAdrian Chadd 		    AH5416(ah)->ah_ratesArray[rateHt40_0]);
3864551052dSAdrian Chadd 
387ea18ed26SAdrian Chadd 	ahp->ah_tx6PowerInHalfDbm = maxPower;
388ea18ed26SAdrian Chadd 	AH_PRIVATE(ah)->ah_maxPowerLevel = maxPower;
389ea18ed26SAdrian Chadd 	ahp->ah_txPowerIndexOffset = txPowerIndexOffset;
390ea18ed26SAdrian Chadd 
391ea18ed26SAdrian Chadd 	/*
392ea18ed26SAdrian Chadd 	 * txPowerIndexOffset is set by the SetPowerTable() call -
393ea18ed26SAdrian Chadd 	 *  adjust the rate table (0 offset if rates EEPROM not loaded)
394ea18ed26SAdrian Chadd 	 */
395ea18ed26SAdrian Chadd 	/* XXX what about the pwrTableOffset? */
39691046e9cSAdrian Chadd 	for (i = 0; i < N(AH5416(ah)->ah_ratesArray); i++) {
39791046e9cSAdrian Chadd 		AH5416(ah)->ah_ratesArray[i] =
39891046e9cSAdrian Chadd 		    (int16_t)(txPowerIndexOffset +
39991046e9cSAdrian Chadd 		      AH5416(ah)->ah_ratesArray[i]);
400ea18ed26SAdrian Chadd 		/* -5 dBm offset for Merlin and later; this includes Kiwi */
40191046e9cSAdrian Chadd 		AH5416(ah)->ah_ratesArray[i] -= AR5416_PWR_TABLE_OFFSET_DB * 2;
40291046e9cSAdrian Chadd 		if (AH5416(ah)->ah_ratesArray[i] > AR5416_MAX_RATE_POWER)
40391046e9cSAdrian Chadd 			AH5416(ah)->ah_ratesArray[i] = AR5416_MAX_RATE_POWER;
40491046e9cSAdrian Chadd 		if (AH5416(ah)->ah_ratesArray[i] < 0)
40591046e9cSAdrian Chadd 			AH5416(ah)->ah_ratesArray[i] = 0;
406ea18ed26SAdrian Chadd 	}
407ea18ed26SAdrian Chadd 
408ea18ed26SAdrian Chadd #ifdef AH_EEPROM_DUMP
40991046e9cSAdrian Chadd 	ar5416PrintPowerPerRate(ah, AH5416(ah)->ah_ratesArray);
410ea18ed26SAdrian Chadd #endif
411ea18ed26SAdrian Chadd 
412ea18ed26SAdrian Chadd 	/*
413ea18ed26SAdrian Chadd 	 * Adjust the HT40 power to meet the correct target TX power
414ea18ed26SAdrian Chadd 	 * for 40MHz mode, based on TX power curves that are established
415ea18ed26SAdrian Chadd 	 * for 20MHz mode.
416ea18ed26SAdrian Chadd 	 *
417ea18ed26SAdrian Chadd 	 * XXX handle overflow/too high power level?
418ea18ed26SAdrian Chadd 	 */
419ea18ed26SAdrian Chadd 	if (IEEE80211_IS_CHAN_HT40(chan)) {
42091046e9cSAdrian Chadd 		AH5416(ah)->ah_ratesArray[rateHt40_0] +=
42191046e9cSAdrian Chadd 		  AH5416(ah)->ah_ht40PowerIncForPdadc;
42291046e9cSAdrian Chadd 		AH5416(ah)->ah_ratesArray[rateHt40_1] +=
42391046e9cSAdrian Chadd 		  AH5416(ah)->ah_ht40PowerIncForPdadc;
42491046e9cSAdrian Chadd 		AH5416(ah)->ah_ratesArray[rateHt40_2] +=
42591046e9cSAdrian Chadd 		  AH5416(ah)->ah_ht40PowerIncForPdadc;
42691046e9cSAdrian Chadd 		AH5416(ah)->ah_ratesArray[rateHt40_3] +=
42791046e9cSAdrian Chadd 		  AH5416(ah)->ah_ht40PowerIncForPdadc;
42891046e9cSAdrian Chadd 		AH5416(ah)->ah_ratesArray[rateHt40_4] +=
42991046e9cSAdrian Chadd 		  AH5416(ah)->ah_ht40PowerIncForPdadc;
43091046e9cSAdrian Chadd 		AH5416(ah)->ah_ratesArray[rateHt40_5] +=
43191046e9cSAdrian Chadd 		  AH5416(ah)->ah_ht40PowerIncForPdadc;
43291046e9cSAdrian Chadd 		AH5416(ah)->ah_ratesArray[rateHt40_6] +=
43391046e9cSAdrian Chadd 		  AH5416(ah)->ah_ht40PowerIncForPdadc;
43491046e9cSAdrian Chadd 		AH5416(ah)->ah_ratesArray[rateHt40_7] +=
43591046e9cSAdrian Chadd 		  AH5416(ah)->ah_ht40PowerIncForPdadc;
436ea18ed26SAdrian Chadd 	}
437ea18ed26SAdrian Chadd 
438ea18ed26SAdrian Chadd 	/* Write the TX power rate registers */
43991046e9cSAdrian Chadd 	ar5416WriteTxPowerRateRegisters(ah, chan, AH5416(ah)->ah_ratesArray);
4404551052dSAdrian Chadd 
441d8daa2e3SAdrian Chadd 	return AH_TRUE;
442ea18ed26SAdrian Chadd #undef POW_SM
443ea18ed26SAdrian Chadd #undef N
444d8daa2e3SAdrian Chadd }
445d8daa2e3SAdrian Chadd 
446d8daa2e3SAdrian Chadd /*
447d8daa2e3SAdrian Chadd  * Read EEPROM header info and program the device for correct operation
448d8daa2e3SAdrian Chadd  * given the channel value.
449d8daa2e3SAdrian Chadd  */
450d8daa2e3SAdrian Chadd HAL_BOOL
ar9287SetBoardValues(struct ath_hal * ah,const struct ieee80211_channel * chan)451d8daa2e3SAdrian Chadd ar9287SetBoardValues(struct ath_hal *ah, const struct ieee80211_channel *chan)
452d8daa2e3SAdrian Chadd {
453d8daa2e3SAdrian Chadd 	const HAL_EEPROM_9287 *ee = AH_PRIVATE(ah)->ah_eeprom;
454d8daa2e3SAdrian Chadd 	const struct ar9287_eeprom *eep = &ee->ee_base;
455d8daa2e3SAdrian Chadd 	const struct modal_eep_ar9287_header *pModal = &eep->modalHeader;
456d8daa2e3SAdrian Chadd 	uint16_t antWrites[AR9287_ANT_16S];
457d8daa2e3SAdrian Chadd 	uint32_t regChainOffset, regval;
458d8daa2e3SAdrian Chadd 	uint8_t txRxAttenLocal;
459d8daa2e3SAdrian Chadd 	int i, j, offset_num;
460d8daa2e3SAdrian Chadd 
461d8daa2e3SAdrian Chadd 	pModal = &eep->modalHeader;
462d8daa2e3SAdrian Chadd 
463d8daa2e3SAdrian Chadd 	antWrites[0] = (uint16_t)((pModal->antCtrlCommon >> 28) & 0xF);
464d8daa2e3SAdrian Chadd 	antWrites[1] = (uint16_t)((pModal->antCtrlCommon >> 24) & 0xF);
465d8daa2e3SAdrian Chadd 	antWrites[2] = (uint16_t)((pModal->antCtrlCommon >> 20) & 0xF);
466d8daa2e3SAdrian Chadd 	antWrites[3] = (uint16_t)((pModal->antCtrlCommon >> 16) & 0xF);
467d8daa2e3SAdrian Chadd 	antWrites[4] = (uint16_t)((pModal->antCtrlCommon >> 12) & 0xF);
468d8daa2e3SAdrian Chadd 	antWrites[5] = (uint16_t)((pModal->antCtrlCommon >> 8) & 0xF);
469d8daa2e3SAdrian Chadd 	antWrites[6] = (uint16_t)((pModal->antCtrlCommon >> 4)  & 0xF);
470d8daa2e3SAdrian Chadd 	antWrites[7] = (uint16_t)(pModal->antCtrlCommon & 0xF);
471d8daa2e3SAdrian Chadd 
472d8daa2e3SAdrian Chadd 	offset_num = 8;
473d8daa2e3SAdrian Chadd 
474d8daa2e3SAdrian Chadd 	for (i = 0, j = offset_num; i < AR9287_MAX_CHAINS; i++) {
475d8daa2e3SAdrian Chadd 		antWrites[j++] = (uint16_t)((pModal->antCtrlChain[i] >> 28) & 0xf);
476d8daa2e3SAdrian Chadd 		antWrites[j++] = (uint16_t)((pModal->antCtrlChain[i] >> 10) & 0x3);
477d8daa2e3SAdrian Chadd 		antWrites[j++] = (uint16_t)((pModal->antCtrlChain[i] >> 8) & 0x3);
478d8daa2e3SAdrian Chadd 		antWrites[j++] = 0;
479d8daa2e3SAdrian Chadd 		antWrites[j++] = (uint16_t)((pModal->antCtrlChain[i] >> 6) & 0x3);
480d8daa2e3SAdrian Chadd 		antWrites[j++] = (uint16_t)((pModal->antCtrlChain[i] >> 4) & 0x3);
481d8daa2e3SAdrian Chadd 		antWrites[j++] = (uint16_t)((pModal->antCtrlChain[i] >> 2) & 0x3);
482d8daa2e3SAdrian Chadd 		antWrites[j++] = (uint16_t)(pModal->antCtrlChain[i] & 0x3);
483d8daa2e3SAdrian Chadd 	}
484d8daa2e3SAdrian Chadd 
485d8daa2e3SAdrian Chadd 	OS_REG_WRITE(ah, AR_PHY_SWITCH_COM, pModal->antCtrlCommon);
486d8daa2e3SAdrian Chadd 
487d8daa2e3SAdrian Chadd 	for (i = 0; i < AR9287_MAX_CHAINS; i++)	{
488d8daa2e3SAdrian Chadd 		regChainOffset = i * 0x1000;
489d8daa2e3SAdrian Chadd 
490d8daa2e3SAdrian Chadd 		OS_REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
491d8daa2e3SAdrian Chadd 			  pModal->antCtrlChain[i]);
492d8daa2e3SAdrian Chadd 
493d8daa2e3SAdrian Chadd 		OS_REG_WRITE(ah, AR_PHY_TIMING_CTRL4_CHAIN(0) + regChainOffset,
4943acbfe72SAdrian Chadd 			  (OS_REG_READ(ah, AR_PHY_TIMING_CTRL4_CHAIN(0)
4953acbfe72SAdrian Chadd 			      + regChainOffset)
496d8daa2e3SAdrian Chadd 			   & ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
497d8daa2e3SAdrian Chadd 			       AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
498d8daa2e3SAdrian Chadd 			  SM(pModal->iqCalICh[i],
499d8daa2e3SAdrian Chadd 			     AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
500d8daa2e3SAdrian Chadd 			  SM(pModal->iqCalQCh[i],
501d8daa2e3SAdrian Chadd 			     AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
502d8daa2e3SAdrian Chadd 
503d8daa2e3SAdrian Chadd 		txRxAttenLocal = pModal->txRxAttenCh[i];
504d8daa2e3SAdrian Chadd 
505d8daa2e3SAdrian Chadd 		OS_REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
506d8daa2e3SAdrian Chadd 			      AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN,
507d8daa2e3SAdrian Chadd 			      pModal->bswMargin[i]);
508d8daa2e3SAdrian Chadd 		OS_REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
509d8daa2e3SAdrian Chadd 			      AR_PHY_GAIN_2GHZ_XATTEN1_DB,
510d8daa2e3SAdrian Chadd 			      pModal->bswAtten[i]);
511d8daa2e3SAdrian Chadd 		OS_REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
512d8daa2e3SAdrian Chadd 			      AR9280_PHY_RXGAIN_TXRX_ATTEN,
513d8daa2e3SAdrian Chadd 			      txRxAttenLocal);
514d8daa2e3SAdrian Chadd 		OS_REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
515d8daa2e3SAdrian Chadd 			      AR9280_PHY_RXGAIN_TXRX_MARGIN,
516d8daa2e3SAdrian Chadd 			      pModal->rxTxMarginCh[i]);
517d8daa2e3SAdrian Chadd 	}
518d8daa2e3SAdrian Chadd 
519d8daa2e3SAdrian Chadd 	if (IEEE80211_IS_CHAN_HT40(chan))
520d8daa2e3SAdrian Chadd 		OS_REG_RMW_FIELD(ah, AR_PHY_SETTLING,
521d8daa2e3SAdrian Chadd 			      AR_PHY_SETTLING_SWITCH, pModal->swSettleHt40);
522d8daa2e3SAdrian Chadd 	else
523d8daa2e3SAdrian Chadd 		OS_REG_RMW_FIELD(ah, AR_PHY_SETTLING,
524d8daa2e3SAdrian Chadd 			      AR_PHY_SETTLING_SWITCH, pModal->switchSettling);
525d8daa2e3SAdrian Chadd 
526d8daa2e3SAdrian Chadd 	OS_REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
527d8daa2e3SAdrian Chadd 		      AR_PHY_DESIRED_SZ_ADC, pModal->adcDesiredSize);
528d8daa2e3SAdrian Chadd 
529d8daa2e3SAdrian Chadd 	OS_REG_WRITE(ah, AR_PHY_RF_CTL4,
530d8daa2e3SAdrian Chadd 		  SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF)
531d8daa2e3SAdrian Chadd 		  | SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAB_OFF)
532d8daa2e3SAdrian Chadd 		  | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAA_ON)
533d8daa2e3SAdrian Chadd 		  | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAB_ON));
534d8daa2e3SAdrian Chadd 
535d8daa2e3SAdrian Chadd 	OS_REG_RMW_FIELD(ah, AR_PHY_RF_CTL3,
536d8daa2e3SAdrian Chadd 		      AR_PHY_TX_END_TO_A2_RX_ON, pModal->txEndToRxOn);
537d8daa2e3SAdrian Chadd 
538d8daa2e3SAdrian Chadd 	OS_REG_RMW_FIELD(ah, AR_PHY_CCA,
539d8daa2e3SAdrian Chadd 		      AR9280_PHY_CCA_THRESH62, pModal->thresh62);
540d8daa2e3SAdrian Chadd 	OS_REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0,
541d8daa2e3SAdrian Chadd 		      AR_PHY_EXT_CCA0_THRESH62, pModal->thresh62);
542d8daa2e3SAdrian Chadd 
543d8daa2e3SAdrian Chadd 	regval = OS_REG_READ(ah, AR9287_AN_RF2G3_CH0);
544d8daa2e3SAdrian Chadd 	regval &= ~(AR9287_AN_RF2G3_DB1 |
545d8daa2e3SAdrian Chadd 		    AR9287_AN_RF2G3_DB2 |
546d8daa2e3SAdrian Chadd 		    AR9287_AN_RF2G3_OB_CCK |
547d8daa2e3SAdrian Chadd 		    AR9287_AN_RF2G3_OB_PSK |
548d8daa2e3SAdrian Chadd 		    AR9287_AN_RF2G3_OB_QAM |
549d8daa2e3SAdrian Chadd 		    AR9287_AN_RF2G3_OB_PAL_OFF);
550d8daa2e3SAdrian Chadd 	regval |= (SM(pModal->db1, AR9287_AN_RF2G3_DB1) |
551d8daa2e3SAdrian Chadd 		   SM(pModal->db2, AR9287_AN_RF2G3_DB2) |
552d8daa2e3SAdrian Chadd 		   SM(pModal->ob_cck, AR9287_AN_RF2G3_OB_CCK) |
553d8daa2e3SAdrian Chadd 		   SM(pModal->ob_psk, AR9287_AN_RF2G3_OB_PSK) |
554d8daa2e3SAdrian Chadd 		   SM(pModal->ob_qam, AR9287_AN_RF2G3_OB_QAM) |
555d8daa2e3SAdrian Chadd 		   SM(pModal->ob_pal_off, AR9287_AN_RF2G3_OB_PAL_OFF));
556d8daa2e3SAdrian Chadd 
5573acbfe72SAdrian Chadd 	/* Analog write - requires a 100usec delay */
5583acbfe72SAdrian Chadd 	OS_A_REG_WRITE(ah, AR9287_AN_RF2G3_CH0, regval);
559d8daa2e3SAdrian Chadd 
560d8daa2e3SAdrian Chadd 	regval = OS_REG_READ(ah, AR9287_AN_RF2G3_CH1);
561d8daa2e3SAdrian Chadd 	regval &= ~(AR9287_AN_RF2G3_DB1 |
562d8daa2e3SAdrian Chadd 		    AR9287_AN_RF2G3_DB2 |
563d8daa2e3SAdrian Chadd 		    AR9287_AN_RF2G3_OB_CCK |
564d8daa2e3SAdrian Chadd 		    AR9287_AN_RF2G3_OB_PSK |
565d8daa2e3SAdrian Chadd 		    AR9287_AN_RF2G3_OB_QAM |
566d8daa2e3SAdrian Chadd 		    AR9287_AN_RF2G3_OB_PAL_OFF);
567d8daa2e3SAdrian Chadd 	regval |= (SM(pModal->db1, AR9287_AN_RF2G3_DB1) |
568d8daa2e3SAdrian Chadd 		   SM(pModal->db2, AR9287_AN_RF2G3_DB2) |
569d8daa2e3SAdrian Chadd 		   SM(pModal->ob_cck, AR9287_AN_RF2G3_OB_CCK) |
570d8daa2e3SAdrian Chadd 		   SM(pModal->ob_psk, AR9287_AN_RF2G3_OB_PSK) |
571d8daa2e3SAdrian Chadd 		   SM(pModal->ob_qam, AR9287_AN_RF2G3_OB_QAM) |
572d8daa2e3SAdrian Chadd 		   SM(pModal->ob_pal_off, AR9287_AN_RF2G3_OB_PAL_OFF));
573d8daa2e3SAdrian Chadd 
5743acbfe72SAdrian Chadd 	OS_A_REG_WRITE(ah, AR9287_AN_RF2G3_CH1, regval);
575d8daa2e3SAdrian Chadd 
576d8daa2e3SAdrian Chadd 	OS_REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
577d8daa2e3SAdrian Chadd 	    AR_PHY_TX_FRAME_TO_DATA_START, pModal->txFrameToDataStart);
578d8daa2e3SAdrian Chadd 	OS_REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
579d8daa2e3SAdrian Chadd 	    AR_PHY_TX_FRAME_TO_PA_ON, pModal->txFrameToPaOn);
580d8daa2e3SAdrian Chadd 
581d8daa2e3SAdrian Chadd 	OS_A_REG_RMW_FIELD(ah, AR9287_AN_TOP2,
582d8daa2e3SAdrian Chadd 	    AR9287_AN_TOP2_XPABIAS_LVL, pModal->xpaBiasLvl);
583d8daa2e3SAdrian Chadd 
584d8daa2e3SAdrian Chadd 	return AH_TRUE;
585d8daa2e3SAdrian Chadd }
586