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!
14 #include "r8180_rtl8225.h"
15 #include "r8180_93cx6.h"
17 #include "ieee80211/dot11d.h"
20 static void write_rtl8225(struct net_device *dev, u8 adr, u16 data)
25 u32 bangdata = (data << 4) | (adr & 0xf);
26 struct r8180_priv *priv = ieee80211_priv(dev);
28 out = read_nic_word(dev, RFPinsOutput) & 0xfff3;
30 write_nic_word(dev, RFPinsEnable,
31 (read_nic_word(dev, RFPinsEnable) | 0x7));
33 select = read_nic_word(dev, RFPinsSelect);
35 write_nic_word(dev, RFPinsSelect, select | 0x7 |
36 ((priv->card_type == USB) ? 0 : SW_CONTROL_GPIO));
38 force_pci_posting(dev);
41 write_nic_word(dev, RFPinsOutput, out | BB_HOST_BANG_EN);
43 force_pci_posting(dev);
46 write_nic_word(dev, RFPinsOutput, out);
48 force_pci_posting(dev);
51 for (i = 15; i >= 0; i--) {
52 bit = (bangdata & (1 << i)) >> i;
54 write_nic_word(dev, RFPinsOutput, bit | out);
56 write_nic_word(dev, RFPinsOutput, bit | out | BB_HOST_BANG_CLK);
57 write_nic_word(dev, RFPinsOutput, bit | out | BB_HOST_BANG_CLK);
60 bit = (bangdata & (1 << i)) >> i;
62 write_nic_word(dev, RFPinsOutput, bit | out | BB_HOST_BANG_CLK);
63 write_nic_word(dev, RFPinsOutput, bit | out | BB_HOST_BANG_CLK);
65 write_nic_word(dev, RFPinsOutput, bit | out);
69 write_nic_word(dev, RFPinsOutput, out | BB_HOST_BANG_EN);
71 force_pci_posting(dev);
74 write_nic_word(dev, RFPinsOutput, out |
75 ((priv->card_type == USB) ? 4 : BB_HOST_BANG_EN));
77 write_nic_word(dev, RFPinsSelect, select |
78 ((priv->card_type == USB) ? 0 : SW_CONTROL_GPIO));
80 if (priv->card_type == USB)
83 rtl8185_rf_pins_enable(dev);
86 static const u16 rtl8225bcd_rxgain[] = {
87 0x0400, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0408, 0x0409,
88 0x040a, 0x040b, 0x0502, 0x0503, 0x0504, 0x0505, 0x0540, 0x0541,
89 0x0542, 0x0543, 0x0544, 0x0545, 0x0580, 0x0581, 0x0582, 0x0583,
90 0x0584, 0x0585, 0x0588, 0x0589, 0x058a, 0x058b, 0x0643, 0x0644,
91 0x0645, 0x0680, 0x0681, 0x0682, 0x0683, 0x0684, 0x0685, 0x0688,
92 0x0689, 0x068a, 0x068b, 0x068c, 0x0742, 0x0743, 0x0744, 0x0745,
93 0x0780, 0x0781, 0x0782, 0x0783, 0x0784, 0x0785, 0x0788, 0x0789,
94 0x078a, 0x078b, 0x078c, 0x078d, 0x0790, 0x0791, 0x0792, 0x0793,
95 0x0794, 0x0795, 0x0798, 0x0799, 0x079a, 0x079b, 0x079c, 0x079d,
96 0x07a0, 0x07a1, 0x07a2, 0x07a3, 0x07a4, 0x07a5, 0x07a8, 0x07a9,
97 0x07aa, 0x07ab, 0x07ac, 0x07ad, 0x07b0, 0x07b1, 0x07b2, 0x07b3,
98 0x07b4, 0x07b5, 0x07b8, 0x07b9, 0x07ba, 0x07bb, 0x07bb
102 static const u8 rtl8225_agc[] = {
103 0x9e, 0x9e, 0x9e, 0x9e, 0x9e, 0x9e, 0x9e, 0x9e,
104 0x9d, 0x9c, 0x9b, 0x9a, 0x99, 0x98, 0x97, 0x96,
105 0x95, 0x94, 0x93, 0x92, 0x91, 0x90, 0x8f, 0x8e,
106 0x8d, 0x8c, 0x8b, 0x8a, 0x89, 0x88, 0x87, 0x86,
107 0x85, 0x84, 0x83, 0x82, 0x81, 0x80, 0x3f, 0x3e,
108 0x3d, 0x3c, 0x3b, 0x3a, 0x39, 0x38, 0x37, 0x36,
109 0x35, 0x34, 0x33, 0x32, 0x31, 0x30, 0x2f, 0x2e,
110 0x2d, 0x2c, 0x2b, 0x2a, 0x29, 0x28, 0x27, 0x26,
111 0x25, 0x24, 0x23, 0x22, 0x21, 0x20, 0x1f, 0x1e,
112 0x1d, 0x1c, 0x1b, 0x1a, 0x19, 0x18, 0x17, 0x16,
113 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x0f, 0x0e,
114 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08, 0x07, 0x06,
115 0x05, 0x04, 0x03, 0x02, 0x01, 0x01, 0x01, 0x01,
116 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
117 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
118 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
121 static const u8 rtl8225_gain[] = {
122 0x23, 0x88, 0x7c, 0xa5, /* -82dBm */
123 0x23, 0x88, 0x7c, 0xb5, /* -82dBm */
124 0x23, 0x88, 0x7c, 0xc5, /* -82dBm */
125 0x33, 0x80, 0x79, 0xc5, /* -78dBm */
126 0x43, 0x78, 0x76, 0xc5, /* -74dBm */
127 0x53, 0x60, 0x73, 0xc5, /* -70dBm */
128 0x63, 0x58, 0x70, 0xc5, /* -66dBm */
131 static const u8 rtl8225_tx_gain_cck_ofdm[] = {
132 0x02, 0x06, 0x0e, 0x1e, 0x3e, 0x7e
135 static const u8 rtl8225_tx_power_cck[] = {
136 0x18, 0x17, 0x15, 0x11, 0x0c, 0x08, 0x04, 0x02,
137 0x1b, 0x1a, 0x17, 0x13, 0x0e, 0x09, 0x04, 0x02,
138 0x1f, 0x1e, 0x1a, 0x15, 0x10, 0x0a, 0x05, 0x02,
139 0x22, 0x21, 0x1d, 0x18, 0x11, 0x0b, 0x06, 0x02,
140 0x26, 0x25, 0x21, 0x1b, 0x14, 0x0d, 0x06, 0x03,
141 0x2b, 0x2a, 0x25, 0x1e, 0x16, 0x0e, 0x07, 0x03
144 static const u8 rtl8225_tx_power_cck_ch14[] = {
145 0x18, 0x17, 0x15, 0x0c, 0x00, 0x00, 0x00, 0x00,
146 0x1b, 0x1a, 0x17, 0x0e, 0x00, 0x00, 0x00, 0x00,
147 0x1f, 0x1e, 0x1a, 0x0f, 0x00, 0x00, 0x00, 0x00,
148 0x22, 0x21, 0x1d, 0x11, 0x00, 0x00, 0x00, 0x00,
149 0x26, 0x25, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00,
150 0x2b, 0x2a, 0x25, 0x15, 0x00, 0x00, 0x00, 0x00
153 static const u8 rtl8225_tx_power_ofdm[] = {
154 0x80, 0x90, 0xa2, 0xb5, 0xcb, 0xe4
157 static const u32 rtl8225_chan[] = {
159 0x0080, 0x0100, 0x0180, 0x0200, 0x0280, 0x0300, 0x0380,
160 0x0400, 0x0480, 0x0500, 0x0580, 0x0600, 0x0680, 0x074A,
163 static void rtl8225_SetTXPowerLevel(struct net_device *dev, short ch)
165 struct r8180_priv *priv = ieee80211_priv(dev);
170 const u8 *cck_power_table;
171 u8 max_cck_power_level;
172 u8 max_ofdm_power_level;
173 u8 min_ofdm_power_level;
174 u8 cck_power_level = 0xff & priv->chtxpwr[ch];
175 u8 ofdm_power_level = 0xff & priv->chtxpwr_ofdm[ch];
177 if (priv->card_type == USB) {
178 max_cck_power_level = 11;
179 max_ofdm_power_level = 25;
180 min_ofdm_power_level = 10;
182 max_cck_power_level = 35;
183 max_ofdm_power_level = 35;
184 min_ofdm_power_level = 0;
187 if (cck_power_level > max_cck_power_level)
188 cck_power_level = max_cck_power_level;
190 GainIdx = cck_power_level % 6;
191 GainSetting = cck_power_level / 6;
194 cck_power_table = rtl8225_tx_power_cck_ch14;
196 cck_power_table = rtl8225_tx_power_cck;
198 write_nic_byte(dev, TX_GAIN_CCK,
199 rtl8225_tx_gain_cck_ofdm[GainSetting] >> 1);
201 for (i = 0; i < 8; i++) {
202 power = cck_power_table[GainIdx * 8 + i];
203 write_phy_cck(dev, 0x44 + i, power);
206 /* FIXME Is this delay really needeed ? */
207 force_pci_posting(dev);
210 if (ofdm_power_level > (max_ofdm_power_level - min_ofdm_power_level))
211 ofdm_power_level = max_ofdm_power_level;
213 ofdm_power_level += min_ofdm_power_level;
215 if (ofdm_power_level > 35)
216 ofdm_power_level = 35;
218 GainIdx = ofdm_power_level % 6;
219 GainSetting = ofdm_power_level / 6;
221 rtl8185_set_anaparam2(dev, RTL8225_ANAPARAM2_ON);
223 write_phy_ofdm(dev, 2, 0x42);
224 write_phy_ofdm(dev, 6, 0x00);
225 write_phy_ofdm(dev, 8, 0x00);
227 write_nic_byte(dev, TX_GAIN_OFDM,
228 rtl8225_tx_gain_cck_ofdm[GainSetting] >> 1);
230 power = rtl8225_tx_power_ofdm[GainIdx];
232 write_phy_ofdm(dev, 5, power);
233 write_phy_ofdm(dev, 7, power);
235 force_pci_posting(dev);
240 u8 rtl8225z2_threshold[]={
241 0x8d, 0x8d, 0x8d, 0x8d, 0x9d, 0xad, 0xbd,
244 // 0xd 0x19 0x1b 0x21
245 u8 rtl8225z2_gain_bg[]={
246 0x23, 0x15, 0xa5, // -82-1dbm
247 0x23, 0x15, 0xb5, // -82-2dbm
248 0x23, 0x15, 0xc5, // -82-3dbm
249 0x33, 0x15, 0xc5, // -78dbm
250 0x43, 0x15, 0xc5, // -74dbm
251 0x53, 0x15, 0xc5, // -70dbm
252 0x63, 0x15, 0xc5, // -66dbm
255 u8 rtl8225z2_gain_a[]={
256 0x13,0x27,0x5a,//,0x37,// -82dbm
257 0x23,0x23,0x58,//,0x37,// -82dbm
258 0x33,0x1f,0x56,//,0x37,// -82dbm
259 0x43,0x1b,0x54,//,0x37,// -78dbm
260 0x53,0x17,0x51,//,0x37,// -74dbm
261 0x63,0x24,0x4f,//,0x37,// -70dbm
262 0x73,0x0f,0x4c,//,0x37,// -66dbm
266 u16 rtl8225z2_rxgain[]={
267 0x0400, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0408, 0x0409,
268 0x040a, 0x040b, 0x0502, 0x0503, 0x0504, 0x0505, 0x0540, 0x0541,
269 0x0542, 0x0543, 0x0544, 0x0545, 0x0580, 0x0581, 0x0582, 0x0583,
270 0x0584, 0x0585, 0x0588, 0x0589, 0x058a, 0x058b, 0x0643, 0x0644,
271 0x0645, 0x0680, 0x0681, 0x0682, 0x0683, 0x0684, 0x0685, 0x0688,
272 0x0689, 0x068a, 0x068b, 0x068c, 0x0742, 0x0743, 0x0744, 0x0745,
273 0x0780, 0x0781, 0x0782, 0x0783, 0x0784, 0x0785, 0x0788, 0x0789,
274 0x078a, 0x078b, 0x078c, 0x078d, 0x0790, 0x0791, 0x0792, 0x0793,
275 0x0794, 0x0795, 0x0798, 0x0799, 0x079a, 0x079b, 0x079c, 0x079d,
276 0x07a0, 0x07a1, 0x07a2, 0x07a3, 0x07a4, 0x07a5, 0x07a8, 0x07a9,
277 0x03aa, 0x03ab, 0x03ac, 0x03ad, 0x03b0, 0x03b1, 0x03b2, 0x03b3,
278 0x03b4, 0x03b5, 0x03b8, 0x03b9, 0x03ba, 0x03bb, 0x03bb
283 u8 ZEBRA2_CCK_OFDM_GAIN_SETTING[]={
284 0x00,0x01,0x02,0x03,0x04,0x05,
285 0x06,0x07,0x08,0x09,0x0a,0x0b,
286 0x0c,0x0d,0x0e,0x0f,0x10,0x11,
287 0x12,0x13,0x14,0x15,0x16,0x17,
288 0x18,0x19,0x1a,0x1b,0x1c,0x1d,
289 0x1e,0x1f,0x20,0x21,0x22,0x23,
294 u8 rtl8225_tx_gain_cck_ofdm[]={
295 0x02,0x06,0x0e,0x1e,0x3e,0x7e
300 u8 rtl8225z2_tx_power_ofdm[]={
301 0x42,0x00,0x40,0x00,0x40
306 u8 rtl8225z2_tx_power_cck_ch14[]={
307 0x36,0x35,0x2e,0x1b,0x00,0x00,0x00,0x00
312 u8 rtl8225z2_tx_power_cck[]={
313 0x36,0x35,0x2e,0x25,0x1c,0x12,0x09,0x04
317 void rtl8225z2_set_gain(struct net_device *dev, short gain)
320 struct r8180_priv *priv = ieee80211_priv(dev);
322 u8 mode = priv->ieee80211->mode;
324 if(mode == IEEE_B || mode == IEEE_G)
325 rtl8225_gain = rtl8225z2_gain_bg;
327 rtl8225_gain = rtl8225z2_gain_a;
329 //write_phy_ofdm(dev, 0x0d, rtl8225_gain[gain * 3]);
330 //write_phy_ofdm(dev, 0x19, rtl8225_gain[gain * 3 + 1]);
331 //write_phy_ofdm(dev, 0x1b, rtl8225_gain[gain * 3 + 2]);
332 //2005.11.17, by ch-hsu
333 write_phy_ofdm(dev, 0x0b, rtl8225_gain[gain * 3]);
334 write_phy_ofdm(dev, 0x1b, rtl8225_gain[gain * 3 + 1]);
335 write_phy_ofdm(dev, 0x1d, rtl8225_gain[gain * 3 + 2]);
336 write_phy_ofdm(dev, 0x21, 0x37);
340 u32 read_rtl8225(struct net_device *dev, u8 adr)
342 u32 data2Write = ((u32)(adr & 0x1f)) << 27;
345 u16 oval,oval2,oval3,tmp;
346 // ThreeWireReg twreg;
347 // ThreeWireReg tdata;
355 oval = read_nic_word(dev, RFPinsOutput);
356 oval2 = read_nic_word(dev, RFPinsEnable);
357 oval3 = read_nic_word(dev, RFPinsSelect);
359 write_nic_word(dev, RFPinsEnable, (oval2|0xf));
360 write_nic_word(dev, RFPinsSelect, (oval3|0xf));
366 write_nic_word(dev, RFPinsOutput, oval | BB_HOST_BANG_EN ); udelay(4);
368 write_nic_word(dev, RFPinsOutput, oval ); udelay(5);
372 mask = (low2high) ? 0x01 : (((u32)0x01)<<(32-1));
373 for(i = 0; i < wLength/2; i++)
375 bit = ((data2Write&mask) != 0) ? 1 : 0;
376 write_nic_word(dev, RFPinsOutput, bit|oval | rw); udelay(1);
378 write_nic_word(dev, RFPinsOutput, bit|oval | BB_HOST_BANG_CLK | rw); udelay(2);
379 write_nic_word(dev, RFPinsOutput, bit|oval | BB_HOST_BANG_CLK | rw); udelay(2);
381 mask = (low2high) ? (mask<<1): (mask>>1);
385 rw = BB_HOST_BANG_RW;
386 write_nic_word(dev, RFPinsOutput, bit|oval | BB_HOST_BANG_CLK | rw); udelay(2);
387 write_nic_word(dev, RFPinsOutput, bit|oval | rw); udelay(2);
391 bit = ((data2Write&mask) != 0) ? 1: 0;
393 write_nic_word(dev, RFPinsOutput, oval|bit|rw| BB_HOST_BANG_CLK); udelay(2);
394 write_nic_word(dev, RFPinsOutput, oval|bit|rw| BB_HOST_BANG_CLK); udelay(2);
396 write_nic_word(dev, RFPinsOutput, oval| bit |rw); udelay(1);
398 mask = (low2high) ? (mask<<1) : (mask>>1);
401 //twreg.struc.clk = 0;
402 //twreg.struc.data = 0;
403 write_nic_word(dev, RFPinsOutput, rw|oval); udelay(2);
404 mask = (low2high) ? 0x01 : (((u32)0x01) << (12-1));
406 // We must set data pin to HW controled, otherwise RF can't driver it and
407 // value RF register won't be able to read back properly. 2006.06.13, by rcnjko.
408 write_nic_word(dev, RFPinsEnable, (oval2 & (~0x01)));
410 for(i = 0; i < rLength; i++)
412 write_nic_word(dev, RFPinsOutput, rw|oval); udelay(1);
414 write_nic_word(dev, RFPinsOutput, rw|oval|BB_HOST_BANG_CLK); udelay(2);
415 write_nic_word(dev, RFPinsOutput, rw|oval|BB_HOST_BANG_CLK); udelay(2);
416 write_nic_word(dev, RFPinsOutput, rw|oval|BB_HOST_BANG_CLK); udelay(2);
417 tmp = read_nic_word(dev, RFPinsInput);
419 dataRead |= (tmp & BB_HOST_BANG_CLK ? mask : 0);
421 write_nic_word(dev, RFPinsOutput, (rw|oval)); udelay(2);
423 mask = (low2high) ? (mask<<1) : (mask>>1);
426 write_nic_word(dev, RFPinsOutput, BB_HOST_BANG_EN|BB_HOST_BANG_RW|oval); udelay(2);
428 write_nic_word(dev, RFPinsEnable, oval2);
429 write_nic_word(dev, RFPinsSelect, oval3); // Set To SW Switch
430 write_nic_word(dev, RFPinsOutput, 0x3a0);
436 short rtl8225_is_V_z2(struct net_device *dev)
441 //write_rtl8225(dev, 0, 0x1b7);
442 //write_rtl8225(dev, 0, 0x0b7);
445 //printk(KERN_WARNING "RF Rigisters:\n");
447 if( read_rtl8225(dev, 8) != 0x588)
450 else /* reg 9 pg 1 = 24 */
451 if( read_rtl8225(dev, 9) != 0x700)
454 /* sw back to pg 0 */
455 write_rtl8225(dev, 0, 0xb7);
461 void rtl8225z2_rf_close(struct net_device *dev)
463 RF_WriteReg(dev, 0x4, 0x1f);
465 force_pci_posting(dev);
468 rtl8180_set_anaparam(dev, RTL8225z2_ANAPARAM_OFF);
469 rtl8185_set_anaparam2(dev, RTL8225z2_ANAPARAM2_OFF);
474 // Map dBm into Tx power index according to
475 // current HW model, for example, RF and PA, and
476 // current wireless mode.
480 struct r8180_priv *priv,
481 WIRELESS_MODE WirelessMode,
485 bool bUseDefault = true;
490 // OFDM Power in dBm = Index * 0.5 + 0
491 // CCK Power in dBm = Index * 0.25 + 13
493 if(priv->card_8185 >= VERSION_8187S_B)
497 if(WirelessMode == WIRELESS_MODE_G)
500 tmp = (2 * PowerInDbm);
504 else if(tmp > 40) // 40 means 20 dBm.
509 else if(WirelessMode == WIRELESS_MODE_B)
512 tmp = (4 * PowerInDbm) - 52;
516 else if(tmp > 28) // 28 means 20 dBm.
524 // TRUE if we want to use a default implementation.
525 // We shall set it to FALSE when we have exact translation formular
526 // for target IC. 070622, by rcnjko.
532 else if(PowerInDbm > 35)
535 TxPwrIdx = (u8)PowerInDbm;
541 void rtl8225z2_SetTXPowerLevel(struct net_device *dev, short ch)
543 struct r8180_priv *priv = ieee80211_priv(dev);
549 //u8 *cck_power_table;
550 u8 max_cck_power_level;
551 //u8 min_cck_power_level;
552 u8 max_ofdm_power_level;
553 u8 min_ofdm_power_level;
554 // u8 cck_power_level = 0xff & priv->chtxpwr[ch];//-by amy 080312
555 // u8 ofdm_power_level = 0xff & priv->chtxpwr_ofdm[ch];//-by amy 080312
556 char cck_power_level = (char)(0xff & priv->chtxpwr[ch]);//+by amy 080312
557 char ofdm_power_level = (char)(0xff & priv->chtxpwr_ofdm[ch]);//+by amy 080312
559 if(IS_DOT11D_ENABLE(priv->ieee80211) &&
560 IS_DOT11D_STATE_DONE(priv->ieee80211) )
562 //PRT_DOT11D_INFO pDot11dInfo = GET_DOT11D_INFO(priv->ieee80211);
563 u8 MaxTxPwrInDbm = DOT11D_GetMaxTxPwrInDbm(priv->ieee80211, ch);
564 u8 CckMaxPwrIdx = DbmToTxPwrIdx(priv, WIRELESS_MODE_B, MaxTxPwrInDbm);
565 u8 OfdmMaxPwrIdx = DbmToTxPwrIdx(priv, WIRELESS_MODE_G, MaxTxPwrInDbm);
567 //printk("Max Tx Power dBm (%d) => CCK Tx power index : %d, OFDM Tx power index: %d\n", MaxTxPwrInDbm, CckMaxPwrIdx, OfdmMaxPwrIdx);
569 //printk("EEPROM channel(%d) => CCK Tx power index: %d, OFDM Tx power index: %d\n",
570 // ch, cck_power_level, ofdm_power_level);
572 if(cck_power_level > CckMaxPwrIdx)
573 cck_power_level = CckMaxPwrIdx;
574 if(ofdm_power_level > OfdmMaxPwrIdx)
575 ofdm_power_level = OfdmMaxPwrIdx;
578 //priv->CurrentCckTxPwrIdx = cck_power_level;
579 //priv->CurrentOfdmTxPwrIdx = ofdm_power_level;
581 max_cck_power_level = 15;
582 max_ofdm_power_level = 25; // 12 -> 25
583 min_ofdm_power_level = 10;
586 if(cck_power_level > 35)
588 cck_power_level = 35;
591 // Set up CCK TXAGC. suggested by SD3 SY.
593 write_nic_byte(dev, CCK_TXAGC, (ZEBRA2_CCK_OFDM_GAIN_SETTING[(u8)cck_power_level]) );
594 //printk("CCK TX power is %x\n", (ZEBRA2_CCK_OFDM_GAIN_SETTING[cck_power_level]));
595 force_pci_posting(dev);
597 /* OFDM power setting */
599 // if(ofdm_power_level > max_ofdm_power_level)
600 // ofdm_power_level = 35;
601 // ofdm_power_level += min_ofdm_power_level;
603 /* if(ofdm_power_level > (max_ofdm_power_level - min_ofdm_power_level))
604 ofdm_power_level = max_ofdm_power_level;
606 ofdm_power_level += min_ofdm_power_level;
608 ofdm_power_level += priv->ofdm_txpwr_base;
610 if(ofdm_power_level > 35)
611 ofdm_power_level = 35;
613 // rtl8185_set_anaparam2(dev,RTL8225_ANAPARAM2_ON);
615 //rtl8185_set_anaparam2(dev, ANAPARM2_ASIC_ON);
618 //must add these for rtl8185B down, xiong-2006-11-21
619 write_phy_ofdm(dev,2,0x42);
620 write_phy_ofdm(dev,5,0);
621 write_phy_ofdm(dev,6,0x40);
622 write_phy_ofdm(dev,7,0);
623 write_phy_ofdm(dev,8,0x40);
626 //write_nic_byte(dev, TX_GAIN_OFDM, ofdm_power_level);
628 write_nic_byte(dev, OFDM_TXAGC, ZEBRA2_CCK_OFDM_GAIN_SETTING[(u8)ofdm_power_level]);
629 if(ofdm_power_level<=11)
631 // write_nic_dword(dev,PHY_ADR,0x00005c87);
632 // write_nic_dword(dev,PHY_ADR,0x00005c89);
633 write_phy_ofdm(dev,0x07,0x5c);
634 write_phy_ofdm(dev,0x09,0x5c);
636 if(ofdm_power_level<=17)
638 // write_nic_dword(dev,PHY_ADR,0x00005487);
639 // write_nic_dword(dev,PHY_ADR,0x00005489);
640 write_phy_ofdm(dev,0x07,0x54);
641 write_phy_ofdm(dev,0x09,0x54);
645 // write_nic_dword(dev,PHY_ADR,0x00005087);
646 // write_nic_dword(dev,PHY_ADR,0x00005089);
647 write_phy_ofdm(dev,0x07,0x50);
648 write_phy_ofdm(dev,0x09,0x50);
650 force_pci_posting(dev);
655 void rtl8225z2_rf_set_chan(struct net_device *dev, short ch)
658 short gset = (priv->ieee80211->state == IEEE80211_LINKED &&
659 ieee80211_is_54g(priv->ieee80211->current_network)) ||
660 priv->ieee80211->iw_mode == IW_MODE_MONITOR;
662 rtl8225z2_SetTXPowerLevel(dev, ch);
664 RF_WriteReg(dev, 0x7, rtl8225_chan[ch]);
666 //YJ,add,080828, if set channel failed, write again
667 if((RF_ReadReg(dev, 0x7) & 0x0F80) != rtl8225_chan[ch])
669 RF_WriteReg(dev, 0x7, rtl8225_chan[ch]);
674 force_pci_posting(dev);
678 static void rtl8225_host_pci_init(struct net_device *dev)
680 write_nic_word(dev, RFPinsOutput, 0x480);
682 rtl8185_rf_pins_enable(dev);
684 write_nic_word(dev, RFPinsSelect, 0x88 | SW_CONTROL_GPIO);
686 write_nic_byte(dev, GP_ENABLE, 0);
688 force_pci_posting(dev);
691 /* bit 6 is for RF on/off detection */
692 write_nic_word(dev, GP_ENABLE, 0xff & (~(1 << 6)));
695 static void rtl8225_rf_set_chan(struct net_device *dev, short ch)
697 struct r8180_priv *priv = ieee80211_priv(dev);
698 short gset = (priv->ieee80211->state == IEEE80211_LINKED &&
699 ieee80211_is_54g(priv->ieee80211->current_network)) ||
700 priv->ieee80211->iw_mode == IW_MODE_MONITOR;
702 rtl8225_SetTXPowerLevel(dev, ch);
704 write_rtl8225(dev, 0x7, rtl8225_chan[ch]);
706 force_pci_posting(dev);
710 write_nic_byte(dev, SIFS, 0x22);
711 write_nic_byte(dev, DIFS, 0x14);
713 write_nic_byte(dev, SIFS, 0x44);
714 write_nic_byte(dev, DIFS, 0x24);
717 if (priv->ieee80211->state == IEEE80211_LINKED &&
718 ieee80211_is_shortslot(priv->ieee80211->current_network))
719 write_nic_byte(dev, SLOT, 0x9);
721 write_nic_byte(dev, SLOT, 0x14);
724 write_nic_byte(dev, EIFS, 81);
725 write_nic_byte(dev, CW_VAL, 0x73);
727 write_nic_byte(dev, EIFS, 81);
728 write_nic_byte(dev, CW_VAL, 0xa5);
732 void rtl8225z2_rf_init(struct net_device *dev)
734 struct r8180_priv *priv = ieee80211_priv(dev);
740 priv->chan = channel;
742 // rtl8180_set_anaparam(dev, RTL8225_ANAPARAM_ON);
744 if (priv->card_type != USB)
745 rtl8225_host_pci_init(dev);
747 write_nic_dword(dev, RF_TIMING, 0x000a8008);
749 brsr = read_nic_word(dev, BRSR);
751 write_nic_word(dev, BRSR, 0xffff);
754 write_nic_dword(dev, RF_PARA, 0x100044);
757 rtl8180_set_mode(dev, EPROM_CMD_CONFIG);
758 write_nic_byte(dev, CONFIG3, 0x44);
759 rtl8180_set_mode(dev, EPROM_CMD_NORMAL);
763 rtl8185_rf_pins_enable(dev);
767 write_rtl8225(dev, 0x0, 0x2bf); mdelay(1);
770 write_rtl8225(dev, 0x1, 0xee0); mdelay(1);
772 write_rtl8225(dev, 0x2, 0x44d); mdelay(1);
774 write_rtl8225(dev, 0x3, 0x441); mdelay(1);
777 write_rtl8225(dev, 0x4, 0x8c3);mdelay(1);
781 write_rtl8225(dev, 0x5, 0xc72);mdelay(1);
784 write_rtl8225(dev, 0x6, 0xe6); mdelay(1);
786 write_rtl8225(dev, 0x7, ((priv->card_type == USB)? 0x82a : rtl8225_chan[channel])); mdelay(1);
788 write_rtl8225(dev, 0x8, 0x3f); mdelay(1);
790 write_rtl8225(dev, 0x9, 0x335); mdelay(1);
792 write_rtl8225(dev, 0xa, 0x9d4); mdelay(1);
794 write_rtl8225(dev, 0xb, 0x7bb); mdelay(1);
796 write_rtl8225(dev, 0xc, 0x850); mdelay(1);
799 write_rtl8225(dev, 0xd, 0xcdf); mdelay(1);
801 write_rtl8225(dev, 0xe, 0x2b); mdelay(1);
803 write_rtl8225(dev, 0xf, 0x114);
809 //if(priv->card_type != USB) /* maybe not needed even for 8185 */
810 // write_rtl8225(dev, 0x7, rtl8225_chan[channel]);
812 write_rtl8225(dev, 0x0, 0x1b7);
815 write_rtl8225(dev, 0x1, (u8)(i+1));
817 /* version B & C & D*/
819 write_rtl8225(dev, 0x2, rtl8225z2_rxgain[i]);
821 write_rtl8225(dev, 0x3, 0x80);
822 write_rtl8225(dev, 0x5, 0x4);
824 write_rtl8225(dev, 0x0, 0xb7);
826 write_rtl8225(dev, 0x2, 0xc4d);
828 if(priv->card_type == USB){
829 // force_pci_posting(dev);
832 write_rtl8225(dev, 0x2, 0x44d);
834 // force_pci_posting(dev);
837 }//End of if(priv->card_type == USB)
838 /* FIXME!! rtl8187 we have to check if calibrarion
839 * is successful and eventually cal. again (repeat
840 * the two write on reg 2)
842 // Check for calibration status, 2005.11.17,
843 data = read_rtl8225(dev, 6);
844 if (!(data&0x00000080))
846 write_rtl8225(dev, 0x02, 0x0c4d);
847 force_pci_posting(dev); mdelay(200);
848 write_rtl8225(dev, 0x02, 0x044d);
849 force_pci_posting(dev); mdelay(100);
850 data = read_rtl8225(dev, 6);
851 if (!(data&0x00000080))
853 DMESGW("RF Calibration Failed!!!!\n");
856 //force_pci_posting(dev);
858 mdelay(200); //200 for 8187
861 // //if(priv->card_type != USB){
862 // write_rtl8225(dev, 0x2, 0x44d);
863 // write_rtl8225(dev, 0x7, rtl8225_chan[channel]);
864 // write_rtl8225(dev, 0x2, 0x47d);
866 // force_pci_posting(dev);
869 // write_rtl8225(dev, 0x2, 0x44d);
872 write_rtl8225(dev, 0x0, 0x2bf);
874 if(priv->card_type != USB)
875 rtl8185_rf_pins_enable(dev);
876 //set up ZEBRA AGC table, 2005.11.17,
878 data = rtl8225_agc[i];
880 addr = i + 0x80; //enable writing AGC table
881 write_phy_ofdm(dev, 0xb, data);
884 write_phy_ofdm(dev, 0xa, addr);
889 force_pci_posting(dev);
892 write_phy_ofdm(dev, 0x0, 0x1); mdelay(1);
893 write_phy_ofdm(dev, 0x1, 0x2); mdelay(1);
894 write_phy_ofdm(dev, 0x2, ((priv->card_type == USB)? 0x42 : 0x62)); mdelay(1);
895 write_phy_ofdm(dev, 0x3, 0x0); mdelay(1);
896 write_phy_ofdm(dev, 0x4, 0x0); mdelay(1);
897 write_phy_ofdm(dev, 0x5, 0x0); mdelay(1);
898 write_phy_ofdm(dev, 0x6, 0x40); mdelay(1);
899 write_phy_ofdm(dev, 0x7, 0x0); mdelay(1);
900 write_phy_ofdm(dev, 0x8, 0x40); mdelay(1);
901 write_phy_ofdm(dev, 0x9, 0xfe); mdelay(1);
903 write_phy_ofdm(dev, 0xa, 0x8); mdelay(1);
905 //write_phy_ofdm(dev, 0x18, 0xef);
908 write_phy_ofdm(dev, 0xb, 0x80); mdelay(1);
910 write_phy_ofdm(dev, 0xc, 0x1);mdelay(1);
913 //if(priv->card_type != USB)
914 write_phy_ofdm(dev, 0xd, 0x43);
916 write_phy_ofdm(dev, 0xe, 0xd3);mdelay(1);
919 write_phy_ofdm(dev, 0xf, 0x38);mdelay(1);
923 // if(priv->card_8185 == 1 && priv->card_8185_Bversion)
924 // write_phy_ofdm(dev, 0x10, 0x04);/*ver B*/
926 write_phy_ofdm(dev, 0x10, 0x84);mdelay(1);
929 write_phy_ofdm(dev, 0x11, 0x07);mdelay(1);
930 /*agc resp time 700*/
933 // if(priv->card_8185 == 2){
935 write_phy_ofdm(dev, 0x12, 0x20);mdelay(1);
937 write_phy_ofdm(dev, 0x13, 0x20);mdelay(1);
939 write_phy_ofdm(dev, 0x14, 0x0); mdelay(1);
940 write_phy_ofdm(dev, 0x15, 0x40); mdelay(1);
941 write_phy_ofdm(dev, 0x16, 0x0); mdelay(1);
942 write_phy_ofdm(dev, 0x17, 0x40); mdelay(1);
944 // if (priv->card_type == USB)
945 // write_phy_ofdm(dev, 0x18, 0xef);
947 write_phy_ofdm(dev, 0x18, 0xef);mdelay(1);
950 write_phy_ofdm(dev, 0x19, 0x19); mdelay(1);
951 write_phy_ofdm(dev, 0x1a, 0x20); mdelay(1);
952 write_phy_ofdm(dev, 0x1b, 0x15);mdelay(1);
954 write_phy_ofdm(dev, 0x1c, 0x4);mdelay(1);
956 write_phy_ofdm(dev, 0x1d, 0xc5);mdelay(1); //2005.11.17,
958 write_phy_ofdm(dev, 0x1e, 0x95);mdelay(1);
960 write_phy_ofdm(dev, 0x1f, 0x75); mdelay(1);
964 write_phy_ofdm(dev, 0x20, 0x1f);mdelay(1);
966 write_phy_ofdm(dev, 0x21, 0x17);mdelay(1);
968 write_phy_ofdm(dev, 0x22, 0x16);mdelay(1);
970 // if(priv->card_type != USB)
971 write_phy_ofdm(dev, 0x23, 0x80);mdelay(1); //FIXME maybe not needed // <>
973 write_phy_ofdm(dev, 0x24, 0x46); mdelay(1);
974 write_phy_ofdm(dev, 0x25, 0x00); mdelay(1);
975 write_phy_ofdm(dev, 0x26, 0x90); mdelay(1);
977 write_phy_ofdm(dev, 0x27, 0x88); mdelay(1);
980 // <> Set init. gain to m74dBm.
982 rtl8225z2_set_gain(dev,4);
984 write_phy_cck(dev, 0x0, 0x98); mdelay(1);
985 write_phy_cck(dev, 0x3, 0x20); mdelay(1);
986 write_phy_cck(dev, 0x4, 0x7e); mdelay(1);
987 write_phy_cck(dev, 0x5, 0x12); mdelay(1);
988 write_phy_cck(dev, 0x6, 0xfc); mdelay(1);
990 write_phy_cck(dev, 0x7, 0x78);mdelay(1);
991 /* Ver C & D & 8187*/
993 write_phy_cck(dev, 0x8, 0x2e);mdelay(1);
995 write_phy_cck(dev, 0x10, ((priv->card_type == USB) ? 0x9b: 0x93)); mdelay(1);
996 write_phy_cck(dev, 0x11, 0x88); mdelay(1);
997 write_phy_cck(dev, 0x12, 0x47); mdelay(1);
998 write_phy_cck(dev, 0x13, 0xd0); /* Ver C & D & 8187*/
1000 write_phy_cck(dev, 0x19, 0x0);
1001 write_phy_cck(dev, 0x1a, 0xa0);
1002 write_phy_cck(dev, 0x1b, 0x8);
1003 write_phy_cck(dev, 0x40, 0x86); /* CCK Carrier Sense Threshold */
1005 write_phy_cck(dev, 0x41, 0x8d);mdelay(1);
1008 write_phy_cck(dev, 0x42, 0x15); mdelay(1);
1009 write_phy_cck(dev, 0x43, 0x18); mdelay(1);
1012 write_phy_cck(dev, 0x44, 0x36); mdelay(1);
1013 write_phy_cck(dev, 0x45, 0x35); mdelay(1);
1014 write_phy_cck(dev, 0x46, 0x2e); mdelay(1);
1015 write_phy_cck(dev, 0x47, 0x25); mdelay(1);
1016 write_phy_cck(dev, 0x48, 0x1c); mdelay(1);
1017 write_phy_cck(dev, 0x49, 0x12); mdelay(1);
1018 write_phy_cck(dev, 0x4a, 0x9); mdelay(1);
1019 write_phy_cck(dev, 0x4b, 0x4); mdelay(1);
1020 write_phy_cck(dev, 0x4c, 0x5);mdelay(1);
1023 write_nic_byte(dev, 0x5b, 0x0d); mdelay(1);
1028 // // TESTR 0xb 8187
1029 // write_phy_cck(dev, 0x10, 0x93);// & 0xfb);
1031 // //if(priv->card_type != USB){
1032 // write_phy_ofdm(dev, 0x2, 0x62);
1033 // write_phy_ofdm(dev, 0x6, 0x0);
1034 // write_phy_ofdm(dev, 0x8, 0x0);
1037 rtl8225z2_SetTXPowerLevel(dev, channel);
1038 write_phy_cck(dev, 0x11, 0x9b); mdelay(1); /* Rx ant A, 0xdb for B */
1039 write_phy_ofdm(dev, 0x26, 0x90); mdelay(1); /* Rx ant A, 0x10 for B */
1041 rtl8185_tx_antenna(dev, 0x3); /* TX ant A, 0x0 for B */
1043 /* switch to high-speed 3-wire
1044 * last digit. 2 for both cck and ofdm
1046 if(priv->card_type == USB)
1047 write_nic_dword(dev, 0x94, 0x3dc00002);
1049 write_nic_dword(dev, 0x94, 0x15c00002);
1050 rtl8185_rf_pins_enable(dev);
1053 // rtl8225_set_mode(dev, 1); /* FIXME start in B mode */ // <>
1055 // /* make sure is waken up! */
1056 // write_rtl8225(dev,0x4, 0x9ff);
1057 // rtl8180_set_anaparam(dev, RTL8225_ANAPARAM_ON);
1058 // rtl8185_set_anaparam2(dev, RTL8225_ANAPARAM2_ON);
1060 rtl8225_rf_set_chan(dev, priv->chan);
1062 //write_nic_word(dev,BRSR,brsr);
1064 //rtl8225z2_rf_set_mode(dev);
1067 void rtl8225z2_rf_set_mode(struct net_device *dev)
1069 struct r8180_priv *priv = ieee80211_priv(dev);
1071 if(priv->ieee80211->mode == IEEE_A)
1073 write_rtl8225(dev, 0x5, 0x1865);
1074 write_nic_dword(dev, RF_PARA, 0x10084);
1075 write_nic_dword(dev, RF_TIMING, 0xa8008);
1076 write_phy_ofdm(dev, 0x0, 0x0);
1077 write_phy_ofdm(dev, 0xa, 0x6);
1078 write_phy_ofdm(dev, 0xb, 0x99);
1079 write_phy_ofdm(dev, 0xf, 0x20);
1080 write_phy_ofdm(dev, 0x11, 0x7);
1082 rtl8225z2_set_gain(dev,4);
1084 write_phy_ofdm(dev,0x15, 0x40);
1085 write_phy_ofdm(dev,0x17, 0x40);
1087 write_nic_dword(dev, 0x94,0x10000000);
1090 write_rtl8225(dev, 0x5, 0x1864);
1091 write_nic_dword(dev, RF_PARA, 0x10044);
1092 write_nic_dword(dev, RF_TIMING, 0xa8008);
1093 write_phy_ofdm(dev, 0x0, 0x1);
1094 write_phy_ofdm(dev, 0xa, 0x6);
1095 write_phy_ofdm(dev, 0xb, 0x99);
1096 write_phy_ofdm(dev, 0xf, 0x20);
1097 write_phy_ofdm(dev, 0x11, 0x7);
1099 rtl8225z2_set_gain(dev,4);
1101 write_phy_ofdm(dev,0x15, 0x40);
1102 write_phy_ofdm(dev,0x17, 0x40);
1104 write_nic_dword(dev, 0x94,0x04000002);
1109 //#define MAX_DOZE_WAITING_TIMES_85B 64
1110 //#define MAX_POLLING_24F_TIMES_87SE 5
1111 #define MAX_DOZE_WAITING_TIMES_85B 20
1112 #define MAX_POLLING_24F_TIMES_87SE 10
1113 #define LPS_MAX_SLEEP_WAITING_TIMES_87SE 5
1116 SetZebraRFPowerState8185(
1117 struct net_device *dev,
1118 RT_RF_POWER_STATE eRFPowerState
1121 struct r8180_priv *priv = ieee80211_priv(dev);
1122 u8 btCR9346, btConfig3;
1123 bool bActionAllowed= true, bTurnOffBB = true;//lzm mod 080826
1128 bool bResult = true;
1131 if(priv->SetRFPowerStateInProgress == true)
1134 priv->SetRFPowerStateInProgress = true;
1136 // enable EEM0 and EEM1 in 9346CR
1137 btCR9346 = read_nic_byte(dev, CR9346);
1138 write_nic_byte(dev, CR9346, (btCR9346|0xC0) );
1139 // enable PARM_En in Config3
1140 btConfig3 = read_nic_byte(dev, CONFIG3);
1141 write_nic_byte(dev, CONFIG3, (btConfig3|CONFIG3_PARM_En) );
1143 switch( priv->rf_chip )
1146 switch( eRFPowerState )
1149 RF_WriteReg(dev,0x4,0x9FF);
1151 write_nic_dword(dev, ANAPARAM, ANAPARM_ON);
1152 write_nic_dword(dev, ANAPARAM2, ANAPARM2_ON);
1154 write_nic_byte(dev, CONFIG4, priv->RFProgType);
1156 //Follow 87B, Isaiah 2007-04-27
1157 u1bTmp = read_nic_byte(dev, 0x24E);
1158 write_nic_byte(dev, 0x24E, (u1bTmp & (~(BIT5|BIT6))) );// 070124 SD1 Alex: turn on CCK and OFDM.
1174 switch( eRFPowerState )
1177 //printk("===================================power on@jiffies:%d\n",jiffies);
1178 write_nic_word(dev, 0x37C, 0x00EC);
1181 write_nic_byte(dev, 0x54, 0x00);
1182 write_nic_byte(dev, 0x62, 0x00);
1186 //RF_WriteReg(dev, 0x0, 0x009f); //mdelay(1);
1187 //RF_WriteReg(dev, 0x4, 0x0972); //mdelay(1);
1188 RF_WriteReg(dev, 0x0, 0x009f); udelay(500);
1189 RF_WriteReg(dev, 0x4, 0x0972); udelay(500);
1190 //turn on RF again, suggested by SD3 stevenl.
1191 RF_WriteReg(dev, 0x0, 0x009f); udelay(500);
1192 RF_WriteReg(dev, 0x4, 0x0972); udelay(500);
1195 // write_nic_dword(dev, PhyAddr, 0x4090); //ofdm 10=00
1196 // write_nic_dword(dev, PhyAddr, 0x4092); //ofdm 12=00
1197 write_phy_ofdm(dev,0x10,0x40);
1198 write_phy_ofdm(dev,0x12,0x40);
1199 //Avoid power down at init time.
1200 write_nic_byte(dev, CONFIG4, priv->RFProgType);
1202 u1bTmp = read_nic_byte(dev, 0x24E);
1203 write_nic_byte(dev, 0x24E, (u1bTmp & (~(BIT5|BIT6))) );
1208 // Make sure BusyQueue is empty befor turn off RFE pwoer.
1209 //printk("===================================power sleep@jiffies:%d\n",jiffies);
1211 for(QueueID = 0, i = 0; QueueID < 6; )
1213 if(get_curr_tx_free_desc(dev,QueueID) == priv->txringcount)
1218 else//lzm mod 080826
1220 priv->TxPollingTimes ++;
1221 if(priv->TxPollingTimes >= LPS_MAX_SLEEP_WAITING_TIMES_87SE)
1223 //RT_TRACE(COMP_POWER, DBG_WARNING, ("\n\n\n SetZebraRFPowerState8185B():eRfSleep: %d times TcbBusyQueue[%d] != 0 !!!\n\n\n", LPS_MAX_SLEEP_WAITING_TIMES_87SE, QueueID));
1224 bActionAllowed=false;
1229 udelay(10); // Windows may delay 3~16ms actually.
1230 //RT_TRACE(COMP_POWER, DBG_LOUD, ("eRfSleep: %d times TcbBusyQueue[%d] !=0 before doze!\n", (pMgntInfo->TxPollingTimes), QueueID));
1235 //if(i >= MAX_DOZE_WAITING_TIMES_85B)
1237 //printk("\n\n\n SetZebraRFPowerState8185B(): %d times BusyQueue[%d] != 0 !!!\n\n\n", MAX_DOZE_WAITING_TIMES_85B, QueueID);
1242 if(bActionAllowed)//lzm add 080826
1244 //turn off BB RXIQ matrix to cut off rx signal
1245 // write_nic_dword(dev, PhyAddr, 0x0090); //ofdm 10=00
1246 // write_nic_dword(dev, PhyAddr, 0x0092); //ofdm 12=00
1247 write_phy_ofdm(dev,0x10,0x00);
1248 write_phy_ofdm(dev,0x12,0x00);
1250 RF_WriteReg(dev, 0x4, 0x0000); //mdelay(1);
1251 RF_WriteReg(dev, 0x0, 0x0000); //mdelay(1);
1252 //turn off AFE except PLL
1253 write_nic_byte(dev, 0x62, 0xff);
1254 write_nic_byte(dev, 0x54, 0xec);
1263 u8 tmp24F = read_nic_byte(dev, 0x24f);
1264 if ((tmp24F == 0x01) || (tmp24F == 0x09))
1269 else//lzm mod 080826
1273 priv->TxPollingTimes++;
1275 if(priv->TxPollingTimes >= LPS_MAX_SLEEP_WAITING_TIMES_87SE)
1277 //RT_TRACE(COMP_POWER, DBG_WARNING, ("\n\n\n SetZebraRFPowerState8185B(): eRfOff: %d times Rx Mac0x24F=0x%x !!!\n\n\n", i, u1bTmp24F));
1283 udelay(10);// Windows may delay 3~16ms actually.
1284 //RT_TRACE(COMP_POWER, DBG_LOUD,("(%d)eRfSleep- u1bTmp24F= 0x%X\n", i, u1bTmp24F));
1290 //if (i > MAX_POLLING_24F_TIMES_87SE)
1295 if (bTurnOffBB)//lzm mod 080826
1298 u1bTmp = read_nic_byte(dev, 0x24E);
1299 write_nic_byte(dev, 0x24E, (u1bTmp|BIT5|BIT6));
1302 //write_nic_byte(dev, 0x54, 0xec);
1303 //write_nic_word(dev, 0x37C, 0x00ec);
1304 write_nic_byte(dev, 0x54, 0xFC); //[ECS] FC-> EC->FC, asked by SD3 Stevenl
1305 write_nic_word(dev, 0x37C, 0x00FC);//[ECS] FC-> EC->FC, asked by SD3 Stevenl
1311 // Make sure BusyQueue is empty befor turn off RFE pwoer.
1312 //printk("===================================power off@jiffies:%d\n",jiffies);
1313 for(QueueID = 0, i = 0; QueueID < 6; )
1315 if(get_curr_tx_free_desc(dev,QueueID) == priv->txringcount)
1326 if(i >= MAX_DOZE_WAITING_TIMES_85B)
1328 //printk("\n\n\n SetZebraRFPowerState8185B(): %d times BusyQueue[%d] != 0 !!!\n\n\n", MAX_DOZE_WAITING_TIMES_85B, QueueID);
1333 //turn off BB RXIQ matrix to cut off rx signal
1334 // write_nic_dword(dev, PhyAddr, 0x0090); //ofdm 10=00
1335 // write_nic_dword(dev, PhyAddr, 0x0092); //ofdm 12=00
1336 write_phy_ofdm(dev,0x10,0x00);
1337 write_phy_ofdm(dev,0x12,0x00);
1339 RF_WriteReg(dev, 0x4, 0x0000); //mdelay(1);
1340 RF_WriteReg(dev, 0x0, 0x0000); //mdelay(1);
1341 //turn off AFE except PLL
1342 write_nic_byte(dev, 0x62, 0xff);
1343 write_nic_byte(dev, 0x54, 0xec);
1351 u8 tmp24F = read_nic_byte(dev, 0x24f);
1352 if ((tmp24F == 0x01) || (tmp24F == 0x09))
1363 if (i > MAX_POLLING_24F_TIMES_87SE)
1368 if (bTurnOffBB)//lzm mod 080826
1372 u1bTmp = read_nic_byte(dev, 0x24E);
1373 write_nic_byte(dev, 0x24E, (u1bTmp|BIT5|BIT6));
1374 //turn off AFE PLL (80M)
1375 //write_nic_byte(dev, 0x54, 0xec);
1376 //write_nic_word(dev, 0x37C, 0x00ec);
1377 write_nic_byte(dev, 0x54, 0xFC); //[ECS] FC-> EC->FC, asked by SD3 Stevenl
1378 write_nic_word(dev, 0x37C, 0x00FC); //[ECS] FC-> EC->FC, asked by SD3 Stevenl
1385 printk("SetZebraRFPowerState8185(): unknow state to set: 0x%X!!!\n", eRFPowerState);
1391 // disable PARM_En in Config3
1392 btConfig3 &= ~(CONFIG3_PARM_En);
1393 write_nic_byte(dev, CONFIG3, btConfig3);
1394 // disable EEM0 and EEM1 in 9346CR
1395 btCR9346 &= ~(0xC0);
1396 write_nic_byte(dev, CR9346, btCR9346);
1398 if(bResult && bActionAllowed)//lzm mod 080826
1400 // Update current RF state variable.
1401 priv->eRFPowerState = eRFPowerState;
1404 priv->SetRFPowerStateInProgress = false;
1406 return (bResult && bActionAllowed) ;
1408 void rtl8225z4_rf_sleep(struct net_device *dev)
1411 // Turn off RF power.
1413 //printk("=========>%s()\n", __func__);
1414 MgntActSet_RF_State(dev, eRfSleep, RF_CHANGE_BY_PS);
1415 //mdelay(2); //FIXME
1417 void rtl8225z4_rf_wakeup(struct net_device *dev)
1420 // Turn on RF power.
1422 //printk("=========>%s()\n", __func__);
1423 MgntActSet_RF_State(dev, eRfOn, RF_CHANGE_BY_PS);