ath9k: Enable dynamic power save in ath9k.
[pandora-kernel.git] / drivers / net / wireless / ath9k / hw.c
index 82c2a42..ab15e55 100644 (file)
 #include "phy.h"
 #include "initvals.h"
 
-static const u8 CLOCK_RATE[] = { 40, 80, 22, 44, 88, 40 };
+static int btcoex_enable;
+module_param(btcoex_enable, bool, 0);
+MODULE_PARM_DESC(btcoex_enable, "Enable Bluetooth coexistence support");
 
-extern struct hal_percal_data iq_cal_multi_sample;
-extern struct hal_percal_data iq_cal_single_sample;
-extern struct hal_percal_data adc_gain_cal_multi_sample;
-extern struct hal_percal_data adc_gain_cal_single_sample;
-extern struct hal_percal_data adc_dc_cal_multi_sample;
-extern struct hal_percal_data adc_dc_cal_single_sample;
-extern struct hal_percal_data adc_init_dc_cal;
+#define ATH9K_CLOCK_RATE_CCK           22
+#define ATH9K_CLOCK_RATE_5GHZ_OFDM     40
+#define ATH9K_CLOCK_RATE_2GHZ_OFDM     44
 
 static bool ath9k_hw_set_reset_reg(struct ath_hal *ah, u32 type);
 static void ath9k_hw_set_regs(struct ath_hal *ah, struct ath9k_channel *chan,
                              enum ath9k_ht_macmode macmode);
 static u32 ath9k_hw_ini_fixup(struct ath_hal *ah,
-                             struct ar5416_eeprom *pEepData,
+                             struct ar5416_eeprom_def *pEepData,
                              u32 reg, u32 value);
 static void ath9k_hw_9280_spur_mitigate(struct ath_hal *ah, struct ath9k_channel *chan);
 static void ath9k_hw_spur_mitigate(struct ath_hal *ah, struct ath9k_channel *chan);
@@ -48,17 +46,18 @@ static void ath9k_hw_spur_mitigate(struct ath_hal *ah, struct ath9k_channel *cha
 
 static u32 ath9k_hw_mac_usec(struct ath_hal *ah, u32 clks)
 {
-       if (ah->ah_curchan != NULL)
-               return clks / CLOCK_RATE[ath9k_hw_chan2wmode(ah, ah->ah_curchan)];
-       else
-               return clks / CLOCK_RATE[ATH9K_MODE_11B];
+       struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
+       if (!ah->ah_curchan) /* should really check for CCK instead */
+               return clks / ATH9K_CLOCK_RATE_CCK;
+       if (conf->channel->band == IEEE80211_BAND_2GHZ)
+               return clks / ATH9K_CLOCK_RATE_2GHZ_OFDM;
+       return clks / ATH9K_CLOCK_RATE_5GHZ_OFDM;
 }
 
 static u32 ath9k_hw_mac_to_usec(struct ath_hal *ah, u32 clks)
 {
-       struct ath9k_channel *chan = ah->ah_curchan;
-
-       if (chan && IS_CHAN_HT40(chan))
+       struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
+       if (conf_is_ht40(conf))
                return ath9k_hw_mac_usec(ah, clks) / 2;
        else
                return ath9k_hw_mac_usec(ah, clks);
@@ -66,33 +65,23 @@ static u32 ath9k_hw_mac_to_usec(struct ath_hal *ah, u32 clks)
 
 static u32 ath9k_hw_mac_clks(struct ath_hal *ah, u32 usecs)
 {
-       if (ah->ah_curchan != NULL)
-               return usecs * CLOCK_RATE[ath9k_hw_chan2wmode(ah,
-                       ah->ah_curchan)];
-       else
-               return usecs * CLOCK_RATE[ATH9K_MODE_11B];
+       struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
+       if (!ah->ah_curchan) /* should really check for CCK instead */
+               return usecs *ATH9K_CLOCK_RATE_CCK;
+       if (conf->channel->band == IEEE80211_BAND_2GHZ)
+               return usecs *ATH9K_CLOCK_RATE_2GHZ_OFDM;
+       return usecs *ATH9K_CLOCK_RATE_5GHZ_OFDM;
 }
 
 static u32 ath9k_hw_mac_to_clks(struct ath_hal *ah, u32 usecs)
 {
-       struct ath9k_channel *chan = ah->ah_curchan;
-
-       if (chan && IS_CHAN_HT40(chan))
+       struct ieee80211_conf *conf = &ah->ah_sc->hw->conf;
+       if (conf_is_ht40(conf))
                return ath9k_hw_mac_clks(ah, usecs) * 2;
        else
                return ath9k_hw_mac_clks(ah, usecs);
 }
 
-enum wireless_mode ath9k_hw_chan2wmode(struct ath_hal *ah,
-                              const struct ath9k_channel *chan)
-{
-       if (IS_CHAN_CCK(chan))
-               return ATH9K_MODE_11A;
-       if (IS_CHAN_G(chan))
-               return ATH9K_MODE_11G;
-       return ATH9K_MODE_11A;
-}
-
 bool ath9k_hw_wait(struct ath_hal *ah, u32 reg, u32 mask, u32 val)
 {
        int i;
@@ -103,9 +92,10 @@ bool ath9k_hw_wait(struct ath_hal *ah, u32 reg, u32 mask, u32 val)
 
                udelay(AH_TIME_QUANTUM);
        }
-       DPRINTF(ah->ah_sc, ATH_DBG_PHY_IO,
-               "%s: timeout on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
-               __func__, reg, REG_READ(ah, reg), mask, val);
+
+       DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
+               "timeout on reg 0x%x: 0x%08x & 0x%08x != 0x%08x\n",
+               reg, REG_READ(ah, reg), mask, val);
 
        return false;
 }
@@ -142,27 +132,27 @@ bool ath9k_get_channel_edges(struct ath_hal *ah,
 }
 
 u16 ath9k_hw_computetxtime(struct ath_hal *ah,
-                          const struct ath9k_rate_table *rates,
+                          struct ath_rate_table *rates,
                           u32 frameLen, u16 rateix,
                           bool shortPreamble)
 {
        u32 bitsPerSymbol, numBits, numSymbols, phyTime, txTime;
        u32 kbps;
 
-       kbps = rates->info[rateix].rateKbps;
+       kbps = rates->info[rateix].ratekbps;
 
        if (kbps == 0)
                return 0;
 
        switch (rates->info[rateix].phy) {
-       case PHY_CCK:
+       case WLAN_RC_PHY_CCK:
                phyTime = CCK_PREAMBLE_BITS + CCK_PLCP_BITS;
-               if (shortPreamble && rates->info[rateix].shortPreamble)
+               if (shortPreamble && rates->info[rateix].short_preamble)
                        phyTime >>= 1;
                numBits = frameLen << 3;
                txTime = CCK_SIFS_TIME + phyTime + ((numBits * 1000) / kbps);
                break;
-       case PHY_OFDM:
+       case WLAN_RC_PHY_OFDM:
                if (ah->ah_curchan && IS_CHAN_QUARTER_RATE(ah->ah_curchan)) {
                        bitsPerSymbol = (kbps * OFDM_SYMBOL_TIME_QUARTER) / 1000;
                        numBits = OFDM_PLCP_BITS + (frameLen << 3);
@@ -187,8 +177,8 @@ u16 ath9k_hw_computetxtime(struct ath_hal *ah,
                }
                break;
        default:
-               DPRINTF(ah->ah_sc, ATH_DBG_PHY_IO,
-                       "%s: unknown phy %u (rate ix %u)\n", __func__,
+               DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
+                       "Unknown phy %u (rate ix %u)\n",
                        rates->info[rateix].phy, rateix);
                txTime = 0;
                break;
@@ -354,9 +344,9 @@ static bool ath9k_hw_chip_test(struct ath_hal *ah)
                        rdData = REG_READ(ah, addr);
                        if (rdData != wrData) {
                                DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
-                                       "%s: address test failed "
+                                       "address test failed "
                                        "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
-                                       __func__, addr, wrData, rdData);
+                                       addr, wrData, rdData);
                                return false;
                        }
                }
@@ -366,9 +356,9 @@ static bool ath9k_hw_chip_test(struct ath_hal *ah)
                        rdData = REG_READ(ah, addr);
                        if (wrData != rdData) {
                                DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
-                                       "%s: address test failed "
+                                       "address test failed "
                                        "addr: 0x%08x - wr:0x%08x != rd:0x%08x\n",
-                                       __func__, addr, wrData, rdData);
+                                       addr, wrData, rdData);
                                return false;
                        }
                }
@@ -387,9 +377,13 @@ static const char *ath9k_hw_devname(u16 devid)
                return "Atheros 5418";
        case AR9160_DEVID_PCI:
                return "Atheros 9160";
+       case AR5416_AR9100_DEVID:
+               return "Atheros 9100";
        case AR9280_DEVID_PCI:
        case AR9280_DEVID_PCIE:
                return "Atheros 9280";
+       case AR9285_DEVID_PCIE:
+               return "Atheros 9285";
        }
 
        return NULL;
@@ -448,8 +442,7 @@ static struct ath_hal_5416 *ath9k_hw_newstate(u16 devid,
        ahp = kzalloc(sizeof(struct ath_hal_5416), GFP_KERNEL);
        if (ahp == NULL) {
                DPRINTF(sc, ATH_DBG_FATAL,
-                       "%s: cannot allocate memory for state block\n",
-                       __func__);
+                       "Cannot allocate memory for state block\n");
                *status = -ENOMEM;
                return NULL;
        }
