2 * Copyright (c) 2002-2009 Sam Leffler, Errno Consulting
3 * Copyright (c) 2002-2008 Atheros Communications, Inc.
5 * Permission to use, copy, modify, and/or distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 * $FreeBSD: head/sys/dev/ath/ath_hal/ar5312/ar5312_reset.c 187831 2009-01-28 18:00:22Z sam $
22 #ifdef AH_SUPPORT_AR5312
25 #include "ah_internal.h"
28 #include "ar5312/ar5312.h"
29 #include "ar5312/ar5312reg.h"
30 #include "ar5312/ar5312phy.h"
32 #include "ah_eeprom_v3.h"
34 /* Additional Time delay to wait after activiting the Base band */
35 #define BASE_ACTIVATE_DELAY 100 /* 100 usec */
36 #define PLL_SETTLE_DELAY 300 /* 300 usec */
38 extern int16_t ar5212GetNf(struct ath_hal *, const struct ieee80211_channel *);
39 extern void ar5212SetRateDurationTable(struct ath_hal *,
40 const struct ieee80211_channel *);
41 extern HAL_BOOL ar5212SetTransmitPower(struct ath_hal *ah,
42 const struct ieee80211_channel *chan, uint16_t *rfXpdGain);
43 extern void ar5212SetDeltaSlope(struct ath_hal *,
44 const struct ieee80211_channel *);
45 extern HAL_BOOL ar5212SetBoardValues(struct ath_hal *,
46 const struct ieee80211_channel *);
47 extern void ar5212SetIFSTiming(struct ath_hal *,
48 const struct ieee80211_channel *);
49 extern HAL_BOOL ar5212IsSpurChannel(struct ath_hal *,
50 const struct ieee80211_channel *);
51 extern HAL_BOOL ar5212ChannelChange(struct ath_hal *,
52 const struct ieee80211_channel *);
54 static HAL_BOOL ar5312SetResetReg(struct ath_hal *, uint32_t resetMask);
57 write_common(struct ath_hal *ah, const HAL_INI_ARRAY *ia,
58 HAL_BOOL bChannelChange, int writes)
60 #define IS_NO_RESET_TIMER_ADDR(x) \
61 ( (((x) >= AR_BEACON) && ((x) <= AR_CFP_DUR)) || \
62 (((x) >= AR_SLEEP1) && ((x) <= AR_SLEEP3)))
63 #define V(r, c) (ia)->data[((r)*(ia)->cols) + (c)]
66 /* Write Common Array Parameters */
67 for (i = 0; i < ia->rows; i++) {
68 uint32_t reg = V(i, 0);
69 /* XXX timer/beacon setup registers? */
70 /* On channel change, don't reset the PCU registers */
71 if (!(bChannelChange && IS_NO_RESET_TIMER_ADDR(reg))) {
72 OS_REG_WRITE(ah, reg, V(i, 1));
77 #undef IS_NO_RESET_TIMER_ADDR
82 * Places the device in and out of reset and then places sane
83 * values in the registers based on EEPROM config, initialization
84 * vectors (as determined by the mode), and station configuration
86 * bChannelChange is used to preserve DMA/PCU registers across
87 * a HW Reset during channel change.
90 ar5312Reset(struct ath_hal *ah, HAL_OPMODE opmode,
91 struct ieee80211_channel *chan,
92 HAL_BOOL bChannelChange, HAL_STATUS *status)
94 #define N(a) (sizeof (a) / sizeof (a[0]))
95 #define FAIL(_code) do { ecode = _code; goto bad; } while (0)
96 struct ath_hal_5212 *ahp = AH5212(ah);
97 HAL_CHANNEL_INTERNAL *ichan;
99 uint32_t saveFrameSeqCount, saveDefAntenna;
100 uint32_t macStaId1, synthDelay, txFrm2TxDStart;
101 uint16_t rfXpdGain[MAX_NUM_PDGAINS_PER_CHANNEL];
102 int16_t cckOfdmPwrDelta = 0;
103 u_int modesIndex, freqIndex;
105 int i, regWrites = 0;
107 uint32_t saveLedState = 0;
109 HALASSERT(ah->ah_magic == AR5212_MAGIC);
110 ee = AH_PRIVATE(ah)->ah_eeprom;
112 OS_MARK(ah, AH_MARK_RESET, bChannelChange);
114 * Map public channel to private.
116 ichan = ath_hal_checkchannel(ah, chan);
117 if (ichan == AH_NULL) {
118 HALDEBUG(ah, HAL_DEBUG_ANY,
119 "%s: invalid channel %u/0x%x; no mapping\n",
120 __func__, chan->ic_freq, chan->ic_flags);
130 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: invalid operating mode %u\n",
135 HALASSERT(ahp->ah_eeversion >= AR_EEPROM_VER3);
137 /* Preserve certain DMA hardware registers on a channel change */
138 if (bChannelChange) {
140 * On Venice, the TSF is almost preserved across a reset;
141 * it requires the doubling writes to the RESET_TSF
142 * bit in the AR_BEACON register; it also has the quirk
143 * of the TSF going back in time on the station (station
144 * latches onto the last beacon's tsf during a reset 50%
145 * of the times); the latter is not a problem for adhoc
146 * stations since as long as the TSF is behind, it will
147 * get resynchronized on receiving the next beacon; the
148 * TSF going backwards in time could be a problem for the
149 * sleep operation (supported on infrastructure stations
150 * only) - the best and most general fix for this situation
151 * is to resynchronize the various sleep/beacon timers on
152 * the receipt of the next beacon i.e. when the TSF itself
153 * gets resynchronized to the AP's TSF - power save is
154 * needed to be temporarily disabled until that time
156 * Need to save the sequence number to restore it after
159 saveFrameSeqCount = OS_REG_READ(ah, AR_D_SEQNUM);
161 saveFrameSeqCount = 0; /* NB: silence compiler */
163 /* If the channel change is across the same mode - perform a fast channel change */
164 if ((IS_2413(ah) || IS_5413(ah))) {
166 * Channel change can only be used when:
167 * -channel change requested - so it's not the initial reset.
168 * -it's not a change to the current channel - often called when switching modes
170 * -the modes of the previous and requested channel are the same - some ugly code for XR
172 if (bChannelChange &&
173 AH_PRIVATE(ah)->ah_curchan != AH_NULL &&
174 (chan->ic_freq != AH_PRIVATE(ah)->ah_curchan->ic_freq) &&
175 ((chan->ic_flags & IEEE80211_CHAN_ALLTURBO) ==
176 (AH_PRIVATE(ah)->ah_curchan->ic_flags & IEEE80211_CHAN_ALLTURBO))) {
177 if (ar5212ChannelChange(ah, chan))
178 /* If ChannelChange completed - skip the rest of reset */
184 * Preserve the antenna on a channel change
186 saveDefAntenna = OS_REG_READ(ah, AR_DEF_ANTENNA);
187 if (saveDefAntenna == 0) /* XXX magic constants */
190 /* Save hardware flag before chip reset clears the register */
191 macStaId1 = OS_REG_READ(ah, AR_STA_ID1) &
192 (AR_STA_ID1_BASE_RATE_11B | AR_STA_ID1_USE_DEFANT);
194 /* Save led state from pci config register */
196 saveLedState = OS_REG_READ(ah, AR5312_PCICFG) &
197 (AR_PCICFG_LEDCTL | AR_PCICFG_LEDMODE | AR_PCICFG_LEDBLINK |
200 ar5312RestoreClock(ah, opmode); /* move to refclk operation */
203 * Adjust gain parameters before reset if
204 * there's an outstanding gain updated.
206 (void) ar5212GetRfgain(ah);
208 if (!ar5312ChipReset(ah, chan)) {
209 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: chip reset failed\n", __func__);
213 /* Setup the indices for the next set of register array writes */
214 if (IEEE80211_IS_CHAN_2GHZ(chan)) {
216 modesIndex = IEEE80211_IS_CHAN_108G(chan) ? 5 :
217 IEEE80211_IS_CHAN_G(chan) ? 4 : 3;
220 modesIndex = IEEE80211_IS_CHAN_ST(chan) ? 2 : 1;
223 OS_MARK(ah, AH_MARK_RESET_LINE, __LINE__);
225 /* Set correct Baseband to analog shift setting to access analog chips. */
226 OS_REG_WRITE(ah, AR_PHY(0), 0x00000007);
228 regWrites = ath_hal_ini_write(ah, &ahp->ah_ini_modes, modesIndex, 0);
229 regWrites = write_common(ah, &ahp->ah_ini_common, bChannelChange,
231 ahp->ah_rfHal->writeRegs(ah, modesIndex, freqIndex, regWrites);
233 OS_MARK(ah, AH_MARK_RESET_LINE, __LINE__);
235 if (IEEE80211_IS_CHAN_HALF(chan) || IEEE80211_IS_CHAN_QUARTER(chan))
236 ar5212SetIFSTiming(ah, chan);
238 /* Overwrite INI values for revised chipsets */
239 if (AH_PRIVATE(ah)->ah_phyRev >= AR_PHY_CHIP_ID_REV_2) {
241 OS_REG_WRITE(ah, AR_PHY_ADC_CTL,
242 SM(2, AR_PHY_ADC_CTL_OFF_INBUFGAIN) |
243 SM(2, AR_PHY_ADC_CTL_ON_INBUFGAIN) |
244 AR_PHY_ADC_CTL_OFF_PWDDAC |
245 AR_PHY_ADC_CTL_OFF_PWDADC);
248 if (chan->channel == 2484) {
249 cckOfdmPwrDelta = SCALE_OC_DELTA(ee->ee_cckOfdmPwrDelta - ee->ee_scaledCh14FilterCckDelta);
251 cckOfdmPwrDelta = SCALE_OC_DELTA(ee->ee_cckOfdmPwrDelta);
254 if (IEEE80211_IS_CHAN_G(chan)) {
255 OS_REG_WRITE(ah, AR_PHY_TXPWRADJ,
256 SM((ee->ee_cckOfdmPwrDelta*-1), AR_PHY_TXPWRADJ_CCK_GAIN_DELTA) |
257 SM((cckOfdmPwrDelta*-1), AR_PHY_TXPWRADJ_CCK_PCDAC_INDEX));
259 OS_REG_WRITE(ah, AR_PHY_TXPWRADJ, 0);
262 /* Add barker RSSI thresh enable as disabled */
263 OS_REG_CLR_BIT(ah, AR_PHY_DAG_CTRLCCK,
264 AR_PHY_DAG_CTRLCCK_EN_RSSI_THR);
265 OS_REG_RMW_FIELD(ah, AR_PHY_DAG_CTRLCCK,
266 AR_PHY_DAG_CTRLCCK_RSSI_THR, 2);
268 /* Set the mute mask to the correct default */
269 OS_REG_WRITE(ah, AR_SEQ_MASK, 0x0000000F);
272 if (AH_PRIVATE(ah)->ah_phyRev >= AR_PHY_CHIP_ID_REV_3) {
273 /* Clear reg to alllow RX_CLEAR line debug */
274 OS_REG_WRITE(ah, AR_PHY_BLUETOOTH, 0);
276 if (AH_PRIVATE(ah)->ah_phyRev >= AR_PHY_CHIP_ID_REV_4) {
278 /* Enable burst prefetch for the data queues */
279 OS_REG_RMW_FIELD(ah, AR_D_FPCTL, ... );
280 /* Enable double-buffering */
281 OS_REG_CLR_BIT(ah, AR_TXCFG, AR_TXCFG_DBL_BUF_DIS);
285 if (IS_5312_2_X(ah)) {
287 OS_REG_WRITE(ah, AR_PHY_SIGMA_DELTA,
288 SM(2, AR_PHY_SIGMA_DELTA_ADC_SEL) |
289 SM(4, AR_PHY_SIGMA_DELTA_FILT2) |
290 SM(0x16, AR_PHY_SIGMA_DELTA_FILT1) |
291 SM(0, AR_PHY_SIGMA_DELTA_ADC_CLIP));
293 if (IEEE80211_IS_CHAN_2GHZ(chan))
294 OS_REG_RMW_FIELD(ah, AR_PHY_RXGAIN, AR_PHY_RXGAIN_TXRX_RF_MAX, 0x0F);
296 /* CCK Short parameter adjustment in 11B mode */
297 if (IEEE80211_IS_CHAN_B(chan))
298 OS_REG_RMW_FIELD(ah, AR_PHY_CCK_RXCTRL4, AR_PHY_CCK_RXCTRL4_FREQ_EST_SHORT, 12);
300 /* Set ADC/DAC select values */
301 OS_REG_WRITE(ah, AR_PHY_SLEEP_SCAL, 0x04);
303 /* Increase 11A AGC Settling */
304 if (IEEE80211_IS_CHAN_A(chan))
305 OS_REG_RMW_FIELD(ah, AR_PHY_SETTLING, AR_PHY_SETTLING_AGC, 32);
307 /* Set ADC/DAC select values */
308 OS_REG_WRITE(ah, AR_PHY_SLEEP_SCAL, 0x0e);
311 /* Setup the transmit power values. */
312 if (!ar5212SetTransmitPower(ah, chan, rfXpdGain)) {
313 HALDEBUG(ah, HAL_DEBUG_ANY,
314 "%s: error init'ing transmit power\n", __func__);
318 /* Write the analog registers */
319 if (!ahp->ah_rfHal->setRfRegs(ah, chan, modesIndex, rfXpdGain)) {
320 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: ar5212SetRfRegs failed\n",
325 /* Write delta slope for OFDM enabled modes (A, G, Turbo) */
326 if (IEEE80211_IS_CHAN_OFDM(chan)) {
328 AH_PRIVATE(ah)->ah_eeversion >= AR_EEPROM_VER5_3)
329 ar5212SetSpurMitigation(ah, chan);
330 ar5212SetDeltaSlope(ah, chan);
333 /* Setup board specific options for EEPROM version 3 */
334 if (!ar5212SetBoardValues(ah, chan)) {
335 HALDEBUG(ah, HAL_DEBUG_ANY,
336 "%s: error setting board options\n", __func__);
340 /* Restore certain DMA hardware registers on a channel change */
342 OS_REG_WRITE(ah, AR_D_SEQNUM, saveFrameSeqCount);
344 OS_MARK(ah, AH_MARK_RESET_LINE, __LINE__);
346 OS_REG_WRITE(ah, AR_STA_ID0, LE_READ_4(ahp->ah_macaddr));
347 OS_REG_WRITE(ah, AR_STA_ID1, LE_READ_2(ahp->ah_macaddr + 4)
349 | AR_STA_ID1_RTS_USE_DEF
350 | ahp->ah_staId1Defaults
352 ar5212SetOperatingMode(ah, opmode);
354 /* Set Venice BSSID mask according to current state */
355 OS_REG_WRITE(ah, AR_BSSMSKL, LE_READ_4(ahp->ah_bssidmask));
356 OS_REG_WRITE(ah, AR_BSSMSKU, LE_READ_2(ahp->ah_bssidmask + 4));
358 /* Restore previous led state */
360 OS_REG_WRITE(ah, AR5312_PCICFG, OS_REG_READ(ah, AR_PCICFG) | saveLedState);
362 /* Restore previous antenna */
363 OS_REG_WRITE(ah, AR_DEF_ANTENNA, saveDefAntenna);
366 OS_REG_WRITE(ah, AR_BSS_ID0, LE_READ_4(ahp->ah_bssid));
367 OS_REG_WRITE(ah, AR_BSS_ID1, LE_READ_2(ahp->ah_bssid + 4));
369 /* Restore bmiss rssi & count thresholds */
370 OS_REG_WRITE(ah, AR_RSSI_THR, ahp->ah_rssiThr);
372 OS_REG_WRITE(ah, AR_ISR, ~0); /* cleared on write */
374 if (!ar5212SetChannel(ah, chan))
377 OS_MARK(ah, AH_MARK_RESET_LINE, __LINE__);
379 ar5212SetCoverageClass(ah, AH_PRIVATE(ah)->ah_coverageClass, 1);
381 ar5212SetRateDurationTable(ah, chan);
383 /* Set Tx frame start to tx data start delay */
384 if (IS_RAD5112_ANY(ah) &&
385 (IEEE80211_IS_CHAN_HALF(chan) || IEEE80211_IS_CHAN_QUARTER(chan))) {
387 IEEE80211_IS_CHAN_HALF(chan) ?
388 TX_FRAME_D_START_HALF_RATE:
389 TX_FRAME_D_START_QUARTER_RATE;
390 OS_REG_RMW_FIELD(ah, AR_PHY_TX_CTL,
391 AR_PHY_TX_FRAME_TO_TX_DATA_START, txFrm2TxDStart);
395 * Setup fast diversity.
396 * Fast diversity can be enabled or disabled via regadd.txt.
397 * Default is enabled.
400 * 0x00009860 0x00009d18 (if 11a / 11g, else no change)
401 * 0x00009970 0x192bb514
402 * 0x0000a208 0xd03e4648
404 * Enable: 0x00009860 0x00009d10 (if 11a / 11g, else no change)
405 * 0x00009970 0x192fb514
406 * 0x0000a208 0xd03e6788
409 /* XXX Setup pre PHY ENABLE EAR additions */
412 if (IS_5312_2_X(ah)) {
413 (void) OS_REG_READ(ah, AR_PHY_SLEEP_SCAL);
417 * Wait for the frequency synth to settle (synth goes on
418 * via AR_PHY_ACTIVE_EN). Read the phy active delay register.
419 * Value is in 100ns increments.
421 synthDelay = OS_REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
422 if (IEEE80211_IS_CHAN_B(chan)) {
423 synthDelay = (4 * synthDelay) / 22;
428 /* Activate the PHY (includes baseband activate and synthesizer on) */
429 OS_REG_WRITE(ah, AR_PHY_ACTIVE, AR_PHY_ACTIVE_EN);
432 * There is an issue if the AP starts the calibration before
433 * the base band timeout completes. This could result in the
434 * rx_clear false triggering. As a workaround we add delay an
435 * extra BASE_ACTIVATE_DELAY usecs to ensure this condition
438 if (IEEE80211_IS_CHAN_HALF(chan)) {
439 OS_DELAY((synthDelay << 1) + BASE_ACTIVATE_DELAY);
440 } else if (IEEE80211_IS_CHAN_QUARTER(chan)) {
441 OS_DELAY((synthDelay << 2) + BASE_ACTIVATE_DELAY);
443 OS_DELAY(synthDelay + BASE_ACTIVATE_DELAY);
447 * The udelay method is not reliable with notebooks.
448 * Need to check to see if the baseband is ready
450 testReg = OS_REG_READ(ah, AR_PHY_TESTCTRL);
451 /* Selects the Tx hold */
452 OS_REG_WRITE(ah, AR_PHY_TESTCTRL, AR_PHY_TESTCTRL_TXHOLD);
455 (OS_REG_READ(ah, 0x9c24) & 0x10)) /* test if baseband not ready */ OS_DELAY(200);
456 OS_REG_WRITE(ah, AR_PHY_TESTCTRL, testReg);
458 /* Calibrate the AGC and start a NF calculation */
459 OS_REG_WRITE(ah, AR_PHY_AGC_CONTROL,
460 OS_REG_READ(ah, AR_PHY_AGC_CONTROL)
461 | AR_PHY_AGC_CONTROL_CAL
462 | AR_PHY_AGC_CONTROL_NF);
464 if (!IEEE80211_IS_CHAN_B(chan) && ahp->ah_bIQCalibration != IQ_CAL_DONE) {
465 /* Start IQ calibration w/ 2^(INIT_IQCAL_LOG_COUNT_MAX+1) samples */
466 OS_REG_RMW_FIELD(ah, AR_PHY_TIMING_CTRL4,
467 AR_PHY_TIMING_CTRL4_IQCAL_LOG_COUNT_MAX,
468 INIT_IQCAL_LOG_COUNT_MAX);
469 OS_REG_SET_BIT(ah, AR_PHY_TIMING_CTRL4,
470 AR_PHY_TIMING_CTRL4_DO_IQCAL);
471 ahp->ah_bIQCalibration = IQ_CAL_RUNNING;
473 ahp->ah_bIQCalibration = IQ_CAL_INACTIVE;
475 /* Setup compression registers */
476 ar5212SetCompRegs(ah);
478 /* Set 1:1 QCU to DCU mapping for all queues */
479 for (i = 0; i < AR_NUM_DCU; i++)
480 OS_REG_WRITE(ah, AR_DQCUMASK(i), 1 << i);
482 ahp->ah_intrTxqs = 0;
483 for (i = 0; i < AH_PRIVATE(ah)->ah_caps.halTotalQueues; i++)
484 ar5212ResetTxQueue(ah, i);
487 * Setup interrupt handling. Note that ar5212ResetTxQueue
488 * manipulates the secondary IMR's as queues are enabled
489 * and disabled. This is done with RMW ops to insure the
490 * settings we make here are preserved.
492 ahp->ah_maskReg = AR_IMR_TXOK | AR_IMR_TXERR | AR_IMR_TXURN
493 | AR_IMR_RXOK | AR_IMR_RXERR | AR_IMR_RXORN
496 if (opmode == HAL_M_HOSTAP)
497 ahp->ah_maskReg |= AR_IMR_MIB;
498 OS_REG_WRITE(ah, AR_IMR, ahp->ah_maskReg);
499 /* Enable bus errors that are OR'd to set the HIUERR bit */
500 OS_REG_WRITE(ah, AR_IMR_S2,
501 OS_REG_READ(ah, AR_IMR_S2)
502 | AR_IMR_S2_MCABT | AR_IMR_S2_SSERR | AR_IMR_S2_DPERR);
504 if (AH_PRIVATE(ah)->ah_rfkillEnabled)
505 ar5212EnableRfKill(ah);
507 if (!ath_hal_wait(ah, AR_PHY_AGC_CONTROL, AR_PHY_AGC_CONTROL_CAL, 0)) {
508 HALDEBUG(ah, HAL_DEBUG_ANY,
509 "%s: offset calibration failed to complete in 1ms;"
510 " noisy environment?\n", __func__);
514 * Set clocks back to 32kHz if they had been using refClk, then
515 * use an external 32kHz crystal when sleeping, if one exists.
517 ar5312SetupClock(ah, opmode);
520 * Writing to AR_BEACON will start timers. Hence it should
521 * be the last register to be written. Do not reset tsf, do
522 * not enable beacons at this point, but preserve other values
523 * like beaconInterval.
525 OS_REG_WRITE(ah, AR_BEACON,
526 (OS_REG_READ(ah, AR_BEACON) &~ (AR_BEACON_EN | AR_BEACON_RESET_TSF)));
528 /* XXX Setup post reset EAR additions */
531 if (AH_PRIVATE(ah)->ah_macVersion > AR_SREV_VERSION_VENICE ||
532 (AH_PRIVATE(ah)->ah_macVersion == AR_SREV_VERSION_VENICE &&
533 AH_PRIVATE(ah)->ah_macRev >= AR_SREV_GRIFFIN_LITE)) {
534 OS_REG_WRITE(ah, AR_QOS_CONTROL, 0x100aa); /* XXX magic */
535 OS_REG_WRITE(ah, AR_QOS_SELECT, 0x3210); /* XXX magic */
538 /* Turn on NOACK Support for QoS packets */
539 OS_REG_WRITE(ah, AR_NOACK,
540 SM(2, AR_NOACK_2BIT_VALUE) |
541 SM(5, AR_NOACK_BIT_OFFSET) |
542 SM(0, AR_NOACK_BYTE_OFFSET));
544 /* Restore user-specified settings */
545 if (ahp->ah_miscMode != 0)
546 OS_REG_WRITE(ah, AR_MISC_MODE, ahp->ah_miscMode);
547 if (ahp->ah_slottime != (u_int) -1)
548 ar5212SetSlotTime(ah, ahp->ah_slottime);
549 if (ahp->ah_acktimeout != (u_int) -1)
550 ar5212SetAckTimeout(ah, ahp->ah_acktimeout);
551 if (ahp->ah_ctstimeout != (u_int) -1)
552 ar5212SetCTSTimeout(ah, ahp->ah_ctstimeout);
553 if (ahp->ah_sifstime != (u_int) -1)
554 ar5212SetSifsTime(ah, ahp->ah_sifstime);
555 if (AH_PRIVATE(ah)->ah_diagreg != 0)
556 OS_REG_WRITE(ah, AR_DIAG_SW, AH_PRIVATE(ah)->ah_diagreg);
558 AH_PRIVATE(ah)->ah_opmode = opmode; /* record operating mode */
560 if (bChannelChange && !IEEE80211_IS_CHAN_DFS(chan))
561 chan->ic_state &= ~IEEE80211_CHANSTATE_CWINT;
563 HALDEBUG(ah, HAL_DEBUG_RESET, "%s: done\n", __func__);
565 OS_MARK(ah, AH_MARK_RESET_DONE, 0);
569 OS_MARK(ah, AH_MARK_RESET_DONE, ecode);
570 if (status != AH_NULL)
578 * Places the PHY and Radio chips into reset. A full reset
579 * must be called to leave this state. The PCI/MAC/PCU are
580 * not placed into reset as we must receive interrupt to
581 * re-enable the hardware.
584 ar5312PhyDisable(struct ath_hal *ah)
586 return ar5312SetResetReg(ah, AR_RC_BB);
590 * Places all of hardware into reset
593 ar5312Disable(struct ath_hal *ah)
595 if (!ar5312SetPowerMode(ah, HAL_PM_AWAKE, AH_TRUE))
598 * Reset the HW - PCI must be reset after the rest of the
599 * device has been reset.
601 return ar5312SetResetReg(ah, AR_RC_MAC | AR_RC_BB);
605 * Places the hardware into reset and then pulls it out of reset
607 * TODO: Only write the PLL if we're changing to or from CCK mode
609 * WARNING: The order of the PLL and mode registers must be correct.
612 ar5312ChipReset(struct ath_hal *ah, const struct ieee80211_channel *chan)
615 OS_MARK(ah, AH_MARK_CHIPRESET, chan ? chan->ic_freq : 0);
620 if (!ar5312SetResetReg(ah, AR_RC_MAC | AR_RC_BB)) {
621 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: ar5312SetResetReg failed\n",
626 /* Bring out of sleep mode (AGAIN) */
627 if (!ar5312SetPowerMode(ah, HAL_PM_AWAKE, AH_TRUE)) {
628 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: ar5312SetPowerMode failed\n",
633 /* Clear warm reset register */
634 if (!ar5312SetResetReg(ah, 0)) {
635 HALDEBUG(ah, HAL_DEBUG_ANY, "%s: ar5312SetResetReg failed\n",
641 * Perform warm reset before the mode/PLL/turbo registers
642 * are changed in order to deactivate the radio. Mode changes
643 * with an active radio can result in corrupted shifts to the
648 * Set CCK and Turbo modes correctly.
650 if (chan != AH_NULL) { /* NB: can be null during attach */
651 uint32_t rfMode, phyPLL = 0, curPhyPLL, turbo;
653 if (IS_RAD5112_ANY(ah)) {
654 rfMode = AR_PHY_MODE_AR5112;
656 if (IEEE80211_IS_CHAN_CCK(chan)) {
657 phyPLL = AR_PHY_PLL_CTL_44_5312;
659 if (IEEE80211_IS_CHAN_HALF(chan)) {
660 phyPLL = AR_PHY_PLL_CTL_40_5312_HALF;
661 } else if (IEEE80211_IS_CHAN_QUARTER(chan)) {
662 phyPLL = AR_PHY_PLL_CTL_40_5312_QUARTER;
664 phyPLL = AR_PHY_PLL_CTL_40_5312;
668 if (IEEE80211_IS_CHAN_CCK(chan))
669 phyPLL = AR_PHY_PLL_CTL_44_5112;
671 phyPLL = AR_PHY_PLL_CTL_40_5112;
672 if (IEEE80211_IS_CHAN_HALF(chan))
673 phyPLL |= AR_PHY_PLL_CTL_HALF;
674 else if (IEEE80211_IS_CHAN_QUARTER(chan))
675 phyPLL |= AR_PHY_PLL_CTL_QUARTER;
678 rfMode = AR_PHY_MODE_AR5111;
679 if (IEEE80211_IS_CHAN_CCK(chan))
680 phyPLL = AR_PHY_PLL_CTL_44;
682 phyPLL = AR_PHY_PLL_CTL_40;
683 if (IEEE80211_IS_CHAN_HALF(chan))
684 phyPLL = AR_PHY_PLL_CTL_HALF;
685 else if (IEEE80211_IS_CHAN_QUARTER(chan))
686 phyPLL = AR_PHY_PLL_CTL_QUARTER;
688 if (IEEE80211_IS_CHAN_G(chan))
689 rfMode |= AR_PHY_MODE_DYNAMIC;
690 else if (IEEE80211_IS_CHAN_OFDM(chan))
691 rfMode |= AR_PHY_MODE_OFDM;
693 rfMode |= AR_PHY_MODE_CCK;
694 if (IEEE80211_IS_CHAN_5GHZ(chan))
695 rfMode |= AR_PHY_MODE_RF5GHZ;
697 rfMode |= AR_PHY_MODE_RF2GHZ;
698 turbo = IEEE80211_IS_CHAN_TURBO(chan) ?
699 (AR_PHY_FC_TURBO_MODE | AR_PHY_FC_TURBO_SHORT) : 0;
700 curPhyPLL = OS_REG_READ(ah, AR_PHY_PLL_CTL);
702 * PLL, Mode, and Turbo values must be written in the correct
704 * - The PLL cannot be set to 44 unless the CCK or DYNAMIC
706 * - Turbo cannot be set at the same time as CCK or DYNAMIC
708 if (IEEE80211_IS_CHAN_CCK(chan)) {
709 OS_REG_WRITE(ah, AR_PHY_TURBO, turbo);
710 OS_REG_WRITE(ah, AR_PHY_MODE, rfMode);
711 if (curPhyPLL != phyPLL) {
712 OS_REG_WRITE(ah, AR_PHY_PLL_CTL, phyPLL);
713 /* Wait for the PLL to settle */
714 OS_DELAY(PLL_SETTLE_DELAY);
717 if (curPhyPLL != phyPLL) {
718 OS_REG_WRITE(ah, AR_PHY_PLL_CTL, phyPLL);
719 /* Wait for the PLL to settle */
720 OS_DELAY(PLL_SETTLE_DELAY);
722 OS_REG_WRITE(ah, AR_PHY_TURBO, turbo);
723 OS_REG_WRITE(ah, AR_PHY_MODE, rfMode);
730 * Write the given reset bit mask into the reset register
733 ar5312SetResetReg(struct ath_hal *ah, uint32_t resetMask)
735 uint32_t mask = resetMask ? resetMask : ~0;
738 if ((rt = ar5312MacReset(ah, mask)) == AH_FALSE) {
741 if ((resetMask & AR_RC_MAC) == 0) {
744 * Set CFG, little-endian for register
745 * and descriptor accesses.
747 #ifdef AH_NEED_DESC_SWAP
748 mask = INIT_CONFIG_STATUS | AR_CFG_SWRD;
750 mask = INIT_CONFIG_STATUS |
751 AR_CFG_SWTD | AR_CFG_SWRD;
753 OS_REG_WRITE(ah, AR_CFG, mask);
755 OS_REG_WRITE(ah, AR_CFG, INIT_CONFIG_STATUS);
761 * ar5312MacReset resets (and then un-resets) the specified
762 * wireless components.
763 * Note: The RCMask cannot be zero on entering from ar5312SetResetReg.
767 ar5312MacReset(struct ath_hal *ah, unsigned int RCMask)
769 int wlanNum = AR5312_UNIT(ah);
770 uint32_t resetBB, resetBits, regMask;
775 #if ( AH_SUPPORT_2316 || AH_SUPPORT_2317 )
779 resetBB = AR5315_RC_BB0_CRES | AR5315_RC_WBB0_RES;
780 /* Warm and cold reset bits for wbb */
781 resetBits = AR5315_RC_WMAC0_RES;
784 resetBB = AR5315_RC_BB1_CRES | AR5315_RC_WBB1_RES;
785 /* Warm and cold reset bits for wbb */
786 resetBits = AR5315_RC_WMAC1_RES;
791 regMask = ~(resetBB | resetBits);
794 reg = OS_REG_READ(ah,
795 (AR5315_RSTIMER_BASE - ((uint32_t) ah->ah_sh) + AR5315_RESET));
797 if (RCMask == AR_RC_BB) {
798 /* Put baseband in reset */
799 reg |= resetBB; /* Cold and warm reset the baseband bits */
802 * Reset the MAC and baseband. This is a bit different than
803 * the PCI version, but holding in reset causes problems.
806 reg |= (resetBits | resetBB) ;
809 (AR5315_RSTIMER_BASE - ((uint32_t) ah->ah_sh)+AR5315_RESET),
813 (AR5315_RSTIMER_BASE - ((uint32_t) ah->ah_sh) +AR5315_RESET));
816 /* Bring MAC and baseband out of reset */
820 (AR5315_RSTIMER_BASE- ((uint32_t) ah->ah_sh) +AR5315_RESET));
822 (AR5315_RSTIMER_BASE - ((uint32_t) ah->ah_sh)+AR5315_RESET),
826 (AR5315_RSTIMER_BASE- ((uint32_t) ah->ah_sh) +AR5315_RESET));
836 resetBB = AR5312_RC_BB0_CRES | AR5312_RC_WBB0_RES;
837 /* Warm and cold reset bits for wbb */
838 resetBits = AR5312_RC_WMAC0_RES;
841 resetBB = AR5312_RC_BB1_CRES | AR5312_RC_WBB1_RES;
842 /* Warm and cold reset bits for wbb */
843 resetBits = AR5312_RC_WMAC1_RES;
848 regMask = ~(resetBB | resetBits);
851 reg = OS_REG_READ(ah,
852 (AR5312_RSTIMER_BASE - ((uint32_t) ah->ah_sh) + AR5312_RESET));
854 if (RCMask == AR_RC_BB) {
855 /* Put baseband in reset */
856 reg |= resetBB; /* Cold and warm reset the baseband bits */
859 * Reset the MAC and baseband. This is a bit different than
860 * the PCI version, but holding in reset causes problems.
863 reg |= (resetBits | resetBB) ;
866 (AR5312_RSTIMER_BASE - ((uint32_t) ah->ah_sh)+AR5312_RESET),
870 (AR5312_RSTIMER_BASE - ((uint32_t) ah->ah_sh) +AR5312_RESET));
873 /* Bring MAC and baseband out of reset */
877 (AR5312_RSTIMER_BASE- ((uint32_t) ah->ah_sh) +AR5312_RESET));
879 (AR5312_RSTIMER_BASE - ((uint32_t) ah->ah_sh)+AR5312_RESET),
883 (AR5312_RSTIMER_BASE- ((uint32_t) ah->ah_sh) +AR5312_RESET));
888 #endif /* AH_SUPPORT_AR5312 */