[package] mac80211: add rt2800 patches from the rt2x00 git rope
[openwrt.git] / package / mac80211 / patches / 313-rt2x00-Channel-HT40-fixes-rt2800usb.patch
1 From c2288ea288283cea727dfa547339d245458071fc Mon Sep 17 00:00:00 2001
2 From: Ivo van Doorn <IvDoorn@gmail.com>
3 Date: Sun, 8 Feb 2009 00:09:22 +0100
4 Subject: [PATCH] rt2x00: Channel HT40+/- fixes (rt2800usb)
5
6 Signed-off-by: Ivo van Doorn <IvDoorn@gmail.com>
7 ---
8  drivers/net/wireless/rt2x00/rt2800usb.c |  107 ++++++++++++++++--------------
9  drivers/net/wireless/rt2x00/rt2800usb.h |    5 +-
10  2 files changed, 61 insertions(+), 51 deletions(-)
11
12 --- a/drivers/net/wireless/rt2x00/rt2800usb.c
13 +++ b/drivers/net/wireless/rt2x00/rt2800usb.c
14 @@ -641,7 +641,7 @@ static void rt2800usb_config_ant(struct 
15                 rt2x00_set_field8(&r3, BBP3_RX_ANTENNA, 0);
16                 break;
17         case 2:
18 -               rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 16);
19 +               rt2x00_set_field8(&r1, BBP1_TX_ANTENNA, 2);
20                 break;
21         case 3:
22                 /* Do nothing */
23 @@ -691,6 +691,7 @@ static void rt2800usb_config_lna_gain(st
24  }
25  
26  static void rt2800usb_config_channel_rt2x(struct rt2x00_dev *rt2x00dev,
27 +                                         struct ieee80211_conf *conf,
28                                           struct rf_channel *rf,
29                                           struct channel_info *info)
30  {
31 @@ -702,6 +703,7 @@ static void rt2800usb_config_channel_rt2
32          * Determine antenna settings from EEPROM
33          */
34         rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
35 +
36         if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TXPATH) == 1)
37                 rt2x00_set_field32(&rf->rf2, RF2_ANTENNA_TX1, 1);
38  
39 @@ -742,8 +744,7 @@ static void rt2800usb_config_channel_rt2
40                                    TXPOWER_G_TO_DEV(info->tx_power2));
41         }
42  
43 -       rt2x00_set_field32(&rf->rf4, RF4_BW40,
44 -                          test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags));
45 +       rt2x00_set_field32(&rf->rf4, RF4_HT40, conf_is_ht40(conf));
46  
47         rt2800usb_rf_write(rt2x00dev, 1, rf->rf1);
48         rt2800usb_rf_write(rt2x00dev, 2, rf->rf2);
49 @@ -766,6 +767,7 @@ static void rt2800usb_config_channel_rt2
50  }
51  
52  static void rt2800usb_config_channel_rt3x(struct rt2x00_dev *rt2x00dev,
53 +                                         struct ieee80211_conf *conf,
54                                           struct rf_channel *rf,
55                                           struct channel_info *info)
56  {
57 @@ -787,10 +789,12 @@ static void rt2800usb_config_channel_rt3
58         rt2x00_set_field8(&rfcsr, RFCSR23_FREQ_OFFSET, rt2x00dev->freq_offset);
59         rt2800usb_rfcsr_write(rt2x00dev, 23, rfcsr);
60  
61 -       if (test_bit(CONFIG_CHANNEL_HT40, &rt2x00dev->flags))
62 -               rt2800usb_rfcsr_write(rt2x00dev, 24, rt2x00dev->calibration_bw40);
63 +       if (conf_is_ht40(conf))
64 +               rt2800usb_rfcsr_write(rt2x00dev, 24,
65 +                                     rt2x00dev->calibration_bw40);
66         else
67 -               rt2800usb_rfcsr_write(rt2x00dev, 24, rt2x00dev->calibration_bw20);
68 +               rt2800usb_rfcsr_write(rt2x00dev, 24,
69 +                                     rt2x00dev->calibration_bw20);
70  
71         rt2800usb_rfcsr_read(rt2x00dev, 23, &rfcsr);
72         rt2x00_set_field8(&rfcsr, RFCSR7_RF_TUNING, 1);
73 @@ -798,46 +802,24 @@ static void rt2800usb_config_channel_rt3
74  }
75  
76  static void rt2800usb_config_channel(struct rt2x00_dev *rt2x00dev,
77 +                                    struct ieee80211_conf *conf,
78                                      struct rf_channel *rf,
79                                      struct channel_info *info)
80  {
81         u32 reg;
82         unsigned int tx_pin;
83         u16 eeprom;
84 +       u8 bbp;
85  
86 -       if (rt2x00_rev(&rt2x00dev->chip) != RT3070_VERSION)
87 -               rt2800usb_config_channel_rt2x(rt2x00dev, rf, info);
88 -       else
89 -               rt2800usb_config_channel_rt3x(rt2x00dev, rf, info);
90 -
91 -       tx_pin = 0;
92 -       rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN, 1);
93 -       rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A0_EN, 1);
94 -       rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G0_EN, 1);
95 -       rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A1_EN, 1);
96 -       rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G1_EN, 1);
97 -       rt2x00_set_field32(&tx_pin, TX_PIN_CFG_RFTR_EN, 1);
98 -       rt2x00_set_field32(&tx_pin, TX_PIN_CFG_TRSW_EN, 1);
99 -
100 +       /*
101 +        * Determine antenna settings from EEPROM
102 +        */
103         rt2x00_eeprom_read(rt2x00dev, EEPROM_ANTENNA, &eeprom);
104  
105 -       /* Turn off unused PA or LNA when only 1T or 1R */
106 -       if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TXPATH) == 1) {
107 -               
108 -               rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A1_EN, 0);
109 -               rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN, 0);
110 -       }
111 -
112 -       /* Turn off unused PA or LNA when only 1T or 1R */
113 -       if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RXPATH) == 1) {
114 -               rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A1_EN, 0);
115 -               rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G1_EN, 0);
116 -       }
117 -
118 -       if (rf->channel > 14)
119 -               rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A0_EN, 1);
120 +       if (rt2x00_rev(&rt2x00dev->chip) != RT3070_VERSION)
121 +               rt2800usb_config_channel_rt2x(rt2x00dev, conf, rf, info);
122         else
123 -               rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN, 1);
124 +               rt2800usb_config_channel_rt3x(rt2x00dev, conf, rf, info);
125  
126         /*
127          * Change BBP settings
128 @@ -855,11 +837,6 @@ static void rt2800usb_config_channel(str
129                         rt2800usb_bbp_write(rt2x00dev, 82, 0x84);
130                         rt2800usb_bbp_write(rt2x00dev, 75, 0x50);
131                 }
132 -
133 -               rt2x00usb_register_read(rt2x00dev, TX_BAND_CFG, &reg);
134 -               rt2x00_set_field32(&rf->rf3, TX_BAND_CFG_A, 0);
135 -               rt2x00_set_field32(&rf->rf3, TX_BAND_CFG_BG, 1);
136 -               rt2x00usb_register_write(rt2x00dev, TX_BAND_CFG, reg);
137         } else {
138                 rt2800usb_bbp_write(rt2x00dev, 82, 0xf2);
139  
140 @@ -867,15 +844,45 @@ static void rt2800usb_config_channel(str
141                         rt2800usb_bbp_write(rt2x00dev, 75, 0x46);
142                 else
143                         rt2800usb_bbp_write(rt2x00dev, 75, 0x50);
144 +       }
145 +
146 +       rt2x00usb_register_read(rt2x00dev, TX_BAND_CFG, &reg);
147 +       rt2x00_set_field32(&reg, TX_BAND_CFG_HT40_PLUS, conf_is_ht40_plus(conf));
148 +       rt2x00_set_field32(&reg, TX_BAND_CFG_A, rf->channel > 14);
149 +       rt2x00_set_field32(&reg, TX_BAND_CFG_BG, rf->channel <= 14);
150 +       rt2x00usb_register_write(rt2x00dev, TX_BAND_CFG, reg);
151 +
152 +       tx_pin = 0;
153 +
154 +       /* Turn on unused PA or LNA when not using 1T or 1R */
155 +       if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_TXPATH) != 1) {
156 +               rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A1_EN, 1);
157 +               rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G1_EN, 1);
158 +       }
159  
160 -               rt2x00usb_register_read(rt2x00dev, TX_BAND_CFG, &reg);
161 -               rt2x00_set_field32(&rf->rf3, TX_BAND_CFG_A, 1);
162 -               rt2x00_set_field32(&rf->rf3, TX_BAND_CFG_BG, 0);
163 -               rt2x00usb_register_write(rt2x00dev, TX_BAND_CFG, reg);
164 +       /* Turn on unused PA or LNA when not using 1T or 1R */
165 +       if (rt2x00_get_field16(eeprom, EEPROM_ANTENNA_RXPATH) != 1) {
166 +               rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A1_EN, 1);
167 +               rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G1_EN, 1);
168         }
169  
170 +       rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_A0_EN, 1);
171 +       rt2x00_set_field32(&tx_pin, TX_PIN_CFG_LNA_PE_G0_EN, 1);
172 +       rt2x00_set_field32(&tx_pin, TX_PIN_CFG_RFTR_EN, 1);
173 +       rt2x00_set_field32(&tx_pin, TX_PIN_CFG_TRSW_EN, 1);
174 +       rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_G0_EN, rf->channel <= 14);
175 +       rt2x00_set_field32(&tx_pin, TX_PIN_CFG_PA_PE_A0_EN, rf->channel > 14);
176 +
177         rt2x00usb_register_write(rt2x00dev, TX_PIN_CFG, tx_pin);
178  
179 +       rt2800usb_bbp_read(rt2x00dev, 4, &bbp);
180 +       rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2 * conf_is_ht40(conf));
181 +       rt2800usb_bbp_write(rt2x00dev, 4, bbp);
182 +
183 +       rt2800usb_bbp_read(rt2x00dev, 3, &bbp);
184 +       rt2x00_set_field8(&bbp, BBP3_HT40_PLUS, conf_is_ht40_plus(conf));
185 +       rt2800usb_bbp_write(rt2x00dev, 3, bbp);
186 +
187         msleep(1);
188  }
189  
190 @@ -1008,8 +1015,8 @@ static void rt2800usb_config(struct rt2x
191         rt2800usb_config_lna_gain(rt2x00dev, libconf);
192  
193         if (flags & IEEE80211_CONF_CHANGE_CHANNEL)
194 -               rt2800usb_config_channel(rt2x00dev, &libconf->rf,
195 -                                        &libconf->channel);
196 +               rt2800usb_config_channel(rt2x00dev, libconf->conf,
197 +                                        &libconf->rf, &libconf->channel);
198         if (flags & IEEE80211_CONF_CHANGE_POWER)
199                 rt2800usb_config_txpower(rt2x00dev, libconf->conf->power_level);
200         if (flags & IEEE80211_CONF_CHANGE_RETRY_LIMITS)
201 @@ -1643,7 +1650,7 @@ static u8 rt2800usb_init_rx_filter(struc
202  
203         if (bw40) {
204                 rt2800usb_bbp_read(rt2x00dev, 4, &bbp);
205 -               rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 0x10);
206 +               rt2x00_set_field8(&bbp, BBP4_BANDWIDTH, 2);
207                 rt2800usb_bbp_write(rt2x00dev, 4, bbp);
208         }
209  
210 @@ -2777,14 +2784,14 @@ static const struct rt2x00lib_ops rt2800
211  
212  static const struct data_queue_desc rt2800usb_queue_rx = {
213         .entry_num              = RX_ENTRIES,
214 -       .data_size              = DATA_FRAME_SIZE,
215 +       .data_size              = AGGREGATION_SIZE,
216         .desc_size              = RXD_DESC_SIZE + RXWI_DESC_SIZE,
217         .priv_size              = sizeof(struct queue_entry_priv_usb),
218  };
219  
220  static const struct data_queue_desc rt2800usb_queue_tx = {
221         .entry_num              = TX_ENTRIES,
222 -       .data_size              = DATA_FRAME_SIZE,
223 +       .data_size              = AGGREGATION_SIZE,
224         .desc_size              = TXINFO_DESC_SIZE + TXWI_DESC_SIZE,
225         .priv_size              = sizeof(struct queue_entry_priv_usb),
226  };
227 --- a/drivers/net/wireless/rt2x00/rt2800usb.h
228 +++ b/drivers/net/wireless/rt2x00/rt2800usb.h
229 @@ -803,6 +803,7 @@
230   * TX_BAND_CFG: 0x1 use upper 20MHz, 0x0 use lower 20MHz
231   */
232  #define TX_BAND_CFG                    0x132c
233 +#define TX_BAND_CFG_HT40_PLUS          FIELD32(0x00000001)
234  #define TX_BAND_CFG_A                  FIELD32(0x00000002)
235  #define TX_BAND_CFG_BG                 FIELD32(0x00000004)
236  
237 @@ -1482,10 +1483,12 @@ struct mac_iveiv_entry {
238   * BBP 3: RX Antenna
239   */
240  #define BBP3_RX_ANTENNA                        FIELD8(0x18)
241 +#define BBP3_HT40_PLUS                 FIELD8(0x20)
242  
243  /*
244   * BBP 4: Bandwidth
245   */
246 +#define BBP4_TX_BF                     FIELD8(0x01)
247  #define BBP4_BANDWIDTH                 FIELD8(0x18)
248  
249  /*
250 @@ -1548,7 +1551,7 @@ struct mac_iveiv_entry {
251  #define RF4_TXPOWER_A_7DBM_BOOST       FIELD32(0x00000040)
252  #define RF4_TXPOWER_A                  FIELD32(0x00000780)
253  #define RF4_FREQ_OFFSET                        FIELD32(0x001f8000)
254 -#define RF4_BW40                       FIELD32(0x00200000)
255 +#define RF4_HT40                       FIELD32(0x00200000)
256  
257  /*
258   * EEPROM content.