@@ -496,8 +489,7 @@ static int ath9k_hw_rfattach(struct ath_hal *ah)
        rfStatus = ath9k_hw_init_rf(ah, &ecode);
        if (!rfStatus) {
                DPRINTF(ah->ah_sc, ATH_DBG_RESET,
-                       "%s: RF setup failed, status %u\n", __func__,
-                       ecode);
+                       "RF setup failed, status %u\n", ecode);
                return ecode;
        }
 
@@ -522,9 +514,9 @@ static int ath9k_hw_rf_claim(struct ath_hal *ah)
                break;
        default:
                DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
-                       "%s: 5G Radio Chip Rev 0x%02X is not "
+                       "5G Radio Chip Rev 0x%02X is not "
                        "supported by this driver\n",
-                       __func__, ah->ah_analog5GhzRev);
+                       ah->ah_analog5GhzRev);
                return -EOPNOTSUPP;
        }
 
@@ -549,7 +541,7 @@ static int ath9k_hw_init_macaddr(struct ath_hal *ah)
        }
        if (sum == 0 || sum == 0xffff * 3) {
                DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
-                       "%s: mac address read failed: %pM\n", __func__,
+                       "mac address read failed: %pM\n",
                        ahp->ah_macaddr);
                return -EADDRNOTAVAIL;
        }
@@ -611,7 +603,7 @@ static int ath9k_hw_post_attach(struct ath_hal *ah)
 
        if (!ath9k_hw_chip_test(ah)) {
                DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
-                       "%s: hardware self-test failed\n", __func__);
+                       "hardware self-test failed\n");
                return -ENODEV;
        }
 
@@ -640,10 +632,7 @@ static struct ath_hal *ath9k_hw_do_attach(u16 devid, struct ath_softc *sc,
        struct ath_hal_5416 *ahp;
        struct ath_hal *ah;
        int ecode;
-#ifndef CONFIG_SLOW_ANT_DIV
-       u32 i;
-       u32 j;
-#endif
+       u32 i, j;
 
        ahp = ath9k_hw_newstate(devid, sc, mem, status);
        if (ahp == NULL)
@@ -657,15 +646,13 @@ static struct ath_hal *ath9k_hw_do_attach(u16 devid, struct ath_softc *sc,
                ahp->ah_intrMitigation = true;
 
        if (!ath9k_hw_set_reset_reg(ah, ATH9K_RESET_POWER_ON)) {
-               DPRINTF(ah->ah_sc, ATH_DBG_RESET, "%s: couldn't reset chip\n",
-                        __func__);
+               DPRINTF(ah->ah_sc, ATH_DBG_RESET, "Couldn't reset chip\n");
                ecode = -EIO;
                goto bad;
        }
 
        if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
-               DPRINTF(ah->ah_sc, ATH_DBG_RESET, "%s: couldn't wakeup chip\n",
-                        __func__);
+               DPRINTF(ah->ah_sc, ATH_DBG_RESET, "Couldn't wakeup chip\n");
                ecode = -EIO;
                goto bad;
        }
@@ -681,17 +668,16 @@ static struct ath_hal *ath9k_hw_do_attach(u16 devid, struct ath_softc *sc,
        }
 
        DPRINTF(ah->ah_sc, ATH_DBG_RESET,
-               "%s: serialize_regmode is %d\n",
-               __func__, ah->ah_config.serialize_regmode);
+               "serialize_regmode is %d\n",
+               ah->ah_config.serialize_regmode);
 
        if ((ah->ah_macVersion != AR_SREV_VERSION_5416_PCI) &&
            (ah->ah_macVersion != AR_SREV_VERSION_5416_PCIE) &&
            (ah->ah_macVersion != AR_SREV_VERSION_9160) &&
-           (!AR_SREV_9100(ah)) && (!AR_SREV_9280(ah))) {
+           (!AR_SREV_9100(ah)) && (!AR_SREV_9280(ah)) && (!AR_SREV_9285(ah))) {
                DPRINTF(ah->ah_sc, ATH_DBG_RESET,
-                       "%s: Mac Chip Rev 0x%02x.%x is not supported by "
-                       "this driver\n", __func__,
-                       ah->ah_macVersion, ah->ah_macRev);
+                       "Mac Chip Rev 0x%02x.%x is not supported by "
+                       "this driver\n", ah->ah_macVersion, ah->ah_macRev);
                ecode = -EOPNOTSUPP;
                goto bad;
        }
@@ -736,10 +722,41 @@ static struct ath_hal *ath9k_hw_do_attach(u16 devid, struct ath_softc *sc,
        }
 
        DPRINTF(ah->ah_sc, ATH_DBG_RESET,
-               "%s: This Mac Chip Rev 0x%02x.%x is \n", __func__,
+               "This Mac Chip Rev 0x%02x.%x is \n",
                ah->ah_macVersion, ah->ah_macRev);
 
-       if (AR_SREV_9280_20_OR_LATER(ah)) {
+       if (AR_SREV_9285_12_OR_LATER(ah)) {
+               INIT_INI_ARRAY(&ahp->ah_iniModes, ar9285Modes_9285_1_2,
+                              ARRAY_SIZE(ar9285Modes_9285_1_2), 6);
+               INIT_INI_ARRAY(&ahp->ah_iniCommon, ar9285Common_9285_1_2,
+                              ARRAY_SIZE(ar9285Common_9285_1_2), 2);
+
+               if (ah->ah_config.pcie_clock_req) {
+                       INIT_INI_ARRAY(&ahp->ah_iniPcieSerdes,
+                       ar9285PciePhy_clkreq_off_L1_9285_1_2,
+                       ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285_1_2), 2);
+               } else {
+                       INIT_INI_ARRAY(&ahp->ah_iniPcieSerdes,
+                       ar9285PciePhy_clkreq_always_on_L1_9285_1_2,
+                       ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285_1_2),
+                                 2);
+               }
+       } else if (AR_SREV_9285_10_OR_LATER(ah)) {
+               INIT_INI_ARRAY(&ahp->ah_iniModes, ar9285Modes_9285,
+                              ARRAY_SIZE(ar9285Modes_9285), 6);
+               INIT_INI_ARRAY(&ahp->ah_iniCommon, ar9285Common_9285,
+                              ARRAY_SIZE(ar9285Common_9285), 2);
+
+               if (ah->ah_config.pcie_clock_req) {
+                       INIT_INI_ARRAY(&ahp->ah_iniPcieSerdes,
+                       ar9285PciePhy_clkreq_off_L1_9285,
+                       ARRAY_SIZE(ar9285PciePhy_clkreq_off_L1_9285), 2);
+               } else {
+                       INIT_INI_ARRAY(&ahp->ah_iniPcieSerdes,
+                       ar9285PciePhy_clkreq_always_on_L1_9285,
+                       ARRAY_SIZE(ar9285PciePhy_clkreq_always_on_L1_9285), 2);
+               }
+       } else if (AR_SREV_9280_20_OR_LATER(ah)) {
                INIT_INI_ARRAY(&ahp->ah_iniModes, ar9280Modes_9280_2,
                               ARRAY_SIZE(ar9280Modes_9280_2), 6);
                INIT_INI_ARRAY(&ahp->ah_iniCommon, ar9280Common_9280_2,
@@ -849,14 +866,13 @@ static struct ath_hal *ath9k_hw_do_attach(u16 devid, struct ath_softc *sc,
                goto bad;
 
        /* rxgain table */
-       if (AR_SREV_9280_20_OR_LATER(ah))
+       if (AR_SREV_9280_20(ah))
                ath9k_hw_init_rxgain_ini(ah);
 
        /* txgain table */
-       if (AR_SREV_9280_20_OR_LATER(ah))
+       if (AR_SREV_9280_20(ah))
                ath9k_hw_init_txgain_ini(ah);
 
-#ifndef CONFIG_SLOW_ANT_DIV
        if (ah->ah_devid == AR9280_DEVID_PCI) {
                for (i = 0; i < ahp->ah_iniModes.ia_rows; i++) {
                        u32 reg = INI_RA(&ahp->ah_iniModes, i, 0);
@@ -865,15 +881,16 @@ static struct ath_hal *ath9k_hw_do_attach(u16 devid, struct ath_softc *sc,
                                u32 val = INI_RA(&ahp->ah_iniModes, i, j);
 
                                INI_RA(&ahp->ah_iniModes, i, j) =
-                                       ath9k_hw_ini_fixup(ah, &ahp->ah_eeprom,
+                                       ath9k_hw_ini_fixup(ah,
+                                                          &ahp->ah_eeprom.def,
                                                           reg, val);
                        }
                }
        }
-#endif
+
        if (!ath9k_hw_fill_cap_info(ah)) {
                DPRINTF(ah->ah_sc, ATH_DBG_RESET,
-                       "%s:failed ath9k_hw_fill_cap_info\n", __func__);
+                       "failed ath9k_hw_fill_cap_info\n");
                ecode = -EINVAL;
                goto bad;
        }
@@ -881,8 +898,7 @@ static struct ath_hal *ath9k_hw_do_attach(u16 devid, struct ath_softc *sc,
        ecode = ath9k_hw_init_macaddr(ah);
        if (ecode != 0) {
                DPRINTF(ah->ah_sc, ATH_DBG_RESET,
-                       "%s: failed initializing mac address\n",
-                       __func__);
+                       "failed initializing mac address\n");
                goto bad;
        }
 
@@ -909,7 +925,7 @@ static void ath9k_hw_init_bb(struct ath_hal *ah,
        u32 synthDelay;
 
        synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
-       if (IS_CHAN_CCK(chan))
+       if (IS_CHAN_B(chan))
                synthDelay = (4 * synthDelay) / 22;
        else
                synthDelay /= 10;
@@ -997,7 +1013,7 @@ static void ath9k_hw_init_pll(struct ath_hal *ah,
                                pll |= SM(0xb, AR_RTC_PLL_DIV);
                }
        }
-       REG_WRITE(ah, (u16) (AR_RTC_PLL_CONTROL), pll);
+       REG_WRITE(ah, AR_RTC_PLL_CONTROL, pll);
 
        udelay(RTC_PLL_SETTLE_DELAY);
 
@@ -1024,8 +1040,6 @@ static void ath9k_hw_init_chain_masks(struct ath_hal *ah)
                }
        case 0x1:
        case 0x2:
-               if (!AR_SREV_9280(ah))
-                       break;
        case 0x7:
                REG_WRITE(ah, AR_PHY_RX_CHAINMASK, rx_chainmask);
                REG_WRITE(ah, AR_PHY_CAL_CHAINMASK, rx_chainmask);
@@ -1044,7 +1058,8 @@ static void ath9k_hw_init_chain_masks(struct ath_hal *ah)
                          REG_READ(ah, AR_PHY_ANALOG_SWAP) | 0x00000001);
 }
 
