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