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