ar2413.c revision 1.2.10.2 1 1.2.10.2 snj /*
2 1.2.10.2 snj * Copyright (c) 2002-2008 Sam Leffler, Errno Consulting
3 1.2.10.2 snj * Copyright (c) 2002-2008 Atheros Communications, Inc.
4 1.2.10.2 snj *
5 1.2.10.2 snj * Permission to use, copy, modify, and/or distribute this software for any
6 1.2.10.2 snj * purpose with or without fee is hereby granted, provided that the above
7 1.2.10.2 snj * copyright notice and this permission notice appear in all copies.
8 1.2.10.2 snj *
9 1.2.10.2 snj * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 1.2.10.2 snj * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 1.2.10.2 snj * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 1.2.10.2 snj * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 1.2.10.2 snj * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 1.2.10.2 snj * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 1.2.10.2 snj * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 1.2.10.2 snj *
17 1.2.10.2 snj * $Id: ar2413.c,v 1.2.10.2 2009/08/07 06:43:40 snj Exp $
18 1.2.10.2 snj */
19 1.2.10.2 snj #include "opt_ah.h"
20 1.2.10.2 snj
21 1.2.10.2 snj #include "ah.h"
22 1.2.10.2 snj #include "ah_internal.h"
23 1.2.10.2 snj
24 1.2.10.2 snj #include "ar5212/ar5212.h"
25 1.2.10.2 snj #include "ar5212/ar5212reg.h"
26 1.2.10.2 snj #include "ar5212/ar5212phy.h"
27 1.2.10.2 snj
28 1.2.10.2 snj #include "ah_eeprom_v3.h"
29 1.2.10.2 snj
30 1.2.10.2 snj #define AH_5212_2413
31 1.2.10.2 snj #include "ar5212/ar5212.ini"
32 1.2.10.2 snj
33 1.2.10.2 snj #define N(a) (sizeof(a)/sizeof(a[0]))
34 1.2.10.2 snj
35 1.2.10.2 snj struct ar2413State {
36 1.2.10.2 snj RF_HAL_FUNCS base; /* public state, must be first */
37 1.2.10.2 snj uint16_t pcdacTable[PWR_TABLE_SIZE_2413];
38 1.2.10.2 snj
39 1.2.10.2 snj uint32_t Bank1Data[N(ar5212Bank1_2413)];
40 1.2.10.2 snj uint32_t Bank2Data[N(ar5212Bank2_2413)];
41 1.2.10.2 snj uint32_t Bank3Data[N(ar5212Bank3_2413)];
42 1.2.10.2 snj uint32_t Bank6Data[N(ar5212Bank6_2413)];
43 1.2.10.2 snj uint32_t Bank7Data[N(ar5212Bank7_2413)];
44 1.2.10.2 snj
45 1.2.10.2 snj /*
46 1.2.10.2 snj * Private state for reduced stack usage.
47 1.2.10.2 snj */
48 1.2.10.2 snj /* filled out Vpd table for all pdGains (chanL) */
49 1.2.10.2 snj uint16_t vpdTable_L[MAX_NUM_PDGAINS_PER_CHANNEL]
50 1.2.10.2 snj [MAX_PWR_RANGE_IN_HALF_DB];
51 1.2.10.2 snj /* filled out Vpd table for all pdGains (chanR) */
52 1.2.10.2 snj uint16_t vpdTable_R[MAX_NUM_PDGAINS_PER_CHANNEL]
53 1.2.10.2 snj [MAX_PWR_RANGE_IN_HALF_DB];
54 1.2.10.2 snj /* filled out Vpd table for all pdGains (interpolated) */
55 1.2.10.2 snj uint16_t vpdTable_I[MAX_NUM_PDGAINS_PER_CHANNEL]
56 1.2.10.2 snj [MAX_PWR_RANGE_IN_HALF_DB];
57 1.2.10.2 snj };
58 1.2.10.2 snj #define AR2413(ah) ((struct ar2413State *) AH5212(ah)->ah_rfHal)
59 1.2.10.2 snj
60 1.2.10.2 snj extern void ar5212ModifyRfBuffer(uint32_t *rfBuf, uint32_t reg32,
61 1.2.10.2 snj uint32_t numBits, uint32_t firstBit, uint32_t column);
62 1.2.10.2 snj
63 1.2.10.2 snj static void
64 1.2.10.2 snj ar2413WriteRegs(struct ath_hal *ah, u_int modesIndex, u_int freqIndex,
65 1.2.10.2 snj int writes)
66 1.2.10.2 snj {
67 1.2.10.2 snj HAL_INI_WRITE_ARRAY(ah, ar5212Modes_2413, modesIndex, writes);
68 1.2.10.2 snj HAL_INI_WRITE_ARRAY(ah, ar5212Common_2413, 1, writes);
69 1.2.10.2 snj HAL_INI_WRITE_ARRAY(ah, ar5212BB_RfGain_2413, freqIndex, writes);
70 1.2.10.2 snj }
71 1.2.10.2 snj
72 1.2.10.2 snj /*
73 1.2.10.2 snj * Take the MHz channel value and set the Channel value
74 1.2.10.2 snj *
75 1.2.10.2 snj * ASSUMES: Writes enabled to analog bus
76 1.2.10.2 snj */
77 1.2.10.2 snj static HAL_BOOL
78 1.2.10.2 snj ar2413SetChannel(struct ath_hal *ah, HAL_CHANNEL_INTERNAL *chan)
79 1.2.10.2 snj {
80 1.2.10.2 snj uint32_t channelSel = 0;
81 1.2.10.2 snj uint32_t bModeSynth = 0;
82 1.2.10.2 snj uint32_t aModeRefSel = 0;
83 1.2.10.2 snj uint32_t reg32 = 0;
84 1.2.10.2 snj uint16_t freq;
85 1.2.10.2 snj
86 1.2.10.2 snj OS_MARK(ah, AH_MARK_SETCHANNEL, chan->channel);
87 1.2.10.2 snj
88 1.2.10.2 snj if (chan->channel < 4800) {
89 1.2.10.2 snj uint32_t txctl;
90 1.2.10.2 snj
91 1.2.10.2 snj if (((chan->channel - 2192) % 5) == 0) {
92 1.2.10.2 snj channelSel = ((chan->channel - 672) * 2 - 3040)/10;
93 1.2.10.2 snj bModeSynth = 0;
94 1.2.10.2 snj } else if (((chan->channel - 2224) % 5) == 0) {
95 1.2.10.2 snj channelSel = ((chan->channel - 704) * 2 - 3040) / 10;
96 1.2.10.2 snj bModeSynth = 1;
97 1.2.10.2 snj } else {
98 1.2.10.2 snj HALDEBUG(ah, HAL_DEBUG_ANY,
99 1.2.10.2 snj "%s: invalid channel %u MHz\n",
100 1.2.10.2 snj __func__, chan->channel);
101 1.2.10.2 snj return AH_FALSE;
102 1.2.10.2 snj }
103 1.2.10.2 snj
104 1.2.10.2 snj channelSel = (channelSel << 2) & 0xff;
105 1.2.10.2 snj channelSel = ath_hal_reverseBits(channelSel, 8);
106 1.2.10.2 snj
107 1.2.10.2 snj txctl = OS_REG_READ(ah, AR_PHY_CCK_TX_CTRL);
108 1.2.10.2 snj if (chan->channel == 2484) {
109 1.2.10.2 snj /* Enable channel spreading for channel 14 */
110 1.2.10.2 snj OS_REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
111 1.2.10.2 snj txctl | AR_PHY_CCK_TX_CTRL_JAPAN);
112 1.2.10.2 snj } else {
113 1.2.10.2 snj OS_REG_WRITE(ah, AR_PHY_CCK_TX_CTRL,
114 1.2.10.2 snj txctl &~ AR_PHY_CCK_TX_CTRL_JAPAN);
115 1.2.10.2 snj }
116 1.2.10.2 snj } else if (((chan->channel % 5) == 2) && (chan->channel <= 5435)) {
117 1.2.10.2 snj freq = chan->channel - 2; /* Align to even 5MHz raster */
118 1.2.10.2 snj channelSel = ath_hal_reverseBits(
119 1.2.10.2 snj (uint32_t)(((freq - 4800)*10)/25 + 1), 8);
120 1.2.10.2 snj aModeRefSel = ath_hal_reverseBits(0, 2);
121 1.2.10.2 snj } else if ((chan->channel % 20) == 0 && chan->channel >= 5120) {
122 1.2.10.2 snj channelSel = ath_hal_reverseBits(
123 1.2.10.2 snj ((chan->channel - 4800) / 20 << 2), 8);
124 1.2.10.2 snj aModeRefSel = ath_hal_reverseBits(3, 2);
125 1.2.10.2 snj } else if ((chan->channel % 10) == 0) {
126 1.2.10.2 snj channelSel = ath_hal_reverseBits(
127 1.2.10.2 snj ((chan->channel - 4800) / 10 << 1), 8);
128 1.2.10.2 snj aModeRefSel = ath_hal_reverseBits(2, 2);
129 1.2.10.2 snj } else if ((chan->channel % 5) == 0) {
130 1.2.10.2 snj channelSel = ath_hal_reverseBits(
131 1.2.10.2 snj (chan->channel - 4800) / 5, 8);
132 1.2.10.2 snj aModeRefSel = ath_hal_reverseBits(1, 2);
133 1.2.10.2 snj } else {
134 1.2.10.2 snj HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid channel %u MHz\n",
135 1.2.10.2 snj __func__, chan->channel);
136 1.2.10.2 snj return AH_FALSE;
137 1.2.10.2 snj }
138 1.2.10.2 snj
139 1.2.10.2 snj reg32 = (channelSel << 4) | (aModeRefSel << 2) | (bModeSynth << 1) |
140 1.2.10.2 snj (1 << 12) | 0x1;
141 1.2.10.2 snj OS_REG_WRITE(ah, AR_PHY(0x27), reg32 & 0xff);
142 1.2.10.2 snj
143 1.2.10.2 snj reg32 >>= 8;
144 1.2.10.2 snj OS_REG_WRITE(ah, AR_PHY(0x36), reg32 & 0x7f);
145 1.2.10.2 snj
146 1.2.10.2 snj AH_PRIVATE(ah)->ah_curchan = chan;
147 1.2.10.2 snj
148 1.2.10.2 snj return AH_TRUE;
149 1.2.10.2 snj }
150 1.2.10.2 snj
151 1.2.10.2 snj /*
152 1.2.10.2 snj * Reads EEPROM header info from device structure and programs
153 1.2.10.2 snj * all rf registers
154 1.2.10.2 snj *
155 1.2.10.2 snj * REQUIRES: Access to the analog rf device
156 1.2.10.2 snj */
157 1.2.10.2 snj static HAL_BOOL
158 1.2.10.2 snj ar2413SetRfRegs(struct ath_hal *ah, HAL_CHANNEL_INTERNAL *chan, uint16_t modesIndex, uint16_t *rfXpdGain)
159 1.2.10.2 snj {
160 1.2.10.2 snj #define RF_BANK_SETUP(_priv, _ix, _col) do { \
161 1.2.10.2 snj int i; \
162 1.2.10.2 snj for (i = 0; i < N(ar5212Bank##_ix##_2413); i++) \
163 1.2.10.2 snj (_priv)->Bank##_ix##Data[i] = ar5212Bank##_ix##_2413[i][_col];\
164 1.2.10.2 snj } while (0)
165 1.2.10.2 snj struct ath_hal_5212 *ahp = AH5212(ah);
166 1.2.10.2 snj const HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom;
167 1.2.10.2 snj uint16_t ob2GHz = 0, db2GHz = 0;
168 1.2.10.2 snj struct ar2413State *priv = AR2413(ah);
169 1.2.10.2 snj int regWrites = 0;
170 1.2.10.2 snj
171 1.2.10.2 snj HALDEBUG(ah, HAL_DEBUG_RFPARAM,
172 1.2.10.2 snj "%s: chan 0x%x flag 0x%x modesIndex 0x%x\n",
173 1.2.10.2 snj __func__, chan->channel, chan->channelFlags, modesIndex);
174 1.2.10.2 snj
175 1.2.10.2 snj HALASSERT(priv);
176 1.2.10.2 snj
177 1.2.10.2 snj /* Setup rf parameters */
178 1.2.10.2 snj switch (chan->channelFlags & CHANNEL_ALL) {
179 1.2.10.2 snj case CHANNEL_B:
180 1.2.10.2 snj ob2GHz = ee->ee_obFor24;
181 1.2.10.2 snj db2GHz = ee->ee_dbFor24;
182 1.2.10.2 snj break;
183 1.2.10.2 snj case CHANNEL_G:
184 1.2.10.2 snj case CHANNEL_108G:
185 1.2.10.2 snj ob2GHz = ee->ee_obFor24g;
186 1.2.10.2 snj db2GHz = ee->ee_dbFor24g;
187 1.2.10.2 snj break;
188 1.2.10.2 snj default:
189 1.2.10.2 snj HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid channel flags 0x%x\n",
190 1.2.10.2 snj __func__, chan->channelFlags);
191 1.2.10.2 snj return AH_FALSE;
192 1.2.10.2 snj }
193 1.2.10.2 snj
194 1.2.10.2 snj /* Bank 1 Write */
195 1.2.10.2 snj RF_BANK_SETUP(priv, 1, 1);
196 1.2.10.2 snj
197 1.2.10.2 snj /* Bank 2 Write */
198 1.2.10.2 snj RF_BANK_SETUP(priv, 2, modesIndex);
199 1.2.10.2 snj
200 1.2.10.2 snj /* Bank 3 Write */
201 1.2.10.2 snj RF_BANK_SETUP(priv, 3, modesIndex);
202 1.2.10.2 snj
203 1.2.10.2 snj /* Bank 6 Write */
204 1.2.10.2 snj RF_BANK_SETUP(priv, 6, modesIndex);
205 1.2.10.2 snj
206 1.2.10.2 snj ar5212ModifyRfBuffer(priv->Bank6Data, ob2GHz, 3, 168, 0);
207 1.2.10.2 snj ar5212ModifyRfBuffer(priv->Bank6Data, db2GHz, 3, 165, 0);
208 1.2.10.2 snj
209 1.2.10.2 snj /* Bank 7 Setup */
210 1.2.10.2 snj RF_BANK_SETUP(priv, 7, modesIndex);
211 1.2.10.2 snj
212 1.2.10.2 snj /* Write Analog registers */
213 1.2.10.2 snj HAL_INI_WRITE_BANK(ah, ar5212Bank1_2413, priv->Bank1Data, regWrites);
214 1.2.10.2 snj HAL_INI_WRITE_BANK(ah, ar5212Bank2_2413, priv->Bank2Data, regWrites);
215 1.2.10.2 snj HAL_INI_WRITE_BANK(ah, ar5212Bank3_2413, priv->Bank3Data, regWrites);
216 1.2.10.2 snj HAL_INI_WRITE_BANK(ah, ar5212Bank6_2413, priv->Bank6Data, regWrites);
217 1.2.10.2 snj HAL_INI_WRITE_BANK(ah, ar5212Bank7_2413, priv->Bank7Data, regWrites);
218 1.2.10.2 snj
219 1.2.10.2 snj /* Now that we have reprogrammed rfgain value, clear the flag. */
220 1.2.10.2 snj ahp->ah_rfgainState = HAL_RFGAIN_INACTIVE;
221 1.2.10.2 snj
222 1.2.10.2 snj return AH_TRUE;
223 1.2.10.2 snj #undef RF_BANK_SETUP
224 1.2.10.2 snj }
225 1.2.10.2 snj
226 1.2.10.2 snj /*
227 1.2.10.2 snj * Return a reference to the requested RF Bank.
228 1.2.10.2 snj */
229 1.2.10.2 snj static uint32_t *
230 1.2.10.2 snj ar2413GetRfBank(struct ath_hal *ah, int bank)
231 1.2.10.2 snj {
232 1.2.10.2 snj struct ar2413State *priv = AR2413(ah);
233 1.2.10.2 snj
234 1.2.10.2 snj HALASSERT(priv != AH_NULL);
235 1.2.10.2 snj switch (bank) {
236 1.2.10.2 snj case 1: return priv->Bank1Data;
237 1.2.10.2 snj case 2: return priv->Bank2Data;
238 1.2.10.2 snj case 3: return priv->Bank3Data;
239 1.2.10.2 snj case 6: return priv->Bank6Data;
240 1.2.10.2 snj case 7: return priv->Bank7Data;
241 1.2.10.2 snj }
242 1.2.10.2 snj HALDEBUG(ah, HAL_DEBUG_ANY, "%s: unknown RF Bank %d requested\n",
243 1.2.10.2 snj __func__, bank);
244 1.2.10.2 snj return AH_NULL;
245 1.2.10.2 snj }
246 1.2.10.2 snj
247 1.2.10.2 snj /*
248 1.2.10.2 snj * Return indices surrounding the value in sorted integer lists.
249 1.2.10.2 snj *
250 1.2.10.2 snj * NB: the input list is assumed to be sorted in ascending order
251 1.2.10.2 snj */
252 1.2.10.2 snj static void
253 1.2.10.2 snj GetLowerUpperIndex(int16_t v, const uint16_t *lp, uint16_t listSize,
254 1.2.10.2 snj uint32_t *vlo, uint32_t *vhi)
255 1.2.10.2 snj {
256 1.2.10.2 snj int16_t target = v;
257 1.2.10.2 snj const uint16_t *ep = lp+listSize;
258 1.2.10.2 snj const uint16_t *tp;
259 1.2.10.2 snj
260 1.2.10.2 snj /*
261 1.2.10.2 snj * Check first and last elements for out-of-bounds conditions.
262 1.2.10.2 snj */
263 1.2.10.2 snj if (target < lp[0]) {
264 1.2.10.2 snj *vlo = *vhi = 0;
265 1.2.10.2 snj return;
266 1.2.10.2 snj }
267 1.2.10.2 snj if (target >= ep[-1]) {
268 1.2.10.2 snj *vlo = *vhi = listSize - 1;
269 1.2.10.2 snj return;
270 1.2.10.2 snj }
271 1.2.10.2 snj
272 1.2.10.2 snj /* look for value being near or between 2 values in list */
273 1.2.10.2 snj for (tp = lp; tp < ep; tp++) {
274 1.2.10.2 snj /*
275 1.2.10.2 snj * If value is close to the current value of the list
276 1.2.10.2 snj * then target is not between values, it is one of the values
277 1.2.10.2 snj */
278 1.2.10.2 snj if (*tp == target) {
279 1.2.10.2 snj *vlo = *vhi = tp - (const uint16_t *) lp;
280 1.2.10.2 snj return;
281 1.2.10.2 snj }
282 1.2.10.2 snj /*
283 1.2.10.2 snj * Look for value being between current value and next value
284 1.2.10.2 snj * if so return these 2 values
285 1.2.10.2 snj */
286 1.2.10.2 snj if (target < tp[1]) {
287 1.2.10.2 snj *vlo = tp - (const uint16_t *) lp;
288 1.2.10.2 snj *vhi = *vlo + 1;
289 1.2.10.2 snj return;
290 1.2.10.2 snj }
291 1.2.10.2 snj }
292 1.2.10.2 snj }
293 1.2.10.2 snj
294 1.2.10.2 snj /*
295 1.2.10.2 snj * Fill the Vpdlist for indices Pmax-Pmin
296 1.2.10.2 snj */
297 1.2.10.2 snj static HAL_BOOL
298 1.2.10.2 snj ar2413FillVpdTable(uint32_t pdGainIdx, int16_t Pmin, int16_t Pmax,
299 1.2.10.2 snj const int16_t *pwrList, const uint16_t *VpdList,
300 1.2.10.2 snj uint16_t numIntercepts, uint16_t retVpdList[][64])
301 1.2.10.2 snj {
302 1.2.10.2 snj uint16_t ii, jj, kk;
303 1.2.10.2 snj int16_t currPwr = (int16_t)(2*Pmin);
304 1.2.10.2 snj /* since Pmin is pwr*2 and pwrList is 4*pwr */
305 1.2.10.2 snj uint32_t idxL = 0, idxR = 0;
306 1.2.10.2 snj
307 1.2.10.2 snj ii = 0;
308 1.2.10.2 snj jj = 0;
309 1.2.10.2 snj
310 1.2.10.2 snj if (numIntercepts < 2)
311 1.2.10.2 snj return AH_FALSE;
312 1.2.10.2 snj
313 1.2.10.2 snj while (ii <= (uint16_t)(Pmax - Pmin)) {
314 1.2.10.2 snj GetLowerUpperIndex(currPwr, (const uint16_t *) pwrList,
315 1.2.10.2 snj numIntercepts, &(idxL), &(idxR));
316 1.2.10.2 snj if (idxR < 1)
317 1.2.10.2 snj idxR = 1; /* extrapolate below */
318 1.2.10.2 snj if (idxL == (uint32_t)(numIntercepts - 1))
319 1.2.10.2 snj idxL = numIntercepts - 2; /* extrapolate above */
320 1.2.10.2 snj if (pwrList[idxL] == pwrList[idxR])
321 1.2.10.2 snj kk = VpdList[idxL];
322 1.2.10.2 snj else
323 1.2.10.2 snj kk = (uint16_t)
324 1.2.10.2 snj (((currPwr - pwrList[idxL])*VpdList[idxR]+
325 1.2.10.2 snj (pwrList[idxR] - currPwr)*VpdList[idxL])/
326 1.2.10.2 snj (pwrList[idxR] - pwrList[idxL]));
327 1.2.10.2 snj retVpdList[pdGainIdx][ii] = kk;
328 1.2.10.2 snj ii++;
329 1.2.10.2 snj currPwr += 2; /* half dB steps */
330 1.2.10.2 snj }
331 1.2.10.2 snj
332 1.2.10.2 snj return AH_TRUE;
333 1.2.10.2 snj }
334 1.2.10.2 snj
335 1.2.10.2 snj /*
336 1.2.10.2 snj * Returns interpolated or the scaled up interpolated value
337 1.2.10.2 snj */
338 1.2.10.2 snj static int16_t
339 1.2.10.2 snj interpolate_signed(uint16_t target, uint16_t srcLeft, uint16_t srcRight,
340 1.2.10.2 snj int16_t targetLeft, int16_t targetRight)
341 1.2.10.2 snj {
342 1.2.10.2 snj int16_t rv;
343 1.2.10.2 snj
344 1.2.10.2 snj if (srcRight != srcLeft) {
345 1.2.10.2 snj rv = ((target - srcLeft)*targetRight +
346 1.2.10.2 snj (srcRight - target)*targetLeft) / (srcRight - srcLeft);
347 1.2.10.2 snj } else {
348 1.2.10.2 snj rv = targetLeft;
349 1.2.10.2 snj }
350 1.2.10.2 snj return rv;
351 1.2.10.2 snj }
352 1.2.10.2 snj
353 1.2.10.2 snj /*
354 1.2.10.2 snj * Uses the data points read from EEPROM to reconstruct the pdadc power table
355 1.2.10.2 snj * Called by ar2413SetPowerTable()
356 1.2.10.2 snj */
357 1.2.10.2 snj static int
358 1.2.10.2 snj ar2413getGainBoundariesAndPdadcsForPowers(struct ath_hal *ah, uint16_t channel,
359 1.2.10.2 snj const RAW_DATA_STRUCT_2413 *pRawDataset,
360 1.2.10.2 snj uint16_t pdGainOverlap_t2,
361 1.2.10.2 snj int16_t *pMinCalPower, uint16_t pPdGainBoundaries[],
362 1.2.10.2 snj uint16_t pPdGainValues[], uint16_t pPDADCValues[])
363 1.2.10.2 snj {
364 1.2.10.2 snj struct ar2413State *priv = AR2413(ah);
365 1.2.10.2 snj #define VpdTable_L priv->vpdTable_L
366 1.2.10.2 snj #define VpdTable_R priv->vpdTable_R
367 1.2.10.2 snj #define VpdTable_I priv->vpdTable_I
368 1.2.10.2 snj uint32_t ii, jj, kk;
369 1.2.10.2 snj int32_t ss;/* potentially -ve index for taking care of pdGainOverlap */
370 1.2.10.2 snj uint32_t idxL = 0, idxR = 0;
371 1.2.10.2 snj uint32_t numPdGainsUsed = 0;
372 1.2.10.2 snj /*
373 1.2.10.2 snj * If desired to support -ve power levels in future, just
374 1.2.10.2 snj * change pwr_I_0 to signed 5-bits.
375 1.2.10.2 snj */
376 1.2.10.2 snj int16_t Pmin_t2[MAX_NUM_PDGAINS_PER_CHANNEL];
377 1.2.10.2 snj /* to accomodate -ve power levels later on. */
378 1.2.10.2 snj int16_t Pmax_t2[MAX_NUM_PDGAINS_PER_CHANNEL];
379 1.2.10.2 snj /* to accomodate -ve power levels later on */
380 1.2.10.2 snj uint16_t numVpd = 0;
381 1.2.10.2 snj uint16_t Vpd_step;
382 1.2.10.2 snj int16_t tmpVal ;
383 1.2.10.2 snj uint32_t sizeCurrVpdTable, maxIndex, tgtIndex;
384 1.2.10.2 snj
385 1.2.10.2 snj /* Get upper lower index */
386 1.2.10.2 snj GetLowerUpperIndex(channel, pRawDataset->pChannels,
387 1.2.10.2 snj pRawDataset->numChannels, &(idxL), &(idxR));
388 1.2.10.2 snj
389 1.2.10.2 snj for (ii = 0; ii < MAX_NUM_PDGAINS_PER_CHANNEL; ii++) {
390 1.2.10.2 snj jj = MAX_NUM_PDGAINS_PER_CHANNEL - ii - 1;
391 1.2.10.2 snj /* work backwards 'cause highest pdGain for lowest power */
392 1.2.10.2 snj numVpd = pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].numVpd;
393 1.2.10.2 snj if (numVpd > 0) {
394 1.2.10.2 snj pPdGainValues[numPdGainsUsed] = pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].pd_gain;
395 1.2.10.2 snj Pmin_t2[numPdGainsUsed] = pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].pwr_t4[0];
396 1.2.10.2 snj if (Pmin_t2[numPdGainsUsed] >pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[0]) {
397 1.2.10.2 snj Pmin_t2[numPdGainsUsed] = pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[0];
398 1.2.10.2 snj }
399 1.2.10.2 snj Pmin_t2[numPdGainsUsed] = (int16_t)
400 1.2.10.2 snj (Pmin_t2[numPdGainsUsed] / 2);
401 1.2.10.2 snj Pmax_t2[numPdGainsUsed] = pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].pwr_t4[numVpd-1];
402 1.2.10.2 snj if (Pmax_t2[numPdGainsUsed] > pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[numVpd-1])
403 1.2.10.2 snj Pmax_t2[numPdGainsUsed] =
404 1.2.10.2 snj pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[numVpd-1];
405 1.2.10.2 snj Pmax_t2[numPdGainsUsed] = (int16_t)(Pmax_t2[numPdGainsUsed] / 2);
406 1.2.10.2 snj ar2413FillVpdTable(
407 1.2.10.2 snj numPdGainsUsed, Pmin_t2[numPdGainsUsed], Pmax_t2[numPdGainsUsed],
408 1.2.10.2 snj &(pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].pwr_t4[0]),
409 1.2.10.2 snj &(pRawDataset->pDataPerChannel[idxL].pDataPerPDGain[jj].Vpd[0]), numVpd, VpdTable_L
410 1.2.10.2 snj );
411 1.2.10.2 snj ar2413FillVpdTable(
412 1.2.10.2 snj numPdGainsUsed, Pmin_t2[numPdGainsUsed], Pmax_t2[numPdGainsUsed],
413 1.2.10.2 snj &(pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].pwr_t4[0]),
414 1.2.10.2 snj &(pRawDataset->pDataPerChannel[idxR].pDataPerPDGain[jj].Vpd[0]), numVpd, VpdTable_R
415 1.2.10.2 snj );
416 1.2.10.2 snj for (kk = 0; kk < (uint16_t)(Pmax_t2[numPdGainsUsed] - Pmin_t2[numPdGainsUsed]); kk++) {
417 1.2.10.2 snj VpdTable_I[numPdGainsUsed][kk] =
418 1.2.10.2 snj interpolate_signed(
419 1.2.10.2 snj channel, pRawDataset->pChannels[idxL], pRawDataset->pChannels[idxR],
420 1.2.10.2 snj (int16_t)VpdTable_L[numPdGainsUsed][kk], (int16_t)VpdTable_R[numPdGainsUsed][kk]);
421 1.2.10.2 snj }
422 1.2.10.2 snj /* fill VpdTable_I for this pdGain */
423 1.2.10.2 snj numPdGainsUsed++;
424 1.2.10.2 snj }
425 1.2.10.2 snj /* if this pdGain is used */
426 1.2.10.2 snj }
427 1.2.10.2 snj
428 1.2.10.2 snj *pMinCalPower = Pmin_t2[0];
429 1.2.10.2 snj kk = 0; /* index for the final table */
430 1.2.10.2 snj for (ii = 0; ii < numPdGainsUsed; ii++) {
431 1.2.10.2 snj if (ii == (numPdGainsUsed - 1))
432 1.2.10.2 snj pPdGainBoundaries[ii] = Pmax_t2[ii] +
433 1.2.10.2 snj PD_GAIN_BOUNDARY_STRETCH_IN_HALF_DB;
434 1.2.10.2 snj else
435 1.2.10.2 snj pPdGainBoundaries[ii] = (uint16_t)
436 1.2.10.2 snj ((Pmax_t2[ii] + Pmin_t2[ii+1]) / 2 );
437 1.2.10.2 snj if (pPdGainBoundaries[ii] > 63) {
438 1.2.10.2 snj HALDEBUG(ah, HAL_DEBUG_ANY,
439 1.2.10.2 snj "%s: clamp pPdGainBoundaries[%d] %d\n",
440 1.2.10.2 snj __func__, ii, pPdGainBoundaries[ii]);/*XXX*/
441 1.2.10.2 snj pPdGainBoundaries[ii] = 63;
442 1.2.10.2 snj }
443 1.2.10.2 snj
444 1.2.10.2 snj /* Find starting index for this pdGain */
445 1.2.10.2 snj if (ii == 0)
446 1.2.10.2 snj ss = 0; /* for the first pdGain, start from index 0 */
447 1.2.10.2 snj else
448 1.2.10.2 snj ss = (pPdGainBoundaries[ii-1] - Pmin_t2[ii]) -
449 1.2.10.2 snj pdGainOverlap_t2;
450 1.2.10.2 snj Vpd_step = (uint16_t)(VpdTable_I[ii][1] - VpdTable_I[ii][0]);
451 1.2.10.2 snj Vpd_step = (uint16_t)((Vpd_step < 1) ? 1 : Vpd_step);
452 1.2.10.2 snj /*
453 1.2.10.2 snj *-ve ss indicates need to extrapolate data below for this pdGain
454 1.2.10.2 snj */
455 1.2.10.2 snj while (ss < 0) {
456 1.2.10.2 snj tmpVal = (int16_t)(VpdTable_I[ii][0] + ss*Vpd_step);
457 1.2.10.2 snj pPDADCValues[kk++] = (uint16_t)((tmpVal < 0) ? 0 : tmpVal);
458 1.2.10.2 snj ss++;
459 1.2.10.2 snj }
460 1.2.10.2 snj
461 1.2.10.2 snj sizeCurrVpdTable = Pmax_t2[ii] - Pmin_t2[ii];
462 1.2.10.2 snj tgtIndex = pPdGainBoundaries[ii] + pdGainOverlap_t2 - Pmin_t2[ii];
463 1.2.10.2 snj maxIndex = (tgtIndex < sizeCurrVpdTable) ? tgtIndex : sizeCurrVpdTable;
464 1.2.10.2 snj
465 1.2.10.2 snj while (ss < (int16_t)maxIndex)
466 1.2.10.2 snj pPDADCValues[kk++] = VpdTable_I[ii][ss++];
467 1.2.10.2 snj
468 1.2.10.2 snj Vpd_step = (uint16_t)(VpdTable_I[ii][sizeCurrVpdTable-1] -
469 1.2.10.2 snj VpdTable_I[ii][sizeCurrVpdTable-2]);
470 1.2.10.2 snj Vpd_step = (uint16_t)((Vpd_step < 1) ? 1 : Vpd_step);
471 1.2.10.2 snj /*
472 1.2.10.2 snj * for last gain, pdGainBoundary == Pmax_t2, so will
473 1.2.10.2 snj * have to extrapolate
474 1.2.10.2 snj */
475 1.2.10.2 snj if (tgtIndex > maxIndex) { /* need to extrapolate above */
476 1.2.10.2 snj while(ss < (int16_t)tgtIndex) {
477 1.2.10.2 snj tmpVal = (uint16_t)
478 1.2.10.2 snj (VpdTable_I[ii][sizeCurrVpdTable-1] +
479 1.2.10.2 snj (ss-maxIndex)*Vpd_step);
480 1.2.10.2 snj pPDADCValues[kk++] = (tmpVal > 127) ?
481 1.2.10.2 snj 127 : tmpVal;
482 1.2.10.2 snj ss++;
483 1.2.10.2 snj }
484 1.2.10.2 snj } /* extrapolated above */
485 1.2.10.2 snj } /* for all pdGainUsed */
486 1.2.10.2 snj
487 1.2.10.2 snj while (ii < MAX_NUM_PDGAINS_PER_CHANNEL) {
488 1.2.10.2 snj pPdGainBoundaries[ii] = pPdGainBoundaries[ii-1];
489 1.2.10.2 snj ii++;
490 1.2.10.2 snj }
491 1.2.10.2 snj while (kk < 128) {
492 1.2.10.2 snj pPDADCValues[kk] = pPDADCValues[kk-1];
493 1.2.10.2 snj kk++;
494 1.2.10.2 snj }
495 1.2.10.2 snj
496 1.2.10.2 snj return numPdGainsUsed;
497 1.2.10.2 snj #undef VpdTable_L
498 1.2.10.2 snj #undef VpdTable_R
499 1.2.10.2 snj #undef VpdTable_I
500 1.2.10.2 snj }
501 1.2.10.2 snj
502 1.2.10.2 snj static HAL_BOOL
503 1.2.10.2 snj ar2413SetPowerTable(struct ath_hal *ah,
504 1.2.10.2 snj int16_t *minPower, int16_t *maxPower, HAL_CHANNEL_INTERNAL *chan,
505 1.2.10.2 snj uint16_t *rfXpdGain)
506 1.2.10.2 snj {
507 1.2.10.2 snj struct ath_hal_5212 *ahp = AH5212(ah);
508 1.2.10.2 snj const HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom;
509 1.2.10.2 snj const RAW_DATA_STRUCT_2413 *pRawDataset = AH_NULL;
510 1.2.10.2 snj uint16_t pdGainOverlap_t2;
511 1.2.10.2 snj int16_t minCalPower2413_t2;
512 1.2.10.2 snj uint16_t *pdadcValues = ahp->ah_pcdacTable;
513 1.2.10.2 snj uint16_t gainBoundaries[4];
514 1.2.10.2 snj uint32_t reg32, regoffset;
515 1.2.10.2 snj int i, numPdGainsUsed;
516 1.2.10.2 snj #ifndef AH_USE_INIPDGAIN
517 1.2.10.2 snj uint32_t tpcrg1;
518 1.2.10.2 snj #endif
519 1.2.10.2 snj
520 1.2.10.2 snj HALDEBUG(ah, HAL_DEBUG_RFPARAM, "%s: chan 0x%x flag 0x%x\n",
521 1.2.10.2 snj __func__, chan->channel,chan->channelFlags);
522 1.2.10.2 snj
523 1.2.10.2 snj if (IS_CHAN_G(chan) || IS_CHAN_108G(chan))
524 1.2.10.2 snj pRawDataset = &ee->ee_rawDataset2413[headerInfo11G];
525 1.2.10.2 snj else if (IS_CHAN_B(chan))
526 1.2.10.2 snj pRawDataset = &ee->ee_rawDataset2413[headerInfo11B];
527 1.2.10.2 snj else {
528 1.2.10.2 snj HALDEBUG(ah, HAL_DEBUG_ANY, "%s: illegal mode\n", __func__);
529 1.2.10.2 snj return AH_FALSE;
530 1.2.10.2 snj }
531 1.2.10.2 snj
532 1.2.10.2 snj pdGainOverlap_t2 = (uint16_t) SM(OS_REG_READ(ah, AR_PHY_TPCRG5),
533 1.2.10.2 snj AR_PHY_TPCRG5_PD_GAIN_OVERLAP);
534 1.2.10.2 snj
535 1.2.10.2 snj numPdGainsUsed = ar2413getGainBoundariesAndPdadcsForPowers(ah,
536 1.2.10.2 snj chan->channel, pRawDataset, pdGainOverlap_t2,
537 1.2.10.2 snj &minCalPower2413_t2,gainBoundaries, rfXpdGain, pdadcValues);
538 1.2.10.2 snj HALASSERT(1 <= numPdGainsUsed && numPdGainsUsed <= 3);
539 1.2.10.2 snj
540 1.2.10.2 snj #ifdef AH_USE_INIPDGAIN
541 1.2.10.2 snj /*
542 1.2.10.2 snj * Use pd_gains curve from eeprom; Atheros always uses
543 1.2.10.2 snj * the default curve from the ini file but some vendors
544 1.2.10.2 snj * (e.g. Zcomax) want to override this curve and not
545 1.2.10.2 snj * honoring their settings results in tx power 5dBm low.
546 1.2.10.2 snj */
547 1.2.10.2 snj OS_REG_RMW_FIELD(ah, AR_PHY_TPCRG1, AR_PHY_TPCRG1_NUM_PD_GAIN,
548 1.2.10.2 snj (pRawDataset->pDataPerChannel[0].numPdGains - 1));
549 1.2.10.2 snj #else
550 1.2.10.2 snj tpcrg1 = OS_REG_READ(ah, AR_PHY_TPCRG1);
551 1.2.10.2 snj tpcrg1 = (tpcrg1 &~ AR_PHY_TPCRG1_NUM_PD_GAIN)
552 1.2.10.2 snj | SM(numPdGainsUsed-1, AR_PHY_TPCRG1_NUM_PD_GAIN);
553 1.2.10.2 snj switch (numPdGainsUsed) {
554 1.2.10.2 snj case 3:
555 1.2.10.2 snj tpcrg1 &= ~AR_PHY_TPCRG1_PDGAIN_SETTING3;
556 1.2.10.2 snj tpcrg1 |= SM(rfXpdGain[2], AR_PHY_TPCRG1_PDGAIN_SETTING3);
557 1.2.10.2 snj /* fall thru... */
558 1.2.10.2 snj case 2:
559 1.2.10.2 snj tpcrg1 &= ~AR_PHY_TPCRG1_PDGAIN_SETTING2;
560 1.2.10.2 snj tpcrg1 |= SM(rfXpdGain[1], AR_PHY_TPCRG1_PDGAIN_SETTING2);
561 1.2.10.2 snj /* fall thru... */
562 1.2.10.2 snj case 1:
563 1.2.10.2 snj tpcrg1 &= ~AR_PHY_TPCRG1_PDGAIN_SETTING1;
564 1.2.10.2 snj tpcrg1 |= SM(rfXpdGain[0], AR_PHY_TPCRG1_PDGAIN_SETTING1);
565 1.2.10.2 snj break;
566 1.2.10.2 snj }
567 1.2.10.2 snj #ifdef AH_DEBUG
568 1.2.10.2 snj if (tpcrg1 != OS_REG_READ(ah, AR_PHY_TPCRG1))
569 1.2.10.2 snj HALDEBUG(ah, HAL_DEBUG_RFPARAM, "%s: using non-default "
570 1.2.10.2 snj "pd_gains (default 0x%x, calculated 0x%x)\n",
571 1.2.10.2 snj __func__, OS_REG_READ(ah, AR_PHY_TPCRG1), tpcrg1);
572 1.2.10.2 snj #endif
573 1.2.10.2 snj OS_REG_WRITE(ah, AR_PHY_TPCRG1, tpcrg1);
574 1.2.10.2 snj #endif
575 1.2.10.2 snj
576 1.2.10.2 snj /*
577 1.2.10.2 snj * Note the pdadc table may not start at 0 dBm power, could be
578 1.2.10.2 snj * negative or greater than 0. Need to offset the power
579 1.2.10.2 snj * values by the amount of minPower for griffin
580 1.2.10.2 snj */
581 1.2.10.2 snj if (minCalPower2413_t2 != 0)
582 1.2.10.2 snj ahp->ah_txPowerIndexOffset = (int16_t)(0 - minCalPower2413_t2);
583 1.2.10.2 snj else
584 1.2.10.2 snj ahp->ah_txPowerIndexOffset = 0;
585 1.2.10.2 snj
586 1.2.10.2 snj /* Finally, write the power values into the baseband power table */
587 1.2.10.2 snj regoffset = 0x9800 + (672 <<2); /* beginning of pdadc table in griffin */
588 1.2.10.2 snj for (i = 0; i < 32; i++) {
589 1.2.10.2 snj reg32 = ((pdadcValues[4*i + 0] & 0xFF) << 0) |
590 1.2.10.2 snj ((pdadcValues[4*i + 1] & 0xFF) << 8) |
591 1.2.10.2 snj ((pdadcValues[4*i + 2] & 0xFF) << 16) |
592 1.2.10.2 snj ((pdadcValues[4*i + 3] & 0xFF) << 24) ;
593 1.2.10.2 snj OS_REG_WRITE(ah, regoffset, reg32);
594 1.2.10.2 snj regoffset += 4;
595 1.2.10.2 snj }
596 1.2.10.2 snj
597 1.2.10.2 snj OS_REG_WRITE(ah, AR_PHY_TPCRG5,
598 1.2.10.2 snj SM(pdGainOverlap_t2, AR_PHY_TPCRG5_PD_GAIN_OVERLAP) |
599 1.2.10.2 snj SM(gainBoundaries[0], AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_1) |
600 1.2.10.2 snj SM(gainBoundaries[1], AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_2) |
601 1.2.10.2 snj SM(gainBoundaries[2], AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_3) |
602 1.2.10.2 snj SM(gainBoundaries[3], AR_PHY_TPCRG5_PD_GAIN_BOUNDARY_4));
603 1.2.10.2 snj
604 1.2.10.2 snj return AH_TRUE;
605 1.2.10.2 snj }
606 1.2.10.2 snj
607 1.2.10.2 snj static int16_t
608 1.2.10.2 snj ar2413GetMinPower(struct ath_hal *ah, const RAW_DATA_PER_CHANNEL_2413 *data)
609 1.2.10.2 snj {
610 1.2.10.2 snj uint32_t ii,jj;
611 1.2.10.2 snj uint16_t Pmin=0,numVpd;
612 1.2.10.2 snj
613 1.2.10.2 snj for (ii = 0; ii < MAX_NUM_PDGAINS_PER_CHANNEL; ii++) {
614 1.2.10.2 snj jj = MAX_NUM_PDGAINS_PER_CHANNEL - ii - 1;
615 1.2.10.2 snj /* work backwards 'cause highest pdGain for lowest power */
616 1.2.10.2 snj numVpd = data->pDataPerPDGain[jj].numVpd;
617 1.2.10.2 snj if (numVpd > 0) {
618 1.2.10.2 snj Pmin = data->pDataPerPDGain[jj].pwr_t4[0];
619 1.2.10.2 snj return(Pmin);
620 1.2.10.2 snj }
621 1.2.10.2 snj }
622 1.2.10.2 snj return(Pmin);
623 1.2.10.2 snj }
624 1.2.10.2 snj
625 1.2.10.2 snj static int16_t
626 1.2.10.2 snj ar2413GetMaxPower(struct ath_hal *ah, const RAW_DATA_PER_CHANNEL_2413 *data)
627 1.2.10.2 snj {
628 1.2.10.2 snj uint32_t ii;
629 1.2.10.2 snj uint16_t Pmax=0,numVpd;
630 1.2.10.2 snj
631 1.2.10.2 snj for (ii=0; ii< MAX_NUM_PDGAINS_PER_CHANNEL; ii++) {
632 1.2.10.2 snj /* work forwards cuase lowest pdGain for highest power */
633 1.2.10.2 snj numVpd = data->pDataPerPDGain[ii].numVpd;
634 1.2.10.2 snj if (numVpd > 0) {
635 1.2.10.2 snj Pmax = data->pDataPerPDGain[ii].pwr_t4[numVpd-1];
636 1.2.10.2 snj return(Pmax);
637 1.2.10.2 snj }
638 1.2.10.2 snj }
639 1.2.10.2 snj return(Pmax);
640 1.2.10.2 snj }
641 1.2.10.2 snj
642 1.2.10.2 snj static HAL_BOOL
643 1.2.10.2 snj ar2413GetChannelMaxMinPower(struct ath_hal *ah, HAL_CHANNEL *chan,
644 1.2.10.2 snj int16_t *maxPow, int16_t *minPow)
645 1.2.10.2 snj {
646 1.2.10.2 snj const HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom;
647 1.2.10.2 snj const RAW_DATA_STRUCT_2413 *pRawDataset = AH_NULL;
648 1.2.10.2 snj const RAW_DATA_PER_CHANNEL_2413 *data = AH_NULL;
649 1.2.10.2 snj uint16_t numChannels;
650 1.2.10.2 snj int totalD,totalF, totalMin,last, i;
651 1.2.10.2 snj
652 1.2.10.2 snj *maxPow = 0;
653 1.2.10.2 snj
654 1.2.10.2 snj if (IS_CHAN_G(chan) || IS_CHAN_108G(chan))
655 1.2.10.2 snj pRawDataset = &ee->ee_rawDataset2413[headerInfo11G];
656 1.2.10.2 snj else if (IS_CHAN_B(chan))
657 1.2.10.2 snj pRawDataset = &ee->ee_rawDataset2413[headerInfo11B];
658 1.2.10.2 snj else
659 1.2.10.2 snj return(AH_FALSE);
660 1.2.10.2 snj
661 1.2.10.2 snj numChannels = pRawDataset->numChannels;
662 1.2.10.2 snj data = pRawDataset->pDataPerChannel;
663 1.2.10.2 snj
664 1.2.10.2 snj /* Make sure the channel is in the range of the TP values
665 1.2.10.2 snj * (freq piers)
666 1.2.10.2 snj */
667 1.2.10.2 snj if (numChannels < 1)
668 1.2.10.2 snj return(AH_FALSE);
669 1.2.10.2 snj
670 1.2.10.2 snj if ((chan->channel < data[0].channelValue) ||
671 1.2.10.2 snj (chan->channel > data[numChannels-1].channelValue)) {
672 1.2.10.2 snj if (chan->channel < data[0].channelValue) {
673 1.2.10.2 snj *maxPow = ar2413GetMaxPower(ah, &data[0]);
674 1.2.10.2 snj *minPow = ar2413GetMinPower(ah, &data[0]);
675 1.2.10.2 snj return(AH_TRUE);
676 1.2.10.2 snj } else {
677 1.2.10.2 snj *maxPow = ar2413GetMaxPower(ah, &data[numChannels - 1]);
678 1.2.10.2 snj *minPow = ar2413GetMinPower(ah, &data[numChannels - 1]);
679 1.2.10.2 snj return(AH_TRUE);
680 1.2.10.2 snj }
681 1.2.10.2 snj }
682 1.2.10.2 snj
683 1.2.10.2 snj /* Linearly interpolate the power value now */
684 1.2.10.2 snj for (last=0,i=0; (i<numChannels) && (chan->channel > data[i].channelValue);
685 1.2.10.2 snj last = i++);
686 1.2.10.2 snj totalD = data[i].channelValue - data[last].channelValue;
687 1.2.10.2 snj if (totalD > 0) {
688 1.2.10.2 snj totalF = ar2413GetMaxPower(ah, &data[i]) - ar2413GetMaxPower(ah, &data[last]);
689 1.2.10.2 snj *maxPow = (int8_t) ((totalF*(chan->channel-data[last].channelValue) +
690 1.2.10.2 snj ar2413GetMaxPower(ah, &data[last])*totalD)/totalD);
691 1.2.10.2 snj totalMin = ar2413GetMinPower(ah, &data[i]) - ar2413GetMinPower(ah, &data[last]);
692 1.2.10.2 snj *minPow = (int8_t) ((totalMin*(chan->channel-data[last].channelValue) +
693 1.2.10.2 snj ar2413GetMinPower(ah, &data[last])*totalD)/totalD);
694 1.2.10.2 snj return(AH_TRUE);
695 1.2.10.2 snj } else {
696 1.2.10.2 snj if (chan->channel == data[i].channelValue) {
697 1.2.10.2 snj *maxPow = ar2413GetMaxPower(ah, &data[i]);
698 1.2.10.2 snj *minPow = ar2413GetMinPower(ah, &data[i]);
699 1.2.10.2 snj return(AH_TRUE);
700 1.2.10.2 snj } else
701 1.2.10.2 snj return(AH_FALSE);
702 1.2.10.2 snj }
703 1.2.10.2 snj }
704 1.2.10.2 snj
705 1.2.10.2 snj /*
706 1.2.10.2 snj * Free memory for analog bank scratch buffers
707 1.2.10.2 snj */
708 1.2.10.2 snj static void
709 1.2.10.2 snj ar2413RfDetach(struct ath_hal *ah)
710 1.2.10.2 snj {
711 1.2.10.2 snj struct ath_hal_5212 *ahp = AH5212(ah);
712 1.2.10.2 snj
713 1.2.10.2 snj HALASSERT(ahp->ah_rfHal != AH_NULL);
714 1.2.10.2 snj ath_hal_free(ahp->ah_rfHal);
715 1.2.10.2 snj ahp->ah_rfHal = AH_NULL;
716 1.2.10.2 snj }
717 1.2.10.2 snj
718 1.2.10.2 snj /*
719 1.2.10.2 snj * Allocate memory for analog bank scratch buffers
720 1.2.10.2 snj * Scratch Buffer will be reinitialized every reset so no need to zero now
721 1.2.10.2 snj */
722 1.2.10.2 snj static HAL_BOOL
723 1.2.10.2 snj ar2413RfAttach(struct ath_hal *ah, HAL_STATUS *status)
724 1.2.10.2 snj {
725 1.2.10.2 snj struct ath_hal_5212 *ahp = AH5212(ah);
726 1.2.10.2 snj struct ar2413State *priv;
727 1.2.10.2 snj
728 1.2.10.2 snj HALASSERT(ah->ah_magic == AR5212_MAGIC);
729 1.2.10.2 snj
730 1.2.10.2 snj HALASSERT(ahp->ah_rfHal == AH_NULL);
731 1.2.10.2 snj priv = ath_hal_malloc(sizeof(struct ar2413State));
732 1.2.10.2 snj if (priv == AH_NULL) {
733 1.2.10.2 snj HALDEBUG(ah, HAL_DEBUG_ANY,
734 1.2.10.2 snj "%s: cannot allocate private state\n", __func__);
735 1.2.10.2 snj *status = HAL_ENOMEM; /* XXX */
736 1.2.10.2 snj return AH_FALSE;
737 1.2.10.2 snj }
738 1.2.10.2 snj priv->base.rfDetach = ar2413RfDetach;
739 1.2.10.2 snj priv->base.writeRegs = ar2413WriteRegs;
740 1.2.10.2 snj priv->base.getRfBank = ar2413GetRfBank;
741 1.2.10.2 snj priv->base.setChannel = ar2413SetChannel;
742 1.2.10.2 snj priv->base.setRfRegs = ar2413SetRfRegs;
743 1.2.10.2 snj priv->base.setPowerTable = ar2413SetPowerTable;
744 1.2.10.2 snj priv->base.getChannelMaxMinPower = ar2413GetChannelMaxMinPower;
745 1.2.10.2 snj priv->base.getNfAdjust = ar5212GetNfAdjust;
746 1.2.10.2 snj
747 1.2.10.2 snj ahp->ah_pcdacTable = priv->pcdacTable;
748 1.2.10.2 snj ahp->ah_pcdacTableSize = sizeof(priv->pcdacTable);
749 1.2.10.2 snj ahp->ah_rfHal = &priv->base;
750 1.2.10.2 snj
751 1.2.10.2 snj return AH_TRUE;
752 1.2.10.2 snj }
753 1.2.10.2 snj
754 1.2.10.2 snj static HAL_BOOL
755 1.2.10.2 snj ar2413Probe(struct ath_hal *ah)
756 1.2.10.2 snj {
757 1.2.10.2 snj return IS_2413(ah);
758 1.2.10.2 snj }
759 1.2.10.2 snj AH_RF(RF2413, ar2413Probe, ar2413RfAttach);
760