-static void ath9k_hw_init_interrupt_masks(struct ath_hal *ah, enum ath9k_opmode opmode)
+static void ath9k_hw_init_interrupt_masks(struct ath_hal *ah,
+                                         enum nl80211_iftype opmode)
 {
        struct ath_hal_5416 *ahp = AH5416(ah);
 
@@ -1061,7 +1076,7 @@ static void ath9k_hw_init_interrupt_masks(struct ath_hal *ah, enum ath9k_opmode
 
        ahp->ah_maskReg |= AR_IMR_TXOK;
 
-       if (opmode == ATH9K_M_HOSTAP)
+       if (opmode == NL80211_IFTYPE_AP)
                ahp->ah_maskReg |= AR_IMR_MIB;
 
        REG_WRITE(ah, AR_IMR, ahp->ah_maskReg);
@@ -1079,8 +1094,7 @@ static bool ath9k_hw_set_ack_timeout(struct ath_hal *ah, u32 us)
        struct ath_hal_5416 *ahp = AH5416(ah);
 
        if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_ACK))) {
-               DPRINTF(ah->ah_sc, ATH_DBG_RESET, "%s: bad ack timeout %u\n",
-                        __func__, us);
+               DPRINTF(ah->ah_sc, ATH_DBG_RESET, "bad ack timeout %u\n", us);
                ahp->ah_acktimeout = (u32) -1;
                return false;
        } else {
@@ -1096,8 +1110,7 @@ static bool ath9k_hw_set_cts_timeout(struct ath_hal *ah, u32 us)
        struct ath_hal_5416 *ahp = AH5416(ah);
 
        if (us > ath9k_hw_mac_to_usec(ah, MS(0xffffffff, AR_TIME_OUT_CTS))) {
-               DPRINTF(ah->ah_sc, ATH_DBG_RESET, "%s: bad cts timeout %u\n",
-                        __func__, us);
+               DPRINTF(ah->ah_sc, ATH_DBG_RESET, "bad cts timeout %u\n", us);
                ahp->ah_ctstimeout = (u32) -1;
                return false;
        } else {
@@ -1114,7 +1127,7 @@ static bool ath9k_hw_set_global_txtimeout(struct ath_hal *ah, u32 tu)
 
        if (tu > 0xFFFF) {
                DPRINTF(ah->ah_sc, ATH_DBG_XMIT,
-                       "%s: bad global tx timeout %u\n", __func__, tu);
+                       "bad global tx timeout %u\n", tu);
                ahp->ah_globaltxtimeout = (u32) -1;
                return false;
        } else {
@@ -1128,8 +1141,8 @@ static void ath9k_hw_init_user_settings(struct ath_hal *ah)
 {
        struct ath_hal_5416 *ahp = AH5416(ah);
 
-       DPRINTF(ah->ah_sc, ATH_DBG_RESET, "--AP %s ahp->ah_miscMode 0x%x\n",
-                __func__, ahp->ah_miscMode);
+       DPRINTF(ah->ah_sc, ATH_DBG_RESET, "ahp->ah_miscMode 0x%x\n",
+               ahp->ah_miscMode);
 
        if (ahp->ah_miscMode != 0)
                REG_WRITE(ah, AR_PCU_MISC,
@@ -1168,15 +1181,14 @@ struct ath_hal *ath9k_hw_attach(u16 devid, struct ath_softc *sc,
        switch (devid) {
        case AR5416_DEVID_PCI:
        case AR5416_DEVID_PCIE:
+       case AR5416_AR9100_DEVID:
        case AR9160_DEVID_PCI:
        case AR9280_DEVID_PCI:
        case AR9280_DEVID_PCIE:
+       case AR9285_DEVID_PCIE:
                ah = ath9k_hw_do_attach(devid, sc, mem, error);
                break;
        default:
-               DPRINTF(ah->ah_sc, ATH_DBG_ANY,
-                        "devid=0x%x not supported.\n", devid);
-               ah = NULL;
                *error = -ENXIO;
                break;
        }
@@ -1191,6 +1203,14 @@ struct ath_hal *ath9k_hw_attach(u16 devid, struct ath_softc *sc,
 static void ath9k_hw_override_ini(struct ath_hal *ah,
                                  struct ath9k_channel *chan)
 {
+       /*
+        * Set the RX_ABORT and RX_DIS and clear if off only after
+        * RXE is set for MAC. This prevents frames with corrupted
+        * descriptor status.
+        */
+       REG_SET_BIT(ah, AR_DIAG_SW, (AR_DIAG_RX_DIS | AR_DIAG_RX_ABORT));
+
+
        if (!AR_SREV_5416_V20_OR_LATER(ah) ||
            AR_SREV_9280_10_OR_LATER(ah))
                return;
@@ -1198,8 +1218,8 @@ static void ath9k_hw_override_ini(struct ath_hal *ah,
        REG_WRITE(ah, 0x9800 + (651 << 2), 0x11);
 }
 
-static u32 ath9k_hw_ini_fixup(struct ath_hal *ah,
-                             struct ar5416_eeprom *pEepData,
+static u32 ath9k_hw_def_ini_fixup(struct ath_hal *ah,
+                             struct ar5416_eeprom_def *pEepData,
                              u32 reg, u32 value)
 {
        struct base_eep_header *pBase = &(pEepData->baseEepHeader);
@@ -1232,6 +1252,18 @@ static u32 ath9k_hw_ini_fixup(struct ath_hal *ah,
        return value;
 }
 
+static u32 ath9k_hw_ini_fixup(struct ath_hal *ah,
+                             struct ar5416_eeprom_def *pEepData,
+                             u32 reg, u32 value)
+{
+       struct ath_hal_5416 *ahp = AH5416(ah);
+
+       if (ahp->ah_eep_map == EEP_MAP_4KBITS)
+               return value;
+       else
+               return ath9k_hw_def_ini_fixup(ah, pEepData, reg, value);
+}
+
 static int ath9k_hw_process_ini(struct ath_hal *ah,
                                struct ath9k_channel *chan,
                                enum ath9k_ht_macmode macmode)
@@ -1299,11 +1331,6 @@ static int ath9k_hw_process_ini(struct ath_hal *ah,
                u32 reg = INI_RA(&ahp->ah_iniModes, i, 0);
                u32 val = INI_RA(&ahp->ah_iniModes, i, modesIndex);
 
-#ifdef CONFIG_SLOW_ANT_DIV
-               if (ah->ah_devid == AR9280_DEVID_PCI)
-                       val = ath9k_hw_ini_fixup(ah, &ahp->ah_eeprom, reg, val);
-#endif
-
                REG_WRITE(ah, reg, val);
 
                if (reg >= 0x7800 && reg < 0x78a0
@@ -1314,10 +1341,10 @@ static int ath9k_hw_process_ini(struct ath_hal *ah,
                DO_DELAY(regWrites);
        }
 
-       if (AR_SREV_9280_20_OR_LATER(ah))
+       if (AR_SREV_9280(ah))
                REG_WRITE_ARRAY(&ahp->ah_iniModesRxGain, modesIndex, regWrites);
 
-       if (AR_SREV_9280_20_OR_LATER(ah))
+       if (AR_SREV_9280(ah))
                REG_WRITE_ARRAY(&ahp->ah_iniModesTxGain, modesIndex, regWrites);
 
        for (i = 0; i < ahp->ah_iniCommon.ia_rows; i++) {
@@ -1354,13 +1381,13 @@ static int ath9k_hw_process_ini(struct ath_hal *ah,
                                          (u32) ah->ah_powerLimit));
        if (status != 0) {
                DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
-                       "%s: error init'ing transmit power\n", __func__);
+                       "error init'ing transmit power\n");
                return -EIO;
        }
 
        if (!ath9k_hw_set_rf_regs(ah, chan, freqIndex)) {
                DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
-                       "%s: ar5416SetRfRegs failed\n", __func__);
+                       "ar5416SetRfRegs failed\n");
                return -EIO;
        }
 
@@ -1429,18 +1456,18 @@ static void ath9k_hw_set_operating_mode(struct ath_hal *ah, int opmode)
        val = REG_READ(ah, AR_STA_ID1);
        val &= ~(AR_STA_ID1_STA_AP | AR_STA_ID1_ADHOC);
        switch (opmode) {
-       case ATH9K_M_HOSTAP:
+       case NL80211_IFTYPE_AP:
                REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_STA_AP
                          | AR_STA_ID1_KSRCH_MODE);
                REG_CLR_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
                break;
-       case ATH9K_M_IBSS:
+       case NL80211_IFTYPE_ADHOC:
                REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_ADHOC
                          | AR_STA_ID1_KSRCH_MODE);
                REG_SET_BIT(ah, AR_CFG, AR_CFG_AP_ADHOC_INDICATION);
                break;
-       case ATH9K_M_STA:
-       case ATH9K_M_MONITOR:
+       case NL80211_IFTYPE_STATION:
+       case NL80211_IFTYPE_MONITOR:
                REG_WRITE(ah, AR_STA_ID1, val | AR_STA_ID1_KSRCH_MODE);
                break;
        }
@@ -1526,14 +1553,13 @@ static bool ath9k_hw_set_reset(struct ath_hal *ah, int type)
                        rst_flags |= AR_RTC_RC_MAC_COLD;
        }
 
-       REG_WRITE(ah, (u16) (AR_RTC_RC), rst_flags);
+       REG_WRITE(ah, AR_RTC_RC, rst_flags);
        udelay(50);
 
-       REG_WRITE(ah, (u16) (AR_RTC_RC), 0);
-       if (!ath9k_hw_wait(ah, (u16) (AR_RTC_RC), AR_RTC_RC_M, 0)) {
+       REG_WRITE(ah, AR_RTC_RC, 0);
+       if (!ath9k_hw_wait(ah, AR_RTC_RC, AR_RTC_RC_M, 0)) {
                DPRINTF(ah->ah_sc, ATH_DBG_RESET,
-                       "%s: RTC stuck in MAC reset\n",
-                       __func__);
+                       "RTC stuck in MAC reset\n");
                return false;
        }
 
@@ -1553,15 +1579,14 @@ static bool ath9k_hw_set_reset_power_on(struct ath_hal *ah)
        REG_WRITE(ah, AR_RTC_FORCE_WAKE, AR_RTC_FORCE_WAKE_EN |
                  AR_RTC_FORCE_WAKE_ON_INT);
 
-       REG_WRITE(ah, (u16) (AR_RTC_RESET), 0);
-       REG_WRITE(ah, (u16) (AR_RTC_RESET), 1);
+       REG_WRITE(ah, AR_RTC_RESET, 0);
+       REG_WRITE(ah, AR_RTC_RESET, 1);
 
        if (!ath9k_hw_wait(ah,
                           AR_RTC_STATUS,
                           AR_RTC_STATUS_M,
                           AR_RTC_STATUS_ON)) {
-               DPRINTF(ah->ah_sc, ATH_DBG_RESET, "%s: RTC not waking up\n",
-                        __func__);
+               DPRINTF(ah->ah_sc, ATH_DBG_RESET, "RTC not waking up\n");
                return false;
        }
 
@@ -1592,10 +1617,15 @@ static void ath9k_hw_set_regs(struct ath_hal *ah, struct ath9k_channel *chan,
                              enum ath9k_ht_macmode macmode)
 {
        u32 phymode;
+       u32 enableDacFifo = 0;
        struct ath_hal_5416 *ahp = AH5416(ah);
 
+       if (AR_SREV_9285_10_OR_LATER(ah))
+               enableDacFifo = (REG_READ(ah, AR_PHY_TURBO) &
+                                        AR_PHY_FC_ENABLE_DAC_FIFO);
+
        phymode = AR_PHY_FC_HT_EN | AR_PHY_FC_SHORT_GI_40
-               | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH;
+               | AR_PHY_FC_SINGLE_HT_LTF1 | AR_PHY_FC_WALSH | enableDacFifo;
 
        if (IS_CHAN_HT40(chan)) {
                phymode |= AR_PHY_FC_DYN2040_EN;
@@ -1635,31 +1665,6 @@ static bool ath9k_hw_chip_reset(struct ath_hal *ah,
        return true;
 }
 
-static struct ath9k_channel *ath9k_hw_check_chan(struct ath_hal *ah,
-                                                struct ath9k_channel *chan)
-{
-       if (!(IS_CHAN_2GHZ(chan) ^ IS_CHAN_5GHZ(chan))) {
-               DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
-                       "%s: invalid channel %u/0x%x; not marked as "
-                       "2GHz or 5GHz\n", __func__, chan->channel,
-                       chan->channelFlags);
-               return NULL;
-       }
-
-       if (!IS_CHAN_OFDM(chan) &&
-           !IS_CHAN_CCK(chan) &&
-           !IS_CHAN_HT20(chan) &&
-           !IS_CHAN_HT40(chan)) {
-               DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
-                       "%s: invalid channel %u/0x%x; not marked as "
-                       "OFDM or CCK or HT20 or HT40PLUS or HT40MINUS\n",
-                       __func__, chan->channel, chan->channelFlags);
-               return NULL;
-       }
-
-       return ath9k_regd_check_channel(ah, chan);
-}
-
 static bool ath9k_hw_channel_change(struct ath_hal *ah,
                                    struct ath9k_channel *chan,
                                    enum ath9k_ht_macmode macmode)
@@ -1669,8 +1674,7 @@ static bool ath9k_hw_channel_change(struct ath_hal *ah,
        for (qnum = 0; qnum < AR_NUM_QCU; qnum++) {
                if (ath9k_hw_numtxpending(ah, qnum)) {
                        DPRINTF(ah->ah_sc, ATH_DBG_QUEUE,
-                               "%s: Transmit frames pending on queue %d\n",
-                               __func__, qnum);
+                               "Transmit frames pending on queue %d\n", qnum);
                        return false;
                }
        }
@@ -1678,8 +1682,8 @@ static bool ath9k_hw_channel_change(struct ath_hal *ah,
        REG_WRITE(ah, AR_PHY_RFBUS_REQ, AR_PHY_RFBUS_REQ_EN);
        if (!ath9k_hw_wait(ah, AR_PHY_RFBUS_GRANT, AR_PHY_RFBUS_GRANT_EN,
                           AR_PHY_RFBUS_GRANT_EN)) {
-               DPRINTF(ah->ah_sc, ATH_DBG_PHY_IO,
-                       "%s: Could not kill baseband RX\n", __func__);
+               DPRINTF(ah->ah_sc, ATH_DBG_REG_IO,
+                       "Could not kill baseband RX\n");
                return false;
        }
 
@@ -1688,13 +1692,13 @@ static bool ath9k_hw_channel_change(struct ath_hal *ah,
        if (AR_SREV_9280_10_OR_LATER(ah)) {
                if (!(ath9k_hw_ar9280_set_channel(ah, chan))) {
                        DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
-                               "%s: failed to set channel\n", __func__);
+                               "failed to set channel\n");
                        return false;
                }
        } else {
                if (!(ath9k_hw_set_channel(ah, chan))) {
                        DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
-                               "%s: failed to set channel\n", __func__);
+                               "failed to set channel\n");
                        return false;
                }
        }
@@ -1706,12 +1710,12 @@ static bool ath9k_hw_channel_change(struct ath_hal *ah,
                                 min((u32) MAX_RATE_POWER,
                                     (u32) ah->ah_powerLimit)) != 0) {
                DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
-                       "%s: error init'ing transmit power\n", __func__);
+                       "error init'ing transmit power\n");
                return false;
        }
 
        synthDelay = REG_READ(ah, AR_PHY_RX_DELAY) & AR_PHY_RX_DELAY_DELAY;
