ar5211_reset.c revision 208644
1185377Ssam/* 2187831Ssam * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting 3185377Ssam * Copyright (c) 2002-2006 Atheros Communications, Inc. 4185377Ssam * 5185377Ssam * Permission to use, copy, modify, and/or distribute this software for any 6185377Ssam * purpose with or without fee is hereby granted, provided that the above 7185377Ssam * copyright notice and this permission notice appear in all copies. 8185377Ssam * 9185377Ssam * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10185377Ssam * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11185377Ssam * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12185377Ssam * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13185377Ssam * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14185377Ssam * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15185377Ssam * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16185377Ssam * 17187611Ssam * $FreeBSD: head/sys/dev/ath/ath_hal/ar5211/ar5211_reset.c 208644 2010-05-29 16:14:02Z rpaulo $ 18185377Ssam */ 19185377Ssam#include "opt_ah.h" 20185377Ssam 21185377Ssam/* 22185377Ssam * Chips specific device attachment and device info collection 23185377Ssam * Connects Init Reg Vectors, EEPROM Data, and device Functions. 24185377Ssam */ 25185377Ssam#include "ah.h" 26185377Ssam#include "ah_internal.h" 27185377Ssam#include "ah_devid.h" 28185377Ssam 29185377Ssam#include "ar5211/ar5211.h" 30185377Ssam#include "ar5211/ar5211reg.h" 31185377Ssam#include "ar5211/ar5211phy.h" 32185377Ssam 33185377Ssam#include "ah_eeprom_v3.h" 34185377Ssam 35185377Ssam/* Add static register initialization vectors */ 36185377Ssam#include "ar5211/boss.ini" 37185377Ssam 38185377Ssam/* 39185377Ssam * Structure to hold 11b tuning information for Beanie/Sombrero 40185377Ssam * 16 MHz mode, divider ratio = 198 = NP+S. N=16, S=4 or 6, P=12 41185377Ssam */ 42185377Ssamtypedef struct { 43185377Ssam uint32_t refClkSel; /* reference clock, 1 for 16 MHz */ 44185377Ssam uint32_t channelSelect; /* P[7:4]S[3:0] bits */ 45185377Ssam uint16_t channel5111; /* 11a channel for 5111 */ 46185377Ssam} CHAN_INFO_2GHZ; 47185377Ssam 48185377Ssam#define CI_2GHZ_INDEX_CORRECTION 19 49208644Srpaulostatic const CHAN_INFO_2GHZ chan2GHzData[] = { 50185377Ssam { 1, 0x46, 96 }, /* 2312 -19 */ 51185377Ssam { 1, 0x46, 97 }, /* 2317 -18 */ 52185377Ssam { 1, 0x46, 98 }, /* 2322 -17 */ 53185377Ssam { 1, 0x46, 99 }, /* 2327 -16 */ 54185377Ssam { 1, 0x46, 100 }, /* 2332 -15 */ 55185377Ssam { 1, 0x46, 101 }, /* 2337 -14 */ 56185377Ssam { 1, 0x46, 102 }, /* 2342 -13 */ 57185377Ssam { 1, 0x46, 103 }, /* 2347 -12 */ 58185377Ssam { 1, 0x46, 104 }, /* 2352 -11 */ 59185377Ssam { 1, 0x46, 105 }, /* 2357 -10 */ 60185377Ssam { 1, 0x46, 106 }, /* 2362 -9 */ 61185377Ssam { 1, 0x46, 107 }, /* 2367 -8 */ 62185377Ssam { 1, 0x46, 108 }, /* 2372 -7 */ 63185377Ssam /* index -6 to 0 are pad to make this a nolookup table */ 64185377Ssam { 1, 0x46, 116 }, /* -6 */ 65185377Ssam { 1, 0x46, 116 }, /* -5 */ 66185377Ssam { 1, 0x46, 116 }, /* -4 */ 67185377Ssam { 1, 0x46, 116 }, /* -3 */ 68185377Ssam { 1, 0x46, 116 }, /* -2 */ 69185377Ssam { 1, 0x46, 116 }, /* -1 */ 70185377Ssam { 1, 0x46, 116 }, /* 0 */ 71185377Ssam { 1, 0x46, 116 }, /* 2412 1 */ 72185377Ssam { 1, 0x46, 117 }, /* 2417 2 */ 73185377Ssam { 1, 0x46, 118 }, /* 2422 3 */ 74185377Ssam { 1, 0x46, 119 }, /* 2427 4 */ 75185377Ssam { 1, 0x46, 120 }, /* 2432 5 */ 76185377Ssam { 1, 0x46, 121 }, /* 2437 6 */ 77185377Ssam { 1, 0x46, 122 }, /* 2442 7 */ 78185377Ssam { 1, 0x46, 123 }, /* 2447 8 */ 79185377Ssam { 1, 0x46, 124 }, /* 2452 9 */ 80185377Ssam { 1, 0x46, 125 }, /* 2457 10 */ 81185377Ssam { 1, 0x46, 126 }, /* 2462 11 */ 82185377Ssam { 1, 0x46, 127 }, /* 2467 12 */ 83185377Ssam { 1, 0x46, 128 }, /* 2472 13 */ 84185377Ssam { 1, 0x44, 124 }, /* 2484 14 */ 85185377Ssam { 1, 0x46, 136 }, /* 2512 15 */ 86185377Ssam { 1, 0x46, 140 }, /* 2532 16 */ 87185377Ssam { 1, 0x46, 144 }, /* 2552 17 */ 88185377Ssam { 1, 0x46, 148 }, /* 2572 18 */ 89185377Ssam { 1, 0x46, 152 }, /* 2592 19 */ 90185377Ssam { 1, 0x46, 156 }, /* 2612 20 */ 91185377Ssam { 1, 0x46, 160 }, /* 2632 21 */ 92185377Ssam { 1, 0x46, 164 }, /* 2652 22 */ 93185377Ssam { 1, 0x46, 168 }, /* 2672 23 */ 94185377Ssam { 1, 0x46, 172 }, /* 2692 24 */ 95185377Ssam { 1, 0x46, 176 }, /* 2712 25 */ 96185377Ssam { 1, 0x46, 180 } /* 2732 26 */ 97185377Ssam}; 98185377Ssam 99185377Ssam/* Power timeouts in usec to wait for chip to wake-up. */ 100185377Ssam#define POWER_UP_TIME 2000 101185377Ssam 102185377Ssam#define DELAY_PLL_SETTLE 300 /* 300 us */ 103185377Ssam#define DELAY_BASE_ACTIVATE 100 /* 100 us */ 104185377Ssam 105185377Ssam#define NUM_RATES 8 106185377Ssam 107185377Ssamstatic HAL_BOOL ar5211SetResetReg(struct ath_hal *ah, uint32_t resetMask); 108187831Ssamstatic HAL_BOOL ar5211SetChannel(struct ath_hal *, 109187831Ssam const struct ieee80211_channel *); 110185377Ssamstatic int16_t ar5211RunNoiseFloor(struct ath_hal *, 111185377Ssam uint8_t runTime, int16_t startingNF); 112187831Ssamstatic HAL_BOOL ar5211IsNfGood(struct ath_hal *, 113187831Ssam struct ieee80211_channel *chan); 114187831Ssamstatic HAL_BOOL ar5211SetRf6and7(struct ath_hal *, 115187831Ssam const struct ieee80211_channel *chan); 116187831Ssamstatic HAL_BOOL ar5211SetBoardValues(struct ath_hal *, 117187831Ssam const struct ieee80211_channel *chan); 118185377Ssamstatic void ar5211SetPowerTable(struct ath_hal *, 119185377Ssam PCDACS_EEPROM *pSrcStruct, uint16_t channel); 120187831Ssamstatic HAL_BOOL ar5211SetTransmitPower(struct ath_hal *, 121187831Ssam const struct ieee80211_channel *); 122185377Ssamstatic void ar5211SetRateTable(struct ath_hal *, 123185377Ssam RD_EDGES_POWER *pRdEdgesPower, TRGT_POWER_INFO *pPowerInfo, 124187831Ssam uint16_t numChannels, const struct ieee80211_channel *chan); 125185377Ssamstatic uint16_t ar5211GetScaledPower(uint16_t channel, uint16_t pcdacValue, 126185377Ssam const PCDACS_EEPROM *pSrcStruct); 127185377Ssamstatic HAL_BOOL ar5211FindValueInList(uint16_t channel, uint16_t pcdacValue, 128185377Ssam const PCDACS_EEPROM *pSrcStruct, uint16_t *powerValue); 129185377Ssamstatic uint16_t ar5211GetInterpolatedValue(uint16_t target, 130185377Ssam uint16_t srcLeft, uint16_t srcRight, 131185377Ssam uint16_t targetLeft, uint16_t targetRight, HAL_BOOL scaleUp); 132185377Ssamstatic void ar5211GetLowerUpperValues(uint16_t value, 133185377Ssam const uint16_t *pList, uint16_t listSize, 134185377Ssam uint16_t *pLowerValue, uint16_t *pUpperValue); 135185377Ssamstatic void ar5211GetLowerUpperPcdacs(uint16_t pcdac, 136185377Ssam uint16_t channel, const PCDACS_EEPROM *pSrcStruct, 137185377Ssam uint16_t *pLowerPcdac, uint16_t *pUpperPcdac); 138185377Ssam 139201758Smbrstatic void ar5211SetRfgain(struct ath_hal *, const GAIN_VALUES *); 140185377Ssamstatic void ar5211RequestRfgain(struct ath_hal *); 141185377Ssamstatic HAL_BOOL ar5211InvalidGainReadback(struct ath_hal *, GAIN_VALUES *); 142185377Ssamstatic HAL_BOOL ar5211IsGainAdjustNeeded(struct ath_hal *, const GAIN_VALUES *); 143185377Ssamstatic int32_t ar5211AdjustGain(struct ath_hal *, GAIN_VALUES *); 144185377Ssamstatic void ar5211SetOperatingMode(struct ath_hal *, int opmode); 145185377Ssam 146185377Ssam/* 147185377Ssam * Places the device in and out of reset and then places sane 148185377Ssam * values in the registers based on EEPROM config, initialization 149185377Ssam * vectors (as determined by the mode), and station configuration 150185377Ssam * 151185377Ssam * bChannelChange is used to preserve DMA/PCU registers across 152185377Ssam * a HW Reset during channel change. 153185377Ssam */ 154185377SsamHAL_BOOL 155185377Ssamar5211Reset(struct ath_hal *ah, HAL_OPMODE opmode, 156187831Ssam struct ieee80211_channel *chan, HAL_BOOL bChannelChange, 157187831Ssam HAL_STATUS *status) 158185377Ssam{ 159185377Ssamuint32_t softLedCfg, softLedState; 160185377Ssam#define N(a) (sizeof (a) /sizeof (a[0])) 161185377Ssam#define FAIL(_code) do { ecode = _code; goto bad; } while (0) 162185377Ssam struct ath_hal_5211 *ahp = AH5211(ah); 163185377Ssam HAL_CHANNEL_INTERNAL *ichan; 164185377Ssam uint32_t i, ledstate; 165185377Ssam HAL_STATUS ecode; 166185377Ssam int q; 167185377Ssam 168185377Ssam uint32_t data, synthDelay; 169185377Ssam uint32_t macStaId1; 170185377Ssam uint16_t modesIndex = 0, freqIndex = 0; 171185377Ssam uint32_t saveFrameSeqCount[AR_NUM_DCU]; 172185377Ssam uint32_t saveTsfLow = 0, saveTsfHigh = 0; 173185377Ssam uint32_t saveDefAntenna; 174185377Ssam 175185377Ssam HALDEBUG(ah, HAL_DEBUG_RESET, 176185377Ssam "%s: opmode %u channel %u/0x%x %s channel\n", 177187831Ssam __func__, opmode, chan->ic_freq, chan->ic_flags, 178185377Ssam bChannelChange ? "change" : "same"); 179185377Ssam 180185377Ssam OS_MARK(ah, AH_MARK_RESET, bChannelChange); 181185377Ssam /* 182185377Ssam * Map public channel to private. 183185377Ssam */ 184185377Ssam ichan = ath_hal_checkchannel(ah, chan); 185187831Ssam if (ichan == AH_NULL) 186185377Ssam FAIL(HAL_EINVAL); 187185377Ssam switch (opmode) { 188185377Ssam case HAL_M_STA: 189185377Ssam case HAL_M_IBSS: 190185377Ssam case HAL_M_HOSTAP: 191185377Ssam case HAL_M_MONITOR: 192185377Ssam break; 193185377Ssam default: 194185377Ssam HALDEBUG(ah, HAL_DEBUG_ANY, 195185377Ssam "%s: invalid operating mode %u\n", __func__, opmode); 196185377Ssam FAIL(HAL_EINVAL); 197185377Ssam break; 198185377Ssam } 199185377Ssam HALASSERT(AH_PRIVATE(ah)->ah_eeversion >= AR_EEPROM_VER3); 200185377Ssam 201185377Ssam /* Preserve certain DMA hardware registers on a channel change */ 202185377Ssam if (bChannelChange) { 203185377Ssam /* 204185377Ssam * Need to save/restore the TSF because of an issue 205185377Ssam * that accelerates the TSF during a chip reset. 206185377Ssam * 207185377Ssam * We could use system timer routines to more 208185377Ssam * accurately restore the TSF, but 209185377Ssam * 1. Timer routines on certain platforms are 210185377Ssam * not accurate enough (e.g. 1 ms resolution). 211185377Ssam * 2. It would still not be accurate. 212185377Ssam * 213185380Ssam * The most important aspect of this workaround, 214185377Ssam * is that, after reset, the TSF is behind 215185377Ssam * other STAs TSFs. This will allow the STA to 216185377Ssam * properly resynchronize its TSF in adhoc mode. 217185377Ssam */ 218185377Ssam saveTsfLow = OS_REG_READ(ah, AR_TSF_L32); 219185377Ssam saveTsfHigh = OS_REG_READ(ah, AR_TSF_U32); 220185377Ssam 221185377Ssam /* Read frame sequence count */ 222185377Ssam if (AH_PRIVATE(ah)->ah_macVersion >= AR_SREV_VERSION_OAHU) { 223185377Ssam saveFrameSeqCount[0] = OS_REG_READ(ah, AR_D0_SEQNUM); 224185377Ssam } else { 225185377Ssam for (i = 0; i < AR_NUM_DCU; i++) 226185377Ssam saveFrameSeqCount[i] = OS_REG_READ(ah, AR_DSEQNUM(i)); 227185377Ssam } 228187831Ssam if (!IEEE80211_IS_CHAN_DFS(chan)) 229187831Ssam chan->ic_state &= ~IEEE80211_CHANSTATE_CWINT; 230185377Ssam } 231185377Ssam 232185377Ssam /* 233185377Ssam * Preserve the antenna on a channel change 234185377Ssam */ 235185377Ssam saveDefAntenna = OS_REG_READ(ah, AR_DEF_ANTENNA); 236185377Ssam if (saveDefAntenna == 0) 237185377Ssam saveDefAntenna = 1; 238185377Ssam 239185377Ssam /* Save hardware flag before chip reset clears the register */ 240185377Ssam macStaId1 = OS_REG_READ(ah, AR_STA_ID1) & AR_STA_ID1_BASE_RATE_11B; 241185377Ssam 242185377Ssam /* Save led state from pci config register */ 243185377Ssam ledstate = OS_REG_READ(ah, AR_PCICFG) & 244185377Ssam (AR_PCICFG_LEDCTL | AR_PCICFG_LEDMODE | AR_PCICFG_LEDBLINK | 245185377Ssam AR_PCICFG_LEDSLOW); 246185377Ssam softLedCfg = OS_REG_READ(ah, AR_GPIOCR); 247185377Ssam softLedState = OS_REG_READ(ah, AR_GPIODO); 248185377Ssam 249187831Ssam if (!ar5211ChipReset(ah, chan)) { 250185377Ssam HALDEBUG(ah, HAL_DEBUG_ANY, "%s: chip reset failed\n", __func__); 251185377Ssam FAIL(HAL_EIO); 252185377Ssam } 253185377Ssam 254185377Ssam /* Setup the indices for the next set of register array writes */ 255187831Ssam if (IEEE80211_IS_CHAN_5GHZ(chan)) { 256187831Ssam freqIndex = 1; 257187831Ssam if (IEEE80211_IS_CHAN_TURBO(chan)) 258187831Ssam modesIndex = 2; 259187831Ssam else if (IEEE80211_IS_CHAN_A(chan)) 260187831Ssam modesIndex = 1; 261187831Ssam else { 262187831Ssam HALDEBUG(ah, HAL_DEBUG_ANY, 263187831Ssam "%s: invalid channel %u/0x%x\n", 264187831Ssam __func__, chan->ic_freq, chan->ic_flags); 265187831Ssam FAIL(HAL_EINVAL); 266187831Ssam } 267187831Ssam } else { 268187831Ssam freqIndex = 2; 269187831Ssam if (IEEE80211_IS_CHAN_B(chan)) 270187831Ssam modesIndex = 3; 271187831Ssam else if (IEEE80211_IS_CHAN_PUREG(chan)) 272187831Ssam modesIndex = 4; 273187831Ssam else { 274187831Ssam HALDEBUG(ah, HAL_DEBUG_ANY, 275187831Ssam "%s: invalid channel %u/0x%x\n", 276187831Ssam __func__, chan->ic_freq, chan->ic_flags); 277187831Ssam FAIL(HAL_EINVAL); 278187831Ssam } 279185377Ssam } 280185377Ssam 281185377Ssam /* Set correct Baseband to analog shift setting to access analog chips. */ 282185377Ssam if (AH_PRIVATE(ah)->ah_macVersion >= AR_SREV_VERSION_OAHU) { 283185377Ssam OS_REG_WRITE(ah, AR_PHY_BASE, 0x00000007); 284185377Ssam } else { 285185377Ssam OS_REG_WRITE(ah, AR_PHY_BASE, 0x00000047); 286185377Ssam } 287185377Ssam 288185377Ssam /* Write parameters specific to AR5211 */ 289185377Ssam if (AH_PRIVATE(ah)->ah_macVersion >= AR_SREV_VERSION_OAHU) { 290187831Ssam if (IEEE80211_IS_CHAN_2GHZ(chan) && 291185377Ssam AH_PRIVATE(ah)->ah_eeversion >= AR_EEPROM_VER3_1) { 292185377Ssam HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom; 293185377Ssam uint32_t ob2GHz, db2GHz; 294185377Ssam 295187831Ssam if (IEEE80211_IS_CHAN_CCK(chan)) { 296185377Ssam ob2GHz = ee->ee_ob2GHz[0]; 297185377Ssam db2GHz = ee->ee_db2GHz[0]; 298185377Ssam } else { 299185377Ssam ob2GHz = ee->ee_ob2GHz[1]; 300185377Ssam db2GHz = ee->ee_db2GHz[1]; 301185377Ssam } 302185377Ssam ob2GHz = ath_hal_reverseBits(ob2GHz, 3); 303185377Ssam db2GHz = ath_hal_reverseBits(db2GHz, 3); 304185377Ssam ar5211Mode2_4[25][freqIndex] = 305185377Ssam (ar5211Mode2_4[25][freqIndex] & ~0xC0) | 306185377Ssam ((ob2GHz << 6) & 0xC0); 307185377Ssam ar5211Mode2_4[26][freqIndex] = 308185377Ssam (ar5211Mode2_4[26][freqIndex] & ~0x0F) | 309185377Ssam (((ob2GHz >> 2) & 0x1) | 310185377Ssam ((db2GHz << 1) & 0x0E)); 311185377Ssam } 312185377Ssam for (i = 0; i < N(ar5211Mode2_4); i++) 313185377Ssam OS_REG_WRITE(ah, ar5211Mode2_4[i][0], 314185377Ssam ar5211Mode2_4[i][freqIndex]); 315185377Ssam } 316185377Ssam 317185377Ssam /* Write the analog registers 6 and 7 before other config */ 318185377Ssam ar5211SetRf6and7(ah, chan); 319185377Ssam 320185377Ssam /* Write registers that vary across all modes */ 321185377Ssam for (i = 0; i < N(ar5211Modes); i++) 322185377Ssam OS_REG_WRITE(ah, ar5211Modes[i][0], ar5211Modes[i][modesIndex]); 323185377Ssam 324185377Ssam /* Write RFGain Parameters that differ between 2.4 and 5 GHz */ 325185377Ssam for (i = 0; i < N(ar5211BB_RfGain); i++) 326185377Ssam OS_REG_WRITE(ah, ar5211BB_RfGain[i][0], ar5211BB_RfGain[i][freqIndex]); 327185377Ssam 328185377Ssam /* Write Common Array Parameters */ 329185377Ssam for (i = 0; i < N(ar5211Common); i++) { 330185377Ssam uint32_t reg = ar5211Common[i][0]; 331185377Ssam /* On channel change, don't reset the PCU registers */ 332185377Ssam if (!(bChannelChange && (0x8000 <= reg && reg < 0x9000))) 333185377Ssam OS_REG_WRITE(ah, reg, ar5211Common[i][1]); 334185377Ssam } 335185377Ssam 336185377Ssam /* Fix pre-AR5211 register values, this includes AR5311s. */ 337185377Ssam if (AH_PRIVATE(ah)->ah_macVersion < AR_SREV_VERSION_OAHU) { 338185377Ssam /* 339185377Ssam * The TX and RX latency values have changed locations 340185377Ssam * within the USEC register in AR5211. Since they're 341185377Ssam * set via the .ini, for both AR5211 and AR5311, they 342185377Ssam * are written properly here for AR5311. 343185377Ssam */ 344185377Ssam data = OS_REG_READ(ah, AR_USEC); 345185377Ssam /* Must be 0 for proper write in AR5311 */ 346185377Ssam HALASSERT((data & 0x00700000) == 0); 347185377Ssam OS_REG_WRITE(ah, AR_USEC, 348185377Ssam (data & (AR_USEC_M | AR_USEC_32_M | AR5311_USEC_TX_LAT_M)) | 349185377Ssam ((29 << AR5311_USEC_RX_LAT_S) & AR5311_USEC_RX_LAT_M)); 350185377Ssam /* The following registers exist only on AR5311. */ 351185377Ssam OS_REG_WRITE(ah, AR5311_QDCLKGATE, 0); 352185377Ssam 353185377Ssam /* Set proper ADC & DAC delays for AR5311. */ 354185377Ssam OS_REG_WRITE(ah, 0x00009878, 0x00000008); 355185377Ssam 356185377Ssam /* Enable the PCU FIFO corruption ECO on AR5311. */ 357185377Ssam OS_REG_WRITE(ah, AR_DIAG_SW, 358185377Ssam OS_REG_READ(ah, AR_DIAG_SW) | AR5311_DIAG_SW_USE_ECO); 359185377Ssam } 360185377Ssam 361185377Ssam /* Restore certain DMA hardware registers on a channel change */ 362185377Ssam if (bChannelChange) { 363185377Ssam /* Restore TSF */ 364185377Ssam OS_REG_WRITE(ah, AR_TSF_L32, saveTsfLow); 365185377Ssam OS_REG_WRITE(ah, AR_TSF_U32, saveTsfHigh); 366185377Ssam 367185377Ssam if (AH_PRIVATE(ah)->ah_macVersion >= AR_SREV_VERSION_OAHU) { 368185377Ssam OS_REG_WRITE(ah, AR_D0_SEQNUM, saveFrameSeqCount[0]); 369185377Ssam } else { 370185377Ssam for (i = 0; i < AR_NUM_DCU; i++) 371185377Ssam OS_REG_WRITE(ah, AR_DSEQNUM(i), saveFrameSeqCount[i]); 372185377Ssam } 373185377Ssam } 374185377Ssam 375185377Ssam OS_REG_WRITE(ah, AR_STA_ID0, LE_READ_4(ahp->ah_macaddr)); 376185377Ssam OS_REG_WRITE(ah, AR_STA_ID1, LE_READ_2(ahp->ah_macaddr + 4) 377185377Ssam | macStaId1 378185377Ssam ); 379185377Ssam ar5211SetOperatingMode(ah, opmode); 380185377Ssam 381185377Ssam /* Restore previous led state */ 382185377Ssam OS_REG_WRITE(ah, AR_PCICFG, OS_REG_READ(ah, AR_PCICFG) | ledstate); 383185377Ssam OS_REG_WRITE(ah, AR_GPIOCR, softLedCfg); 384185377Ssam OS_REG_WRITE(ah, AR_GPIODO, softLedState); 385185377Ssam 386185377Ssam /* Restore previous antenna */ 387185377Ssam OS_REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna); 388185377Ssam 389185377Ssam OS_REG_WRITE(ah, AR_BSS_ID0, LE_READ_4(ahp->ah_bssid)); 390185377Ssam OS_REG_WRITE(ah, AR_BSS_ID1, LE_READ_2(ahp->ah_bssid + 4)); 391185377Ssam 392185377Ssam /* Restore bmiss rssi & count thresholds */ 393185377Ssam OS_REG_WRITE(ah, AR_RSSI_THR, ahp->ah_rssiThr); 394185377Ssam 395185377Ssam OS_REG_WRITE(ah, AR_ISR, ~0); /* cleared on write */ 396185377Ssam 397185377Ssam /* 398185377Ssam * for pre-Production Oahu only. 399185377Ssam * Disable clock gating in all DMA blocks. Helps when using 400185380Ssam * 11B and AES but results in higher power consumption. 401185377Ssam */ 402185377Ssam if (AH_PRIVATE(ah)->ah_macVersion == AR_SREV_VERSION_OAHU && 403185377Ssam AH_PRIVATE(ah)->ah_macRev < AR_SREV_OAHU_PROD) { 404185377Ssam OS_REG_WRITE(ah, AR_CFG, 405185377Ssam OS_REG_READ(ah, AR_CFG) | AR_CFG_CLK_GATE_DIS); 406185377Ssam } 407185377Ssam 408185377Ssam /* Setup the transmit power values. */ 409185377Ssam if (!ar5211SetTransmitPower(ah, chan)) { 410185377Ssam HALDEBUG(ah, HAL_DEBUG_ANY, 411185377Ssam "%s: error init'ing transmit power\n", __func__); 412185377Ssam FAIL(HAL_EIO); 413185377Ssam } 414185377Ssam 415185377Ssam /* 416185377Ssam * Configurable OFDM spoofing for 11n compatibility; used 417185377Ssam * only when operating in station mode. 418185377Ssam */ 419185377Ssam if (opmode != HAL_M_HOSTAP && 420185377Ssam (AH_PRIVATE(ah)->ah_11nCompat & HAL_DIAG_11N_SERVICES) != 0) { 421185377Ssam /* NB: override the .ini setting */ 422185377Ssam OS_REG_RMW_FIELD(ah, AR_PHY_FRAME_CTL, 423185377Ssam AR_PHY_FRAME_CTL_ERR_SERV, 424185377Ssam MS(AH_PRIVATE(ah)->ah_11nCompat, HAL_DIAG_11N_SERVICES)&1); 425185377Ssam } 426185377Ssam 427185377Ssam /* Setup board specific options for EEPROM version 3 */ 428185377Ssam ar5211SetBoardValues(ah, chan); 429185377Ssam 430187831Ssam if (!ar5211SetChannel(ah, chan)) { 431185377Ssam HALDEBUG(ah, HAL_DEBUG_ANY, "%s: unable to set channel\n", 432185377Ssam __func__); 433185377Ssam FAIL(HAL_EIO); 434185377Ssam } 435185377Ssam 436185377Ssam /* Activate the PHY */ 437187831Ssam if (AH_PRIVATE(ah)->ah_devid == AR5211_FPGA11B && 438187831Ssam IEEE80211_IS_CHAN_2GHZ(chan)) 439185377Ssam OS_REG_WRITE(ah, 0xd808, 0x502); /* required for FPGA */ 440185377Ssam OS_REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN); 441185377Ssam 442185377Ssam /* 443185377Ssam * Wait for the frequency synth to settle (synth goes on 444185377Ssam * via AR_PHY_ACTIVE_EN). Read the phy active delay register. 445185377Ssam * Value is in 100ns increments. 446185377Ssam */ 447185377Ssam data = OS_REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_M; 448187831Ssam if (IEEE80211_IS_CHAN_CCK(chan)) { 449185377Ssam synthDelay = (4 * data) / 22; 450185377Ssam } else { 451185377Ssam synthDelay = data / 10; 452185377Ssam } 453185377Ssam /* 454185377Ssam * There is an issue if the AP starts the calibration before 455185377Ssam * the baseband timeout completes. This could result in the 456185377Ssam * rxclear false triggering. Add an extra delay to ensure this 457185377Ssam * this does not happen. 458185377Ssam */ 459185377Ssam OS_DELAY(synthDelay + DELAY_BASE_ACTIVATE); 460185377Ssam 461185377Ssam /* Calibrate the AGC and wait for completion. */ 462185377Ssam OS_REG_WRITE(ah, AR_PHY_AGC_CONTROL, 463185377Ssam OS_REG_READ(ah, AR_PHY_AGC_CONTROL) | AR_PHY_AGC_CONTROL_CAL); 464185377Ssam (void) ath_hal_wait(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_CAL, 0); 465185377Ssam 466185377Ssam /* Perform noise floor and set status */ 467187831Ssam if (!ar5211CalNoiseFloor(ah, chan)) { 468187831Ssam if (!IEEE80211_IS_CHAN_CCK(chan)) 469187831Ssam chan->ic_state |= IEEE80211_CHANSTATE_CWINT; 470185377Ssam HALDEBUG(ah, HAL_DEBUG_ANY, 471185377Ssam "%s: noise floor calibration failed\n", __func__); 472185377Ssam FAIL(HAL_EIO); 473185377Ssam } 474185377Ssam 475185377Ssam /* Start IQ calibration w/ 2^(INIT_IQCAL_LOG_COUNT_MAX+1) samples */ 476185377Ssam if (ahp->ah_calibrationTime != 0) { 477185377Ssam OS_REG_WRITE(ah, AR_PHY_TIMING_CTRL4, 478185377Ssam AR_PHY_TIMING_CTRL4_DO_IQCAL | (INIT_IQCAL_LOG_COUNT_MAX << AR_PHY_TIMING_CTRL4_IQCAL_LOG_COUNT_MAX_S)); 479185377Ssam ahp->ah_bIQCalibration = AH_TRUE; 480185377Ssam } 481185377Ssam 482185377Ssam /* set 1:1 QCU to DCU mapping for all queues */ 483185377Ssam for (q = 0; q < AR_NUM_DCU; q++) 484185377Ssam OS_REG_WRITE(ah, AR_DQCUMASK(q), 1<<q); 485185377Ssam 486185377Ssam for (q = 0; q < HAL_NUM_TX_QUEUES; q++) 487185377Ssam ar5211ResetTxQueue(ah, q); 488185377Ssam 489185377Ssam /* Setup QCU0 transmit interrupt masks (TX_ERR, TX_OK, TX_DESC, TX_URN) */ 490185377Ssam OS_REG_WRITE(ah, AR_IMR_S0, 491185377Ssam (AR_IMR_S0_QCU_TXOK & AR_QCU_0) | 492185377Ssam (AR_IMR_S0_QCU_TXDESC & (AR_QCU_0<<AR_IMR_S0_QCU_TXDESC_S))); 493185377Ssam OS_REG_WRITE(ah, AR_IMR_S1, (AR_IMR_S1_QCU_TXERR & AR_QCU_0)); 494185377Ssam OS_REG_WRITE(ah, AR_IMR_S2, (AR_IMR_S2_QCU_TXURN & AR_QCU_0)); 495185377Ssam 496185377Ssam /* 497185377Ssam * GBL_EIFS must always be written after writing 498185377Ssam * to any QCUMASK register. 499185377Ssam */ 500185377Ssam OS_REG_WRITE(ah, AR_D_GBL_IFS_EIFS, OS_REG_READ(ah, AR_D_GBL_IFS_EIFS)); 501185377Ssam 502185377Ssam /* Now set up the Interrupt Mask Register and save it for future use */ 503185377Ssam OS_REG_WRITE(ah, AR_IMR, INIT_INTERRUPT_MASK); 504185377Ssam ahp->ah_maskReg = INIT_INTERRUPT_MASK; 505185377Ssam 506185377Ssam /* Enable bus error interrupts */ 507185377Ssam OS_REG_WRITE(ah, AR_IMR_S2, OS_REG_READ(ah, AR_IMR_S2) | 508185377Ssam AR_IMR_S2_MCABT | AR_IMR_S2_SSERR | AR_IMR_S2_DPERR); 509185377Ssam 510185377Ssam /* Enable interrupts specific to AP */ 511185377Ssam if (opmode == HAL_M_HOSTAP) { 512185377Ssam OS_REG_WRITE(ah, AR_IMR, OS_REG_READ(ah, AR_IMR) | AR_IMR_MIB); 513185377Ssam ahp->ah_maskReg |= AR_IMR_MIB; 514185377Ssam } 515185377Ssam 516185377Ssam if (AH_PRIVATE(ah)->ah_rfkillEnabled) 517185377Ssam ar5211EnableRfKill(ah); 518185377Ssam 519185377Ssam /* 520185377Ssam * Writing to AR_BEACON will start timers. Hence it should 521185377Ssam * be the last register to be written. Do not reset tsf, do 522185377Ssam * not enable beacons at this point, but preserve other values 523185377Ssam * like beaconInterval. 524185377Ssam */ 525185377Ssam OS_REG_WRITE(ah, AR_BEACON, 526185377Ssam (OS_REG_READ(ah, AR_BEACON) &~ (AR_BEACON_EN | AR_BEACON_RESET_TSF))); 527185377Ssam 528185377Ssam /* Restore user-specified slot time and timeouts */ 529185377Ssam if (ahp->ah_sifstime != (u_int) -1) 530185377Ssam ar5211SetSifsTime(ah, ahp->ah_sifstime); 531185377Ssam if (ahp->ah_slottime != (u_int) -1) 532185377Ssam ar5211SetSlotTime(ah, ahp->ah_slottime); 533185377Ssam if (ahp->ah_acktimeout != (u_int) -1) 534185377Ssam ar5211SetAckTimeout(ah, ahp->ah_acktimeout); 535185377Ssam if (ahp->ah_ctstimeout != (u_int) -1) 536185377Ssam ar5211SetCTSTimeout(ah, ahp->ah_ctstimeout); 537185377Ssam if (AH_PRIVATE(ah)->ah_diagreg != 0) 538185377Ssam OS_REG_WRITE(ah, AR_DIAG_SW, AH_PRIVATE(ah)->ah_diagreg); 539185377Ssam 540185377Ssam AH_PRIVATE(ah)->ah_opmode = opmode; /* record operating mode */ 541185377Ssam 542185377Ssam HALDEBUG(ah, HAL_DEBUG_RESET, "%s: done\n", __func__); 543185377Ssam 544185377Ssam return AH_TRUE; 545185377Ssambad: 546187611Ssam if (status != AH_NULL) 547185377Ssam *status = ecode; 548185377Ssam return AH_FALSE; 549185377Ssam#undef FAIL 550185377Ssam#undef N 551185377Ssam} 552185377Ssam 553185377Ssam/* 554185377Ssam * Places the PHY and Radio chips into reset. A full reset 555185377Ssam * must be called to leave this state. The PCI/MAC/PCU are 556185377Ssam * not placed into reset as we must receive interrupt to 557185377Ssam * re-enable the hardware. 558185377Ssam */ 559185377SsamHAL_BOOL 560185377Ssamar5211PhyDisable(struct ath_hal *ah) 561185377Ssam{ 562185377Ssam return ar5211SetResetReg(ah, AR_RC_BB); 563185377Ssam} 564185377Ssam 565185377Ssam/* 566185377Ssam * Places all of hardware into reset 567185377Ssam */ 568185377SsamHAL_BOOL 569185377Ssamar5211Disable(struct ath_hal *ah) 570185377Ssam{ 571185377Ssam if (!ar5211SetPowerMode(ah, HAL_PM_AWAKE, AH_TRUE)) 572185377Ssam return AH_FALSE; 573185377Ssam /* 574185377Ssam * Reset the HW - PCI must be reset after the rest of the 575185377Ssam * device has been reset. 576185377Ssam */ 577185377Ssam if (!ar5211SetResetReg(ah, AR_RC_MAC | AR_RC_BB | AR_RC_PCI)) 578185377Ssam return AH_FALSE; 579185377Ssam OS_DELAY(2100); /* 8245 @ 96Mhz hangs with 2000us. */ 580185377Ssam 581185377Ssam return AH_TRUE; 582185377Ssam} 583185377Ssam 584185377Ssam/* 585185377Ssam * Places the hardware into reset and then pulls it out of reset 586185377Ssam * 587185377Ssam * Only write the PLL if we're changing to or from CCK mode 588185377Ssam * 589185377Ssam * Attach calls with channelFlags = 0, as the coldreset should have 590185377Ssam * us in the correct mode and we cannot check the hwchannel flags. 591185377Ssam */ 592185377SsamHAL_BOOL 593187831Ssamar5211ChipReset(struct ath_hal *ah, const struct ieee80211_channel *chan) 594185377Ssam{ 595185377Ssam if (!ar5211SetPowerMode(ah, HAL_PM_AWAKE, AH_TRUE)) 596185377Ssam return AH_FALSE; 597185377Ssam 598187831Ssam /* NB: called from attach with chan null */ 599187831Ssam if (chan != AH_NULL) { 600187831Ssam /* Set CCK and Turbo modes correctly */ 601187831Ssam OS_REG_WRITE(ah, AR_PHY_TURBO, IEEE80211_IS_CHAN_TURBO(chan) ? 602187831Ssam AR_PHY_FC_TURBO_MODE | AR_PHY_FC_TURBO_SHORT : 0); 603187831Ssam if (IEEE80211_IS_CHAN_B(chan)) { 604187831Ssam OS_REG_WRITE(ah, AR5211_PHY_MODE, 605187831Ssam AR5211_PHY_MODE_CCK | AR5211_PHY_MODE_RF2GHZ); 606187831Ssam OS_REG_WRITE(ah, AR_PHY_PLL_CTL, AR_PHY_PLL_CTL_44); 607187831Ssam /* Wait for the PLL to settle */ 608185377Ssam OS_DELAY(DELAY_PLL_SETTLE); 609187831Ssam } else if (AH_PRIVATE(ah)->ah_devid == AR5211_DEVID) { 610185377Ssam OS_REG_WRITE(ah, AR_PHY_PLL_CTL, AR_PHY_PLL_CTL_40); 611185377Ssam OS_DELAY(DELAY_PLL_SETTLE); 612185377Ssam OS_REG_WRITE(ah, AR5211_PHY_MODE, 613187831Ssam AR5211_PHY_MODE_OFDM | (IEEE80211_IS_CHAN_2GHZ(chan) ? 614187831Ssam AR5211_PHY_MODE_RF2GHZ : 615187831Ssam AR5211_PHY_MODE_RF5GHZ)); 616185377Ssam } 617185377Ssam } 618185377Ssam 619185377Ssam /* 620185377Ssam * Reset the HW - PCI must be reset after the rest of the 621185377Ssam * device has been reset 622185377Ssam */ 623185377Ssam if (!ar5211SetResetReg(ah, AR_RC_MAC | AR_RC_BB | AR_RC_PCI)) 624185377Ssam return AH_FALSE; 625185377Ssam OS_DELAY(2100); /* 8245 @ 96Mhz hangs with 2000us. */ 626185377Ssam 627185377Ssam /* Bring out of sleep mode (AGAIN) */ 628185377Ssam if (!ar5211SetPowerMode(ah, HAL_PM_AWAKE, AH_TRUE)) 629185377Ssam return AH_FALSE; 630185377Ssam 631185377Ssam /* Clear warm reset register */ 632185377Ssam return ar5211SetResetReg(ah, 0); 633185377Ssam} 634185377Ssam 635185377Ssam/* 636185377Ssam * Recalibrate the lower PHY chips to account for temperature/environment 637185377Ssam * changes. 638185377Ssam */ 639185377SsamHAL_BOOL 640187831Ssamar5211PerCalibrationN(struct ath_hal *ah, struct ieee80211_channel *chan, 641187831Ssam u_int chainMask, HAL_BOOL longCal, HAL_BOOL *isCalDone) 642185377Ssam{ 643185377Ssam struct ath_hal_5211 *ahp = AH5211(ah); 644185377Ssam HAL_CHANNEL_INTERNAL *ichan; 645185377Ssam int32_t qCoff, qCoffDenom; 646185377Ssam uint32_t data; 647185377Ssam int32_t iqCorrMeas; 648185377Ssam int32_t iCoff, iCoffDenom; 649185377Ssam uint32_t powerMeasQ, powerMeasI; 650185377Ssam 651185377Ssam ichan = ath_hal_checkchannel(ah, chan); 652185377Ssam if (ichan == AH_NULL) { 653185377Ssam HALDEBUG(ah, HAL_DEBUG_ANY, 654185377Ssam "%s: invalid channel %u/0x%x; no mapping\n", 655187831Ssam __func__, chan->ic_freq, chan->ic_flags); 656185377Ssam return AH_FALSE; 657185377Ssam } 658185377Ssam /* IQ calibration in progress. Check to see if it has finished. */ 659185377Ssam if (ahp->ah_bIQCalibration && 660185377Ssam !(OS_REG_READ(ah, AR_PHY_TIMING_CTRL4) & AR_PHY_TIMING_CTRL4_DO_IQCAL)) { 661185377Ssam /* IQ Calibration has finished. */ 662185377Ssam ahp->ah_bIQCalibration = AH_FALSE; 663185377Ssam 664185377Ssam /* Read calibration results. */ 665185377Ssam powerMeasI = OS_REG_READ(ah, AR_PHY_IQCAL_RES_PWR_MEAS_I); 666185377Ssam powerMeasQ = OS_REG_READ(ah, AR_PHY_IQCAL_RES_PWR_MEAS_Q); 667185377Ssam iqCorrMeas = OS_REG_READ(ah, AR_PHY_IQCAL_RES_IQ_CORR_MEAS); 668185377Ssam 669185377Ssam /* 670185377Ssam * Prescale these values to remove 64-bit operation requirement at the loss 671185377Ssam * of a little precision. 672185377Ssam */ 673185377Ssam iCoffDenom = (powerMeasI / 2 + powerMeasQ / 2) / 128; 674185377Ssam qCoffDenom = powerMeasQ / 64; 675185377Ssam 676185377Ssam /* Protect against divide-by-0. */ 677185377Ssam if (iCoffDenom != 0 && qCoffDenom != 0) { 678185377Ssam iCoff = (-iqCorrMeas) / iCoffDenom; 679185377Ssam /* IQCORR_Q_I_COFF is a signed 6 bit number */ 680185377Ssam iCoff = iCoff & 0x3f; 681185377Ssam 682185377Ssam qCoff = ((int32_t)powerMeasI / qCoffDenom) - 64; 683185377Ssam /* IQCORR_Q_Q_COFF is a signed 5 bit number */ 684185377Ssam qCoff = qCoff & 0x1f; 685185377Ssam 686185377Ssam HALDEBUG(ah, HAL_DEBUG_PERCAL, "powerMeasI = 0x%08x\n", 687185377Ssam powerMeasI); 688185377Ssam HALDEBUG(ah, HAL_DEBUG_PERCAL, "powerMeasQ = 0x%08x\n", 689185377Ssam powerMeasQ); 690185377Ssam HALDEBUG(ah, HAL_DEBUG_PERCAL, "iqCorrMeas = 0x%08x\n", 691185377Ssam iqCorrMeas); 692185377Ssam HALDEBUG(ah, HAL_DEBUG_PERCAL, "iCoff = %d\n", 693185377Ssam iCoff); 694185377Ssam HALDEBUG(ah, HAL_DEBUG_PERCAL, "qCoff = %d\n", 695185377Ssam qCoff); 696185377Ssam 697185377Ssam /* Write IQ */ 698185377Ssam data = OS_REG_READ(ah, AR_PHY_TIMING_CTRL4) | 699185377Ssam AR_PHY_TIMING_CTRL4_IQCORR_ENABLE | 700185377Ssam (((uint32_t)iCoff) << AR_PHY_TIMING_CTRL4_IQCORR_Q_I_COFF_S) | 701185377Ssam ((uint32_t)qCoff); 702185377Ssam OS_REG_WRITE(ah, AR_PHY_TIMING_CTRL4, data); 703185377Ssam } 704185377Ssam } 705185380Ssam *isCalDone = !ahp->ah_bIQCalibration; 706185377Ssam 707185380Ssam if (longCal) { 708185380Ssam /* Perform noise floor and set status */ 709187831Ssam if (!ar5211IsNfGood(ah, chan)) { 710185380Ssam /* report up and clear internal state */ 711187831Ssam chan->ic_state |= IEEE80211_CHANSTATE_CWINT; 712185377Ssam return AH_FALSE; 713185377Ssam } 714187831Ssam if (!ar5211CalNoiseFloor(ah, chan)) { 715185380Ssam /* 716185380Ssam * Delay 5ms before retrying the noise floor 717185380Ssam * just to make sure, as we are in an error 718185380Ssam * condition here. 719185380Ssam */ 720185380Ssam OS_DELAY(5000); 721187831Ssam if (!ar5211CalNoiseFloor(ah, chan)) { 722187831Ssam if (!IEEE80211_IS_CHAN_CCK(chan)) 723187831Ssam chan->ic_state |= IEEE80211_CHANSTATE_CWINT; 724185380Ssam return AH_FALSE; 725185380Ssam } 726185380Ssam } 727185380Ssam ar5211RequestRfgain(ah); 728185377Ssam } 729185380Ssam return AH_TRUE; 730185380Ssam} 731185377Ssam 732185380SsamHAL_BOOL 733187831Ssamar5211PerCalibration(struct ath_hal *ah, struct ieee80211_channel *chan, 734187831Ssam HAL_BOOL *isIQdone) 735185380Ssam{ 736185380Ssam return ar5211PerCalibrationN(ah, chan, 0x1, AH_TRUE, isIQdone); 737185380Ssam} 738185377Ssam 739185380SsamHAL_BOOL 740187831Ssamar5211ResetCalValid(struct ath_hal *ah, const struct ieee80211_channel *chan) 741185380Ssam{ 742185380Ssam /* XXX */ 743185377Ssam return AH_TRUE; 744185377Ssam} 745185377Ssam 746185377Ssam/* 747185377Ssam * Writes the given reset bit mask into the reset register 748185377Ssam */ 749185377Ssamstatic HAL_BOOL 750185377Ssamar5211SetResetReg(struct ath_hal *ah, uint32_t resetMask) 751185377Ssam{ 752185377Ssam uint32_t mask = resetMask ? resetMask : ~0; 753185377Ssam HAL_BOOL rt; 754185377Ssam 755185377Ssam (void) OS_REG_READ(ah, AR_RXDP);/* flush any pending MMR writes */ 756185377Ssam OS_REG_WRITE(ah, AR_RC, resetMask); 757185377Ssam 758185377Ssam /* need to wait at least 128 clocks when reseting PCI before read */ 759185377Ssam OS_DELAY(15); 760185377Ssam 761185377Ssam resetMask &= AR_RC_MAC | AR_RC_BB; 762185377Ssam mask &= AR_RC_MAC | AR_RC_BB; 763185377Ssam rt = ath_hal_wait(ah, AR_RC, mask, resetMask); 764185377Ssam if ((resetMask & AR_RC_MAC) == 0) { 765185377Ssam if (isBigEndian()) { 766185377Ssam /* 767185377Ssam * Set CFG, little-endian for register 768185377Ssam * and descriptor accesses. 769185377Ssam */ 770185377Ssam mask = INIT_CONFIG_STATUS | 771185377Ssam AR_CFG_SWTD | AR_CFG_SWRD | AR_CFG_SWRG; 772185377Ssam OS_REG_WRITE(ah, AR_CFG, LE_READ_4(&mask)); 773185377Ssam } else 774185377Ssam OS_REG_WRITE(ah, AR_CFG, INIT_CONFIG_STATUS); 775185377Ssam } 776185377Ssam return rt; 777185377Ssam} 778185377Ssam 779185377Ssam/* 780185377Ssam * Takes the MHz channel value and sets the Channel value 781185377Ssam * 782185377Ssam * ASSUMES: Writes enabled to analog bus before AGC is active 783185377Ssam * or by disabling the AGC. 784185377Ssam */ 785185377Ssamstatic HAL_BOOL 786187831Ssamar5211SetChannel(struct ath_hal *ah, const struct ieee80211_channel *chan) 787185377Ssam{ 788185377Ssam uint32_t refClk, reg32, data2111; 789185377Ssam int16_t chan5111, chanIEEE; 790185377Ssam 791187831Ssam chanIEEE = chan->ic_ieee; 792187831Ssam if (IEEE80211_IS_CHAN_2GHZ(chan)) { 793185377Ssam const CHAN_INFO_2GHZ* ci = 794185377Ssam &chan2GHzData[chanIEEE + CI_2GHZ_INDEX_CORRECTION]; 795185377Ssam 796185377Ssam data2111 = ((ath_hal_reverseBits(ci->channelSelect, 8) & 0xff) 797185377Ssam << 5) 798185377Ssam | (ci->refClkSel << 4); 799185377Ssam chan5111 = ci->channel5111; 800185377Ssam } else { 801185377Ssam data2111 = 0; 802185377Ssam chan5111 = chanIEEE; 803185377Ssam } 804185377Ssam 805185377Ssam /* Rest of the code is common for 5 GHz and 2.4 GHz. */ 806185377Ssam if (chan5111 >= 145 || (chan5111 & 0x1)) { 807185377Ssam reg32 = ath_hal_reverseBits(chan5111 - 24, 8) & 0xFF; 808185377Ssam refClk = 1; 809185377Ssam } else { 810185377Ssam reg32 = ath_hal_reverseBits(((chan5111 - 24) / 2), 8) & 0xFF; 811185377Ssam refClk = 0; 812185377Ssam } 813185377Ssam 814185377Ssam reg32 = (reg32 << 2) | (refClk << 1) | (1 << 10) | 0x1; 815185377Ssam OS_REG_WRITE(ah, AR_PHY(0x27), ((data2111 & 0xff) << 8) | (reg32 & 0xff)); 816185377Ssam reg32 >>= 8; 817185377Ssam OS_REG_WRITE(ah, AR_PHY(0x34), (data2111 & 0xff00) | (reg32 & 0xff)); 818185377Ssam 819185377Ssam AH_PRIVATE(ah)->ah_curchan = chan; 820185377Ssam return AH_TRUE; 821185377Ssam} 822185377Ssam 823185377Ssamstatic int16_t 824185377Ssamar5211GetNoiseFloor(struct ath_hal *ah) 825185377Ssam{ 826185377Ssam int16_t nf; 827185377Ssam 828185377Ssam nf = (OS_REG_READ(ah, AR_PHY(25)) >> 19) & 0x1ff; 829185377Ssam if (nf & 0x100) 830185377Ssam nf = 0 - ((nf ^ 0x1ff) + 1); 831185377Ssam return nf; 832185377Ssam} 833185377Ssam 834185377Ssam/* 835185377Ssam * Peform the noisefloor calibration for the length of time set 836185377Ssam * in runTime (valid values 1 to 7) 837185377Ssam * 838185377Ssam * Returns: The NF value at the end of the given time (or 0 for failure) 839185377Ssam */ 840185377Ssamint16_t 841185377Ssamar5211RunNoiseFloor(struct ath_hal *ah, uint8_t runTime, int16_t startingNF) 842185377Ssam{ 843185377Ssam int i, searchTime; 844185377Ssam 845185377Ssam HALASSERT(runTime <= 7); 846185377Ssam 847185377Ssam /* Setup noise floor run time and starting value */ 848185377Ssam OS_REG_WRITE(ah, AR_PHY(25), 849185377Ssam (OS_REG_READ(ah, AR_PHY(25)) & ~0xFFF) | 850185377Ssam ((runTime << 9) & 0xE00) | (startingNF & 0x1FF)); 851185377Ssam /* Calibrate the noise floor */ 852185377Ssam OS_REG_WRITE(ah, AR_PHY_AGC_CONTROL, 853185377Ssam OS_REG_READ(ah, AR_PHY_AGC_CONTROL) | AR_PHY_AGC_CONTROL_NF); 854185377Ssam 855185377Ssam /* Compute the required amount of searchTime needed to finish NF */ 856185377Ssam if (runTime == 0) { 857185377Ssam /* 8 search windows * 6.4us each */ 858185377Ssam searchTime = 8 * 7; 859185377Ssam } else { 860185377Ssam /* 512 * runtime search windows * 6.4us each */ 861185377Ssam searchTime = (runTime * 512) * 7; 862185377Ssam } 863185377Ssam 864185377Ssam /* 865185377Ssam * Do not read noise floor until it has been updated 866185377Ssam * 867185377Ssam * As a guesstimate - we may only get 1/60th the time on 868185377Ssam * the air to see search windows in a heavily congested 869185377Ssam * network (40 us every 2400 us of time) 870185377Ssam */ 871185377Ssam for (i = 0; i < 60; i++) { 872185377Ssam if ((OS_REG_READ(ah, AR_PHY_AGC_CONTROL) & AR_PHY_AGC_CONTROL_NF) == 0) 873185377Ssam break; 874185377Ssam OS_DELAY(searchTime); 875185377Ssam } 876185377Ssam if (i >= 60) { 877185377Ssam HALDEBUG(ah, HAL_DEBUG_NFCAL, 878185377Ssam "NF with runTime %d failed to end on channel %d\n", 879187831Ssam runTime, AH_PRIVATE(ah)->ah_curchan->ic_freq); 880185377Ssam HALDEBUG(ah, HAL_DEBUG_NFCAL, 881185377Ssam " PHY NF Reg state: 0x%x\n", 882185377Ssam OS_REG_READ(ah, AR_PHY_AGC_CONTROL)); 883185377Ssam HALDEBUG(ah, HAL_DEBUG_NFCAL, 884185377Ssam " PHY Active Reg state: 0x%x\n", 885185377Ssam OS_REG_READ(ah, AR_PHY_ACTIVE)); 886185377Ssam return 0; 887185377Ssam } 888185377Ssam 889185377Ssam return ar5211GetNoiseFloor(ah); 890185377Ssam} 891185377Ssam 892185377Ssamstatic HAL_BOOL 893187831SsamgetNoiseFloorThresh(struct ath_hal *ah, const struct ieee80211_channel *chan, 894187831Ssam int16_t *nft) 895185377Ssam{ 896185377Ssam HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom; 897185377Ssam 898187831Ssam switch (chan->ic_flags & IEEE80211_CHAN_ALLFULL) { 899187831Ssam case IEEE80211_CHAN_A: 900185377Ssam *nft = ee->ee_noiseFloorThresh[0]; 901185377Ssam break; 902187831Ssam case IEEE80211_CHAN_B: 903185377Ssam *nft = ee->ee_noiseFloorThresh[1]; 904185377Ssam break; 905187831Ssam case IEEE80211_CHAN_PUREG: 906185377Ssam *nft = ee->ee_noiseFloorThresh[2]; 907185377Ssam break; 908185377Ssam default: 909185377Ssam HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid channel flags 0x%x\n", 910187831Ssam __func__, chan->ic_flags); 911185377Ssam return AH_FALSE; 912185377Ssam } 913185377Ssam return AH_TRUE; 914185377Ssam} 915185377Ssam 916185377Ssam/* 917185377Ssam * Read the NF and check it against the noise floor threshhold 918185377Ssam * 919185377Ssam * Returns: TRUE if the NF is good 920185377Ssam */ 921185377Ssamstatic HAL_BOOL 922187831Ssamar5211IsNfGood(struct ath_hal *ah, struct ieee80211_channel *chan) 923185377Ssam{ 924187831Ssam HAL_CHANNEL_INTERNAL *ichan = ath_hal_checkchannel(ah, chan); 925185377Ssam int16_t nf, nfThresh; 926185377Ssam 927185377Ssam if (!getNoiseFloorThresh(ah, chan, &nfThresh)) 928185377Ssam return AH_FALSE; 929208644Srpaulo if (OS_REG_READ(ah, AR_PHY_AGC_CONTROL) & AR_PHY_AGC_CONTROL_NF) { 930185377Ssam HALDEBUG(ah, HAL_DEBUG_ANY, 931185377Ssam "%s: NF did not complete in calibration window\n", __func__); 932208644Srpaulo } 933185377Ssam nf = ar5211GetNoiseFloor(ah); 934185377Ssam if (nf > nfThresh) { 935185377Ssam HALDEBUG(ah, HAL_DEBUG_ANY, 936185377Ssam "%s: noise floor failed; detected %u, threshold %u\n", 937185377Ssam __func__, nf, nfThresh); 938185377Ssam /* 939185377Ssam * NB: Don't discriminate 2.4 vs 5Ghz, if this 940185377Ssam * happens it indicates a problem regardless 941185377Ssam * of the band. 942185377Ssam */ 943187831Ssam chan->ic_state |= IEEE80211_CHANSTATE_CWINT; 944185377Ssam } 945187831Ssam ichan->rawNoiseFloor = nf; 946185377Ssam return (nf <= nfThresh); 947185377Ssam} 948185377Ssam 949185377Ssam/* 950185377Ssam * Peform the noisefloor calibration and check for any constant channel 951185377Ssam * interference. 952185377Ssam * 953185377Ssam * NOTE: preAR5211 have a lengthy carrier wave detection process - hence 954185377Ssam * it is if'ed for MKK regulatory domain only. 955185377Ssam * 956185377Ssam * Returns: TRUE for a successful noise floor calibration; else FALSE 957185377Ssam */ 958185377SsamHAL_BOOL 959187831Ssamar5211CalNoiseFloor(struct ath_hal *ah, const struct ieee80211_channel *chan) 960185377Ssam{ 961185377Ssam#define N(a) (sizeof (a) / sizeof (a[0])) 962185377Ssam /* Check for Carrier Wave interference in MKK regulatory zone */ 963185377Ssam if (AH_PRIVATE(ah)->ah_macVersion < AR_SREV_VERSION_OAHU && 964187831Ssam (chan->ic_flags & CHANNEL_NFCREQUIRED)) { 965185377Ssam static const uint8_t runtime[3] = { 0, 2, 7 }; 966187831Ssam HAL_CHANNEL_INTERNAL *ichan = ath_hal_checkchannel(ah, chan); 967185377Ssam int16_t nf, nfThresh; 968185377Ssam int i; 969185377Ssam 970185377Ssam if (!getNoiseFloorThresh(ah, chan, &nfThresh)) 971185377Ssam return AH_FALSE; 972185377Ssam /* 973185377Ssam * Run a quick noise floor that will hopefully 974185377Ssam * complete (decrease delay time). 975185377Ssam */ 976185377Ssam for (i = 0; i < N(runtime); i++) { 977185377Ssam nf = ar5211RunNoiseFloor(ah, runtime[i], 0); 978185377Ssam if (nf > nfThresh) { 979185377Ssam HALDEBUG(ah, HAL_DEBUG_ANY, 980185377Ssam "%s: run failed with %u > threshold %u " 981185377Ssam "(runtime %u)\n", __func__, 982185377Ssam nf, nfThresh, runtime[i]); 983187831Ssam ichan->rawNoiseFloor = 0; 984185377Ssam } else 985187831Ssam ichan->rawNoiseFloor = nf; 986185377Ssam } 987185377Ssam return (i <= N(runtime)); 988185377Ssam } else { 989185377Ssam /* Calibrate the noise floor */ 990185377Ssam OS_REG_WRITE(ah, AR_PHY_AGC_CONTROL, 991185377Ssam OS_REG_READ(ah, AR_PHY_AGC_CONTROL) | 992185377Ssam AR_PHY_AGC_CONTROL_NF); 993185377Ssam } 994185377Ssam return AH_TRUE; 995185377Ssam#undef N 996185377Ssam} 997185377Ssam 998185377Ssam/* 999185377Ssam * Adjust NF based on statistical values for 5GHz frequencies. 1000185377Ssam */ 1001185377Ssamint16_t 1002185377Ssamar5211GetNfAdjust(struct ath_hal *ah, const HAL_CHANNEL_INTERNAL *c) 1003185377Ssam{ 1004185377Ssam static const struct { 1005185377Ssam uint16_t freqLow; 1006185377Ssam int16_t adjust; 1007185377Ssam } adjust5111[] = { 1008185377Ssam { 5790, 11 }, /* NB: ordered high -> low */ 1009185377Ssam { 5730, 10 }, 1010185377Ssam { 5690, 9 }, 1011185377Ssam { 5660, 8 }, 1012185377Ssam { 5610, 7 }, 1013185377Ssam { 5530, 5 }, 1014185377Ssam { 5450, 4 }, 1015185377Ssam { 5379, 2 }, 1016185377Ssam { 5209, 0 }, /* XXX? bogus but doesn't matter */ 1017185377Ssam { 0, 1 }, 1018185377Ssam }; 1019185377Ssam int i; 1020185377Ssam 1021185377Ssam for (i = 0; c->channel <= adjust5111[i].freqLow; i++) 1022185377Ssam ; 1023185377Ssam /* NB: placeholder for 5111's less severe requirement */ 1024185377Ssam return adjust5111[i].adjust / 3; 1025185377Ssam} 1026185377Ssam 1027185377Ssam/* 1028185377Ssam * Reads EEPROM header info from device structure and programs 1029185377Ssam * analog registers 6 and 7 1030185377Ssam * 1031185377Ssam * REQUIRES: Access to the analog device 1032185377Ssam */ 1033185377Ssamstatic HAL_BOOL 1034187831Ssamar5211SetRf6and7(struct ath_hal *ah, const struct ieee80211_channel *chan) 1035185377Ssam{ 1036185377Ssam#define N(a) (sizeof (a) / sizeof (a[0])) 1037187831Ssam uint16_t freq = ath_hal_gethwchannel(ah, chan); 1038185377Ssam HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom; 1039185377Ssam struct ath_hal_5211 *ahp = AH5211(ah); 1040185377Ssam uint16_t rfXpdGain, rfPloSel, rfPwdXpd; 1041185377Ssam uint16_t tempOB, tempDB; 1042185377Ssam uint16_t freqIndex; 1043185377Ssam int i; 1044185377Ssam 1045187831Ssam freqIndex = IEEE80211_IS_CHAN_2GHZ(chan) ? 2 : 1; 1046185377Ssam 1047185377Ssam /* 1048185377Ssam * TODO: This array mode correspondes with the index used 1049185377Ssam * during the read. 1050185377Ssam * For readability, this should be changed to an enum or #define 1051185377Ssam */ 1052187831Ssam switch (chan->ic_flags & IEEE80211_CHAN_ALLFULL) { 1053187831Ssam case IEEE80211_CHAN_A: 1054187831Ssam if (freq > 4000 && freq < 5260) { 1055185377Ssam tempOB = ee->ee_ob1; 1056185377Ssam tempDB = ee->ee_db1; 1057187831Ssam } else if (freq >= 5260 && freq < 5500) { 1058185377Ssam tempOB = ee->ee_ob2; 1059185377Ssam tempDB = ee->ee_db2; 1060187831Ssam } else if (freq >= 5500 && freq < 5725) { 1061185377Ssam tempOB = ee->ee_ob3; 1062185377Ssam tempDB = ee->ee_db3; 1063187831Ssam } else if (freq >= 5725) { 1064185377Ssam tempOB = ee->ee_ob4; 1065185377Ssam tempDB = ee->ee_db4; 1066185377Ssam } else { 1067185377Ssam /* XXX panic?? */ 1068185377Ssam tempOB = tempDB = 0; 1069185377Ssam } 1070185377Ssam 1071185377Ssam rfXpdGain = ee->ee_xgain[0]; 1072185377Ssam rfPloSel = ee->ee_xpd[0]; 1073185377Ssam rfPwdXpd = !ee->ee_xpd[0]; 1074185377Ssam 1075185377Ssam ar5211Rf6n7[5][freqIndex] = 1076185377Ssam (ar5211Rf6n7[5][freqIndex] & ~0x10000000) | 1077185377Ssam (ee->ee_cornerCal.pd84<< 28); 1078185377Ssam ar5211Rf6n7[6][freqIndex] = 1079185377Ssam (ar5211Rf6n7[6][freqIndex] & ~0x04000000) | 1080185377Ssam (ee->ee_cornerCal.pd90 << 26); 1081185377Ssam ar5211Rf6n7[21][freqIndex] = 1082185377Ssam (ar5211Rf6n7[21][freqIndex] & ~0x08) | 1083185377Ssam (ee->ee_cornerCal.gSel << 3); 1084185377Ssam break; 1085187831Ssam case IEEE80211_CHAN_B: 1086185377Ssam tempOB = ee->ee_obFor24; 1087185377Ssam tempDB = ee->ee_dbFor24; 1088185377Ssam rfXpdGain = ee->ee_xgain[1]; 1089185377Ssam rfPloSel = ee->ee_xpd[1]; 1090185377Ssam rfPwdXpd = !ee->ee_xpd[1]; 1091185377Ssam break; 1092187831Ssam case IEEE80211_CHAN_PUREG: 1093185377Ssam tempOB = ee->ee_obFor24g; 1094185377Ssam tempDB = ee->ee_dbFor24g; 1095185377Ssam rfXpdGain = ee->ee_xgain[2]; 1096185377Ssam rfPloSel = ee->ee_xpd[2]; 1097185377Ssam rfPwdXpd = !ee->ee_xpd[2]; 1098185377Ssam break; 1099185377Ssam default: 1100185377Ssam HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid channel flags 0x%x\n", 1101187831Ssam __func__, chan->ic_flags); 1102185377Ssam return AH_FALSE; 1103185377Ssam } 1104185377Ssam 1105185377Ssam HALASSERT(1 <= tempOB && tempOB <= 5); 1106185377Ssam HALASSERT(1 <= tempDB && tempDB <= 5); 1107185377Ssam 1108185377Ssam /* Set rfXpdGain and rfPwdXpd */ 1109185377Ssam ar5211Rf6n7[11][freqIndex] = (ar5211Rf6n7[11][freqIndex] & ~0xC0) | 1110185377Ssam (((ath_hal_reverseBits(rfXpdGain, 4) << 7) | (rfPwdXpd << 6)) & 0xC0); 1111185377Ssam ar5211Rf6n7[12][freqIndex] = (ar5211Rf6n7[12][freqIndex] & ~0x07) | 1112185377Ssam ((ath_hal_reverseBits(rfXpdGain, 4) >> 1) & 0x07); 1113185377Ssam 1114185377Ssam /* Set OB */ 1115185377Ssam ar5211Rf6n7[12][freqIndex] = (ar5211Rf6n7[12][freqIndex] & ~0x80) | 1116185377Ssam ((ath_hal_reverseBits(tempOB, 3) << 7) & 0x80); 1117185377Ssam ar5211Rf6n7[13][freqIndex] = (ar5211Rf6n7[13][freqIndex] & ~0x03) | 1118185377Ssam ((ath_hal_reverseBits(tempOB, 3) >> 1) & 0x03); 1119185377Ssam 1120185377Ssam /* Set DB */ 1121185377Ssam ar5211Rf6n7[13][freqIndex] = (ar5211Rf6n7[13][freqIndex] & ~0x1C) | 1122185377Ssam ((ath_hal_reverseBits(tempDB, 3) << 2) & 0x1C); 1123185377Ssam 1124185377Ssam /* Set rfPloSel */ 1125185377Ssam ar5211Rf6n7[17][freqIndex] = (ar5211Rf6n7[17][freqIndex] & ~0x08) | 1126185377Ssam ((rfPloSel << 3) & 0x08); 1127185377Ssam 1128185377Ssam /* Write the Rf registers 6 & 7 */ 1129185377Ssam for (i = 0; i < N(ar5211Rf6n7); i++) 1130185377Ssam OS_REG_WRITE(ah, ar5211Rf6n7[i][0], ar5211Rf6n7[i][freqIndex]); 1131185377Ssam 1132185377Ssam /* Now that we have reprogrammed rfgain value, clear the flag. */ 1133185377Ssam ahp->ah_rfgainState = RFGAIN_INACTIVE; 1134185377Ssam 1135185377Ssam return AH_TRUE; 1136185377Ssam#undef N 1137185377Ssam} 1138185377Ssam 1139185377SsamHAL_BOOL 1140185377Ssamar5211SetAntennaSwitchInternal(struct ath_hal *ah, HAL_ANT_SETTING settings, 1141187831Ssam const struct ieee80211_channel *chan) 1142185377Ssam{ 1143185377Ssam#define ANT_SWITCH_TABLE1 0x9960 1144185377Ssam#define ANT_SWITCH_TABLE2 0x9964 1145185377Ssam HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom; 1146185377Ssam struct ath_hal_5211 *ahp = AH5211(ah); 1147185377Ssam uint32_t antSwitchA, antSwitchB; 1148185377Ssam int ix; 1149185377Ssam 1150187831Ssam switch (chan->ic_flags & IEEE80211_CHAN_ALLFULL) { 1151187831Ssam case IEEE80211_CHAN_A: ix = 0; break; 1152187831Ssam case IEEE80211_CHAN_B: ix = 1; break; 1153187831Ssam case IEEE80211_CHAN_PUREG: ix = 2; break; 1154185377Ssam default: 1155185377Ssam HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid channel flags 0x%x\n", 1156187831Ssam __func__, chan->ic_flags); 1157185377Ssam return AH_FALSE; 1158185377Ssam } 1159185377Ssam 1160185377Ssam antSwitchA = ee->ee_antennaControl[1][ix] 1161185377Ssam | (ee->ee_antennaControl[2][ix] << 6) 1162185377Ssam | (ee->ee_antennaControl[3][ix] << 12) 1163185377Ssam | (ee->ee_antennaControl[4][ix] << 18) 1164185377Ssam | (ee->ee_antennaControl[5][ix] << 24) 1165185377Ssam ; 1166185377Ssam antSwitchB = ee->ee_antennaControl[6][ix] 1167185377Ssam | (ee->ee_antennaControl[7][ix] << 6) 1168185377Ssam | (ee->ee_antennaControl[8][ix] << 12) 1169185377Ssam | (ee->ee_antennaControl[9][ix] << 18) 1170185377Ssam | (ee->ee_antennaControl[10][ix] << 24) 1171185377Ssam ; 1172185377Ssam /* 1173185377Ssam * For fixed antenna, give the same setting for both switch banks 1174185377Ssam */ 1175185377Ssam switch (settings) { 1176185377Ssam case HAL_ANT_FIXED_A: 1177185377Ssam antSwitchB = antSwitchA; 1178185377Ssam break; 1179185377Ssam case HAL_ANT_FIXED_B: 1180185377Ssam antSwitchA = antSwitchB; 1181185377Ssam break; 1182185377Ssam case HAL_ANT_VARIABLE: 1183185377Ssam break; 1184185377Ssam default: 1185185377Ssam HALDEBUG(ah, HAL_DEBUG_ANY, "%s: bad antenna setting %u\n", 1186185377Ssam __func__, settings); 1187185377Ssam return AH_FALSE; 1188185377Ssam } 1189185377Ssam ahp->ah_diversityControl = settings; 1190185377Ssam 1191185377Ssam OS_REG_WRITE(ah, ANT_SWITCH_TABLE1, antSwitchA); 1192185377Ssam OS_REG_WRITE(ah, ANT_SWITCH_TABLE2, antSwitchB); 1193185377Ssam 1194185377Ssam return AH_TRUE; 1195185377Ssam#undef ANT_SWITCH_TABLE1 1196185377Ssam#undef ANT_SWITCH_TABLE2 1197185377Ssam} 1198185377Ssam 1199185377Ssam/* 1200185377Ssam * Reads EEPROM header info and programs the device for correct operation 1201185377Ssam * given the channel value 1202185377Ssam */ 1203185377Ssamstatic HAL_BOOL 1204187831Ssamar5211SetBoardValues(struct ath_hal *ah, const struct ieee80211_channel *chan) 1205185377Ssam{ 1206185377Ssam HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom; 1207185377Ssam struct ath_hal_5211 *ahp = AH5211(ah); 1208185377Ssam int arrayMode, falseDectectBackoff; 1209185377Ssam 1210187831Ssam switch (chan->ic_flags & IEEE80211_CHAN_ALLFULL) { 1211187831Ssam case IEEE80211_CHAN_A: 1212185377Ssam arrayMode = 0; 1213185377Ssam OS_REG_RMW_FIELD(ah, AR_PHY_FRAME_CTL, 1214185377Ssam AR_PHY_FRAME_CTL_TX_CLIP, ee->ee_cornerCal.clip); 1215185377Ssam break; 1216187831Ssam case IEEE80211_CHAN_B: 1217185377Ssam arrayMode = 1; 1218185377Ssam break; 1219187831Ssam case IEEE80211_CHAN_PUREG: 1220185377Ssam arrayMode = 2; 1221185377Ssam break; 1222185377Ssam default: 1223185377Ssam HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid channel flags 0x%x\n", 1224187831Ssam __func__, chan->ic_flags); 1225185377Ssam return AH_FALSE; 1226185377Ssam } 1227185377Ssam 1228185377Ssam /* Set the antenna register(s) correctly for the chip revision */ 1229185377Ssam if (AH_PRIVATE(ah)->ah_macVersion < AR_SREV_VERSION_OAHU) { 1230185377Ssam OS_REG_WRITE(ah, AR_PHY(68), 1231185377Ssam (OS_REG_READ(ah, AR_PHY(68)) & 0xFFFFFFFC) | 0x3); 1232185377Ssam } else { 1233185377Ssam OS_REG_WRITE(ah, AR_PHY(68), 1234185377Ssam (OS_REG_READ(ah, AR_PHY(68)) & 0xFFFFFC06) | 1235185377Ssam (ee->ee_antennaControl[0][arrayMode] << 4) | 0x1); 1236185377Ssam 1237185377Ssam ar5211SetAntennaSwitchInternal(ah, 1238185377Ssam ahp->ah_diversityControl, chan); 1239185377Ssam 1240185377Ssam /* Set the Noise Floor Thresh on ar5211 devices */ 1241185377Ssam OS_REG_WRITE(ah, AR_PHY_BASE + (90 << 2), 1242185377Ssam (ee->ee_noiseFloorThresh[arrayMode] & 0x1FF) | (1<<9)); 1243185377Ssam } 1244185377Ssam OS_REG_WRITE(ah, AR_PHY_BASE + (17 << 2), 1245185377Ssam (OS_REG_READ(ah, AR_PHY_BASE + (17 << 2)) & 0xFFFFC07F) | 1246185377Ssam ((ee->ee_switchSettling[arrayMode] << 7) & 0x3F80)); 1247185377Ssam OS_REG_WRITE(ah, AR_PHY_BASE + (18 << 2), 1248185377Ssam (OS_REG_READ(ah, AR_PHY_BASE + (18 << 2)) & 0xFFFC0FFF) | 1249185377Ssam ((ee->ee_txrxAtten[arrayMode] << 12) & 0x3F000)); 1250185377Ssam OS_REG_WRITE(ah, AR_PHY_BASE + (20 << 2), 1251185377Ssam (OS_REG_READ(ah, AR_PHY_BASE + (20 << 2)) & 0xFFFF0000) | 1252185377Ssam ((ee->ee_pgaDesiredSize[arrayMode] << 8) & 0xFF00) | 1253185377Ssam (ee->ee_adcDesiredSize[arrayMode] & 0x00FF)); 1254185377Ssam OS_REG_WRITE(ah, AR_PHY_BASE + (13 << 2), 1255185377Ssam (ee->ee_txEndToXPAOff[arrayMode] << 24) | 1256185377Ssam (ee->ee_txEndToXPAOff[arrayMode] << 16) | 1257185377Ssam (ee->ee_txFrameToXPAOn[arrayMode] << 8) | 1258185377Ssam ee->ee_txFrameToXPAOn[arrayMode]); 1259185377Ssam OS_REG_WRITE(ah, AR_PHY_BASE + (10 << 2), 1260185377Ssam (OS_REG_READ(ah, AR_PHY_BASE + (10 << 2)) & 0xFFFF00FF) | 1261185377Ssam (ee->ee_txEndToXLNAOn[arrayMode] << 8)); 1262185377Ssam OS_REG_WRITE(ah, AR_PHY_BASE + (25 << 2), 1263185377Ssam (OS_REG_READ(ah, AR_PHY_BASE + (25 << 2)) & 0xFFF80FFF) | 1264185377Ssam ((ee->ee_thresh62[arrayMode] << 12) & 0x7F000)); 1265185377Ssam 1266185377Ssam#define NO_FALSE_DETECT_BACKOFF 2 1267185377Ssam#define CB22_FALSE_DETECT_BACKOFF 6 1268185377Ssam /* 1269185377Ssam * False detect backoff - suspected 32 MHz spur causes 1270185377Ssam * false detects in OFDM, causing Tx Hangs. Decrease 1271185377Ssam * weak signal sensitivity for this card. 1272185377Ssam */ 1273185377Ssam falseDectectBackoff = NO_FALSE_DETECT_BACKOFF; 1274185377Ssam if (AH_PRIVATE(ah)->ah_eeversion < AR_EEPROM_VER3_3) { 1275185377Ssam if (AH_PRIVATE(ah)->ah_subvendorid == 0x1022 && 1276187831Ssam IEEE80211_IS_CHAN_OFDM(chan)) 1277185377Ssam falseDectectBackoff += CB22_FALSE_DETECT_BACKOFF; 1278185377Ssam } else { 1279187831Ssam uint16_t freq = ath_hal_gethwchannel(ah, chan); 1280187831Ssam uint32_t remainder = freq % 32; 1281185377Ssam 1282185377Ssam if (remainder && (remainder < 10 || remainder > 22)) 1283185377Ssam falseDectectBackoff += ee->ee_falseDetectBackoff[arrayMode]; 1284185377Ssam } 1285185377Ssam OS_REG_WRITE(ah, 0x9924, 1286185377Ssam (OS_REG_READ(ah, 0x9924) & 0xFFFFFF01) 1287185377Ssam | ((falseDectectBackoff << 1) & 0xF7)); 1288185377Ssam 1289185377Ssam return AH_TRUE; 1290185377Ssam#undef NO_FALSE_DETECT_BACKOFF 1291185377Ssam#undef CB22_FALSE_DETECT_BACKOFF 1292185377Ssam} 1293185377Ssam 1294185377Ssam/* 1295185377Ssam * Set the limit on the overall output power. Used for dynamic 1296185377Ssam * transmit power control and the like. 1297185377Ssam * 1298185377Ssam * NOTE: The power is passed in is in units of 0.5 dBm. 1299185377Ssam */ 1300185377SsamHAL_BOOL 1301185377Ssamar5211SetTxPowerLimit(struct ath_hal *ah, uint32_t limit) 1302185377Ssam{ 1303185377Ssam 1304185377Ssam AH_PRIVATE(ah)->ah_powerLimit = AH_MIN(limit, MAX_RATE_POWER); 1305185377Ssam OS_REG_WRITE(ah, AR_PHY_POWER_TX_RATE_MAX, limit); 1306185377Ssam return AH_TRUE; 1307185377Ssam} 1308185377Ssam 1309185377Ssam/* 1310185377Ssam * Sets the transmit power in the baseband for the given 1311185377Ssam * operating channel and mode. 1312185377Ssam */ 1313187831Ssamstatic HAL_BOOL 1314187831Ssamar5211SetTransmitPower(struct ath_hal *ah, const struct ieee80211_channel *chan) 1315185377Ssam{ 1316187831Ssam uint16_t freq = ath_hal_gethwchannel(ah, chan); 1317185377Ssam HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom; 1318185377Ssam TRGT_POWER_INFO *pi; 1319185377Ssam RD_EDGES_POWER *rep; 1320185377Ssam PCDACS_EEPROM eepromPcdacs; 1321185377Ssam u_int nchan, cfgCtl; 1322185377Ssam int i; 1323185377Ssam 1324185377Ssam /* setup the pcdac struct to point to the correct info, based on mode */ 1325187831Ssam switch (chan->ic_flags & IEEE80211_CHAN_ALLFULL) { 1326187831Ssam case IEEE80211_CHAN_A: 1327185377Ssam eepromPcdacs.numChannels = ee->ee_numChannels11a; 1328185377Ssam eepromPcdacs.pChannelList= ee->ee_channels11a; 1329185377Ssam eepromPcdacs.pDataPerChannel = ee->ee_dataPerChannel11a; 1330185377Ssam nchan = ee->ee_numTargetPwr_11a; 1331185377Ssam pi = ee->ee_trgtPwr_11a; 1332185377Ssam break; 1333187831Ssam case IEEE80211_CHAN_PUREG: 1334185377Ssam eepromPcdacs.numChannels = ee->ee_numChannels2_4; 1335185377Ssam eepromPcdacs.pChannelList= ee->ee_channels11g; 1336185377Ssam eepromPcdacs.pDataPerChannel = ee->ee_dataPerChannel11g; 1337185377Ssam nchan = ee->ee_numTargetPwr_11g; 1338185377Ssam pi = ee->ee_trgtPwr_11g; 1339185377Ssam break; 1340187831Ssam case IEEE80211_CHAN_B: 1341185377Ssam eepromPcdacs.numChannels = ee->ee_numChannels2_4; 1342185377Ssam eepromPcdacs.pChannelList= ee->ee_channels11b; 1343185377Ssam eepromPcdacs.pDataPerChannel = ee->ee_dataPerChannel11b; 1344185377Ssam nchan = ee->ee_numTargetPwr_11b; 1345185377Ssam pi = ee->ee_trgtPwr_11b; 1346185377Ssam break; 1347185377Ssam default: 1348185377Ssam HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid channel flags 0x%x\n", 1349187831Ssam __func__, chan->ic_flags); 1350185377Ssam return AH_FALSE; 1351185377Ssam } 1352185377Ssam 1353187831Ssam ar5211SetPowerTable(ah, &eepromPcdacs, freq); 1354185377Ssam 1355185377Ssam rep = AH_NULL; 1356185377Ssam /* Match CTL to EEPROM value */ 1357185377Ssam cfgCtl = ath_hal_getctl(ah, chan); 1358185377Ssam for (i = 0; i < ee->ee_numCtls; i++) 1359185377Ssam if (ee->ee_ctl[i] != 0 && ee->ee_ctl[i] == cfgCtl) { 1360185377Ssam rep = &ee->ee_rdEdgesPower[i * NUM_EDGES]; 1361185377Ssam break; 1362185377Ssam } 1363185377Ssam ar5211SetRateTable(ah, rep, pi, nchan, chan); 1364185377Ssam 1365185377Ssam return AH_TRUE; 1366185377Ssam} 1367185377Ssam 1368185377Ssam/* 1369185377Ssam * Read the transmit power levels from the structures taken 1370185377Ssam * from EEPROM. Interpolate read transmit power values for 1371185377Ssam * this channel. Organize the transmit power values into a 1372185377Ssam * table for writing into the hardware. 1373185377Ssam */ 1374185377Ssamvoid 1375187831Ssamar5211SetPowerTable(struct ath_hal *ah, PCDACS_EEPROM *pSrcStruct, 1376187831Ssam uint16_t channel) 1377185377Ssam{ 1378185377Ssam static FULL_PCDAC_STRUCT pcdacStruct; 1379185377Ssam static uint16_t pcdacTable[PWR_TABLE_SIZE]; 1380185377Ssam 1381185377Ssam uint16_t i, j; 1382185377Ssam uint16_t *pPcdacValues; 1383185377Ssam int16_t *pScaledUpDbm; 1384185377Ssam int16_t minScaledPwr; 1385185377Ssam int16_t maxScaledPwr; 1386185377Ssam int16_t pwr; 1387185377Ssam uint16_t pcdacMin = 0; 1388185377Ssam uint16_t pcdacMax = 63; 1389185377Ssam uint16_t pcdacTableIndex; 1390185377Ssam uint16_t scaledPcdac; 1391185377Ssam uint32_t addr; 1392185377Ssam uint32_t temp32; 1393185377Ssam 1394185377Ssam OS_MEMZERO(&pcdacStruct, sizeof(FULL_PCDAC_STRUCT)); 1395185377Ssam OS_MEMZERO(pcdacTable, sizeof(uint16_t) * PWR_TABLE_SIZE); 1396185377Ssam pPcdacValues = pcdacStruct.PcdacValues; 1397185377Ssam pScaledUpDbm = pcdacStruct.PwrValues; 1398185377Ssam 1399185377Ssam /* Initialize the pcdacs to dBM structs pcdacs to be 1 to 63 */ 1400185377Ssam for (i = PCDAC_START, j = 0; i <= PCDAC_STOP; i+= PCDAC_STEP, j++) 1401185377Ssam pPcdacValues[j] = i; 1402185377Ssam 1403185377Ssam pcdacStruct.numPcdacValues = j; 1404185377Ssam pcdacStruct.pcdacMin = PCDAC_START; 1405185377Ssam pcdacStruct.pcdacMax = PCDAC_STOP; 1406185377Ssam 1407185377Ssam /* Fill out the power values for this channel */ 1408185377Ssam for (j = 0; j < pcdacStruct.numPcdacValues; j++ ) 1409185377Ssam pScaledUpDbm[j] = ar5211GetScaledPower(channel, pPcdacValues[j], pSrcStruct); 1410185377Ssam 1411185377Ssam /* Now scale the pcdac values to fit in the 64 entry power table */ 1412185377Ssam minScaledPwr = pScaledUpDbm[0]; 1413185377Ssam maxScaledPwr = pScaledUpDbm[pcdacStruct.numPcdacValues - 1]; 1414185377Ssam 1415185377Ssam /* find minimum and make monotonic */ 1416185377Ssam for (j = 0; j < pcdacStruct.numPcdacValues; j++) { 1417185377Ssam if (minScaledPwr >= pScaledUpDbm[j]) { 1418185377Ssam minScaledPwr = pScaledUpDbm[j]; 1419185377Ssam pcdacMin = j; 1420185377Ssam } 1421185377Ssam /* 1422185377Ssam * Make the full_hsh monotonically increasing otherwise 1423185377Ssam * interpolation algorithm will get fooled gotta start 1424185377Ssam * working from the top, hence i = 63 - j. 1425185377Ssam */ 1426185377Ssam i = (uint16_t)(pcdacStruct.numPcdacValues - 1 - j); 1427185377Ssam if (i == 0) 1428185377Ssam break; 1429185377Ssam if (pScaledUpDbm[i-1] > pScaledUpDbm[i]) { 1430185377Ssam /* 1431185377Ssam * It could be a glitch, so make the power for 1432185377Ssam * this pcdac the same as the power from the 1433185377Ssam * next highest pcdac. 1434185377Ssam */ 1435185377Ssam pScaledUpDbm[i - 1] = pScaledUpDbm[i]; 1436185377Ssam } 1437185377Ssam } 1438185377Ssam 1439185377Ssam for (j = 0; j < pcdacStruct.numPcdacValues; j++) 1440185377Ssam if (maxScaledPwr < pScaledUpDbm[j]) { 1441185377Ssam maxScaledPwr = pScaledUpDbm[j]; 1442185377Ssam pcdacMax = j; 1443185377Ssam } 1444185377Ssam 1445185377Ssam /* Find the first power level with a pcdac */ 1446185377Ssam pwr = (uint16_t)(PWR_STEP * ((minScaledPwr - PWR_MIN + PWR_STEP / 2) / PWR_STEP) + PWR_MIN); 1447185377Ssam 1448185377Ssam /* Write all the first pcdac entries based off the pcdacMin */ 1449185377Ssam pcdacTableIndex = 0; 1450185377Ssam for (i = 0; i < (2 * (pwr - PWR_MIN) / EEP_SCALE + 1); i++) 1451185377Ssam pcdacTable[pcdacTableIndex++] = pcdacMin; 1452185377Ssam 1453185377Ssam i = 0; 1454185377Ssam while (pwr < pScaledUpDbm[pcdacStruct.numPcdacValues - 1]) { 1455185377Ssam pwr += PWR_STEP; 1456185377Ssam /* stop if dbM > max_power_possible */ 1457185377Ssam while (pwr < pScaledUpDbm[pcdacStruct.numPcdacValues - 1] && 1458185377Ssam (pwr - pScaledUpDbm[i])*(pwr - pScaledUpDbm[i+1]) > 0) 1459185377Ssam i++; 1460185377Ssam /* scale by 2 and add 1 to enable round up or down as needed */ 1461185377Ssam scaledPcdac = (uint16_t)(ar5211GetInterpolatedValue(pwr, 1462185377Ssam pScaledUpDbm[i], pScaledUpDbm[i+1], 1463185377Ssam (uint16_t)(pPcdacValues[i] * 2), 1464185377Ssam (uint16_t)(pPcdacValues[i+1] * 2), 0) + 1); 1465185377Ssam 1466185377Ssam pcdacTable[pcdacTableIndex] = scaledPcdac / 2; 1467185377Ssam if (pcdacTable[pcdacTableIndex] > pcdacMax) 1468185377Ssam pcdacTable[pcdacTableIndex] = pcdacMax; 1469185377Ssam pcdacTableIndex++; 1470185377Ssam } 1471185377Ssam 1472185377Ssam /* Write all the last pcdac entries based off the last valid pcdac */ 1473185377Ssam while (pcdacTableIndex < PWR_TABLE_SIZE) { 1474185377Ssam pcdacTable[pcdacTableIndex] = pcdacTable[pcdacTableIndex - 1]; 1475185377Ssam pcdacTableIndex++; 1476185377Ssam } 1477185377Ssam 1478185377Ssam /* Finally, write the power values into the baseband power table */ 1479185377Ssam addr = AR_PHY_BASE + (608 << 2); 1480185377Ssam for (i = 0; i < 32; i++) { 1481185377Ssam temp32 = 0xffff & ((pcdacTable[2 * i + 1] << 8) | 0xff); 1482185377Ssam temp32 = (temp32 << 16) | (0xffff & ((pcdacTable[2 * i] << 8) | 0xff)); 1483185377Ssam OS_REG_WRITE(ah, addr, temp32); 1484185377Ssam addr += 4; 1485185377Ssam } 1486185377Ssam 1487185377Ssam} 1488185377Ssam 1489185377Ssam/* 1490185377Ssam * Set the transmit power in the baseband for the given 1491185377Ssam * operating channel and mode. 1492185377Ssam */ 1493187831Ssamstatic void 1494185377Ssamar5211SetRateTable(struct ath_hal *ah, RD_EDGES_POWER *pRdEdgesPower, 1495185377Ssam TRGT_POWER_INFO *pPowerInfo, uint16_t numChannels, 1496187831Ssam const struct ieee80211_channel *chan) 1497185377Ssam{ 1498187831Ssam uint16_t freq = ath_hal_gethwchannel(ah, chan); 1499185377Ssam HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom; 1500185377Ssam struct ath_hal_5211 *ahp = AH5211(ah); 1501185377Ssam static uint16_t ratesArray[NUM_RATES]; 1502185377Ssam static const uint16_t tpcScaleReductionTable[5] = 1503185377Ssam { 0, 3, 6, 9, MAX_RATE_POWER }; 1504185377Ssam 1505185377Ssam uint16_t *pRatesPower; 1506185377Ssam uint16_t lowerChannel, lowerIndex=0, lowerPower=0; 1507185377Ssam uint16_t upperChannel, upperIndex=0, upperPower=0; 1508185377Ssam uint16_t twiceMaxEdgePower=63; 1509185377Ssam uint16_t twicePower = 0; 1510185377Ssam uint16_t i, numEdges; 1511185377Ssam uint16_t tempChannelList[NUM_EDGES]; /* temp array for holding edge channels */ 1512185377Ssam uint16_t twiceMaxRDPower; 1513185377Ssam int16_t scaledPower = 0; /* for gcc -O2 */ 1514185377Ssam uint16_t mask = 0x3f; 1515185377Ssam HAL_BOOL paPreDEnable = 0; 1516185377Ssam int8_t twiceAntennaGain, twiceAntennaReduction = 0; 1517185377Ssam 1518185377Ssam pRatesPower = ratesArray; 1519187831Ssam twiceMaxRDPower = chan->ic_maxregpower * 2; 1520185377Ssam 1521187831Ssam if (IEEE80211_IS_CHAN_5GHZ(chan)) { 1522185377Ssam twiceAntennaGain = ee->ee_antennaGainMax[0]; 1523185377Ssam } else { 1524185377Ssam twiceAntennaGain = ee->ee_antennaGainMax[1]; 1525185377Ssam } 1526185377Ssam 1527185377Ssam twiceAntennaReduction = ath_hal_getantennareduction(ah, chan, twiceAntennaGain); 1528185377Ssam 1529185377Ssam if (pRdEdgesPower) { 1530185377Ssam /* Get the edge power */ 1531185377Ssam for (i = 0; i < NUM_EDGES; i++) { 1532185377Ssam if (pRdEdgesPower[i].rdEdge == 0) 1533185377Ssam break; 1534185377Ssam tempChannelList[i] = pRdEdgesPower[i].rdEdge; 1535185377Ssam } 1536185377Ssam numEdges = i; 1537185377Ssam 1538187831Ssam ar5211GetLowerUpperValues(freq, tempChannelList, 1539185377Ssam numEdges, &lowerChannel, &upperChannel); 1540185377Ssam /* Get the index for this channel */ 1541185377Ssam for (i = 0; i < numEdges; i++) 1542185377Ssam if (lowerChannel == tempChannelList[i]) 1543185377Ssam break; 1544185377Ssam HALASSERT(i != numEdges); 1545185377Ssam 1546185377Ssam if ((lowerChannel == upperChannel && 1547187831Ssam lowerChannel == freq) || 1548185377Ssam pRdEdgesPower[i].flag) { 1549185377Ssam twiceMaxEdgePower = pRdEdgesPower[i].twice_rdEdgePower; 1550185377Ssam HALASSERT(twiceMaxEdgePower > 0); 1551185377Ssam } 1552185377Ssam } 1553185377Ssam 1554185377Ssam /* extrapolate the power values for the test Groups */ 1555185377Ssam for (i = 0; i < numChannels; i++) 1556185377Ssam tempChannelList[i] = pPowerInfo[i].testChannel; 1557185377Ssam 1558187831Ssam ar5211GetLowerUpperValues(freq, tempChannelList, 1559185377Ssam numChannels, &lowerChannel, &upperChannel); 1560185377Ssam 1561185377Ssam /* get the index for the channel */ 1562185377Ssam for (i = 0; i < numChannels; i++) { 1563185377Ssam if (lowerChannel == tempChannelList[i]) 1564185377Ssam lowerIndex = i; 1565185377Ssam if (upperChannel == tempChannelList[i]) { 1566185377Ssam upperIndex = i; 1567185377Ssam break; 1568185377Ssam } 1569185377Ssam } 1570185377Ssam 1571185377Ssam for (i = 0; i < NUM_RATES; i++) { 1572187831Ssam if (IEEE80211_IS_CHAN_OFDM(chan)) { 1573185377Ssam /* power for rates 6,9,12,18,24 is all the same */ 1574185377Ssam if (i < 5) { 1575185377Ssam lowerPower = pPowerInfo[lowerIndex].twicePwr6_24; 1576185377Ssam upperPower = pPowerInfo[upperIndex].twicePwr6_24; 1577185377Ssam } else if (i == 5) { 1578185377Ssam lowerPower = pPowerInfo[lowerIndex].twicePwr36; 1579185377Ssam upperPower = pPowerInfo[upperIndex].twicePwr36; 1580185377Ssam } else if (i == 6) { 1581185377Ssam lowerPower = pPowerInfo[lowerIndex].twicePwr48; 1582185377Ssam upperPower = pPowerInfo[upperIndex].twicePwr48; 1583185377Ssam } else if (i == 7) { 1584185377Ssam lowerPower = pPowerInfo[lowerIndex].twicePwr54; 1585185377Ssam upperPower = pPowerInfo[upperIndex].twicePwr54; 1586185377Ssam } 1587185377Ssam } else { 1588185377Ssam switch (i) { 1589185377Ssam case 0: 1590185377Ssam case 1: 1591185377Ssam lowerPower = pPowerInfo[lowerIndex].twicePwr6_24; 1592185377Ssam upperPower = pPowerInfo[upperIndex].twicePwr6_24; 1593185377Ssam break; 1594185377Ssam case 2: 1595185377Ssam case 3: 1596185377Ssam lowerPower = pPowerInfo[lowerIndex].twicePwr36; 1597185377Ssam upperPower = pPowerInfo[upperIndex].twicePwr36; 1598185377Ssam break; 1599185377Ssam case 4: 1600185377Ssam case 5: 1601185377Ssam lowerPower = pPowerInfo[lowerIndex].twicePwr48; 1602185377Ssam upperPower = pPowerInfo[upperIndex].twicePwr48; 1603185377Ssam break; 1604185377Ssam case 6: 1605185377Ssam case 7: 1606185377Ssam lowerPower = pPowerInfo[lowerIndex].twicePwr54; 1607185377Ssam upperPower = pPowerInfo[upperIndex].twicePwr54; 1608185377Ssam break; 1609185377Ssam } 1610185377Ssam } 1611185377Ssam 1612187831Ssam twicePower = ar5211GetInterpolatedValue(freq, 1613185377Ssam lowerChannel, upperChannel, lowerPower, upperPower, 0); 1614185377Ssam 1615185377Ssam /* Reduce power by band edge restrictions */ 1616185377Ssam twicePower = AH_MIN(twicePower, twiceMaxEdgePower); 1617185377Ssam 1618185377Ssam /* 1619185377Ssam * If turbo is set, reduce power to keep power 1620185377Ssam * consumption under 2 Watts. Note that we always do 1621185377Ssam * this unless specially configured. Then we limit 1622185377Ssam * power only for non-AP operation. 1623185377Ssam */ 1624187831Ssam if (IEEE80211_IS_CHAN_TURBO(chan) && 1625185377Ssam AH_PRIVATE(ah)->ah_eeversion >= AR_EEPROM_VER3_1 1626185377Ssam#ifdef AH_ENABLE_AP_SUPPORT 1627185377Ssam && AH_PRIVATE(ah)->ah_opmode != HAL_M_HOSTAP 1628185377Ssam#endif 1629185377Ssam ) { 1630185377Ssam twicePower = AH_MIN(twicePower, ee->ee_turbo2WMaxPower5); 1631185377Ssam } 1632185377Ssam 1633185377Ssam /* Reduce power by max regulatory domain allowed restrictions */ 1634185377Ssam pRatesPower[i] = AH_MIN(twicePower, twiceMaxRDPower - twiceAntennaReduction); 1635185377Ssam 1636185377Ssam /* Use 6 Mb power level for transmit power scaling reduction */ 1637185377Ssam /* We don't want to reduce higher rates if its not needed */ 1638185377Ssam if (i == 0) { 1639185377Ssam scaledPower = pRatesPower[0] - 1640185377Ssam (tpcScaleReductionTable[AH_PRIVATE(ah)->ah_tpScale] * 2); 1641185377Ssam if (scaledPower < 1) 1642185377Ssam scaledPower = 1; 1643185377Ssam } 1644185377Ssam 1645185377Ssam pRatesPower[i] = AH_MIN(pRatesPower[i], scaledPower); 1646185377Ssam } 1647185377Ssam 1648185377Ssam /* Record txPower at Rate 6 for info gathering */ 1649185377Ssam ahp->ah_tx6PowerInHalfDbm = pRatesPower[0]; 1650185377Ssam 1651185377Ssam#ifdef AH_DEBUG 1652185377Ssam HALDEBUG(ah, HAL_DEBUG_RESET, 1653185377Ssam "%s: final output power setting %d MHz:\n", 1654187831Ssam __func__, chan->ic_freq); 1655185377Ssam HALDEBUG(ah, HAL_DEBUG_RESET, 1656185377Ssam "6 Mb %d dBm, MaxRD: %d dBm, MaxEdge %d dBm\n", 1657185377Ssam scaledPower / 2, twiceMaxRDPower / 2, twiceMaxEdgePower / 2); 1658185377Ssam HALDEBUG(ah, HAL_DEBUG_RESET, "TPC Scale %d dBm - Ant Red %d dBm\n", 1659185377Ssam tpcScaleReductionTable[AH_PRIVATE(ah)->ah_tpScale] * 2, 1660185377Ssam twiceAntennaReduction / 2); 1661187831Ssam if (IEEE80211_IS_CHAN_TURBO(chan) && 1662185377Ssam AH_PRIVATE(ah)->ah_eeversion >= AR_EEPROM_VER3_1) 1663185377Ssam HALDEBUG(ah, HAL_DEBUG_RESET, "Max Turbo %d dBm\n", 1664185377Ssam ee->ee_turbo2WMaxPower5); 1665185377Ssam HALDEBUG(ah, HAL_DEBUG_RESET, 1666185377Ssam " %2d | %2d | %2d | %2d | %2d | %2d | %2d | %2d dBm\n", 1667185377Ssam pRatesPower[0] / 2, pRatesPower[1] / 2, pRatesPower[2] / 2, 1668185377Ssam pRatesPower[3] / 2, pRatesPower[4] / 2, pRatesPower[5] / 2, 1669185377Ssam pRatesPower[6] / 2, pRatesPower[7] / 2); 1670185377Ssam#endif /* AH_DEBUG */ 1671185377Ssam 1672185377Ssam /* Write the power table into the hardware */ 1673185377Ssam OS_REG_WRITE(ah, AR_PHY_POWER_TX_RATE1, 1674185377Ssam ((paPreDEnable & 1)<< 30) | ((pRatesPower[3] & mask) << 24) | 1675185377Ssam ((paPreDEnable & 1)<< 22) | ((pRatesPower[2] & mask) << 16) | 1676185377Ssam ((paPreDEnable & 1)<< 14) | ((pRatesPower[1] & mask) << 8) | 1677185377Ssam ((paPreDEnable & 1)<< 6 ) | (pRatesPower[0] & mask)); 1678185377Ssam OS_REG_WRITE(ah, AR_PHY_POWER_TX_RATE2, 1679185377Ssam ((paPreDEnable & 1)<< 30) | ((pRatesPower[7] & mask) << 24) | 1680185377Ssam ((paPreDEnable & 1)<< 22) | ((pRatesPower[6] & mask) << 16) | 1681185377Ssam ((paPreDEnable & 1)<< 14) | ((pRatesPower[5] & mask) << 8) | 1682185377Ssam ((paPreDEnable & 1)<< 6 ) | (pRatesPower[4] & mask)); 1683185377Ssam 1684185377Ssam /* set max power to the power value at rate 6 */ 1685185377Ssam ar5211SetTxPowerLimit(ah, pRatesPower[0]); 1686185377Ssam 1687185377Ssam AH_PRIVATE(ah)->ah_maxPowerLevel = pRatesPower[0]; 1688185377Ssam} 1689185377Ssam 1690185377Ssam/* 1691185377Ssam * Get or interpolate the pcdac value from the calibrated data 1692185377Ssam */ 1693185377Ssamuint16_t 1694187831Ssamar5211GetScaledPower(uint16_t channel, uint16_t pcdacValue, 1695187831Ssam const PCDACS_EEPROM *pSrcStruct) 1696185377Ssam{ 1697185377Ssam uint16_t powerValue; 1698185377Ssam uint16_t lFreq, rFreq; /* left and right frequency values */ 1699185377Ssam uint16_t llPcdac, ulPcdac; /* lower and upper left pcdac values */ 1700185377Ssam uint16_t lrPcdac, urPcdac; /* lower and upper right pcdac values */ 1701185377Ssam uint16_t lPwr, uPwr; /* lower and upper temp pwr values */ 1702185377Ssam uint16_t lScaledPwr, rScaledPwr; /* left and right scaled power */ 1703185377Ssam 1704185377Ssam if (ar5211FindValueInList(channel, pcdacValue, pSrcStruct, &powerValue)) 1705185377Ssam /* value was copied from srcStruct */ 1706185377Ssam return powerValue; 1707185377Ssam 1708185377Ssam ar5211GetLowerUpperValues(channel, pSrcStruct->pChannelList, 1709185377Ssam pSrcStruct->numChannels, &lFreq, &rFreq); 1710185377Ssam ar5211GetLowerUpperPcdacs(pcdacValue, lFreq, pSrcStruct, 1711185377Ssam &llPcdac, &ulPcdac); 1712185377Ssam ar5211GetLowerUpperPcdacs(pcdacValue, rFreq, pSrcStruct, 1713185377Ssam &lrPcdac, &urPcdac); 1714185377Ssam 1715185377Ssam /* get the power index for the pcdac value */ 1716185377Ssam ar5211FindValueInList(lFreq, llPcdac, pSrcStruct, &lPwr); 1717185377Ssam ar5211FindValueInList(lFreq, ulPcdac, pSrcStruct, &uPwr); 1718185377Ssam lScaledPwr = ar5211GetInterpolatedValue(pcdacValue, 1719185377Ssam llPcdac, ulPcdac, lPwr, uPwr, 0); 1720185377Ssam 1721185377Ssam ar5211FindValueInList(rFreq, lrPcdac, pSrcStruct, &lPwr); 1722185377Ssam ar5211FindValueInList(rFreq, urPcdac, pSrcStruct, &uPwr); 1723185377Ssam rScaledPwr = ar5211GetInterpolatedValue(pcdacValue, 1724185377Ssam lrPcdac, urPcdac, lPwr, uPwr, 0); 1725185377Ssam 1726185377Ssam return ar5211GetInterpolatedValue(channel, lFreq, rFreq, 1727185377Ssam lScaledPwr, rScaledPwr, 0); 1728185377Ssam} 1729185377Ssam 1730185377Ssam/* 1731185377Ssam * Find the value from the calibrated source data struct 1732185377Ssam */ 1733185377SsamHAL_BOOL 1734185377Ssamar5211FindValueInList(uint16_t channel, uint16_t pcdacValue, 1735185377Ssam const PCDACS_EEPROM *pSrcStruct, uint16_t *powerValue) 1736185377Ssam{ 1737185377Ssam const DATA_PER_CHANNEL *pChannelData; 1738185377Ssam const uint16_t *pPcdac; 1739185377Ssam uint16_t i, j; 1740185377Ssam 1741185377Ssam pChannelData = pSrcStruct->pDataPerChannel; 1742185377Ssam for (i = 0; i < pSrcStruct->numChannels; i++ ) { 1743185377Ssam if (pChannelData->channelValue == channel) { 1744185377Ssam pPcdac = pChannelData->PcdacValues; 1745185377Ssam for (j = 0; j < pChannelData->numPcdacValues; j++ ) { 1746185377Ssam if (*pPcdac == pcdacValue) { 1747185377Ssam *powerValue = pChannelData->PwrValues[j]; 1748185377Ssam return AH_TRUE; 1749185377Ssam } 1750185377Ssam pPcdac++; 1751185377Ssam } 1752185377Ssam } 1753185377Ssam pChannelData++; 1754185377Ssam } 1755185377Ssam return AH_FALSE; 1756185377Ssam} 1757185377Ssam 1758185377Ssam/* 1759185377Ssam * Returns interpolated or the scaled up interpolated value 1760185377Ssam */ 1761185377Ssamuint16_t 1762185377Ssamar5211GetInterpolatedValue(uint16_t target, 1763185377Ssam uint16_t srcLeft, uint16_t srcRight, 1764185377Ssam uint16_t targetLeft, uint16_t targetRight, 1765185377Ssam HAL_BOOL scaleUp) 1766185377Ssam{ 1767185377Ssam uint16_t rv; 1768185377Ssam int16_t lRatio; 1769185377Ssam uint16_t scaleValue = EEP_SCALE; 1770185377Ssam 1771185377Ssam /* to get an accurate ratio, always scale, if want to scale, then don't scale back down */ 1772185377Ssam if ((targetLeft * targetRight) == 0) 1773185377Ssam return 0; 1774185377Ssam if (scaleUp) 1775185377Ssam scaleValue = 1; 1776185377Ssam 1777185377Ssam if (srcRight != srcLeft) { 1778185377Ssam /* 1779185377Ssam * Note the ratio always need to be scaled, 1780185377Ssam * since it will be a fraction. 1781185377Ssam */ 1782185377Ssam lRatio = (target - srcLeft) * EEP_SCALE / (srcRight - srcLeft); 1783185377Ssam if (lRatio < 0) { 1784185377Ssam /* Return as Left target if value would be negative */ 1785185377Ssam rv = targetLeft * (scaleUp ? EEP_SCALE : 1); 1786185377Ssam } else if (lRatio > EEP_SCALE) { 1787185377Ssam /* Return as Right target if Ratio is greater than 100% (SCALE) */ 1788185377Ssam rv = targetRight * (scaleUp ? EEP_SCALE : 1); 1789185377Ssam } else { 1790185377Ssam rv = (lRatio * targetRight + (EEP_SCALE - lRatio) * 1791185377Ssam targetLeft) / scaleValue; 1792185377Ssam } 1793185377Ssam } else { 1794185377Ssam rv = targetLeft; 1795185377Ssam if (scaleUp) 1796185377Ssam rv *= EEP_SCALE; 1797185377Ssam } 1798185377Ssam return rv; 1799185377Ssam} 1800185377Ssam 1801185377Ssam/* 1802185377Ssam * Look for value being within 0.1 of the search values 1803185377Ssam * however, NDIS can't do float calculations, so multiply everything 1804185377Ssam * up by EEP_SCALE so can do integer arithmatic 1805185377Ssam * 1806185377Ssam * INPUT value -value to search for 1807185377Ssam * INPUT pList -ptr to the list to search 1808185377Ssam * INPUT listSize -number of entries in list 1809185377Ssam * OUTPUT pLowerValue -return the lower value 1810185377Ssam * OUTPUT pUpperValue -return the upper value 1811185377Ssam */ 1812185377Ssamvoid 1813185377Ssamar5211GetLowerUpperValues(uint16_t value, 1814185377Ssam const uint16_t *pList, uint16_t listSize, 1815185377Ssam uint16_t *pLowerValue, uint16_t *pUpperValue) 1816185377Ssam{ 1817185377Ssam const uint16_t listEndValue = *(pList + listSize - 1); 1818185377Ssam uint32_t target = value * EEP_SCALE; 1819185377Ssam int i; 1820185377Ssam 1821185377Ssam /* 1822185377Ssam * See if value is lower than the first value in the list 1823185377Ssam * if so return first value 1824185377Ssam */ 1825185377Ssam if (target < (uint32_t)(*pList * EEP_SCALE - EEP_DELTA)) { 1826185377Ssam *pLowerValue = *pList; 1827185377Ssam *pUpperValue = *pList; 1828185377Ssam return; 1829185377Ssam } 1830185377Ssam 1831185377Ssam /* 1832185377Ssam * See if value is greater than last value in list 1833185377Ssam * if so return last value 1834185377Ssam */ 1835185377Ssam if (target > (uint32_t)(listEndValue * EEP_SCALE + EEP_DELTA)) { 1836185377Ssam *pLowerValue = listEndValue; 1837185377Ssam *pUpperValue = listEndValue; 1838185377Ssam return; 1839185377Ssam } 1840185377Ssam 1841185377Ssam /* look for value being near or between 2 values in list */ 1842185377Ssam for (i = 0; i < listSize; i++) { 1843185377Ssam /* 1844185377Ssam * If value is close to the current value of the list 1845185377Ssam * then target is not between values, it is one of the values 1846185377Ssam */ 1847185377Ssam if (abs(pList[i] * EEP_SCALE - (int32_t) target) < EEP_DELTA) { 1848185377Ssam *pLowerValue = pList[i]; 1849185377Ssam *pUpperValue = pList[i]; 1850185377Ssam return; 1851185377Ssam } 1852185377Ssam 1853185377Ssam /* 1854185377Ssam * Look for value being between current value and next value 1855185377Ssam * if so return these 2 values 1856185377Ssam */ 1857185377Ssam if (target < (uint32_t)(pList[i + 1] * EEP_SCALE - EEP_DELTA)) { 1858185377Ssam *pLowerValue = pList[i]; 1859185377Ssam *pUpperValue = pList[i + 1]; 1860185377Ssam return; 1861185377Ssam } 1862185377Ssam } 1863185377Ssam} 1864185377Ssam 1865185377Ssam/* 1866185377Ssam * Get the upper and lower pcdac given the channel and the pcdac 1867185377Ssam * used in the search 1868185377Ssam */ 1869185377Ssamvoid 1870185377Ssamar5211GetLowerUpperPcdacs(uint16_t pcdac, uint16_t channel, 1871185377Ssam const PCDACS_EEPROM *pSrcStruct, 1872185377Ssam uint16_t *pLowerPcdac, uint16_t *pUpperPcdac) 1873185377Ssam{ 1874185377Ssam const DATA_PER_CHANNEL *pChannelData; 1875185377Ssam int i; 1876185377Ssam 1877185377Ssam /* Find the channel information */ 1878185377Ssam pChannelData = pSrcStruct->pDataPerChannel; 1879185377Ssam for (i = 0; i < pSrcStruct->numChannels; i++) { 1880185377Ssam if (pChannelData->channelValue == channel) 1881185377Ssam break; 1882185377Ssam pChannelData++; 1883185377Ssam } 1884185377Ssam ar5211GetLowerUpperValues(pcdac, pChannelData->PcdacValues, 1885185377Ssam pChannelData->numPcdacValues, pLowerPcdac, pUpperPcdac); 1886185377Ssam} 1887185377Ssam 1888185377Ssam#define DYN_ADJ_UP_MARGIN 15 1889185377Ssam#define DYN_ADJ_LO_MARGIN 20 1890185377Ssam 1891185377Ssamstatic const GAIN_OPTIMIZATION_LADDER gainLadder = { 1892185377Ssam 9, /* numStepsInLadder */ 1893185377Ssam 4, /* defaultStepNum */ 1894185377Ssam { { {4, 1, 1, 1}, 6, "FG8"}, 1895185377Ssam { {4, 0, 1, 1}, 4, "FG7"}, 1896185377Ssam { {3, 1, 1, 1}, 3, "FG6"}, 1897185377Ssam { {4, 0, 0, 1}, 1, "FG5"}, 1898185377Ssam { {4, 1, 1, 0}, 0, "FG4"}, /* noJack */ 1899185377Ssam { {4, 0, 1, 0}, -2, "FG3"}, /* halfJack */ 1900185377Ssam { {3, 1, 1, 0}, -3, "FG2"}, /* clip3 */ 1901185377Ssam { {4, 0, 0, 0}, -4, "FG1"}, /* noJack */ 1902185377Ssam { {2, 1, 1, 0}, -6, "FG0"} /* clip2 */ 1903185377Ssam } 1904185377Ssam}; 1905185377Ssam 1906185377Ssam/* 1907185377Ssam * Initialize the gain structure to good values 1908185377Ssam */ 1909185377Ssamvoid 1910185377Ssamar5211InitializeGainValues(struct ath_hal *ah) 1911185377Ssam{ 1912185377Ssam struct ath_hal_5211 *ahp = AH5211(ah); 1913185377Ssam GAIN_VALUES *gv = &ahp->ah_gainValues; 1914185377Ssam 1915185377Ssam /* initialize gain optimization values */ 1916185377Ssam gv->currStepNum = gainLadder.defaultStepNum; 1917185377Ssam gv->currStep = &gainLadder.optStep[gainLadder.defaultStepNum]; 1918185377Ssam gv->active = AH_TRUE; 1919185377Ssam gv->loTrig = 20; 1920185377Ssam gv->hiTrig = 35; 1921185377Ssam} 1922185377Ssam 1923185377Ssamstatic HAL_BOOL 1924185377Ssamar5211InvalidGainReadback(struct ath_hal *ah, GAIN_VALUES *gv) 1925185377Ssam{ 1926187831Ssam const struct ieee80211_channel *chan = AH_PRIVATE(ah)->ah_curchan; 1927185377Ssam uint32_t gStep, g; 1928185377Ssam uint32_t L1, L2, L3, L4; 1929185377Ssam 1930187831Ssam if (IEEE80211_IS_CHAN_CCK(chan)) { 1931185377Ssam gStep = 0x18; 1932185377Ssam L1 = 0; 1933185377Ssam L2 = gStep + 4; 1934185377Ssam L3 = 0x40; 1935185377Ssam L4 = L3 + 50; 1936185377Ssam 1937185377Ssam gv->loTrig = L1; 1938185377Ssam gv->hiTrig = L4+5; 1939185377Ssam } else { 1940185377Ssam gStep = 0x3f; 1941185377Ssam L1 = 0; 1942185377Ssam L2 = 50; 1943185377Ssam L3 = L1; 1944185377Ssam L4 = L3 + 50; 1945185377Ssam 1946185377Ssam gv->loTrig = L1 + DYN_ADJ_LO_MARGIN; 1947185377Ssam gv->hiTrig = L4 - DYN_ADJ_UP_MARGIN; 1948185377Ssam } 1949185377Ssam g = gv->currGain; 1950185377Ssam 1951185377Ssam return !((g >= L1 && g<= L2) || (g >= L3 && g <= L4)); 1952185377Ssam} 1953185377Ssam 1954185377Ssam/* 1955185377Ssam * Enable the probe gain check on the next packet 1956185377Ssam */ 1957185377Ssamstatic void 1958185377Ssamar5211RequestRfgain(struct ath_hal *ah) 1959185377Ssam{ 1960185377Ssam struct ath_hal_5211 *ahp = AH5211(ah); 1961185377Ssam 1962185377Ssam /* Enable the gain readback probe */ 1963185377Ssam OS_REG_WRITE(ah, AR_PHY_PAPD_PROBE, 1964185377Ssam SM(ahp->ah_tx6PowerInHalfDbm, AR_PHY_PAPD_PROBE_POWERTX) 1965185377Ssam | AR_PHY_PAPD_PROBE_NEXT_TX); 1966185377Ssam 1967185377Ssam ahp->ah_rfgainState = HAL_RFGAIN_READ_REQUESTED; 1968185377Ssam} 1969185377Ssam 1970185377Ssam/* 1971185377Ssam * Exported call to check for a recent gain reading and return 1972185377Ssam * the current state of the thermal calibration gain engine. 1973185377Ssam */ 1974185377SsamHAL_RFGAIN 1975185377Ssamar5211GetRfgain(struct ath_hal *ah) 1976185377Ssam{ 1977185377Ssam struct ath_hal_5211 *ahp = AH5211(ah); 1978185377Ssam GAIN_VALUES *gv = &ahp->ah_gainValues; 1979185377Ssam uint32_t rddata; 1980185377Ssam 1981185377Ssam if (!gv->active) 1982185377Ssam return HAL_RFGAIN_INACTIVE; 1983185377Ssam 1984185377Ssam if (ahp->ah_rfgainState == HAL_RFGAIN_READ_REQUESTED) { 1985185377Ssam /* Caller had asked to setup a new reading. Check it. */ 1986185377Ssam rddata = OS_REG_READ(ah, AR_PHY_PAPD_PROBE); 1987185377Ssam 1988185377Ssam if ((rddata & AR_PHY_PAPD_PROBE_NEXT_TX) == 0) { 1989185377Ssam /* bit got cleared, we have a new reading. */ 1990185377Ssam gv->currGain = rddata >> AR_PHY_PAPD_PROBE_GAINF_S; 1991185377Ssam /* inactive by default */ 1992185377Ssam ahp->ah_rfgainState = HAL_RFGAIN_INACTIVE; 1993185377Ssam 1994185377Ssam if (!ar5211InvalidGainReadback(ah, gv) && 1995185377Ssam ar5211IsGainAdjustNeeded(ah, gv) && 1996185377Ssam ar5211AdjustGain(ah, gv) > 0) { 1997185377Ssam /* 1998185377Ssam * Change needed. Copy ladder info 1999185377Ssam * into eeprom info. 2000185377Ssam */ 2001185377Ssam ar5211SetRfgain(ah, gv); 2002185377Ssam ahp->ah_rfgainState = HAL_RFGAIN_NEED_CHANGE; 2003185377Ssam } 2004185377Ssam } 2005185377Ssam } 2006185377Ssam return ahp->ah_rfgainState; 2007185377Ssam} 2008185377Ssam 2009185377Ssam/* 2010185377Ssam * Check to see if our readback gain level sits within the linear 2011185377Ssam * region of our current variable attenuation window 2012185377Ssam */ 2013185377Ssamstatic HAL_BOOL 2014185377Ssamar5211IsGainAdjustNeeded(struct ath_hal *ah, const GAIN_VALUES *gv) 2015185377Ssam{ 2016185377Ssam return (gv->currGain <= gv->loTrig || gv->currGain >= gv->hiTrig); 2017185377Ssam} 2018185377Ssam 2019185377Ssam/* 2020185377Ssam * Move the rabbit ears in the correct direction. 2021185377Ssam */ 2022185377Ssamstatic int32_t 2023185377Ssamar5211AdjustGain(struct ath_hal *ah, GAIN_VALUES *gv) 2024185377Ssam{ 2025185377Ssam /* return > 0 for valid adjustments. */ 2026185377Ssam if (!gv->active) 2027185377Ssam return -1; 2028185377Ssam 2029185377Ssam gv->currStep = &gainLadder.optStep[gv->currStepNum]; 2030185377Ssam if (gv->currGain >= gv->hiTrig) { 2031185377Ssam if (gv->currStepNum == 0) { 2032185377Ssam HALDEBUG(ah, HAL_DEBUG_RFPARAM, 2033185377Ssam "%s: Max gain limit.\n", __func__); 2034185377Ssam return -1; 2035185377Ssam } 2036185377Ssam HALDEBUG(ah, HAL_DEBUG_RFPARAM, 2037185377Ssam "%s: Adding gain: currG=%d [%s] --> ", 2038185377Ssam __func__, gv->currGain, gv->currStep->stepName); 2039185377Ssam gv->targetGain = gv->currGain; 2040185377Ssam while (gv->targetGain >= gv->hiTrig && gv->currStepNum > 0) { 2041185377Ssam gv->targetGain -= 2 * (gainLadder.optStep[--(gv->currStepNum)].stepGain - 2042185377Ssam gv->currStep->stepGain); 2043185377Ssam gv->currStep = &gainLadder.optStep[gv->currStepNum]; 2044185377Ssam } 2045185377Ssam HALDEBUG(ah, HAL_DEBUG_RFPARAM, "targG=%d [%s]\n", 2046185377Ssam gv->targetGain, gv->currStep->stepName); 2047185377Ssam return 1; 2048185377Ssam } 2049185377Ssam if (gv->currGain <= gv->loTrig) { 2050185377Ssam if (gv->currStepNum == gainLadder.numStepsInLadder-1) { 2051185377Ssam HALDEBUG(ah, HAL_DEBUG_RFPARAM, 2052185377Ssam "%s: Min gain limit.\n", __func__); 2053185377Ssam return -2; 2054185377Ssam } 2055185377Ssam HALDEBUG(ah, HAL_DEBUG_RFPARAM, 2056185377Ssam "%s: Deducting gain: currG=%d [%s] --> ", 2057185377Ssam __func__, gv->currGain, gv->currStep->stepName); 2058185377Ssam gv->targetGain = gv->currGain; 2059185377Ssam while (gv->targetGain <= gv->loTrig && 2060185377Ssam gv->currStepNum < (gainLadder.numStepsInLadder - 1)) { 2061185377Ssam gv->targetGain -= 2 * 2062185377Ssam (gainLadder.optStep[++(gv->currStepNum)].stepGain - gv->currStep->stepGain); 2063185377Ssam gv->currStep = &gainLadder.optStep[gv->currStepNum]; 2064185377Ssam } 2065185377Ssam HALDEBUG(ah, HAL_DEBUG_RFPARAM, "targG=%d [%s]\n", 2066185377Ssam gv->targetGain, gv->currStep->stepName); 2067185377Ssam return 2; 2068185377Ssam } 2069185377Ssam return 0; /* caller didn't call needAdjGain first */ 2070185377Ssam} 2071185377Ssam 2072185377Ssam/* 2073185377Ssam * Adjust the 5GHz EEPROM information with the desired calibration values. 2074185377Ssam */ 2075185377Ssamstatic void 2076185377Ssamar5211SetRfgain(struct ath_hal *ah, const GAIN_VALUES *gv) 2077185377Ssam{ 2078185377Ssam HAL_EEPROM *ee = AH_PRIVATE(ah)->ah_eeprom; 2079185377Ssam 2080185377Ssam if (!gv->active) 2081185377Ssam return; 2082185377Ssam ee->ee_cornerCal.clip = gv->currStep->paramVal[0]; /* bb_tx_clip */ 2083185377Ssam ee->ee_cornerCal.pd90 = gv->currStep->paramVal[1]; /* rf_pwd_90 */ 2084185377Ssam ee->ee_cornerCal.pd84 = gv->currStep->paramVal[2]; /* rf_pwd_84 */ 2085185377Ssam ee->ee_cornerCal.gSel = gv->currStep->paramVal[3]; /* rf_rfgainsel */ 2086185377Ssam} 2087185377Ssam 2088185377Ssamstatic void 2089185377Ssamar5211SetOperatingMode(struct ath_hal *ah, int opmode) 2090185377Ssam{ 2091185377Ssam struct ath_hal_5211 *ahp = AH5211(ah); 2092185377Ssam uint32_t val; 2093185377Ssam 2094185377Ssam val = OS_REG_READ(ah, AR_STA_ID1) & 0xffff; 2095185377Ssam switch (opmode) { 2096185377Ssam case HAL_M_HOSTAP: 2097185377Ssam OS_REG_WRITE(ah, AR_STA_ID1, val 2098185377Ssam | AR_STA_ID1_STA_AP 2099185377Ssam | AR_STA_ID1_RTS_USE_DEF 2100185377Ssam | ahp->ah_staId1Defaults); 2101185377Ssam break; 2102185377Ssam case HAL_M_IBSS: 2103185377Ssam OS_REG_WRITE(ah, AR_STA_ID1, val 2104185377Ssam | AR_STA_ID1_ADHOC 2105185377Ssam | AR_STA_ID1_DESC_ANTENNA 2106185377Ssam | ahp->ah_staId1Defaults); 2107185377Ssam break; 2108185377Ssam case HAL_M_STA: 2109185377Ssam case HAL_M_MONITOR: 2110185377Ssam OS_REG_WRITE(ah, AR_STA_ID1, val 2111185377Ssam | AR_STA_ID1_DEFAULT_ANTENNA 2112185377Ssam | ahp->ah_staId1Defaults); 2113185377Ssam break; 2114185377Ssam } 2115185377Ssam} 2116185377Ssam 2117185377Ssamvoid 2118185377Ssamar5211SetPCUConfig(struct ath_hal *ah) 2119185377Ssam{ 2120185377Ssam ar5211SetOperatingMode(ah, AH_PRIVATE(ah)->ah_opmode); 2121185377Ssam} 2122