xref: /dragonfly/sys/dev/netif/ath/ath_hal/ar9002/ar9280.c (revision 572ff6f6)
1*572ff6f6SMatthew Dillon /*
2*572ff6f6SMatthew Dillon  * Copyright (c) 2008-2009 Sam Leffler, Errno Consulting
3*572ff6f6SMatthew Dillon  * Copyright (c) 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 #include "opt_ah.h"
20*572ff6f6SMatthew Dillon 
21*572ff6f6SMatthew Dillon /*
22*572ff6f6SMatthew Dillon  * NB: Merlin and later have a simpler RF backend.
23*572ff6f6SMatthew Dillon  */
24*572ff6f6SMatthew Dillon #include "ah.h"
25*572ff6f6SMatthew Dillon #include "ah_internal.h"
26*572ff6f6SMatthew Dillon 
27*572ff6f6SMatthew Dillon #include "ah_eeprom_v14.h"
28*572ff6f6SMatthew Dillon 
29*572ff6f6SMatthew Dillon #include "ar9002/ar9280.h"
30*572ff6f6SMatthew Dillon #include "ar5416/ar5416reg.h"
31*572ff6f6SMatthew Dillon #include "ar5416/ar5416phy.h"
32*572ff6f6SMatthew Dillon 
33*572ff6f6SMatthew Dillon #define N(a)    (sizeof(a)/sizeof(a[0]))
34*572ff6f6SMatthew Dillon 
35*572ff6f6SMatthew Dillon struct ar9280State {
36*572ff6f6SMatthew Dillon 	RF_HAL_FUNCS	base;		/* public state, must be first */
37*572ff6f6SMatthew Dillon 	uint16_t	pcdacTable[1];	/* XXX */
38*572ff6f6SMatthew Dillon };
39*572ff6f6SMatthew Dillon #define	AR9280(ah)	((struct ar9280State *) AH5212(ah)->ah_rfHal)
40*572ff6f6SMatthew Dillon 
41*572ff6f6SMatthew Dillon static HAL_BOOL ar9280GetChannelMaxMinPower(struct ath_hal *,
42*572ff6f6SMatthew Dillon 	const struct ieee80211_channel *, int16_t *maxPow,int16_t *minPow);
43*572ff6f6SMatthew Dillon int16_t ar9280GetNfAdjust(struct ath_hal *ah, const HAL_CHANNEL_INTERNAL *c);
44*572ff6f6SMatthew Dillon 
45*572ff6f6SMatthew Dillon static void
ar9280WriteRegs(struct ath_hal * ah,u_int modesIndex,u_int freqIndex,int writes)46*572ff6f6SMatthew Dillon ar9280WriteRegs(struct ath_hal *ah, u_int modesIndex, u_int freqIndex,
47*572ff6f6SMatthew Dillon 	int writes)
48*572ff6f6SMatthew Dillon {
49*572ff6f6SMatthew Dillon 	(void) ath_hal_ini_write(ah, &AH5416(ah)->ah_ini_bb_rfgain,
50*572ff6f6SMatthew Dillon 		freqIndex, writes);
51*572ff6f6SMatthew Dillon }
52*572ff6f6SMatthew Dillon 
53*572ff6f6SMatthew Dillon /*
54*572ff6f6SMatthew Dillon  * Take the MHz channel value and set the Channel value
55*572ff6f6SMatthew Dillon  *
56*572ff6f6SMatthew Dillon  * ASSUMES: Writes enabled to analog bus
57*572ff6f6SMatthew Dillon  *
58*572ff6f6SMatthew Dillon  * Actual Expression,
59*572ff6f6SMatthew Dillon  *
60*572ff6f6SMatthew Dillon  * For 2GHz channel,
61*572ff6f6SMatthew Dillon  * Channel Frequency = (3/4) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^17)
62*572ff6f6SMatthew Dillon  * (freq_ref = 40MHz)
63*572ff6f6SMatthew Dillon  *
64*572ff6f6SMatthew Dillon  * For 5GHz channel,
65*572ff6f6SMatthew Dillon  * Channel Frequency = (3/2) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^10)
66*572ff6f6SMatthew Dillon  * (freq_ref = 40MHz/(24>>amodeRefSel))
67*572ff6f6SMatthew Dillon  *
68*572ff6f6SMatthew Dillon  * For 5GHz channels which are 5MHz spaced,
69*572ff6f6SMatthew Dillon  * Channel Frequency = (3/2) * freq_ref * (chansel[8:0] + chanfrac[16:0]/2^17)
70*572ff6f6SMatthew Dillon  * (freq_ref = 40MHz)
71*572ff6f6SMatthew Dillon  */
72*572ff6f6SMatthew Dillon static HAL_BOOL
ar9280SetChannel(struct ath_hal * ah,const struct ieee80211_channel * chan)73*572ff6f6SMatthew Dillon ar9280SetChannel(struct ath_hal *ah, const struct ieee80211_channel *chan)
74*572ff6f6SMatthew Dillon {
75*572ff6f6SMatthew Dillon 	uint16_t bMode, fracMode, aModeRefSel = 0;
76*572ff6f6SMatthew Dillon 	uint32_t freq, ndiv, channelSel = 0, channelFrac = 0, reg32 = 0;
77*572ff6f6SMatthew Dillon 	CHAN_CENTERS centers;
78*572ff6f6SMatthew Dillon 	uint32_t refDivA = 24;
79*572ff6f6SMatthew Dillon 	uint8_t frac_n_5g;
80*572ff6f6SMatthew Dillon 
81*572ff6f6SMatthew Dillon 	OS_MARK(ah, AH_MARK_SETCHANNEL, chan->ic_freq);
82*572ff6f6SMatthew Dillon 
83*572ff6f6SMatthew Dillon 	ar5416GetChannelCenters(ah, chan, &centers);
84*572ff6f6SMatthew Dillon 	freq = centers.synth_center;
85*572ff6f6SMatthew Dillon 
86*572ff6f6SMatthew Dillon 	reg32 = OS_REG_READ(ah, AR_PHY_SYNTH_CONTROL);
87*572ff6f6SMatthew Dillon 	reg32 &= 0xc0000000;
88*572ff6f6SMatthew Dillon 
89*572ff6f6SMatthew Dillon 	if (ath_hal_eepromGet(ah, AR_EEP_FRAC_N_5G, &frac_n_5g) != HAL_OK)
90*572ff6f6SMatthew Dillon 		frac_n_5g = 0;
91*572ff6f6SMatthew Dillon 
92*572ff6f6SMatthew Dillon 	if (freq < 4800) {     /* 2 GHz, fractional mode */
93*572ff6f6SMatthew Dillon 		uint32_t txctl;
94*572ff6f6SMatthew Dillon 
95*572ff6f6SMatthew Dillon 		bMode = 1;
96*572ff6f6SMatthew Dillon 		fracMode = 1;
97*572ff6f6SMatthew Dillon 		aModeRefSel = 0;
98*572ff6f6SMatthew Dillon 		channelSel = (freq * 0x10000)/15;
99*572ff6f6SMatthew Dillon 
100*572ff6f6SMatthew Dillon 		txctl = OS_REG_READ(ah, AR_PHY_CCK_TX_CTRL);
101*572ff6f6SMatthew Dillon 		if (freq == 2484) {
102*572ff6f6SMatthew Dillon 			/* Enable channel spreading for channel 14 */
103*572ff6f6SMatthew Dillon 			OS_REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
104*572ff6f6SMatthew Dillon 			    txctl | AR_PHY_CCK_TX_CTRL_JAPAN);
105*572ff6f6SMatthew Dillon 		} else {
106*572ff6f6SMatthew Dillon 			OS_REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
107*572ff6f6SMatthew Dillon 			    txctl &~ AR_PHY_CCK_TX_CTRL_JAPAN);
108*572ff6f6SMatthew Dillon 		}
109*572ff6f6SMatthew Dillon 	} else {
110*572ff6f6SMatthew Dillon 		bMode = 0;
111*572ff6f6SMatthew Dillon 		fracMode = 0;
112*572ff6f6SMatthew Dillon 
113*572ff6f6SMatthew Dillon 		switch (frac_n_5g) {
114*572ff6f6SMatthew Dillon 		case 0:
115*572ff6f6SMatthew Dillon 			/*
116*572ff6f6SMatthew Dillon 			 * Enable fractional mode for half/quarter rate
117*572ff6f6SMatthew Dillon 			 * channels.
118*572ff6f6SMatthew Dillon 			 *
119*572ff6f6SMatthew Dillon 			 * This is from the Linux ath9k code, rather than
120*572ff6f6SMatthew Dillon 			 * the Atheros HAL code.
121*572ff6f6SMatthew Dillon 			 */
122*572ff6f6SMatthew Dillon 			if (IEEE80211_IS_CHAN_QUARTER(chan) ||
123*572ff6f6SMatthew Dillon 			    IEEE80211_IS_CHAN_HALF(chan))
124*572ff6f6SMatthew Dillon 				aModeRefSel = 0;
125*572ff6f6SMatthew Dillon 			else if ((freq % 20) == 0) {
126*572ff6f6SMatthew Dillon 				aModeRefSel = 3;
127*572ff6f6SMatthew Dillon 			} else if ((freq % 10) == 0) {
128*572ff6f6SMatthew Dillon 				aModeRefSel = 2;
129*572ff6f6SMatthew Dillon 			}
130*572ff6f6SMatthew Dillon 			if (aModeRefSel) break;
131*572ff6f6SMatthew Dillon 		case 1:
132*572ff6f6SMatthew Dillon 		default:
133*572ff6f6SMatthew Dillon 			aModeRefSel = 0;
134*572ff6f6SMatthew Dillon 			/* Enable 2G (fractional) mode for channels which are 5MHz spaced */
135*572ff6f6SMatthew Dillon 
136*572ff6f6SMatthew Dillon 			/*
137*572ff6f6SMatthew Dillon 			 * Workaround for talking on PSB non-5MHz channels;
138*572ff6f6SMatthew Dillon 			 * the pre-Merlin chips only had a 2.5MHz channel
139*572ff6f6SMatthew Dillon 			 * spacing so some channels aren't reachable.
140*572ff6f6SMatthew Dillon 
141*572ff6f6SMatthew Dillon 			 *
142*572ff6f6SMatthew Dillon 			 * This interoperates on the quarter rate channels
143*572ff6f6SMatthew Dillon 			 * with the AR5112 and later RF synths.  Please note
144*572ff6f6SMatthew Dillon 			 * that the synthesiser isn't able to completely
145*572ff6f6SMatthew Dillon 			 * accurately represent these frequencies (as the
146*572ff6f6SMatthew Dillon 			 * resolution in this reference is 2.5MHz) and thus
147*572ff6f6SMatthew Dillon 			 * it will be slightly "off centre."  This matches
148*572ff6f6SMatthew Dillon 			 * the same slightly incorrect centre frequency
149*572ff6f6SMatthew Dillon 			 * behaviour that the AR5112 and later channel
150*572ff6f6SMatthew Dillon 			 * selection code has.
151*572ff6f6SMatthew Dillon 			 *
152*572ff6f6SMatthew Dillon 			 * This also interoperates with the AR5416
153*572ff6f6SMatthew Dillon 			 * synthesiser modification for programming
154*572ff6f6SMatthew Dillon 			 * fractional frequencies in 5GHz mode.  However
155*572ff6f6SMatthew Dillon 			 * that modification is also disabled by default.
156*572ff6f6SMatthew Dillon 			 *
157*572ff6f6SMatthew Dillon 			 * This is disabled because it hasn't been tested for
158*572ff6f6SMatthew Dillon 			 * regulatory compliance and neither have the NICs
159*572ff6f6SMatthew Dillon 			 * which would use it.  So if you enable this code,
160*572ff6f6SMatthew Dillon 			 * you must first ensure that you've re-certified the
161*572ff6f6SMatthew Dillon 			 * NICs in question beforehand or you will be
162*572ff6f6SMatthew Dillon 			 * violating your local regulatory rules and breaking
163*572ff6f6SMatthew Dillon 			 * the law.
164*572ff6f6SMatthew Dillon 			 */
165*572ff6f6SMatthew Dillon #if 0
166*572ff6f6SMatthew Dillon 			if (freq % 5 == 0) {
167*572ff6f6SMatthew Dillon #endif
168*572ff6f6SMatthew Dillon 				/* Normal */
169*572ff6f6SMatthew Dillon 				fracMode = 1;
170*572ff6f6SMatthew Dillon 				refDivA = 1;
171*572ff6f6SMatthew Dillon 				channelSel = (freq * 0x8000)/15;
172*572ff6f6SMatthew Dillon #if 0
173*572ff6f6SMatthew Dillon 			} else {
174*572ff6f6SMatthew Dillon 				/* Offset by 500KHz */
175*572ff6f6SMatthew Dillon 				uint32_t f, ch, ch2;
176*572ff6f6SMatthew Dillon 
177*572ff6f6SMatthew Dillon 				fracMode = 1;
178*572ff6f6SMatthew Dillon 				refDivA = 1;
179*572ff6f6SMatthew Dillon 
180*572ff6f6SMatthew Dillon 				/* Calculate the "adjusted" frequency */
181*572ff6f6SMatthew Dillon 				f = freq - 2;
182*572ff6f6SMatthew Dillon 				ch = (((f - 4800) * 10) / 25) + 1;
183*572ff6f6SMatthew Dillon 
184*572ff6f6SMatthew Dillon 				ch2 = ((ch * 25) / 5) + 9600;
185*572ff6f6SMatthew Dillon 				channelSel = (ch2 * 0x4000) / 15;
186*572ff6f6SMatthew Dillon 				//ath_hal_printf(ah,
187*572ff6f6SMatthew Dillon 				//    "%s: freq=%d, ch=%d, ch2=%d, "
188*572ff6f6SMatthew Dillon 				//    "channelSel=%d\n",
189*572ff6f6SMatthew Dillon 				//    __func__, freq, ch, ch2, channelSel);
190*572ff6f6SMatthew Dillon 			}
191*572ff6f6SMatthew Dillon #endif
192*572ff6f6SMatthew Dillon 
193*572ff6f6SMatthew Dillon 			/* RefDivA setting */
194*572ff6f6SMatthew Dillon 			OS_A_REG_RMW_FIELD(ah, AR_AN_SYNTH9,
195*572ff6f6SMatthew Dillon 			    AR_AN_SYNTH9_REFDIVA, refDivA);
196*572ff6f6SMatthew Dillon 		}
197*572ff6f6SMatthew Dillon 
198*572ff6f6SMatthew Dillon 		if (!fracMode) {
199*572ff6f6SMatthew Dillon 			ndiv = (freq * (refDivA >> aModeRefSel))/60;
200*572ff6f6SMatthew Dillon 			channelSel =  ndiv & 0x1ff;
201*572ff6f6SMatthew Dillon 			channelFrac = (ndiv & 0xfffffe00) * 2;
202*572ff6f6SMatthew Dillon 			channelSel = (channelSel << 17) | channelFrac;
203*572ff6f6SMatthew Dillon 		}
204*572ff6f6SMatthew Dillon 	}
205*572ff6f6SMatthew Dillon 
206*572ff6f6SMatthew Dillon 	reg32 = reg32 | (bMode << 29) | (fracMode << 28) |
207*572ff6f6SMatthew Dillon 	    (aModeRefSel << 26) | (channelSel);
208*572ff6f6SMatthew Dillon 
209*572ff6f6SMatthew Dillon 	OS_REG_WRITE(ah, AR_PHY_SYNTH_CONTROL, reg32);
210*572ff6f6SMatthew Dillon 
211*572ff6f6SMatthew Dillon 	AH_PRIVATE(ah)->ah_curchan = chan;
212*572ff6f6SMatthew Dillon 
213*572ff6f6SMatthew Dillon 	return AH_TRUE;
214*572ff6f6SMatthew Dillon }
215*572ff6f6SMatthew Dillon 
216*572ff6f6SMatthew Dillon /*
217*572ff6f6SMatthew Dillon  * Return a reference to the requested RF Bank.
218*572ff6f6SMatthew Dillon  */
219*572ff6f6SMatthew Dillon static uint32_t *
ar9280GetRfBank(struct ath_hal * ah,int bank)220*572ff6f6SMatthew Dillon ar9280GetRfBank(struct ath_hal *ah, int bank)
221*572ff6f6SMatthew Dillon {
222*572ff6f6SMatthew Dillon 	HALDEBUG(ah, HAL_DEBUG_ANY, "%s: unknown RF Bank %d requested\n",
223*572ff6f6SMatthew Dillon 	    __func__, bank);
224*572ff6f6SMatthew Dillon 	return AH_NULL;
225*572ff6f6SMatthew Dillon }
226*572ff6f6SMatthew Dillon 
227*572ff6f6SMatthew Dillon /*
228*572ff6f6SMatthew Dillon  * Reads EEPROM header info from device structure and programs
229*572ff6f6SMatthew Dillon  * all rf registers
230*572ff6f6SMatthew Dillon  */
231*572ff6f6SMatthew Dillon static HAL_BOOL
ar9280SetRfRegs(struct ath_hal * ah,const struct ieee80211_channel * chan,uint16_t modesIndex,uint16_t * rfXpdGain)232*572ff6f6SMatthew Dillon ar9280SetRfRegs(struct ath_hal *ah, const struct ieee80211_channel *chan,
233*572ff6f6SMatthew Dillon                 uint16_t modesIndex, uint16_t *rfXpdGain)
234*572ff6f6SMatthew Dillon {
235*572ff6f6SMatthew Dillon 	return AH_TRUE;		/* nothing to do */
236*572ff6f6SMatthew Dillon }
237*572ff6f6SMatthew Dillon 
238*572ff6f6SMatthew Dillon /*
239*572ff6f6SMatthew Dillon  * Read the transmit power levels from the structures taken from EEPROM
240*572ff6f6SMatthew Dillon  * Interpolate read transmit power values for this channel
241*572ff6f6SMatthew Dillon  * Organize the transmit power values into a table for writing into the hardware
242*572ff6f6SMatthew Dillon  */
243*572ff6f6SMatthew Dillon 
244*572ff6f6SMatthew Dillon static HAL_BOOL
ar9280SetPowerTable(struct ath_hal * ah,int16_t * pPowerMin,int16_t * pPowerMax,const struct ieee80211_channel * chan,uint16_t * rfXpdGain)245*572ff6f6SMatthew Dillon ar9280SetPowerTable(struct ath_hal *ah, int16_t *pPowerMin, int16_t *pPowerMax,
246*572ff6f6SMatthew Dillon 	const struct ieee80211_channel *chan, uint16_t *rfXpdGain)
247*572ff6f6SMatthew Dillon {
248*572ff6f6SMatthew Dillon 	return AH_TRUE;
249*572ff6f6SMatthew Dillon }
250*572ff6f6SMatthew Dillon 
251*572ff6f6SMatthew Dillon #if 0
252*572ff6f6SMatthew Dillon static int16_t
253*572ff6f6SMatthew Dillon ar9280GetMinPower(struct ath_hal *ah, EXPN_DATA_PER_CHANNEL_5112 *data)
254*572ff6f6SMatthew Dillon {
255*572ff6f6SMatthew Dillon     int i, minIndex;
256*572ff6f6SMatthew Dillon     int16_t minGain,minPwr,minPcdac,retVal;
257*572ff6f6SMatthew Dillon 
258*572ff6f6SMatthew Dillon     /* Assume NUM_POINTS_XPD0 > 0 */
259*572ff6f6SMatthew Dillon     minGain = data->pDataPerXPD[0].xpd_gain;
260*572ff6f6SMatthew Dillon     for (minIndex=0,i=1; i<NUM_XPD_PER_CHANNEL; i++) {
261*572ff6f6SMatthew Dillon         if (data->pDataPerXPD[i].xpd_gain < minGain) {
262*572ff6f6SMatthew Dillon             minIndex = i;
263*572ff6f6SMatthew Dillon             minGain = data->pDataPerXPD[i].xpd_gain;
264*572ff6f6SMatthew Dillon         }
265*572ff6f6SMatthew Dillon     }
266*572ff6f6SMatthew Dillon     minPwr = data->pDataPerXPD[minIndex].pwr_t4[0];
267*572ff6f6SMatthew Dillon     minPcdac = data->pDataPerXPD[minIndex].pcdac[0];
268*572ff6f6SMatthew Dillon     for (i=1; i<NUM_POINTS_XPD0; i++) {
269*572ff6f6SMatthew Dillon         if (data->pDataPerXPD[minIndex].pwr_t4[i] < minPwr) {
270*572ff6f6SMatthew Dillon             minPwr = data->pDataPerXPD[minIndex].pwr_t4[i];
271*572ff6f6SMatthew Dillon             minPcdac = data->pDataPerXPD[minIndex].pcdac[i];
272*572ff6f6SMatthew Dillon         }
273*572ff6f6SMatthew Dillon     }
274*572ff6f6SMatthew Dillon     retVal = minPwr - (minPcdac*2);
275*572ff6f6SMatthew Dillon     return(retVal);
276*572ff6f6SMatthew Dillon }
277*572ff6f6SMatthew Dillon #endif
278*572ff6f6SMatthew Dillon 
279*572ff6f6SMatthew Dillon static HAL_BOOL
ar9280GetChannelMaxMinPower(struct ath_hal * ah,const struct ieee80211_channel * chan,int16_t * maxPow,int16_t * minPow)280*572ff6f6SMatthew Dillon ar9280GetChannelMaxMinPower(struct ath_hal *ah,
281*572ff6f6SMatthew Dillon 	const struct ieee80211_channel *chan,
282*572ff6f6SMatthew Dillon 	int16_t *maxPow, int16_t *minPow)
283*572ff6f6SMatthew Dillon {
284*572ff6f6SMatthew Dillon #if 0
285*572ff6f6SMatthew Dillon     struct ath_hal_5212 *ahp = AH5212(ah);
286*572ff6f6SMatthew Dillon     int numChannels=0,i,last;
287*572ff6f6SMatthew Dillon     int totalD, totalF,totalMin;
288*572ff6f6SMatthew Dillon     EXPN_DATA_PER_CHANNEL_5112 *data=AH_NULL;
289*572ff6f6SMatthew Dillon     EEPROM_POWER_EXPN_5112 *powerArray=AH_NULL;
290*572ff6f6SMatthew Dillon 
291*572ff6f6SMatthew Dillon     *maxPow = 0;
292*572ff6f6SMatthew Dillon     if (IS_CHAN_A(chan)) {
293*572ff6f6SMatthew Dillon         powerArray = ahp->ah_modePowerArray5112;
294*572ff6f6SMatthew Dillon         data = powerArray[headerInfo11A].pDataPerChannel;
295*572ff6f6SMatthew Dillon         numChannels = powerArray[headerInfo11A].numChannels;
296*572ff6f6SMatthew Dillon     } else if (IS_CHAN_G(chan) || IS_CHAN_108G(chan)) {
297*572ff6f6SMatthew Dillon         /* XXX - is this correct? Should we also use the same power for turbo G? */
298*572ff6f6SMatthew Dillon         powerArray = ahp->ah_modePowerArray5112;
299*572ff6f6SMatthew Dillon         data = powerArray[headerInfo11G].pDataPerChannel;
300*572ff6f6SMatthew Dillon         numChannels = powerArray[headerInfo11G].numChannels;
301*572ff6f6SMatthew Dillon     } else if (IS_CHAN_B(chan)) {
302*572ff6f6SMatthew Dillon         powerArray = ahp->ah_modePowerArray5112;
303*572ff6f6SMatthew Dillon         data = powerArray[headerInfo11B].pDataPerChannel;
304*572ff6f6SMatthew Dillon         numChannels = powerArray[headerInfo11B].numChannels;
305*572ff6f6SMatthew Dillon     } else {
306*572ff6f6SMatthew Dillon         return (AH_TRUE);
307*572ff6f6SMatthew Dillon     }
308*572ff6f6SMatthew Dillon     /* Make sure the channel is in the range of the TP values
309*572ff6f6SMatthew Dillon      *  (freq piers)
310*572ff6f6SMatthew Dillon      */
311*572ff6f6SMatthew Dillon     if ((numChannels < 1) ||
312*572ff6f6SMatthew Dillon         (chan->channel < data[0].channelValue) ||
313*572ff6f6SMatthew Dillon         (chan->channel > data[numChannels-1].channelValue))
314*572ff6f6SMatthew Dillon         return(AH_FALSE);
315*572ff6f6SMatthew Dillon 
316*572ff6f6SMatthew Dillon     /* Linearly interpolate the power value now */
317*572ff6f6SMatthew Dillon     for (last=0,i=0;
318*572ff6f6SMatthew Dillon          (i<numChannels) && (chan->channel > data[i].channelValue);
319*572ff6f6SMatthew Dillon          last=i++);
320*572ff6f6SMatthew Dillon     totalD = data[i].channelValue - data[last].channelValue;
321*572ff6f6SMatthew Dillon     if (totalD > 0) {
322*572ff6f6SMatthew Dillon         totalF = data[i].maxPower_t4 - data[last].maxPower_t4;
323*572ff6f6SMatthew Dillon         *maxPow = (int8_t) ((totalF*(chan->channel-data[last].channelValue) + data[last].maxPower_t4*totalD)/totalD);
324*572ff6f6SMatthew Dillon 
325*572ff6f6SMatthew Dillon         totalMin = ar9280GetMinPower(ah,&data[i]) - ar9280GetMinPower(ah, &data[last]);
326*572ff6f6SMatthew Dillon         *minPow = (int8_t) ((totalMin*(chan->channel-data[last].channelValue) + ar9280GetMinPower(ah, &data[last])*totalD)/totalD);
327*572ff6f6SMatthew Dillon         return (AH_TRUE);
328*572ff6f6SMatthew Dillon     } else {
329*572ff6f6SMatthew Dillon         if (chan->channel == data[i].channelValue) {
330*572ff6f6SMatthew Dillon             *maxPow = data[i].maxPower_t4;
331*572ff6f6SMatthew Dillon             *minPow = ar9280GetMinPower(ah, &data[i]);
332*572ff6f6SMatthew Dillon             return(AH_TRUE);
333*572ff6f6SMatthew Dillon         } else
334*572ff6f6SMatthew Dillon             return(AH_FALSE);
335*572ff6f6SMatthew Dillon     }
336*572ff6f6SMatthew Dillon #else
337*572ff6f6SMatthew Dillon 	*maxPow = *minPow = 0;
338*572ff6f6SMatthew Dillon 	return AH_FALSE;
339*572ff6f6SMatthew Dillon #endif
340*572ff6f6SMatthew Dillon }
341*572ff6f6SMatthew Dillon 
342*572ff6f6SMatthew Dillon /*
343*572ff6f6SMatthew Dillon  * The ordering of nfarray is thus:
344*572ff6f6SMatthew Dillon  *
345*572ff6f6SMatthew Dillon  * nfarray[0]: Chain 0 ctl
346*572ff6f6SMatthew Dillon  * nfarray[1]: Chain 1 ctl
347*572ff6f6SMatthew Dillon  * nfarray[2]: Chain 2 ctl
348*572ff6f6SMatthew Dillon  * nfarray[3]: Chain 0 ext
349*572ff6f6SMatthew Dillon  * nfarray[4]: Chain 1 ext
350*572ff6f6SMatthew Dillon  * nfarray[5]: Chain 2 ext
351*572ff6f6SMatthew Dillon  */
352*572ff6f6SMatthew Dillon static void
ar9280GetNoiseFloor(struct ath_hal * ah,int16_t nfarray[])353*572ff6f6SMatthew Dillon ar9280GetNoiseFloor(struct ath_hal *ah, int16_t nfarray[])
354*572ff6f6SMatthew Dillon {
355*572ff6f6SMatthew Dillon 	int16_t nf;
356*572ff6f6SMatthew Dillon 
357*572ff6f6SMatthew Dillon 	nf = MS(OS_REG_READ(ah, AR_PHY_CCA), AR9280_PHY_MINCCA_PWR);
358*572ff6f6SMatthew Dillon 	if (nf & 0x100)
359*572ff6f6SMatthew Dillon 		nf = 0 - ((nf ^ 0x1ff) + 1);
360*572ff6f6SMatthew Dillon 	HALDEBUG(ah, HAL_DEBUG_NFCAL,
361*572ff6f6SMatthew Dillon 	    "NF calibrated [ctl] [chain 0] is %d\n", nf);
362*572ff6f6SMatthew Dillon 	nfarray[0] = nf;
363*572ff6f6SMatthew Dillon 
364*572ff6f6SMatthew Dillon 	nf = MS(OS_REG_READ(ah, AR_PHY_CH1_CCA), AR9280_PHY_CH1_MINCCA_PWR);
365*572ff6f6SMatthew Dillon 	if (nf & 0x100)
366*572ff6f6SMatthew Dillon 		nf = 0 - ((nf ^ 0x1ff) + 1);
367*572ff6f6SMatthew Dillon 	HALDEBUG(ah, HAL_DEBUG_NFCAL,
368*572ff6f6SMatthew Dillon 	    "NF calibrated [ctl] [chain 1] is %d\n", nf);
369*572ff6f6SMatthew Dillon 	nfarray[1] = nf;
370*572ff6f6SMatthew Dillon 
371*572ff6f6SMatthew Dillon 	nf = MS(OS_REG_READ(ah, AR_PHY_EXT_CCA), AR9280_PHY_EXT_MINCCA_PWR);
372*572ff6f6SMatthew Dillon 	if (nf & 0x100)
373*572ff6f6SMatthew Dillon 		nf = 0 - ((nf ^ 0x1ff) + 1);
374*572ff6f6SMatthew Dillon 	HALDEBUG(ah, HAL_DEBUG_NFCAL,
375*572ff6f6SMatthew Dillon 	    "NF calibrated [ext] [chain 0] is %d\n", nf);
376*572ff6f6SMatthew Dillon 	nfarray[3] = nf;
377*572ff6f6SMatthew Dillon 
378*572ff6f6SMatthew Dillon 	nf = MS(OS_REG_READ(ah, AR_PHY_CH1_EXT_CCA), AR9280_PHY_CH1_EXT_MINCCA_PWR);
379*572ff6f6SMatthew Dillon 	if (nf & 0x100)
380*572ff6f6SMatthew Dillon 		nf = 0 - ((nf ^ 0x1ff) + 1);
381*572ff6f6SMatthew Dillon 	HALDEBUG(ah, HAL_DEBUG_NFCAL,
382*572ff6f6SMatthew Dillon 	    "NF calibrated [ext] [chain 1] is %d\n", nf);
383*572ff6f6SMatthew Dillon 	nfarray[4] = nf;
384*572ff6f6SMatthew Dillon 
385*572ff6f6SMatthew Dillon         /* Chain 2 - invalid */
386*572ff6f6SMatthew Dillon         nfarray[2] = 0;
387*572ff6f6SMatthew Dillon         nfarray[5] = 0;
388*572ff6f6SMatthew Dillon 
389*572ff6f6SMatthew Dillon }
390*572ff6f6SMatthew Dillon 
391*572ff6f6SMatthew Dillon /*
392*572ff6f6SMatthew Dillon  * Adjust NF based on statistical values for 5GHz frequencies.
393*572ff6f6SMatthew Dillon  * Stubbed:Not used by Fowl
394*572ff6f6SMatthew Dillon  */
395*572ff6f6SMatthew Dillon int16_t
ar9280GetNfAdjust(struct ath_hal * ah,const HAL_CHANNEL_INTERNAL * c)396*572ff6f6SMatthew Dillon ar9280GetNfAdjust(struct ath_hal *ah, const HAL_CHANNEL_INTERNAL *c)
397*572ff6f6SMatthew Dillon {
398*572ff6f6SMatthew Dillon 	return 0;
399*572ff6f6SMatthew Dillon }
400*572ff6f6SMatthew Dillon 
401*572ff6f6SMatthew Dillon /*
402*572ff6f6SMatthew Dillon  * Free memory for analog bank scratch buffers
403*572ff6f6SMatthew Dillon  */
404*572ff6f6SMatthew Dillon static void
ar9280RfDetach(struct ath_hal * ah)405*572ff6f6SMatthew Dillon ar9280RfDetach(struct ath_hal *ah)
406*572ff6f6SMatthew Dillon {
407*572ff6f6SMatthew Dillon 	struct ath_hal_5212 *ahp = AH5212(ah);
408*572ff6f6SMatthew Dillon 
409*572ff6f6SMatthew Dillon 	HALASSERT(ahp->ah_rfHal != AH_NULL);
410*572ff6f6SMatthew Dillon 	ath_hal_free(ahp->ah_rfHal);
411*572ff6f6SMatthew Dillon 	ahp->ah_rfHal = AH_NULL;
412*572ff6f6SMatthew Dillon }
413*572ff6f6SMatthew Dillon 
414*572ff6f6SMatthew Dillon HAL_BOOL
ar9280RfAttach(struct ath_hal * ah,HAL_STATUS * status)415*572ff6f6SMatthew Dillon ar9280RfAttach(struct ath_hal *ah, HAL_STATUS *status)
416*572ff6f6SMatthew Dillon {
417*572ff6f6SMatthew Dillon 	struct ath_hal_5212 *ahp = AH5212(ah);
418*572ff6f6SMatthew Dillon 	struct ar9280State *priv;
419*572ff6f6SMatthew Dillon 
420*572ff6f6SMatthew Dillon 	HALDEBUG(ah, HAL_DEBUG_ATTACH, "%s: attach AR9280 radio\n", __func__);
421*572ff6f6SMatthew Dillon 
422*572ff6f6SMatthew Dillon 	HALASSERT(ahp->ah_rfHal == AH_NULL);
423*572ff6f6SMatthew Dillon 	priv = ath_hal_malloc(sizeof(struct ar9280State));
424*572ff6f6SMatthew Dillon 	if (priv == AH_NULL) {
425*572ff6f6SMatthew Dillon 		HALDEBUG(ah, HAL_DEBUG_ANY,
426*572ff6f6SMatthew Dillon 		    "%s: cannot allocate private state\n", __func__);
427*572ff6f6SMatthew Dillon 		*status = HAL_ENOMEM;		/* XXX */
428*572ff6f6SMatthew Dillon 		return AH_FALSE;
429*572ff6f6SMatthew Dillon 	}
430*572ff6f6SMatthew Dillon 	priv->base.rfDetach		= ar9280RfDetach;
431*572ff6f6SMatthew Dillon 	priv->base.writeRegs		= ar9280WriteRegs;
432*572ff6f6SMatthew Dillon 	priv->base.getRfBank		= ar9280GetRfBank;
433*572ff6f6SMatthew Dillon 	priv->base.setChannel		= ar9280SetChannel;
434*572ff6f6SMatthew Dillon 	priv->base.setRfRegs		= ar9280SetRfRegs;
435*572ff6f6SMatthew Dillon 	priv->base.setPowerTable	= ar9280SetPowerTable;
436*572ff6f6SMatthew Dillon 	priv->base.getChannelMaxMinPower = ar9280GetChannelMaxMinPower;
437*572ff6f6SMatthew Dillon 	priv->base.getNfAdjust		= ar9280GetNfAdjust;
438*572ff6f6SMatthew Dillon 
439*572ff6f6SMatthew Dillon 	ahp->ah_pcdacTable = priv->pcdacTable;
440*572ff6f6SMatthew Dillon 	ahp->ah_pcdacTableSize = sizeof(priv->pcdacTable);
441*572ff6f6SMatthew Dillon 	ahp->ah_rfHal = &priv->base;
442*572ff6f6SMatthew Dillon 	/*
443*572ff6f6SMatthew Dillon 	 * Set noise floor adjust method; we arrange a
444*572ff6f6SMatthew Dillon 	 * direct call instead of thunking.
445*572ff6f6SMatthew Dillon 	 */
446*572ff6f6SMatthew Dillon 	AH_PRIVATE(ah)->ah_getNfAdjust = priv->base.getNfAdjust;
447*572ff6f6SMatthew Dillon 	AH_PRIVATE(ah)->ah_getNoiseFloor = ar9280GetNoiseFloor;
448*572ff6f6SMatthew Dillon 
449*572ff6f6SMatthew Dillon 	return AH_TRUE;
450*572ff6f6SMatthew Dillon }
451*572ff6f6SMatthew Dillon 
452*572ff6f6SMatthew Dillon static HAL_BOOL
ar9280RfProbe(struct ath_hal * ah)453*572ff6f6SMatthew Dillon ar9280RfProbe(struct ath_hal *ah)
454*572ff6f6SMatthew Dillon {
455*572ff6f6SMatthew Dillon 	return (AR_SREV_MERLIN(ah));
456*572ff6f6SMatthew Dillon }
457*572ff6f6SMatthew Dillon 
458*572ff6f6SMatthew Dillon AH_RF(RF9280, ar9280RfProbe, ar9280RfAttach);
459