-       if (IS_CHAN_CCK(chan))
+       if (IS_CHAN_B(chan))
                synthDelay = (4 * synthDelay) / 22;
        else
                synthDelay /= 10;
@@ -1881,9 +1885,9 @@ static void ath9k_hw_9280_spur_mitigate(struct ath_hal *ah, struct ath9k_channel
                if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
 
                        /* workaround for gcc bug #37014 */
-                       volatile int tmp = abs(cur_vit_mask - bin);
+                       volatile int tmp_v = abs(cur_vit_mask - bin);
 
-                       if (tmp < 75)
+                       if (tmp_v < 75)
                                mask_amt = 1;
                        else
                                mask_amt = 0;
@@ -2082,9 +2086,9 @@ static void ath9k_hw_spur_mitigate(struct ath_hal *ah, struct ath9k_channel *cha
                if ((cur_vit_mask > lower) && (cur_vit_mask < upper)) {
 
                        /* workaround for gcc bug #37014 */
-                       volatile int tmp = abs(cur_vit_mask - bin);
+                       volatile int tmp_v = abs(cur_vit_mask - bin);
 
-                       if (tmp < 75)
+                       if (tmp_v < 75)
                                mask_amt = 1;
                        else
                                mask_amt = 0;
@@ -2185,41 +2189,35 @@ static void ath9k_hw_spur_mitigate(struct ath_hal *ah, struct ath9k_channel *cha
        REG_WRITE(ah, AR_PHY_MASK2_P_61_45, tmp_mask);
 }
 
-bool ath9k_hw_reset(struct ath_hal *ah, struct ath9k_channel *chan,
-                   enum ath9k_ht_macmode macmode,
-                   u8 txchainmask, u8 rxchainmask,
-                   enum ath9k_ht_extprotspacing extprotspacing,
-                   bool bChannelChange, int *status)
+int ath9k_hw_reset(struct ath_hal *ah, struct ath9k_channel *chan,
+                   bool bChannelChange)
 {
        u32 saveLedState;
+       struct ath_softc *sc = ah->ah_sc;
        struct ath_hal_5416 *ahp = AH5416(ah);
        struct ath9k_channel *curchan = ah->ah_curchan;
        u32 saveDefAntenna;
        u32 macStaId1;
-       int ecode;
-       int i, rx_chainmask;
+       int i, rx_chainmask, r;
 
-       ahp->ah_extprotspacing = extprotspacing;
-       ahp->ah_txchainmask = txchainmask;
-       ahp->ah_rxchainmask = rxchainmask;
+       ahp->ah_extprotspacing = sc->sc_ht_extprotspacing;
+       ahp->ah_txchainmask = sc->sc_tx_chainmask;
+       ahp->ah_rxchainmask = sc->sc_rx_chainmask;
 
        if (AR_SREV_9280(ah)) {
                ahp->ah_txchainmask &= 0x3;
                ahp->ah_rxchainmask &= 0x3;
        }
 
-       if (ath9k_hw_check_chan(ah, chan) == NULL) {
+       if (ath9k_regd_check_channel(ah, chan) == NULL) {
                DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL,
-                       "%s: invalid channel %u/0x%x; no mapping\n",
-                       __func__, chan->channel, chan->channelFlags);
-               ecode = -EINVAL;
-               goto bad;
+                       "invalid channel %u/0x%x; no mapping\n",
+                       chan->channel, chan->channelFlags);
+               return -EINVAL;
        }
 
-       if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE)) {
-               ecode = -EIO;
-               goto bad;
-       }
+       if (!ath9k_hw_setpower(ah, ATH9K_PM_AWAKE))
+               return -EIO;
 
        if (curchan)
                ath9k_hw_getnf(ah, curchan);
@@ -2231,13 +2229,12 @@ bool ath9k_hw_reset(struct ath_hal *ah, struct ath9k_channel *chan,
            ((chan->channelFlags & CHANNEL_ALL) ==
             (ah->ah_curchan->channelFlags & CHANNEL_ALL)) &&
            (!AR_SREV_9280(ah) || (!IS_CHAN_A_5MHZ_SPACED(chan) &&
-                                  !IS_CHAN_A_5MHZ_SPACED(ah->
-                                                         ah_curchan)))) {
+                                  !IS_CHAN_A_5MHZ_SPACED(ah->ah_curchan)))) {
 
-               if (ath9k_hw_channel_change(ah, chan, macmode)) {
+               if (ath9k_hw_channel_change(ah, chan, sc->tx_chan_width)) {
                        ath9k_hw_loadnf(ah, ah->ah_curchan);
                        ath9k_hw_start_nfcal(ah);
-                       return true;
+                       return 0;
                }
        }
 
@@ -2254,10 +2251,8 @@ bool ath9k_hw_reset(struct ath_hal *ah, struct ath9k_channel *chan,
        ath9k_hw_mark_phy_inactive(ah);
 
        if (!ath9k_hw_chip_reset(ah, chan)) {
-               DPRINTF(ah->ah_sc, ATH_DBG_RESET, "%s: chip reset failed\n",
-                        __func__);
-               ecode = -EINVAL;
-               goto bad;
+               DPRINTF(ah->ah_sc, ATH_DBG_RESET, "chip reset failed\n");
+               return -EINVAL;
        }
 
        if (AR_SREV_9280(ah)) {
@@ -2273,11 +2268,26 @@ bool ath9k_hw_reset(struct ath_hal *ah, struct ath9k_channel *chan,
                ath9k_hw_cfg_output(ah, 9, AR_GPIO_OUTPUT_MUX_AS_OUTPUT);
        }
 
-       ecode = ath9k_hw_process_ini(ah, chan, macmode);
-       if (ecode != 0) {
-               ecode = -EINVAL;
-               goto bad;
-       }
+       r = ath9k_hw_process_ini(ah, chan, sc->tx_chan_width);
+       if (r)
+               return r;
+
+       /* Setup MFP options for CCMP */
+       if (AR_SREV_9280_20_OR_LATER(ah)) {
+               /* Mask Retry(b11), PwrMgt(b12), MoreData(b13) to 0 in mgmt
+                * frames when constructing CCMP AAD. */
+               REG_RMW_FIELD(ah, AR_AES_MUTE_MASK1, AR_AES_MUTE_MASK1_FC_MGMT,
+                             0xc7ff);
+               ah->sw_mgmt_crypto = false;
+       } else if (AR_SREV_9160_10_OR_LATER(ah)) {
+               /* Disable hardware crypto for management frames */
+               REG_CLR_BIT(ah, AR_PCU_MISC_MODE2,
+                           AR_PCU_MISC_MODE2_MGMT_CRYPTO_ENABLE);
+               REG_SET_BIT(ah, AR_PCU_MISC_MODE2,
+                           AR_PCU_MISC_MODE2_NO_CRYPTO_FOR_NON_DATA_PKT);
+               ah->sw_mgmt_crypto = true;
+       } else
+               ah->sw_mgmt_crypto = true;
 
        if (IS_CHAN_OFDM(chan) || IS_CHAN_HT(chan))
                ath9k_hw_set_delta_slope(ah, chan);
@@ -2289,9 +2299,8 @@ bool ath9k_hw_reset(struct ath_hal *ah, struct ath9k_channel *chan,
 
        if (!ath9k_hw_eeprom_set_board_values(ah, chan)) {
                DPRINTF(ah->ah_sc, ATH_DBG_EEPROM,
-                       "%s: error setting board options\n", __func__);
-               ecode = -EIO;
-               goto bad;
+                       "error setting board options\n");
+               return -EIO;
        }
 
        ath9k_hw_decrease_chain_power(ah, chan);
@@ -2319,15 +2328,11 @@ bool ath9k_hw_reset(struct ath_hal *ah, struct ath9k_channel *chan,
        REG_WRITE(ah, AR_RSSI_THR, INIT_RSSI_THR);
 
        if (AR_SREV_9280_10_OR_LATER(ah)) {
-               if (!(ath9k_hw_ar9280_set_channel(ah, chan))) {
-                       ecode = -EIO;
-                       goto bad;
-               }
+               if (!(ath9k_hw_ar9280_set_channel(ah, chan)))
+                       return -EIO;
        } else {
-               if (!(ath9k_hw_set_channel(ah, chan))) {
-                       ecode = -EIO;
-                       goto bad;
-               }
+               if (!(ath9k_hw_set_channel(ah, chan)))
+                       return -EIO;
        }
 
        for (i = 0; i < AR_NUM_DCU; i++)
@@ -2361,10 +2366,8 @@ bool ath9k_hw_reset(struct ath_hal *ah, struct ath9k_channel *chan,
 
        ath9k_hw_init_bb(ah, chan);
 
-       if (!ath9k_hw_init_cal(ah, chan)){
-               ecode = -EIO;;
-               goto bad;
-       }
+       if (!ath9k_hw_init_cal(ah, chan))
+               return -EIO;;
 
        rx_chainmask = ahp->ah_rxchainmask;
        if ((rx_chainmask == 0x5) || (rx_chainmask == 0x3)) {
@@ -2379,15 +2382,13 @@ bool ath9k_hw_reset(struct ath_hal *ah, struct ath9k_channel *chan,
                mask = REG_READ(ah, AR_CFG);
                if (mask & (AR_CFG_SWRB | AR_CFG_SWTB | AR_CFG_SWRG)) {
                        DPRINTF(ah->ah_sc, ATH_DBG_RESET,
-                               "%s CFG Byte Swap Set 0x%x\n", __func__,
-                               mask);
+                               "CFG Byte Swap Set 0x%x\n", mask);
                } else {
                        mask =
                                INIT_CONFIG_STATUS | AR_CFG_SWRB | AR_CFG_SWTB;
                        REG_WRITE(ah, AR_CFG, mask);
                        DPRINTF(ah->ah_sc, ATH_DBG_RESET,
-                               "%s Setting CFG 0x%x\n", __func__,
-                               REG_READ(ah, AR_CFG));
+                               "Setting CFG 0x%x\n", REG_READ(ah, AR_CFG));
                }
        } else {
 #ifdef __BIG_ENDIAN
@@ -2395,11 +2396,7 @@ bool ath9k_hw_reset(struct ath_hal *ah, struct ath9k_channel *chan,
 #endif
        }
 
-       return true;
-bad:
-       if (status)
-               *status = ecode;
-       return false;
+       return 0;
 }
 
 /************************/
@@ -2412,7 +2409,7 @@ bool ath9k_hw_keyreset(struct ath_hal *ah, u16 entry)
 
        if (entry >= ah->ah_caps.keycache_size) {
                DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
-                       "%s: entry %u out of range\n", __func__, entry);
+                       "entry %u out of range\n", entry);
                return false;
        }
 
@@ -2449,7 +2446,7 @@ bool ath9k_hw_keysetmac(struct ath_hal *ah, u16 entry, const u8 *mac)
 
        if (entry >= ah->ah_caps.keycache_size) {
                DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
-                       "%s: entry %u out of range\n", __func__, entry);
+                       "entry %u out of range\n", entry);
                return false;
        }
 
