1 From 6e3a17190815c6aa4dc53c2cfe9125fb1154f187 Mon Sep 17 00:00:00 2001
2 From: Gabor Juhos <juhosg@openwrt.org>
3 Date: Sun, 24 Mar 2013 19:26:27 +0100
4 Subject: [PATCH] rt2x00: rt2800lib: add channel configuration function for
7 Signed-off-by: Gabor Juhos <juhosg@openwrt.org>
9 drivers/net/wireless/ralink/rt2x00/rt2800lib.c | 208 +++++++++++++++++++++++++++++++
10 1 file changed, 208 insertions(+)
12 --- a/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
13 +++ b/drivers/net/wireless/ralink/rt2x00/rt2800lib.c
14 @@ -2880,6 +2880,211 @@ static void rt2800_config_channel_rf3053
18 +static void rt2800_config_channel_rf3853(struct rt2x00_dev *rt2x00dev,
19 + struct ieee80211_conf *conf,
20 + struct rf_channel *rf,
21 + struct channel_info *info)
25 + u8 pwr1, pwr2, pwr3;
27 + const bool txbf_enabled = false; /* TODO */
29 + /* TODO: add band selection */
31 + if (rf->channel <= 14)
32 + rt2800_rfcsr_write(rt2x00dev, 6, 0x40);
33 + else if (rf->channel < 132)
34 + rt2800_rfcsr_write(rt2x00dev, 6, 0x80);
36 + rt2800_rfcsr_write(rt2x00dev, 6, 0x40);
38 + rt2800_rfcsr_write(rt2x00dev, 8, rf->rf1);
39 + rt2800_rfcsr_write(rt2x00dev, 9, rf->rf3);
41 + if (rf->channel <= 14)
42 + rt2800_rfcsr_write(rt2x00dev, 11, 0x46);
44 + rt2800_rfcsr_write(rt2x00dev, 11, 0x48);
46 + if (rf->channel <= 14)
47 + rt2800_rfcsr_write(rt2x00dev, 12, 0x1a);
49 + rt2800_rfcsr_write(rt2x00dev, 12, 0x52);
51 + rt2800_rfcsr_write(rt2x00dev, 13, 0x12);
53 + rfcsr = rt2800_rfcsr_read(rt2x00dev, 1);
54 + rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 0);
55 + rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 0);
56 + rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 0);
57 + rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 0);
58 + rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 0);
59 + rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 0);
60 + rt2x00_set_field8(&rfcsr, RFCSR1_RF_BLOCK_EN, 1);
61 + rt2x00_set_field8(&rfcsr, RFCSR1_PLL_PD, 1);
63 + switch (rt2x00dev->default_ant.tx_chain_num) {
65 + rt2x00_set_field8(&rfcsr, RFCSR1_TX2_PD, 1);
68 + rt2x00_set_field8(&rfcsr, RFCSR1_TX1_PD, 1);
71 + rt2x00_set_field8(&rfcsr, RFCSR1_TX0_PD, 1);
75 + switch (rt2x00dev->default_ant.rx_chain_num) {
77 + rt2x00_set_field8(&rfcsr, RFCSR1_RX2_PD, 1);
80 + rt2x00_set_field8(&rfcsr, RFCSR1_RX1_PD, 1);
83 + rt2x00_set_field8(&rfcsr, RFCSR1_RX0_PD, 1);
86 + rt2800_rfcsr_write(rt2x00dev, 1, rfcsr);
88 + rt2800_freq_cal_mode1(rt2x00dev);
90 + rfcsr = rt2800_rfcsr_read(rt2x00dev, 30);
91 + if (!conf_is_ht40(conf))
95 + rt2800_rfcsr_write(rt2x00dev, 30, rfcsr);
97 + if (rf->channel <= 14)
98 + rt2800_rfcsr_write(rt2x00dev, 31, 0xa0);
100 + rt2800_rfcsr_write(rt2x00dev, 31, 0x80);
102 + if (conf_is_ht40(conf))
103 + rt2800_rfcsr_write(rt2x00dev, 32, 0x80);
105 + rt2800_rfcsr_write(rt2x00dev, 32, 0xd8);
107 + if (rf->channel <= 14)
108 + rt2800_rfcsr_write(rt2x00dev, 34, 0x3c);
110 + rt2800_rfcsr_write(rt2x00dev, 34, 0x20);
112 + /* loopback RF_BS */
113 + rfcsr = rt2800_rfcsr_read(rt2x00dev, 36);
114 + if (rf->channel <= 14)
115 + rt2x00_set_field8(&rfcsr, RFCSR36_RF_BS, 1);
117 + rt2x00_set_field8(&rfcsr, RFCSR36_RF_BS, 0);
118 + rt2800_rfcsr_write(rt2x00dev, 36, rfcsr);
120 + if (rf->channel <= 14)
122 + else if (rf->channel < 100)
124 + else if (rf->channel < 132)
132 + rt2800_rfcsr_write(rt2x00dev, 39, rfcsr);
134 + if (rf->channel <= 14)
135 + rt2800_rfcsr_write(rt2x00dev, 44, 0x93);
137 + rt2800_rfcsr_write(rt2x00dev, 44, 0x9b);
139 + if (rf->channel <= 14)
141 + else if (rf->channel < 100)
143 + else if (rf->channel < 132)
147 + rt2800_rfcsr_write(rt2x00dev, 45, rfcsr);
149 + if (rf->channel <= 14)
157 + rt2800_rfcsr_write(rt2x00dev, 49, rfcsr);
159 + rt2800_rfcsr_write(rt2x00dev, 50, 0x86);
161 + rfcsr = rt2800_rfcsr_read(rt2x00dev, 51);
162 + if (rf->channel <= 14)
163 + rt2800_rfcsr_write(rt2x00dev, 51, 0x75);
165 + rt2800_rfcsr_write(rt2x00dev, 51, 0x51);
167 + rfcsr = rt2800_rfcsr_read(rt2x00dev, 52);
168 + if (rf->channel <= 14)
169 + rt2800_rfcsr_write(rt2x00dev, 52, 0x45);
171 + rt2800_rfcsr_write(rt2x00dev, 52, 0x05);
173 + if (rf->channel <= 14) {
174 + pwr1 = info->default_power1 & 0x1f;
175 + pwr2 = info->default_power2 & 0x1f;
176 + pwr3 = info->default_power3 & 0x1f;
178 + pwr1 = 0x48 | ((info->default_power1 & 0x18) << 1) |
179 + (info->default_power1 & 0x7);
180 + pwr2 = 0x48 | ((info->default_power2 & 0x18) << 1) |
181 + (info->default_power2 & 0x7);
182 + pwr3 = 0x48 | ((info->default_power3 & 0x18) << 1) |
183 + (info->default_power3 & 0x7);
186 + rt2800_rfcsr_write(rt2x00dev, 53, pwr1);
187 + rt2800_rfcsr_write(rt2x00dev, 54, pwr2);
188 + rt2800_rfcsr_write(rt2x00dev, 55, pwr3);
190 + rt2x00_dbg(rt2x00dev, "Channel:%d, pwr1:%02x, pwr2:%02x, pwr3:%02x\n",
191 + rf->channel, pwr1, pwr2, pwr3);
193 + bbp = (info->default_power1 >> 5) |
194 + ((info->default_power2 & 0xe0) >> 1);
195 + rt2800_bbp_write(rt2x00dev, 109, bbp);
197 + bbp = rt2800_bbp_read(rt2x00dev, 110);
199 + bbp |= (info->default_power3 & 0xe0) >> 1;
200 + rt2800_bbp_write(rt2x00dev, 110, bbp);
202 + rfcsr = rt2800_rfcsr_read(rt2x00dev, 57);
203 + if (rf->channel <= 14)
204 + rt2800_rfcsr_write(rt2x00dev, 57, 0x6e);
206 + rt2800_rfcsr_write(rt2x00dev, 57, 0x3e);
208 + /* Enable RF tuning */
209 + rfcsr = rt2800_rfcsr_read(rt2x00dev, 3);
210 + rt2x00_set_field8(&rfcsr, RFCSR3_VCOCAL_EN, 1);
211 + rt2800_rfcsr_write(rt2x00dev, 3, rfcsr);
215 + bbp = rt2800_bbp_read(rt2x00dev, 49);
216 + /* clear update flag */
217 + rt2800_bbp_write(rt2x00dev, 49, bbp & 0xfe);
218 + rt2800_bbp_write(rt2x00dev, 49, bbp);
220 + /* TODO: add calibration for TxBF */
223 #define POWER_BOUND 0x27
224 #define POWER_BOUND_5G 0x2b
226 @@ -3734,6 +3939,9 @@ static void rt2800_config_channel(struct
228 rt2800_config_channel_rf3322(rt2x00dev, conf, rf, info);
231 + rt2800_config_channel_rf3853(rt2x00dev, conf, rf, info);