]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
ath9k: implement .get_antenna and .set_antenna
authorFelix Fietkau <nbd@openwrt.org>
Fri, 2 Sep 2011 23:40:27 +0000 (01:40 +0200)
committerJohn W. Linville <linville@tuxdriver.com>
Wed, 14 Sep 2011 17:56:22 +0000 (13:56 -0400)
On MIMO chips this can be used to enable/disable hardware chains, ensuring
that the MCS information is updated accordingly.
On non-MIMO chips with rx diversity (e.g. 9285), this configures the rx
input antenna.

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
Signed-off-by: John W. Linville <linville@tuxdriver.com>
drivers/net/wireless/ath/ath9k/ath9k.h
drivers/net/wireless/ath/ath9k/init.c
drivers/net/wireless/ath/ath9k/main.c
drivers/net/wireless/ath/ath9k/recv.c

index b2992d4097c3d4f4c35d9b9fc1d9c344aaf9ea8f..0fb4a26f89797f53d875327246d7e1c1c50c678e 100644 (file)
@@ -649,6 +649,7 @@ struct ath_softc {
        struct ath_descdma txsdma;
 
        struct ath_ant_comb ant_comb;
+       u8 ant_tx, ant_rx;
 };
 
 void ath9k_tasklet(unsigned long data);
@@ -669,6 +670,7 @@ int ath9k_init_device(u16 devid, struct ath_softc *sc,
                    const struct ath_bus_ops *bus_ops);
 void ath9k_deinit_device(struct ath_softc *sc);
 void ath9k_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw);
+void ath9k_reload_chainmask_settings(struct ath_softc *sc);
 
 void ath_radio_disable(struct ath_softc *sc, struct ieee80211_hw *hw);
 bool ath9k_uses_beacons(int type);
index be302fbdc3dc3588a247dd66b187aa9671c4cd9e..9b34c4bab9372621dba1b82d4eb340b80b5e1e71 100644 (file)
@@ -653,9 +653,22 @@ static void ath9k_init_txpower_limits(struct ath_softc *sc)
        ah->curchan = curchan;
 }
 
+void ath9k_reload_chainmask_settings(struct ath_softc *sc)
+{
+       if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT))
+               return;
+
+       if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
+               setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_2GHZ].ht_cap);
+       if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
+               setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_5GHZ].ht_cap);
+}
+
+
 void ath9k_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
 {
-       struct ath_common *common = ath9k_hw_common(sc->sc_ah);
+       struct ath_hw *ah = sc->sc_ah;
+       struct ath_common *common = ath9k_hw_common(ah);
 
        hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
                IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
@@ -693,6 +706,16 @@ void ath9k_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
        hw->sta_data_size = sizeof(struct ath_node);
        hw->vif_data_size = sizeof(struct ath_vif);
 
+       hw->wiphy->available_antennas_rx = BIT(ah->caps.max_rxchains) - 1;
+       hw->wiphy->available_antennas_tx = BIT(ah->caps.max_txchains) - 1;
+
+       /* single chain devices with rx diversity */
+       if (ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
+               hw->wiphy->available_antennas_rx = BIT(0) | BIT(1);
+
+       sc->ant_rx = hw->wiphy->available_antennas_rx;
+       sc->ant_tx = hw->wiphy->available_antennas_tx;
+
 #ifdef CONFIG_ATH9K_RATE_CONTROL
        hw->rate_control_algorithm = "ath9k_rate_control";
 #endif
@@ -704,12 +727,7 @@ void ath9k_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
                hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
                        &sc->sbands[IEEE80211_BAND_5GHZ];
 
-       if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
-               if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
-                       setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_2GHZ].ht_cap);
-               if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
-                       setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_5GHZ].ht_cap);
-       }
+       ath9k_reload_chainmask_settings(sc);
 
        SET_IEEE80211_PERM_ADDR(hw, common->macaddr);
 }
index 19c78be3dc414e74ab78bd605688998daad05fa9..c8ac2ce61ffe86e218cfc96d8b049f3b985b79cc 100644 (file)
@@ -281,6 +281,22 @@ static bool ath_complete_reset(struct ath_softc *sc, bool start)
                        ath_start_ani(common);
        }
 
+       if (ath9k_hw_ops(ah)->antdiv_comb_conf_get && sc->ant_rx != 3) {
+               struct ath_hw_antcomb_conf div_ant_conf;
+               u8 lna_conf;
+
+               ath9k_hw_antdiv_comb_conf_get(ah, &div_ant_conf);
+
+               if (sc->ant_rx == 1)
+                       lna_conf = ATH_ANT_DIV_COMB_LNA1;
+               else
+                       lna_conf = ATH_ANT_DIV_COMB_LNA2;
+               div_ant_conf.main_lna_conf = lna_conf;
+               div_ant_conf.alt_lna_conf = lna_conf;
+
+               ath9k_hw_antdiv_comb_conf_set(ah, &div_ant_conf);
+       }
+
        ieee80211_wake_queues(sc->hw);
 
        return true;
@@ -2379,6 +2395,59 @@ static int ath9k_get_stats(struct ieee80211_hw *hw,
        return 0;
 }
 
+static u32 fill_chainmask(u32 cap, u32 new)
+{
+       u32 filled = 0;
+       int i;
+
+       for (i = 0; cap && new; i++, cap >>= 1) {
+               if (!(cap & BIT(0)))
+                       continue;
+
+               if (new & BIT(0))
+                       filled |= BIT(i);
+
+               new >>= 1;
+       }
+
+       return filled;
+}
+
+static int ath9k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
+{
+       struct ath_softc *sc = hw->priv;
+       struct ath_hw *ah = sc->sc_ah;
+
+       if (!rx_ant || !tx_ant)
+               return -EINVAL;
+
+       sc->ant_rx = rx_ant;
+       sc->ant_tx = tx_ant;
+
+       if (ah->caps.rx_chainmask == 1)
+               return 0;
+
+       /* AR9100 runs into calibration issues if not all rx chains are enabled */
+       if (AR_SREV_9100(ah))
+               ah->rxchainmask = 0x7;
+       else
+               ah->rxchainmask = fill_chainmask(ah->caps.rx_chainmask, rx_ant);
+
+       ah->txchainmask = fill_chainmask(ah->caps.tx_chainmask, tx_ant);
+       ath9k_reload_chainmask_settings(sc);
+
+       return 0;
+}
+
+static int ath9k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
+{
+       struct ath_softc *sc = hw->priv;
+
+       *tx_ant = sc->ant_tx;
+       *rx_ant = sc->ant_rx;
+       return 0;
+}
+
 struct ieee80211_ops ath9k_ops = {
        .tx                 = ath9k_tx,
        .start              = ath9k_start,
@@ -2405,4 +2474,6 @@ struct ieee80211_ops ath9k_ops = {
        .tx_frames_pending  = ath9k_tx_frames_pending,
        .tx_last_beacon     = ath9k_tx_last_beacon,
        .get_stats          = ath9k_get_stats,
+       .set_antenna        = ath9k_set_antenna,
+       .get_antenna        = ath9k_get_antenna,
 };
index 9c7f905f3871b6e4ac76ce542f7306ddb317c08c..8d3e19dfe7db496021c4b49ca940058981cc9958 100644 (file)
@@ -1950,7 +1950,7 @@ int ath_rx_tasklet(struct ath_softc *sc, int flush, bool hp)
                        ath_rx_ps(sc, skb);
                spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
 
-               if (ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
+               if ((ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) && sc->ant_rx == 3)
                        ath_ant_comb_scan(sc, &rs);
 
                ieee80211_rx(hw, skb);