xref: /dflybsd-src/sys/dev/netif/ath/ath_hal/ar9002/ar9287_reset.c (revision 572ff6f6e8b95055988f178b6ba12ce77bb5b3c2)
1*572ff6f6SMatthew Dillon /*
2*572ff6f6SMatthew Dillon  * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
3*572ff6f6SMatthew Dillon  * Copyright (c) 2002-2008 Atheros Communications, Inc.
4*572ff6f6SMatthew Dillon  *
5*572ff6f6SMatthew Dillon  * Permission to use, copy, modify, and/or distribute this software for any
6*572ff6f6SMatthew Dillon  * purpose with or without fee is hereby granted, provided that the above
7*572ff6f6SMatthew Dillon  * copyright notice and this permission notice appear in all copies.
8*572ff6f6SMatthew Dillon  *
9*572ff6f6SMatthew Dillon  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10*572ff6f6SMatthew Dillon  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11*572ff6f6SMatthew Dillon  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12*572ff6f6SMatthew Dillon  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13*572ff6f6SMatthew Dillon  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14*572ff6f6SMatthew Dillon  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15*572ff6f6SMatthew Dillon  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16*572ff6f6SMatthew Dillon  *
17*572ff6f6SMatthew Dillon  * $FreeBSD$
18*572ff6f6SMatthew Dillon  */
19*572ff6f6SMatthew Dillon 
20*572ff6f6SMatthew Dillon #include "opt_ah.h"
21*572ff6f6SMatthew Dillon 
22*572ff6f6SMatthew Dillon #include "ah.h"
23*572ff6f6SMatthew Dillon #include "ah_internal.h"
24*572ff6f6SMatthew Dillon #include "ah_devid.h"
25*572ff6f6SMatthew Dillon 
26*572ff6f6SMatthew Dillon #include "ah_eeprom_v14.h"
27*572ff6f6SMatthew Dillon #include "ah_eeprom_9287.h"
28*572ff6f6SMatthew Dillon 
29*572ff6f6SMatthew Dillon #include "ar5416/ar5416.h"
30*572ff6f6SMatthew Dillon #include "ar5416/ar5416reg.h"
31*572ff6f6SMatthew Dillon #include "ar5416/ar5416phy.h"
32*572ff6f6SMatthew Dillon 
33*572ff6f6SMatthew Dillon #include "ar9002/ar9287phy.h"
34*572ff6f6SMatthew Dillon #include "ar9002/ar9287an.h"
35*572ff6f6SMatthew Dillon 
36*572ff6f6SMatthew Dillon #include "ar9002/ar9287_olc.h"
37*572ff6f6SMatthew Dillon #include "ar9002/ar9287_reset.h"
38*572ff6f6SMatthew Dillon 
39*572ff6f6SMatthew Dillon /*
40*572ff6f6SMatthew Dillon  * Set the TX power calibration table per-chain.
41*572ff6f6SMatthew Dillon  *
42*572ff6f6SMatthew Dillon  * This only supports open-loop TX power control for the AR9287.
43*572ff6f6SMatthew Dillon  */
44*572ff6f6SMatthew Dillon static void
ar9287SetPowerCalTable(struct ath_hal * ah,const struct ieee80211_channel * chan,int16_t * pTxPowerIndexOffset)45*572ff6f6SMatthew Dillon ar9287SetPowerCalTable(struct ath_hal *ah,
46*572ff6f6SMatthew Dillon     const struct ieee80211_channel *chan, int16_t *pTxPowerIndexOffset)
47*572ff6f6SMatthew Dillon {
48*572ff6f6SMatthew Dillon 	struct cal_data_op_loop_ar9287 *pRawDatasetOpenLoop;
49*572ff6f6SMatthew Dillon 	uint8_t *pCalBChans = NULL;
50*572ff6f6SMatthew Dillon 	uint16_t pdGainOverlap_t2;
51*572ff6f6SMatthew Dillon 	uint16_t numPiers = 0, i;
52*572ff6f6SMatthew Dillon 	uint16_t numXpdGain, xpdMask;
53*572ff6f6SMatthew Dillon 	uint16_t xpdGainValues[AR5416_NUM_PD_GAINS] = {0, 0, 0, 0};
54*572ff6f6SMatthew Dillon 	uint32_t regChainOffset;
55*572ff6f6SMatthew Dillon 	HAL_EEPROM_9287 *ee = AH_PRIVATE(ah)->ah_eeprom;
56*572ff6f6SMatthew Dillon 	struct ar9287_eeprom *pEepData = &ee->ee_base;
57*572ff6f6SMatthew Dillon 
58*572ff6f6SMatthew Dillon 	xpdMask = pEepData->modalHeader.xpdGain;
59*572ff6f6SMatthew Dillon 
60*572ff6f6SMatthew Dillon 	if ((pEepData->baseEepHeader.version & AR9287_EEP_VER_MINOR_MASK) >=
61*572ff6f6SMatthew Dillon 	    AR9287_EEP_MINOR_VER_2)
62*572ff6f6SMatthew Dillon 		pdGainOverlap_t2 = pEepData->modalHeader.pdGainOverlap;
63*572ff6f6SMatthew Dillon 	else
64*572ff6f6SMatthew Dillon 		pdGainOverlap_t2 = (uint16_t)(MS(OS_REG_READ(ah, AR_PHY_TPCRG5),
65*572ff6f6SMatthew Dillon 					    AR_PHY_TPCRG5_PD_GAIN_OVERLAP));
66*572ff6f6SMatthew Dillon 
67*572ff6f6SMatthew Dillon 	/* Note: Kiwi should only be 2ghz.. */
68*572ff6f6SMatthew Dillon 	if (IEEE80211_IS_CHAN_2GHZ(chan)) {
69*572ff6f6SMatthew Dillon 		pCalBChans = pEepData->calFreqPier2G;
70*572ff6f6SMatthew Dillon 		numPiers = AR9287_NUM_2G_CAL_PIERS;
71*572ff6f6SMatthew Dillon 		pRawDatasetOpenLoop = (struct cal_data_op_loop_ar9287 *)pEepData->calPierData2G[0];
72*572ff6f6SMatthew Dillon 		AH5416(ah)->initPDADC = pRawDatasetOpenLoop->vpdPdg[0][0];
73*572ff6f6SMatthew Dillon 	}
74*572ff6f6SMatthew Dillon 	numXpdGain = 0;
75*572ff6f6SMatthew Dillon 
76*572ff6f6SMatthew Dillon 	/* Calculate the value of xpdgains from the xpdGain Mask */
77*572ff6f6SMatthew Dillon 	for (i = 1; i <= AR5416_PD_GAINS_IN_MASK; i++) {
78*572ff6f6SMatthew Dillon 		if ((xpdMask >> (AR5416_PD_GAINS_IN_MASK - i)) & 1) {
79*572ff6f6SMatthew Dillon 			if (numXpdGain >= AR5416_NUM_PD_GAINS)
80*572ff6f6SMatthew Dillon 				break;
81*572ff6f6SMatthew Dillon 			xpdGainValues[numXpdGain] =
82*572ff6f6SMatthew Dillon 				(uint16_t)(AR5416_PD_GAINS_IN_MASK-i);
83*572ff6f6SMatthew Dillon 			numXpdGain++;
84*572ff6f6SMatthew Dillon 		}
85*572ff6f6SMatthew Dillon 	}
86*572ff6f6SMatthew Dillon 
87*572ff6f6SMatthew Dillon 	OS_REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
88*572ff6f6SMatthew Dillon 		      (numXpdGain - 1) & 0x3);
89*572ff6f6SMatthew Dillon 	OS_REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_1,
90*572ff6f6SMatthew Dillon 		      xpdGainValues[0]);
91*572ff6f6SMatthew Dillon 	OS_REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_2,
92*572ff6f6SMatthew Dillon 		      xpdGainValues[1]);
93*572ff6f6SMatthew Dillon 	OS_REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_PD_GAIN_3,
94*572ff6f6SMatthew Dillon 		      xpdGainValues[2]);
95*572ff6f6SMatthew Dillon 
96*572ff6f6SMatthew Dillon 	for (i = 0; i < AR9287_MAX_CHAINS; i++) {
97*572ff6f6SMatthew Dillon 		regChainOffset = i * 0x1000;
98*572ff6f6SMatthew Dillon 
99*572ff6f6SMatthew Dillon 		if (pEepData->baseEepHeader.txMask & (1 << i)) {
100*572ff6f6SMatthew Dillon 			int8_t txPower;
101*572ff6f6SMatthew Dillon 			pRawDatasetOpenLoop =
102*572ff6f6SMatthew Dillon 			(struct cal_data_op_loop_ar9287 *)pEepData->calPierData2G[i];
103*572ff6f6SMatthew Dillon 				ar9287olcGetTxGainIndex(ah, chan,
104*572ff6f6SMatthew Dillon 				    pRawDatasetOpenLoop,
105*572ff6f6SMatthew Dillon 				    pCalBChans, numPiers,
106*572ff6f6SMatthew Dillon 				    &txPower);
107*572ff6f6SMatthew Dillon 				ar9287olcSetPDADCs(ah, txPower, i);
108*572ff6f6SMatthew Dillon 		}
109*572ff6f6SMatthew Dillon 	}
110*572ff6f6SMatthew Dillon 
111*572ff6f6SMatthew Dillon 	*pTxPowerIndexOffset = 0;
112*572ff6f6SMatthew Dillon }
113*572ff6f6SMatthew Dillon 
114*572ff6f6SMatthew Dillon 
115*572ff6f6SMatthew Dillon /* XXX hard-coded values? */
116*572ff6f6SMatthew Dillon #define REDUCE_SCALED_POWER_BY_TWO_CHAIN     6
117*572ff6f6SMatthew Dillon 
118*572ff6f6SMatthew Dillon /*
119*572ff6f6SMatthew Dillon  * ar9287SetPowerPerRateTable
120*572ff6f6SMatthew Dillon  *
121*572ff6f6SMatthew Dillon  * Sets the transmit power in the baseband for the given
122*572ff6f6SMatthew Dillon  * operating channel and mode.
123*572ff6f6SMatthew Dillon  *
124*572ff6f6SMatthew Dillon  * This is like the v14 EEPROM table except the 5GHz code.
125*572ff6f6SMatthew Dillon  */
126*572ff6f6SMatthew Dillon 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)127*572ff6f6SMatthew Dillon ar9287SetPowerPerRateTable(struct ath_hal *ah,
128*572ff6f6SMatthew Dillon     struct ar9287_eeprom *pEepData,
129*572ff6f6SMatthew Dillon     const struct ieee80211_channel *chan,
130*572ff6f6SMatthew Dillon     int16_t *ratesArray, uint16_t cfgCtl,
131*572ff6f6SMatthew Dillon     uint16_t AntennaReduction,
132*572ff6f6SMatthew Dillon     uint16_t twiceMaxRegulatoryPower,
133*572ff6f6SMatthew Dillon     uint16_t powerLimit)
134*572ff6f6SMatthew Dillon {
135*572ff6f6SMatthew Dillon #define	N(a)	(sizeof(a)/sizeof(a[0]))
136*572ff6f6SMatthew Dillon /* Local defines to distinguish between extension and control CTL's */
137*572ff6f6SMatthew Dillon #define EXT_ADDITIVE (0x8000)
138*572ff6f6SMatthew Dillon #define CTL_11A_EXT (CTL_11A | EXT_ADDITIVE)
139*572ff6f6SMatthew Dillon #define CTL_11G_EXT (CTL_11G | EXT_ADDITIVE)
140*572ff6f6SMatthew Dillon #define CTL_11B_EXT (CTL_11B | EXT_ADDITIVE)
141*572ff6f6SMatthew Dillon 
142*572ff6f6SMatthew Dillon 	uint16_t twiceMaxEdgePower = AR5416_MAX_RATE_POWER;
143*572ff6f6SMatthew Dillon 	int i;
144*572ff6f6SMatthew Dillon 	int16_t  twiceLargestAntenna;
145*572ff6f6SMatthew Dillon 	struct cal_ctl_data_ar9287 *rep;
146*572ff6f6SMatthew Dillon 	CAL_TARGET_POWER_LEG targetPowerOfdm;
147*572ff6f6SMatthew Dillon 	CAL_TARGET_POWER_LEG targetPowerCck = {0, {0, 0, 0, 0}};
148*572ff6f6SMatthew Dillon 	CAL_TARGET_POWER_LEG targetPowerOfdmExt = {0, {0, 0, 0, 0}};
149*572ff6f6SMatthew Dillon 	CAL_TARGET_POWER_LEG targetPowerCckExt = {0, {0, 0, 0, 0}};
150*572ff6f6SMatthew Dillon 	CAL_TARGET_POWER_HT  targetPowerHt20;
151*572ff6f6SMatthew Dillon 	CAL_TARGET_POWER_HT  targetPowerHt40 = {0, {0, 0, 0, 0}};
152*572ff6f6SMatthew Dillon 	int16_t scaledPower, minCtlPower;
153*572ff6f6SMatthew Dillon 
154*572ff6f6SMatthew Dillon #define SUB_NUM_CTL_MODES_AT_2G_40 3   /* excluding HT40, EXT-OFDM, EXT-CCK */
155*572ff6f6SMatthew Dillon 	static const uint16_t ctlModesFor11g[] = {
156*572ff6f6SMatthew Dillon 	   CTL_11B, CTL_11G, CTL_2GHT20, CTL_11B_EXT, CTL_11G_EXT, CTL_2GHT40
157*572ff6f6SMatthew Dillon 	};
158*572ff6f6SMatthew Dillon 	const uint16_t *pCtlMode;
159*572ff6f6SMatthew Dillon 	uint16_t numCtlModes, ctlMode, freq;
160*572ff6f6SMatthew Dillon 	CHAN_CENTERS centers;
161*572ff6f6SMatthew Dillon 
162*572ff6f6SMatthew Dillon 	ar5416GetChannelCenters(ah,  chan, &centers);
163*572ff6f6SMatthew Dillon 
164*572ff6f6SMatthew Dillon 	/* Compute TxPower reduction due to Antenna Gain */
165*572ff6f6SMatthew Dillon 
166*572ff6f6SMatthew Dillon 	twiceLargestAntenna = AH_MAX(
167*572ff6f6SMatthew Dillon 	    pEepData->modalHeader.antennaGainCh[0],
168*572ff6f6SMatthew Dillon 	    pEepData->modalHeader.antennaGainCh[1]);
169*572ff6f6SMatthew Dillon 
170*572ff6f6SMatthew Dillon 	twiceLargestAntenna = (int16_t)AH_MIN((AntennaReduction) - twiceLargestAntenna, 0);
171*572ff6f6SMatthew Dillon 
172*572ff6f6SMatthew Dillon 	/* XXX setup for 5212 use (really used?) */
173*572ff6f6SMatthew Dillon 	ath_hal_eepromSet(ah, AR_EEP_ANTGAINMAX_2, twiceLargestAntenna);
174*572ff6f6SMatthew Dillon 
175*572ff6f6SMatthew Dillon 	/*
176*572ff6f6SMatthew Dillon 	 * scaledPower is the minimum of the user input power level and
177*572ff6f6SMatthew Dillon 	 * the regulatory allowed power level
178*572ff6f6SMatthew Dillon 	 */
179*572ff6f6SMatthew Dillon 	scaledPower = AH_MIN(powerLimit, twiceMaxRegulatoryPower + twiceLargestAntenna);
180*572ff6f6SMatthew Dillon 
181*572ff6f6SMatthew Dillon 	/* Reduce scaled Power by number of chains active to get to per chain tx power level */
182*572ff6f6SMatthew Dillon 	/* TODO: better value than these? */
183*572ff6f6SMatthew Dillon 	switch (owl_get_ntxchains(AH5416(ah)->ah_tx_chainmask)) {
184*572ff6f6SMatthew Dillon 	case 1:
185*572ff6f6SMatthew Dillon 		break;
186*572ff6f6SMatthew Dillon 	case 2:
187*572ff6f6SMatthew Dillon 		scaledPower -= REDUCE_SCALED_POWER_BY_TWO_CHAIN;
188*572ff6f6SMatthew Dillon 		break;
189*572ff6f6SMatthew Dillon 	default:
190*572ff6f6SMatthew Dillon 		return AH_FALSE; /* Unsupported number of chains */
191*572ff6f6SMatthew Dillon 	}
192*572ff6f6SMatthew Dillon 
193*572ff6f6SMatthew Dillon 	scaledPower = AH_MAX(0, scaledPower);
194*572ff6f6SMatthew Dillon 
195*572ff6f6SMatthew Dillon 	/* Get target powers from EEPROM - our baseline for TX Power */
196*572ff6f6SMatthew Dillon 	/* XXX assume channel is 2ghz */
197*572ff6f6SMatthew Dillon 	if (1) {
198*572ff6f6SMatthew Dillon 		/* Setup for CTL modes */
199*572ff6f6SMatthew Dillon 		numCtlModes = N(ctlModesFor11g) - SUB_NUM_CTL_MODES_AT_2G_40; /* CTL_11B, CTL_11G, CTL_2GHT20 */
200*572ff6f6SMatthew Dillon 		pCtlMode = ctlModesFor11g;
201*572ff6f6SMatthew Dillon 
202*572ff6f6SMatthew Dillon 		ar5416GetTargetPowersLeg(ah,  chan, pEepData->calTargetPowerCck,
203*572ff6f6SMatthew Dillon 				AR9287_NUM_2G_CCK_TARGET_POWERS, &targetPowerCck, 4, AH_FALSE);
204*572ff6f6SMatthew Dillon 		ar5416GetTargetPowersLeg(ah,  chan, pEepData->calTargetPower2G,
205*572ff6f6SMatthew Dillon 				AR9287_NUM_2G_20_TARGET_POWERS, &targetPowerOfdm, 4, AH_FALSE);
206*572ff6f6SMatthew Dillon 		ar5416GetTargetPowers(ah,  chan, pEepData->calTargetPower2GHT20,
207*572ff6f6SMatthew Dillon 				AR9287_NUM_2G_20_TARGET_POWERS, &targetPowerHt20, 8, AH_FALSE);
208*572ff6f6SMatthew Dillon 
209*572ff6f6SMatthew Dillon 		if (IEEE80211_IS_CHAN_HT40(chan)) {
210*572ff6f6SMatthew Dillon 			numCtlModes = N(ctlModesFor11g);    /* All 2G CTL's */
211*572ff6f6SMatthew Dillon 
212*572ff6f6SMatthew Dillon 			ar5416GetTargetPowers(ah,  chan, pEepData->calTargetPower2GHT40,
213*572ff6f6SMatthew Dillon 				AR9287_NUM_2G_40_TARGET_POWERS, &targetPowerHt40, 8, AH_TRUE);
214*572ff6f6SMatthew Dillon 			/* Get target powers for extension channels */
215*572ff6f6SMatthew Dillon 			ar5416GetTargetPowersLeg(ah,  chan, pEepData->calTargetPowerCck,
216*572ff6f6SMatthew Dillon 				AR9287_NUM_2G_CCK_TARGET_POWERS, &targetPowerCckExt, 4, AH_TRUE);
217*572ff6f6SMatthew Dillon 			ar5416GetTargetPowersLeg(ah,  chan, pEepData->calTargetPower2G,
218*572ff6f6SMatthew Dillon 				AR9287_NUM_2G_20_TARGET_POWERS, &targetPowerOfdmExt, 4, AH_TRUE);
219*572ff6f6SMatthew Dillon 		}
220*572ff6f6SMatthew Dillon 	}
221*572ff6f6SMatthew Dillon 
222*572ff6f6SMatthew Dillon 	/*
223*572ff6f6SMatthew Dillon 	 * For MIMO, need to apply regulatory caps individually across dynamically
224*572ff6f6SMatthew Dillon 	 * running modes: CCK, OFDM, HT20, HT40
225*572ff6f6SMatthew Dillon 	 *
226*572ff6f6SMatthew Dillon 	 * The outer loop walks through each possible applicable runtime mode.
227*572ff6f6SMatthew Dillon 	 * The inner loop walks through each ctlIndex entry in EEPROM.
228*572ff6f6SMatthew Dillon 	 * The ctl value is encoded as [7:4] == test group, [3:0] == test mode.
229*572ff6f6SMatthew Dillon 	 *
230*572ff6f6SMatthew Dillon 	 */
231*572ff6f6SMatthew Dillon 	for (ctlMode = 0; ctlMode < numCtlModes; ctlMode++) {
232*572ff6f6SMatthew Dillon 		HAL_BOOL isHt40CtlMode = (pCtlMode[ctlMode] == CTL_5GHT40) ||
233*572ff6f6SMatthew Dillon 		    (pCtlMode[ctlMode] == CTL_2GHT40);
234*572ff6f6SMatthew Dillon 		if (isHt40CtlMode) {
235*572ff6f6SMatthew Dillon 			freq = centers.ctl_center;
236*572ff6f6SMatthew Dillon 		} else if (pCtlMode[ctlMode] & EXT_ADDITIVE) {
237*572ff6f6SMatthew Dillon 			freq = centers.ext_center;
238*572ff6f6SMatthew Dillon 		} else {
239*572ff6f6SMatthew Dillon 			freq = centers.ctl_center;
240*572ff6f6SMatthew Dillon 		}
241*572ff6f6SMatthew Dillon 
242*572ff6f6SMatthew Dillon 		/* walk through each CTL index stored in EEPROM */
243*572ff6f6SMatthew Dillon 		for (i = 0; (i < AR9287_NUM_CTLS) && pEepData->ctlIndex[i]; i++) {
244*572ff6f6SMatthew Dillon 			uint16_t twiceMinEdgePower;
245*572ff6f6SMatthew Dillon 
246*572ff6f6SMatthew Dillon 			/* compare test group from regulatory channel list with test mode from pCtlMode list */
247*572ff6f6SMatthew Dillon 			if ((((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) == pEepData->ctlIndex[i]) ||
248*572ff6f6SMatthew Dillon 				(((cfgCtl & ~CTL_MODE_M) | (pCtlMode[ctlMode] & CTL_MODE_M)) ==
249*572ff6f6SMatthew Dillon 				 ((pEepData->ctlIndex[i] & CTL_MODE_M) | SD_NO_CTL))) {
250*572ff6f6SMatthew Dillon 				rep = &(pEepData->ctlData[i]);
251*572ff6f6SMatthew Dillon 				twiceMinEdgePower = ar5416GetMaxEdgePower(freq,
252*572ff6f6SMatthew Dillon 							rep->ctlEdges[owl_get_ntxchains(AH5416(ah)->ah_tx_chainmask) - 1],
253*572ff6f6SMatthew Dillon 							IEEE80211_IS_CHAN_2GHZ(chan));
254*572ff6f6SMatthew Dillon 				if ((cfgCtl & ~CTL_MODE_M) == SD_NO_CTL) {
255*572ff6f6SMatthew Dillon 					/* Find the minimum of all CTL edge powers that apply to this channel */
256*572ff6f6SMatthew Dillon 					twiceMaxEdgePower = AH_MIN(twiceMaxEdgePower, twiceMinEdgePower);
257*572ff6f6SMatthew Dillon 				} else {
258*572ff6f6SMatthew Dillon 					/* specific */
259*572ff6f6SMatthew Dillon 					twiceMaxEdgePower = twiceMinEdgePower;
260*572ff6f6SMatthew Dillon 					break;
261*572ff6f6SMatthew Dillon 				}
262*572ff6f6SMatthew Dillon 			}
263*572ff6f6SMatthew Dillon 		}
264*572ff6f6SMatthew Dillon 		minCtlPower = (uint8_t)AH_MIN(twiceMaxEdgePower, scaledPower);
265*572ff6f6SMatthew Dillon 		/* Apply ctl mode to correct target power set */
266*572ff6f6SMatthew Dillon 		switch(pCtlMode[ctlMode]) {
267*572ff6f6SMatthew Dillon 		case CTL_11B:
268*572ff6f6SMatthew Dillon 			for (i = 0; i < N(targetPowerCck.tPow2x); i++) {
269*572ff6f6SMatthew Dillon 				targetPowerCck.tPow2x[i] = (uint8_t)AH_MIN(targetPowerCck.tPow2x[i], minCtlPower);
270*572ff6f6SMatthew Dillon 			}
271*572ff6f6SMatthew Dillon 			break;
272*572ff6f6SMatthew Dillon 		case CTL_11A:
273*572ff6f6SMatthew Dillon 		case CTL_11G:
274*572ff6f6SMatthew Dillon 			for (i = 0; i < N(targetPowerOfdm.tPow2x); i++) {
275*572ff6f6SMatthew Dillon 				targetPowerOfdm.tPow2x[i] = (uint8_t)AH_MIN(targetPowerOfdm.tPow2x[i], minCtlPower);
276*572ff6f6SMatthew Dillon 			}
277*572ff6f6SMatthew Dillon 			break;
278*572ff6f6SMatthew Dillon 		case CTL_5GHT20:
279*572ff6f6SMatthew Dillon 		case CTL_2GHT20:
280*572ff6f6SMatthew Dillon 			for (i = 0; i < N(targetPowerHt20.tPow2x); i++) {
281*572ff6f6SMatthew Dillon 				targetPowerHt20.tPow2x[i] = (uint8_t)AH_MIN(targetPowerHt20.tPow2x[i], minCtlPower);
282*572ff6f6SMatthew Dillon 			}
283*572ff6f6SMatthew Dillon 			break;
284*572ff6f6SMatthew Dillon 		case CTL_11B_EXT:
285*572ff6f6SMatthew Dillon 			targetPowerCckExt.tPow2x[0] = (uint8_t)AH_MIN(targetPowerCckExt.tPow2x[0], minCtlPower);
286*572ff6f6SMatthew Dillon 			break;
287*572ff6f6SMatthew Dillon 		case CTL_11A_EXT:
288*572ff6f6SMatthew Dillon 		case CTL_11G_EXT:
289*572ff6f6SMatthew Dillon 			targetPowerOfdmExt.tPow2x[0] = (uint8_t)AH_MIN(targetPowerOfdmExt.tPow2x[0], minCtlPower);
290*572ff6f6SMatthew Dillon 			break;
291*572ff6f6SMatthew Dillon 		case CTL_5GHT40:
292*572ff6f6SMatthew Dillon 		case CTL_2GHT40:
293*572ff6f6SMatthew Dillon 			for (i = 0; i < N(targetPowerHt40.tPow2x); i++) {
294*572ff6f6SMatthew Dillon 				targetPowerHt40.tPow2x[i] = (uint8_t)AH_MIN(targetPowerHt40.tPow2x[i], minCtlPower);
295*572ff6f6SMatthew Dillon 			}
296*572ff6f6SMatthew Dillon 			break;
297*572ff6f6SMatthew Dillon 		default:
298*572ff6f6SMatthew Dillon 			return AH_FALSE;
299*572ff6f6SMatthew Dillon 			break;
300*572ff6f6SMatthew Dillon 		}
301*572ff6f6SMatthew Dillon 	} /* end ctl mode checking */
302*572ff6f6SMatthew Dillon 
303*572ff6f6SMatthew Dillon 	/* Set rates Array from collected data */
304*572ff6f6SMatthew Dillon 	ar5416SetRatesArrayFromTargetPower(ah, chan, ratesArray,
305*572ff6f6SMatthew Dillon 	    &targetPowerCck,
306*572ff6f6SMatthew Dillon 	    &targetPowerCckExt,
307*572ff6f6SMatthew Dillon 	    &targetPowerOfdm,
308*572ff6f6SMatthew Dillon 	    &targetPowerOfdmExt,
309*572ff6f6SMatthew Dillon 	    &targetPowerHt20,
310*572ff6f6SMatthew Dillon 	    &targetPowerHt40);
311*572ff6f6SMatthew Dillon 	return AH_TRUE;
312*572ff6f6SMatthew Dillon #undef EXT_ADDITIVE
313*572ff6f6SMatthew Dillon #undef CTL_11A_EXT
314*572ff6f6SMatthew Dillon #undef CTL_11G_EXT
315*572ff6f6SMatthew Dillon #undef CTL_11B_EXT
316*572ff6f6SMatthew Dillon #undef SUB_NUM_CTL_MODES_AT_5G_40
317*572ff6f6SMatthew Dillon #undef SUB_NUM_CTL_MODES_AT_2G_40
318*572ff6f6SMatthew Dillon #undef N
319*572ff6f6SMatthew Dillon }
320*572ff6f6SMatthew Dillon 
321*572ff6f6SMatthew Dillon #undef REDUCE_SCALED_POWER_BY_TWO_CHAIN
322*572ff6f6SMatthew Dillon 
323*572ff6f6SMatthew Dillon /*
324*572ff6f6SMatthew Dillon  * This is based off of the AR5416/AR9285 code and likely could
325*572ff6f6SMatthew Dillon  * be unified in the future.
326*572ff6f6SMatthew Dillon  */
327*572ff6f6SMatthew Dillon HAL_BOOL
ar9287SetTransmitPower(struct ath_hal * ah,const struct ieee80211_channel * chan,uint16_t * rfXpdGain)328*572ff6f6SMatthew Dillon ar9287SetTransmitPower(struct ath_hal *ah,
329*572ff6f6SMatthew Dillon 	const struct ieee80211_channel *chan, uint16_t *rfXpdGain)
330*572ff6f6SMatthew Dillon {
331*572ff6f6SMatthew Dillon #define	POW_SM(_r, _s)     (((_r) & 0x3f) << (_s))
332*572ff6f6SMatthew Dillon #define	N(a)	    (sizeof (a) / sizeof (a[0]))
333*572ff6f6SMatthew Dillon 
334*572ff6f6SMatthew Dillon 	const struct modal_eep_ar9287_header *pModal;
335*572ff6f6SMatthew Dillon 	struct ath_hal_5212 *ahp = AH5212(ah);
336*572ff6f6SMatthew Dillon 	int16_t	     txPowerIndexOffset = 0;
337*572ff6f6SMatthew Dillon 	int		 i;
338*572ff6f6SMatthew Dillon 
339*572ff6f6SMatthew Dillon 	uint16_t	    cfgCtl;
340*572ff6f6SMatthew Dillon 	uint16_t	    powerLimit;
341*572ff6f6SMatthew Dillon 	uint16_t	    twiceAntennaReduction;
342*572ff6f6SMatthew Dillon 	uint16_t	    twiceMaxRegulatoryPower;
343*572ff6f6SMatthew Dillon 	int16_t	     maxPower;
344*572ff6f6SMatthew Dillon 	HAL_EEPROM_9287 *ee = AH_PRIVATE(ah)->ah_eeprom;
345*572ff6f6SMatthew Dillon 	struct ar9287_eeprom *pEepData = &ee->ee_base;
346*572ff6f6SMatthew Dillon 
347*572ff6f6SMatthew Dillon 	AH5416(ah)->ah_ht40PowerIncForPdadc = 2;
348*572ff6f6SMatthew Dillon 
349*572ff6f6SMatthew Dillon 	/* Setup info for the actual eeprom */
350*572ff6f6SMatthew Dillon 	OS_MEMZERO(AH5416(ah)->ah_ratesArray,
351*572ff6f6SMatthew Dillon 	  sizeof(AH5416(ah)->ah_ratesArray));
352*572ff6f6SMatthew Dillon 	cfgCtl = ath_hal_getctl(ah, chan);
353*572ff6f6SMatthew Dillon 	powerLimit = chan->ic_maxregpower * 2;
354*572ff6f6SMatthew Dillon 	twiceAntennaReduction = chan->ic_maxantgain;
355*572ff6f6SMatthew Dillon 	twiceMaxRegulatoryPower = AH_MIN(MAX_RATE_POWER,
356*572ff6f6SMatthew Dillon 	    AH_PRIVATE(ah)->ah_powerLimit);
357*572ff6f6SMatthew Dillon 	pModal = &pEepData->modalHeader;
358*572ff6f6SMatthew Dillon 	HALDEBUG(ah, HAL_DEBUG_RESET, "%s Channel=%u CfgCtl=%u\n",
359*572ff6f6SMatthew Dillon 	    __func__,chan->ic_freq, cfgCtl );
360*572ff6f6SMatthew Dillon 
361*572ff6f6SMatthew Dillon 	/* XXX Assume Minor is v2 or later */
362*572ff6f6SMatthew Dillon 	AH5416(ah)->ah_ht40PowerIncForPdadc = pModal->ht40PowerIncForPdadc;
363*572ff6f6SMatthew Dillon 
364*572ff6f6SMatthew Dillon 	/* Fetch per-rate power table for the given channel */
365*572ff6f6SMatthew Dillon 	if (! ar9287SetPowerPerRateTable(ah, pEepData,  chan,
366*572ff6f6SMatthew Dillon 	    &AH5416(ah)->ah_ratesArray[0],
367*572ff6f6SMatthew Dillon 	    cfgCtl,
368*572ff6f6SMatthew Dillon 	    twiceAntennaReduction,
369*572ff6f6SMatthew Dillon 	    twiceMaxRegulatoryPower, powerLimit)) {
370*572ff6f6SMatthew Dillon 		HALDEBUG(ah, HAL_DEBUG_ANY,
371*572ff6f6SMatthew Dillon 		    "%s: unable to set tx power per rate table\n", __func__);
372*572ff6f6SMatthew Dillon 		return AH_FALSE;
373*572ff6f6SMatthew Dillon 	}
374*572ff6f6SMatthew Dillon 
375*572ff6f6SMatthew Dillon 	/* Set TX power control calibration curves for each TX chain */
376*572ff6f6SMatthew Dillon 	ar9287SetPowerCalTable(ah, chan, &txPowerIndexOffset);
377*572ff6f6SMatthew Dillon 
378*572ff6f6SMatthew Dillon 	/* Calculate maximum power level */
379*572ff6f6SMatthew Dillon 	maxPower = AH_MAX(AH5416(ah)->ah_ratesArray[rate6mb],
380*572ff6f6SMatthew Dillon 	    AH5416(ah)->ah_ratesArray[rateHt20_0]);
381*572ff6f6SMatthew Dillon 	maxPower = AH_MAX(maxPower,
382*572ff6f6SMatthew Dillon 	    AH5416(ah)->ah_ratesArray[rate1l]);
383*572ff6f6SMatthew Dillon 
384*572ff6f6SMatthew Dillon 	if (IEEE80211_IS_CHAN_HT40(chan))
385*572ff6f6SMatthew Dillon 		maxPower = AH_MAX(maxPower,
386*572ff6f6SMatthew Dillon 		    AH5416(ah)->ah_ratesArray[rateHt40_0]);
387*572ff6f6SMatthew Dillon 
388*572ff6f6SMatthew Dillon 	ahp->ah_tx6PowerInHalfDbm = maxPower;
389*572ff6f6SMatthew Dillon 	AH_PRIVATE(ah)->ah_maxPowerLevel = maxPower;
390*572ff6f6SMatthew Dillon 	ahp->ah_txPowerIndexOffset = txPowerIndexOffset;
391*572ff6f6SMatthew Dillon 
392*572ff6f6SMatthew Dillon 	/*
393*572ff6f6SMatthew Dillon 	 * txPowerIndexOffset is set by the SetPowerTable() call -
394*572ff6f6SMatthew Dillon 	 *  adjust the rate table (0 offset if rates EEPROM not loaded)
395*572ff6f6SMatthew Dillon 	 */
396*572ff6f6SMatthew Dillon 	/* XXX what about the pwrTableOffset? */
397*572ff6f6SMatthew Dillon 	for (i = 0; i < N(AH5416(ah)->ah_ratesArray); i++) {
398*572ff6f6SMatthew Dillon 		AH5416(ah)->ah_ratesArray[i] =
399*572ff6f6SMatthew Dillon 		    (int16_t)(txPowerIndexOffset +
400*572ff6f6SMatthew Dillon 		      AH5416(ah)->ah_ratesArray[i]);
401*572ff6f6SMatthew Dillon 		/* -5 dBm offset for Merlin and later; this includes Kiwi */
402*572ff6f6SMatthew Dillon 		AH5416(ah)->ah_ratesArray[i] -= AR5416_PWR_TABLE_OFFSET_DB * 2;
403*572ff6f6SMatthew Dillon 		if (AH5416(ah)->ah_ratesArray[i] > AR5416_MAX_RATE_POWER)
404*572ff6f6SMatthew Dillon 			AH5416(ah)->ah_ratesArray[i] = AR5416_MAX_RATE_POWER;
405*572ff6f6SMatthew Dillon 		if (AH5416(ah)->ah_ratesArray[i] < 0)
406*572ff6f6SMatthew Dillon 			AH5416(ah)->ah_ratesArray[i] = 0;
407*572ff6f6SMatthew Dillon 	}
408*572ff6f6SMatthew Dillon 
409*572ff6f6SMatthew Dillon #ifdef AH_EEPROM_DUMP
410*572ff6f6SMatthew Dillon 	ar5416PrintPowerPerRate(ah, AH5416(ah)->ah_ratesArray);
411*572ff6f6SMatthew Dillon #endif
412*572ff6f6SMatthew Dillon 
413*572ff6f6SMatthew Dillon 	/*
414*572ff6f6SMatthew Dillon 	 * Adjust the HT40 power to meet the correct target TX power
415*572ff6f6SMatthew Dillon 	 * for 40MHz mode, based on TX power curves that are established
416*572ff6f6SMatthew Dillon 	 * for 20MHz mode.
417*572ff6f6SMatthew Dillon 	 *
418*572ff6f6SMatthew Dillon 	 * XXX handle overflow/too high power level?
419*572ff6f6SMatthew Dillon 	 */
420*572ff6f6SMatthew Dillon 	if (IEEE80211_IS_CHAN_HT40(chan)) {
421*572ff6f6SMatthew Dillon 		AH5416(ah)->ah_ratesArray[rateHt40_0] +=
422*572ff6f6SMatthew Dillon 		  AH5416(ah)->ah_ht40PowerIncForPdadc;
423*572ff6f6SMatthew Dillon 		AH5416(ah)->ah_ratesArray[rateHt40_1] +=
424*572ff6f6SMatthew Dillon 		  AH5416(ah)->ah_ht40PowerIncForPdadc;
425*572ff6f6SMatthew Dillon 		AH5416(ah)->ah_ratesArray[rateHt40_2] +=
426*572ff6f6SMatthew Dillon 		  AH5416(ah)->ah_ht40PowerIncForPdadc;
427*572ff6f6SMatthew Dillon 		AH5416(ah)->ah_ratesArray[rateHt40_3] +=
428*572ff6f6SMatthew Dillon 		  AH5416(ah)->ah_ht40PowerIncForPdadc;
429*572ff6f6SMatthew Dillon 		AH5416(ah)->ah_ratesArray[rateHt40_4] +=
430*572ff6f6SMatthew Dillon 		  AH5416(ah)->ah_ht40PowerIncForPdadc;
431*572ff6f6SMatthew Dillon 		AH5416(ah)->ah_ratesArray[rateHt40_5] +=
432*572ff6f6SMatthew Dillon 		  AH5416(ah)->ah_ht40PowerIncForPdadc;
433*572ff6f6SMatthew Dillon 		AH5416(ah)->ah_ratesArray[rateHt40_6] +=
434*572ff6f6SMatthew Dillon 		  AH5416(ah)->ah_ht40PowerIncForPdadc;
435*572ff6f6SMatthew Dillon 		AH5416(ah)->ah_ratesArray[rateHt40_7] +=
436*572ff6f6SMatthew Dillon 		  AH5416(ah)->ah_ht40PowerIncForPdadc;
437*572ff6f6SMatthew Dillon 	}
438*572ff6f6SMatthew Dillon 
439*572ff6f6SMatthew Dillon 	/* Write the TX power rate registers */
440*572ff6f6SMatthew Dillon 	ar5416WriteTxPowerRateRegisters(ah, chan, AH5416(ah)->ah_ratesArray);
441*572ff6f6SMatthew Dillon 
442*572ff6f6SMatthew Dillon 	return AH_TRUE;
443*572ff6f6SMatthew Dillon #undef POW_SM
444*572ff6f6SMatthew Dillon #undef N
445*572ff6f6SMatthew Dillon }
446*572ff6f6SMatthew Dillon 
447*572ff6f6SMatthew Dillon /*
448*572ff6f6SMatthew Dillon  * Read EEPROM header info and program the device for correct operation
449*572ff6f6SMatthew Dillon  * given the channel value.
450*572ff6f6SMatthew Dillon  */
451*572ff6f6SMatthew Dillon HAL_BOOL
ar9287SetBoardValues(struct ath_hal * ah,const struct ieee80211_channel * chan)452*572ff6f6SMatthew Dillon ar9287SetBoardValues(struct ath_hal *ah, const struct ieee80211_channel *chan)
453*572ff6f6SMatthew Dillon {
454*572ff6f6SMatthew Dillon 	const HAL_EEPROM_9287 *ee = AH_PRIVATE(ah)->ah_eeprom;
455*572ff6f6SMatthew Dillon 	const struct ar9287_eeprom *eep = &ee->ee_base;
456*572ff6f6SMatthew Dillon 	const struct modal_eep_ar9287_header *pModal = &eep->modalHeader;
457*572ff6f6SMatthew Dillon 	uint16_t antWrites[AR9287_ANT_16S];
458*572ff6f6SMatthew Dillon 	uint32_t regChainOffset, regval;
459*572ff6f6SMatthew Dillon 	uint8_t txRxAttenLocal;
460*572ff6f6SMatthew Dillon 	int i, j, offset_num;
461*572ff6f6SMatthew Dillon 
462*572ff6f6SMatthew Dillon 	pModal = &eep->modalHeader;
463*572ff6f6SMatthew Dillon 
464*572ff6f6SMatthew Dillon 	antWrites[0] = (uint16_t)((pModal->antCtrlCommon >> 28) & 0xF);
465*572ff6f6SMatthew Dillon 	antWrites[1] = (uint16_t)((pModal->antCtrlCommon >> 24) & 0xF);
466*572ff6f6SMatthew Dillon 	antWrites[2] = (uint16_t)((pModal->antCtrlCommon >> 20) & 0xF);
467*572ff6f6SMatthew Dillon 	antWrites[3] = (uint16_t)((pModal->antCtrlCommon >> 16) & 0xF);
468*572ff6f6SMatthew Dillon 	antWrites[4] = (uint16_t)((pModal->antCtrlCommon >> 12) & 0xF);
469*572ff6f6SMatthew Dillon 	antWrites[5] = (uint16_t)((pModal->antCtrlCommon >> 8) & 0xF);
470*572ff6f6SMatthew Dillon 	antWrites[6] = (uint16_t)((pModal->antCtrlCommon >> 4)  & 0xF);
471*572ff6f6SMatthew Dillon 	antWrites[7] = (uint16_t)(pModal->antCtrlCommon & 0xF);
472*572ff6f6SMatthew Dillon 
473*572ff6f6SMatthew Dillon 	offset_num = 8;
474*572ff6f6SMatthew Dillon 
475*572ff6f6SMatthew Dillon 	for (i = 0, j = offset_num; i < AR9287_MAX_CHAINS; i++) {
476*572ff6f6SMatthew Dillon 		antWrites[j++] = (uint16_t)((pModal->antCtrlChain[i] >> 28) & 0xf);
477*572ff6f6SMatthew Dillon 		antWrites[j++] = (uint16_t)((pModal->antCtrlChain[i] >> 10) & 0x3);
478*572ff6f6SMatthew Dillon 		antWrites[j++] = (uint16_t)((pModal->antCtrlChain[i] >> 8) & 0x3);
479*572ff6f6SMatthew Dillon 		antWrites[j++] = 0;
480*572ff6f6SMatthew Dillon 		antWrites[j++] = (uint16_t)((pModal->antCtrlChain[i] >> 6) & 0x3);
481*572ff6f6SMatthew Dillon 		antWrites[j++] = (uint16_t)((pModal->antCtrlChain[i] >> 4) & 0x3);
482*572ff6f6SMatthew Dillon 		antWrites[j++] = (uint16_t)((pModal->antCtrlChain[i] >> 2) & 0x3);
483*572ff6f6SMatthew Dillon 		antWrites[j++] = (uint16_t)(pModal->antCtrlChain[i] & 0x3);
484*572ff6f6SMatthew Dillon 	}
485*572ff6f6SMatthew Dillon 
486*572ff6f6SMatthew Dillon 	OS_REG_WRITE(ah, AR_PHY_SWITCH_COM, pModal->antCtrlCommon);
487*572ff6f6SMatthew Dillon 
488*572ff6f6SMatthew Dillon 	for (i = 0; i < AR9287_MAX_CHAINS; i++)	{
489*572ff6f6SMatthew Dillon 		regChainOffset = i * 0x1000;
490*572ff6f6SMatthew Dillon 
491*572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, AR_PHY_SWITCH_CHAIN_0 + regChainOffset,
492*572ff6f6SMatthew Dillon 			  pModal->antCtrlChain[i]);
493*572ff6f6SMatthew Dillon 
494*572ff6f6SMatthew Dillon 		OS_REG_WRITE(ah, AR_PHY_TIMING_CTRL4_CHAIN(0) + regChainOffset,
495*572ff6f6SMatthew Dillon 			  (OS_REG_READ(ah, AR_PHY_TIMING_CTRL4_CHAIN(0)
496*572ff6f6SMatthew Dillon 			      + regChainOffset)
497*572ff6f6SMatthew Dillon 			   & ~(AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF |
498*572ff6f6SMatthew Dillon 			       AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF)) |
499*572ff6f6SMatthew Dillon 			  SM(pModal->iqCalICh[i],
500*572ff6f6SMatthew Dillon 			     AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF) |
501*572ff6f6SMatthew Dillon 			  SM(pModal->iqCalQCh[i],
502*572ff6f6SMatthew Dillon 			     AR_PHY_TIMING_CTRL4_IQCORR_Q_Q_COFF));
503*572ff6f6SMatthew Dillon 
504*572ff6f6SMatthew Dillon 		txRxAttenLocal = pModal->txRxAttenCh[i];
505*572ff6f6SMatthew Dillon 
506*572ff6f6SMatthew Dillon 		OS_REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
507*572ff6f6SMatthew Dillon 			      AR_PHY_GAIN_2GHZ_XATTEN1_MARGIN,
508*572ff6f6SMatthew Dillon 			      pModal->bswMargin[i]);
509*572ff6f6SMatthew Dillon 		OS_REG_RMW_FIELD(ah, AR_PHY_GAIN_2GHZ + regChainOffset,
510*572ff6f6SMatthew Dillon 			      AR_PHY_GAIN_2GHZ_XATTEN1_DB,
511*572ff6f6SMatthew Dillon 			      pModal->bswAtten[i]);
512*572ff6f6SMatthew Dillon 		OS_REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
513*572ff6f6SMatthew Dillon 			      AR9280_PHY_RXGAIN_TXRX_ATTEN,
514*572ff6f6SMatthew Dillon 			      txRxAttenLocal);
515*572ff6f6SMatthew Dillon 		OS_REG_RMW_FIELD(ah, AR_PHY_RXGAIN + regChainOffset,
516*572ff6f6SMatthew Dillon 			      AR9280_PHY_RXGAIN_TXRX_MARGIN,
517*572ff6f6SMatthew Dillon 			      pModal->rxTxMarginCh[i]);
518*572ff6f6SMatthew Dillon 	}
519*572ff6f6SMatthew Dillon 
520*572ff6f6SMatthew Dillon 	if (IEEE80211_IS_CHAN_HT40(chan))
521*572ff6f6SMatthew Dillon 		OS_REG_RMW_FIELD(ah, AR_PHY_SETTLING,
522*572ff6f6SMatthew Dillon 			      AR_PHY_SETTLING_SWITCH, pModal->swSettleHt40);
523*572ff6f6SMatthew Dillon 	else
524*572ff6f6SMatthew Dillon 		OS_REG_RMW_FIELD(ah, AR_PHY_SETTLING,
525*572ff6f6SMatthew Dillon 			      AR_PHY_SETTLING_SWITCH, pModal->switchSettling);
526*572ff6f6SMatthew Dillon 
527*572ff6f6SMatthew Dillon 	OS_REG_RMW_FIELD(ah, AR_PHY_DESIRED_SZ,
528*572ff6f6SMatthew Dillon 		      AR_PHY_DESIRED_SZ_ADC, pModal->adcDesiredSize);
529*572ff6f6SMatthew Dillon 
530*572ff6f6SMatthew Dillon 	OS_REG_WRITE(ah, AR_PHY_RF_CTL4,
531*572ff6f6SMatthew Dillon 		  SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAA_OFF)
532*572ff6f6SMatthew Dillon 		  | SM(pModal->txEndToXpaOff, AR_PHY_RF_CTL4_TX_END_XPAB_OFF)
533*572ff6f6SMatthew Dillon 		  | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAA_ON)
534*572ff6f6SMatthew Dillon 		  | SM(pModal->txFrameToXpaOn, AR_PHY_RF_CTL4_FRAME_XPAB_ON));
535*572ff6f6SMatthew Dillon 
536*572ff6f6SMatthew Dillon 	OS_REG_RMW_FIELD(ah, AR_PHY_RF_CTL3,
537*572ff6f6SMatthew Dillon 		      AR_PHY_TX_END_TO_A2_RX_ON, pModal->txEndToRxOn);
538*572ff6f6SMatthew Dillon 
539*572ff6f6SMatthew Dillon 	OS_REG_RMW_FIELD(ah, AR_PHY_CCA,
540*572ff6f6SMatthew Dillon 		      AR9280_PHY_CCA_THRESH62, pModal->thresh62);
541*572ff6f6SMatthew Dillon 	OS_REG_RMW_FIELD(ah, AR_PHY_EXT_CCA0,
542*572ff6f6SMatthew Dillon 		      AR_PHY_EXT_CCA0_THRESH62, pModal->thresh62);
543*572ff6f6SMatthew Dillon 
544*572ff6f6SMatthew Dillon 	regval = OS_REG_READ(ah, AR9287_AN_RF2G3_CH0);
545*572ff6f6SMatthew Dillon 	regval &= ~(AR9287_AN_RF2G3_DB1 |
546*572ff6f6SMatthew Dillon 		    AR9287_AN_RF2G3_DB2 |
547*572ff6f6SMatthew Dillon 		    AR9287_AN_RF2G3_OB_CCK |
548*572ff6f6SMatthew Dillon 		    AR9287_AN_RF2G3_OB_PSK |
549*572ff6f6SMatthew Dillon 		    AR9287_AN_RF2G3_OB_QAM |
550*572ff6f6SMatthew Dillon 		    AR9287_AN_RF2G3_OB_PAL_OFF);
551*572ff6f6SMatthew Dillon 	regval |= (SM(pModal->db1, AR9287_AN_RF2G3_DB1) |
552*572ff6f6SMatthew Dillon 		   SM(pModal->db2, AR9287_AN_RF2G3_DB2) |
553*572ff6f6SMatthew Dillon 		   SM(pModal->ob_cck, AR9287_AN_RF2G3_OB_CCK) |
554*572ff6f6SMatthew Dillon 		   SM(pModal->ob_psk, AR9287_AN_RF2G3_OB_PSK) |
555*572ff6f6SMatthew Dillon 		   SM(pModal->ob_qam, AR9287_AN_RF2G3_OB_QAM) |
556*572ff6f6SMatthew Dillon 		   SM(pModal->ob_pal_off, AR9287_AN_RF2G3_OB_PAL_OFF));
557*572ff6f6SMatthew Dillon 
558*572ff6f6SMatthew Dillon 	/* Analog write - requires a 100usec delay */
559*572ff6f6SMatthew Dillon 	OS_A_REG_WRITE(ah, AR9287_AN_RF2G3_CH0, regval);
560*572ff6f6SMatthew Dillon 
561*572ff6f6SMatthew Dillon 	regval = OS_REG_READ(ah, AR9287_AN_RF2G3_CH1);
562*572ff6f6SMatthew Dillon 	regval &= ~(AR9287_AN_RF2G3_DB1 |
563*572ff6f6SMatthew Dillon 		    AR9287_AN_RF2G3_DB2 |
564*572ff6f6SMatthew Dillon 		    AR9287_AN_RF2G3_OB_CCK |
565*572ff6f6SMatthew Dillon 		    AR9287_AN_RF2G3_OB_PSK |
566*572ff6f6SMatthew Dillon 		    AR9287_AN_RF2G3_OB_QAM |
567*572ff6f6SMatthew Dillon 		    AR9287_AN_RF2G3_OB_PAL_OFF);
568*572ff6f6SMatthew Dillon 	regval |= (SM(pModal->db1, AR9287_AN_RF2G3_DB1) |
569*572ff6f6SMatthew Dillon 		   SM(pModal->db2, AR9287_AN_RF2G3_DB2) |
570*572ff6f6SMatthew Dillon 		   SM(pModal->ob_cck, AR9287_AN_RF2G3_OB_CCK) |
571*572ff6f6SMatthew Dillon 		   SM(pModal->ob_psk, AR9287_AN_RF2G3_OB_PSK) |
572*572ff6f6SMatthew Dillon 		   SM(pModal->ob_qam, AR9287_AN_RF2G3_OB_QAM) |
573*572ff6f6SMatthew Dillon 		   SM(pModal->ob_pal_off, AR9287_AN_RF2G3_OB_PAL_OFF));
574*572ff6f6SMatthew Dillon 
575*572ff6f6SMatthew Dillon 	OS_A_REG_WRITE(ah, AR9287_AN_RF2G3_CH1, regval);
576*572ff6f6SMatthew Dillon 
577*572ff6f6SMatthew Dillon 	OS_REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
578*572ff6f6SMatthew Dillon 	    AR_PHY_TX_FRAME_TO_DATA_START, pModal->txFrameToDataStart);
579*572ff6f6SMatthew Dillon 	OS_REG_RMW_FIELD(ah, AR_PHY_RF_CTL2,
580*572ff6f6SMatthew Dillon 	    AR_PHY_TX_FRAME_TO_PA_ON, pModal->txFrameToPaOn);
581*572ff6f6SMatthew Dillon 
582*572ff6f6SMatthew Dillon 	OS_A_REG_RMW_FIELD(ah, AR9287_AN_TOP2,
583*572ff6f6SMatthew Dillon 	    AR9287_AN_TOP2_XPABIAS_LVL, pModal->xpaBiasLvl);
584*572ff6f6SMatthew Dillon 
585*572ff6f6SMatthew Dillon 	return AH_TRUE;
586*572ff6f6SMatthew Dillon }
587