@@ -2485,7 +2482,7 @@ bool ath9k_hw_set_keycache_entry(struct ath_hal *ah, u16 entry,
 
        if (entry >= pCap->keycache_size) {
                DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
-                       "%s: entry %u out of range\n", __func__, entry);
+                       "entry %u out of range\n", entry);
                return false;
        }
 
@@ -2496,8 +2493,7 @@ bool ath9k_hw_set_keycache_entry(struct ath_hal *ah, u16 entry,
        case ATH9K_CIPHER_AES_CCM:
                if (!(pCap->hw_caps & ATH9K_HW_CAP_CIPHER_AESCCM)) {
                        DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
-                               "%s: AES-CCM not supported by "
-                               "mac rev 0x%x\n", __func__,
+                               "AES-CCM not supported by mac rev 0x%x\n",
                                ah->ah_macRev);
                        return false;
                }
@@ -2508,16 +2504,14 @@ bool ath9k_hw_set_keycache_entry(struct ath_hal *ah, u16 entry,
                if (ATH9K_IS_MIC_ENABLED(ah)
                    && entry + 64 >= pCap->keycache_size) {
                        DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
-                               "%s: entry %u inappropriate for TKIP\n",
-                               __func__, entry);
+                               "entry %u inappropriate for TKIP\n", entry);
                        return false;
                }
                break;
        case ATH9K_CIPHER_WEP:
                if (k->kv_len < LEN_WEP40) {
                        DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
-                               "%s: WEP key length %u too small\n",
-                               __func__, k->kv_len);
+                               "WEP key length %u too small\n", k->kv_len);
                        return false;
                }
                if (k->kv_len <= LEN_WEP40)
