2 * Copyright (c) 2004-2008 Reyk Floeter <reyk@openbsd.org>
3 * Copyright (c) 2006-2008 Nick Kossifidis <mickflemm@gmail.com>
4 * Copyright (c) 2007-2008 Luis Rodriguez <mcgrof@winlab.rutgers.edu>
5 * Copyright (c) 2007-2008 Pavel Roskin <proski@gnu.org>
6 * Copyright (c) 2007-2008 Jiri Slaby <jirislaby@gmail.com>
8 * Permission to use, copy, modify, and distribute this software for any
9 * purpose with or without fee is hereby granted, provided that the above
10 * copyright notice and this permission notice appear in all copies.
12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22 /*****************************\
23 Reset functions and helpers
24 \*****************************/
26 #include <asm/unaligned.h>
28 #include <linux/pci.h> /* To determine if a card is pci-e */
29 #include <linux/log2.h>
36 * Check if a register write has been completed
38 int ath5k_hw_register_timeout(struct ath5k_hw *ah, u32 reg, u32 flag, u32 val,
44 for (i = AR5K_TUNE_REGISTER_TIMEOUT; i > 0; i--) {
45 data = ath5k_hw_reg_read(ah, reg);
46 if (is_set && (data & flag))
48 else if ((data & flag) == val)
53 return (i <= 0) ? -EAGAIN : 0;
57 * ath5k_hw_write_ofdm_timings - set OFDM timings on AR5212
59 * @ah: the &struct ath5k_hw
60 * @channel: the currently set channel upon reset
62 * Write the delta slope coefficient (used on pilot tracking ?) for OFDM
63 * operation on the AR5212 upon reset. This is a helper for ath5k_hw_reset().
65 * Since delta slope is floating point we split it on its exponent and
66 * mantissa and provide these values on hw.
68 * For more infos i think this patent is related
69 * http://www.freepatentsonline.com/7184495.html
71 static inline int ath5k_hw_write_ofdm_timings(struct ath5k_hw *ah,
72 struct ieee80211_channel *channel)
74 /* Get exponent and mantissa and set it */
75 u32 coef_scaled, coef_exp, coef_man,
76 ds_coef_exp, ds_coef_man, clock;
78 BUG_ON(!(ah->ah_version == AR5K_AR5212) ||
79 !(channel->hw_value & CHANNEL_OFDM));
82 * ALGO: coef = (5 * clock / carrier_freq) / 2
83 * we scale coef by shifting clock value by 24 for
84 * better precision since we use integers */
85 /* TODO: Half/quarter rate */
86 clock = (channel->hw_value & CHANNEL_TURBO) ? 80 : 40;
87 coef_scaled = ((5 * (clock << 24)) / 2) / channel->center_freq;
90 * ALGO: coef_exp = 14 - highest set bit position */
91 coef_exp = ilog2(coef_scaled);
93 /* Doesn't make sense if it's zero*/
94 if (!coef_scaled || !coef_exp)
97 /* Note: we've shifted coef_scaled by 24 */
98 coef_exp = 14 - (coef_exp - 24);
101 /* Get mantissa (significant digits)
102 * ALGO: coef_mant = floor(coef_scaled* 2^coef_exp+0.5) */
103 coef_man = coef_scaled +
104 (1 << (24 - coef_exp - 1));
106 /* Calculate delta slope coefficient exponent
107 * and mantissa (remove scaling) and set them on hw */
108 ds_coef_man = coef_man >> (24 - coef_exp);
109 ds_coef_exp = coef_exp - 16;
111 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_TIMING_3,
112 AR5K_PHY_TIMING_3_DSC_MAN, ds_coef_man);
113 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_TIMING_3,
114 AR5K_PHY_TIMING_3_DSC_EXP, ds_coef_exp);
121 * index into rates for control rates, we can set it up like this because
122 * this is only used for AR5212 and we know it supports G mode
124 static const unsigned int control_rates[] =
125 { 0, 1, 1, 1, 4, 4, 6, 6, 8, 8, 8, 8 };
128 * ath5k_hw_write_rate_duration - fill rate code to duration table
130 * @ah: the &struct ath5k_hw
131 * @mode: one of enum ath5k_driver_mode
133 * Write the rate code to duration table upon hw reset. This is a helper for
134 * ath5k_hw_reset(). It seems all this is doing is setting an ACK timeout on
135 * the hardware, based on current mode, for each rate. The rates which are
136 * capable of short preamble (802.11b rates 2Mbps, 5.5Mbps, and 11Mbps) have
137 * different rate code so we write their value twice (one for long preample
138 * and one for short).
140 * Note: Band doesn't matter here, if we set the values for OFDM it works
141 * on both a and g modes. So all we have to do is set values for all g rates
142 * that include all OFDM and CCK rates. If we operate in turbo or xr/half/
143 * quarter rate mode, we need to use another set of bitrates (that's why we
144 * need the mode parameter) but we don't handle these proprietary modes yet.
146 static inline void ath5k_hw_write_rate_duration(struct ath5k_hw *ah,
149 struct ath5k_softc *sc = ah->ah_sc;
150 struct ieee80211_rate *rate;
153 /* Write rate duration table */
154 for (i = 0; i < sc->sbands[IEEE80211_BAND_2GHZ].n_bitrates; i++) {
158 rate = &sc->sbands[IEEE80211_BAND_2GHZ].bitrates[control_rates[i]];
160 /* Set ACK timeout */
161 reg = AR5K_RATE_DUR(rate->hw_value);
163 /* An ACK frame consists of 10 bytes. If you add the FCS,
164 * which ieee80211_generic_frame_duration() adds,
165 * its 14 bytes. Note we use the control rate and not the
166 * actual rate for this rate. See mac80211 tx.c
167 * ieee80211_duration() for a brief description of
168 * what rate we should choose to TX ACKs. */
169 tx_time = le16_to_cpu(ieee80211_generic_frame_duration(sc->hw,
172 ath5k_hw_reg_write(ah, tx_time, reg);
174 if (!(rate->flags & IEEE80211_RATE_SHORT_PREAMBLE))
178 * We're not distinguishing short preamble here,
179 * This is true, all we'll get is a longer value here
180 * which is not necessarilly bad. We could use
181 * export ieee80211_frame_duration() but that needs to be
182 * fixed first to be properly used by mac802111 drivers:
184 * - remove erp stuff and let the routine figure ofdm
186 * - remove passing argument ieee80211_local as
187 * drivers don't have access to it
188 * - move drivers using ieee80211_generic_frame_duration()
191 ath5k_hw_reg_write(ah, tx_time,
192 reg + (AR5K_SET_SHORT_PREAMBLE << 2));
199 static int ath5k_hw_nic_reset(struct ath5k_hw *ah, u32 val)
202 u32 mask = val ? val : ~0U;
204 ATH5K_TRACE(ah->ah_sc);
206 /* Read-and-clear RX Descriptor Pointer*/
207 ath5k_hw_reg_read(ah, AR5K_RXDP);
210 * Reset the device and wait until success
212 ath5k_hw_reg_write(ah, val, AR5K_RESET_CTL);
214 /* Wait at least 128 PCI clocks */
217 if (ah->ah_version == AR5K_AR5210) {
218 val &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_DMA
219 | AR5K_RESET_CTL_MAC | AR5K_RESET_CTL_PHY;
220 mask &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_DMA
221 | AR5K_RESET_CTL_MAC | AR5K_RESET_CTL_PHY;
223 val &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_BASEBAND;
224 mask &= AR5K_RESET_CTL_PCU | AR5K_RESET_CTL_BASEBAND;
227 ret = ath5k_hw_register_timeout(ah, AR5K_RESET_CTL, mask, val, false);
230 * Reset configuration register (for hw byte-swap). Note that this
231 * is only set for big endian. We do the necessary magic in
234 if ((val & AR5K_RESET_CTL_PCU) == 0)
235 ath5k_hw_reg_write(ah, AR5K_INIT_CFG, AR5K_CFG);
243 static int ath5k_hw_set_power(struct ath5k_hw *ah, enum ath5k_power_mode mode,
244 bool set_chip, u16 sleep_duration)
249 ATH5K_TRACE(ah->ah_sc);
250 staid = ath5k_hw_reg_read(ah, AR5K_STA_ID1);
254 staid &= ~AR5K_STA_ID1_DEFAULT_ANTENNA;
256 case AR5K_PM_NETWORK_SLEEP:
258 ath5k_hw_reg_write(ah,
259 AR5K_SLEEP_CTL_SLE_ALLOW |
263 staid |= AR5K_STA_ID1_PWR_SV;
266 case AR5K_PM_FULL_SLEEP:
268 ath5k_hw_reg_write(ah, AR5K_SLEEP_CTL_SLE_SLP,
271 staid |= AR5K_STA_ID1_PWR_SV;
276 staid &= ~AR5K_STA_ID1_PWR_SV;
281 data = ath5k_hw_reg_read(ah, AR5K_SLEEP_CTL);
283 /* If card is down we 'll get 0xffff... so we
284 * need to clean this up before we write the register
286 if (data & 0xffc00000)
289 /* Preserve sleep duration etc */
290 data = data & ~AR5K_SLEEP_CTL_SLE;
292 ath5k_hw_reg_write(ah, data | AR5K_SLEEP_CTL_SLE_WAKE,
296 for (i = 200; i > 0; i--) {
297 /* Check if the chip did wake up */
298 if ((ath5k_hw_reg_read(ah, AR5K_PCICFG) &
299 AR5K_PCICFG_SPWR_DN) == 0)
302 /* Wait a bit and retry */
304 ath5k_hw_reg_write(ah, data | AR5K_SLEEP_CTL_SLE_WAKE,
308 /* Fail if the chip didn't wake up */
319 ath5k_hw_reg_write(ah, staid, AR5K_STA_ID1);
327 * Put MAC and Baseband on warm reset and
328 * keep that state (don't clean sleep control
329 * register). After this MAC and Baseband are
330 * disabled and a full reset is needed to come
331 * back. This way we save as much power as possible
332 * without puting the card on full sleep.
334 int ath5k_hw_on_hold(struct ath5k_hw *ah)
336 struct pci_dev *pdev = ah->ah_sc->pdev;
340 /* Make sure device is awake */
341 ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
343 ATH5K_ERR(ah->ah_sc, "failed to wakeup the MAC Chip\n");
348 * Put chipset on warm reset...
350 * Note: puting PCI core on warm reset on PCI-E cards
351 * results card to hang and always return 0xffff... so
352 * we ingore that flag for PCI-E cards. On PCI cards
353 * this flag gets cleared after 64 PCI clocks.
355 bus_flags = (pdev->is_pcie) ? 0 : AR5K_RESET_CTL_PCI;
357 if (ah->ah_version == AR5K_AR5210) {
358 ret = ath5k_hw_nic_reset(ah, AR5K_RESET_CTL_PCU |
359 AR5K_RESET_CTL_MAC | AR5K_RESET_CTL_DMA |
360 AR5K_RESET_CTL_PHY | AR5K_RESET_CTL_PCI);
363 ret = ath5k_hw_nic_reset(ah, AR5K_RESET_CTL_PCU |
364 AR5K_RESET_CTL_BASEBAND | bus_flags);
368 ATH5K_ERR(ah->ah_sc, "failed to put device on warm reset\n");
372 /* ...wakeup again!*/
373 ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
375 ATH5K_ERR(ah->ah_sc, "failed to put device on hold\n");
383 * Bring up MAC + PHY Chips and program PLL
384 * TODO: Half/Quarter rate support
386 int ath5k_hw_nic_wakeup(struct ath5k_hw *ah, int flags, bool initial)
388 struct pci_dev *pdev = ah->ah_sc->pdev;
389 u32 turbo, mode, clock, bus_flags;
396 ATH5K_TRACE(ah->ah_sc);
398 /* Wakeup the device */
399 ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
401 ATH5K_ERR(ah->ah_sc, "failed to wakeup the MAC Chip\n");
406 * Put chipset on warm reset...
408 * Note: puting PCI core on warm reset on PCI-E cards
409 * results card to hang and always return 0xffff... so
410 * we ingore that flag for PCI-E cards. On PCI cards
411 * this flag gets cleared after 64 PCI clocks.
413 bus_flags = (pdev->is_pcie) ? 0 : AR5K_RESET_CTL_PCI;
415 if (ah->ah_version == AR5K_AR5210) {
416 ret = ath5k_hw_nic_reset(ah, AR5K_RESET_CTL_PCU |
417 AR5K_RESET_CTL_MAC | AR5K_RESET_CTL_DMA |
418 AR5K_RESET_CTL_PHY | AR5K_RESET_CTL_PCI);
421 ret = ath5k_hw_nic_reset(ah, AR5K_RESET_CTL_PCU |
422 AR5K_RESET_CTL_BASEBAND | bus_flags);
426 ATH5K_ERR(ah->ah_sc, "failed to reset the MAC Chip\n");
430 /* ...wakeup again!...*/
431 ret = ath5k_hw_set_power(ah, AR5K_PM_AWAKE, true, 0);
433 ATH5K_ERR(ah->ah_sc, "failed to resume the MAC Chip\n");
437 /* ...clear reset control register and pull device out of
439 if (ath5k_hw_nic_reset(ah, 0)) {
440 ATH5K_ERR(ah->ah_sc, "failed to warm reset the MAC Chip\n");
444 /* On initialization skip PLL programming since we don't have
445 * a channel / mode set yet */
449 if (ah->ah_version != AR5K_AR5210) {
451 * Get channel mode flags
454 if (ah->ah_radio >= AR5K_RF5112) {
455 mode = AR5K_PHY_MODE_RAD_RF5112;
456 clock = AR5K_PHY_PLL_RF5112;
458 mode = AR5K_PHY_MODE_RAD_RF5111; /*Zero*/
459 clock = AR5K_PHY_PLL_RF5111; /*Zero*/
462 if (flags & CHANNEL_2GHZ) {
463 mode |= AR5K_PHY_MODE_FREQ_2GHZ;
464 clock |= AR5K_PHY_PLL_44MHZ;
466 if (flags & CHANNEL_CCK) {
467 mode |= AR5K_PHY_MODE_MOD_CCK;
468 } else if (flags & CHANNEL_OFDM) {
469 /* XXX Dynamic OFDM/CCK is not supported by the
470 * AR5211 so we set MOD_OFDM for plain g (no
471 * CCK headers) operation. We need to test
472 * this, 5211 might support ofdm-only g after
473 * all, there are also initial register values
474 * in the code for g mode (see initvals.c). */
475 if (ah->ah_version == AR5K_AR5211)
476 mode |= AR5K_PHY_MODE_MOD_OFDM;
478 mode |= AR5K_PHY_MODE_MOD_DYN;
481 "invalid radio modulation mode\n");
484 } else if (flags & CHANNEL_5GHZ) {
485 mode |= AR5K_PHY_MODE_FREQ_5GHZ;
487 if (ah->ah_radio == AR5K_RF5413)
488 clock = AR5K_PHY_PLL_40MHZ_5413;
490 clock |= AR5K_PHY_PLL_40MHZ;
492 if (flags & CHANNEL_OFDM)
493 mode |= AR5K_PHY_MODE_MOD_OFDM;
496 "invalid radio modulation mode\n");
500 ATH5K_ERR(ah->ah_sc, "invalid radio frequency mode\n");
504 if (flags & CHANNEL_TURBO)
505 turbo = AR5K_PHY_TURBO_MODE | AR5K_PHY_TURBO_SHORT;
506 } else { /* Reset the device */
508 /* ...enable Atheros turbo mode if requested */
509 if (flags & CHANNEL_TURBO)
510 ath5k_hw_reg_write(ah, AR5K_PHY_TURBO_MODE,
514 if (ah->ah_version != AR5K_AR5210) {
516 /* ...update PLL if needed */
517 if (ath5k_hw_reg_read(ah, AR5K_PHY_PLL) != clock) {
518 ath5k_hw_reg_write(ah, clock, AR5K_PHY_PLL);
522 /* ...set the PHY operating mode */
523 ath5k_hw_reg_write(ah, mode, AR5K_PHY_MODE);
524 ath5k_hw_reg_write(ah, turbo, AR5K_PHY_TURBO);
531 * If there is an external 32KHz crystal available, use it
532 * as ref. clock instead of 32/40MHz clock and baseband clocks
533 * to save power during sleep or restore normal 32/40MHz
536 * XXX: When operating on 32KHz certain PHY registers (27 - 31,
537 * 123 - 127) require delay on access.
539 static void ath5k_hw_set_sleep_clock(struct ath5k_hw *ah, bool enable)
541 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
542 u32 scal, spending, usec32;
544 /* Only set 32KHz settings if we have an external
545 * 32KHz crystal present */
546 if ((AR5K_EEPROM_HAS32KHZCRYSTAL(ee->ee_misc1) ||
547 AR5K_EEPROM_HAS32KHZCRYSTAL_OLD(ee->ee_misc1)) &&
551 AR5K_REG_WRITE_BITS(ah, AR5K_USEC_5211, AR5K_USEC_32, 1);
552 /* Set up tsf increment on each cycle */
553 AR5K_REG_WRITE_BITS(ah, AR5K_TSF_PARM, AR5K_TSF_PARM_INC, 61);
555 /* Set baseband sleep control registers
556 * and sleep control rate */
557 ath5k_hw_reg_write(ah, 0x1f, AR5K_PHY_SCR);
559 if ((ah->ah_radio == AR5K_RF5112) ||
560 (ah->ah_radio == AR5K_RF5413) ||
561 (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4)))
565 ath5k_hw_reg_write(ah, spending, AR5K_PHY_SPENDING);
567 if ((ah->ah_radio == AR5K_RF5112) ||
568 (ah->ah_radio == AR5K_RF5413) ||
569 (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4))) {
570 ath5k_hw_reg_write(ah, 0x26, AR5K_PHY_SLMT);
571 ath5k_hw_reg_write(ah, 0x0d, AR5K_PHY_SCAL);
572 ath5k_hw_reg_write(ah, 0x07, AR5K_PHY_SCLOCK);
573 ath5k_hw_reg_write(ah, 0x3f, AR5K_PHY_SDELAY);
574 AR5K_REG_WRITE_BITS(ah, AR5K_PCICFG,
575 AR5K_PCICFG_SLEEP_CLOCK_RATE, 0x02);
577 ath5k_hw_reg_write(ah, 0x0a, AR5K_PHY_SLMT);
578 ath5k_hw_reg_write(ah, 0x0c, AR5K_PHY_SCAL);
579 ath5k_hw_reg_write(ah, 0x03, AR5K_PHY_SCLOCK);
580 ath5k_hw_reg_write(ah, 0x20, AR5K_PHY_SDELAY);
581 AR5K_REG_WRITE_BITS(ah, AR5K_PCICFG,
582 AR5K_PCICFG_SLEEP_CLOCK_RATE, 0x03);
585 /* Enable sleep clock operation */
586 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG,
587 AR5K_PCICFG_SLEEP_CLOCK_EN);
591 /* Disable sleep clock operation and
592 * restore default parameters */
593 AR5K_REG_DISABLE_BITS(ah, AR5K_PCICFG,
594 AR5K_PCICFG_SLEEP_CLOCK_EN);
596 AR5K_REG_WRITE_BITS(ah, AR5K_PCICFG,
597 AR5K_PCICFG_SLEEP_CLOCK_RATE, 0);
599 ath5k_hw_reg_write(ah, 0x1f, AR5K_PHY_SCR);
600 ath5k_hw_reg_write(ah, AR5K_PHY_SLMT_32MHZ, AR5K_PHY_SLMT);
602 if (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4))
603 scal = AR5K_PHY_SCAL_32MHZ_2417;
604 else if (ee->ee_is_hb63)
605 scal = AR5K_PHY_SCAL_32MHZ_HB63;
607 scal = AR5K_PHY_SCAL_32MHZ;
608 ath5k_hw_reg_write(ah, scal, AR5K_PHY_SCAL);
610 ath5k_hw_reg_write(ah, AR5K_PHY_SCLOCK_32MHZ, AR5K_PHY_SCLOCK);
611 ath5k_hw_reg_write(ah, AR5K_PHY_SDELAY_32MHZ, AR5K_PHY_SDELAY);
613 if ((ah->ah_radio == AR5K_RF5112) ||
614 (ah->ah_radio == AR5K_RF5413) ||
615 (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4)))
619 ath5k_hw_reg_write(ah, spending, AR5K_PHY_SPENDING);
621 if ((ah->ah_radio == AR5K_RF5112) ||
622 (ah->ah_radio == AR5K_RF5413))
626 AR5K_REG_WRITE_BITS(ah, AR5K_USEC_5211, AR5K_USEC_32, usec32);
628 AR5K_REG_WRITE_BITS(ah, AR5K_TSF_PARM, AR5K_TSF_PARM_INC, 1);
633 /* TODO: Half/Quarter rate */
634 static void ath5k_hw_tweak_initval_settings(struct ath5k_hw *ah,
635 struct ieee80211_channel *channel)
637 if (ah->ah_version == AR5K_AR5212 &&
638 ah->ah_phy_revision >= AR5K_SREV_PHY_5212A) {
640 /* Setup ADC control */
641 ath5k_hw_reg_write(ah,
643 AR5K_PHY_ADC_CTL_INBUFGAIN_OFF) |
645 AR5K_PHY_ADC_CTL_INBUFGAIN_ON) |
646 AR5K_PHY_ADC_CTL_PWD_DAC_OFF |
647 AR5K_PHY_ADC_CTL_PWD_ADC_OFF),
652 /* Disable barker RSSI threshold */
653 AR5K_REG_DISABLE_BITS(ah, AR5K_PHY_DAG_CCK_CTL,
654 AR5K_PHY_DAG_CCK_CTL_EN_RSSI_THR);
656 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_DAG_CCK_CTL,
657 AR5K_PHY_DAG_CCK_CTL_RSSI_THR, 2);
659 /* Set the mute mask */
660 ath5k_hw_reg_write(ah, 0x0000000f, AR5K_SEQ_MASK);
663 /* Clear PHY_BLUETOOTH to allow RX_CLEAR line debug */
664 if (ah->ah_phy_revision >= AR5K_SREV_PHY_5212B)
665 ath5k_hw_reg_write(ah, 0, AR5K_PHY_BLUETOOTH);
667 /* Enable DCU double buffering */
668 if (ah->ah_phy_revision > AR5K_SREV_PHY_5212B)
669 AR5K_REG_DISABLE_BITS(ah, AR5K_TXCFG,
670 AR5K_TXCFG_DCU_DBL_BUF_DIS);
672 /* Set DAC/ADC delays */
673 if (ah->ah_version == AR5K_AR5212) {
675 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
676 if (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4))
677 scal = AR5K_PHY_SCAL_32MHZ_2417;
678 else if (ee->ee_is_hb63)
679 scal = AR5K_PHY_SCAL_32MHZ_HB63;
681 scal = AR5K_PHY_SCAL_32MHZ;
682 ath5k_hw_reg_write(ah, scal, AR5K_PHY_SCAL);
686 if ((ah->ah_radio == AR5K_RF5413) ||
687 (ah->ah_mac_version == (AR5K_SREV_AR2417 >> 4))) {
690 if (channel->center_freq == 2462 ||
691 channel->center_freq == 2467)
694 /* Only update if needed */
695 if (ath5k_hw_reg_read(ah, AR5K_PHY_FAST_ADC) != fast_adc)
696 ath5k_hw_reg_write(ah, fast_adc,
700 /* Fix for first revision of the RF5112 RF chipset */
701 if (ah->ah_radio == AR5K_RF5112 &&
702 ah->ah_radio_5ghz_revision <
703 AR5K_SREV_RAD_5112A) {
705 ath5k_hw_reg_write(ah, AR5K_PHY_CCKTXCTL_WORLD,
707 if (channel->hw_value & CHANNEL_5GHZ)
711 ath5k_hw_reg_write(ah, data, AR5K_PHY_FRAME_CTL);
714 if (ah->ah_mac_srev < AR5K_SREV_AR5211) {
716 /* 5311 has different tx/rx latency masks
717 * from 5211, since we deal 5311 the same
718 * as 5211 when setting initvals, shift
719 * values here to their proper locations */
720 usec_reg = ath5k_hw_reg_read(ah, AR5K_USEC_5211);
721 ath5k_hw_reg_write(ah, usec_reg & (AR5K_USEC_1 |
723 AR5K_USEC_TX_LATENCY_5211 |
725 AR5K_USEC_RX_LATENCY_5210)),
727 /* Clear QCU/DCU clock gating register */
728 ath5k_hw_reg_write(ah, 0, AR5K_QCUDCU_CLKGT);
729 /* Set DAC/ADC delays */
730 ath5k_hw_reg_write(ah, 0x08, AR5K_PHY_SCAL);
731 /* Enable PCU FIFO corruption ECO */
732 AR5K_REG_ENABLE_BITS(ah, AR5K_DIAG_SW_5211,
733 AR5K_DIAG_SW_ECO_ENABLE);
737 static void ath5k_hw_commit_eeprom_settings(struct ath5k_hw *ah,
738 struct ieee80211_channel *channel, u8 *ant, u8 ee_mode)
740 struct ath5k_eeprom_info *ee = &ah->ah_capabilities.cap_eeprom;
741 s16 cck_ofdm_pwr_delta;
743 /* Adjust power delta for channel 14 */
744 if (channel->center_freq == 2484)
746 ((ee->ee_cck_ofdm_power_delta -
747 ee->ee_scaled_cck_delta) * 2) / 10;
750 (ee->ee_cck_ofdm_power_delta * 2) / 10;
752 /* Set CCK to OFDM power delta on tx power
753 * adjustment register */
754 if (ah->ah_phy_revision >= AR5K_SREV_PHY_5212A) {
755 if (channel->hw_value == CHANNEL_G)
756 ath5k_hw_reg_write(ah,
757 AR5K_REG_SM((ee->ee_cck_ofdm_gain_delta * -1),
758 AR5K_PHY_TX_PWR_ADJ_CCK_GAIN_DELTA) |
759 AR5K_REG_SM((cck_ofdm_pwr_delta * -1),
760 AR5K_PHY_TX_PWR_ADJ_CCK_PCDAC_INDEX),
761 AR5K_PHY_TX_PWR_ADJ);
763 ath5k_hw_reg_write(ah, 0, AR5K_PHY_TX_PWR_ADJ);
765 /* For older revs we scale power on sw during tx power
767 ah->ah_txpower.txp_cck_ofdm_pwr_delta = cck_ofdm_pwr_delta;
768 ah->ah_txpower.txp_cck_ofdm_gainf_delta =
769 ee->ee_cck_ofdm_gain_delta;
772 /* Set antenna idle switch table */
773 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_ANT_CTL,
774 AR5K_PHY_ANT_CTL_SWTABLE_IDLE,
775 (ah->ah_ant_ctl[ee_mode][0] |
776 AR5K_PHY_ANT_CTL_TXRX_EN));
778 /* Set antenna switch tables */
779 ath5k_hw_reg_write(ah, ah->ah_ant_ctl[ee_mode][ant[0]],
780 AR5K_PHY_ANT_SWITCH_TABLE_0);
781 ath5k_hw_reg_write(ah, ah->ah_ant_ctl[ee_mode][ant[1]],
782 AR5K_PHY_ANT_SWITCH_TABLE_1);
784 /* Noise floor threshold */
785 ath5k_hw_reg_write(ah,
786 AR5K_PHY_NF_SVAL(ee->ee_noise_floor_thr[ee_mode]),
789 if ((channel->hw_value & CHANNEL_TURBO) &&
790 (ah->ah_ee_version >= AR5K_EEPROM_VERSION_5_0)) {
791 /* Switch settling time (Turbo) */
792 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_SETTLING,
793 AR5K_PHY_SETTLING_SWITCH,
794 ee->ee_switch_settling_turbo[ee_mode]);
796 /* Tx/Rx attenuation (Turbo) */
797 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN,
798 AR5K_PHY_GAIN_TXRX_ATTEN,
799 ee->ee_atn_tx_rx_turbo[ee_mode]);
801 /* ADC/PGA desired size (Turbo) */
802 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_DESIRED_SIZE,
803 AR5K_PHY_DESIRED_SIZE_ADC,
804 ee->ee_adc_desired_size_turbo[ee_mode]);
806 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_DESIRED_SIZE,
807 AR5K_PHY_DESIRED_SIZE_PGA,
808 ee->ee_pga_desired_size_turbo[ee_mode]);
810 /* Tx/Rx margin (Turbo) */
811 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN_2GHZ,
812 AR5K_PHY_GAIN_2GHZ_MARGIN_TXRX,
813 ee->ee_margin_tx_rx_turbo[ee_mode]);
816 /* Switch settling time */
817 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_SETTLING,
818 AR5K_PHY_SETTLING_SWITCH,
819 ee->ee_switch_settling[ee_mode]);
821 /* Tx/Rx attenuation */
822 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN,
823 AR5K_PHY_GAIN_TXRX_ATTEN,
824 ee->ee_atn_tx_rx[ee_mode]);
826 /* ADC/PGA desired size */
827 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_DESIRED_SIZE,
828 AR5K_PHY_DESIRED_SIZE_ADC,
829 ee->ee_adc_desired_size[ee_mode]);
831 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_DESIRED_SIZE,
832 AR5K_PHY_DESIRED_SIZE_PGA,
833 ee->ee_pga_desired_size[ee_mode]);
836 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_1)
837 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_GAIN_2GHZ,
838 AR5K_PHY_GAIN_2GHZ_MARGIN_TXRX,
839 ee->ee_margin_tx_rx[ee_mode]);
843 ath5k_hw_reg_write(ah,
844 (ee->ee_tx_end2xpa_disable[ee_mode] << 24) |
845 (ee->ee_tx_end2xpa_disable[ee_mode] << 16) |
846 (ee->ee_tx_frm2xpa_enable[ee_mode] << 8) |
847 (ee->ee_tx_frm2xpa_enable[ee_mode]), AR5K_PHY_RF_CTL4);
850 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_RF_CTL3,
851 AR5K_PHY_RF_CTL3_TXE2XLNA_ON,
852 ee->ee_tx_end2xlna_enable[ee_mode]);
855 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_NF,
856 AR5K_PHY_NF_THRESH62,
857 ee->ee_thr_62[ee_mode]);
860 /* False detect backoff for channels
861 * that have spur noise. Write the new
862 * cyclic power RSSI threshold. */
863 if (ath5k_hw_chan_has_spur_noise(ah, channel))
864 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_OFDM_SELFCORR,
865 AR5K_PHY_OFDM_SELFCORR_CYPWR_THR1,
866 AR5K_INIT_CYCRSSI_THR1 +
867 ee->ee_false_detect[ee_mode]);
869 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_OFDM_SELFCORR,
870 AR5K_PHY_OFDM_SELFCORR_CYPWR_THR1,
871 AR5K_INIT_CYCRSSI_THR1);
873 /* I/Q correction (set enable bit last to match HAL sources) */
874 /* TODO: Per channel i/q infos ? */
875 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_4_0) {
876 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_IQ, AR5K_PHY_IQ_CORR_Q_I_COFF,
877 ee->ee_i_cal[ee_mode]);
878 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_IQ, AR5K_PHY_IQ_CORR_Q_Q_COFF,
879 ee->ee_q_cal[ee_mode]);
880 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ, AR5K_PHY_IQ_CORR_ENABLE);
883 /* Heavy clipping -disable for now */
884 if (ah->ah_ee_version >= AR5K_EEPROM_VERSION_5_1)
885 ath5k_hw_reg_write(ah, 0, AR5K_PHY_HEAVY_CLIP_ENABLE);
891 * Main reset function
893 int ath5k_hw_reset(struct ath5k_hw *ah, enum nl80211_iftype op_mode,
894 struct ieee80211_channel *channel, bool change_channel)
896 struct ath_common *common = ath5k_hw_common(ah);
897 u32 s_seq[10], s_ant, s_led[3], staid1_flags, tsf_up, tsf_lo;
899 u8 mode, freq, ee_mode, ant[2];
902 ATH5K_TRACE(ah->ah_sc);
913 * Save some registers before a reset
915 /*DCU/Antenna selection not available on 5210*/
916 if (ah->ah_version != AR5K_AR5210) {
918 switch (channel->hw_value & CHANNEL_MODES) {
920 mode = AR5K_MODE_11A;
921 freq = AR5K_INI_RFGAIN_5GHZ;
922 ee_mode = AR5K_EEPROM_MODE_11A;
925 mode = AR5K_MODE_11G;
926 freq = AR5K_INI_RFGAIN_2GHZ;
927 ee_mode = AR5K_EEPROM_MODE_11G;
930 mode = AR5K_MODE_11B;
931 freq = AR5K_INI_RFGAIN_2GHZ;
932 ee_mode = AR5K_EEPROM_MODE_11B;
935 mode = AR5K_MODE_11A_TURBO;
936 freq = AR5K_INI_RFGAIN_5GHZ;
937 ee_mode = AR5K_EEPROM_MODE_11A;
940 if (ah->ah_version == AR5K_AR5211) {
942 "TurboG mode not available on 5211");
945 mode = AR5K_MODE_11G_TURBO;
946 freq = AR5K_INI_RFGAIN_2GHZ;
947 ee_mode = AR5K_EEPROM_MODE_11G;
950 if (ah->ah_version == AR5K_AR5211) {
952 "XR mode not available on 5211");
956 freq = AR5K_INI_RFGAIN_5GHZ;
957 ee_mode = AR5K_EEPROM_MODE_11A;
961 "invalid channel: %d\n", channel->center_freq);
965 if (change_channel) {
967 * Save frame sequence count
968 * For revs. after Oahu, only save
969 * seq num for DCU 0 (Global seq num)
971 if (ah->ah_mac_srev < AR5K_SREV_AR5211) {
973 for (i = 0; i < 10; i++)
974 s_seq[i] = ath5k_hw_reg_read(ah,
975 AR5K_QUEUE_DCU_SEQNUM(i));
978 s_seq[0] = ath5k_hw_reg_read(ah,
979 AR5K_QUEUE_DCU_SEQNUM(0));
982 /* TSF accelerates on AR5211 durring reset
983 * As a workaround save it here and restore
984 * it later so that it's back in time after
985 * reset. This way it'll get re-synced on the
986 * next beacon without breaking ad-hoc.
988 * On AR5212 TSF is almost preserved across a
989 * reset so it stays back in time anyway and
990 * we don't have to save/restore it.
992 * XXX: Since this breaks power saving we have
993 * to disable power saving until we receive the
994 * next beacon, so we can resync beacon timers */
995 if (ah->ah_version == AR5K_AR5211) {
996 tsf_up = ath5k_hw_reg_read(ah, AR5K_TSF_U32);
997 tsf_lo = ath5k_hw_reg_read(ah, AR5K_TSF_L32);
1001 /* Save default antenna */
1002 s_ant = ath5k_hw_reg_read(ah, AR5K_DEFAULT_ANTENNA);
1004 if (ah->ah_version == AR5K_AR5212) {
1005 /* Restore normal 32/40MHz clock operation
1006 * to avoid register access delay on certain
1008 ath5k_hw_set_sleep_clock(ah, false);
1010 /* Since we are going to write rf buffer
1011 * check if we have any pending gain_F
1012 * optimization settings */
1013 if (change_channel && ah->ah_rf_banks != NULL)
1014 ath5k_hw_gainf_calibrate(ah);
1019 s_led[0] = ath5k_hw_reg_read(ah, AR5K_PCICFG) &
1020 AR5K_PCICFG_LEDSTATE;
1021 s_led[1] = ath5k_hw_reg_read(ah, AR5K_GPIOCR);
1022 s_led[2] = ath5k_hw_reg_read(ah, AR5K_GPIODO);
1024 /* AR5K_STA_ID1 flags, only preserve antenna
1025 * settings and ack/cts rate mode */
1026 staid1_flags = ath5k_hw_reg_read(ah, AR5K_STA_ID1) &
1027 (AR5K_STA_ID1_DEFAULT_ANTENNA |
1028 AR5K_STA_ID1_DESC_ANTENNA |
1029 AR5K_STA_ID1_RTS_DEF_ANTENNA |
1030 AR5K_STA_ID1_ACKCTS_6MB |
1031 AR5K_STA_ID1_BASE_RATE_11B |
1032 AR5K_STA_ID1_SELFGEN_DEF_ANT);
1034 /* Wakeup the device */
1035 ret = ath5k_hw_nic_wakeup(ah, channel->hw_value, false);
1039 /* PHY access enable */
1040 if (ah->ah_mac_srev >= AR5K_SREV_AR5211)
1041 ath5k_hw_reg_write(ah, AR5K_PHY_SHIFT_5GHZ, AR5K_PHY(0));
1043 ath5k_hw_reg_write(ah, AR5K_PHY_SHIFT_5GHZ | 0x40,
1046 /* Write initial settings */
1047 ret = ath5k_hw_write_initvals(ah, mode, change_channel);
1052 * 5211/5212 Specific
1054 if (ah->ah_version != AR5K_AR5210) {
1057 * Write initial RF gain settings
1058 * This should work for both 5111/5112
1060 ret = ath5k_hw_rfgain_init(ah, freq);
1067 * Tweak initval settings for revised
1068 * chipsets and add some more config
1071 ath5k_hw_tweak_initval_settings(ah, channel);
1076 ret = ath5k_hw_txpower(ah, channel, ee_mode,
1077 ah->ah_txpower.txp_max_pwr / 2);
1081 /* Write rate duration table only on AR5212 and if
1082 * virtual interface has already been brought up
1083 * XXX: rethink this after new mode changes to
1084 * mac80211 are integrated */
1085 if (ah->ah_version == AR5K_AR5212 &&
1086 ah->ah_sc->vif != NULL)
1087 ath5k_hw_write_rate_duration(ah, mode);
1092 ret = ath5k_hw_rfregs_init(ah, channel, mode);
1097 /* Write OFDM timings on 5212*/
1098 if (ah->ah_version == AR5K_AR5212 &&
1099 channel->hw_value & CHANNEL_OFDM) {
1100 struct ath5k_eeprom_info *ee =
1101 &ah->ah_capabilities.cap_eeprom;
1103 ret = ath5k_hw_write_ofdm_timings(ah, channel);
1107 /* Note: According to docs we can have a newer
1108 * EEPROM on old hardware, so we need to verify
1109 * that our hardware is new enough to have spur
1110 * mitigation registers (delta phase etc) */
1111 if (ah->ah_mac_srev >= AR5K_SREV_AR5424 ||
1112 (ah->ah_mac_srev >= AR5K_SREV_AR5424 &&
1113 ee->ee_version >= AR5K_EEPROM_VERSION_5_3))
1114 ath5k_hw_set_spur_mitigation_filter(ah,
1118 /*Enable/disable 802.11b mode on 5111
1119 (enable 2111 frequency converter + CCK)*/
1120 if (ah->ah_radio == AR5K_RF5111) {
1121 if (mode == AR5K_MODE_11B)
1122 AR5K_REG_ENABLE_BITS(ah, AR5K_TXCFG,
1125 AR5K_REG_DISABLE_BITS(ah, AR5K_TXCFG,
1130 * In case a fixed antenna was set as default
1131 * use the same switch table twice.
1133 if (ah->ah_ant_mode == AR5K_ANTMODE_FIXED_A)
1134 ant[0] = ant[1] = AR5K_ANT_SWTABLE_A;
1135 else if (ah->ah_ant_mode == AR5K_ANTMODE_FIXED_B)
1136 ant[0] = ant[1] = AR5K_ANT_SWTABLE_B;
1138 ant[0] = AR5K_ANT_SWTABLE_A;
1139 ant[1] = AR5K_ANT_SWTABLE_B;
1142 /* Commit values from EEPROM */
1143 ath5k_hw_commit_eeprom_settings(ah, channel, ant, ee_mode);
1147 * For 5210 we do all initialization using
1148 * initvals, so we don't have to modify
1149 * any settings (5210 also only supports
1153 /* Disable phy and wait */
1154 ath5k_hw_reg_write(ah, AR5K_PHY_ACT_DISABLE, AR5K_PHY_ACT);
1159 * Restore saved values
1162 /*DCU/Antenna selection not available on 5210*/
1163 if (ah->ah_version != AR5K_AR5210) {
1165 if (change_channel) {
1166 if (ah->ah_mac_srev < AR5K_SREV_AR5211) {
1167 for (i = 0; i < 10; i++)
1168 ath5k_hw_reg_write(ah, s_seq[i],
1169 AR5K_QUEUE_DCU_SEQNUM(i));
1171 ath5k_hw_reg_write(ah, s_seq[0],
1172 AR5K_QUEUE_DCU_SEQNUM(0));
1176 if (ah->ah_version == AR5K_AR5211) {
1177 ath5k_hw_reg_write(ah, tsf_up, AR5K_TSF_U32);
1178 ath5k_hw_reg_write(ah, tsf_lo, AR5K_TSF_L32);
1182 ath5k_hw_reg_write(ah, s_ant, AR5K_DEFAULT_ANTENNA);
1186 AR5K_REG_ENABLE_BITS(ah, AR5K_PCICFG, s_led[0]);
1189 ath5k_hw_reg_write(ah, s_led[1], AR5K_GPIOCR);
1190 ath5k_hw_reg_write(ah, s_led[2], AR5K_GPIODO);
1192 /* Restore sta_id flags and preserve our mac address*/
1193 ath5k_hw_reg_write(ah,
1194 get_unaligned_le32(common->macaddr),
1196 ath5k_hw_reg_write(ah,
1197 staid1_flags | get_unaligned_le16(common->macaddr + 4),
1205 /* Restore bssid and bssid mask */
1206 ath5k_hw_set_associd(ah);
1208 /* Set PCU config */
1209 ath5k_hw_set_opmode(ah, op_mode);
1211 /* Clear any pending interrupts
1212 * PISR/SISR Not available on 5210 */
1213 if (ah->ah_version != AR5K_AR5210)
1214 ath5k_hw_reg_write(ah, 0xffffffff, AR5K_PISR);
1216 /* Set RSSI/BRSSI thresholds
1218 * Note: If we decide to set this value
1219 * dynamicaly, have in mind that when AR5K_RSSI_THR
1220 * register is read it might return 0x40 if we haven't
1221 * wrote anything to it plus BMISS RSSI threshold is zeroed.
1222 * So doing a save/restore procedure here isn't the right
1223 * choice. Instead store it on ath5k_hw */
1224 ath5k_hw_reg_write(ah, (AR5K_TUNE_RSSI_THRES |
1225 AR5K_TUNE_BMISS_THRES <<
1226 AR5K_RSSI_THR_BMISS_S),
1229 /* MIC QoS support */
1230 if (ah->ah_mac_srev >= AR5K_SREV_AR2413) {
1231 ath5k_hw_reg_write(ah, 0x000100aa, AR5K_MIC_QOS_CTL);
1232 ath5k_hw_reg_write(ah, 0x00003210, AR5K_MIC_QOS_SEL);
1235 /* QoS NOACK Policy */
1236 if (ah->ah_version == AR5K_AR5212) {
1237 ath5k_hw_reg_write(ah,
1238 AR5K_REG_SM(2, AR5K_QOS_NOACK_2BIT_VALUES) |
1239 AR5K_REG_SM(5, AR5K_QOS_NOACK_BIT_OFFSET) |
1240 AR5K_REG_SM(0, AR5K_QOS_NOACK_BYTE_OFFSET),
1249 /* Set channel on PHY */
1250 ret = ath5k_hw_channel(ah, channel);
1255 * Enable the PHY and wait until completion
1256 * This includes BaseBand and Synthesizer
1259 ath5k_hw_reg_write(ah, AR5K_PHY_ACT_ENABLE, AR5K_PHY_ACT);
1262 * On 5211+ read activation -> rx delay
1265 * TODO: Half/quarter rate support
1267 if (ah->ah_version != AR5K_AR5210) {
1269 delay = ath5k_hw_reg_read(ah, AR5K_PHY_RX_DELAY) &
1270 AR5K_PHY_RX_DELAY_M;
1271 delay = (channel->hw_value & CHANNEL_CCK) ?
1272 ((delay << 2) / 22) : (delay / 10);
1274 udelay(100 + (2 * delay));
1280 * Perform ADC test to see if baseband is ready
1281 * Set tx hold and check adc test register
1283 phy_tst1 = ath5k_hw_reg_read(ah, AR5K_PHY_TST1);
1284 ath5k_hw_reg_write(ah, AR5K_PHY_TST1_TXHOLD, AR5K_PHY_TST1);
1285 for (i = 0; i <= 20; i++) {
1286 if (!(ath5k_hw_reg_read(ah, AR5K_PHY_ADC_TEST) & 0x10))
1290 ath5k_hw_reg_write(ah, phy_tst1, AR5K_PHY_TST1);
1293 * Start automatic gain control calibration
1295 * During AGC calibration RX path is re-routed to
1296 * a power detector so we don't receive anything.
1298 * This method is used to calibrate some static offsets
1299 * used together with on-the fly I/Q calibration (the
1300 * one performed via ath5k_hw_phy_calibrate), that doesn't
1301 * interrupt rx path.
1303 * While rx path is re-routed to the power detector we also
1304 * start a noise floor calibration, to measure the
1305 * card's noise floor (the noise we measure when we are not
1306 * transmiting or receiving anything).
1308 * If we are in a noisy environment AGC calibration may time
1309 * out and/or noise floor calibration might timeout.
1311 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_AGCCTL,
1312 AR5K_PHY_AGCCTL_CAL | AR5K_PHY_AGCCTL_NF);
1314 /* At the same time start I/Q calibration for QAM constellation
1315 * -no need for CCK- */
1316 ah->ah_calibration = false;
1317 if (!(mode == AR5K_MODE_11B)) {
1318 ah->ah_calibration = true;
1319 AR5K_REG_WRITE_BITS(ah, AR5K_PHY_IQ,
1320 AR5K_PHY_IQ_CAL_NUM_LOG_MAX, 15);
1321 AR5K_REG_ENABLE_BITS(ah, AR5K_PHY_IQ,
1325 /* Wait for gain calibration to finish (we check for I/Q calibration
1326 * during ath5k_phy_calibrate) */
1327 if (ath5k_hw_register_timeout(ah, AR5K_PHY_AGCCTL,
1328 AR5K_PHY_AGCCTL_CAL, 0, false)) {
1329 ATH5K_ERR(ah->ah_sc, "gain calibration timeout (%uMHz)\n",
1330 channel->center_freq);
1333 /* Restore antenna mode */
1334 ath5k_hw_set_antenna_mode(ah, ah->ah_ant_mode);
1336 /* Restore slot time and ACK timeouts */
1337 if (ah->ah_coverage_class > 0)
1338 ath5k_hw_set_coverage_class(ah, ah->ah_coverage_class);
1341 * Configure QCUs/DCUs
1344 /* TODO: HW Compression support for data queues */
1345 /* TODO: Burst prefetch for data queues */
1348 * Reset queues and start beacon timers at the end of the reset routine
1349 * This also sets QCU mask on each DCU for 1:1 qcu to dcu mapping
1350 * Note: If we want we can assign multiple qcus on one dcu.
1352 for (i = 0; i < ah->ah_capabilities.cap_queues.q_tx_num; i++) {
1353 ret = ath5k_hw_reset_tx_queue(ah, i);
1355 ATH5K_ERR(ah->ah_sc,
1356 "failed to reset TX queue #%d\n", i);
1363 * Configure DMA/Interrupts
1367 * Set Rx/Tx DMA Configuration
1369 * Set standard DMA size (128). Note that
1370 * a DMA size of 512 causes rx overruns and tx errors
1371 * on pci-e cards (tested on 5424 but since rx overruns
1372 * also occur on 5416/5418 with madwifi we set 128
1373 * for all PCI-E cards to be safe).
1375 * XXX: need to check 5210 for this
1376 * TODO: Check out tx triger level, it's always 64 on dumps but I
1377 * guess we can tweak it and see how it goes ;-)
1379 if (ah->ah_version != AR5K_AR5210) {
1380 AR5K_REG_WRITE_BITS(ah, AR5K_TXCFG,
1381 AR5K_TXCFG_SDMAMR, AR5K_DMASIZE_128B);
1382 AR5K_REG_WRITE_BITS(ah, AR5K_RXCFG,
1383 AR5K_RXCFG_SDMAMW, AR5K_DMASIZE_128B);
1386 /* Pre-enable interrupts on 5211/5212*/
1387 if (ah->ah_version != AR5K_AR5210)
1388 ath5k_hw_set_imr(ah, ah->ah_imr);
1390 /* Enable 32KHz clock function for AR5212+ chips
1391 * Set clocks to 32KHz operation and use an
1392 * external 32KHz crystal when sleeping if one
1394 if (ah->ah_version == AR5K_AR5212 &&
1395 op_mode != NL80211_IFTYPE_AP)
1396 ath5k_hw_set_sleep_clock(ah, true);
1399 * Disable beacons and reset the TSF
1401 AR5K_REG_DISABLE_BITS(ah, AR5K_BEACON, AR5K_BEACON_ENABLE);
1402 ath5k_hw_reset_tsf(ah);