#define SC_OP_RFKILL_REGISTERED        BIT(11)
 #define SC_OP_RFKILL_SW_BLOCKED        BIT(12)
 #define SC_OP_RFKILL_HW_BLOCKED        BIT(13)
+#define SC_OP_WAIT_FOR_BEACON  BIT(14)
 
 struct ath_bus_ops {
        void            (*read_cachesize)(struct ath_softc *sc, int *csz);
        u32 sc_keymax;
        DECLARE_BITMAP(sc_keymap, ATH_KEYMAX);
        u8 sc_splitmic;
+       atomic_t ps_usecount;
        enum ath9k_int sc_imask;
        enum PROT_MODE sc_protmode;
        enum ath9k_ht_extprotspacing sc_ht_extprotspacing;
 static inline void ath_ahb_exit(void) {};
 #endif
 
+static inline void ath9k_ps_wakeup(struct ath_softc *sc)
+{
+       if (atomic_inc_return(&sc->ps_usecount) == 1)
+               if (sc->sc_ah->ah_power_mode !=  ATH9K_PM_AWAKE) {
+                       sc->sc_ah->ah_restore_mode = sc->sc_ah->ah_power_mode;
+                       ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
+               }
+}
+
+static inline void ath9k_ps_restore(struct ath_softc *sc)
+{
+       if (atomic_dec_and_test(&sc->ps_usecount))
+               if (sc->hw->conf.flags & IEEE80211_CONF_PS)
+                       ath9k_hw_setpower(sc->sc_ah,
+                                         sc->sc_ah->ah_restore_mode);
+}
 #endif /* CORE_H */
 
        if (sc->sc_flags & SC_OP_INVALID)
                return -EIO;
 
+       ath9k_ps_wakeup(sc);
+
        /*
         * This is only performed if the channel settings have
         * actually changed.
        ath_cache_conf_rate(sc, &hw->conf);
        ath_update_txpow(sc);
        ath9k_hw_set_interrupts(ah, sc->sc_imask);
+       ath9k_ps_restore(sc);
        return 0;
 }
 
                                      ATH9K_HW_CAP_AUTOSLEEP)) {
                                        /* Clear RxAbort bit so that we can
                                         * receive frames */
+                                       ath9k_hw_setpower(ah, ATH9K_PM_AWAKE);
                                        ath9k_hw_setrxabort(ah, 0);
                                        sched = true;
+                                       sc->sc_flags |= SC_OP_WAIT_FOR_BEACON;
                                }
                        }
                }
        struct ieee80211_channel *channel = sc->hw->conf.channel;
        int r;
 
+       ath9k_ps_wakeup(sc);
        spin_lock_bh(&sc->sc_resetlock);
 
        r = ath9k_hw_reset(ah, ah->ah_curchan, false);
        ath9k_hw_set_gpio(ah, ATH_LED_PIN, 0);
 
        ieee80211_wake_queues(sc->hw);
+       ath9k_ps_restore(sc);
 }
 
 static void ath_radio_disable(struct ath_softc *sc)
        struct ieee80211_channel *channel = sc->hw->conf.channel;
        int r;
 
+       ath9k_ps_wakeup(sc);
        ieee80211_stop_queues(sc->hw);
 
        /* Disable LED */
 
        ath9k_hw_phy_disable(ah);
        ath9k_hw_setpower(ah, ATH9K_PM_FULL_SLEEP);
+       ath9k_ps_restore(sc);
 }
 
 static bool ath_is_rfkill_set(struct ath_softc *sc)
        struct ieee80211_hw *hw = sc->hw;
        int i = 0;
 
+       ath9k_ps_wakeup(sc);
+
        DPRINTF(sc, ATH_DBG_CONFIG, "Detach ATH hw\n");
 
 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
 
        ath9k_hw_detach(sc->sc_ah);
        ath9k_exit_debug(sc);
+       ath9k_ps_restore(sc);
 }
 
 static int ath_init(u16 devid, struct ath_softc *sc)
        hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
                IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
                IEEE80211_HW_SIGNAL_DBM |
-               IEEE80211_HW_AMPDU_AGGREGATION;
+               IEEE80211_HW_AMPDU_AGGREGATION |
+               IEEE80211_HW_SUPPORTS_PS |
+               IEEE80211_HW_PS_NULLFUNC_STACK;
 
        if (AR_SREV_9160_10_OR_LATER(sc->sc_ah))
                hw->flags |= IEEE80211_HW_MFP_CAPABLE;
        struct ieee80211_conf *conf = &hw->conf;
 
        mutex_lock(&sc->mutex);
+       if (changed & IEEE80211_CONF_CHANGE_PS) {
+               if (conf->flags & IEEE80211_CONF_PS) {
+                       if ((sc->sc_imask & ATH9K_INT_TIM_TIMER) == 0) {
+                               sc->sc_imask |= ATH9K_INT_TIM_TIMER;
+                               ath9k_hw_set_interrupts(sc->sc_ah,
+                                               sc->sc_imask);
+                       }
+                       ath9k_hw_setrxabort(sc->sc_ah, 1);
+                       ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_NETWORK_SLEEP);
+               } else {
+                       ath9k_hw_setpower(sc->sc_ah, ATH9K_PM_AWAKE);
+                       ath9k_hw_setrxabort(sc->sc_ah, 0);
+                       sc->sc_flags &= ~SC_OP_WAIT_FOR_BEACON;
+                       if (sc->sc_imask & ATH9K_INT_TIM_TIMER) {
+                               sc->sc_imask &= ~ATH9K_INT_TIM_TIMER;
+                               ath9k_hw_set_interrupts(sc->sc_ah,
+                                               sc->sc_imask);
+                       }
+               }
+       }
+
        if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
                struct ieee80211_channel *curchan = hw->conf.channel;
                int pos;
        struct ath_softc *sc = hw->priv;
        int ret = 0;
 
+       ath9k_ps_wakeup(sc);
        DPRINTF(sc, ATH_DBG_KEYCACHE, "Set HW Key\n");
 
        switch (cmd) {
                ret = -EINVAL;
        }
 
+       ath9k_ps_restore(sc);
        return ret;
 }