@@ -2532,8 +2526,7 @@ bool ath9k_hw_set_keycache_entry(struct ath_hal *ah, u16 entry,
                break;
        default:
                DPRINTF(ah->ah_sc, ATH_DBG_KEYCACHE,
-                       "%s: cipher %u not supported\n", __func__,
-                       k->kv_type);
+                       "cipher %u not supported\n", k->kv_type);
                return false;
        }
 
@@ -2629,7 +2622,7 @@ static void ath9k_set_power_sleep(struct ath_hal *ah, int setChip)
                if (!AR_SREV_9100(ah))
                        REG_WRITE(ah, AR_RC, AR_RC_AHB | AR_RC_HOSTIF);
 
-               REG_CLR_BIT(ah, (u16) (AR_RTC_RESET),
+               REG_CLR_BIT(ah, (AR_RTC_RESET),
                            AR_RTC_RESET_EN);
        }
 }
@@ -2682,8 +2675,7 @@ static bool ath9k_hw_set_power_awake(struct ath_hal *ah,
                }
                if (i == 0) {
                        DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
-                               "%s: Failed to wakeup in %uus\n",
-                               __func__, POWER_UP_TIME / 20);
+                               "Failed to wakeup in %uus\n", POWER_UP_TIME / 20);
                        return false;
                }
        }
@@ -2705,8 +2697,8 @@ bool ath9k_hw_setpower(struct ath_hal *ah,
        };
        int status = true, setChip = true;
 
-       DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT, "%s: %s -> %s (%s)\n", __func__,
-               modes[ahp->ah_powerMode], modes[mode],
+       DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT, "%s -> %s (%s)\n",
+               modes[ah->ah_power_mode], modes[mode],
                setChip ? "set chip " : "");
 
        switch (mode) {
@@ -2722,10 +2714,10 @@ bool ath9k_hw_setpower(struct ath_hal *ah,
                break;
        default:
                DPRINTF(ah->ah_sc, ATH_DBG_POWER_MGMT,
-                       "%s: unknown power mode %u\n", __func__, mode);
+                       "Unknown power mode %u\n", mode);
                return false;
        }
-       ahp->ah_powerMode = mode;
+       ah->ah_power_mode = mode;
 
        return status;
 }
@@ -2789,11 +2781,14 @@ void ath9k_hw_configpcipowersave(struct ath_hal *ah, int restore)
        if (ah->ah_config.pcie_waen) {
                REG_WRITE(ah, AR_WA, ah->ah_config.pcie_waen);
        } else {
-               if (AR_SREV_9280(ah))
-                       REG_WRITE(ah, AR_WA, 0x0040073f);
+               if (AR_SREV_9285(ah))
+                       REG_WRITE(ah, AR_WA, AR9285_WA_DEFAULT);
+               else if (AR_SREV_9280(ah))
+                       REG_WRITE(ah, AR_WA, AR9280_WA_DEFAULT);
                else
-                       REG_WRITE(ah, AR_WA, 0x0000073f);
+                       REG_WRITE(ah, AR_WA, AR_WA_DEFAULT);
        }
+
 }
 
 /**********************/
@@ -2899,8 +2894,7 @@ bool ath9k_hw_getisr(struct ath_hal *ah, enum ath9k_int *masked)
 
                if (isr & AR_ISR_RXORN) {
                        DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
-                               "%s: receive FIFO overrun interrupt\n",
-                               __func__);
+                               "receive FIFO overrun interrupt\n");
                }
 
                if (!AR_SREV_9100(ah)) {
@@ -2926,27 +2920,23 @@ bool ath9k_hw_getisr(struct ath_hal *ah, enum ath9k_int *masked)
                if (fatal_int) {
                        if (sync_cause & AR_INTR_SYNC_HOST1_FATAL) {
                                DPRINTF(ah->ah_sc, ATH_DBG_ANY,
-                                       "%s: received PCI FATAL interrupt\n",
-                                       __func__);
+                                       "received PCI FATAL interrupt\n");
                        }
                        if (sync_cause & AR_INTR_SYNC_HOST1_PERR) {
                                DPRINTF(ah->ah_sc, ATH_DBG_ANY,
-                                       "%s: received PCI PERR interrupt\n",
-                                       __func__);
+                                       "received PCI PERR interrupt\n");
                        }
                }
                if (sync_cause & AR_INTR_SYNC_RADM_CPL_TIMEOUT) {
                        DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
-                               "%s: AR_INTR_SYNC_RADM_CPL_TIMEOUT\n",
-                               __func__);
+                               "AR_INTR_SYNC_RADM_CPL_TIMEOUT\n");
                        REG_WRITE(ah, AR_RC, AR_RC_HOSTIF);
                        REG_WRITE(ah, AR_RC, 0);
                        *masked |= ATH9K_INT_FATAL;
                }
                if (sync_cause & AR_INTR_SYNC_LOCAL_TIMEOUT) {
                        DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT,
-                               "%s: AR_INTR_SYNC_LOCAL_TIMEOUT\n",
-                               __func__);
+                               "AR_INTR_SYNC_LOCAL_TIMEOUT\n");
                }
 
                REG_WRITE(ah, AR_INTR_SYNC_CAUSE_CLR, sync_cause);
@@ -2968,12 +2958,10 @@ enum ath9k_int ath9k_hw_set_interrupts(struct ath_hal *ah, enum ath9k_int ints)
        u32 mask, mask2;
        struct ath9k_hw_capabilities *pCap = &ah->ah_caps;
 
-       DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "%s: 0x%x => 0x%x\n", __func__,
-                omask, ints);
+       DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "0x%x => 0x%x\n", omask, ints);
 
        if (omask & ATH9K_INT_GLOBAL) {
-               DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "%s: disable IER\n",
-                        __func__);
+               DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "disable IER\n");
                REG_WRITE(ah, AR_IER, AR_IER_DISABLE);
                (void) REG_READ(ah, AR_IER);
                if (!AR_SREV_9100(ah)) {
@@ -3028,8 +3016,7 @@ enum ath9k_int ath9k_hw_set_interrupts(struct ath_hal *ah, enum ath9k_int ints)
                        mask2 |= AR_IMR_S2_CST;
        }
 
-       DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "%s: new IMR 0x%x\n", __func__,
-                mask);
+       DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "new IMR 0x%x\n", mask);
        REG_WRITE(ah, AR_IMR, mask);
        mask = REG_READ(ah, AR_IMR_S2) & ~(AR_IMR_S2_TIM |
                                           AR_IMR_S2_DTIM |
@@ -3049,8 +3036,7 @@ enum ath9k_int ath9k_hw_set_interrupts(struct ath_hal *ah, enum ath9k_int ints)
        }
 
        if (ints & ATH9K_INT_GLOBAL) {
-               DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "%s: enable IER\n",
-                        __func__);
+               DPRINTF(ah->ah_sc, ATH_DBG_INTERRUPT, "enable IER\n");
                REG_WRITE(ah, AR_IER, AR_IER_ENABLE);
                if (!AR_SREV_9100(ah)) {
                        REG_WRITE(ah, AR_INTR_ASYNC_ENABLE,
@@ -3082,14 +3068,14 @@ void ath9k_hw_beaconinit(struct ath_hal *ah, u32 next_beacon, u32 beacon_period)
        ahp->ah_beaconInterval = beacon_period;
 
        switch (ah->ah_opmode) {
-       case ATH9K_M_STA:
-       case ATH9K_M_MONITOR:
+       case NL80211_IFTYPE_STATION:
+       case NL80211_IFTYPE_MONITOR:
                REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
                REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT, 0xffff);
                REG_WRITE(ah, AR_NEXT_SWBA, 0x7ffff);
                flags |= AR_TBTT_TIMER_EN;
                break;
-       case ATH9K_M_IBSS:
+       case NL80211_IFTYPE_ADHOC:
                REG_SET_BIT(ah, AR_TXCFG,
                            AR_TXCFG_ADHOC_BEACON_ATIM_TX_POLICY);
                REG_WRITE(ah, AR_NEXT_NDP_TIMER,
@@ -3097,7 +3083,7 @@ void ath9k_hw_beaconinit(struct ath_hal *ah, u32 next_beacon, u32 beacon_period)
                                     (ahp->ah_atimWindow ? ahp->
                                      ah_atimWindow : 1)));
                flags |= AR_NDP_TIMER_EN;
-       case ATH9K_M_HOSTAP:
+       case NL80211_IFTYPE_AP:
                REG_WRITE(ah, AR_NEXT_TBTT_TIMER, TU_TO_USEC(next_beacon));
                REG_WRITE(ah, AR_NEXT_DMA_BEACON_ALERT,
                          TU_TO_USEC(next_beacon -
@@ -3110,6 +3096,12 @@ void ath9k_hw_beaconinit(struct ath_hal *ah, u32 next_beacon, u32 beacon_period)
                flags |=
                        AR_TBTT_TIMER_EN | AR_DBA_TIMER_EN | AR_SWBA_TIMER_EN;
                break;
+       default:
+               DPRINTF(ah->ah_sc, ATH_DBG_BEACON,
+                       "%s: unsupported opmode: %d\n",
+                       __func__, ah->ah_opmode);
+               return;
+               break;
        }
 
        REG_WRITE(ah, AR_BEACON_PERIOD, TU_TO_USEC(beacon_period));
@@ -3156,14 +3148,10 @@ void ath9k_hw_set_sta_beacon_timers(struct ath_hal *ah,
        else
                nextTbtt = bs->bs_nexttbtt;
 
-       DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "%s: next DTIM %d\n", __func__,
-                bs->bs_nextdtim);
-       DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "%s: next beacon %d\n", __func__,
-                nextTbtt);
-       DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "%s: beacon period %d\n", __func__,
-                beaconintval);
-       DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "%s: DTIM period %d\n", __func__,
-                dtimperiod);
+       DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "next DTIM %d\n", bs->bs_nextdtim);
+       DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "next beacon %d\n", nextTbtt);
+       DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "beacon period %d\n", beaconintval);
+       DPRINTF(ah->ah_sc, ATH_DBG_BEACON, "DTIM period %d\n", dtimperiod);
 
        REG_WRITE(ah, AR_NEXT_DTIM,
                  TU_TO_USEC(bs->bs_nextdtim - SLEEP_SLOP));
