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