2 This is part of the rtl8180-sa2400 driver
3 released under the GPL (See file COPYING for details).
4 Copyright (c) 2005 Andrea Merello <andreamrl@tiscali.it>
6 This files contains programming code for the rtl8225
9 *Many* thanks to Realtek Corp. for their great support!
16 #include "r8180_rtl8225.h"
20 0x23,0x88,0x7c,0xa5,// -82dbm
21 0x23,0x88,0x7c,0xb5,// -82dbm
22 0x23,0x88,0x7c,0xc5,// -82dbm
23 0x33,0x80,0x79,0xc5,// -78dbm
24 0x43,0x78,0x76,0xc5,// -74dbm
25 0x53,0x60,0x73,0xc5,// -70dbm
26 0x63,0x58,0x70,0xc5,// -66dbm
47 u16 rtl8225bcd_rxgain[]={
48 0x0400, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0408, 0x0409,
49 0x040a, 0x040b, 0x0502, 0x0503, 0x0504, 0x0505, 0x0540, 0x0541,
50 0x0542, 0x0543, 0x0544, 0x0545, 0x0580, 0x0581, 0x0582, 0x0583,
51 0x0584, 0x0585, 0x0588, 0x0589, 0x058a, 0x058b, 0x0643, 0x0644,
52 0x0645, 0x0680, 0x0681, 0x0682, 0x0683, 0x0684, 0x0685, 0x0688,
53 0x0689, 0x068a, 0x068b, 0x068c, 0x0742, 0x0743, 0x0744, 0x0745,
54 0x0780, 0x0781, 0x0782, 0x0783, 0x0784, 0x0785, 0x0788, 0x0789,
55 0x078a, 0x078b, 0x078c, 0x078d, 0x0790, 0x0791, 0x0792, 0x0793,
56 0x0794, 0x0795, 0x0798, 0x0799, 0x079a, 0x079b, 0x079c, 0x079d,
57 0x07a0, 0x07a1, 0x07a2, 0x07a3, 0x07a4, 0x07a5, 0x07a8, 0x07a9,
58 0x07aa, 0x07ab, 0x07ac, 0x07ad, 0x07b0, 0x07b1, 0x07b2, 0x07b3,
59 0x07b4, 0x07b5, 0x07b8, 0x07b9, 0x07ba, 0x07bb, 0x07bb
64 0x9e,0x9e,0x9e,0x9e,0x9e,0x9e,0x9e,0x9e,0x9d,0x9c,0x9b,0x9a,0x99,0x98,0x97,0x96,
65 0x95,0x94,0x93,0x92,0x91,0x90,0x8f,0x8e,0x8d,0x8c,0x8b,0x8a,0x89,0x88,0x87,0x86,
66 0x85,0x84,0x83,0x82,0x81,0x80,0x3f,0x3e,0x3d,0x3c,0x3b,0x3a,0x39,0x38,0x37,0x36,
67 0x35,0x34,0x33,0x32,0x31,0x30,0x2f,0x2e,0x2d,0x2c,0x2b,0x2a,0x29,0x28,0x27,0x26,
68 0x25,0x24,0x23,0x22,0x21,0x20,0x1f,0x1e,0x1d,0x1c,0x1b,0x1a,0x19,0x18,0x17,0x16,
69 0x15,0x14,0x13,0x12,0x11,0x10,0x0f,0x0e,0x0d,0x0c,0x0b,0x0a,0x09,0x08,0x07,0x06,
70 0x05,0x04,0x03,0x02,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
71 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
75 u8 rtl8225_tx_gain_cck_ofdm[]={
76 0x02,0x06,0x0e,0x1e,0x3e,0x7e
80 u8 rtl8225_tx_power_ofdm[]={
81 0x80,0x90,0xa2,0xb5,0xcb,0xe4
85 u8 rtl8225_tx_power_cck_ch14[]={
86 0x18,0x17,0x15,0x0c,0x00,0x00,0x00,0x00,
87 0x1b,0x1a,0x17,0x0e,0x00,0x00,0x00,0x00,
88 0x1f,0x1e,0x1a,0x0f,0x00,0x00,0x00,0x00,
89 0x22,0x21,0x1d,0x11,0x00,0x00,0x00,0x00,
90 0x26,0x25,0x21,0x13,0x00,0x00,0x00,0x00,
91 0x2b,0x2a,0x25,0x15,0x00,0x00,0x00,0x00
95 u8 rtl8225_tx_power_cck[]={
96 0x18,0x17,0x15,0x11,0x0c,0x08,0x04,0x02,
97 0x1b,0x1a,0x17,0x13,0x0e,0x09,0x04,0x02,
98 0x1f,0x1e,0x1a,0x15,0x10,0x0a,0x05,0x02,
99 0x22,0x21,0x1d,0x18,0x11,0x0b,0x06,0x02,
100 0x26,0x25,0x21,0x1b,0x14,0x0d,0x06,0x03,
101 0x2b,0x2a,0x25,0x1e,0x16,0x0e,0x07,0x03
105 void rtl8225_set_gain(struct net_device *dev, short gain)
107 write_phy_ofdm(dev, 0x0d, rtl8225_gain[gain * 4]);
108 write_phy_ofdm(dev, 0x23, rtl8225_gain[gain * 4 + 1]);
109 write_phy_ofdm(dev, 0x1b, rtl8225_gain[gain * 4 + 2]);
110 write_phy_ofdm(dev, 0x1d, rtl8225_gain[gain * 4 + 3]);
113 void write_rtl8225(struct net_device *dev, u8 adr, u16 data)
118 u32 bangdata = (data << 4) | (adr & 0xf);
119 struct r8180_priv *priv = ieee80211_priv(dev);
121 out = read_nic_word(dev, RFPinsOutput) & 0xfff3;
123 write_nic_word(dev,RFPinsEnable,
124 (read_nic_word(dev,RFPinsEnable) | 0x7));
126 select = read_nic_word(dev, RFPinsSelect);
128 write_nic_word(dev, RFPinsSelect, select | 0x7 |
129 ((priv->card_type == USB) ? 0 : SW_CONTROL_GPIO));
131 force_pci_posting(dev);
134 write_nic_word(dev, RFPinsOutput, out | BB_HOST_BANG_EN );//| 0x1fff);
136 force_pci_posting(dev);
139 write_nic_word(dev, RFPinsOutput, out);
141 force_pci_posting(dev);
147 bit = (bangdata & (1<<i)) >> i;
149 write_nic_word(dev, RFPinsOutput, bit | out);
151 write_nic_word(dev, RFPinsOutput, bit | out | BB_HOST_BANG_CLK);
152 write_nic_word(dev, RFPinsOutput, bit | out | BB_HOST_BANG_CLK);
155 bit = (bangdata & (1<<i)) >> i;
157 write_nic_word(dev, RFPinsOutput, bit | out | BB_HOST_BANG_CLK);
158 write_nic_word(dev, RFPinsOutput, bit | out | BB_HOST_BANG_CLK);
160 write_nic_word(dev, RFPinsOutput, bit | out);
164 write_nic_word(dev, RFPinsOutput, out | BB_HOST_BANG_EN);
166 force_pci_posting(dev);
169 write_nic_word(dev, RFPinsOutput, out |
170 ((priv->card_type == USB) ? 4 : BB_HOST_BANG_EN));
172 write_nic_word(dev, RFPinsSelect, select |
173 ((priv->card_type == USB) ? 0 : SW_CONTROL_GPIO));
175 if(priv->card_type == USB)
178 rtl8185_rf_pins_enable(dev);
181 void rtl8225_SetTXPowerLevel(struct net_device *dev, short ch)
183 struct r8180_priv *priv = ieee80211_priv(dev);
190 u8 max_cck_power_level;
191 u8 max_ofdm_power_level;
192 u8 min_ofdm_power_level;
193 u8 cck_power_level = 0xff & priv->chtxpwr[ch];
194 u8 ofdm_power_level = 0xff & priv->chtxpwr_ofdm[ch];
196 if(priv->card_type == USB){
197 max_cck_power_level = 11;
198 max_ofdm_power_level = 25; // 12 -> 25
199 min_ofdm_power_level = 10;
201 max_cck_power_level = 35;
202 max_ofdm_power_level = 35;
203 min_ofdm_power_level = 0;
205 /* CCK power setting */
206 if(cck_power_level > max_cck_power_level)
207 cck_power_level = max_cck_power_level;
208 GainIdx=cck_power_level % 6;
209 GainSetting=cck_power_level / 6;
212 cck_power_table = rtl8225_tx_power_cck_ch14;
214 cck_power_table = rtl8225_tx_power_cck;
216 // if(priv->card_8185 == 1 && priv->card_8185_Bversion ){
218 // write_nic_byte(dev, TX_GAIN_CCK, rtl8225_tx_gain_cck_ofdm[GainSetting]);
221 write_nic_byte(dev, TX_GAIN_CCK, rtl8225_tx_gain_cck_ofdm[GainSetting]>>1);
226 power = cck_power_table[GainIdx * 8 + i];
227 write_phy_cck(dev, 0x44 + i, power);
230 /* FIXME Is this delay really needeed ? */
231 force_pci_posting(dev);
234 /* OFDM power setting */
236 // if(ofdm_power_level > max_ofdm_power_level)
237 // ofdm_power_level = 35;
238 // ofdm_power_level += min_ofdm_power_level;
240 if(ofdm_power_level > (max_ofdm_power_level - min_ofdm_power_level))
241 ofdm_power_level = max_ofdm_power_level;
243 ofdm_power_level += min_ofdm_power_level;
244 if(ofdm_power_level > 35)
245 ofdm_power_level = 35;
248 GainIdx=ofdm_power_level % 6;
249 GainSetting=ofdm_power_level / 6;
251 // if(priv->card_type == USB){
252 rtl8185_set_anaparam2(dev,RTL8225_ANAPARAM2_ON);
254 write_phy_ofdm(dev,2,0x42);
255 write_phy_ofdm(dev,6,0);
256 write_phy_ofdm(dev,8,0);
259 // if(priv->card_8185 == 1 && priv->card_8185_Bversion){
261 // write_nic_byte(dev, TX_GAIN_OFDM, rtl8225_tx_gain_cck_ofdm[GainSetting]);
264 write_nic_byte(dev, TX_GAIN_OFDM, rtl8225_tx_gain_cck_ofdm[GainSetting]>>1);
268 power = rtl8225_tx_power_ofdm[GainIdx];
270 write_phy_ofdm(dev, 0x5, power);
271 write_phy_ofdm(dev, 0x7, power);
273 force_pci_posting(dev);
275 //write_nic_byte(dev, TX_AGC_CONTROL,4);
278 void rtl8225_rf_set_chan(struct net_device *dev, short ch)
280 struct r8180_priv *priv = ieee80211_priv(dev);
281 short gset = (priv->ieee80211->state == IEEE80211_LINKED &&
282 ieee80211_is_54g(priv->ieee80211->current_network)) ||
283 priv->ieee80211->iw_mode == IW_MODE_MONITOR;
285 rtl8225_SetTXPowerLevel(dev, ch);
287 write_rtl8225(dev, 0x7, rtl8225_chan[ch]);
289 force_pci_posting(dev);
292 // A mode sifs 0x44, difs 34-14, slot 9, eifs 23, cwm 3, cwM 7, ctstoself 0x10
294 write_nic_byte(dev,SIFS,0x22);// SIFS: 0x22
295 write_nic_byte(dev,DIFS,0x14); //DIFS: 20
296 //write_nic_byte(dev,DIFS,20); //DIFS: 20
298 write_nic_byte(dev,SIFS,0x44);// SIFS: 0x22
299 write_nic_byte(dev,DIFS,50 - 14); //DIFS: 36
301 if(priv->ieee80211->state == IEEE80211_LINKED &&
302 ieee80211_is_shortslot(priv->ieee80211->current_network))
303 write_nic_byte(dev,SLOT,0x9); //SLOT: 9
306 write_nic_byte(dev,SLOT,0x14); //SLOT: 20 (0x14)
310 write_nic_byte(dev,EIFS,81);//91 - 20); // EIFS: 91 (0x5B)
311 write_nic_byte(dev,CW_VAL,0x73); //CW VALUE: 0x37
312 //DMESG("using G net params");
314 write_nic_byte(dev,EIFS,81); // EIFS: 91 (0x5B)
315 write_nic_byte(dev,CW_VAL,0xa5); //CW VALUE: 0x37
316 //DMESG("using B net params");
322 void rtl8225_host_pci_init(struct net_device *dev)
324 write_nic_word(dev, RFPinsOutput, 0x480);
326 rtl8185_rf_pins_enable(dev);
328 //if(priv->card_8185 == 2 && priv->enable_gpio0 ) /* version D */
329 //write_nic_word(dev, RFPinsSelect, 0x88);
331 write_nic_word(dev, RFPinsSelect, 0x88 | SW_CONTROL_GPIO); /* 0x488 | SW_CONTROL_GPIO */
333 write_nic_byte(dev, GP_ENABLE, 0);
335 force_pci_posting(dev);
338 write_nic_word(dev, GP_ENABLE, 0xff & (~(1<<6))); /* bit 6 is for RF on/off detection */
343 void rtl8225_host_usb_init(struct net_device *dev)