@@ -3190,190 +3178,6 @@ void ath9k_hw_set_sta_beacon_timers(struct ath_hal *ah,
 
 }
 
-/***************/
-/* Rate tables */
-/***************/
-
-static struct ath9k_rate_table ar5416_11a_table = {
-       8,
-       {0},
-       {
-               {true, PHY_OFDM, 6000, 0x0b, 0x00, (0x80 | 12), 0},
-               {true, PHY_OFDM, 9000, 0x0f, 0x00, 18, 0},
-               {true, PHY_OFDM, 12000, 0x0a, 0x00, (0x80 | 24), 2},
-               {true, PHY_OFDM, 18000, 0x0e, 0x00, 36, 2},
-               {true, PHY_OFDM, 24000, 0x09, 0x00, (0x80 | 48), 4},
-               {true, PHY_OFDM, 36000, 0x0d, 0x00, 72, 4},
-               {true, PHY_OFDM, 48000, 0x08, 0x00, 96, 4},
-               {true, PHY_OFDM, 54000, 0x0c, 0x00, 108, 4}
-       },
-};
-
-static struct ath9k_rate_table ar5416_11b_table = {
-       4,
-       {0},
-       {
-               {true, PHY_CCK, 1000, 0x1b, 0x00, (0x80 | 2), 0},
-               {true, PHY_CCK, 2000, 0x1a, 0x04, (0x80 | 4), 1},
-               {true, PHY_CCK, 5500, 0x19, 0x04, (0x80 | 11), 1},
-               {true, PHY_CCK, 11000, 0x18, 0x04, (0x80 | 22), 1}
-       },
-};
-
-static struct ath9k_rate_table ar5416_11g_table = {
-       12,
-       {0},
-       {
-               {true, PHY_CCK, 1000, 0x1b, 0x00, (0x80 | 2), 0},
-               {true, PHY_CCK, 2000, 0x1a, 0x04, (0x80 | 4), 1},
-               {true, PHY_CCK, 5500, 0x19, 0x04, (0x80 | 11), 2},
-               {true, PHY_CCK, 11000, 0x18, 0x04, (0x80 | 22), 3},
-
-               {false, PHY_OFDM, 6000, 0x0b, 0x00, 12, 4},
-               {false, PHY_OFDM, 9000, 0x0f, 0x00, 18, 4},
-               {true, PHY_OFDM, 12000, 0x0a, 0x00, 24, 6},
-               {true, PHY_OFDM, 18000, 0x0e, 0x00, 36, 6},
-               {true, PHY_OFDM, 24000, 0x09, 0x00, 48, 8},
-               {true, PHY_OFDM, 36000, 0x0d, 0x00, 72, 8},
-               {true, PHY_OFDM, 48000, 0x08, 0x00, 96, 8},
-               {true, PHY_OFDM, 54000, 0x0c, 0x00, 108, 8}
-       },
-};
-
-static struct ath9k_rate_table ar5416_11ng_table = {
-       28,
-       {0},
-       {
-               {true, PHY_CCK, 1000, 0x1b, 0x00, (0x80 | 2), 0},
-               {true, PHY_CCK, 2000, 0x1a, 0x04, (0x80 | 4), 1},
-               {true, PHY_CCK, 5500, 0x19, 0x04, (0x80 | 11), 2},
-               {true, PHY_CCK, 11000, 0x18, 0x04, (0x80 | 22), 3},
-
-               {false, PHY_OFDM, 6000, 0x0b, 0x00, 12, 4},
-               {false, PHY_OFDM, 9000, 0x0f, 0x00, 18, 4},
-               {true, PHY_OFDM, 12000, 0x0a, 0x00, 24, 6},
-               {true, PHY_OFDM, 18000, 0x0e, 0x00, 36, 6},
-               {true, PHY_OFDM, 24000, 0x09, 0x00, 48, 8},
-               {true, PHY_OFDM, 36000, 0x0d, 0x00, 72, 8},
-               {true, PHY_OFDM, 48000, 0x08, 0x00, 96, 8},
-               {true, PHY_OFDM, 54000, 0x0c, 0x00, 108, 8},
-               {true, PHY_HT, 6500, 0x80, 0x00, 0, 4},
-               {true, PHY_HT, 13000, 0x81, 0x00, 1, 6},
-               {true, PHY_HT, 19500, 0x82, 0x00, 2, 6},
-               {true, PHY_HT, 26000, 0x83, 0x00, 3, 8},
-               {true, PHY_HT, 39000, 0x84, 0x00, 4, 8},
-               {true, PHY_HT, 52000, 0x85, 0x00, 5, 8},
-               {true, PHY_HT, 58500, 0x86, 0x00, 6, 8},
-               {true, PHY_HT, 65000, 0x87, 0x00, 7, 8},
-               {true, PHY_HT, 13000, 0x88, 0x00, 8, 4},
-               {true, PHY_HT, 26000, 0x89, 0x00, 9, 6},
-               {true, PHY_HT, 39000, 0x8a, 0x00, 10, 6},
-               {true, PHY_HT, 52000, 0x8b, 0x00, 11, 8},
-               {true, PHY_HT, 78000, 0x8c, 0x00, 12, 8},
-               {true, PHY_HT, 104000, 0x8d, 0x00, 13, 8},
-               {true, PHY_HT, 117000, 0x8e, 0x00, 14, 8},
-               {true, PHY_HT, 130000, 0x8f, 0x00, 15, 8},
-       },
-};
-
-static struct ath9k_rate_table ar5416_11na_table = {
-       24,
-       {0},
-       {
-               {true, PHY_OFDM, 6000, 0x0b, 0x00, (0x80 | 12), 0},
-               {true, PHY_OFDM, 9000, 0x0f, 0x00, 18, 0},
-               {true, PHY_OFDM, 12000, 0x0a, 0x00, (0x80 | 24), 2},
-               {true, PHY_OFDM, 18000, 0x0e, 0x00, 36, 2},
-               {true, PHY_OFDM, 24000, 0x09, 0x00, (0x80 | 48), 4},
-               {true, PHY_OFDM, 36000, 0x0d, 0x00, 72, 4},
-               {true, PHY_OFDM, 48000, 0x08, 0x00, 96, 4},
-               {true, PHY_OFDM, 54000, 0x0c, 0x00, 108, 4},
-               {true, PHY_HT, 6500, 0x80, 0x00, 0, 0},
-               {true, PHY_HT, 13000, 0x81, 0x00, 1, 2},
-               {true, PHY_HT, 19500, 0x82, 0x00, 2, 2},
-               {true, PHY_HT, 26000, 0x83, 0x00, 3, 4},
-               {true, PHY_HT, 39000, 0x84, 0x00, 4, 4},
-               {true, PHY_HT, 52000, 0x85, 0x00, 5, 4},
-               {true, PHY_HT, 58500, 0x86, 0x00, 6, 4},
-               {true, PHY_HT, 65000, 0x87, 0x00, 7, 4},
-               {true, PHY_HT, 13000, 0x88, 0x00, 8, 0},
-               {true, PHY_HT, 26000, 0x89, 0x00, 9, 2},
-               {true, PHY_HT, 39000, 0x8a, 0x00, 10, 2},
-               {true, PHY_HT, 52000, 0x8b, 0x00, 11, 4},
-               {true, PHY_HT, 78000, 0x8c, 0x00, 12, 4},
-               {true, PHY_HT, 104000, 0x8d, 0x00, 13, 4},
-               {true, PHY_HT, 117000, 0x8e, 0x00, 14, 4},
-               {true, PHY_HT, 130000, 0x8f, 0x00, 15, 4},
-       },
-};
-
-static void ath9k_hw_setup_rate_table(struct ath_hal *ah,
-                                     struct ath9k_rate_table *rt)
-{
-       int i;
-
-       if (rt->rateCodeToIndex[0] != 0)
-               return;
-
-       for (i = 0; i < 256; i++)
-               rt->rateCodeToIndex[i] = (u8) -1;
-
-       for (i = 0; i < rt->rateCount; i++) {
-               u8 code = rt->info[i].rateCode;
-               u8 cix = rt->info[i].controlRate;
-
-               rt->rateCodeToIndex[code] = i;
-               rt->rateCodeToIndex[code | rt->info[i].shortPreamble] = i;
-
-               rt->info[i].lpAckDuration =
-                       ath9k_hw_computetxtime(ah, rt,
-                                              WLAN_CTRL_FRAME_SIZE,
-                                              cix,
-                                              false);
-               rt->info[i].spAckDuration =
-                       ath9k_hw_computetxtime(ah, rt,
-                                              WLAN_CTRL_FRAME_SIZE,
-                                              cix,
-                                              true);
-       }
-}
-
-const struct ath9k_rate_table *ath9k_hw_getratetable(struct ath_hal *ah,
-                                                    u32 mode)
-{
-       struct ath9k_rate_table *rt;
-
-       switch (mode) {
-       case ATH9K_MODE_11A:
-               rt = &ar5416_11a_table;
-               break;
-       case ATH9K_MODE_11B:
-               rt = &ar5416_11b_table;
-               break;
-       case ATH9K_MODE_11G:
-               rt = &ar5416_11g_table;
-               break;
-       case ATH9K_MODE_11NG_HT20:
-       case ATH9K_MODE_11NG_HT40PLUS:
-       case ATH9K_MODE_11NG_HT40MINUS:
-               rt = &ar5416_11ng_table;
-               break;
-       case ATH9K_MODE_11NA_HT20:
-       case ATH9K_MODE_11NA_HT40PLUS:
-       case ATH9K_MODE_11NA_HT40MINUS:
-               rt = &ar5416_11na_table;
-               break;
-       default:
-               DPRINTF(ah->ah_sc, ATH_DBG_CHANNEL, "%s: invalid mode 0x%x\n",
-                       __func__, mode);
-               return NULL;
-       }
-
-       ath9k_hw_setup_rate_table(ah, rt);
-
-       return rt;
-}
-
 /*******************/
 /* HW Capabilities */
 /*******************/
