ath9k: minor fixes for the antenna control patch
[openwrt.git] / package / mac80211 / patches / 582-ath9k_antenna_control.patch
1 --- a/drivers/net/wireless/ath/ath9k/init.c
2 +++ b/drivers/net/wireless/ath/ath9k/init.c
3 @@ -652,9 +652,22 @@ static void ath9k_init_txpower_limits(st
4         ah->curchan = curchan;
5  }
6  
7 +void ath9k_reload_chainmask_settings(struct ath_softc *sc)
8 +{
9 +       if (!(sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT))
10 +               return;
11 +
12 +       if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
13 +               setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_2GHZ].ht_cap);
14 +       if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
15 +               setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_5GHZ].ht_cap);
16 +}
17 +
18 +
19  void ath9k_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw)
20  {
21 -       struct ath_common *common = ath9k_hw_common(sc->sc_ah);
22 +       struct ath_hw *ah = sc->sc_ah;
23 +       struct ath_common *common = ath9k_hw_common(ah);
24  
25         hw->flags = IEEE80211_HW_RX_INCLUDES_FCS |
26                 IEEE80211_HW_HOST_BROADCAST_PS_BUFFERING |
27 @@ -692,6 +705,16 @@ void ath9k_set_hw_capab(struct ath_softc
28         hw->sta_data_size = sizeof(struct ath_node);
29         hw->vif_data_size = sizeof(struct ath_vif);
30  
31 +       hw->wiphy->available_antennas_rx = BIT(ah->caps.max_rxchains) - 1;
32 +       hw->wiphy->available_antennas_tx = BIT(ah->caps.max_txchains) - 1;
33 +
34 +       /* single chain devices with rx diversity */
35 +       if (ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
36 +               hw->wiphy->available_antennas_rx = BIT(0) | BIT(1);
37 +
38 +       sc->ant_rx = hw->wiphy->available_antennas_rx;
39 +       sc->ant_tx = hw->wiphy->available_antennas_tx;
40 +
41  #ifdef CONFIG_ATH9K_RATE_CONTROL
42         hw->rate_control_algorithm = "ath9k_rate_control";
43  #endif
44 @@ -703,12 +726,7 @@ void ath9k_set_hw_capab(struct ath_softc
45                 hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
46                         &sc->sbands[IEEE80211_BAND_5GHZ];
47  
48 -       if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_HT) {
49 -               if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_2GHZ)
50 -                       setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_2GHZ].ht_cap);
51 -               if (sc->sc_ah->caps.hw_caps & ATH9K_HW_CAP_5GHZ)
52 -                       setup_ht_cap(sc, &sc->sbands[IEEE80211_BAND_5GHZ].ht_cap);
53 -       }
54 +       ath9k_reload_chainmask_settings(sc);
55  
56         SET_IEEE80211_PERM_ADDR(hw, common->macaddr);
57  }
58 --- a/drivers/net/wireless/ath/ath9k/ath9k.h
59 +++ b/drivers/net/wireless/ath/ath9k/ath9k.h
60 @@ -652,6 +652,7 @@ struct ath_softc {
61         struct ath_descdma txsdma;
62  
63         struct ath_ant_comb ant_comb;
64 +       u8 ant_tx, ant_rx;
65  };
66  
67  void ath9k_tasklet(unsigned long data);
68 @@ -673,6 +674,7 @@ int ath9k_init_device(u16 devid, struct 
69                     const struct ath_bus_ops *bus_ops);
70  void ath9k_deinit_device(struct ath_softc *sc);
71  void ath9k_set_hw_capab(struct ath_softc *sc, struct ieee80211_hw *hw);
72 +void ath9k_reload_chainmask_settings(struct ath_softc *sc);
73  
74  void ath_radio_disable(struct ath_softc *sc, struct ieee80211_hw *hw);
75  bool ath9k_uses_beacons(int type);
76 --- a/drivers/net/wireless/ath/ath9k/main.c
77 +++ b/drivers/net/wireless/ath/ath9k/main.c
78 @@ -262,6 +262,22 @@ static bool ath_complete_reset(struct at
79                         ath_start_ani(common);
80         }
81  
82 +       if (ath9k_hw_ops(ah)->antdiv_comb_conf_get && sc->ant_rx != 3) {
83 +               struct ath_hw_antcomb_conf div_ant_conf;
84 +               u8 lna_conf;
85 +
86 +               ath9k_hw_antdiv_comb_conf_get(ah, &div_ant_conf);
87 +
88 +               if (sc->ant_rx == 1)
89 +                       lna_conf = ATH_ANT_DIV_COMB_LNA1;
90 +               else
91 +                       lna_conf = ATH_ANT_DIV_COMB_LNA2;
92 +               div_ant_conf.main_lna_conf = lna_conf;
93 +               div_ant_conf.alt_lna_conf = lna_conf;
94 +
95 +               ath9k_hw_antdiv_comb_conf_set(ah, &div_ant_conf);
96 +       }
97 +
98         ieee80211_wake_queues(sc->hw);
99  
100         return true;
101 @@ -2360,6 +2376,59 @@ static int ath9k_get_stats(struct ieee80
102         return 0;
103  }
104  
105 +static u32 fill_chainmask(u32 cap, u32 new)
106 +{
107 +       u32 filled = 0;
108 +       int i;
109 +
110 +       for (i = 0; cap && new; i++, cap >>= 1) {
111 +               if (!(cap & BIT(0)))
112 +                       continue;
113 +
114 +               if (new & BIT(0))
115 +                       filled |= BIT(i);
116 +
117 +               new >>= 1;
118 +       }
119 +
120 +       return filled;
121 +}
122 +
123 +static int ath9k_set_antenna(struct ieee80211_hw *hw, u32 tx_ant, u32 rx_ant)
124 +{
125 +       struct ath_softc *sc = hw->priv;
126 +       struct ath_hw *ah = sc->sc_ah;
127 +
128 +       if (!rx_ant || !tx_ant)
129 +               return -EINVAL;
130 +
131 +       sc->ant_rx = rx_ant;
132 +       sc->ant_tx = tx_ant;
133 +
134 +       if (ah->caps.rx_chainmask == 1)
135 +               return 0;
136 +
137 +       /* AR9100 runs into calibration issues if not all rx chains are enabled */
138 +       if (AR_SREV_9100(ah))
139 +               ah->rxchainmask = 0x7;
140 +       else
141 +               ah->rxchainmask = fill_chainmask(ah->caps.rx_chainmask, rx_ant);
142 +
143 +       ah->txchainmask = fill_chainmask(ah->caps.tx_chainmask, tx_ant);
144 +       ath9k_reload_chainmask_settings(sc);
145 +
146 +       return 0;
147 +}
148 +
149 +static int ath9k_get_antenna(struct ieee80211_hw *hw, u32 *tx_ant, u32 *rx_ant)
150 +{
151 +       struct ath_softc *sc = hw->priv;
152 +
153 +       *tx_ant = sc->ant_tx;
154 +       *rx_ant = sc->ant_rx;
155 +       return 0;
156 +}
157 +
158  struct ieee80211_ops ath9k_ops = {
159         .tx                 = ath9k_tx,
160         .start              = ath9k_start,
161 @@ -2386,4 +2455,6 @@ struct ieee80211_ops ath9k_ops = {
162         .tx_frames_pending  = ath9k_tx_frames_pending,
163         .tx_last_beacon     = ath9k_tx_last_beacon,
164         .get_stats          = ath9k_get_stats,
165 +       .set_antenna        = ath9k_set_antenna,
166 +       .get_antenna        = ath9k_get_antenna,
167  };
168 --- a/drivers/net/wireless/ath/ath9k/recv.c
169 +++ b/drivers/net/wireless/ath/ath9k/recv.c
170 @@ -1956,7 +1956,7 @@ int ath_rx_tasklet(struct ath_softc *sc,
171                         ath_rx_ps(sc, skb);
172                 spin_unlock_irqrestore(&sc->sc_pm_lock, flags);
173  
174 -               if (ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB)
175 +               if ((ah->caps.hw_caps & ATH9K_HW_CAP_ANT_DIV_COMB) && sc->ant_rx == 3)
176                         ath_ant_comb_scan(sc, &rs);
177  
178                 ieee80211_rx(hw, skb);