#include "opt_ah.h"
#include "ah.h"
#include "ah_internal.h"
#include "ar5210/ar5210.h"
#include "ar5210/ar5210reg.h"
#include "ar5210/ar5210phy.h"
#include "ah_eeprom_v1.h"
typedef struct {
uint32_t Offset;
uint32_t Value;
} REGISTER_VAL;
static const REGISTER_VAL ar5k0007_init[] = {
#include "ar5210/ar5k_0007.ini"
};
static const uint8_t ar5k0007_pwrSettings[17] = {
9, 9, 0, 0, 0, 0, 0, 2, 2, 6, 6, 6, 6, 6, 6, 2, 2
};
#define AR_RC_SETTLE_TIME 20000
static HAL_BOOL ar5210SetResetReg(struct ath_hal *,
uint32_t resetMask, u_int delay);
static HAL_BOOL ar5210SetChannel(struct ath_hal *, struct ieee80211_channel *);
static void ar5210SetOperatingMode(struct ath_hal *, int opmode);
HAL_BOOL
ar5210Reset(struct ath_hal *ah, HAL_OPMODE opmode,
struct ieee80211_channel *chan, HAL_BOOL bChannelChange,
HAL_RESET_TYPE resetType,
HAL_STATUS *status)
{
#define N(a) (sizeof (a) /sizeof (a[0]))
#define FAIL(_code) do { ecode = _code; goto bad; } while (0)
struct ath_hal_5210 *ahp = AH5210(ah);
const HAL_EEPROM_v1 *ee = AH_PRIVATE(ah)->ah_eeprom;
HAL_CHANNEL_INTERNAL *ichan;
HAL_STATUS ecode;
uint32_t ledstate;
int i, q;
HALDEBUG(ah, HAL_DEBUG_RESET,
"%s: opmode %u channel %u/0x%x %s channel\n", __func__,
opmode, chan->ic_freq, chan->ic_flags,
bChannelChange ? "change" : "same");
if (!IEEE80211_IS_CHAN_5GHZ(chan)) {
HALDEBUG(ah, HAL_DEBUG_ANY, "%s: channel not 5GHz\n", __func__);
FAIL(HAL_EINVAL);
}
ichan = ath_hal_checkchannel(ah, chan);
if (ichan == AH_NULL) {
HALDEBUG(ah, HAL_DEBUG_ANY,
"%s: invalid channel %u/0x%x; no mapping\n",
__func__, chan->ic_freq, chan->ic_flags);
FAIL(HAL_EINVAL);
}
switch (opmode) {
case HAL_M_STA:
case HAL_M_IBSS:
case HAL_M_HOSTAP:
case HAL_M_MONITOR:
break;
default:
HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid operating mode %u\n",
__func__, opmode);
FAIL(HAL_EINVAL);
break;
}
ledstate = OS_REG_READ(ah, AR_PCICFG) &
(AR_PCICFG_LED_PEND | AR_PCICFG_LED_ACT);
if (!ar5210ChipReset(ah, chan)) {
HALDEBUG(ah, HAL_DEBUG_ANY, "%s: chip reset failed\n",
__func__);
FAIL(HAL_EIO);
}
OS_REG_WRITE(ah, AR_STA_ID0, LE_READ_4(ahp->ah_macaddr));
OS_REG_WRITE(ah, AR_STA_ID1, LE_READ_2(ahp->ah_macaddr + 4));
ar5210SetOperatingMode(ah, opmode);
switch (opmode) {
case HAL_M_HOSTAP:
OS_REG_WRITE(ah, AR_BCR, INIT_BCON_CNTRL_REG);
OS_REG_WRITE(ah, AR_PCICFG,
AR_PCICFG_LED_ACT | AR_PCICFG_LED_BCTL);
break;
case HAL_M_IBSS:
OS_REG_WRITE(ah, AR_BCR, INIT_BCON_CNTRL_REG | AR_BCR_BCMD);
OS_REG_WRITE(ah, AR_PCICFG,
AR_PCICFG_CLKRUNEN | AR_PCICFG_LED_PEND | AR_PCICFG_LED_BCTL);
break;
case HAL_M_STA:
OS_REG_WRITE(ah, AR_BCR, INIT_BCON_CNTRL_REG);
OS_REG_WRITE(ah, AR_PCICFG,
AR_PCICFG_CLKRUNEN | AR_PCICFG_LED_PEND | AR_PCICFG_LED_BCTL);
break;
case HAL_M_MONITOR:
OS_REG_WRITE(ah, AR_BCR, INIT_BCON_CNTRL_REG);
OS_REG_WRITE(ah, AR_PCICFG,
AR_PCICFG_LED_ACT | AR_PCICFG_LED_BCTL);
break;
}
OS_REG_WRITE(ah, AR_PCICFG, OS_REG_READ(ah, AR_PCICFG) | ledstate);
#if 0
OS_REG_WRITE(ah, AR_BSS_ID0, LE_READ_4(ahp->ah_bssid));
OS_REG_WRITE(ah, AR_BSS_ID1, LE_READ_2(ahp->ah_bssid + 4));
#endif
ar5210WriteAssocid(ah, ahp->ah_bssid, ahp->ah_associd);
OS_REG_WRITE(ah, AR_TXDP0, 0);
OS_REG_WRITE(ah, AR_TXDP1, 0);
OS_REG_WRITE(ah, AR_RXDP, 0);
(void) OS_REG_READ(ah, AR_ISR);
OS_REG_WRITE(ah, AR_IMR, 0);
OS_REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
ahp->ah_maskReg = 0;
(void) OS_REG_READ(ah, AR_BSR);
OS_REG_WRITE(ah, AR_TXCFG, AR_DMASIZE_128B);
OS_REG_WRITE(ah, AR_RXCFG, AR_DMASIZE_128B);
OS_REG_WRITE(ah, AR_TOPS, 8);
OS_REG_WRITE(ah, AR_RXNOFRM, 8);
OS_REG_WRITE(ah, AR_RPGTO, 0);
OS_REG_WRITE(ah, AR_TXNOFRM, 0);
OS_REG_WRITE(ah, AR_SFR, 0);
OS_REG_WRITE(ah, AR_MIBC, 0);
OS_REG_WRITE(ah, AR_RSSI_THR, ahp->ah_rssiThr);
OS_REG_WRITE(ah, AR_CFP_DUR, 0);
ar5210SetRxFilter(ah, 0);
OS_REG_WRITE(ah, AR_MCAST_FIL0, 0);
OS_REG_WRITE(ah, AR_MCAST_FIL1, 0);
OS_REG_WRITE(ah, AR_TX_MASK0, 0);
OS_REG_WRITE(ah, AR_TX_MASK1, 0);
OS_REG_WRITE(ah, AR_CLR_TMASK, 1);
OS_REG_WRITE(ah, AR_TRIG_LEV, 1);
ar5210UpdateDiagReg(ah, 0);
OS_REG_WRITE(ah, AR_CFP_PERIOD, 0);
OS_REG_WRITE(ah, AR_TIMER0, 0);
OS_REG_WRITE(ah, AR_TSF_L32, 0);
OS_REG_WRITE(ah, AR_TIMER1, ~0);
OS_REG_WRITE(ah, AR_TIMER2, ~0);
OS_REG_WRITE(ah, AR_TIMER3, 1);
for (i = 0; i < N(ar5k0007_init); i++) {
uint32_t reg = ar5k0007_init[i].Offset;
if (!(bChannelChange && (0x8000 <= reg && reg < 0x9000)))
OS_REG_WRITE(ah, reg, ar5k0007_init[i].Value);
}
if (!ar5210SetTransmitPower(ah, chan)) {
HALDEBUG(ah, HAL_DEBUG_ANY,
"%s: error init'ing transmit power\n", __func__);
FAIL(HAL_EIO);
}
OS_REG_WRITE(ah, AR_PHY(10),
(OS_REG_READ(ah, AR_PHY(10)) & 0xFFFF00FF) |
(ee->ee_xlnaOn << 8));
OS_REG_WRITE(ah, AR_PHY(13),
(ee->ee_xpaOff << 24) | (ee->ee_xpaOff << 16) |
(ee->ee_xpaOn << 8) | ee->ee_xpaOn);
OS_REG_WRITE(ah, AR_PHY(17),
(OS_REG_READ(ah, AR_PHY(17)) & 0xFFFFC07F) |
((ee->ee_antenna >> 1) & 0x3F80));
OS_REG_WRITE(ah, AR_PHY(18),
(OS_REG_READ(ah, AR_PHY(18)) & 0xFFFC0FFF) |
((ee->ee_antenna << 10) & 0x3F000));
OS_REG_WRITE(ah, AR_PHY(25),
(OS_REG_READ(ah, AR_PHY(25)) & 0xFFF80FFF) |
((ee->ee_thresh62 << 12) & 0x7F000));
OS_REG_WRITE(ah, AR_PHY(68),
(OS_REG_READ(ah, AR_PHY(68)) & 0xFFFFFFFC) |
(ee->ee_antenna & 0x3));
if (!ar5210SetChannel(ah, chan)) {
HALDEBUG(ah, HAL_DEBUG_ANY, "%s: unable to set channel\n",
__func__);
FAIL(HAL_EIO);
}
if (bChannelChange && !IEEE80211_IS_CHAN_DFS(chan))
chan->ic_state &= ~IEEE80211_CHANSTATE_CWINT;
OS_REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ENABLE);
OS_DELAY(1000);
OS_REG_WRITE(ah, AR_PHY_AGCCTL,
OS_REG_READ(ah, AR_PHY_AGCCTL) | AR_PHY_AGC_CAL);
(void) ath_hal_wait(ah, AR_PHY_AGCCTL, AR_PHY_AGC_CAL, 0);
if (!ar5210CalNoiseFloor(ah, ichan)) {
chan->ic_state |= IEEE80211_CHANSTATE_CWINT;
HALDEBUG(ah, HAL_DEBUG_ANY,
"%s: noise floor calibration failed\n", __func__);
FAIL(HAL_EIO);
}
for (q = 0; q < HAL_NUM_TX_QUEUES; q++)
ar5210ResetTxQueue(ah, q);
if (AH_PRIVATE(ah)->ah_rfkillEnabled)
ar5210EnableRfKill(ah);
OS_REG_WRITE(ah, AR_BEACON,
(OS_REG_READ(ah, AR_BEACON) &
~(AR_BEACON_EN | AR_BEACON_RESET_TSF)));
if (ahp->ah_sifstime != (u_int) -1)
ar5210SetSifsTime(ah, ahp->ah_sifstime);
if (ahp->ah_slottime != (u_int) -1)
ar5210SetSlotTime(ah, ahp->ah_slottime);
if (ahp->ah_acktimeout != (u_int) -1)
ar5210SetAckTimeout(ah, ahp->ah_acktimeout);
if (ahp->ah_ctstimeout != (u_int) -1)
ar5210SetCTSTimeout(ah, ahp->ah_ctstimeout);
if (AH_PRIVATE(ah)->ah_diagreg != 0)
ar5210UpdateDiagReg(ah, AH_PRIVATE(ah)->ah_diagreg);
AH_PRIVATE(ah)->ah_opmode = opmode;
HALDEBUG(ah, HAL_DEBUG_RESET, "%s: done\n", __func__);
return AH_TRUE;
bad:
if (status != AH_NULL)
*status = ecode;
return AH_FALSE;
#undef FAIL
#undef N
}
static void
ar5210SetOperatingMode(struct ath_hal *ah, int opmode)
{
struct ath_hal_5210 *ahp = AH5210(ah);
uint32_t val;
val = OS_REG_READ(ah, AR_STA_ID1) & 0xffff;
switch (opmode) {
case HAL_M_HOSTAP:
OS_REG_WRITE(ah, AR_STA_ID1, val
| AR_STA_ID1_AP
| AR_STA_ID1_NO_PSPOLL
| AR_STA_ID1_DESC_ANTENNA
| ahp->ah_staId1Defaults);
break;
case HAL_M_IBSS:
OS_REG_WRITE(ah, AR_STA_ID1, val
| AR_STA_ID1_ADHOC
| AR_STA_ID1_NO_PSPOLL
| AR_STA_ID1_DESC_ANTENNA
| ahp->ah_staId1Defaults);
break;
case HAL_M_STA:
OS_REG_WRITE(ah, AR_STA_ID1, val
| AR_STA_ID1_NO_PSPOLL
| AR_STA_ID1_PWR_SV
| ahp->ah_staId1Defaults);
break;
case HAL_M_MONITOR:
OS_REG_WRITE(ah, AR_STA_ID1, val
| AR_STA_ID1_NO_PSPOLL
| ahp->ah_staId1Defaults);
break;
}
}
void
ar5210SetPCUConfig(struct ath_hal *ah)
{
ar5210SetOperatingMode(ah, AH_PRIVATE(ah)->ah_opmode);
}
HAL_BOOL
ar5210PhyDisable(struct ath_hal *ah)
{
return ar5210SetResetReg(ah, AR_RC_RPHY, 10);
}
HAL_BOOL
ar5210Disable(struct ath_hal *ah)
{
#define AR_RC_HW (AR_RC_RPCU | AR_RC_RDMA | AR_RC_RPHY | AR_RC_RMAC)
if (!ar5210SetPowerMode(ah, HAL_PM_AWAKE, AH_TRUE))
return AH_FALSE;
if (!ar5210SetResetReg(ah, AR_RC_HW, AR_RC_SETTLE_TIME))
return AH_FALSE;
OS_DELAY(1000);
(void) ar5210SetResetReg(ah, AR_RC_HW | AR_RC_RPCI, AR_RC_SETTLE_TIME);
OS_DELAY(2100);
return AH_TRUE;
#undef AR_RC_HW
}
HAL_BOOL
ar5210ChipReset(struct ath_hal *ah, struct ieee80211_channel *chan)
{
#define AR_RC_HW (AR_RC_RPCU | AR_RC_RDMA | AR_RC_RPHY | AR_RC_RMAC)
HALDEBUG(ah, HAL_DEBUG_RESET, "%s turbo %s\n", __func__,
chan && IEEE80211_IS_CHAN_TURBO(chan) ?
"enabled" : "disabled");
if (!ar5210SetPowerMode(ah, HAL_PM_AWAKE, AH_TRUE))
return AH_FALSE;
OS_REG_WRITE(ah, AR_PHY_FRCTL,
chan && IEEE80211_IS_CHAN_TURBO(chan) ? AR_PHY_TURBO_MODE : 0);
if (!ar5210SetResetReg(ah, AR_RC_HW, AR_RC_SETTLE_TIME))
return AH_FALSE;
OS_DELAY(1000);
if (!ar5210SetResetReg(ah, AR_RC_HW | AR_RC_RPCI, AR_RC_SETTLE_TIME))
return AH_FALSE;
OS_DELAY(2100);
if (!ar5210SetPowerMode(ah, HAL_PM_AWAKE, AH_TRUE))
return AH_FALSE;
return ar5210SetResetReg(ah, 0, 10);
#undef AR_RC_HW
}
enum {
FIRPWR_M = 0x03fc0000,
FIRPWR_S = 18,
KCOARSEHIGH_M = 0x003f8000,
KCOARSEHIGH_S = 15,
KCOARSELOW_M = 0x00007f80,
KCOARSELOW_S = 7,
ADCSAT_ICOUNT_M = 0x0001f800,
ADCSAT_ICOUNT_S = 11,
ADCSAT_THRESH_M = 0x000007e0,
ADCSAT_THRESH_S = 5
};
HAL_BOOL
ar5210PerCalibrationN(struct ath_hal *ah,
struct ieee80211_channel *chan, u_int chainMask,
HAL_BOOL longCal, HAL_BOOL *isCalDone)
{
uint32_t regBeacon;
uint32_t reg9858, reg985c, reg9868;
HAL_CHANNEL_INTERNAL *ichan;
ichan = ath_hal_checkchannel(ah, chan);
if (ichan == AH_NULL)
return AH_FALSE;
ar5210UpdateDiagReg(ah,
OS_REG_READ(ah, AR_DIAG_SW) | (AR_DIAG_SW_DIS_TX | AR_DIAG_SW_DIS_RX));
regBeacon = OS_REG_READ(ah, AR_BEACON);
OS_REG_WRITE(ah, AR_BEACON, regBeacon & ~AR_BEACON_EN);
OS_DELAY(4000);
OS_REG_WRITE(ah, 0x9808, OS_REG_READ(ah, 0x9808) | 0x08000000);
OS_DELAY(10);
if (!ar5210SetChannel(ah, chan))
return AH_FALSE;
OS_DELAY(1000);
OS_REG_WRITE(ah, 0x9808, OS_REG_READ(ah, 0x9808) & (~0x08000000));
reg9858 = OS_REG_READ(ah, 0x9858);
reg985c = OS_REG_READ(ah, 0x985c);
reg9868 = OS_REG_READ(ah, 0x9868);
OS_REG_WRITE(ah, 0x9858, (reg9858 & ~FIRPWR_M) |
((-1 << FIRPWR_S) & FIRPWR_M));
OS_REG_WRITE(ah, 0x985c,
(reg985c & ~(KCOARSEHIGH_M | KCOARSELOW_M)) |
((-1 << KCOARSEHIGH_S) & KCOARSEHIGH_M) |
((-127 << KCOARSELOW_S) & KCOARSELOW_M));
OS_REG_WRITE(ah, 0x9868,
(reg9868 & ~(ADCSAT_ICOUNT_M | ADCSAT_THRESH_M)) |
((2 << ADCSAT_ICOUNT_S) & ADCSAT_ICOUNT_M) |
((12 << ADCSAT_THRESH_S) & ADCSAT_THRESH_M));
OS_DELAY(20);
OS_REG_WRITE(ah, 0x9808, OS_REG_READ(ah, 0x9808) | 0x08000000);
OS_DELAY(10);
OS_REG_WRITE(ah, 0x98D4, 0x21);
OS_REG_WRITE(ah, 0x9808, OS_REG_READ(ah, 0x9808) & (~0x08000000));
OS_DELAY(1000);
OS_REG_WRITE(ah, AR_PHY_AGCCTL,
OS_REG_READ(ah, AR_PHY_AGCCTL) | AR_PHY_AGC_CAL);
if (!ath_hal_wait(ah, AR_PHY_AGCCTL, AR_PHY_AGC_CAL, 0)) {
HALDEBUG(ah, HAL_DEBUG_ANY, "%s: AGC calibration timeout\n",
__func__);
}
OS_REG_WRITE(ah, 0x9858, reg9858);
OS_REG_WRITE(ah, 0x985c, reg985c);
OS_REG_WRITE(ah, 0x9868, reg9868);
if (!ar5210CalNoiseFloor(ah, ichan)) {
HALDEBUG(ah, HAL_DEBUG_NFCAL | HAL_DEBUG_PERCAL,
"%s: Performing 2nd Noise Cal\n", __func__);
OS_DELAY(5000);
if (!ar5210CalNoiseFloor(ah, ichan))
chan->ic_state |= IEEE80211_CHANSTATE_CWINT;
}
ar5210UpdateDiagReg(ah,
OS_REG_READ(ah, AR_DIAG_SW) & ~(AR_DIAG_SW_DIS_TX | AR_DIAG_SW_DIS_RX));
OS_REG_WRITE(ah, AR_BEACON, regBeacon);
*isCalDone = AH_TRUE;
return AH_TRUE;
}
HAL_BOOL
ar5210PerCalibration(struct ath_hal *ah, struct ieee80211_channel *chan,
HAL_BOOL *isIQdone)
{
return ar5210PerCalibrationN(ah, chan, 0x1, AH_TRUE, isIQdone);
}
HAL_BOOL
ar5210ResetCalValid(struct ath_hal *ah, const struct ieee80211_channel *chan)
{
return AH_TRUE;
}
static HAL_BOOL
ar5210SetResetReg(struct ath_hal *ah, uint32_t resetMask, u_int delay)
{
uint32_t mask = resetMask ? resetMask : ~0;
HAL_BOOL rt;
OS_REG_WRITE(ah, AR_RC, resetMask);
OS_DELAY(delay);
resetMask &= AR_RC_RPCU | AR_RC_RDMA | AR_RC_RPHY | AR_RC_RMAC;
mask &= AR_RC_RPCU | AR_RC_RDMA | AR_RC_RPHY | AR_RC_RMAC;
rt = ath_hal_wait(ah, AR_RC, mask, resetMask);
if ((resetMask & AR_RC_RMAC) == 0) {
if (isBigEndian()) {
mask = INIT_CONFIG_STATUS | AR_CFG_SWTD | AR_CFG_SWRD;
OS_REG_WRITE(ah, AR_CFG, mask);
} else
OS_REG_WRITE(ah, AR_CFG, INIT_CONFIG_STATUS);
}
return rt;
}
static uint8_t
getPcdac(struct ath_hal *ah, const struct tpcMap *pRD, uint8_t dBm)
{
int32_t i;
int useNextEntry = AH_FALSE;
uint32_t interp;
for (i = AR_TP_SCALING_ENTRIES - 1; i >= 0; i--) {
if (dBm == AR_I2DBM(i)) {
if (pRD->pcdac[i] != 63)
return pRD->pcdac[i];
useNextEntry = AH_TRUE;
} else if (dBm + 1 == AR_I2DBM(i) && i > 0) {
if (pRD->pcdac[i] != 63 && pRD->pcdac[i-1] != 63) {
interp = (350 * (pRD->pcdac[i] - pRD->pcdac[i-1])) + 999;
interp = (interp / 1000) + pRD->pcdac[i-1];
return interp;
}
useNextEntry = AH_TRUE;
} else if (useNextEntry == AH_TRUE) {
if (pRD->pcdac[i] != 63)
return pRD->pcdac[i];
}
}
for (i = 0; i < AR_TP_SCALING_ENTRIES; i++)
if (pRD->pcdac[i] != 63)
return pRD->pcdac[i];
#ifdef AH_DEBUG
ath_hal_printf(ah, "%s: empty transmit power table?\n", __func__);
#endif
return 1;
}
static uint8_t
getGainF(struct ath_hal *ah, const struct tpcMap *pRD,
uint8_t pcdac, uint8_t *dBm)
{
uint32_t interp;
int low, high, i;
low = high = -1;
for (i = 0; i < AR_TP_SCALING_ENTRIES; i++) {
if(pRD->pcdac[i] == 63)
continue;
if (pcdac == pRD->pcdac[i]) {
*dBm = AR_I2DBM(i);
return pRD->gainF[i];
}
if (pcdac > pRD->pcdac[i])
low = i;
if (pcdac < pRD->pcdac[i]) {
high = i;
if (low == -1) {
*dBm = AR_I2DBM(i);
return pRD->gainF[i];
}
break;
}
}
if (i >= AR_TP_SCALING_ENTRIES && low == -1) {
#ifdef AH_DEBUG
ath_hal_printf(ah,
"%s: no valid entries in the pcdac table: %d\n",
__func__, pcdac);
#endif
return 63;
}
if (i >= AR_TP_SCALING_ENTRIES) {
*dBm = AR_I2DBM(low);
return pRD->gainF[low];
}
*dBm = (low + high) + 3;
interp = ((pcdac - pRD->pcdac[low]) * 1000) /
(pRD->pcdac[high] - pRD->pcdac[low]);
interp = ((interp * (pRD->gainF[high] - pRD->gainF[low])) + 999) / 1000;
return interp + pRD->gainF[low];
}
HAL_BOOL
ar5210SetTxPowerLimit(struct ath_hal *ah, uint32_t limit)
{
AH_PRIVATE(ah)->ah_powerLimit = AH_MIN(limit, AR5210_MAX_RATE_POWER);
return AH_TRUE;
}
static HAL_BOOL
setupPowerSettings(struct ath_hal *ah, const struct ieee80211_channel *chan,
uint8_t cp[17])
{
uint16_t freq = ath_hal_gethwchannel(ah, chan);
const HAL_EEPROM_v1 *ee = AH_PRIVATE(ah)->ah_eeprom;
uint8_t gainFRD, gainF36, gainF48, gainF54;
uint8_t dBmRD, dBm36, dBm48, dBm54, dontcare;
uint32_t rd, group;
const struct tpcMap *pRD;
cp[15] = (ee->ee_biasCurrents >> 4) & 0x7;
cp[16] = ee->ee_biasCurrents & 0x7;
if (freq < 5170 || freq > 5320) {
HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid channel %u\n",
__func__, freq);
return AH_FALSE;
}
HALASSERT(ee->ee_version >= AR_EEPROM_VER1 &&
ee->ee_version < AR_EEPROM_VER3);
for (rd = 0; rd < AR_REG_DOMAINS_MAX; rd++)
if (AH_PRIVATE(ah)->ah_currentRD == ee->ee_regDomain[rd])
break;
if (rd == AR_REG_DOMAINS_MAX) {
#ifdef AH_DEBUG
ath_hal_printf(ah,
"%s: no calibrated regulatory domain matches the "
"current regularly domain (0x%0x)\n", __func__,
AH_PRIVATE(ah)->ah_currentRD);
#endif
return AH_FALSE;
}
group = ((freq - 5170) / 10);
if (group > 11) {
group--;
}
group = group / 3;
pRD = &ee->ee_tpc[group];
cp[14] = pRD->regdmn[rd];
cp[9] = AH_MIN(pRD->regdmn[rd], pRD->rate36);
cp[8] = AH_MIN(pRD->regdmn[rd], pRD->rate48);
cp[7] = AH_MIN(pRD->regdmn[rd], pRD->rate54);
gainFRD = getGainF(ah, pRD, pRD->regdmn[rd], &dBmRD);
gainF36 = getGainF(ah, pRD, cp[9], &dBm36);
gainF48 = getGainF(ah, pRD, cp[8], &dBm48);
gainF54 = getGainF(ah, pRD, cp[7], &dBm54);
if (AH_PRIVATE(ah)->ah_tpScale != HAL_TP_SCALE_MAX) {
static const uint16_t tpcScaleReductionTable[5] =
{ 0, 3, 6, 9, AR5210_MAX_RATE_POWER };
uint16_t tpScale;
tpScale = tpcScaleReductionTable[AH_PRIVATE(ah)->ah_tpScale];
if (dBmRD < tpScale+3)
dBmRD = 3;
else
dBmRD -= tpScale;
cp[14] = getPcdac(ah, pRD, dBmRD);
gainFRD = getGainF(ah, pRD, cp[14], &dontcare);
dBm36 = AH_MIN(dBm36, dBmRD);
cp[9] = getPcdac(ah, pRD, dBm36);
gainF36 = getGainF(ah, pRD, cp[9], &dontcare);
dBm48 = AH_MIN(dBm48, dBmRD);
cp[8] = getPcdac(ah, pRD, dBm48);
gainF48 = getGainF(ah, pRD, cp[8], &dontcare);
dBm54 = AH_MIN(dBm54, dBmRD);
cp[7] = getPcdac(ah, pRD, dBm54);
gainF54 = getGainF(ah, pRD, cp[7], &dontcare);
}
AH_PRIVATE(ah)->ah_maxPowerLevel = 2*dBmRD;
cp[13] = cp[12] = cp[11] = cp[10] = cp[14];
cp[0] = gainFRD - gainF54;
cp[1] = gainFRD - gainF48;
cp[2] = gainFRD - gainF36;
cp[3] = cp[4] = cp[5] = cp[6] = 0;
return AH_TRUE;
}
HAL_BOOL
ar5210SetTransmitPower(struct ath_hal *ah, const struct ieee80211_channel *chan)
{
#define N(a) (sizeof (a) / sizeof (a[0]))
static const uint32_t pwr_regs_start[17] = {
0x00000000, 0x00000000, 0x00000000,
0x00000000, 0x00000000, 0xf0000000,
0xcc000000, 0x00000000, 0x00000000,
0x00000000, 0x0a000000, 0x000000e2,
0x0a000020, 0x01000002, 0x01000018,
0x40000000, 0x00000418
};
uint16_t i;
uint8_t cp[sizeof(ar5k0007_pwrSettings)];
uint32_t pwr_regs[17];
OS_MEMCPY(pwr_regs, pwr_regs_start, sizeof(pwr_regs));
OS_MEMCPY(cp, ar5k0007_pwrSettings, sizeof(cp));
if (!setupPowerSettings(ah, chan, cp)) {
#ifdef AH_DEBUG
ath_hal_printf(ah, "%s: unable to setup power settings\n",
__func__);
#endif
return AH_FALSE;
}
if (cp[15] < 1 || cp[15] > 5) {
#ifdef AH_DEBUG
ath_hal_printf(ah, "%s: OB out of range (%u)\n",
__func__, cp[15]);
#endif
return AH_FALSE;
}
if (cp[16] < 1 || cp[16] > 5) {
#ifdef AH_DEBUG
ath_hal_printf(ah, "%s: DB out of range (%u)\n",
__func__, cp[16]);
#endif
return AH_FALSE;
}
for (i = 0; i < 7; i++)
cp[i] = ath_hal_reverseBits(cp[i], 5);
for (i = 7; i < 15; i++)
cp[i] = ath_hal_reverseBits(cp[i], 6);
pwr_regs[0] |= ((cp[1] << 5) & 0xE0) | (cp[0] & 0x1F);
pwr_regs[1] |= ((cp[3] << 7) & 0x80) | ((cp[2] << 2) & 0x7C) |
((cp[1] >> 3) & 0x03);
pwr_regs[2] |= ((cp[4] << 4) & 0xF0) | ((cp[3] >> 1) & 0x0F);
pwr_regs[3] |= ((cp[6] << 6) & 0xC0) | ((cp[5] << 1) & 0x3E) |
((cp[4] >> 4) & 0x01);
pwr_regs[4] |= ((cp[7] << 3) & 0xF8) | ((cp[6] >> 2) & 0x07);
pwr_regs[5] |= ((cp[9] << 7) & 0x80) | ((cp[8] << 1) & 0x7E) |
((cp[7] >> 5) & 0x01);
pwr_regs[6] |= ((cp[10] << 5) & 0xE0) | ((cp[9] >> 1) & 0x1F);
pwr_regs[7] |= ((cp[11] << 3) & 0xF8) | ((cp[10] >> 3) & 0x07);
pwr_regs[8] |= ((cp[12] << 1) & 0x7E) | ((cp[11] >> 5) & 0x01);
pwr_regs[9] |= ((cp[13] << 5) & 0xE0);
pwr_regs[10] |= ((cp[14] << 3) & 0xF8) | ((cp[13] >> 3) & 0x07);
pwr_regs[11] |= ((cp[14] >> 5) & 0x01);
pwr_regs[8] |= (ath_hal_reverseBits(cp[15], 3) << 7) & 0x80;
pwr_regs[9] |= (ath_hal_reverseBits(cp[15], 3) >> 1) & 0x03;
pwr_regs[9] |= (ath_hal_reverseBits(cp[16], 3) << 2) & 0x1C;
for (i = 0; i < N(pwr_regs)-1; i++)
OS_REG_WRITE(ah, 0x0000989c, pwr_regs[i]);
OS_REG_WRITE(ah, 0x000098d4, pwr_regs[i]);
return AH_TRUE;
#undef N
}
static HAL_BOOL
ar5210SetChannel(struct ath_hal *ah, struct ieee80211_channel *chan)
{
uint16_t freq = ath_hal_gethwchannel(ah, chan);
uint32_t data;
data = ath_hal_reverseBits((freq - 5120)/10, 5);
data = (data << 1) | 0x41;
OS_REG_WRITE(ah, AR_PHY(0x27), data);
OS_REG_WRITE(ah, AR_PHY(0x30), 0);
AH_PRIVATE(ah)->ah_curchan = chan;
return AH_TRUE;
}
int16_t
ar5210GetNoiseFloor(struct ath_hal *ah)
{
int16_t nf;
nf = (OS_REG_READ(ah, AR_PHY(25)) >> 19) & 0x1ff;
if (nf & 0x100)
nf = 0 - ((nf ^ 0x1ff) + 1);
return nf;
}
#define NORMAL_NF_THRESH (-72)
HAL_BOOL
ar5210CalNoiseFloor(struct ath_hal *ah, HAL_CHANNEL_INTERNAL *ichan)
{
int32_t nf, nfLoops;
OS_REG_WRITE(ah, AR_PHY_AGCCTL,
OS_REG_READ(ah, AR_PHY_AGCCTL) | AR_PHY_AGC_NF);
if (!ath_hal_wait(ah, AR_PHY_AGCCTL, AR_PHY_AGC_NF, 0)) {
#ifdef ATH_HAL_DEBUG
ath_hal_printf(ah, " -PHY NF Reg state: 0x%x\n",
OS_REG_READ(ah, AR_PHY_AGCCTL));
ath_hal_printf(ah, " -MAC Reset Reg state: 0x%x\n",
OS_REG_READ(ah, AR_RC));
ath_hal_printf(ah, " -PHY Active Reg state: 0x%x\n",
OS_REG_READ(ah, AR_PHY_ACTIVE));
#endif
return AH_FALSE;
}
nf = 0;
for (nfLoops = 0; ((nfLoops < 21) && (nf > NORMAL_NF_THRESH)); nfLoops++) {
OS_DELAY(1000);
nf = ar5210GetNoiseFloor(ah);
}
if (nf > NORMAL_NF_THRESH) {
HALDEBUG(ah, HAL_DEBUG_ANY, "%s: Bad noise cal %d\n",
__func__, nf);
ichan->rawNoiseFloor = 0;
return AH_FALSE;
}
ichan->rawNoiseFloor = nf;
return AH_TRUE;
}
int16_t
ar5210GetNfAdjust(struct ath_hal *ah, const HAL_CHANNEL_INTERNAL *c)
{
return 0;
}
HAL_RFGAIN
ar5210GetRfgain(struct ath_hal *ah)
{
return HAL_RFGAIN_INACTIVE;
}