2 Copyright (c) Realtek Semiconductor Corp. All rights reserved.
8 Hardware Initialization and Hardware IO for RTL8185B
12 ---------- --------------- -------------------------------
13 2006-11-15 Xiong Created
16 This file is ported from RTL8185B Windows driver.
21 /*--------------------------Include File------------------------------------*/
22 #include <linux/spinlock.h>
25 #include "r8180_sa2400.h" /* PHILIPS Radio frontend */
26 #include "r8180_max2820.h" /* MAXIM Radio frontend */
27 #include "r8180_gct.h" /* GCT Radio frontend */
28 #include "r8180_rtl8225.h" /* RTL8225 Radio frontend */
29 #include "r8180_rtl8255.h" /* RTL8255 Radio frontend */
30 #include "r8180_93cx6.h" /* Card EEPROM */
33 #ifdef CONFIG_RTL8180_PM
37 #include "ieee80211/dot11d.h"
39 #ifdef CONFIG_RTL8185B
41 //#define CONFIG_RTL8180_IO_MAP
43 #define TC_3W_POLL_MAX_TRY_CNT 5
44 #ifdef CONFIG_RTL818X_S
45 static u8 MAC_REG_TABLE[][2]={
47 // 0x34(BRSR), 0xBE(RATE_FALLBACK_CTL), 0x1E0(ARFR) would set in HwConfigureRTL8185()
48 // 0x272(RFSW_CTRL), 0x1CE(AESMSK_QC) set in InitializeAdapter8185().
49 // 0x1F0~0x1F8 set in MacConfig_85BASIC()
50 {0x08, 0xae}, {0x0a, 0x72}, {0x5b, 0x42},
51 {0x84, 0x88}, {0x85, 0x24}, {0x88, 0x54}, {0x8b, 0xb8}, {0x8c, 0x03},
52 {0x8d, 0x40}, {0x8e, 0x00}, {0x8f, 0x00}, {0x5b, 0x18}, {0x91, 0x03},
53 {0x94, 0x0F}, {0x95, 0x32},
54 {0x96, 0x00}, {0x97, 0x07}, {0xb4, 0x22}, {0xdb, 0x00},
55 {0xf0, 0x32}, {0xf1, 0x32}, {0xf2, 0x00}, {0xf3, 0x00}, {0xf4, 0x32},
56 {0xf5, 0x43}, {0xf6, 0x00}, {0xf7, 0x00}, {0xf8, 0x46}, {0xf9, 0xa4},
57 {0xfa, 0x00}, {0xfb, 0x00}, {0xfc, 0x96}, {0xfd, 0xa4}, {0xfe, 0x00},
61 // For Flextronics system Logo PCIHCT failure:
62 // 0x1C4~0x1CD set no-zero value to avoid PCI configuration space 0x45[7]=1
64 {0x58, 0x00}, {0x59, 0x00}, {0x5a, 0x04}, {0x5b, 0x00}, {0x60, 0x24},
65 {0x61, 0x97}, {0x62, 0xF0}, {0x63, 0x09}, {0x80, 0x0F}, {0x81, 0xFF},
66 {0x82, 0xFF}, {0x83, 0x03},
67 {0xC4, 0x22}, {0xC5, 0x22}, {0xC6, 0x22}, {0xC7, 0x22}, {0xC8, 0x22}, //lzm add 080826
68 {0xC9, 0x22}, {0xCA, 0x22}, {0xCB, 0x22}, {0xCC, 0x22}, {0xCD, 0x22},//lzm add 080826
74 {0x0c, 0x04}, {0x4c, 0x30}, {0x4d, 0x08}, {0x50, 0x05}, {0x51, 0xf5},
75 {0x52, 0x04}, {0x53, 0xa0}, {0x54, 0xff}, {0x55, 0xff}, {0x56, 0xff},
76 {0x57, 0xff}, {0x58, 0x08}, {0x59, 0x08}, {0x5a, 0x08}, {0x5b, 0x08},
77 {0x60, 0x08}, {0x61, 0x08}, {0x62, 0x08}, {0x63, 0x08}, {0x64, 0x2f},
78 {0x8c, 0x3f}, {0x8d, 0x3f}, {0x8e, 0x3f},
79 {0x8f, 0x3f}, {0xc4, 0xff}, {0xc5, 0xff}, {0xc6, 0xff}, {0xc7, 0xff},
80 {0xc8, 0x00}, {0xc9, 0x00}, {0xca, 0x80}, {0xcb, 0x00},
83 {0x5e, 0x00},{0x9f, 0x03}
87 static u8 ZEBRA_AGC[]={
89 0x7E,0x7E,0x7E,0x7E,0x7D,0x7C,0x7B,0x7A,0x79,0x78,0x77,0x76,0x75,0x74,0x73,0x72,
90 0x71,0x70,0x6F,0x6E,0x6D,0x6C,0x6B,0x6A,0x69,0x68,0x67,0x66,0x65,0x64,0x63,0x62,
91 0x48,0x47,0x46,0x45,0x44,0x29,0x28,0x27,0x26,0x25,0x24,0x23,0x22,0x21,0x08,0x07,
92 0x06,0x05,0x04,0x03,0x02,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
93 0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x10,0x11,0x12,0x13,0x15,0x16,
94 0x17,0x17,0x18,0x18,0x19,0x1a,0x1a,0x1b,0x1b,0x1c,0x1c,0x1d,0x1d,0x1d,0x1e,0x1e,
95 0x1f,0x1f,0x1f,0x20,0x20,0x20,0x20,0x21,0x21,0x21,0x22,0x22,0x22,0x23,0x23,0x24,
96 0x24,0x25,0x25,0x25,0x26,0x26,0x27,0x27,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F
99 static u32 ZEBRA_RF_RX_GAIN_TABLE[]={
100 0x0096,0x0076,0x0056,0x0036,0x0016,0x01f6,0x01d6,0x01b6,
101 0x0196,0x0176,0x00F7,0x00D7,0x00B7,0x0097,0x0077,0x0057,
102 0x0037,0x00FB,0x00DB,0x00BB,0x00FF,0x00E3,0x00C3,0x00A3,
103 0x0083,0x0063,0x0043,0x0023,0x0003,0x01E3,0x01C3,0x01A3,
104 0x0183,0x0163,0x0143,0x0123,0x0103
107 static u8 OFDM_CONFIG[]={
108 // OFDM reg0x06[7:0]=0xFF: Enable power saving mode in RX
109 // OFDM reg0x3C[4]=1'b1: Enable RX power saving mode
110 // ofdm 0x3a = 0x7b ,(original : 0xfb) For ECS shielding room TP test
113 0x10, 0x0F, 0x0A, 0x0C, 0x14, 0xFA, 0xFF, 0x50,
114 0x00, 0x50, 0x00, 0x00, 0x00, 0x5C, 0x00, 0x00,
116 0x40, 0x00, 0x40, 0x00, 0x00, 0x00, 0xA8, 0x26,
117 0x32, 0x33, 0x06, 0xA5, 0x6F, 0x55, 0xC8, 0xBB,
119 0x0A, 0xE1, 0x2C, 0x4A, 0x86, 0x83, 0x34, 0x00,
120 0x4F, 0x24, 0x6F, 0xC2, 0x03, 0x40, 0x80, 0x00,
122 0xC0, 0xC1, 0x58, 0xF1, 0x00, 0xC4, 0x90, 0x3e,
123 0xD8, 0x3C, 0x7B, 0x10, 0x10
126 static u8 MAC_REG_TABLE[][2]={
128 {0xf0, 0x32}, {0xf1, 0x32}, {0xf2, 0x00}, {0xf3, 0x00}, {0xf4, 0x32},
129 {0xf5, 0x43}, {0xf6, 0x00}, {0xf7, 0x00}, {0xf8, 0x46}, {0xf9, 0xa4},
130 {0xfa, 0x00}, {0xfb, 0x00}, {0xfc, 0x96}, {0xfd, 0xa4}, {0xfe, 0x00},
135 {0x58, 0x4b}, {0x59, 0x00}, {0x5a, 0x4b}, {0x5b, 0x00}, {0x60, 0x4b},
136 {0x61, 0x09}, {0x62, 0x4b}, {0x63, 0x09}, {0xce, 0x0f}, {0xcf, 0x00},
137 {0xe0, 0xff}, {0xe1, 0x0f}, {0xe2, 0x00}, {0xf0, 0x4e}, {0xf1, 0x01},
138 {0xf2, 0x02}, {0xf3, 0x03}, {0xf4, 0x04}, {0xf5, 0x05}, {0xf6, 0x06},
139 {0xf7, 0x07}, {0xf8, 0x08},
144 {0x0c, 0x04}, {0x21, 0x61}, {0x22, 0x68}, {0x23, 0x6f}, {0x24, 0x76},
145 {0x25, 0x7d}, {0x26, 0x84}, {0x27, 0x8d}, {0x4d, 0x08}, {0x4e, 0x00},
146 {0x50, 0x05}, {0x51, 0xf5}, {0x52, 0x04}, {0x53, 0xa0}, {0x54, 0x1f},
147 {0x55, 0x23}, {0x56, 0x45}, {0x57, 0x67}, {0x58, 0x08}, {0x59, 0x08},
148 {0x5a, 0x08}, {0x5b, 0x08}, {0x60, 0x08}, {0x61, 0x08}, {0x62, 0x08},
149 {0x63, 0x08}, {0x64, 0xcf}, {0x72, 0x56}, {0x73, 0x9a},
153 {0x34, 0xff}, {0x35, 0x0f}, {0x5b, 0x40}, {0x84, 0x88}, {0x85, 0x24},
154 {0x88, 0x54}, {0x8b, 0xb8}, {0x8c, 0x07}, {0x8d, 0x00}, {0x94, 0x1b},
155 {0x95, 0x12}, {0x96, 0x00}, {0x97, 0x06}, {0x9d, 0x1a}, {0x9f, 0x10},
156 {0xb4, 0x22}, {0xbe, 0x80}, {0xdb, 0x00}, {0xee, 0x00}, {0x5b, 0x42},
172 {0x8c, 0x01}, {0x8d, 0x10},{0x8e, 0x08}, {0x8f, 0x00}
176 static u8 ZEBRA_AGC[]={
178 0x5e,0x5e,0x5e,0x5e,0x5d,0x5b,0x59,0x57,0x55,0x53,0x51,0x4f,0x4d,0x4b,0x49,0x47,
179 0x45,0x43,0x41,0x3f,0x3d,0x3b,0x39,0x37,0x35,0x33,0x31,0x2f,0x2d,0x2b,0x29,0x27,
180 0x25,0x23,0x21,0x1f,0x1d,0x1b,0x19,0x17,0x15,0x13,0x11,0x0f,0x0d,0x0b,0x09,0x07,
181 0x05,0x03,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,
182 0x19,0x19,0x19,0x019,0x19,0x19,0x19,0x19,0x19,0x19,0x1e,0x1f,0x20,0x21,0x21,0x22,
183 0x23,0x24,0x24,0x25,0x25,0x26,0x26,0x27,0x27,0x28,0x28,0x28,0x29,0x2a,0x2a,0x2b,
184 0x2b,0x2b,0x2c,0x2c,0x2c,0x2d,0x2d,0x2d,0x2e,0x2e,0x2f,0x30,0x31,0x31,0x31,0x31,
185 0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31,0x31
188 static u32 ZEBRA_RF_RX_GAIN_TABLE[]={
190 0x0400,0x0401,0x0402,0x0403,0x0404,0x0405,0x0408,0x0409,
191 0x040a,0x040b,0x0502,0x0503,0x0504,0x0505,0x0540,0x0541,
192 0x0542,0x0543,0x0544,0x0545,0x0580,0x0581,0x0582,0x0583,
193 0x0584,0x0585,0x0588,0x0589,0x058a,0x058b,0x0643,0x0644,
194 0x0645,0x0680,0x0681,0x0682,0x0683,0x0684,0x0685,0x0688,
195 0x0689,0x068a,0x068b,0x068c,0x0742,0x0743,0x0744,0x0745,
196 0x0780,0x0781,0x0782,0x0783,0x0784,0x0785,0x0788,0x0789,
197 0x078a,0x078b,0x078c,0x078d,0x0790,0x0791,0x0792,0x0793,
198 0x0794,0x0795,0x0798,0x0799,0x079a,0x079b,0x079c,0x079d,
199 0x07a0,0x07a1,0x07a2,0x07a3,0x07a4,0x07a5,0x07a8,0x07a9,
200 0x03aa,0x03ab,0x03ac,0x03ad,0x03b0,0x03b1,0x03b2,0x03b3,
201 0x03b4,0x03b5,0x03b8,0x03b9,0x03ba,0x03bb,0x03bb
204 // 2006.07.13, SD3 szuyitasi:
205 // OFDM.0x03=0x0C (original is 0x0F)
206 // Use the new SD3 given param, by shien chang, 2006.07.14
207 static u8 OFDM_CONFIG[]={
208 0x10, 0x0d, 0x01, 0x0C, 0x14, 0xfb, 0x0f, 0x60, 0x00, 0x60,
209 0x00, 0x00, 0x00, 0x5c, 0x00, 0x00, 0x40, 0x00, 0x40, 0x00,
210 0x00, 0x00, 0xa8, 0x46, 0xb2, 0x33, 0x07, 0xa5, 0x6f, 0x55,
211 0xc8, 0xb3, 0x0a, 0xe1, 0x1c, 0x8a, 0xb6, 0x83, 0x34, 0x0f,
212 0x4f, 0x23, 0x6f, 0xc2, 0x6b, 0x40, 0x80, 0x00, 0xc0, 0xc1,
213 0x58, 0xf1, 0x00, 0xe4, 0x90, 0x3e, 0x6d, 0x3c, 0xff, 0x07
217 /*---------------------------------------------------------------
219 * the code is ported from Windows source code
220 ----------------------------------------------------------------*/
223 PlatformIOWrite1Byte(
224 struct net_device *dev,
229 #ifndef CONFIG_RTL8180_IO_MAP
230 write_nic_byte(dev, offset, data);
231 read_nic_byte(dev, offset); // To make sure write operation is completed, 2005.11.09, by rcnjko.
234 u32 Page = (offset >> 8);
239 write_nic_byte(dev, offset, data);
246 u8 psr = read_nic_byte(dev, PSR);
248 write_nic_byte(dev, PSR, ((psr & 0xfc) | (u8)Page)); // Switch to page N.
249 write_nic_byte(dev, (offset & 0xff), data);
250 write_nic_byte(dev, PSR, (psr & 0xfc)); // Switch to page 0.
255 // Illegal page number.
256 DMESGE("PlatformIOWrite1Byte(): illegal page number: %d, offset: %#X", Page, offset);
263 PlatformIOWrite2Byte(
264 struct net_device *dev,
269 #ifndef CONFIG_RTL8180_IO_MAP
270 write_nic_word(dev, offset, data);
271 read_nic_word(dev, offset); // To make sure write operation is completed, 2005.11.09, by rcnjko.
275 u32 Page = (offset >> 8);
280 write_nic_word(dev, offset, data);
287 u8 psr = read_nic_byte(dev, PSR);
289 write_nic_byte(dev, PSR, ((psr & 0xfc) | (u8)Page)); // Switch to page N.
290 write_nic_word(dev, (offset & 0xff), data);
291 write_nic_byte(dev, PSR, (psr & 0xfc)); // Switch to page 0.
296 // Illegal page number.
297 DMESGE("PlatformIOWrite2Byte(): illegal page number: %d, offset: %#X", Page, offset);
302 u8 PlatformIORead1Byte(struct net_device *dev, u32 offset);
305 PlatformIOWrite4Byte(
306 struct net_device *dev,
311 #ifndef CONFIG_RTL8180_IO_MAP
313 if (offset == PhyAddr)
314 {//For Base Band configuration.
315 unsigned char cmdByte;
316 unsigned long dataBytes;
320 cmdByte = (u8)(data & 0x000000ff);
325 // The critical section is only BB read/write race condition.
327 // 1. We assume NO one will access BB at DIRQL, otherwise, system will crash for
328 // acquiring the spinlock in such context.
329 // 2. PlatformIOWrite4Byte() MUST NOT be recursive.
331 // NdisAcquireSpinLock( &(pDevice->IoSpinLock) );
333 for(idx = 0; idx < 30; idx++)
334 { // Make sure command bit is clear before access it.
335 u1bTmp = PlatformIORead1Byte(dev, PhyAddr);
336 if((u1bTmp & BIT7) == 0)
342 for(idx=0; idx < 3; idx++)
344 PlatformIOWrite1Byte(dev,offset+1+idx,((u8*)&dataBytes)[idx] );
346 write_nic_byte(dev, offset, cmdByte);
348 // NdisReleaseSpinLock( &(pDevice->IoSpinLock) );
352 write_nic_dword(dev, offset, data);
353 read_nic_dword(dev, offset); // To make sure write operation is completed, 2005.11.09, by rcnjko.
356 u32 Page = (offset >> 8);
361 write_nic_word(dev, offset, data);
368 u8 psr = read_nic_byte(dev, PSR);
370 write_nic_byte(dev, PSR, ((psr & 0xfc) | (u8)Page)); // Switch to page N.
371 write_nic_dword(dev, (offset & 0xff), data);
372 write_nic_byte(dev, PSR, (psr & 0xfc)); // Switch to page 0.
377 // Illegal page number.
378 DMESGE("PlatformIOWrite4Byte(): illegal page number: %d, offset: %#X", Page, offset);
386 struct net_device *dev,
392 #ifndef CONFIG_RTL8180_IO_MAP
393 data = read_nic_byte(dev, offset);
396 u32 Page = (offset >> 8);
401 data = read_nic_byte(dev, offset);
408 u8 psr = read_nic_byte(dev, PSR);
410 write_nic_byte(dev, PSR, ((psr & 0xfc) | (u8)Page)); // Switch to page N.
411 data = read_nic_byte(dev, (offset & 0xff));
412 write_nic_byte(dev, PSR, (psr & 0xfc)); // Switch to page 0.
417 // Illegal page number.
418 DMESGE("PlatformIORead1Byte(): illegal page number: %d, offset: %#X", Page, offset);
428 struct net_device *dev,
434 #ifndef CONFIG_RTL8180_IO_MAP
435 data = read_nic_word(dev, offset);
438 u32 Page = (offset >> 8);
443 data = read_nic_word(dev, offset);
450 u8 psr = read_nic_byte(dev, PSR);
452 write_nic_byte(dev, PSR, ((psr & 0xfc) | (u8)Page)); // Switch to page N.
453 data = read_nic_word(dev, (offset & 0xff));
454 write_nic_byte(dev, PSR, (psr & 0xfc)); // Switch to page 0.
459 // Illegal page number.
460 DMESGE("PlatformIORead2Byte(): illegal page number: %d, offset: %#X", Page, offset);
470 struct net_device *dev,
476 #ifndef CONFIG_RTL8180_IO_MAP
477 data = read_nic_dword(dev, offset);
480 u32 Page = (offset >> 8);
485 data = read_nic_dword(dev, offset);
492 u8 psr = read_nic_byte(dev, PSR);
494 write_nic_byte(dev, PSR, ((psr & 0xfc) | (u8)Page)); // Switch to page N.
495 data = read_nic_dword(dev, (offset & 0xff));
496 write_nic_byte(dev, PSR, (psr & 0xfc)); // Switch to page 0.
501 // Illegal page number.
502 DMESGE("PlatformIORead4Byte(): illegal page number: %d, offset: %#X\n", Page, offset);
511 SetOutputEnableOfRfPins(
512 struct net_device *dev
515 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
517 switch(priv->rf_chip)
519 case RFCHIPID_RTL8225:
522 write_nic_word(dev, RFPinsEnable, 0x1bff);
523 //write_nic_word(dev, RFPinsEnable, 0x1fff);
530 struct net_device *dev,
538 u16 oval,oval2,oval3;
543 #ifdef CONFIG_RTL818X_S
544 // RTL8187S HSSI Read/Write Function
545 u1bTmp = read_nic_byte(dev, RF_SW_CONFIG);
546 u1bTmp |= RF_SW_CFG_SI; //reg08[1]=1 Serial Interface(SI)
547 write_nic_byte(dev, RF_SW_CONFIG, u1bTmp);
549 UshortBuffer = read_nic_word(dev, RFPinsOutput);
550 oval = UshortBuffer & 0xfff8; // We shall clear bit0, 1, 2 first, 2005.10.28, by rcnjko.
552 oval2 = read_nic_word(dev, RFPinsEnable);
553 oval3 = read_nic_word(dev, RFPinsSelect);
555 // <RJ_NOTE> 3-wire should be controled by HW when we finish SW 3-wire programming. 2005.08.10, by rcnjko.
558 write_nic_word(dev, RFPinsEnable, (oval2|0x0007)); // Set To Output Enable
559 write_nic_word(dev, RFPinsSelect, (oval3|0x0007)); // Set To SW Switch
562 // Add this to avoid hardware and software 3-wire conflict.
563 // 2005.03.01, by rcnjko.
565 twreg.struc.enableB = 1;
566 write_nic_word(dev, RFPinsOutput, (twreg.longData|oval)); // Set SI_EN (RFLE)
568 twreg.struc.enableB = 0;
569 write_nic_word(dev, RFPinsOutput, (twreg.longData|oval)); // Clear SI_EN (RFLE)
572 mask = (low2high)?0x01:((u32)0x01<<(totalLength-1));
574 for(i=0; i<totalLength/2; i++)
576 twreg.struc.data = ((data2Write&mask)!=0) ? 1 : 0;
577 write_nic_word(dev, RFPinsOutput, (twreg.longData|oval));
579 write_nic_word(dev, RFPinsOutput, (twreg.longData|oval));
580 write_nic_word(dev, RFPinsOutput, (twreg.longData|oval));
582 mask = (low2high)?(mask<<1):(mask>>1);
583 twreg.struc.data = ((data2Write&mask)!=0) ? 1 : 0;
584 write_nic_word(dev, RFPinsOutput, (twreg.longData|oval));
585 write_nic_word(dev, RFPinsOutput, (twreg.longData|oval));
587 write_nic_word(dev, RFPinsOutput, (twreg.longData|oval));
588 mask = (low2high)?(mask<<1):(mask>>1);
591 twreg.struc.enableB = 1;
593 twreg.struc.data = 0;
594 write_nic_word(dev, RFPinsOutput, twreg.longData|oval);
597 write_nic_word(dev, RFPinsOutput, oval|0x0004);
598 write_nic_word(dev, RFPinsSelect, oval3|0x0000);
600 SetOutputEnableOfRfPins(dev);
607 struct net_device *dev,
620 // Check if WE and RE are cleared.
621 for(TryCnt = 0; TryCnt < TC_3W_POLL_MAX_TRY_CNT; TryCnt++)
623 u1bTmp = read_nic_byte(dev, SW_3W_CMD1);
624 if( (u1bTmp & (SW_3W_CMD1_RE|SW_3W_CMD1_WE)) == 0 )
630 if (TryCnt == TC_3W_POLL_MAX_TRY_CNT)
631 panic("HwThreeWire(): CmdReg: %#X RE|WE bits are not clear!!\n", u1bTmp);
633 // RTL8187S HSSI Read/Write Function
634 u1bTmp = read_nic_byte(dev, RF_SW_CONFIG);
638 u1bTmp |= RF_SW_CFG_SI; //reg08[1]=1 Serial Interface(SI)
641 u1bTmp &= ~RF_SW_CFG_SI; //reg08[1]=0 Parallel Interface(PI)
644 write_nic_byte(dev, RF_SW_CONFIG, u1bTmp);
648 // jong: HW SI read must set reg84[3]=0.
649 u1bTmp = read_nic_byte(dev, RFPinsSelect);
651 write_nic_byte(dev, RFPinsSelect, u1bTmp );
653 // Fill up data buffer for write operation.
657 if(nDataBufBitCnt == 16)
659 write_nic_word(dev, SW_3W_DB0, *((u16*)pDataBuf));
661 else if(nDataBufBitCnt == 64) // RTL8187S shouldn't enter this case
663 write_nic_dword(dev, SW_3W_DB0, *((u32*)pDataBuf));
664 write_nic_dword(dev, SW_3W_DB1, *((u32*)(pDataBuf + 4)));
669 int ByteCnt = nDataBufBitCnt / 8;
670 //printk("%d\n",nDataBufBitCnt);
671 if ((nDataBufBitCnt % 8) != 0)
672 panic("HwThreeWire(): nDataBufBitCnt(%d) should be multiple of 8!!!\n",
675 if (nDataBufBitCnt > 64)
676 panic("HwThreeWire(): nDataBufBitCnt(%d) should <= 64!!!\n",
679 for(idx = 0; idx < ByteCnt; idx++)
681 write_nic_byte(dev, (SW_3W_DB0+idx), *(pDataBuf+idx));
689 // SI - reg274[3:0] : RF register's Address
690 write_nic_word(dev, SW_3W_DB0, *((u16*)pDataBuf) );
694 // PI - reg274[15:12] : RF register's Address
695 write_nic_word(dev, SW_3W_DB0, (*((u16*)pDataBuf)) << 12);
699 // Set up command: WE or RE.
702 write_nic_byte(dev, SW_3W_CMD1, SW_3W_CMD1_WE);
706 write_nic_byte(dev, SW_3W_CMD1, SW_3W_CMD1_RE);
709 // Check if DONE is set.
710 for(TryCnt = 0; TryCnt < TC_3W_POLL_MAX_TRY_CNT; TryCnt++)
712 u1bTmp = read_nic_byte(dev, SW_3W_CMD1);
713 if( (u1bTmp & SW_3W_CMD1_DONE) != 0 )
720 write_nic_byte(dev, SW_3W_CMD1, 0);
722 // Read back data for read operation.
727 //Serial Interface : reg363_362[11:0]
728 *((u16*)pDataBuf) = read_nic_word(dev, SI_DATA_READ) ;
732 //Parallel Interface : reg361_360[11:0]
733 *((u16*)pDataBuf) = read_nic_word(dev, PI_DATA_READ);
736 *((u16*)pDataBuf) &= 0x0FFF;
747 struct net_device *dev,
760 // Check if WE and RE are cleared.
761 for(TryCnt = 0; TryCnt < TC_3W_POLL_MAX_TRY_CNT; TryCnt++)
763 u1bTmp = read_nic_byte(dev, SW_3W_CMD1);
764 if( (u1bTmp & (SW_3W_CMD1_RE|SW_3W_CMD1_WE)) == 0 )
770 if (TryCnt == TC_3W_POLL_MAX_TRY_CNT)
771 panic("HwThreeWire(): CmdReg: %#X RE|WE bits are not clear!!\n", u1bTmp);
773 // Fill up data buffer for write operation.
774 if(nDataBufBitCnt == 16)
776 write_nic_word(dev, SW_3W_DB0, *((u16 *)pDataBuf));
778 else if(nDataBufBitCnt == 64)
780 write_nic_dword(dev, SW_3W_DB0, *((u32 *)pDataBuf));
781 write_nic_dword(dev, SW_3W_DB1, *((u32 *)(pDataBuf + 4)));
786 int ByteCnt = nDataBufBitCnt / 8;
788 if ((nDataBufBitCnt % 8) != 0)
789 panic("HwThreeWire(): nDataBufBitCnt(%d) should be multiple of 8!!!\n",
792 if (nDataBufBitCnt > 64)
793 panic("HwThreeWire(): nDataBufBitCnt(%d) should <= 64!!!\n",
796 for(idx = 0; idx < ByteCnt; idx++)
798 write_nic_byte(dev, (SW_3W_DB0+idx), *(pDataBuf+idx));
802 // Fill up length field.
803 u1bTmp = (u8)(nDataBufBitCnt - 1); // Number of bits - 1.
805 u1bTmp |= SW_3W_CMD0_HOLD;
806 write_nic_byte(dev, SW_3W_CMD0, u1bTmp);
808 // Set up command: WE or RE.
811 write_nic_byte(dev, SW_3W_CMD1, SW_3W_CMD1_WE);
815 write_nic_byte(dev, SW_3W_CMD1, SW_3W_CMD1_RE);
818 // Check if WE and RE are cleared and DONE is set.
819 for(TryCnt = 0; TryCnt < TC_3W_POLL_MAX_TRY_CNT; TryCnt++)
821 u1bTmp = read_nic_byte(dev, SW_3W_CMD1);
822 if( (u1bTmp & (SW_3W_CMD1_RE|SW_3W_CMD1_WE)) == 0 &&
823 (u1bTmp & SW_3W_CMD1_DONE) != 0 )
829 if(TryCnt == TC_3W_POLL_MAX_TRY_CNT)
831 //RT_ASSERT(TryCnt != TC_3W_POLL_MAX_TRY_CNT,
832 // ("HwThreeWire(): CmdReg: %#X RE|WE bits are not clear or DONE is not set!!\n", u1bTmp));
833 // Workaround suggested by wcchu: clear WE here. 2006.07.07, by rcnjko.
834 write_nic_byte(dev, SW_3W_CMD1, 0);
837 // Read back data for read operation.
838 // <RJ_TODO> I am not sure if this is correct output format of a read operation.
841 if(nDataBufBitCnt == 16)
843 *((u16 *)pDataBuf) = read_nic_word(dev, SW_3W_DB0);
845 else if(nDataBufBitCnt == 64)
847 *((u32 *)pDataBuf) = read_nic_dword(dev, SW_3W_DB0);
848 *((u32 *)(pDataBuf + 4)) = read_nic_dword(dev, SW_3W_DB1);
853 int ByteCnt = nDataBufBitCnt / 8;
855 if ((nDataBufBitCnt % 8) != 0)
856 panic("HwThreeWire(): nDataBufBitCnt(%d) should be multiple of 8!!!\n",
859 if (nDataBufBitCnt > 64)
860 panic("HwThreeWire(): nDataBufBitCnt(%d) should <= 64!!!\n",
863 for(idx = 0; idx < ByteCnt; idx++)
865 *(pDataBuf+idx) = read_nic_byte(dev, (SW_3W_DB0+idx));
878 struct net_device *dev,
888 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
891 switch(priv->rf_chip)
893 case RFCHIPID_RTL8225:
894 case RF_ZEBRA2: // Annie 2006-05-12.
895 case RF_ZEBRA4: //by amy
896 switch(priv->RegThreeWireMode)
899 { // Perform SW 3-wire programming by driver.
900 data2Write = (data << 4) | (u32)(offset & 0x0f);
903 ZEBRA_RFSerialWrite(dev, data2Write, len, low2high);
909 data2Write = (data << 4) | (u32)(offset & 0x0f);
913 (u8 *)(&data2Write), // pDataBuf,
914 len, // nDataBufBitCnt,
919 #ifdef CONFIG_RTL818X_S
920 case HW_THREE_WIRE_PI: //Parallel Interface
922 data2Write = (data << 4) | (u32)(offset & 0x0f);
926 (u8*)(&data2Write), // pDataBuf,
927 len, // nDataBufBitCnt,
935 case HW_THREE_WIRE_SI: //Serial Interface
937 data2Write = (data << 4) | (u32)(offset & 0x0f);
939 // printk(" enter ZEBRA_RFSerialWrite\n ");
941 // ZEBRA_RFSerialWrite(dev, data2Write, len, low2high);
945 (u8*)(&data2Write), // pDataBuf,
946 len, // nDataBufBitCnt,
950 // printk(" exit ZEBRA_RFSerialWrite\n ");
957 DMESGE("RF_WriteReg(): invalid RegThreeWireMode(%d) !!!", priv->RegThreeWireMode);
963 DMESGE("RF_WriteReg(): unknown RFChipID: %#X", priv->rf_chip);
971 struct net_device *dev,
981 u16 oval,oval2,oval3,tmp, wReg80;
985 //PHAL_DATA_8187 pHalData = GetHalData8187(pAdapter);
986 #ifdef CONFIG_RTL818X_S
987 { // RTL8187S HSSI Read/Write Function
988 u1bTmp = read_nic_byte(dev, RF_SW_CONFIG);
989 u1bTmp |= RF_SW_CFG_SI; //reg08[1]=1 Serial Interface(SI)
990 write_nic_byte(dev, RF_SW_CONFIG, u1bTmp);
994 wReg80 = oval = read_nic_word(dev, RFPinsOutput);
995 oval2 = read_nic_word(dev, RFPinsEnable);
996 oval3 = read_nic_word(dev, RFPinsSelect);
998 write_nic_word(dev, RFPinsEnable, oval2|0xf);
999 write_nic_word(dev, RFPinsSelect, oval3|0xf);
1003 // We must clear BIT0-3 here, otherwise,
1004 // SW_Enalbe will be true when we first call ZEBRA_RFSerialRead() after 8187MPVC open,
1005 // which will cause the value read become 0. 2005.04.11, by rcnjko.
1008 // Avoid collision with hardware three-wire.
1010 twreg.struc.enableB = 1;
1011 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(4);
1014 twreg.struc.enableB = 0;
1015 twreg.struc.clk = 0;
1016 twreg.struc.read_write = 0;
1017 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(5);
1019 mask = (low2high) ? 0x01 : ((u32)0x01<<(32-1));
1020 for(i = 0; i < wLength/2; i++)
1022 twreg.struc.data = ((data2Write&mask) != 0) ? 1 : 0;
1023 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(1);
1024 twreg.struc.clk = 1;
1025 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
1026 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
1028 mask = (low2high) ? (mask<<1): (mask>>1);
1032 // Commented out by Jackie, 2004.08.26. <RJ_NOTE> We must comment out the following two lines for we cannot pull down VCOPDN during RF Serail Read.
1033 //PlatformEFIOWrite2Byte(pAdapter, RFPinsEnable, 0xe); // turn off data enable
1034 //PlatformEFIOWrite2Byte(pAdapter, RFPinsSelect, 0xe);
1036 twreg.struc.read_write=1;
1037 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
1038 twreg.struc.clk = 0;
1039 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
1042 twreg.struc.data = ((data2Write&mask) != 0) ? 1: 0;
1043 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
1044 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
1046 twreg.struc.clk = 0;
1047 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(1);
1049 mask = (low2high) ? (mask<<1) : (mask>>1);
1052 twreg.struc.clk = 0;
1053 twreg.struc.data = 0;
1054 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
1055 mask = (low2high) ? 0x01 : ((u32)0x01 << (12-1));
1058 // 061016, by rcnjko:
1059 // We must set data pin to HW controled, otherwise RF can't driver it and
1060 // value RF register won't be able to read back properly.
1062 write_nic_word(dev, RFPinsEnable, ( ((oval2|0x0E) & (~0x01))) );
1064 for(i = 0; i < rLength; i++)
1066 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(1);
1067 twreg.struc.clk = 1;
1068 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
1069 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
1070 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
1071 tmp = read_nic_word(dev, RFPinsInput);
1072 tdata.longData = tmp;
1073 *data2Read |= tdata.struc.clk ? mask : 0;
1075 twreg.struc.clk = 0;
1076 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
1078 mask = (low2high) ? (mask<<1) : (mask>>1);
1080 twreg.struc.enableB = 1;
1081 twreg.struc.clk = 0;
1082 twreg.struc.data = 0;
1083 twreg.struc.read_write = 1;
1084 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
1086 //PlatformEFIOWrite2Byte(pAdapter, RFPinsEnable, oval2|0x8); // Set To Output Enable
1087 write_nic_word(dev, RFPinsEnable, oval2); // Set To Output Enable, <RJ_NOTE> We cannot enable BIT3 here, otherwise, we will failed to switch channel. 2005.04.12.
1088 //PlatformEFIOWrite2Byte(pAdapter, RFPinsEnable, 0x1bff);
1089 write_nic_word(dev, RFPinsSelect, oval3); // Set To SW Switch
1090 //PlatformEFIOWrite2Byte(pAdapter, RFPinsSelect, 0x0488);
1091 write_nic_word(dev, RFPinsOutput, 0x3a0);
1092 //PlatformEFIOWrite2Byte(pAdapter, RFPinsOutput, 0x0480);
1098 struct net_device *dev,
1102 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1109 switch(priv->rf_chip)
1111 case RFCHIPID_RTL8225:
1114 switch(priv->RegThreeWireMode)
1116 #ifdef CONFIG_RTL818X_S
1117 case HW_THREE_WIRE_PI: // For 87S Parallel Interface.
1119 data2Write = ((u32)(offset&0x0f));
1123 (u8*)(&data2Write), // pDataBuf,
1124 wlen, // nDataBufBitCnt,
1127 dataRead= data2Write;
1131 case HW_THREE_WIRE_SI: // For 87S Serial Interface.
1133 data2Write = ((u32)(offset&0x0f)) ;
1137 (u8*)(&data2Write), // pDataBuf,
1138 wlen, // nDataBufBitCnt,
1142 dataRead= data2Write;
1147 // Perform SW 3-wire programming by driver.
1150 data2Write = ((u32)(offset&0x1f)) << 27; // For Zebra E-cut. 2005.04.11, by rcnjko.
1154 ZEBRA_RFSerialRead(dev, data2Write, wlen,&dataRead,rlen, low2high);
1168 // by Owen on 04/07/14 for writing BB register successfully
1171 struct net_device *dev,
1175 //u8 TimeoutCounter;
1179 UCharData = (u8)((Data & 0x0000ff00) >> 8);
1180 PlatformIOWrite4Byte(dev, PhyAddr, Data);
1181 //for(TimeoutCounter = 10; TimeoutCounter > 0; TimeoutCounter--)
1183 PlatformIOWrite4Byte(dev, PhyAddr, Data & 0xffffff7f);
1184 RegisterContent = PlatformIORead1Byte(dev, PhyDataR);
1185 //if(UCharData == RegisterContent)
1192 struct net_device *dev,
1196 //u8 TimeoutCounter;
1199 PlatformIOWrite4Byte(dev, PhyAddr, addr & 0xffffff7f);
1200 RegisterContent = PlatformIORead1Byte(dev, PhyDataR);
1202 return RegisterContent;
1205 #ifdef CONFIG_RTL818X_S
1208 // Perform Antenna settings with antenna diversity on 87SE.
1209 // Created by Roger, 2008.01.25.
1212 SetAntennaConfig87SE(
1213 struct net_device *dev,
1214 u8 DefaultAnt, // 0: Main, 1: Aux.
1215 bool bAntDiversity // 1:Enable, 0: Disable.
1218 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1219 bool bAntennaSwitched = true;
1221 //printk("SetAntennaConfig87SE(): DefaultAnt(%d), bAntDiversity(%d)\n", DefaultAnt, bAntDiversity);
1223 // Threshold for antenna diversity.
1224 write_phy_cck(dev, 0x0c, 0x09); // Reg0c : 09
1226 if( bAntDiversity ) // Enable Antenna Diversity.
1228 if( DefaultAnt == 1 ) // aux antenna
1230 // Mac register, aux antenna
1231 write_nic_byte(dev, ANTSEL, 0x00);
1233 // Config CCK RX antenna.
1234 write_phy_cck(dev, 0x11, 0xbb); // Reg11 : bb
1235 write_phy_cck(dev, 0x01, 0xc7); // Reg01 : c7
1237 // Config OFDM RX antenna.
1238 write_phy_ofdm(dev, 0x0D, 0x54); // Reg0d : 54
1239 write_phy_ofdm(dev, 0x18, 0xb2); // Reg18 : b2
1241 else // use main antenna
1243 // Mac register, main antenna
1244 write_nic_byte(dev, ANTSEL, 0x03);
1246 // Config CCK RX antenna.
1247 write_phy_cck(dev, 0x11, 0x9b); // Reg11 : 9b
1248 write_phy_cck(dev, 0x01, 0xc7); // Reg01 : c7
1250 // Config OFDM RX antenna.
1251 write_phy_ofdm(dev, 0x0d, 0x5c); // Reg0d : 5c
1252 write_phy_ofdm(dev, 0x18, 0xb2); // Reg18 : b2
1255 else // Disable Antenna Diversity.
1257 if( DefaultAnt == 1 ) // aux Antenna
1259 // Mac register, aux antenna
1260 write_nic_byte(dev, ANTSEL, 0x00);
1262 // Config CCK RX antenna.
1263 write_phy_cck(dev, 0x11, 0xbb); // Reg11 : bb
1264 write_phy_cck(dev, 0x01, 0x47); // Reg01 : 47
1266 // Config OFDM RX antenna.
1267 write_phy_ofdm(dev, 0x0D, 0x54); // Reg0d : 54
1268 write_phy_ofdm(dev, 0x18, 0x32); // Reg18 : 32
1270 else // main Antenna
1272 // Mac register, main antenna
1273 write_nic_byte(dev, ANTSEL, 0x03);
1275 // Config CCK RX antenna.
1276 write_phy_cck(dev, 0x11, 0x9b); // Reg11 : 9b
1277 write_phy_cck(dev, 0x01, 0x47); // Reg01 : 47
1279 // Config OFDM RX antenna.
1280 write_phy_ofdm(dev, 0x0D, 0x5c); // Reg0d : 5c
1281 write_phy_ofdm(dev, 0x18, 0x32); // Reg18 : 32
1284 priv->CurrAntennaIndex = DefaultAnt; // Update default settings.
1285 return bAntennaSwitched;
1289 /*---------------------------------------------------------------
1290 * Hardware Initialization.
1291 * the code is ported from Windows source code
1292 ----------------------------------------------------------------*/
1295 ZEBRA_Config_85BASIC_HardCode(
1296 struct net_device *dev
1300 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1303 u32 u4bRegOffset, u4bRegValue, u4bRF23, u4bRF24;
1306 #ifdef CONFIG_RTL818X_S
1308 //=============================================================================
1309 // 87S_PCIE :: RADIOCFG.TXT
1310 //=============================================================================
1313 // Page1 : reg16-reg30
1314 RF_WriteReg(dev, 0x00, 0x013f); mdelay(1); // switch to page1
1315 u4bRF23= RF_ReadReg(dev, 0x08); mdelay(1);
1316 u4bRF24= RF_ReadReg(dev, 0x09); mdelay(1);
1318 if (u4bRF23==0x818 && u4bRF24==0x70C && priv->card_8185 == VERSION_8187S_C)
1319 priv->card_8185 = VERSION_8187S_D;
1321 // Page0 : reg0-reg15
1323 // RF_WriteReg(dev, 0x00, 0x003f); mdelay(1);//1
1324 RF_WriteReg(dev, 0x00, 0x009f); mdelay(1);// 1
1326 RF_WriteReg(dev, 0x01, 0x06e0); mdelay(1);
1328 // RF_WriteReg(dev, 0x02, 0x004c); mdelay(1);//2
1329 RF_WriteReg(dev, 0x02, 0x004d); mdelay(1);// 2
1331 // RF_WriteReg(dev, 0x03, 0x0000); mdelay(1);//3
1332 RF_WriteReg(dev, 0x03, 0x07f1); mdelay(1);// 3
1334 RF_WriteReg(dev, 0x04, 0x0975); mdelay(1);
1335 RF_WriteReg(dev, 0x05, 0x0c72); mdelay(1);
1336 RF_WriteReg(dev, 0x06, 0x0ae6); mdelay(1);
1337 RF_WriteReg(dev, 0x07, 0x00ca); mdelay(1);
1338 RF_WriteReg(dev, 0x08, 0x0e1c); mdelay(1);
1339 RF_WriteReg(dev, 0x09, 0x02f0); mdelay(1);
1340 RF_WriteReg(dev, 0x0a, 0x09d0); mdelay(1);
1341 RF_WriteReg(dev, 0x0b, 0x01ba); mdelay(1);
1342 RF_WriteReg(dev, 0x0c, 0x0640); mdelay(1);
1343 RF_WriteReg(dev, 0x0d, 0x08df); mdelay(1);
1344 RF_WriteReg(dev, 0x0e, 0x0020); mdelay(1);
1345 RF_WriteReg(dev, 0x0f, 0x0990); mdelay(1);
1348 // Page1 : reg16-reg30
1349 RF_WriteReg(dev, 0x00, 0x013f); mdelay(1);
1351 RF_WriteReg(dev, 0x03, 0x0806); mdelay(1);
1353 if(priv->card_8185 < VERSION_8187S_C)
1355 RF_WriteReg(dev, 0x04, 0x03f7); mdelay(1);
1356 RF_WriteReg(dev, 0x05, 0x05ab); mdelay(1);
1357 RF_WriteReg(dev, 0x06, 0x00c1); mdelay(1);
1361 RF_WriteReg(dev, 0x04, 0x03a7); mdelay(1);
1362 RF_WriteReg(dev, 0x05, 0x059b); mdelay(1);
1363 RF_WriteReg(dev, 0x06, 0x0081); mdelay(1);
1367 RF_WriteReg(dev, 0x07, 0x01A0); mdelay(1);
1368 // Don't write RF23/RF24 to make a difference between 87S C cut and D cut. asked by SD3 stevenl.
1369 // RF_WriteReg(dev, 0x08, 0x0597); mdelay(1);
1370 // RF_WriteReg(dev, 0x09, 0x050a); mdelay(1);
1371 RF_WriteReg(dev, 0x0a, 0x0001); mdelay(1);
1372 RF_WriteReg(dev, 0x0b, 0x0418); mdelay(1);
1374 if(priv->card_8185 == VERSION_8187S_D)
1376 RF_WriteReg(dev, 0x0c, 0x0fbe); mdelay(1);
1377 RF_WriteReg(dev, 0x0d, 0x0008); mdelay(1);
1378 RF_WriteReg(dev, 0x0e, 0x0807); mdelay(1); // RX LO buffer
1382 RF_WriteReg(dev, 0x0c, 0x0fbe); mdelay(1);
1383 RF_WriteReg(dev, 0x0d, 0x0008); mdelay(1);
1384 RF_WriteReg(dev, 0x0e, 0x0806); mdelay(1); // RX LO buffer
1387 RF_WriteReg(dev, 0x0f, 0x0acc); mdelay(1);
1389 // RF_WriteReg(dev, 0x00, 0x017f); mdelay(1);//6
1390 RF_WriteReg(dev, 0x00, 0x01d7); mdelay(1);// 6
1392 RF_WriteReg(dev, 0x03, 0x0e00); mdelay(1);
1393 RF_WriteReg(dev, 0x04, 0x0e50); mdelay(1);
1396 RF_WriteReg(dev, 0x01, i); mdelay(1);
1397 RF_WriteReg(dev, 0x02, ZEBRA_RF_RX_GAIN_TABLE[i]); mdelay(1);
1398 //DbgPrint("RF - 0x%x = 0x%x", i, ZEBRA_RF_RX_GAIN_TABLE[i]);
1401 RF_WriteReg(dev, 0x05, 0x0203); mdelay(1); /// 203, 343
1402 //RF_WriteReg(dev, 0x06, 0x0300); mdelay(1); // 400
1403 RF_WriteReg(dev, 0x06, 0x0200); mdelay(1); // 400
1405 RF_WriteReg(dev, 0x00, 0x0137); mdelay(1); // switch to reg16-reg30, and HSSI disable 137
1406 mdelay(10); // Deay 10 ms. //0xfd
1408 // RF_WriteReg(dev, 0x0c, 0x09be); mdelay(1); // 7
1409 //RF_WriteReg(dev, 0x0c, 0x07be); mdelay(1);
1410 //mdelay(10); // Deay 10 ms. //0xfd
1412 RF_WriteReg(dev, 0x0d, 0x0008); mdelay(1); // Z4 synthesizer loop filter setting, 392
1413 mdelay(10); // Deay 10 ms. //0xfd
1415 RF_WriteReg(dev, 0x00, 0x0037); mdelay(1); // switch to reg0-reg15, and HSSI disable
1416 mdelay(10); // Deay 10 ms. //0xfd
1418 RF_WriteReg(dev, 0x04, 0x0160); mdelay(1); // CBC on, Tx Rx disable, High gain
1419 mdelay(10); // Deay 10 ms. //0xfd
1421 RF_WriteReg(dev, 0x07, 0x0080); mdelay(1); // Z4 setted channel 1
1422 mdelay(10); // Deay 10 ms. //0xfd
1424 RF_WriteReg(dev, 0x02, 0x088D); mdelay(1); // LC calibration
1425 mdelay(200); // Deay 200 ms. //0xfd
1426 mdelay(10); // Deay 10 ms. //0xfd
1427 mdelay(10); // Deay 10 ms. //0xfd
1429 RF_WriteReg(dev, 0x00, 0x0137); mdelay(1); // switch to reg16-reg30 137, and HSSI disable 137
1430 mdelay(10); // Deay 10 ms. //0xfd
1432 RF_WriteReg(dev, 0x07, 0x0000); mdelay(1);
1433 RF_WriteReg(dev, 0x07, 0x0180); mdelay(1);
1434 RF_WriteReg(dev, 0x07, 0x0220); mdelay(1);
1435 RF_WriteReg(dev, 0x07, 0x03E0); mdelay(1);
1437 // DAC calibration off 20070702
1438 RF_WriteReg(dev, 0x06, 0x00c1); mdelay(1);
1439 RF_WriteReg(dev, 0x0a, 0x0001); mdelay(1);
1441 // For crystal calibration, added by Roger, 2007.12.11.
1442 if( priv->bXtalCalibration ) // reg 30.
1443 { // enable crystal calibration.
1444 // RF Reg[30], (1)Xin:[12:9], Xout:[8:5], addr[4:0].
1445 // (2)PA Pwr delay timer[15:14], default: 2.4us, set BIT15=0
1446 // (3)RF signal on/off when calibration[13], default: on, set BIT13=0.
1447 // So we should minus 4 BITs offset.
1448 RF_WriteReg(dev, 0x0f, (priv->XtalCal_Xin<<5)|(priv->XtalCal_Xout<<1)|BIT11|BIT9); mdelay(1);
1449 printk("ZEBRA_Config_85BASIC_HardCode(): (%02x)\n",
1450 (priv->XtalCal_Xin<<5) | (priv->XtalCal_Xout<<1) | BIT11| BIT9);
1453 { // using default value. Xin=6, Xout=6.
1454 RF_WriteReg(dev, 0x0f, 0x0acc); mdelay(1);
1457 // RF_WriteReg(dev, 0x0f, 0x0acc); mdelay(1); //-by amy 080312
1459 RF_WriteReg(dev, 0x00, 0x00bf); mdelay(1); // switch to reg0-reg15, and HSSI enable
1460 // RF_WriteReg(dev, 0x0d, 0x009f); mdelay(1); // Rx BB start calibration, 00c//-edward
1461 RF_WriteReg(dev, 0x0d, 0x08df); mdelay(1); // Rx BB start calibration, 00c//+edward
1462 RF_WriteReg(dev, 0x02, 0x004d); mdelay(1); // temperature meter off
1463 RF_WriteReg(dev, 0x04, 0x0975); mdelay(1); // Rx mode
1464 mdelay(10); // Deay 10 ms. //0xfe
1465 mdelay(10); // Deay 10 ms. //0xfe
1466 mdelay(10); // Deay 10 ms. //0xfe
1467 RF_WriteReg(dev, 0x00, 0x0197); mdelay(1); // Rx mode//+edward
1468 RF_WriteReg(dev, 0x05, 0x05ab); mdelay(1); // Rx mode//+edward
1469 RF_WriteReg(dev, 0x00, 0x009f); mdelay(1); // Rx mode//+edward
1472 RF_WriteReg(dev, 0x00, 0x0197); mdelay(1);
1473 RF_WriteReg(dev, 0x05, 0x05ab); mdelay(1);
1474 RF_WriteReg(dev, 0x00, 0x009F); mdelay(1);
1476 RF_WriteReg(dev, 0x01, 0x0000); mdelay(1); // Rx mode//+edward
1477 RF_WriteReg(dev, 0x02, 0x0000); mdelay(1); // Rx mode//+edward
1478 //power save parameters.
1479 u1b24E = read_nic_byte(dev, 0x24E);
1480 write_nic_byte(dev, 0x24E, (u1b24E & (~(BIT5|BIT6))));
1482 //=============================================================================
1484 //=============================================================================
1486 //=============================================================================
1488 /* [POWER SAVE] Power Saving Parameters by jong. 2007-11-27
1489 CCK reg0x00[7]=1'b1 :power saving for TX (default)
1490 CCK reg0x00[6]=1'b1: power saving for RX (default)
1491 CCK reg0x06[4]=1'b1: turn off channel estimation related circuits if not doing channel estimation.
1492 CCK reg0x06[3]=1'b1: turn off unused circuits before cca = 1
1493 CCK reg0x06[2]=1'b1: turn off cck's circuit if macrst =0
1496 write_nic_dword(dev, PHY_ADR, 0x0100c880);
1497 write_nic_dword(dev, PHY_ADR, 0x01001c86);
1498 write_nic_dword(dev, PHY_ADR, 0x01007890);
1499 write_nic_dword(dev, PHY_ADR, 0x0100d0ae);
1500 write_nic_dword(dev, PHY_ADR, 0x010006af);
1501 write_nic_dword(dev, PHY_ADR, 0x01004681);
1503 write_phy_cck(dev,0x00,0xc8);
1504 write_phy_cck(dev,0x06,0x1c);
1505 write_phy_cck(dev,0x10,0x78);
1506 write_phy_cck(dev,0x2e,0xd0);
1507 write_phy_cck(dev,0x2f,0x06);
1508 write_phy_cck(dev,0x01,0x46);
1511 write_nic_byte(dev, CCK_TXAGC, 0x10);
1512 write_nic_byte(dev, OFDM_TXAGC, 0x1B);
1513 write_nic_byte(dev, ANTSEL, 0x03);
1515 //=============================================================================
1517 //=============================================================================
1519 RF_WriteReg(dev, 0x00, 0x00b7); mdelay(1);
1520 RF_WriteReg(dev, 0x01, 0x0ee0); mdelay(1);
1521 RF_WriteReg(dev, 0x02, 0x044d); mdelay(1);
1522 RF_WriteReg(dev, 0x03, 0x0441); mdelay(1);
1523 RF_WriteReg(dev, 0x04, 0x08c3); mdelay(1);
1524 RF_WriteReg(dev, 0x05, 0x0c72); mdelay(1);
1525 RF_WriteReg(dev, 0x06, 0x00e6); mdelay(1);
1526 RF_WriteReg(dev, 0x07, 0x082a); mdelay(1);
1527 RF_WriteReg(dev, 0x08, 0x003f); mdelay(1);
1528 RF_WriteReg(dev, 0x09, 0x0335); mdelay(1);
1529 RF_WriteReg(dev, 0x0a, 0x09d4); mdelay(1);
1530 RF_WriteReg(dev, 0x0b, 0x07bb); mdelay(1);
1531 RF_WriteReg(dev, 0x0c, 0x0850); mdelay(1);
1532 RF_WriteReg(dev, 0x0d, 0x0cdf); mdelay(1);
1533 RF_WriteReg(dev, 0x0e, 0x002b); mdelay(1);
1534 RF_WriteReg(dev, 0x0f, 0x0114); mdelay(1);
1536 RF_WriteReg(dev, 0x00, 0x01b7); mdelay(1);
1541 RF_WriteReg(dev, 0x01, i); mdelay(1);
1542 RF_WriteReg(dev, 0x02, ZEBRA_RF_RX_GAIN_TABLE[i]); mdelay(1);
1543 //DbgPrint("RF - 0x%x = 0x%x", i, ZEBRA_RF_RX_GAIN_TABLE[i]);
1546 RF_WriteReg(dev, 0x03, 0x0080); mdelay(1); // write reg 18
1547 RF_WriteReg(dev, 0x05, 0x0004); mdelay(1); // write reg 20
1548 RF_WriteReg(dev, 0x00, 0x00b7); mdelay(1); // switch to reg0-reg15
1552 RF_WriteReg(dev, 0x02, 0x0c4d); mdelay(1);
1553 mdelay(100); // Deay 100 ms. //0xfe
1554 mdelay(100); // Deay 100 ms. //0xfe
1555 RF_WriteReg(dev, 0x02, 0x044d); mdelay(1);
1556 RF_WriteReg(dev, 0x00, 0x02bf); mdelay(1); //0x002f disable 6us corner change, 06f--> enable
1558 //=============================================================================
1560 //=============================================================================
1562 //=============================================================================
1564 //=============================================================================
1566 //=============================================================================
1567 // Follow WMAC RTL8225_Config()
1568 //=============================================================================
1571 write_nic_byte(dev, CCK_TXAGC, 0x03);
1572 write_nic_byte(dev, OFDM_TXAGC, 0x07);
1573 write_nic_byte(dev, ANTSEL, 0x03);
1575 //=============================================================================
1578 // SetOutputEnableOfRfPins(dev);//by amy
1583 //=============================================================================
1585 //=============================================================================
1587 // PlatformIOWrite4Byte( dev, PhyAddr, 0x00001280); // Annie, 2006-05-05
1588 write_phy_ofdm(dev, 0x00, 0x12);
1589 //WriteBBPortUchar(dev, 0x00001280);
1591 for (i=0; i<128; i++)
1593 //DbgPrint("AGC - [%x+1] = 0x%x\n", i, ZEBRA_AGC[i+1]);
1595 data = ZEBRA_AGC[i+1];
1597 data = data | 0x0000008F;
1599 addr = i + 0x80; //enable writing AGC table
1601 addr = addr | 0x0000008E;
1603 WriteBBPortUchar(dev, data);
1604 WriteBBPortUchar(dev, addr);
1605 WriteBBPortUchar(dev, 0x0000008E);
1608 PlatformIOWrite4Byte( dev, PhyAddr, 0x00001080); // Annie, 2006-05-05
1609 //WriteBBPortUchar(dev, 0x00001080);
1611 //=============================================================================
1613 //=============================================================================
1615 //=============================================================================
1620 u4bRegValue=OFDM_CONFIG[i];
1622 //DbgPrint("OFDM - 0x%x = 0x%x\n", u4bRegOffset, u4bRegValue);
1624 WriteBBPortUchar(dev,
1626 (u4bRegOffset & 0x7f) |
1627 ((u4bRegValue & 0xff) << 8)));
1630 //=============================================================================
1631 //by amy for antenna
1632 //=============================================================================
1634 #ifdef CONFIG_RTL818X_S
1635 // Config Sw/Hw Combinational Antenna Diversity. Added by Roger, 2008.02.26.
1636 SetAntennaConfig87SE(dev, priv->bDefaultAntenna1, priv->bSwAntennaDiverity);
1640 // Config Sw/Hw Antenna Diversity
1641 if( priv->bSwAntennaDiverity ) // Use SW+Hw Antenna Diversity
1643 if( priv->bDefaultAntenna1 == true ) // aux antenna
1645 // Mac register, aux antenna
1646 write_nic_byte(dev, ANTSEL, 0x00);
1647 // Config CCK RX antenna.
1648 write_phy_cck(dev, 0x11, 0xbb); // Reg11 : bb
1649 write_phy_cck(dev, 0x0c, 0x09); // Reg0c : 09
1650 write_phy_cck(dev, 0x01, 0xc7); // Reg01 : c7
1651 // Config OFDM RX antenna.
1652 write_phy_ofdm(dev, 0x0d, 0x54); // Reg0d : 54
1653 write_phy_ofdm(dev, 0x18, 0xb2); // Reg18 : b2
1655 else // main antenna
1657 // Mac register, main antenna
1658 write_nic_byte(dev, ANTSEL, 0x03);
1660 // Config CCK RX antenna.
1661 write_phy_cck(dev, 0x11, 0x9b); // Reg11 : 9b
1662 write_phy_cck(dev, 0x0c, 0x09); // Reg0c : 09
1663 write_phy_cck(dev, 0x01, 0xc7); // Reg01 : c7
1664 // Config OFDM RX antenna.
1665 write_phy_ofdm(dev, 0x0d, 0x5c); // Reg0d : 5c
1666 write_phy_ofdm(dev, 0x18, 0xb2); // Reg18 : b2
1669 else // Disable Antenna Diversity
1671 if( priv->bDefaultAntenna1 == true ) // aux Antenna
1673 // Mac register, aux antenna
1674 write_nic_byte(dev, ANTSEL, 0x00);
1675 // Config CCK RX antenna.
1676 write_phy_cck(dev, 0x11, 0xbb); // Reg11 : bb
1677 write_phy_cck(dev, 0x0c, 0x09); // Reg0c : 09
1678 write_phy_cck(dev, 0x01, 0x47); // Reg01 : 47
1679 // Config OFDM RX antenna.
1680 write_phy_ofdm(dev, 0x0d, 0x54); // Reg0d : 54
1681 write_phy_ofdm(dev, 0x18, 0x32); // Reg18 : 32
1683 else // main Antenna
1685 // Mac register, main antenna
1686 write_nic_byte(dev, ANTSEL, 0x03);
1687 // Config CCK RX antenna.
1688 write_phy_cck(dev, 0x11, 0x9b); // Reg11 : 9b
1689 write_phy_cck(dev, 0x0c, 0x09); // Reg0c : 09
1690 write_phy_cck(dev, 0x01, 0x47); // Reg01 : 47
1691 // Config OFDM RX antenna.
1692 write_phy_ofdm(dev, 0x0d, 0x5c); // Reg0d : 5c
1693 write_phy_ofdm(dev, 0x18, 0x32); // Reg18 : 32
1697 //by amy for antenna
1703 struct net_device *dev
1706 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1707 //unsigned char* IGTable;
1708 //u8 DIG_CurrentInitialGain = 4;
1709 //unsigned char u1Tmp;
1712 if(priv->eRFPowerState != eRfOn)
1714 //Don't access BB/RF under disable PLL situation.
1715 //RT_TRACE(COMP_DIG, DBG_LOUD, ("UpdateInitialGain - pHalData->eRFPowerState!=eRfOn\n"));
1716 // Back to the original state
1717 priv->InitialGain= priv->InitialGainBackUp;
1721 switch(priv->rf_chip)
1725 // Dynamic set initial gain, by shien chang, 2006.07.14
1726 switch(priv->InitialGain)
1729 DMESG("RTL8185B + 8225 Initial Gain State 1: -82 dBm \n");
1730 write_nic_dword(dev, PhyAddr, 0x2697); mdelay(1);
1731 write_nic_dword(dev, PhyAddr, 0x86a4); mdelay(1);
1732 write_nic_dword(dev, PhyAddr, 0xfa85); mdelay(1);
1736 DMESG("RTL8185B + 8225 Initial Gain State 2: -82 dBm \n");
1737 write_nic_dword(dev, PhyAddr, 0x2697); mdelay(1);
1738 write_nic_dword(dev, PhyAddr, 0x86a4); mdelay(1);
1739 write_nic_dword(dev, PhyAddr, 0xfb85); mdelay(1);
1743 DMESG("RTL8185B + 8225 Initial Gain State 3: -82 dBm \n");
1744 write_nic_dword(dev, PhyAddr, 0x2697); mdelay(1);
1745 write_nic_dword(dev, PhyAddr, 0x96a4); mdelay(1);
1746 write_nic_dword(dev, PhyAddr, 0xfb85); mdelay(1);
1750 DMESG("RTL8185B + 8225 Initial Gain State 4: -78 dBm \n");
1751 write_nic_dword(dev, PhyAddr, 0x2697); mdelay(1);
1752 write_nic_dword(dev, PhyAddr, 0xa6a4); mdelay(1);
1753 write_nic_dword(dev, PhyAddr, 0xfb85); mdelay(1);
1757 DMESG("RTL8185B + 8225 Initial Gain State 5: -74 dBm \n");
1758 write_nic_dword(dev, PhyAddr, 0x3697); mdelay(1);
1759 write_nic_dword(dev, PhyAddr, 0xa6a4); mdelay(1);
1760 write_nic_dword(dev, PhyAddr, 0xfb85); mdelay(1);
1764 DMESG("RTL8185B + 8225 Initial Gain State 6: -70 dBm \n");
1765 write_nic_dword(dev, PhyAddr, 0x4697); mdelay(1);
1766 write_nic_dword(dev, PhyAddr, 0xa6a4); mdelay(1);
1767 write_nic_dword(dev, PhyAddr, 0xfb85); mdelay(1);
1771 DMESG("RTL8185B + 8225 Initial Gain State 7: -66 dBm \n");
1772 write_nic_dword(dev, PhyAddr, 0x5697); mdelay(1);
1773 write_nic_dword(dev, PhyAddr, 0xa6a4); mdelay(1);
1774 write_nic_dword(dev, PhyAddr, 0xfb85); mdelay(1);
1778 DMESG("RTL8185B + 8225 Initial Gain State 1: -82 dBm (default)\n");
1779 write_nic_dword(dev, PhyAddr, 0x2697); mdelay(1);
1780 write_nic_dword(dev, PhyAddr, 0x86a4); mdelay(1);
1781 write_nic_dword(dev, PhyAddr, 0xfa85); mdelay(1);
1787 // Dynamic set initial gain, follow 87B
1788 switch(priv->InitialGain)
1791 //DMESG("RTL8187 + 8225 Initial Gain State 1: -82 dBm \n");
1792 write_phy_ofdm(dev, 0x17, 0x26); mdelay(1);
1793 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
1794 write_phy_ofdm(dev, 0x05, 0xfa); mdelay(1);
1798 //DMESG("RTL8187 + 8225 Initial Gain State 2: -82 dBm \n");
1799 write_phy_ofdm(dev, 0x17, 0x36); mdelay(1);
1800 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
1801 write_phy_ofdm(dev, 0x05, 0xfa); mdelay(1);
1805 //DMESG("RTL8187 + 8225 Initial Gain State 3: -82 dBm \n");
1806 write_phy_ofdm(dev, 0x17, 0x36); mdelay(1);
1807 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
1808 write_phy_ofdm(dev, 0x05, 0xfb); mdelay(1);
1812 //DMESG("RTL8187 + 8225 Initial Gain State 4: -78 dBm \n");
1813 write_phy_ofdm(dev, 0x17, 0x46); mdelay(1);
1814 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
1815 write_phy_ofdm(dev, 0x05, 0xfb); mdelay(1);
1819 //DMESG("RTL8187 + 8225 Initial Gain State 5: -74 dBm \n");
1820 write_phy_ofdm(dev, 0x17, 0x46); mdelay(1);
1821 write_phy_ofdm(dev, 0x24, 0x96); mdelay(1);
1822 write_phy_ofdm(dev, 0x05, 0xfb); mdelay(1);
1826 //DMESG ("RTL8187 + 8225 Initial Gain State 6: -70 dBm \n");
1827 write_phy_ofdm(dev, 0x17, 0x56); mdelay(1);
1828 write_phy_ofdm(dev, 0x24, 0x96); mdelay(1);
1829 write_phy_ofdm(dev, 0x05, 0xfc); mdelay(1);
1833 //DMESG("RTL8187 + 8225 Initial Gain State 7: -66 dBm \n");
1834 write_phy_ofdm(dev, 0x17, 0x56); mdelay(1);
1835 write_phy_ofdm(dev, 0x24, 0xa6); mdelay(1);
1836 write_phy_ofdm(dev, 0x05, 0xfc); mdelay(1);
1840 //DMESG("RTL8187 + 8225 Initial Gain State 8:\n");
1841 write_phy_ofdm(dev, 0x17, 0x66); mdelay(1);
1842 write_phy_ofdm(dev, 0x24, 0xb6); mdelay(1);
1843 write_phy_ofdm(dev, 0x05, 0xfc); mdelay(1);
1848 //DMESG("RTL8187 + 8225 Initial Gain State 1: -82 dBm (default)\n");
1849 write_phy_ofdm(dev, 0x17, 0x26); mdelay(1);
1850 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
1851 write_phy_ofdm(dev, 0x05, 0xfa); mdelay(1);
1858 DMESG("UpdateInitialGain(): unknown RFChipID: %#X\n", priv->rf_chip);
1862 #ifdef CONFIG_RTL818X_S
1865 // Tx Power tracking mechanism routine on 87SE.
1866 // Created by Roger, 2007.12.11.
1869 InitTxPwrTracking87SE(
1870 struct net_device *dev
1873 //struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1876 u4bRfReg = RF_ReadReg(dev, 0x02);
1878 // Enable Thermal meter indication.
1879 //printk("InitTxPwrTracking87SE(): Enable thermal meter indication, Write RF[0x02] = %#x", u4bRfReg|PWR_METER_EN);
1880 RF_WriteReg(dev, 0x02, u4bRfReg|PWR_METER_EN); mdelay(1);
1886 struct net_device *dev
1889 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1890 write_nic_dword(dev, RCR, priv->ReceiveConfig);
1891 priv->RFProgType = read_nic_byte(dev, CONFIG4) & 0x03;
1893 switch(priv->rf_chip)
1897 ZEBRA_Config_85BASIC_HardCode( dev);
1901 #ifdef CONFIG_RTL818X_S
1902 // Set default initial gain state to 4, approved by SD3 DZ, by Bruce, 2007-06-06.
1903 if(priv->bDigMechanism)
1905 if(priv->InitialGain == 0)
1906 priv->InitialGain = 4;
1907 //printk("PhyConfig8185(): DIG is enabled, set default initial gain index to %d\n", priv->InitialGain);
1911 // Enable thermal meter indication to implement TxPower tracking on 87SE.
1912 // We initialize thermal meter here to avoid unsuccessful configuration.
1913 // Added by Roger, 2007.12.11.
1915 if(priv->bTxPowerTrack)
1916 InitTxPwrTracking87SE(dev);
1920 priv->InitialGainBackUp= priv->InitialGain;
1921 UpdateInitialGain(dev);
1931 struct net_device *dev
1934 //RTL8185_TODO: Determine Retrylimit, TxAGC, AutoRateFallback control.
1935 // u8 bUNIVERSAL_CONTROL_RL = 1;
1936 u8 bUNIVERSAL_CONTROL_RL = 0;
1938 u8 bUNIVERSAL_CONTROL_AGC = 1;
1939 u8 bUNIVERSAL_CONTROL_ANT = 1;
1940 u8 bAUTO_RATE_FALLBACK_CTL = 1;
1942 //struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1943 //struct ieee80211_device *ieee = priv->ieee80211;
1944 //if(IS_WIRELESS_MODE_A(dev) || IS_WIRELESS_MODE_G(dev))
1945 //{by amy 080312 if((ieee->mode == IEEE_G)||(ieee->mode == IEEE_A))
1947 // write_nic_word(dev, BRSR, 0xffff);
1951 // write_nic_word(dev, BRSR, 0x000f);
1954 write_nic_word(dev, BRSR, 0x0fff);
1956 val8 = read_nic_byte(dev, CW_CONF);
1958 if(bUNIVERSAL_CONTROL_RL)
1963 write_nic_byte(dev, CW_CONF, val8);
1966 val8 = read_nic_byte(dev, TXAGC_CTL);
1967 if(bUNIVERSAL_CONTROL_AGC)
1969 write_nic_byte(dev, CCK_TXAGC, 128);
1970 write_nic_byte(dev, OFDM_TXAGC, 128);
1975 val8 = val8 | 0x01 ;
1979 write_nic_byte(dev, TXAGC_CTL, val8);
1981 // Tx Antenna including Feedback control
1982 val8 = read_nic_byte(dev, TXAGC_CTL );
1984 if(bUNIVERSAL_CONTROL_ANT)
1986 write_nic_byte(dev, ANTSEL, 0x00);
1991 val8 = val8 & (val8|0x02); //xiong-2006-11-15
1994 write_nic_byte(dev, TXAGC_CTL, val8);
1996 // Auto Rate fallback control
1997 val8 = read_nic_byte(dev, RATE_FALLBACK);
1999 if( bAUTO_RATE_FALLBACK_CTL )
2001 val8 |= RATE_FALLBACK_CTL_ENABLE | RATE_FALLBACK_CTL_AUTO_STEP1;
2003 // <RJ_TODO_8185B> We shall set up the ARFR according to user's setting.
2004 //write_nic_word(dev, ARFR, 0x0fff); // set 1M ~ 54M
2007 PlatformIOWrite2Byte(dev, ARFR, 0x0fff); // set 1M ~ 54M
2009 #ifdef CONFIG_RTL818X_S
2010 // Aadded by Roger, 2007.11.15.
2011 PlatformIOWrite2Byte(dev, ARFR, 0x0fff); //set 1M ~ 54Mbps.
2013 PlatformIOWrite2Byte(dev, ARFR, 0x0c00); //set 48Mbps, 54Mbps.
2014 // By SD3 szuyi's request. by Roger, 2007.03.26.
2021 write_nic_byte(dev, RATE_FALLBACK, val8);
2027 MacConfig_85BASIC_HardCode(
2028 struct net_device *dev)
2030 //============================================================================
2032 //============================================================================
2035 u32 u4bRegOffset, u4bRegValue,u4bPageIndex = 0;
2038 nLinesRead=sizeof(MAC_REG_TABLE)/2;
2040 for(i = 0; i < nLinesRead; i++) //nLinesRead=101
2042 u4bRegOffset=MAC_REG_TABLE[i][0];
2043 u4bRegValue=MAC_REG_TABLE[i][1];
2045 if(u4bRegOffset == 0x5e)
2047 u4bPageIndex = u4bRegValue;
2051 u4bRegOffset |= (u4bPageIndex << 8);
2053 //DbgPrint("MAC - 0x%x = 0x%x\n", u4bRegOffset, u4bRegValue);
2054 write_nic_byte(dev, u4bRegOffset, (u8)u4bRegValue);
2056 //============================================================================
2063 struct net_device *dev)
2067 MacConfig_85BASIC_HardCode(dev);
2069 //============================================================================
2071 // Follow TID_AC_MAP of WMac.
2072 write_nic_word(dev, TID_AC_MAP, 0xfa50);
2074 // Interrupt Migration, Jong suggested we use set 0x0000 first, 2005.12.14, by rcnjko.
2075 write_nic_word(dev, IntMig, 0x0000);
2077 // Prevent TPC to cause CRC error. Added by Annie, 2006-06-10.
2078 PlatformIOWrite4Byte(dev, 0x1F0, 0x00000000);
2079 PlatformIOWrite4Byte(dev, 0x1F4, 0x00000000);
2080 PlatformIOWrite1Byte(dev, 0x1F8, 0x00);
2082 // Asked for by SD3 CM Lin, 2006.06.27, by rcnjko.
2083 //PlatformIOWrite4Byte(dev, RFTiming, 0x00004001);
2086 write_nic_dword(dev, RFTiming, 0x00004001);
2088 #ifdef CONFIG_RTL818X_S
2089 // power save parameter based on "87SE power save parameters 20071127.doc", as follow.
2091 //Enable DA10 TX power saving
2092 u1DA = read_nic_byte(dev, PHYPR);
2093 write_nic_byte(dev, PHYPR, (u1DA | BIT2) );
2096 write_nic_word(dev, 0x360, 0x1000);
2097 write_nic_word(dev, 0x362, 0x1000);
2100 write_nic_word(dev, 0x370, 0x0560);
2101 write_nic_word(dev, 0x372, 0x0560);
2102 write_nic_word(dev, 0x374, 0x0DA4);
2103 write_nic_word(dev, 0x376, 0x0DA4);
2104 write_nic_word(dev, 0x378, 0x0560);
2105 write_nic_word(dev, 0x37A, 0x0560);
2106 write_nic_word(dev, 0x37C, 0x00EC);
2107 // write_nic_word(dev, 0x37E, 0x00FE);//-edward
2108 write_nic_word(dev, 0x37E, 0x00EC);//+edward
2110 write_nic_dword(dev, RFTiming, 0x00004003);
2112 write_nic_byte(dev, 0x24E,0x01);
2121 GetSupportedWirelessMode8185(
2122 struct net_device *dev
2125 u8 btSupportedWirelessMode = 0;
2126 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2128 switch(priv->rf_chip)
2132 btSupportedWirelessMode = (WIRELESS_MODE_B | WIRELESS_MODE_G);
2135 btSupportedWirelessMode = WIRELESS_MODE_B;
2139 return btSupportedWirelessMode;
2143 ActUpdateChannelAccessSetting(
2144 struct net_device *dev,
2145 WIRELESS_MODE WirelessMode,
2146 PCHANNEL_ACCESS_SETTING ChnlAccessSetting
2149 struct r8180_priv *priv = ieee80211_priv(dev);
2150 struct ieee80211_device *ieee = priv->ieee80211;
2153 //PSTA_QOS pStaQos = Adapter->MgntInfo.pStaQos;
2154 u8 bFollowLegacySetting = 0;
2159 // TODO: We still don't know how to set up these registers, just follow WMAC to
2160 // verify 8185B FPAG.
2163 // Jong said CWmin/CWmax register are not functional in 8185B,
2164 // so we shall fill channel access realted register into AC parameter registers,
2167 ChnlAccessSetting->SIFS_Timer = 0x22; // Suggested by Jong, 2005.12.08.
2168 ChnlAccessSetting->DIFS_Timer = 0x1C; // 2006.06.02, by rcnjko.
2169 ChnlAccessSetting->SlotTimeTimer = 9; // 2006.06.02, by rcnjko.
2170 ChnlAccessSetting->EIFS_Timer = 0x5B; // Suggested by wcchu, it is the default value of EIFS register, 2005.12.08.
2171 ChnlAccessSetting->CWminIndex = 3; // 2006.06.02, by rcnjko.
2172 ChnlAccessSetting->CWmaxIndex = 7; // 2006.06.02, by rcnjko.
2174 write_nic_byte(dev, SIFS, ChnlAccessSetting->SIFS_Timer);
2175 //Adapter->HalFunc.SetHwRegHandler( Adapter, HW_VAR_SLOT_TIME, &ChnlAccessSetting->SlotTimeTimer ); // Rewrited from directly use PlatformEFIOWrite1Byte(), by Annie, 2006-03-29.
2176 write_nic_byte(dev, SLOT, ChnlAccessSetting->SlotTimeTimer); // Rewrited from directly use PlatformEFIOWrite1Byte(), by Annie, 2006-03-29.
2178 u1bAIFS = aSifsTime + (2 * ChnlAccessSetting->SlotTimeTimer );
2180 //write_nic_byte(dev, AC_VO_PARAM, u1bAIFS);
2181 //write_nic_byte(dev, AC_VI_PARAM, u1bAIFS);
2182 //write_nic_byte(dev, AC_BE_PARAM, u1bAIFS);
2183 //write_nic_byte(dev, AC_BK_PARAM, u1bAIFS);
2185 write_nic_byte(dev, EIFS, ChnlAccessSetting->EIFS_Timer);
2187 write_nic_byte(dev, AckTimeOutReg, 0x5B); // <RJ_EXPR_QOS> Suggested by wcchu, it is the default value of EIFS register, 2005.12.08.
2190 // <RJ_TODO_NOW_8185B> Update ECWmin/ECWmax, AIFS, TXOP Limit of each AC to the value defined by SPEC.
2191 if( pStaQos->CurrentQosMode > QOS_DISABLE )
2193 if(pStaQos->QBssWirelessMode == WirelessMode)
2195 // Follow AC Parameters of the QBSS.
2196 for(eACI = 0; eACI < AC_MAX; eACI++)
2198 Adapter->HalFunc.SetHwRegHandler(Adapter, HW_VAR_AC_PARAM, (pu1Byte)(&(pStaQos->WMMParamEle.AcParam[eACI])) );
2203 // Follow Default WMM AC Parameters.
2204 bFollowLegacySetting = 1;
2210 bFollowLegacySetting = 1;
2214 // this setting is copied from rtl8187B. xiong-2006-11-13
2215 if(bFollowLegacySetting)
2220 // Follow 802.11 seeting to AC parameter, all AC shall use the same parameter.
2221 // 2005.12.01, by rcnjko.
2223 AcParam.longData = 0;
2224 AcParam.f.AciAifsn.f.AIFSN = 2; // Follow 802.11 DIFS.
2225 AcParam.f.AciAifsn.f.ACM = 0;
2226 AcParam.f.Ecw.f.ECWmin = ChnlAccessSetting->CWminIndex; // Follow 802.11 CWmin.
2227 AcParam.f.Ecw.f.ECWmax = ChnlAccessSetting->CWmaxIndex; // Follow 802.11 CWmax.
2228 AcParam.f.TXOPLimit = 0;
2230 //lzm reserved 080826
2233 // For turbo mode setting. port from 87B by Isaiah 2008-08-01
2234 if( ieee->current_network.Turbo_Enable == 1 )
2235 AcParam.f.TXOPLimit = 0x01FF;
2237 // For 87SE with Intel 4965 Ad-Hoc mode have poor throughput (19MB)
2238 if (ieee->iw_mode == IW_MODE_ADHOC)
2239 AcParam.f.TXOPLimit = 0x0020;
2242 for(eACI = 0; eACI < AC_MAX; eACI++)
2244 AcParam.f.AciAifsn.f.ACI = (u8)eACI;
2246 PAC_PARAM pAcParam = (PAC_PARAM)(&AcParam);
2251 // Retrive paramters to udpate.
2252 eACI = pAcParam->f.AciAifsn.f.ACI;
2253 u1bAIFS = pAcParam->f.AciAifsn.f.AIFSN * ChnlAccessSetting->SlotTimeTimer + aSifsTime;
2254 u4bAcParam = ( (((u32)(pAcParam->f.TXOPLimit)) << AC_PARAM_TXOP_LIMIT_OFFSET) |
2255 (((u32)(pAcParam->f.Ecw.f.ECWmax)) << AC_PARAM_ECW_MAX_OFFSET) |
2256 (((u32)(pAcParam->f.Ecw.f.ECWmin)) << AC_PARAM_ECW_MIN_OFFSET) |
2257 (((u32)u1bAIFS) << AC_PARAM_AIFS_OFFSET));
2262 //write_nic_dword(dev, AC_BK_PARAM, u4bAcParam);
2266 //write_nic_dword(dev, AC_BE_PARAM, u4bAcParam);
2270 //write_nic_dword(dev, AC_VI_PARAM, u4bAcParam);
2274 //write_nic_dword(dev, AC_VO_PARAM, u4bAcParam);
2278 DMESGW( "SetHwReg8185(): invalid ACI: %d !\n", eACI);
2283 // If it is set, immediately set ACM control bit to downgrading AC for passing WMM testplan. Annie, 2005-12-13.
2284 //write_nic_byte(dev, ACM_CONTROL, pAcParam->f.AciAifsn);
2286 PACI_AIFSN pAciAifsn = (PACI_AIFSN)(&pAcParam->f.AciAifsn);
2287 AC_CODING eACI = pAciAifsn->f.ACI;
2290 //for 8187B AsynIORead issue
2292 u8 AcmCtrl = pHalData->AcmControl;
2296 if( pAciAifsn->f.ACM )
2301 AcmCtrl |= (BEQ_ACM_EN|BEQ_ACM_CTL|ACM_HW_EN); // or 0x21
2305 AcmCtrl |= (VIQ_ACM_EN|VIQ_ACM_CTL|ACM_HW_EN); // or 0x42
2309 AcmCtrl |= (VOQ_ACM_EN|VOQ_ACM_CTL|ACM_HW_EN); // or 0x84
2313 DMESGW("SetHwReg8185(): [HW_VAR_ACM_CTRL] ACM set failed: eACI is %d\n", eACI );
2322 AcmCtrl &= ( (~BEQ_ACM_EN) & (~BEQ_ACM_CTL) & (~ACM_HW_EN) ); // and 0xDE
2326 AcmCtrl &= ( (~VIQ_ACM_EN) & (~VIQ_ACM_CTL) & (~ACM_HW_EN) ); // and 0xBD
2330 AcmCtrl &= ( (~VOQ_ACM_EN) & (~VOQ_ACM_CTL) & (~ACM_HW_EN) ); // and 0x7B
2338 //printk(KERN_WARNING "SetHwReg8185(): [HW_VAR_ACM_CTRL] Write 0x%X\n", AcmCtrl);
2341 pHalData->AcmControl = AcmCtrl;
2343 //write_nic_byte(dev, ACM_CONTROL, AcmCtrl);
2344 write_nic_byte(dev, ACM_CONTROL, 0);
2354 ActSetWirelessMode8185(
2355 struct net_device *dev,
2359 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2360 struct ieee80211_device *ieee = priv->ieee80211;
2361 //PMGNT_INFO pMgntInfo = &(Adapter->MgntInfo);
2362 u8 btSupportedWirelessMode = GetSupportedWirelessMode8185(dev);
2364 if( (btWirelessMode & btSupportedWirelessMode) == 0 )
2365 { // Don't switch to unsupported wireless mode, 2006.02.15, by rcnjko.
2366 DMESGW("ActSetWirelessMode8185(): WirelessMode(%d) is not supported (%d)!\n",
2367 btWirelessMode, btSupportedWirelessMode);
2371 // 1. Assign wireless mode to swtich if necessary.
2372 if (btWirelessMode == WIRELESS_MODE_AUTO)
2374 if((btSupportedWirelessMode & WIRELESS_MODE_A))
2376 btWirelessMode = WIRELESS_MODE_A;
2378 else if((btSupportedWirelessMode & WIRELESS_MODE_G))
2380 btWirelessMode = WIRELESS_MODE_G;
2382 else if((btSupportedWirelessMode & WIRELESS_MODE_B))
2384 btWirelessMode = WIRELESS_MODE_B;
2388 DMESGW("ActSetWirelessMode8185(): No valid wireless mode supported, btSupportedWirelessMode(%x)!!!\n",
2389 btSupportedWirelessMode);
2390 btWirelessMode = WIRELESS_MODE_B;
2395 // 2. Swtich band: RF or BB specific actions,
2396 // for example, refresh tables in omc8255, or change initial gain if necessary.
2397 switch(priv->rf_chip)
2402 // Nothing to do for Zebra to switch band.
2403 // Update current wireless mode if we swtich to specified band successfully.
2404 ieee->mode = (WIRELESS_MODE)btWirelessMode;
2409 DMESGW("ActSetWirelessMode8185(): unsupported RF: 0x%X !!!\n", priv->rf_chip);
2413 // 3. Change related setting.
2414 if( ieee->mode == WIRELESS_MODE_A ){
2415 DMESG("WIRELESS_MODE_A\n");
2417 else if( ieee->mode == WIRELESS_MODE_B ){
2418 DMESG("WIRELESS_MODE_B\n");
2420 else if( ieee->mode == WIRELESS_MODE_G ){
2421 DMESG("WIRELESS_MODE_G\n");
2424 ActUpdateChannelAccessSetting( dev, ieee->mode, &priv->ChannelAccessSetting);
2427 void rtl8185b_irq_enable(struct net_device *dev)
2429 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2431 priv->irq_enabled = 1;
2432 write_nic_dword(dev, IMR, priv->IntrMask);
2434 //by amy for power save
2436 DrvIFIndicateDisassociation(
2437 struct net_device *dev,
2441 //printk("==> DrvIFIndicateDisassociation()\n");
2443 // nothing is needed after disassociation request.
2445 //printk("<== DrvIFIndicateDisassociation()\n");
2449 struct net_device *dev
2452 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2455 //printk("XXXXXXXXXX MgntDisconnect IBSS\n");
2457 DrvIFIndicateDisassociation(dev, unspec_reason);
2459 // PlatformZeroMemory( pMgntInfo->Bssid, 6 );
2460 for(i=0;i<6;i++) priv->ieee80211->current_network.bssid[i] = 0x55;
2462 priv->ieee80211->state = IEEE80211_NOLINK;
2466 // Vista add a Adhoc profile, HW radio off untill OID_DOT11_RESET_REQUEST
2467 // Driver would set MSR=NO_LINK, then HW Radio ON, MgntQueue Stuck.
2468 // Because Bcn DMA isn't complete, mgnt queue would stuck until Bcn packet send.
2470 // Disable Beacon Queue Own bit, suggested by jong
2471 // Adapter->HalFunc.SetTxDescOWNHandler(Adapter, BEACON_QUEUE, 0, 0);
2472 ieee80211_stop_send_beacons(priv->ieee80211);
2474 priv->ieee80211->link_change(dev);
2475 notify_wx_assoc_event(priv->ieee80211);
2477 // Stop SW Beacon.Use hw beacon so do not need to do so.by amy
2479 if(pMgntInfo->bEnableSwBeaconTimer)
2481 // SwBeaconTimer will stop if pMgntInfo->mIbss==FALSE, see SwBeaconCallback() for details.
2482 // comment out by haich, 2007.10.01
2483 //#if DEV_BUS_TYPE==USB_INTERFACE
2484 PlatformCancelTimer( Adapter, &pMgntInfo->SwBeaconTimer);
2489 // MgntIndicateMediaStatus( Adapter, RT_MEDIA_DISCONNECT, GENERAL_INDICATE );
2493 MlmeDisassociateRequest(
2494 struct net_device *dev,
2499 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2502 SendDisassociation(priv->ieee80211, asSta, asRsn );
2504 if( memcmp(priv->ieee80211->current_network.bssid, asSta, 6 ) == 0 ){
2505 //ShuChen TODO: change media status.
2506 //ShuChen TODO: What to do when disassociate.
2507 DrvIFIndicateDisassociation(dev, unspec_reason);
2510 // pMgntInfo->AsocTimestamp = 0;
2511 for(i=0;i<6;i++) priv->ieee80211->current_network.bssid[i] = 0x22;
2512 // pMgntInfo->mBrates.Length = 0;
2513 // Adapter->HalFunc.SetHwRegHandler( Adapter, HW_VAR_BASIC_RATE, (pu1Byte)(&pMgntInfo->mBrates) );
2515 ieee80211_disassociate(priv->ieee80211);
2524 struct net_device *dev,
2528 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2531 // Commented out by rcnjko, 2005.01.27:
2532 // I move SecClearAllKeys() to MgntActSet_802_11_DISASSOCIATE().
2534 // //2004/09/15, kcwu, the key should be cleared, or the new handshaking will not success
2535 // SecClearAllKeys(Adapter);
2537 // In WPA WPA2 need to Clear all key ... because new key will set after new handshaking.
2539 if( pMgntInfo->SecurityInfo.AuthMode > RT_802_11AuthModeAutoSwitch ||
2540 (pMgntInfo->bAPSuportCCKM && pMgntInfo->bCCX8021xenable) ) // In CCKM mode will Clear key
2542 SecClearAllKeys(Adapter);
2543 RT_TRACE(COMP_SEC, DBG_LOUD,("======>CCKM clear key..."))
2546 // 2004.10.11, by rcnjko.
2547 //MlmeDisassociateRequest( Adapter, pMgntInfo->Bssid, disas_lv_ss );
2548 MlmeDisassociateRequest( dev, priv->ieee80211->current_network.bssid, asRsn );
2550 priv->ieee80211->state = IEEE80211_NOLINK;
2551 // pMgntInfo->AsocTimestamp = 0;
2555 struct net_device *dev,
2559 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2561 // Schedule an workitem to wake up for ps mode, 070109, by rcnjko.
2564 if(pMgntInfo->mPss != eAwake)
2567 // Using AwkaeTimer to prevent mismatch ps state.
2568 // In the timer the state will be changed according to the RF is being awoke or not. By Bruce, 2007-10-31.
2570 // PlatformScheduleWorkItem( &(pMgntInfo->AwakeWorkItem) );
2571 PlatformSetTimer( Adapter, &(pMgntInfo->AwakeTimer), 0 );
2575 // Indication of disassociation event.
2576 //DrvIFIndicateDisassociation(Adapter, asRsn);
2577 if(IS_DOT11D_ENABLE(priv->ieee80211))
2578 Dot11d_Reset(priv->ieee80211);
2579 // In adhoc mode, update beacon frame.
2580 if( priv->ieee80211->state == IEEE80211_LINKED )
2582 if( priv->ieee80211->iw_mode == IW_MODE_ADHOC )
2584 // RT_TRACE(COMP_MLME, DBG_LOUD, ("MgntDisconnect() ===> MgntDisconnectIBSS\n"));
2585 //printk("MgntDisconnect() ===> MgntDisconnectIBSS\n");
2586 MgntDisconnectIBSS(dev);
2588 if( priv->ieee80211->iw_mode == IW_MODE_INFRA )
2590 // We clear key here instead of MgntDisconnectAP() because that
2591 // MgntActSet_802_11_DISASSOCIATE() is an interface called by OS,
2592 // e.g. OID_802_11_DISASSOCIATE in Windows while as MgntDisconnectAP() is
2593 // used to handle disassociation related things to AP, e.g. send Disassoc
2594 // frame to AP. 2005.01.27, by rcnjko.
2595 // SecClearAllKeys(Adapter);
2597 // RT_TRACE(COMP_MLME, DBG_LOUD, ("MgntDisconnect() ===> MgntDisconnectAP\n"));
2598 //printk("MgntDisconnect() ===> MgntDisconnectAP\n");
2599 MgntDisconnectAP(dev, asRsn);
2602 // Inidicate Disconnect, 2005.02.23, by rcnjko.
2603 // MgntIndicateMediaStatus( Adapter, RT_MEDIA_DISCONNECT, GENERAL_INDICATE);
2610 // Chang RF Power State.
2611 // Note that, only MgntActSet_RF_State() is allowed to set HW_VAR_RF_STATE.
2618 struct net_device *dev,
2619 RT_RF_POWER_STATE eRFPowerState
2622 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2623 bool bResult = false;
2625 // printk("---------> SetRFPowerState(): eRFPowerState(%d)\n", eRFPowerState);
2626 if(eRFPowerState == priv->eRFPowerState)
2628 // printk("<--------- SetRFPowerState(): discard the request for eRFPowerState(%d) is the same.\n", eRFPowerState);
2632 switch(priv->rf_chip)
2636 bResult = SetZebraRFPowerState8185(dev, eRFPowerState);
2640 printk("SetRFPowerState8185(): unknown RFChipID: 0x%X!!!\n", priv->rf_chip);
2643 // printk("<--------- SetRFPowerState(): bResult(%d)\n", bResult);
2648 HalEnableRx8185Dummy(
2649 struct net_device *dev
2654 HalDisableRx8185Dummy(
2655 struct net_device *dev
2661 MgntActSet_RF_State(
2662 struct net_device *dev,
2663 RT_RF_POWER_STATE StateToSet,
2667 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2668 bool bActionAllowed = false;
2669 bool bConnectBySSID = false;
2670 RT_RF_POWER_STATE rtState;
2671 u16 RFWaitCounter = 0;
2673 // printk("===>MgntActSet_RF_State(): StateToSet(%d), ChangeSource(0x%x)\n",StateToSet, ChangeSource);
2675 // Prevent the race condition of RF state change. By Bruce, 2007-11-28.
2676 // Only one thread can change the RF state at one time, and others should wait to be executed.
2681 // down(&priv->rf_state);
2682 spin_lock_irqsave(&priv->rf_ps_lock,flag);
2683 if(priv->RFChangeInProgress)
2685 // printk("====================>haha111111111\n");
2686 // up(&priv->rf_state);
2687 // RT_TRACE(COMP_RF, DBG_LOUD, ("MgntActSet_RF_State(): RF Change in progress! Wait to set..StateToSet(%d).\n", StateToSet));
2688 spin_unlock_irqrestore(&priv->rf_ps_lock,flag);
2689 // Set RF after the previous action is done.
2690 while(priv->RFChangeInProgress)
2693 // RT_TRACE(COMP_RF, DBG_LOUD, ("MgntActSet_RF_State(): Wait 1 ms (%d times)...\n", RFWaitCounter));
2694 udelay(1000); // 1 ms
2696 // Wait too long, return FALSE to avoid to be stuck here.
2697 if(RFWaitCounter > 1000) // 1sec
2699 // RT_ASSERT(FALSE, ("MgntActSet_RF_State(): Wait too logn to set RF\n"));
2700 printk("MgntActSet_RF_State(): Wait too long to set RF\n");
2701 // TODO: Reset RF state?
2708 // printk("========================>haha2\n");
2709 priv->RFChangeInProgress = true;
2710 // up(&priv->rf_state);
2711 spin_unlock_irqrestore(&priv->rf_ps_lock,flag);
2716 rtState = priv->eRFPowerState;
2723 // Turn On RF no matter the IPS setting because we need to update the RF state to Ndis under Vista, or
2724 // the Windows does not allow the driver to perform site survey any more. By Bruce, 2007-10-02.
2726 priv->RfOffReason &= (~ChangeSource);
2728 if(! priv->RfOffReason)
2730 priv->RfOffReason = 0;
2731 bActionAllowed = true;
2733 if(rtState == eRfOff && ChangeSource >=RF_CHANGE_BY_HW && !priv->bInHctTest)
2735 bConnectBySSID = true;
2739 // RT_TRACE(COMP_RF, DBG_LOUD, ("MgntActSet_RF_State - eRfon reject pMgntInfo->RfOffReason= 0x%x, ChangeSource=0x%X\n", pMgntInfo->RfOffReason, ChangeSource));
2744 // 070125, rcnjko: we always keep connected in AP mode.
2746 if (priv->RfOffReason > RF_CHANGE_BY_IPS)
2750 // Disconnect to current BSS when radio off. Asked by QuanTa.
2754 // Calling MgntDisconnect() instead of MgntActSet_802_11_DISASSOCIATE(),
2755 // because we do NOT need to set ssid to dummy ones.
2756 // Revised by Roger, 2007.12.04.
2758 MgntDisconnect( dev, disas_lv_ss );
2760 // Clear content of bssDesc[] and bssDesc4Query[] to avoid reporting old bss to UI.
2761 // 2007.05.28, by shien chang.
2762 // PlatformZeroMemory( pMgntInfo->bssDesc, sizeof(RT_WLAN_BSS)*MAX_BSS_DESC );
2763 // pMgntInfo->NumBssDesc = 0;
2764 // PlatformZeroMemory( pMgntInfo->bssDesc4Query, sizeof(RT_WLAN_BSS)*MAX_BSS_DESC );
2765 // pMgntInfo->NumBssDesc4Query = 0;
2770 priv->RfOffReason |= ChangeSource;
2771 bActionAllowed = true;
2775 priv->RfOffReason |= ChangeSource;
2776 bActionAllowed = true;
2785 // RT_TRACE(COMP_RF, DBG_LOUD, ("MgntActSet_RF_State(): Action is allowed.... StateToSet(%d), RfOffReason(%#X)\n", StateToSet, pMgntInfo->RfOffReason));
2786 // Config HW to the specified mode.
2787 // printk("MgntActSet_RF_State(): Action is allowed.... StateToSet(%d), RfOffReason(%#X)\n", StateToSet, priv->RfOffReason);
2788 SetRFPowerState(dev, StateToSet);
2791 if(StateToSet == eRfOn)
2793 HalEnableRx8185Dummy(dev);
2796 // by amy not supported
2797 // MgntActSet_802_11_SSID(Adapter, Adapter->MgntInfo.Ssid.Octet, Adapter->MgntInfo.Ssid.Length, TRUE );
2801 else if(StateToSet == eRfOff)
2803 HalDisableRx8185Dummy(dev);
2808 // printk("MgntActSet_RF_State(): Action is rejected.... StateToSet(%d), ChangeSource(%#X), RfOffReason(%#X)\n", StateToSet, ChangeSource, priv->RfOffReason);
2811 // Release RF spinlock
2812 // down(&priv->rf_state);
2813 spin_lock_irqsave(&priv->rf_ps_lock,flag);
2814 priv->RFChangeInProgress = false;
2815 // up(&priv->rf_state);
2816 spin_unlock_irqrestore(&priv->rf_ps_lock,flag);
2817 // printk("<===MgntActSet_RF_State()\n");
2818 return bActionAllowed;
2822 struct net_device *dev
2825 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2829 // This flag "bSwRfProcessing", indicates the status of IPS procedure, should be set if the IPS workitem
2830 // is really scheduled.
2831 // The old code, sets this flag before scheduling the IPS workitem and however, at the same time the
2832 // previous IPS workitem did not end yet, fails to schedule the current workitem. Thus, bSwRfProcessing
2833 // blocks the IPS procedure of switching RF.
2834 // By Bruce, 2007-12-25.
2836 priv->bSwRfProcessing = true;
2838 MgntActSet_RF_State(dev, priv->eInactivePowerState, RF_CHANGE_BY_IPS);
2841 // To solve CAM values miss in RF OFF, rewrite CAM values after RF ON. By Bruce, 2007-09-20.
2846 if( ( pMgntInfo->SecurityInfo.PairwiseEncAlgorithm == WEP104_Encryption ) ||
2847 (pMgntInfo->SecurityInfo.PairwiseEncAlgorithm == WEP40_Encryption) )
2849 if( pMgntInfo->SecurityInfo.KeyLen[index] != 0)
2850 pAdapter->HalFunc.SetKeyHandler(pAdapter, index, 0, FALSE, pMgntInfo->SecurityInfo.PairwiseEncAlgorithm, TRUE, FALSE);
2856 priv->bSwRfProcessing = false;
2861 // Enter the inactive power save mode. RF will be off
2862 // 2007.08.17, by shien chang.
2866 struct net_device *dev
2869 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2870 RT_RF_POWER_STATE rtState;
2871 //printk("==============================>enter IPS\n");
2872 if (priv->bInactivePs)
2874 rtState = priv->eRFPowerState;
2877 // Added by Bruce, 2007-12-25.
2878 // Do not enter IPS in the following conditions:
2879 // (1) RF is already OFF or Sleep
2880 // (2) bSwRfProcessing (indicates the IPS is still under going)
2881 // (3) Connectted (only disconnected can trigger IPS)
2882 // (4) IBSS (send Beacon)
2883 // (5) AP mode (send Beacon)
2885 if (rtState == eRfOn && !priv->bSwRfProcessing
2886 && (priv->ieee80211->state != IEEE80211_LINKED ))
2888 // printk("IPSEnter(): Turn off RF.\n");
2889 priv->eInactivePowerState = eRfOff;
2890 InactivePowerSave(dev);
2893 // printk("priv->eRFPowerState is %d\n",priv->eRFPowerState);
2897 struct net_device *dev
2900 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2901 RT_RF_POWER_STATE rtState;
2902 //printk("===================================>leave IPS\n");
2903 if (priv->bInactivePs)
2905 rtState = priv->eRFPowerState;
2906 if ((rtState == eRfOff || rtState == eRfSleep) && (!priv->bSwRfProcessing) && priv->RfOffReason <= RF_CHANGE_BY_IPS)
2908 // printk("IPSLeave(): Turn on RF.\n");
2909 priv->eInactivePowerState = eRfOn;
2910 InactivePowerSave(dev);
2913 // printk("priv->eRFPowerState is %d\n",priv->eRFPowerState);
2915 //by amy for power save
2916 void rtl8185b_adapter_start(struct net_device *dev)
2918 struct r8180_priv *priv = ieee80211_priv(dev);
2919 struct ieee80211_device *ieee = priv->ieee80211;
2921 u8 SupportedWirelessMode;
2922 u8 InitWirelessMode;
2923 u8 bInvalidWirelessMode = 0;
2931 //rtl8180_rtx_disable(dev);
2933 write_nic_byte(dev,0x24e, (BIT5|BIT6|BIT0));
2937 priv->dma_poll_mask = 0;
2938 priv->dma_poll_stop_mask = 0;
2940 //rtl8180_beacon_tx_disable(dev);
2942 HwConfigureRTL8185(dev);
2944 write_nic_dword(dev, MAC0, ((u32*)dev->dev_addr)[0]);
2945 write_nic_word(dev, MAC4, ((u32*)dev->dev_addr)[1] & 0xffff );
2947 write_nic_byte(dev, MSR, read_nic_byte(dev, MSR) & 0xf3); // default network type to 'No Link'
2949 //write_nic_byte(dev, BRSR, 0x0); // Set BRSR= 1M
2951 write_nic_word(dev, BcnItv, 100);
2952 write_nic_word(dev, AtimWnd, 2);
2954 //PlatformEFIOWrite2Byte(dev, FEMR, 0xFFFF);
2955 PlatformIOWrite2Byte(dev, FEMR, 0xFFFF);
2957 write_nic_byte(dev, WPA_CONFIG, 0);
2959 MacConfig_85BASIC(dev);
2961 // Override the RFSW_CTRL (MAC offset 0x272-0x273), 2006.06.07, by rcnjko.
2962 // BT_DEMO_BOARD type
2963 PlatformIOWrite2Byte(dev, RFSW_CTRL, 0x569a);
2965 //#ifdef CONFIG_RTL818X_S
2966 // for jong required
2967 // PlatformIOWrite2Byte(dev, RFSW_CTRL, 0x9a56);
2971 //PlatformIOWrite2Byte(dev, RFSW_CTRL, 0x9a56);
2973 //-----------------------------------------------------------------------------
2974 // Set up PHY related.
2975 //-----------------------------------------------------------------------------
2976 // Enable Config3.PARAM_En to revise AnaaParm.
2977 write_nic_byte(dev, CR9346, 0xc0); // enable config register write
2979 tmpu8 = read_nic_byte(dev, CONFIG3);
2980 #ifdef CONFIG_RTL818X_S
2981 write_nic_byte(dev, CONFIG3, (tmpu8 |CONFIG3_PARM_En) );
2983 write_nic_byte(dev, CONFIG3, (tmpu8 |CONFIG3_PARM_En | CONFIG3_CLKRUN_En) );
2986 // Turn on Analog power.
2987 // Asked for by William, otherwise, MAC 3-wire can't work, 2006.06.27, by rcnjko.
2988 write_nic_dword(dev, ANAPARAM2, ANAPARM2_ASIC_ON);
2989 write_nic_dword(dev, ANAPARAM, ANAPARM_ASIC_ON);
2991 #ifdef CONFIG_RTL818X_S
2992 write_nic_word(dev, ANAPARAM3, 0x0010);
2994 write_nic_byte(dev, ANAPARAM3, 0x00);
2998 write_nic_byte(dev, CONFIG3, tmpu8);
2999 write_nic_byte(dev, CR9346, 0x00);
3000 //{by amy 080312 for led
3001 // enable EEM0 and EEM1 in 9346CR
3002 btCR9346 = read_nic_byte(dev, CR9346);
3003 write_nic_byte(dev, CR9346, (btCR9346|0xC0) );
3005 // B cut use LED1 to control HW RF on/off
3006 TmpU1b = read_nic_byte(dev, CONFIG5);
3007 TmpU1b = TmpU1b & ~BIT3;
3008 write_nic_byte(dev,CONFIG5, TmpU1b);
3010 // disable EEM0 and EEM1 in 9346CR
3011 btCR9346 &= ~(0xC0);
3012 write_nic_byte(dev, CR9346, btCR9346);
3014 //Enable Led (suggested by Jong)
3015 // B-cut RF Radio on/off 5e[3]=0
3016 btPSR = read_nic_byte(dev, PSR);
3017 write_nic_byte(dev, PSR, (btPSR | BIT3));
3018 //by amy 080312 for led}
3019 // setup initial timing for RFE.
3020 write_nic_word(dev, RFPinsOutput, 0x0480);
3021 SetOutputEnableOfRfPins(dev);
3022 write_nic_word(dev, RFPinsSelect, 0x2488);
3027 // We assume RegWirelessMode has already been initialized before,
3028 // however, we has to validate the wireless mode here and provide a reasonble
3029 // initialized value if necessary. 2005.01.13, by rcnjko.
3030 SupportedWirelessMode = GetSupportedWirelessMode8185(dev);
3031 if( (ieee->mode != WIRELESS_MODE_B) &&
3032 (ieee->mode != WIRELESS_MODE_G) &&
3033 (ieee->mode != WIRELESS_MODE_A) &&
3034 (ieee->mode != WIRELESS_MODE_AUTO))
3035 { // It should be one of B, G, A, or AUTO.
3036 bInvalidWirelessMode = 1;
3039 { // One of B, G, A, or AUTO.
3040 // Check if the wireless mode is supported by RF.
3041 if( (ieee->mode != WIRELESS_MODE_AUTO) &&
3042 (ieee->mode & SupportedWirelessMode) == 0 )
3044 bInvalidWirelessMode = 1;
3048 if(bInvalidWirelessMode || ieee->mode==WIRELESS_MODE_AUTO)
3049 { // Auto or other invalid value.
3050 // Assigne a wireless mode to initialize.
3051 if((SupportedWirelessMode & WIRELESS_MODE_A))
3053 InitWirelessMode = WIRELESS_MODE_A;
3055 else if((SupportedWirelessMode & WIRELESS_MODE_G))
3057 InitWirelessMode = WIRELESS_MODE_G;
3059 else if((SupportedWirelessMode & WIRELESS_MODE_B))
3061 InitWirelessMode = WIRELESS_MODE_B;
3065 DMESGW("InitializeAdapter8185(): No valid wireless mode supported, SupportedWirelessMode(%x)!!!\n",
3066 SupportedWirelessMode);
3067 InitWirelessMode = WIRELESS_MODE_B;
3070 // Initialize RegWirelessMode if it is not a valid one.
3071 if(bInvalidWirelessMode)
3073 ieee->mode = (WIRELESS_MODE)InitWirelessMode;
3077 { // One of B, G, A.
3078 InitWirelessMode = ieee->mode;
3080 //by amy for power save
3082 // printk("initialize ENABLE_IPS\n");
3083 priv->eRFPowerState = eRfOff;
3084 priv->RfOffReason = 0;
3087 // u32 tmp = jiffies;
3088 MgntActSet_RF_State(dev, eRfOn, 0);
3090 // printk("rf on cost jiffies:%lx\n", (tmp2-tmp)*1000/HZ);
3092 // DrvIFIndicateCurrentPhyStatus(priv);
3094 // If inactive power mode is enabled, disable rf while in disconnected state.
3095 // 2007.07.16, by shien chang.
3097 if (priv->bInactivePs)
3100 // u32 tmp = jiffies;
3101 MgntActSet_RF_State(dev,eRfOff, RF_CHANGE_BY_IPS);
3103 // printk("rf off cost jiffies:%lx\n", (tmp2-tmp)*1000/HZ);
3108 //by amy for power save
3110 // Turn off RF if necessary. 2005.08.23, by rcnjko.
3111 // We shall turn off RF after setting CMDR, otherwise,
3112 // RF will be turnned on after we enable MAC Tx/Rx.
3113 if(Adapter->MgntInfo.RegRfOff == TRUE)
3115 SetRFPowerState8185(Adapter, RF_OFF);
3119 SetRFPowerState8185(Adapter, RF_ON);
3123 /* //these is equal with above TODO.
3124 write_nic_byte(dev, CR9346, 0xc0); // enable config register write
3125 write_nic_byte(dev, CONFIG3, read_nic_byte(dev, CONFIG3) | CONFIG3_PARM_En);
3126 RF_WriteReg(dev, 0x4, 0x9FF);
3127 write_nic_dword(dev, ANAPARAM2, ANAPARM2_ASIC_ON);
3128 write_nic_dword(dev, ANAPARAM, ANAPARM_ASIC_ON);
3129 write_nic_byte(dev, CONFIG3, (read_nic_byte(dev, CONFIG3)&(~CONFIG3_PARM_En)));
3130 write_nic_byte(dev, CR9346, 0x00);
3133 ActSetWirelessMode8185(dev, (u8)(InitWirelessMode));
3135 //-----------------------------------------------------------------------------
3137 rtl8185b_irq_enable(dev);
3139 netif_start_queue(dev);
3144 void rtl8185b_rx_enable(struct net_device *dev)
3148 /* for now we accept data, management & ctl frame*/
3149 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3151 rxconf=read_nic_dword(dev,RX_CONF);
3152 rxconf = rxconf &~ MAC_FILTER_MASK;
3153 rxconf = rxconf | (1<<ACCEPT_MNG_FRAME_SHIFT);
3154 rxconf = rxconf | (1<<ACCEPT_DATA_FRAME_SHIFT);
3155 rxconf = rxconf | (1<<ACCEPT_BCAST_FRAME_SHIFT);
3156 rxconf = rxconf | (1<<ACCEPT_MCAST_FRAME_SHIFT);
3157 // rxconf = rxconf | (1<<ACCEPT_CRCERR_FRAME_SHIFT);
3158 if (dev->flags & IFF_PROMISC) DMESG ("NIC in promisc mode");
3160 if(priv->ieee80211->iw_mode == IW_MODE_MONITOR || \
3161 dev->flags & IFF_PROMISC){
3162 rxconf = rxconf | (1<<ACCEPT_ALLMAC_FRAME_SHIFT);
3164 rxconf = rxconf | (1<<ACCEPT_NICMAC_FRAME_SHIFT);
3165 if(priv->card_8185 == 0)
3166 rxconf = rxconf | (1<<RX_CHECK_BSSID_SHIFT);
3169 /*if(priv->ieee80211->iw_mode == IW_MODE_MASTER){
3170 rxconf = rxconf | (1<<ACCEPT_ALLMAC_FRAME_SHIFT);
3171 rxconf = rxconf | (1<<RX_CHECK_BSSID_SHIFT);
3174 if(priv->ieee80211->iw_mode == IW_MODE_MONITOR){
3175 rxconf = rxconf | (1<<ACCEPT_CTL_FRAME_SHIFT);
3176 rxconf = rxconf | (1<<ACCEPT_ICVERR_FRAME_SHIFT);
3177 rxconf = rxconf | (1<<ACCEPT_PWR_FRAME_SHIFT);
3180 if( priv->crcmon == 1 && priv->ieee80211->iw_mode == IW_MODE_MONITOR)
3181 rxconf = rxconf | (1<<ACCEPT_CRCERR_FRAME_SHIFT);
3183 //if(!priv->card_8185){
3184 rxconf = rxconf &~ RX_FIFO_THRESHOLD_MASK;
3185 rxconf = rxconf | (RX_FIFO_THRESHOLD_NONE<<RX_FIFO_THRESHOLD_SHIFT);
3188 rxconf = rxconf | (1<<RX_AUTORESETPHY_SHIFT);
3189 rxconf = rxconf &~ MAX_RX_DMA_MASK;
3190 rxconf = rxconf | (MAX_RX_DMA_2048<<MAX_RX_DMA_SHIFT);
3192 //if(!priv->card_8185)
3193 rxconf = rxconf | RCR_ONLYERLPKT;
3195 rxconf = rxconf &~ RCR_CS_MASK;
3196 if(!priv->card_8185)
3197 rxconf |= (priv->rcr_csense<<RCR_CS_SHIFT);
3198 // rxconf &=~ 0xfff00000;
3199 // rxconf |= 0x90100000;//9014f76f;
3200 write_nic_dword(dev, RX_CONF, rxconf);
3203 if (dev->flags & IFF_PROMISC) DMESG ("NIC in promisc mode");
3205 if(priv->ieee80211->iw_mode == IW_MODE_MONITOR || \
3206 dev->flags & IFF_PROMISC){
3207 priv->ReceiveConfig = priv->ReceiveConfig & (~RCR_APM);
3208 priv->ReceiveConfig = priv->ReceiveConfig | RCR_AAP;
3211 /*if(priv->ieee80211->iw_mode == IW_MODE_MASTER){
3212 rxconf = rxconf | (1<<ACCEPT_ALLMAC_FRAME_SHIFT);
3213 rxconf = rxconf | (1<<RX_CHECK_BSSID_SHIFT);
3216 if(priv->ieee80211->iw_mode == IW_MODE_MONITOR){
3217 priv->ReceiveConfig = priv->ReceiveConfig | RCR_ACF | RCR_APWRMGT | RCR_AICV;
3220 if( priv->crcmon == 1 && priv->ieee80211->iw_mode == IW_MODE_MONITOR)
3221 priv->ReceiveConfig = priv->ReceiveConfig | RCR_ACRC32;
3223 write_nic_dword(dev, RCR, priv->ReceiveConfig);
3228 DMESG("rxconf: %x %x",priv->ReceiveConfig ,read_nic_dword(dev,RCR));
3230 cmd=read_nic_byte(dev,CMD);
3231 write_nic_byte(dev,CMD,cmd | (1<<CMD_RX_ENABLE_SHIFT));
3235 void rtl8185b_tx_enable(struct net_device *dev)
3241 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3244 txconf= read_nic_dword(dev,TX_CONF);
3245 if(priv->card_8185){
3248 byte = read_nic_byte(dev,CW_CONF);
3249 byte &= ~(1<<CW_CONF_PERPACKET_CW_SHIFT);
3250 byte &= ~(1<<CW_CONF_PERPACKET_RETRY_SHIFT);
3251 write_nic_byte(dev, CW_CONF, byte);
3253 tx_agc_ctl = read_nic_byte(dev, TX_AGC_CTL);
3254 tx_agc_ctl &= ~(1<<TX_AGC_CTL_PERPACKET_GAIN_SHIFT);
3255 tx_agc_ctl &= ~(1<<TX_AGC_CTL_PERPACKET_ANTSEL_SHIFT);
3256 tx_agc_ctl |=(1<<TX_AGC_CTL_FEEDBACK_ANT);
3257 write_nic_byte(dev, TX_AGC_CTL, tx_agc_ctl);
3259 write_nic_word(dev, 0x5e, 0x01);
3260 force_pci_posting(dev);
3262 write_nic_word(dev, 0xfe, 0x10);
3263 force_pci_posting(dev);
3265 write_nic_word(dev, 0x5e, 0x00);
3266 force_pci_posting(dev);
3269 write_nic_byte(dev, 0xec, 0x3f); /* Disable early TX */
3272 if(priv->card_8185){
3274 txconf = txconf &~ (1<<TCR_PROBE_NOTIMESTAMP_SHIFT);
3279 txconf= txconf &~ (1<<TX_CONF_HEADER_AUTOICREMENT_SHIFT);
3281 txconf= txconf | (1<<TX_CONF_HEADER_AUTOICREMENT_SHIFT);
3284 txconf = txconf &~ TX_LOOPBACK_MASK;
3285 txconf = txconf | (TX_LOOPBACK_NONE <<TX_LOOPBACK_SHIFT);
3286 txconf = txconf &~ TCR_DPRETRY_MASK;
3287 txconf = txconf &~ TCR_RTSRETRY_MASK;
3288 txconf = txconf | (priv->retry_data<<TX_DPRETRY_SHIFT);
3289 txconf = txconf | (priv->retry_rts<<TX_RTSRETRY_SHIFT);
3290 txconf = txconf &~ (1<<TX_NOCRC_SHIFT);
3292 if(priv->card_8185){
3293 if(priv->hw_plcp_len)
3294 txconf = txconf &~ TCR_PLCP_LEN;
3296 txconf = txconf | TCR_PLCP_LEN;
3298 txconf = txconf &~ TCR_SAT;
3300 txconf = txconf &~ TCR_MXDMA_MASK;
3301 txconf = txconf | (TCR_MXDMA_2048<<TCR_MXDMA_SHIFT);
3302 txconf = txconf | TCR_CWMIN;
3303 txconf = txconf | TCR_DISCW;
3305 // if(priv->ieee80211->hw_wep)
3306 // txconf=txconf &~ (1<<TX_NOICV_SHIFT);
3308 txconf=txconf | (1<<TX_NOICV_SHIFT);
3310 write_nic_dword(dev,TX_CONF,txconf);
3313 write_nic_dword(dev, TCR, priv->TransmitConfig);
3314 byte = read_nic_byte(dev, MSR);
3315 byte |= MSR_LINK_ENEDCA;
3316 write_nic_byte(dev, MSR, byte);
3321 DMESG("txconf: %x %x",priv->TransmitConfig,read_nic_dword(dev,TCR));
3324 cmd=read_nic_byte(dev,CMD);
3325 write_nic_byte(dev,CMD,cmd | (1<<CMD_TX_ENABLE_SHIFT));
3327 //write_nic_dword(dev,TX_CONF,txconf);
3331 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
3332 write_nic_byte(dev, TX_DMA_POLLING, priv->dma_poll_mask);
3333 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);