@@ -3393,15 +3197,14 @@ bool ath9k_hw_fill_cap_info(struct ath_hal *ah)
 
        capField = ath9k_hw_get_eeprom(ah, EEP_OP_CAP);
 
-       if (ah->ah_opmode != ATH9K_M_HOSTAP &&
+       if (ah->ah_opmode != NL80211_IFTYPE_AP &&
            ah->ah_subvendorid == AR_SUBVENDOR_ID_NEW_A) {
                if (ah->ah_currentRD == 0x64 || ah->ah_currentRD == 0x65)
                        ah->ah_currentRD += 5;
                else if (ah->ah_currentRD == 0x41)
                        ah->ah_currentRD = 0x43;
                DPRINTF(ah->ah_sc, ATH_DBG_REGULATORY,
-                       "%s: regdomain mapped to 0x%x\n", __func__,
-                       ah->ah_currentRD);
+                       "regdomain mapped to 0x%x\n", ah->ah_currentRD);
        }
 
        eeval = ath9k_hw_get_eeprom(ah, EEP_OP_MODE);
@@ -3493,7 +3296,9 @@ bool ath9k_hw_fill_cap_info(struct ath_hal *ah)
        pCap->num_mr_retries = 4;
        pCap->tx_triglevel_max = MAX_TX_FIFO_THRESHOLD;
 
-       if (AR_SREV_9280_10_OR_LATER(ah))
+       if (AR_SREV_9285_10_OR_LATER(ah))
+               pCap->num_gpio_pins = AR9285_NUM_GPIO;
+       else if (AR_SREV_9280_10_OR_LATER(ah))
                pCap->num_gpio_pins = AR928X_NUM_GPIO;
        else
                pCap->num_gpio_pins = AR_NUM_GPIO;
@@ -3536,7 +3341,7 @@ bool ath9k_hw_fill_cap_info(struct ath_hal *ah)
        else
                pCap->hw_caps |= ATH9K_HW_CAP_AUTOSLEEP;
 
-       if (AR_SREV_9280(ah))
+       if (AR_SREV_9280(ah) || AR_SREV_9285(ah))
                pCap->hw_caps &= ~ATH9K_HW_CAP_4KB_SPLITTRANS;
        else
                pCap->hw_caps |= ATH9K_HW_CAP_4KB_SPLITTRANS;
@@ -3556,9 +3361,15 @@ bool ath9k_hw_fill_cap_info(struct ath_hal *ah)
        pCap->reg_cap |= AR_EEPROM_EEREGCAP_EN_FCC_MIDBAND;
 
        pCap->num_antcfg_5ghz =
-               ath9k_hw_get_num_ant_config(ah, IEEE80211_BAND_5GHZ);
+               ath9k_hw_get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_5GHZ);
        pCap->num_antcfg_2ghz =
-               ath9k_hw_get_num_ant_config(ah, IEEE80211_BAND_2GHZ);
+               ath9k_hw_get_num_ant_config(ah, ATH9K_HAL_FREQ_BAND_2GHZ);
+
+       if (AR_SREV_9280_10_OR_LATER(ah) && btcoex_enable) {
+               pCap->hw_caps |= ATH9K_HW_CAP_BT_COEX;
+               ah->ah_btactive_gpio = 6;
+               ah->ah_wlanactive_gpio = 5;
+       }
 
        return true;
 }
@@ -3738,17 +3549,18 @@ void ath9k_hw_cfg_gpio_input(struct ath_hal *ah, u32 gpio)
 
 u32 ath9k_hw_gpio_get(struct ath_hal *ah, u32 gpio)
 {
+#define MS_REG_READ(x, y) \
+       (MS(REG_READ(ah, AR_GPIO_IN_OUT), x##_GPIO_IN_VAL) & (AR_GPIO_BIT(y)))
+
        if (gpio >= ah->ah_caps.num_gpio_pins)
                return 0xffffffff;
 
-       if (AR_SREV_9280_10_OR_LATER(ah)) {
-               return (MS
-                       (REG_READ(ah, AR_GPIO_IN_OUT),
-                        AR928X_GPIO_IN_VAL) & AR_GPIO_BIT(gpio)) != 0;
-       } else {
-               return (MS(REG_READ(ah, AR_GPIO_IN_OUT), AR_GPIO_IN_VAL) &
-                       AR_GPIO_BIT(gpio)) != 0;
-       }
+       if (AR_SREV_9285_10_OR_LATER(ah))
+               return MS_REG_READ(AR9285, gpio) != 0;
+       else if (AR_SREV_9280_10_OR_LATER(ah))
+               return MS_REG_READ(AR928X, gpio) != 0;
+       else
+               return MS_REG_READ(AR, gpio) != 0;
 }
 
 void ath9k_hw_cfg_output(struct ath_hal *ah, u32 gpio,
@@ -4007,8 +3819,7 @@ void ath9k_hw_reset_tsf(struct ath_hal *ah)
                count++;
                if (count > 10) {
                        DPRINTF(ah->ah_sc, ATH_DBG_RESET,
-                               "%s: AR_SLP32_TSF_WRITE_STATUS limit exceeded\n",
-                               __func__);
+                               "AR_SLP32_TSF_WRITE_STATUS limit exceeded\n");
                        break;
                }
                udelay(10);
@@ -4033,8 +3844,7 @@ bool ath9k_hw_setslottime(struct ath_hal *ah, u32 us)
        struct ath_hal_5416 *ahp = AH5416(ah);
 
        if (us < ATH9K_SLOT_TIME_9 || us > ath9k_hw_mac_to_usec(ah, 0xffff)) {
-               DPRINTF(ah->ah_sc, ATH_DBG_RESET, "%s: bad slot time %u\n",
-                        __func__, us);
+               DPRINTF(ah->ah_sc, ATH_DBG_RESET, "bad slot time %u\n", us);
                ahp->ah_slottime = (u32) -1;
                return false;
        } else {
@@ -4056,3 +3866,30 @@ void ath9k_hw_set11nmac2040(struct ath_hal *ah, enum ath9k_ht_macmode mode)
 
        REG_WRITE(ah, AR_2040_MODE, macmode);
 }
+
+/***************************/
+/*  Bluetooth Coexistence  */
+/***************************/
+
+void ath9k_hw_btcoex_enable(struct ath_hal *ah)
+{
+       /* connect bt_active to baseband */
+       REG_CLR_BIT(ah, AR_GPIO_INPUT_EN_VAL,
+                       (AR_GPIO_INPUT_EN_VAL_BT_PRIORITY_DEF |
+                        AR_GPIO_INPUT_EN_VAL_BT_FREQUENCY_DEF));
+
+       REG_SET_BIT(ah, AR_GPIO_INPUT_EN_VAL,
+                       AR_GPIO_INPUT_EN_VAL_BT_ACTIVE_BB);
+
+       /* Set input mux for bt_active to gpio pin */
+       REG_RMW_FIELD(ah, AR_GPIO_INPUT_MUX1,
+                       AR_GPIO_INPUT_MUX1_BT_ACTIVE,
+                       ah->ah_btactive_gpio);
+
+       /* Configure the desired gpio port for input */
+       ath9k_hw_cfg_gpio_input(ah, ah->ah_btactive_gpio);
+
+       /* Configure the desired GPIO port for TX_FRAME output */
+       ath9k_hw_cfg_output(ah, ah->ah_wlanactive_gpio,
+                           AR_GPIO_OUTPUT_MUX_AS_TX_FRAME);
+}