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 */
35 #include "ieee80211/dot11d.h"
37 #ifdef CONFIG_RTL8185B
39 //#define CONFIG_RTL8180_IO_MAP
41 #define TC_3W_POLL_MAX_TRY_CNT 5
42 static u8 MAC_REG_TABLE[][2]={
44 // 0x34(BRSR), 0xBE(RATE_FALLBACK_CTL), 0x1E0(ARFR) would set in HwConfigureRTL8185()
45 // 0x272(RFSW_CTRL), 0x1CE(AESMSK_QC) set in InitializeAdapter8185().
46 // 0x1F0~0x1F8 set in MacConfig_85BASIC()
47 {0x08, 0xae}, {0x0a, 0x72}, {0x5b, 0x42},
48 {0x84, 0x88}, {0x85, 0x24}, {0x88, 0x54}, {0x8b, 0xb8}, {0x8c, 0x03},
49 {0x8d, 0x40}, {0x8e, 0x00}, {0x8f, 0x00}, {0x5b, 0x18}, {0x91, 0x03},
50 {0x94, 0x0F}, {0x95, 0x32},
51 {0x96, 0x00}, {0x97, 0x07}, {0xb4, 0x22}, {0xdb, 0x00},
52 {0xf0, 0x32}, {0xf1, 0x32}, {0xf2, 0x00}, {0xf3, 0x00}, {0xf4, 0x32},
53 {0xf5, 0x43}, {0xf6, 0x00}, {0xf7, 0x00}, {0xf8, 0x46}, {0xf9, 0xa4},
54 {0xfa, 0x00}, {0xfb, 0x00}, {0xfc, 0x96}, {0xfd, 0xa4}, {0xfe, 0x00},
58 // For Flextronics system Logo PCIHCT failure:
59 // 0x1C4~0x1CD set no-zero value to avoid PCI configuration space 0x45[7]=1
61 {0x58, 0x00}, {0x59, 0x00}, {0x5a, 0x04}, {0x5b, 0x00}, {0x60, 0x24},
62 {0x61, 0x97}, {0x62, 0xF0}, {0x63, 0x09}, {0x80, 0x0F}, {0x81, 0xFF},
63 {0x82, 0xFF}, {0x83, 0x03},
64 {0xC4, 0x22}, {0xC5, 0x22}, {0xC6, 0x22}, {0xC7, 0x22}, {0xC8, 0x22}, //lzm add 080826
65 {0xC9, 0x22}, {0xCA, 0x22}, {0xCB, 0x22}, {0xCC, 0x22}, {0xCD, 0x22},//lzm add 080826
71 {0x0c, 0x04}, {0x4c, 0x30}, {0x4d, 0x08}, {0x50, 0x05}, {0x51, 0xf5},
72 {0x52, 0x04}, {0x53, 0xa0}, {0x54, 0xff}, {0x55, 0xff}, {0x56, 0xff},
73 {0x57, 0xff}, {0x58, 0x08}, {0x59, 0x08}, {0x5a, 0x08}, {0x5b, 0x08},
74 {0x60, 0x08}, {0x61, 0x08}, {0x62, 0x08}, {0x63, 0x08}, {0x64, 0x2f},
75 {0x8c, 0x3f}, {0x8d, 0x3f}, {0x8e, 0x3f},
76 {0x8f, 0x3f}, {0xc4, 0xff}, {0xc5, 0xff}, {0xc6, 0xff}, {0xc7, 0xff},
77 {0xc8, 0x00}, {0xc9, 0x00}, {0xca, 0x80}, {0xcb, 0x00},
80 {0x5e, 0x00},{0x9f, 0x03}
84 static u8 ZEBRA_AGC[]={
86 0x7E,0x7E,0x7E,0x7E,0x7D,0x7C,0x7B,0x7A,0x79,0x78,0x77,0x76,0x75,0x74,0x73,0x72,
87 0x71,0x70,0x6F,0x6E,0x6D,0x6C,0x6B,0x6A,0x69,0x68,0x67,0x66,0x65,0x64,0x63,0x62,
88 0x48,0x47,0x46,0x45,0x44,0x29,0x28,0x27,0x26,0x25,0x24,0x23,0x22,0x21,0x08,0x07,
89 0x06,0x05,0x04,0x03,0x02,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
90 0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x10,0x11,0x12,0x13,0x15,0x16,
91 0x17,0x17,0x18,0x18,0x19,0x1a,0x1a,0x1b,0x1b,0x1c,0x1c,0x1d,0x1d,0x1d,0x1e,0x1e,
92 0x1f,0x1f,0x1f,0x20,0x20,0x20,0x20,0x21,0x21,0x21,0x22,0x22,0x22,0x23,0x23,0x24,
93 0x24,0x25,0x25,0x25,0x26,0x26,0x27,0x27,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F
96 static u32 ZEBRA_RF_RX_GAIN_TABLE[]={
97 0x0096,0x0076,0x0056,0x0036,0x0016,0x01f6,0x01d6,0x01b6,
98 0x0196,0x0176,0x00F7,0x00D7,0x00B7,0x0097,0x0077,0x0057,
99 0x0037,0x00FB,0x00DB,0x00BB,0x00FF,0x00E3,0x00C3,0x00A3,
100 0x0083,0x0063,0x0043,0x0023,0x0003,0x01E3,0x01C3,0x01A3,
101 0x0183,0x0163,0x0143,0x0123,0x0103
104 static u8 OFDM_CONFIG[]={
105 // OFDM reg0x06[7:0]=0xFF: Enable power saving mode in RX
106 // OFDM reg0x3C[4]=1'b1: Enable RX power saving mode
107 // ofdm 0x3a = 0x7b ,(original : 0xfb) For ECS shielding room TP test
110 0x10, 0x0F, 0x0A, 0x0C, 0x14, 0xFA, 0xFF, 0x50,
111 0x00, 0x50, 0x00, 0x00, 0x00, 0x5C, 0x00, 0x00,
113 0x40, 0x00, 0x40, 0x00, 0x00, 0x00, 0xA8, 0x26,
114 0x32, 0x33, 0x06, 0xA5, 0x6F, 0x55, 0xC8, 0xBB,
116 0x0A, 0xE1, 0x2C, 0x4A, 0x86, 0x83, 0x34, 0x00,
117 0x4F, 0x24, 0x6F, 0xC2, 0x03, 0x40, 0x80, 0x00,
119 0xC0, 0xC1, 0x58, 0xF1, 0x00, 0xC4, 0x90, 0x3e,
120 0xD8, 0x3C, 0x7B, 0x10, 0x10
123 /*---------------------------------------------------------------
125 * the code is ported from Windows source code
126 ----------------------------------------------------------------*/
129 PlatformIOWrite1Byte(
130 struct net_device *dev,
135 #ifndef CONFIG_RTL8180_IO_MAP
136 write_nic_byte(dev, offset, data);
137 read_nic_byte(dev, offset); // To make sure write operation is completed, 2005.11.09, by rcnjko.
140 u32 Page = (offset >> 8);
145 write_nic_byte(dev, offset, data);
152 u8 psr = read_nic_byte(dev, PSR);
154 write_nic_byte(dev, PSR, ((psr & 0xfc) | (u8)Page)); // Switch to page N.
155 write_nic_byte(dev, (offset & 0xff), data);
156 write_nic_byte(dev, PSR, (psr & 0xfc)); // Switch to page 0.
161 // Illegal page number.
162 DMESGE("PlatformIOWrite1Byte(): illegal page number: %d, offset: %#X", Page, offset);
169 PlatformIOWrite2Byte(
170 struct net_device *dev,
175 #ifndef CONFIG_RTL8180_IO_MAP
176 write_nic_word(dev, offset, data);
177 read_nic_word(dev, offset); // To make sure write operation is completed, 2005.11.09, by rcnjko.
181 u32 Page = (offset >> 8);
186 write_nic_word(dev, offset, data);
193 u8 psr = read_nic_byte(dev, PSR);
195 write_nic_byte(dev, PSR, ((psr & 0xfc) | (u8)Page)); // Switch to page N.
196 write_nic_word(dev, (offset & 0xff), data);
197 write_nic_byte(dev, PSR, (psr & 0xfc)); // Switch to page 0.
202 // Illegal page number.
203 DMESGE("PlatformIOWrite2Byte(): illegal page number: %d, offset: %#X", Page, offset);
208 u8 PlatformIORead1Byte(struct net_device *dev, u32 offset);
211 PlatformIOWrite4Byte(
212 struct net_device *dev,
217 #ifndef CONFIG_RTL8180_IO_MAP
219 if (offset == PhyAddr)
220 {//For Base Band configuration.
221 unsigned char cmdByte;
222 unsigned long dataBytes;
226 cmdByte = (u8)(data & 0x000000ff);
231 // The critical section is only BB read/write race condition.
233 // 1. We assume NO one will access BB at DIRQL, otherwise, system will crash for
234 // acquiring the spinlock in such context.
235 // 2. PlatformIOWrite4Byte() MUST NOT be recursive.
237 // NdisAcquireSpinLock( &(pDevice->IoSpinLock) );
239 for(idx = 0; idx < 30; idx++)
240 { // Make sure command bit is clear before access it.
241 u1bTmp = PlatformIORead1Byte(dev, PhyAddr);
242 if((u1bTmp & BIT7) == 0)
248 for(idx=0; idx < 3; idx++)
250 PlatformIOWrite1Byte(dev,offset+1+idx,((u8*)&dataBytes)[idx] );
252 write_nic_byte(dev, offset, cmdByte);
254 // NdisReleaseSpinLock( &(pDevice->IoSpinLock) );
258 write_nic_dword(dev, offset, data);
259 read_nic_dword(dev, offset); // To make sure write operation is completed, 2005.11.09, by rcnjko.
262 u32 Page = (offset >> 8);
267 write_nic_word(dev, offset, data);
274 u8 psr = read_nic_byte(dev, PSR);
276 write_nic_byte(dev, PSR, ((psr & 0xfc) | (u8)Page)); // Switch to page N.
277 write_nic_dword(dev, (offset & 0xff), data);
278 write_nic_byte(dev, PSR, (psr & 0xfc)); // Switch to page 0.
283 // Illegal page number.
284 DMESGE("PlatformIOWrite4Byte(): illegal page number: %d, offset: %#X", Page, offset);
292 struct net_device *dev,
298 #ifndef CONFIG_RTL8180_IO_MAP
299 data = read_nic_byte(dev, offset);
302 u32 Page = (offset >> 8);
307 data = read_nic_byte(dev, offset);
314 u8 psr = read_nic_byte(dev, PSR);
316 write_nic_byte(dev, PSR, ((psr & 0xfc) | (u8)Page)); // Switch to page N.
317 data = read_nic_byte(dev, (offset & 0xff));
318 write_nic_byte(dev, PSR, (psr & 0xfc)); // Switch to page 0.
323 // Illegal page number.
324 DMESGE("PlatformIORead1Byte(): illegal page number: %d, offset: %#X", Page, offset);
334 struct net_device *dev,
340 #ifndef CONFIG_RTL8180_IO_MAP
341 data = read_nic_word(dev, offset);
344 u32 Page = (offset >> 8);
349 data = read_nic_word(dev, offset);
356 u8 psr = read_nic_byte(dev, PSR);
358 write_nic_byte(dev, PSR, ((psr & 0xfc) | (u8)Page)); // Switch to page N.
359 data = read_nic_word(dev, (offset & 0xff));
360 write_nic_byte(dev, PSR, (psr & 0xfc)); // Switch to page 0.
365 // Illegal page number.
366 DMESGE("PlatformIORead2Byte(): illegal page number: %d, offset: %#X", Page, offset);
376 struct net_device *dev,
382 #ifndef CONFIG_RTL8180_IO_MAP
383 data = read_nic_dword(dev, offset);
386 u32 Page = (offset >> 8);
391 data = read_nic_dword(dev, offset);
398 u8 psr = read_nic_byte(dev, PSR);
400 write_nic_byte(dev, PSR, ((psr & 0xfc) | (u8)Page)); // Switch to page N.
401 data = read_nic_dword(dev, (offset & 0xff));
402 write_nic_byte(dev, PSR, (psr & 0xfc)); // Switch to page 0.
407 // Illegal page number.
408 DMESGE("PlatformIORead4Byte(): illegal page number: %d, offset: %#X\n", Page, offset);
417 SetOutputEnableOfRfPins(
418 struct net_device *dev
421 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
423 switch(priv->rf_chip)
425 case RFCHIPID_RTL8225:
428 write_nic_word(dev, RFPinsEnable, 0x1bff);
429 //write_nic_word(dev, RFPinsEnable, 0x1fff);
436 struct net_device *dev,
444 u16 oval,oval2,oval3;
449 // RTL8187S HSSI Read/Write Function
450 u1bTmp = read_nic_byte(dev, RF_SW_CONFIG);
451 u1bTmp |= RF_SW_CFG_SI; //reg08[1]=1 Serial Interface(SI)
452 write_nic_byte(dev, RF_SW_CONFIG, u1bTmp);
453 UshortBuffer = read_nic_word(dev, RFPinsOutput);
454 oval = UshortBuffer & 0xfff8; // We shall clear bit0, 1, 2 first, 2005.10.28, by rcnjko.
456 oval2 = read_nic_word(dev, RFPinsEnable);
457 oval3 = read_nic_word(dev, RFPinsSelect);
459 // <RJ_NOTE> 3-wire should be controled by HW when we finish SW 3-wire programming. 2005.08.10, by rcnjko.
462 write_nic_word(dev, RFPinsEnable, (oval2|0x0007)); // Set To Output Enable
463 write_nic_word(dev, RFPinsSelect, (oval3|0x0007)); // Set To SW Switch
466 // Add this to avoid hardware and software 3-wire conflict.
467 // 2005.03.01, by rcnjko.
469 twreg.struc.enableB = 1;
470 write_nic_word(dev, RFPinsOutput, (twreg.longData|oval)); // Set SI_EN (RFLE)
472 twreg.struc.enableB = 0;
473 write_nic_word(dev, RFPinsOutput, (twreg.longData|oval)); // Clear SI_EN (RFLE)
476 mask = (low2high)?0x01:((u32)0x01<<(totalLength-1));
478 for(i=0; i<totalLength/2; i++)
480 twreg.struc.data = ((data2Write&mask)!=0) ? 1 : 0;
481 write_nic_word(dev, RFPinsOutput, (twreg.longData|oval));
483 write_nic_word(dev, RFPinsOutput, (twreg.longData|oval));
484 write_nic_word(dev, RFPinsOutput, (twreg.longData|oval));
486 mask = (low2high)?(mask<<1):(mask>>1);
487 twreg.struc.data = ((data2Write&mask)!=0) ? 1 : 0;
488 write_nic_word(dev, RFPinsOutput, (twreg.longData|oval));
489 write_nic_word(dev, RFPinsOutput, (twreg.longData|oval));
491 write_nic_word(dev, RFPinsOutput, (twreg.longData|oval));
492 mask = (low2high)?(mask<<1):(mask>>1);
495 twreg.struc.enableB = 1;
497 twreg.struc.data = 0;
498 write_nic_word(dev, RFPinsOutput, twreg.longData|oval);
501 write_nic_word(dev, RFPinsOutput, oval|0x0004);
502 write_nic_word(dev, RFPinsSelect, oval3|0x0000);
504 SetOutputEnableOfRfPins(dev);
511 struct net_device *dev,
524 // Check if WE and RE are cleared.
525 for(TryCnt = 0; TryCnt < TC_3W_POLL_MAX_TRY_CNT; TryCnt++)
527 u1bTmp = read_nic_byte(dev, SW_3W_CMD1);
528 if( (u1bTmp & (SW_3W_CMD1_RE|SW_3W_CMD1_WE)) == 0 )
534 if (TryCnt == TC_3W_POLL_MAX_TRY_CNT)
535 panic("HwThreeWire(): CmdReg: %#X RE|WE bits are not clear!!\n", u1bTmp);
537 // RTL8187S HSSI Read/Write Function
538 u1bTmp = read_nic_byte(dev, RF_SW_CONFIG);
542 u1bTmp |= RF_SW_CFG_SI; //reg08[1]=1 Serial Interface(SI)
545 u1bTmp &= ~RF_SW_CFG_SI; //reg08[1]=0 Parallel Interface(PI)
548 write_nic_byte(dev, RF_SW_CONFIG, u1bTmp);
552 // jong: HW SI read must set reg84[3]=0.
553 u1bTmp = read_nic_byte(dev, RFPinsSelect);
555 write_nic_byte(dev, RFPinsSelect, u1bTmp );
557 // Fill up data buffer for write operation.
561 if(nDataBufBitCnt == 16)
563 write_nic_word(dev, SW_3W_DB0, *((u16*)pDataBuf));
565 else if(nDataBufBitCnt == 64) // RTL8187S shouldn't enter this case
567 write_nic_dword(dev, SW_3W_DB0, *((u32*)pDataBuf));
568 write_nic_dword(dev, SW_3W_DB1, *((u32*)(pDataBuf + 4)));
573 int ByteCnt = nDataBufBitCnt / 8;
574 //printk("%d\n",nDataBufBitCnt);
575 if ((nDataBufBitCnt % 8) != 0)
576 panic("HwThreeWire(): nDataBufBitCnt(%d) should be multiple of 8!!!\n",
579 if (nDataBufBitCnt > 64)
580 panic("HwThreeWire(): nDataBufBitCnt(%d) should <= 64!!!\n",
583 for(idx = 0; idx < ByteCnt; idx++)
585 write_nic_byte(dev, (SW_3W_DB0+idx), *(pDataBuf+idx));
593 // SI - reg274[3:0] : RF register's Address
594 write_nic_word(dev, SW_3W_DB0, *((u16*)pDataBuf) );
598 // PI - reg274[15:12] : RF register's Address
599 write_nic_word(dev, SW_3W_DB0, (*((u16*)pDataBuf)) << 12);
603 // Set up command: WE or RE.
606 write_nic_byte(dev, SW_3W_CMD1, SW_3W_CMD1_WE);
610 write_nic_byte(dev, SW_3W_CMD1, SW_3W_CMD1_RE);
613 // Check if DONE is set.
614 for(TryCnt = 0; TryCnt < TC_3W_POLL_MAX_TRY_CNT; TryCnt++)
616 u1bTmp = read_nic_byte(dev, SW_3W_CMD1);
617 if( (u1bTmp & SW_3W_CMD1_DONE) != 0 )
624 write_nic_byte(dev, SW_3W_CMD1, 0);
626 // Read back data for read operation.
631 //Serial Interface : reg363_362[11:0]
632 *((u16*)pDataBuf) = read_nic_word(dev, SI_DATA_READ) ;
636 //Parallel Interface : reg361_360[11:0]
637 *((u16*)pDataBuf) = read_nic_word(dev, PI_DATA_READ);
640 *((u16*)pDataBuf) &= 0x0FFF;
651 struct net_device *dev,
664 // Check if WE and RE are cleared.
665 for(TryCnt = 0; TryCnt < TC_3W_POLL_MAX_TRY_CNT; TryCnt++)
667 u1bTmp = read_nic_byte(dev, SW_3W_CMD1);
668 if( (u1bTmp & (SW_3W_CMD1_RE|SW_3W_CMD1_WE)) == 0 )
674 if (TryCnt == TC_3W_POLL_MAX_TRY_CNT)
675 panic("HwThreeWire(): CmdReg: %#X RE|WE bits are not clear!!\n", u1bTmp);
677 // Fill up data buffer for write operation.
678 if(nDataBufBitCnt == 16)
680 write_nic_word(dev, SW_3W_DB0, *((u16 *)pDataBuf));
682 else if(nDataBufBitCnt == 64)
684 write_nic_dword(dev, SW_3W_DB0, *((u32 *)pDataBuf));
685 write_nic_dword(dev, SW_3W_DB1, *((u32 *)(pDataBuf + 4)));
690 int ByteCnt = nDataBufBitCnt / 8;
692 if ((nDataBufBitCnt % 8) != 0)
693 panic("HwThreeWire(): nDataBufBitCnt(%d) should be multiple of 8!!!\n",
696 if (nDataBufBitCnt > 64)
697 panic("HwThreeWire(): nDataBufBitCnt(%d) should <= 64!!!\n",
700 for(idx = 0; idx < ByteCnt; idx++)
702 write_nic_byte(dev, (SW_3W_DB0+idx), *(pDataBuf+idx));
706 // Fill up length field.
707 u1bTmp = (u8)(nDataBufBitCnt - 1); // Number of bits - 1.
709 u1bTmp |= SW_3W_CMD0_HOLD;
710 write_nic_byte(dev, SW_3W_CMD0, u1bTmp);
712 // Set up command: WE or RE.
715 write_nic_byte(dev, SW_3W_CMD1, SW_3W_CMD1_WE);
719 write_nic_byte(dev, SW_3W_CMD1, SW_3W_CMD1_RE);
722 // Check if WE and RE are cleared and DONE is set.
723 for(TryCnt = 0; TryCnt < TC_3W_POLL_MAX_TRY_CNT; TryCnt++)
725 u1bTmp = read_nic_byte(dev, SW_3W_CMD1);
726 if( (u1bTmp & (SW_3W_CMD1_RE|SW_3W_CMD1_WE)) == 0 &&
727 (u1bTmp & SW_3W_CMD1_DONE) != 0 )
733 if(TryCnt == TC_3W_POLL_MAX_TRY_CNT)
735 //RT_ASSERT(TryCnt != TC_3W_POLL_MAX_TRY_CNT,
736 // ("HwThreeWire(): CmdReg: %#X RE|WE bits are not clear or DONE is not set!!\n", u1bTmp));
737 // Workaround suggested by wcchu: clear WE here. 2006.07.07, by rcnjko.
738 write_nic_byte(dev, SW_3W_CMD1, 0);
741 // Read back data for read operation.
742 // <RJ_TODO> I am not sure if this is correct output format of a read operation.
745 if(nDataBufBitCnt == 16)
747 *((u16 *)pDataBuf) = read_nic_word(dev, SW_3W_DB0);
749 else if(nDataBufBitCnt == 64)
751 *((u32 *)pDataBuf) = read_nic_dword(dev, SW_3W_DB0);
752 *((u32 *)(pDataBuf + 4)) = read_nic_dword(dev, SW_3W_DB1);
757 int ByteCnt = nDataBufBitCnt / 8;
759 if ((nDataBufBitCnt % 8) != 0)
760 panic("HwThreeWire(): nDataBufBitCnt(%d) should be multiple of 8!!!\n",
763 if (nDataBufBitCnt > 64)
764 panic("HwThreeWire(): nDataBufBitCnt(%d) should <= 64!!!\n",
767 for(idx = 0; idx < ByteCnt; idx++)
769 *(pDataBuf+idx) = read_nic_byte(dev, (SW_3W_DB0+idx));
782 struct net_device *dev,
792 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
795 switch(priv->rf_chip)
797 case RFCHIPID_RTL8225:
798 case RF_ZEBRA2: // Annie 2006-05-12.
799 case RF_ZEBRA4: //by amy
800 switch(priv->RegThreeWireMode)
803 { // Perform SW 3-wire programming by driver.
804 data2Write = (data << 4) | (u32)(offset & 0x0f);
807 ZEBRA_RFSerialWrite(dev, data2Write, len, low2high);
813 data2Write = (data << 4) | (u32)(offset & 0x0f);
817 (u8 *)(&data2Write), // pDataBuf,
818 len, // nDataBufBitCnt,
823 case HW_THREE_WIRE_PI: //Parallel Interface
825 data2Write = (data << 4) | (u32)(offset & 0x0f);
829 (u8*)(&data2Write), // pDataBuf,
830 len, // nDataBufBitCnt,
838 case HW_THREE_WIRE_SI: //Serial Interface
840 data2Write = (data << 4) | (u32)(offset & 0x0f);
842 // printk(" enter ZEBRA_RFSerialWrite\n ");
844 // ZEBRA_RFSerialWrite(dev, data2Write, len, low2high);
848 (u8*)(&data2Write), // pDataBuf,
849 len, // nDataBufBitCnt,
853 // printk(" exit ZEBRA_RFSerialWrite\n ");
859 DMESGE("RF_WriteReg(): invalid RegThreeWireMode(%d) !!!", priv->RegThreeWireMode);
865 DMESGE("RF_WriteReg(): unknown RFChipID: %#X", priv->rf_chip);
873 struct net_device *dev,
883 u16 oval,oval2,oval3,tmp, wReg80;
887 //PHAL_DATA_8187 pHalData = GetHalData8187(pAdapter);
888 { // RTL8187S HSSI Read/Write Function
889 u1bTmp = read_nic_byte(dev, RF_SW_CONFIG);
890 u1bTmp |= RF_SW_CFG_SI; //reg08[1]=1 Serial Interface(SI)
891 write_nic_byte(dev, RF_SW_CONFIG, u1bTmp);
894 wReg80 = oval = read_nic_word(dev, RFPinsOutput);
895 oval2 = read_nic_word(dev, RFPinsEnable);
896 oval3 = read_nic_word(dev, RFPinsSelect);
898 write_nic_word(dev, RFPinsEnable, oval2|0xf);
899 write_nic_word(dev, RFPinsSelect, oval3|0xf);
903 // We must clear BIT0-3 here, otherwise,
904 // SW_Enalbe will be true when we first call ZEBRA_RFSerialRead() after 8187MPVC open,
905 // which will cause the value read become 0. 2005.04.11, by rcnjko.
908 // Avoid collision with hardware three-wire.
910 twreg.struc.enableB = 1;
911 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(4);
914 twreg.struc.enableB = 0;
916 twreg.struc.read_write = 0;
917 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(5);
919 mask = (low2high) ? 0x01 : ((u32)0x01<<(32-1));
920 for(i = 0; i < wLength/2; i++)
922 twreg.struc.data = ((data2Write&mask) != 0) ? 1 : 0;
923 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(1);
925 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
926 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
928 mask = (low2high) ? (mask<<1): (mask>>1);
932 // 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.
933 //PlatformEFIOWrite2Byte(pAdapter, RFPinsEnable, 0xe); // turn off data enable
934 //PlatformEFIOWrite2Byte(pAdapter, RFPinsSelect, 0xe);
936 twreg.struc.read_write=1;
937 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
939 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
942 twreg.struc.data = ((data2Write&mask) != 0) ? 1: 0;
943 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
944 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
947 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(1);
949 mask = (low2high) ? (mask<<1) : (mask>>1);
953 twreg.struc.data = 0;
954 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
955 mask = (low2high) ? 0x01 : ((u32)0x01 << (12-1));
958 // 061016, by rcnjko:
959 // We must set data pin to HW controled, otherwise RF can't driver it and
960 // value RF register won't be able to read back properly.
962 write_nic_word(dev, RFPinsEnable, ( ((oval2|0x0E) & (~0x01))) );
964 for(i = 0; i < rLength; i++)
966 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(1);
968 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
969 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
970 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
971 tmp = read_nic_word(dev, RFPinsInput);
972 tdata.longData = tmp;
973 *data2Read |= tdata.struc.clk ? mask : 0;
976 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
978 mask = (low2high) ? (mask<<1) : (mask>>1);
980 twreg.struc.enableB = 1;
982 twreg.struc.data = 0;
983 twreg.struc.read_write = 1;
984 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
986 //PlatformEFIOWrite2Byte(pAdapter, RFPinsEnable, oval2|0x8); // Set To Output Enable
987 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.
988 //PlatformEFIOWrite2Byte(pAdapter, RFPinsEnable, 0x1bff);
989 write_nic_word(dev, RFPinsSelect, oval3); // Set To SW Switch
990 //PlatformEFIOWrite2Byte(pAdapter, RFPinsSelect, 0x0488);
991 write_nic_word(dev, RFPinsOutput, 0x3a0);
992 //PlatformEFIOWrite2Byte(pAdapter, RFPinsOutput, 0x0480);
998 struct net_device *dev,
1002 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1009 switch(priv->rf_chip)
1011 case RFCHIPID_RTL8225:
1014 switch(priv->RegThreeWireMode)
1016 case HW_THREE_WIRE_PI: // For 87S Parallel Interface.
1018 data2Write = ((u32)(offset&0x0f));
1022 (u8*)(&data2Write), // pDataBuf,
1023 wlen, // nDataBufBitCnt,
1026 dataRead= data2Write;
1030 case HW_THREE_WIRE_SI: // For 87S Serial Interface.
1032 data2Write = ((u32)(offset&0x0f)) ;
1036 (u8*)(&data2Write), // pDataBuf,
1037 wlen, // nDataBufBitCnt,
1041 dataRead= data2Write;
1045 // Perform SW 3-wire programming by driver.
1048 data2Write = ((u32)(offset&0x1f)) << 27; // For Zebra E-cut. 2005.04.11, by rcnjko.
1052 ZEBRA_RFSerialRead(dev, data2Write, wlen,&dataRead,rlen, low2high);
1066 // by Owen on 04/07/14 for writing BB register successfully
1069 struct net_device *dev,
1073 //u8 TimeoutCounter;
1077 UCharData = (u8)((Data & 0x0000ff00) >> 8);
1078 PlatformIOWrite4Byte(dev, PhyAddr, Data);
1079 //for(TimeoutCounter = 10; TimeoutCounter > 0; TimeoutCounter--)
1081 PlatformIOWrite4Byte(dev, PhyAddr, Data & 0xffffff7f);
1082 RegisterContent = PlatformIORead1Byte(dev, PhyDataR);
1083 //if(UCharData == RegisterContent)
1090 struct net_device *dev,
1094 //u8 TimeoutCounter;
1097 PlatformIOWrite4Byte(dev, PhyAddr, addr & 0xffffff7f);
1098 RegisterContent = PlatformIORead1Byte(dev, PhyDataR);
1100 return RegisterContent;
1105 // Perform Antenna settings with antenna diversity on 87SE.
1106 // Created by Roger, 2008.01.25.
1109 SetAntennaConfig87SE(
1110 struct net_device *dev,
1111 u8 DefaultAnt, // 0: Main, 1: Aux.
1112 bool bAntDiversity // 1:Enable, 0: Disable.
1115 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1116 bool bAntennaSwitched = true;
1118 //printk("SetAntennaConfig87SE(): DefaultAnt(%d), bAntDiversity(%d)\n", DefaultAnt, bAntDiversity);
1120 // Threshold for antenna diversity.
1121 write_phy_cck(dev, 0x0c, 0x09); // Reg0c : 09
1123 if( bAntDiversity ) // Enable Antenna Diversity.
1125 if( DefaultAnt == 1 ) // aux antenna
1127 // Mac register, aux antenna
1128 write_nic_byte(dev, ANTSEL, 0x00);
1130 // Config CCK RX antenna.
1131 write_phy_cck(dev, 0x11, 0xbb); // Reg11 : bb
1132 write_phy_cck(dev, 0x01, 0xc7); // Reg01 : c7
1134 // Config OFDM RX antenna.
1135 write_phy_ofdm(dev, 0x0D, 0x54); // Reg0d : 54
1136 write_phy_ofdm(dev, 0x18, 0xb2); // Reg18 : b2
1138 else // use main antenna
1140 // Mac register, main antenna
1141 write_nic_byte(dev, ANTSEL, 0x03);
1143 // Config CCK RX antenna.
1144 write_phy_cck(dev, 0x11, 0x9b); // Reg11 : 9b
1145 write_phy_cck(dev, 0x01, 0xc7); // Reg01 : c7
1147 // Config OFDM RX antenna.
1148 write_phy_ofdm(dev, 0x0d, 0x5c); // Reg0d : 5c
1149 write_phy_ofdm(dev, 0x18, 0xb2); // Reg18 : b2
1152 else // Disable Antenna Diversity.
1154 if( DefaultAnt == 1 ) // aux Antenna
1156 // Mac register, aux antenna
1157 write_nic_byte(dev, ANTSEL, 0x00);
1159 // Config CCK RX antenna.
1160 write_phy_cck(dev, 0x11, 0xbb); // Reg11 : bb
1161 write_phy_cck(dev, 0x01, 0x47); // Reg01 : 47
1163 // Config OFDM RX antenna.
1164 write_phy_ofdm(dev, 0x0D, 0x54); // Reg0d : 54
1165 write_phy_ofdm(dev, 0x18, 0x32); // Reg18 : 32
1167 else // main Antenna
1169 // Mac register, main antenna
1170 write_nic_byte(dev, ANTSEL, 0x03);
1172 // Config CCK RX antenna.
1173 write_phy_cck(dev, 0x11, 0x9b); // Reg11 : 9b
1174 write_phy_cck(dev, 0x01, 0x47); // Reg01 : 47
1176 // Config OFDM RX antenna.
1177 write_phy_ofdm(dev, 0x0D, 0x5c); // Reg0d : 5c
1178 write_phy_ofdm(dev, 0x18, 0x32); // Reg18 : 32
1181 priv->CurrAntennaIndex = DefaultAnt; // Update default settings.
1182 return bAntennaSwitched;
1185 /*---------------------------------------------------------------
1186 * Hardware Initialization.
1187 * the code is ported from Windows source code
1188 ----------------------------------------------------------------*/
1191 ZEBRA_Config_85BASIC_HardCode(
1192 struct net_device *dev
1196 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1199 u32 u4bRegOffset, u4bRegValue, u4bRF23, u4bRF24;
1203 //=============================================================================
1204 // 87S_PCIE :: RADIOCFG.TXT
1205 //=============================================================================
1208 // Page1 : reg16-reg30
1209 RF_WriteReg(dev, 0x00, 0x013f); mdelay(1); // switch to page1
1210 u4bRF23= RF_ReadReg(dev, 0x08); mdelay(1);
1211 u4bRF24= RF_ReadReg(dev, 0x09); mdelay(1);
1213 if (u4bRF23==0x818 && u4bRF24==0x70C && priv->card_8185 == VERSION_8187S_C)
1214 priv->card_8185 = VERSION_8187S_D;
1216 // Page0 : reg0-reg15
1218 // RF_WriteReg(dev, 0x00, 0x003f); mdelay(1);//1
1219 RF_WriteReg(dev, 0x00, 0x009f); mdelay(1);// 1
1221 RF_WriteReg(dev, 0x01, 0x06e0); mdelay(1);
1223 // RF_WriteReg(dev, 0x02, 0x004c); mdelay(1);//2
1224 RF_WriteReg(dev, 0x02, 0x004d); mdelay(1);// 2
1226 // RF_WriteReg(dev, 0x03, 0x0000); mdelay(1);//3
1227 RF_WriteReg(dev, 0x03, 0x07f1); mdelay(1);// 3
1229 RF_WriteReg(dev, 0x04, 0x0975); mdelay(1);
1230 RF_WriteReg(dev, 0x05, 0x0c72); mdelay(1);
1231 RF_WriteReg(dev, 0x06, 0x0ae6); mdelay(1);
1232 RF_WriteReg(dev, 0x07, 0x00ca); mdelay(1);
1233 RF_WriteReg(dev, 0x08, 0x0e1c); mdelay(1);
1234 RF_WriteReg(dev, 0x09, 0x02f0); mdelay(1);
1235 RF_WriteReg(dev, 0x0a, 0x09d0); mdelay(1);
1236 RF_WriteReg(dev, 0x0b, 0x01ba); mdelay(1);
1237 RF_WriteReg(dev, 0x0c, 0x0640); mdelay(1);
1238 RF_WriteReg(dev, 0x0d, 0x08df); mdelay(1);
1239 RF_WriteReg(dev, 0x0e, 0x0020); mdelay(1);
1240 RF_WriteReg(dev, 0x0f, 0x0990); mdelay(1);
1243 // Page1 : reg16-reg30
1244 RF_WriteReg(dev, 0x00, 0x013f); mdelay(1);
1246 RF_WriteReg(dev, 0x03, 0x0806); mdelay(1);
1248 if(priv->card_8185 < VERSION_8187S_C)
1250 RF_WriteReg(dev, 0x04, 0x03f7); mdelay(1);
1251 RF_WriteReg(dev, 0x05, 0x05ab); mdelay(1);
1252 RF_WriteReg(dev, 0x06, 0x00c1); mdelay(1);
1256 RF_WriteReg(dev, 0x04, 0x03a7); mdelay(1);
1257 RF_WriteReg(dev, 0x05, 0x059b); mdelay(1);
1258 RF_WriteReg(dev, 0x06, 0x0081); mdelay(1);
1262 RF_WriteReg(dev, 0x07, 0x01A0); mdelay(1);
1263 // Don't write RF23/RF24 to make a difference between 87S C cut and D cut. asked by SD3 stevenl.
1264 // RF_WriteReg(dev, 0x08, 0x0597); mdelay(1);
1265 // RF_WriteReg(dev, 0x09, 0x050a); mdelay(1);
1266 RF_WriteReg(dev, 0x0a, 0x0001); mdelay(1);
1267 RF_WriteReg(dev, 0x0b, 0x0418); mdelay(1);
1269 if(priv->card_8185 == VERSION_8187S_D)
1271 RF_WriteReg(dev, 0x0c, 0x0fbe); mdelay(1);
1272 RF_WriteReg(dev, 0x0d, 0x0008); mdelay(1);
1273 RF_WriteReg(dev, 0x0e, 0x0807); mdelay(1); // RX LO buffer
1277 RF_WriteReg(dev, 0x0c, 0x0fbe); mdelay(1);
1278 RF_WriteReg(dev, 0x0d, 0x0008); mdelay(1);
1279 RF_WriteReg(dev, 0x0e, 0x0806); mdelay(1); // RX LO buffer
1282 RF_WriteReg(dev, 0x0f, 0x0acc); mdelay(1);
1284 // RF_WriteReg(dev, 0x00, 0x017f); mdelay(1);//6
1285 RF_WriteReg(dev, 0x00, 0x01d7); mdelay(1);// 6
1287 RF_WriteReg(dev, 0x03, 0x0e00); mdelay(1);
1288 RF_WriteReg(dev, 0x04, 0x0e50); mdelay(1);
1291 RF_WriteReg(dev, 0x01, i); mdelay(1);
1292 RF_WriteReg(dev, 0x02, ZEBRA_RF_RX_GAIN_TABLE[i]); mdelay(1);
1293 //DbgPrint("RF - 0x%x = 0x%x", i, ZEBRA_RF_RX_GAIN_TABLE[i]);
1296 RF_WriteReg(dev, 0x05, 0x0203); mdelay(1); /// 203, 343
1297 //RF_WriteReg(dev, 0x06, 0x0300); mdelay(1); // 400
1298 RF_WriteReg(dev, 0x06, 0x0200); mdelay(1); // 400
1300 RF_WriteReg(dev, 0x00, 0x0137); mdelay(1); // switch to reg16-reg30, and HSSI disable 137
1301 mdelay(10); // Deay 10 ms. //0xfd
1303 // RF_WriteReg(dev, 0x0c, 0x09be); mdelay(1); // 7
1304 //RF_WriteReg(dev, 0x0c, 0x07be); mdelay(1);
1305 //mdelay(10); // Deay 10 ms. //0xfd
1307 RF_WriteReg(dev, 0x0d, 0x0008); mdelay(1); // Z4 synthesizer loop filter setting, 392
1308 mdelay(10); // Deay 10 ms. //0xfd
1310 RF_WriteReg(dev, 0x00, 0x0037); mdelay(1); // switch to reg0-reg15, and HSSI disable
1311 mdelay(10); // Deay 10 ms. //0xfd
1313 RF_WriteReg(dev, 0x04, 0x0160); mdelay(1); // CBC on, Tx Rx disable, High gain
1314 mdelay(10); // Deay 10 ms. //0xfd
1316 RF_WriteReg(dev, 0x07, 0x0080); mdelay(1); // Z4 setted channel 1
1317 mdelay(10); // Deay 10 ms. //0xfd
1319 RF_WriteReg(dev, 0x02, 0x088D); mdelay(1); // LC calibration
1320 mdelay(200); // Deay 200 ms. //0xfd
1321 mdelay(10); // Deay 10 ms. //0xfd
1322 mdelay(10); // Deay 10 ms. //0xfd
1324 RF_WriteReg(dev, 0x00, 0x0137); mdelay(1); // switch to reg16-reg30 137, and HSSI disable 137
1325 mdelay(10); // Deay 10 ms. //0xfd
1327 RF_WriteReg(dev, 0x07, 0x0000); mdelay(1);
1328 RF_WriteReg(dev, 0x07, 0x0180); mdelay(1);
1329 RF_WriteReg(dev, 0x07, 0x0220); mdelay(1);
1330 RF_WriteReg(dev, 0x07, 0x03E0); mdelay(1);
1332 // DAC calibration off 20070702
1333 RF_WriteReg(dev, 0x06, 0x00c1); mdelay(1);
1334 RF_WriteReg(dev, 0x0a, 0x0001); mdelay(1);
1336 // For crystal calibration, added by Roger, 2007.12.11.
1337 if( priv->bXtalCalibration ) // reg 30.
1338 { // enable crystal calibration.
1339 // RF Reg[30], (1)Xin:[12:9], Xout:[8:5], addr[4:0].
1340 // (2)PA Pwr delay timer[15:14], default: 2.4us, set BIT15=0
1341 // (3)RF signal on/off when calibration[13], default: on, set BIT13=0.
1342 // So we should minus 4 BITs offset.
1343 RF_WriteReg(dev, 0x0f, (priv->XtalCal_Xin<<5)|(priv->XtalCal_Xout<<1)|BIT11|BIT9); mdelay(1);
1344 printk("ZEBRA_Config_85BASIC_HardCode(): (%02x)\n",
1345 (priv->XtalCal_Xin<<5) | (priv->XtalCal_Xout<<1) | BIT11| BIT9);
1348 { // using default value. Xin=6, Xout=6.
1349 RF_WriteReg(dev, 0x0f, 0x0acc); mdelay(1);
1352 // RF_WriteReg(dev, 0x0f, 0x0acc); mdelay(1); //-by amy 080312
1354 RF_WriteReg(dev, 0x00, 0x00bf); mdelay(1); // switch to reg0-reg15, and HSSI enable
1355 // RF_WriteReg(dev, 0x0d, 0x009f); mdelay(1); // Rx BB start calibration, 00c//-edward
1356 RF_WriteReg(dev, 0x0d, 0x08df); mdelay(1); // Rx BB start calibration, 00c//+edward
1357 RF_WriteReg(dev, 0x02, 0x004d); mdelay(1); // temperature meter off
1358 RF_WriteReg(dev, 0x04, 0x0975); mdelay(1); // Rx mode
1359 mdelay(10); // Deay 10 ms. //0xfe
1360 mdelay(10); // Deay 10 ms. //0xfe
1361 mdelay(10); // Deay 10 ms. //0xfe
1362 RF_WriteReg(dev, 0x00, 0x0197); mdelay(1); // Rx mode//+edward
1363 RF_WriteReg(dev, 0x05, 0x05ab); mdelay(1); // Rx mode//+edward
1364 RF_WriteReg(dev, 0x00, 0x009f); mdelay(1); // Rx mode//+edward
1367 RF_WriteReg(dev, 0x00, 0x0197); mdelay(1);
1368 RF_WriteReg(dev, 0x05, 0x05ab); mdelay(1);
1369 RF_WriteReg(dev, 0x00, 0x009F); mdelay(1);
1371 RF_WriteReg(dev, 0x01, 0x0000); mdelay(1); // Rx mode//+edward
1372 RF_WriteReg(dev, 0x02, 0x0000); mdelay(1); // Rx mode//+edward
1373 //power save parameters.
1374 u1b24E = read_nic_byte(dev, 0x24E);
1375 write_nic_byte(dev, 0x24E, (u1b24E & (~(BIT5|BIT6))));
1377 //=============================================================================
1379 //=============================================================================
1381 //=============================================================================
1383 /* [POWER SAVE] Power Saving Parameters by jong. 2007-11-27
1384 CCK reg0x00[7]=1'b1 :power saving for TX (default)
1385 CCK reg0x00[6]=1'b1: power saving for RX (default)
1386 CCK reg0x06[4]=1'b1: turn off channel estimation related circuits if not doing channel estimation.
1387 CCK reg0x06[3]=1'b1: turn off unused circuits before cca = 1
1388 CCK reg0x06[2]=1'b1: turn off cck's circuit if macrst =0
1391 write_nic_dword(dev, PHY_ADR, 0x0100c880);
1392 write_nic_dword(dev, PHY_ADR, 0x01001c86);
1393 write_nic_dword(dev, PHY_ADR, 0x01007890);
1394 write_nic_dword(dev, PHY_ADR, 0x0100d0ae);
1395 write_nic_dword(dev, PHY_ADR, 0x010006af);
1396 write_nic_dword(dev, PHY_ADR, 0x01004681);
1398 write_phy_cck(dev,0x00,0xc8);
1399 write_phy_cck(dev,0x06,0x1c);
1400 write_phy_cck(dev,0x10,0x78);
1401 write_phy_cck(dev,0x2e,0xd0);
1402 write_phy_cck(dev,0x2f,0x06);
1403 write_phy_cck(dev,0x01,0x46);
1406 write_nic_byte(dev, CCK_TXAGC, 0x10);
1407 write_nic_byte(dev, OFDM_TXAGC, 0x1B);
1408 write_nic_byte(dev, ANTSEL, 0x03);
1412 //=============================================================================
1414 //=============================================================================
1416 // PlatformIOWrite4Byte( dev, PhyAddr, 0x00001280); // Annie, 2006-05-05
1417 write_phy_ofdm(dev, 0x00, 0x12);
1418 //WriteBBPortUchar(dev, 0x00001280);
1420 for (i=0; i<128; i++)
1422 //DbgPrint("AGC - [%x+1] = 0x%x\n", i, ZEBRA_AGC[i+1]);
1424 data = ZEBRA_AGC[i+1];
1426 data = data | 0x0000008F;
1428 addr = i + 0x80; //enable writing AGC table
1430 addr = addr | 0x0000008E;
1432 WriteBBPortUchar(dev, data);
1433 WriteBBPortUchar(dev, addr);
1434 WriteBBPortUchar(dev, 0x0000008E);
1437 PlatformIOWrite4Byte( dev, PhyAddr, 0x00001080); // Annie, 2006-05-05
1438 //WriteBBPortUchar(dev, 0x00001080);
1440 //=============================================================================
1442 //=============================================================================
1444 //=============================================================================
1449 u4bRegValue=OFDM_CONFIG[i];
1451 //DbgPrint("OFDM - 0x%x = 0x%x\n", u4bRegOffset, u4bRegValue);
1453 WriteBBPortUchar(dev,
1455 (u4bRegOffset & 0x7f) |
1456 ((u4bRegValue & 0xff) << 8)));
1459 //=============================================================================
1460 //by amy for antenna
1461 //=============================================================================
1463 // Config Sw/Hw Combinational Antenna Diversity. Added by Roger, 2008.02.26.
1464 SetAntennaConfig87SE(dev, priv->bDefaultAntenna1, priv->bSwAntennaDiverity);
1467 // Config Sw/Hw Antenna Diversity
1468 if( priv->bSwAntennaDiverity ) // Use SW+Hw Antenna Diversity
1470 if( priv->bDefaultAntenna1 == true ) // aux antenna
1472 // Mac register, aux antenna
1473 write_nic_byte(dev, ANTSEL, 0x00);
1474 // Config CCK RX antenna.
1475 write_phy_cck(dev, 0x11, 0xbb); // Reg11 : bb
1476 write_phy_cck(dev, 0x0c, 0x09); // Reg0c : 09
1477 write_phy_cck(dev, 0x01, 0xc7); // Reg01 : c7
1478 // Config OFDM RX antenna.
1479 write_phy_ofdm(dev, 0x0d, 0x54); // Reg0d : 54
1480 write_phy_ofdm(dev, 0x18, 0xb2); // Reg18 : b2
1482 else // main antenna
1484 // Mac register, main antenna
1485 write_nic_byte(dev, ANTSEL, 0x03);
1487 // Config CCK RX antenna.
1488 write_phy_cck(dev, 0x11, 0x9b); // Reg11 : 9b
1489 write_phy_cck(dev, 0x0c, 0x09); // Reg0c : 09
1490 write_phy_cck(dev, 0x01, 0xc7); // Reg01 : c7
1491 // Config OFDM RX antenna.
1492 write_phy_ofdm(dev, 0x0d, 0x5c); // Reg0d : 5c
1493 write_phy_ofdm(dev, 0x18, 0xb2); // Reg18 : b2
1496 else // Disable Antenna Diversity
1498 if( priv->bDefaultAntenna1 == true ) // aux Antenna
1500 // Mac register, aux antenna
1501 write_nic_byte(dev, ANTSEL, 0x00);
1502 // Config CCK RX antenna.
1503 write_phy_cck(dev, 0x11, 0xbb); // Reg11 : bb
1504 write_phy_cck(dev, 0x0c, 0x09); // Reg0c : 09
1505 write_phy_cck(dev, 0x01, 0x47); // Reg01 : 47
1506 // Config OFDM RX antenna.
1507 write_phy_ofdm(dev, 0x0d, 0x54); // Reg0d : 54
1508 write_phy_ofdm(dev, 0x18, 0x32); // Reg18 : 32
1510 else // main Antenna
1512 // Mac register, main antenna
1513 write_nic_byte(dev, ANTSEL, 0x03);
1514 // Config CCK RX antenna.
1515 write_phy_cck(dev, 0x11, 0x9b); // Reg11 : 9b
1516 write_phy_cck(dev, 0x0c, 0x09); // Reg0c : 09
1517 write_phy_cck(dev, 0x01, 0x47); // Reg01 : 47
1518 // Config OFDM RX antenna.
1519 write_phy_ofdm(dev, 0x0d, 0x5c); // Reg0d : 5c
1520 write_phy_ofdm(dev, 0x18, 0x32); // Reg18 : 32
1524 //by amy for antenna
1530 struct net_device *dev
1533 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1534 //unsigned char* IGTable;
1535 //u8 DIG_CurrentInitialGain = 4;
1536 //unsigned char u1Tmp;
1539 if(priv->eRFPowerState != eRfOn)
1541 //Don't access BB/RF under disable PLL situation.
1542 //RT_TRACE(COMP_DIG, DBG_LOUD, ("UpdateInitialGain - pHalData->eRFPowerState!=eRfOn\n"));
1543 // Back to the original state
1544 priv->InitialGain= priv->InitialGainBackUp;
1548 switch(priv->rf_chip)
1552 // Dynamic set initial gain, by shien chang, 2006.07.14
1553 switch(priv->InitialGain)
1556 DMESG("RTL8185B + 8225 Initial Gain State 1: -82 dBm \n");
1557 write_nic_dword(dev, PhyAddr, 0x2697); mdelay(1);
1558 write_nic_dword(dev, PhyAddr, 0x86a4); mdelay(1);
1559 write_nic_dword(dev, PhyAddr, 0xfa85); mdelay(1);
1563 DMESG("RTL8185B + 8225 Initial Gain State 2: -82 dBm \n");
1564 write_nic_dword(dev, PhyAddr, 0x2697); mdelay(1);
1565 write_nic_dword(dev, PhyAddr, 0x86a4); mdelay(1);
1566 write_nic_dword(dev, PhyAddr, 0xfb85); mdelay(1);
1570 DMESG("RTL8185B + 8225 Initial Gain State 3: -82 dBm \n");
1571 write_nic_dword(dev, PhyAddr, 0x2697); mdelay(1);
1572 write_nic_dword(dev, PhyAddr, 0x96a4); mdelay(1);
1573 write_nic_dword(dev, PhyAddr, 0xfb85); mdelay(1);
1577 DMESG("RTL8185B + 8225 Initial Gain State 4: -78 dBm \n");
1578 write_nic_dword(dev, PhyAddr, 0x2697); mdelay(1);
1579 write_nic_dword(dev, PhyAddr, 0xa6a4); mdelay(1);
1580 write_nic_dword(dev, PhyAddr, 0xfb85); mdelay(1);
1584 DMESG("RTL8185B + 8225 Initial Gain State 5: -74 dBm \n");
1585 write_nic_dword(dev, PhyAddr, 0x3697); mdelay(1);
1586 write_nic_dword(dev, PhyAddr, 0xa6a4); mdelay(1);
1587 write_nic_dword(dev, PhyAddr, 0xfb85); mdelay(1);
1591 DMESG("RTL8185B + 8225 Initial Gain State 6: -70 dBm \n");
1592 write_nic_dword(dev, PhyAddr, 0x4697); mdelay(1);
1593 write_nic_dword(dev, PhyAddr, 0xa6a4); mdelay(1);
1594 write_nic_dword(dev, PhyAddr, 0xfb85); mdelay(1);
1598 DMESG("RTL8185B + 8225 Initial Gain State 7: -66 dBm \n");
1599 write_nic_dword(dev, PhyAddr, 0x5697); mdelay(1);
1600 write_nic_dword(dev, PhyAddr, 0xa6a4); mdelay(1);
1601 write_nic_dword(dev, PhyAddr, 0xfb85); mdelay(1);
1605 DMESG("RTL8185B + 8225 Initial Gain State 1: -82 dBm (default)\n");
1606 write_nic_dword(dev, PhyAddr, 0x2697); mdelay(1);
1607 write_nic_dword(dev, PhyAddr, 0x86a4); mdelay(1);
1608 write_nic_dword(dev, PhyAddr, 0xfa85); mdelay(1);
1614 // Dynamic set initial gain, follow 87B
1615 switch(priv->InitialGain)
1618 //DMESG("RTL8187 + 8225 Initial Gain State 1: -82 dBm \n");
1619 write_phy_ofdm(dev, 0x17, 0x26); mdelay(1);
1620 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
1621 write_phy_ofdm(dev, 0x05, 0xfa); mdelay(1);
1625 //DMESG("RTL8187 + 8225 Initial Gain State 2: -82 dBm \n");
1626 write_phy_ofdm(dev, 0x17, 0x36); mdelay(1);
1627 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
1628 write_phy_ofdm(dev, 0x05, 0xfa); mdelay(1);
1632 //DMESG("RTL8187 + 8225 Initial Gain State 3: -82 dBm \n");
1633 write_phy_ofdm(dev, 0x17, 0x36); mdelay(1);
1634 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
1635 write_phy_ofdm(dev, 0x05, 0xfb); mdelay(1);
1639 //DMESG("RTL8187 + 8225 Initial Gain State 4: -78 dBm \n");
1640 write_phy_ofdm(dev, 0x17, 0x46); mdelay(1);
1641 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
1642 write_phy_ofdm(dev, 0x05, 0xfb); mdelay(1);
1646 //DMESG("RTL8187 + 8225 Initial Gain State 5: -74 dBm \n");
1647 write_phy_ofdm(dev, 0x17, 0x46); mdelay(1);
1648 write_phy_ofdm(dev, 0x24, 0x96); mdelay(1);
1649 write_phy_ofdm(dev, 0x05, 0xfb); mdelay(1);
1653 //DMESG ("RTL8187 + 8225 Initial Gain State 6: -70 dBm \n");
1654 write_phy_ofdm(dev, 0x17, 0x56); mdelay(1);
1655 write_phy_ofdm(dev, 0x24, 0x96); mdelay(1);
1656 write_phy_ofdm(dev, 0x05, 0xfc); mdelay(1);
1660 //DMESG("RTL8187 + 8225 Initial Gain State 7: -66 dBm \n");
1661 write_phy_ofdm(dev, 0x17, 0x56); mdelay(1);
1662 write_phy_ofdm(dev, 0x24, 0xa6); mdelay(1);
1663 write_phy_ofdm(dev, 0x05, 0xfc); mdelay(1);
1667 //DMESG("RTL8187 + 8225 Initial Gain State 8:\n");
1668 write_phy_ofdm(dev, 0x17, 0x66); mdelay(1);
1669 write_phy_ofdm(dev, 0x24, 0xb6); mdelay(1);
1670 write_phy_ofdm(dev, 0x05, 0xfc); mdelay(1);
1675 //DMESG("RTL8187 + 8225 Initial Gain State 1: -82 dBm (default)\n");
1676 write_phy_ofdm(dev, 0x17, 0x26); mdelay(1);
1677 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
1678 write_phy_ofdm(dev, 0x05, 0xfa); mdelay(1);
1685 DMESG("UpdateInitialGain(): unknown RFChipID: %#X\n", priv->rf_chip);
1691 // Tx Power tracking mechanism routine on 87SE.
1692 // Created by Roger, 2007.12.11.
1695 InitTxPwrTracking87SE(
1696 struct net_device *dev
1699 //struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1702 u4bRfReg = RF_ReadReg(dev, 0x02);
1704 // Enable Thermal meter indication.
1705 //printk("InitTxPwrTracking87SE(): Enable thermal meter indication, Write RF[0x02] = %#x", u4bRfReg|PWR_METER_EN);
1706 RF_WriteReg(dev, 0x02, u4bRfReg|PWR_METER_EN); mdelay(1);
1711 struct net_device *dev
1714 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1715 write_nic_dword(dev, RCR, priv->ReceiveConfig);
1716 priv->RFProgType = read_nic_byte(dev, CONFIG4) & 0x03;
1718 switch(priv->rf_chip)
1722 ZEBRA_Config_85BASIC_HardCode( dev);
1726 // Set default initial gain state to 4, approved by SD3 DZ, by Bruce, 2007-06-06.
1727 if(priv->bDigMechanism)
1729 if(priv->InitialGain == 0)
1730 priv->InitialGain = 4;
1731 //printk("PhyConfig8185(): DIG is enabled, set default initial gain index to %d\n", priv->InitialGain);
1735 // Enable thermal meter indication to implement TxPower tracking on 87SE.
1736 // We initialize thermal meter here to avoid unsuccessful configuration.
1737 // Added by Roger, 2007.12.11.
1739 if(priv->bTxPowerTrack)
1740 InitTxPwrTracking87SE(dev);
1743 priv->InitialGainBackUp= priv->InitialGain;
1744 UpdateInitialGain(dev);
1754 struct net_device *dev
1757 //RTL8185_TODO: Determine Retrylimit, TxAGC, AutoRateFallback control.
1758 // u8 bUNIVERSAL_CONTROL_RL = 1;
1759 u8 bUNIVERSAL_CONTROL_RL = 0;
1761 u8 bUNIVERSAL_CONTROL_AGC = 1;
1762 u8 bUNIVERSAL_CONTROL_ANT = 1;
1763 u8 bAUTO_RATE_FALLBACK_CTL = 1;
1765 //struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1766 //struct ieee80211_device *ieee = priv->ieee80211;
1767 //if(IS_WIRELESS_MODE_A(dev) || IS_WIRELESS_MODE_G(dev))
1768 //{by amy 080312 if((ieee->mode == IEEE_G)||(ieee->mode == IEEE_A))
1770 // write_nic_word(dev, BRSR, 0xffff);
1774 // write_nic_word(dev, BRSR, 0x000f);
1777 write_nic_word(dev, BRSR, 0x0fff);
1779 val8 = read_nic_byte(dev, CW_CONF);
1781 if(bUNIVERSAL_CONTROL_RL)
1786 write_nic_byte(dev, CW_CONF, val8);
1789 val8 = read_nic_byte(dev, TXAGC_CTL);
1790 if(bUNIVERSAL_CONTROL_AGC)
1792 write_nic_byte(dev, CCK_TXAGC, 128);
1793 write_nic_byte(dev, OFDM_TXAGC, 128);
1798 val8 = val8 | 0x01 ;
1802 write_nic_byte(dev, TXAGC_CTL, val8);
1804 // Tx Antenna including Feedback control
1805 val8 = read_nic_byte(dev, TXAGC_CTL );
1807 if(bUNIVERSAL_CONTROL_ANT)
1809 write_nic_byte(dev, ANTSEL, 0x00);
1814 val8 = val8 & (val8|0x02); //xiong-2006-11-15
1817 write_nic_byte(dev, TXAGC_CTL, val8);
1819 // Auto Rate fallback control
1820 val8 = read_nic_byte(dev, RATE_FALLBACK);
1822 if( bAUTO_RATE_FALLBACK_CTL )
1824 val8 |= RATE_FALLBACK_CTL_ENABLE | RATE_FALLBACK_CTL_AUTO_STEP1;
1826 // <RJ_TODO_8185B> We shall set up the ARFR according to user's setting.
1827 //write_nic_word(dev, ARFR, 0x0fff); // set 1M ~ 54M
1830 PlatformIOWrite2Byte(dev, ARFR, 0x0fff); // set 1M ~ 54M
1832 // Aadded by Roger, 2007.11.15.
1833 PlatformIOWrite2Byte(dev, ARFR, 0x0fff); //set 1M ~ 54Mbps.
1839 write_nic_byte(dev, RATE_FALLBACK, val8);
1845 MacConfig_85BASIC_HardCode(
1846 struct net_device *dev)
1848 //============================================================================
1850 //============================================================================
1853 u32 u4bRegOffset, u4bRegValue,u4bPageIndex = 0;
1856 nLinesRead=sizeof(MAC_REG_TABLE)/2;
1858 for(i = 0; i < nLinesRead; i++) //nLinesRead=101
1860 u4bRegOffset=MAC_REG_TABLE[i][0];
1861 u4bRegValue=MAC_REG_TABLE[i][1];
1863 if(u4bRegOffset == 0x5e)
1865 u4bPageIndex = u4bRegValue;
1869 u4bRegOffset |= (u4bPageIndex << 8);
1871 //DbgPrint("MAC - 0x%x = 0x%x\n", u4bRegOffset, u4bRegValue);
1872 write_nic_byte(dev, u4bRegOffset, (u8)u4bRegValue);
1874 //============================================================================
1881 struct net_device *dev)
1885 MacConfig_85BASIC_HardCode(dev);
1887 //============================================================================
1889 // Follow TID_AC_MAP of WMac.
1890 write_nic_word(dev, TID_AC_MAP, 0xfa50);
1892 // Interrupt Migration, Jong suggested we use set 0x0000 first, 2005.12.14, by rcnjko.
1893 write_nic_word(dev, IntMig, 0x0000);
1895 // Prevent TPC to cause CRC error. Added by Annie, 2006-06-10.
1896 PlatformIOWrite4Byte(dev, 0x1F0, 0x00000000);
1897 PlatformIOWrite4Byte(dev, 0x1F4, 0x00000000);
1898 PlatformIOWrite1Byte(dev, 0x1F8, 0x00);
1900 // Asked for by SD3 CM Lin, 2006.06.27, by rcnjko.
1901 //PlatformIOWrite4Byte(dev, RFTiming, 0x00004001);
1904 write_nic_dword(dev, RFTiming, 0x00004001);
1906 // power save parameter based on "87SE power save parameters 20071127.doc", as follow.
1908 //Enable DA10 TX power saving
1909 u1DA = read_nic_byte(dev, PHYPR);
1910 write_nic_byte(dev, PHYPR, (u1DA | BIT2) );
1913 write_nic_word(dev, 0x360, 0x1000);
1914 write_nic_word(dev, 0x362, 0x1000);
1917 write_nic_word(dev, 0x370, 0x0560);
1918 write_nic_word(dev, 0x372, 0x0560);
1919 write_nic_word(dev, 0x374, 0x0DA4);
1920 write_nic_word(dev, 0x376, 0x0DA4);
1921 write_nic_word(dev, 0x378, 0x0560);
1922 write_nic_word(dev, 0x37A, 0x0560);
1923 write_nic_word(dev, 0x37C, 0x00EC);
1924 // write_nic_word(dev, 0x37E, 0x00FE);//-edward
1925 write_nic_word(dev, 0x37E, 0x00EC);//+edward
1926 write_nic_byte(dev, 0x24E,0x01);
1935 GetSupportedWirelessMode8185(
1936 struct net_device *dev
1939 u8 btSupportedWirelessMode = 0;
1940 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1942 switch(priv->rf_chip)
1946 btSupportedWirelessMode = (WIRELESS_MODE_B | WIRELESS_MODE_G);
1949 btSupportedWirelessMode = WIRELESS_MODE_B;
1953 return btSupportedWirelessMode;
1957 ActUpdateChannelAccessSetting(
1958 struct net_device *dev,
1959 WIRELESS_MODE WirelessMode,
1960 PCHANNEL_ACCESS_SETTING ChnlAccessSetting
1963 struct r8180_priv *priv = ieee80211_priv(dev);
1964 struct ieee80211_device *ieee = priv->ieee80211;
1967 //PSTA_QOS pStaQos = Adapter->MgntInfo.pStaQos;
1968 u8 bFollowLegacySetting = 0;
1973 // TODO: We still don't know how to set up these registers, just follow WMAC to
1974 // verify 8185B FPAG.
1977 // Jong said CWmin/CWmax register are not functional in 8185B,
1978 // so we shall fill channel access realted register into AC parameter registers,
1981 ChnlAccessSetting->SIFS_Timer = 0x22; // Suggested by Jong, 2005.12.08.
1982 ChnlAccessSetting->DIFS_Timer = 0x1C; // 2006.06.02, by rcnjko.
1983 ChnlAccessSetting->SlotTimeTimer = 9; // 2006.06.02, by rcnjko.
1984 ChnlAccessSetting->EIFS_Timer = 0x5B; // Suggested by wcchu, it is the default value of EIFS register, 2005.12.08.
1985 ChnlAccessSetting->CWminIndex = 3; // 2006.06.02, by rcnjko.
1986 ChnlAccessSetting->CWmaxIndex = 7; // 2006.06.02, by rcnjko.
1988 write_nic_byte(dev, SIFS, ChnlAccessSetting->SIFS_Timer);
1989 //Adapter->HalFunc.SetHwRegHandler( Adapter, HW_VAR_SLOT_TIME, &ChnlAccessSetting->SlotTimeTimer ); // Rewrited from directly use PlatformEFIOWrite1Byte(), by Annie, 2006-03-29.
1990 write_nic_byte(dev, SLOT, ChnlAccessSetting->SlotTimeTimer); // Rewrited from directly use PlatformEFIOWrite1Byte(), by Annie, 2006-03-29.
1992 u1bAIFS = aSifsTime + (2 * ChnlAccessSetting->SlotTimeTimer );
1994 //write_nic_byte(dev, AC_VO_PARAM, u1bAIFS);
1995 //write_nic_byte(dev, AC_VI_PARAM, u1bAIFS);
1996 //write_nic_byte(dev, AC_BE_PARAM, u1bAIFS);
1997 //write_nic_byte(dev, AC_BK_PARAM, u1bAIFS);
1999 write_nic_byte(dev, EIFS, ChnlAccessSetting->EIFS_Timer);
2001 write_nic_byte(dev, AckTimeOutReg, 0x5B); // <RJ_EXPR_QOS> Suggested by wcchu, it is the default value of EIFS register, 2005.12.08.
2004 // <RJ_TODO_NOW_8185B> Update ECWmin/ECWmax, AIFS, TXOP Limit of each AC to the value defined by SPEC.
2005 if( pStaQos->CurrentQosMode > QOS_DISABLE )
2007 if(pStaQos->QBssWirelessMode == WirelessMode)
2009 // Follow AC Parameters of the QBSS.
2010 for(eACI = 0; eACI < AC_MAX; eACI++)
2012 Adapter->HalFunc.SetHwRegHandler(Adapter, HW_VAR_AC_PARAM, (pu1Byte)(&(pStaQos->WMMParamEle.AcParam[eACI])) );
2017 // Follow Default WMM AC Parameters.
2018 bFollowLegacySetting = 1;
2024 bFollowLegacySetting = 1;
2028 // this setting is copied from rtl8187B. xiong-2006-11-13
2029 if(bFollowLegacySetting)
2034 // Follow 802.11 seeting to AC parameter, all AC shall use the same parameter.
2035 // 2005.12.01, by rcnjko.
2037 AcParam.longData = 0;
2038 AcParam.f.AciAifsn.f.AIFSN = 2; // Follow 802.11 DIFS.
2039 AcParam.f.AciAifsn.f.ACM = 0;
2040 AcParam.f.Ecw.f.ECWmin = ChnlAccessSetting->CWminIndex; // Follow 802.11 CWmin.
2041 AcParam.f.Ecw.f.ECWmax = ChnlAccessSetting->CWmaxIndex; // Follow 802.11 CWmax.
2042 AcParam.f.TXOPLimit = 0;
2044 //lzm reserved 080826
2046 // For turbo mode setting. port from 87B by Isaiah 2008-08-01
2047 if( ieee->current_network.Turbo_Enable == 1 )
2048 AcParam.f.TXOPLimit = 0x01FF;
2049 // For 87SE with Intel 4965 Ad-Hoc mode have poor throughput (19MB)
2050 if (ieee->iw_mode == IW_MODE_ADHOC)
2051 AcParam.f.TXOPLimit = 0x0020;
2054 for(eACI = 0; eACI < AC_MAX; eACI++)
2056 AcParam.f.AciAifsn.f.ACI = (u8)eACI;
2058 PAC_PARAM pAcParam = (PAC_PARAM)(&AcParam);
2063 // Retrive paramters to udpate.
2064 eACI = pAcParam->f.AciAifsn.f.ACI;
2065 u1bAIFS = pAcParam->f.AciAifsn.f.AIFSN * ChnlAccessSetting->SlotTimeTimer + aSifsTime;
2066 u4bAcParam = ( (((u32)(pAcParam->f.TXOPLimit)) << AC_PARAM_TXOP_LIMIT_OFFSET) |
2067 (((u32)(pAcParam->f.Ecw.f.ECWmax)) << AC_PARAM_ECW_MAX_OFFSET) |
2068 (((u32)(pAcParam->f.Ecw.f.ECWmin)) << AC_PARAM_ECW_MIN_OFFSET) |
2069 (((u32)u1bAIFS) << AC_PARAM_AIFS_OFFSET));
2074 //write_nic_dword(dev, AC_BK_PARAM, u4bAcParam);
2078 //write_nic_dword(dev, AC_BE_PARAM, u4bAcParam);
2082 //write_nic_dword(dev, AC_VI_PARAM, u4bAcParam);
2086 //write_nic_dword(dev, AC_VO_PARAM, u4bAcParam);
2090 DMESGW( "SetHwReg8185(): invalid ACI: %d !\n", eACI);
2095 // If it is set, immediately set ACM control bit to downgrading AC for passing WMM testplan. Annie, 2005-12-13.
2096 //write_nic_byte(dev, ACM_CONTROL, pAcParam->f.AciAifsn);
2098 PACI_AIFSN pAciAifsn = (PACI_AIFSN)(&pAcParam->f.AciAifsn);
2099 AC_CODING eACI = pAciAifsn->f.ACI;
2102 //for 8187B AsynIORead issue
2104 u8 AcmCtrl = pHalData->AcmControl;
2108 if( pAciAifsn->f.ACM )
2113 AcmCtrl |= (BEQ_ACM_EN|BEQ_ACM_CTL|ACM_HW_EN); // or 0x21
2117 AcmCtrl |= (VIQ_ACM_EN|VIQ_ACM_CTL|ACM_HW_EN); // or 0x42
2121 AcmCtrl |= (VOQ_ACM_EN|VOQ_ACM_CTL|ACM_HW_EN); // or 0x84
2125 DMESGW("SetHwReg8185(): [HW_VAR_ACM_CTRL] ACM set failed: eACI is %d\n", eACI );
2134 AcmCtrl &= ( (~BEQ_ACM_EN) & (~BEQ_ACM_CTL) & (~ACM_HW_EN) ); // and 0xDE
2138 AcmCtrl &= ( (~VIQ_ACM_EN) & (~VIQ_ACM_CTL) & (~ACM_HW_EN) ); // and 0xBD
2142 AcmCtrl &= ( (~VOQ_ACM_EN) & (~VOQ_ACM_CTL) & (~ACM_HW_EN) ); // and 0x7B
2150 //printk(KERN_WARNING "SetHwReg8185(): [HW_VAR_ACM_CTRL] Write 0x%X\n", AcmCtrl);
2153 pHalData->AcmControl = AcmCtrl;
2155 //write_nic_byte(dev, ACM_CONTROL, AcmCtrl);
2156 write_nic_byte(dev, ACM_CONTROL, 0);
2166 ActSetWirelessMode8185(
2167 struct net_device *dev,
2171 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2172 struct ieee80211_device *ieee = priv->ieee80211;
2173 //PMGNT_INFO pMgntInfo = &(Adapter->MgntInfo);
2174 u8 btSupportedWirelessMode = GetSupportedWirelessMode8185(dev);
2176 if( (btWirelessMode & btSupportedWirelessMode) == 0 )
2177 { // Don't switch to unsupported wireless mode, 2006.02.15, by rcnjko.
2178 DMESGW("ActSetWirelessMode8185(): WirelessMode(%d) is not supported (%d)!\n",
2179 btWirelessMode, btSupportedWirelessMode);
2183 // 1. Assign wireless mode to swtich if necessary.
2184 if (btWirelessMode == WIRELESS_MODE_AUTO)
2186 if((btSupportedWirelessMode & WIRELESS_MODE_A))
2188 btWirelessMode = WIRELESS_MODE_A;
2190 else if((btSupportedWirelessMode & WIRELESS_MODE_G))
2192 btWirelessMode = WIRELESS_MODE_G;
2194 else if((btSupportedWirelessMode & WIRELESS_MODE_B))
2196 btWirelessMode = WIRELESS_MODE_B;
2200 DMESGW("ActSetWirelessMode8185(): No valid wireless mode supported, btSupportedWirelessMode(%x)!!!\n",
2201 btSupportedWirelessMode);
2202 btWirelessMode = WIRELESS_MODE_B;
2207 // 2. Swtich band: RF or BB specific actions,
2208 // for example, refresh tables in omc8255, or change initial gain if necessary.
2209 switch(priv->rf_chip)
2214 // Nothing to do for Zebra to switch band.
2215 // Update current wireless mode if we swtich to specified band successfully.
2216 ieee->mode = (WIRELESS_MODE)btWirelessMode;
2221 DMESGW("ActSetWirelessMode8185(): unsupported RF: 0x%X !!!\n", priv->rf_chip);
2225 // 3. Change related setting.
2226 if( ieee->mode == WIRELESS_MODE_A ){
2227 DMESG("WIRELESS_MODE_A\n");
2229 else if( ieee->mode == WIRELESS_MODE_B ){
2230 DMESG("WIRELESS_MODE_B\n");
2232 else if( ieee->mode == WIRELESS_MODE_G ){
2233 DMESG("WIRELESS_MODE_G\n");
2236 ActUpdateChannelAccessSetting( dev, ieee->mode, &priv->ChannelAccessSetting);
2239 void rtl8185b_irq_enable(struct net_device *dev)
2241 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2243 priv->irq_enabled = 1;
2244 write_nic_dword(dev, IMR, priv->IntrMask);
2246 //by amy for power save
2248 DrvIFIndicateDisassociation(
2249 struct net_device *dev,
2253 //printk("==> DrvIFIndicateDisassociation()\n");
2255 // nothing is needed after disassociation request.
2257 //printk("<== DrvIFIndicateDisassociation()\n");
2261 struct net_device *dev
2264 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2267 //printk("XXXXXXXXXX MgntDisconnect IBSS\n");
2269 DrvIFIndicateDisassociation(dev, unspec_reason);
2271 // PlatformZeroMemory( pMgntInfo->Bssid, 6 );
2272 for(i=0;i<6;i++) priv->ieee80211->current_network.bssid[i] = 0x55;
2274 priv->ieee80211->state = IEEE80211_NOLINK;
2278 // Vista add a Adhoc profile, HW radio off untill OID_DOT11_RESET_REQUEST
2279 // Driver would set MSR=NO_LINK, then HW Radio ON, MgntQueue Stuck.
2280 // Because Bcn DMA isn't complete, mgnt queue would stuck until Bcn packet send.
2282 // Disable Beacon Queue Own bit, suggested by jong
2283 // Adapter->HalFunc.SetTxDescOWNHandler(Adapter, BEACON_QUEUE, 0, 0);
2284 ieee80211_stop_send_beacons(priv->ieee80211);
2286 priv->ieee80211->link_change(dev);
2287 notify_wx_assoc_event(priv->ieee80211);
2289 // Stop SW Beacon.Use hw beacon so do not need to do so.by amy
2291 if(pMgntInfo->bEnableSwBeaconTimer)
2293 // SwBeaconTimer will stop if pMgntInfo->mIbss==FALSE, see SwBeaconCallback() for details.
2294 // comment out by haich, 2007.10.01
2295 //#if DEV_BUS_TYPE==USB_INTERFACE
2296 PlatformCancelTimer( Adapter, &pMgntInfo->SwBeaconTimer);
2301 // MgntIndicateMediaStatus( Adapter, RT_MEDIA_DISCONNECT, GENERAL_INDICATE );
2305 MlmeDisassociateRequest(
2306 struct net_device *dev,
2311 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2314 SendDisassociation(priv->ieee80211, asSta, asRsn );
2316 if( memcmp(priv->ieee80211->current_network.bssid, asSta, 6 ) == 0 ){
2317 //ShuChen TODO: change media status.
2318 //ShuChen TODO: What to do when disassociate.
2319 DrvIFIndicateDisassociation(dev, unspec_reason);
2322 // pMgntInfo->AsocTimestamp = 0;
2323 for(i=0;i<6;i++) priv->ieee80211->current_network.bssid[i] = 0x22;
2324 // pMgntInfo->mBrates.Length = 0;
2325 // Adapter->HalFunc.SetHwRegHandler( Adapter, HW_VAR_BASIC_RATE, (pu1Byte)(&pMgntInfo->mBrates) );
2327 ieee80211_disassociate(priv->ieee80211);
2336 struct net_device *dev,
2340 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2343 // Commented out by rcnjko, 2005.01.27:
2344 // I move SecClearAllKeys() to MgntActSet_802_11_DISASSOCIATE().
2346 // //2004/09/15, kcwu, the key should be cleared, or the new handshaking will not success
2347 // SecClearAllKeys(Adapter);
2349 // In WPA WPA2 need to Clear all key ... because new key will set after new handshaking.
2351 if( pMgntInfo->SecurityInfo.AuthMode > RT_802_11AuthModeAutoSwitch ||
2352 (pMgntInfo->bAPSuportCCKM && pMgntInfo->bCCX8021xenable) ) // In CCKM mode will Clear key
2354 SecClearAllKeys(Adapter);
2355 RT_TRACE(COMP_SEC, DBG_LOUD,("======>CCKM clear key..."))
2358 // 2004.10.11, by rcnjko.
2359 //MlmeDisassociateRequest( Adapter, pMgntInfo->Bssid, disas_lv_ss );
2360 MlmeDisassociateRequest( dev, priv->ieee80211->current_network.bssid, asRsn );
2362 priv->ieee80211->state = IEEE80211_NOLINK;
2363 // pMgntInfo->AsocTimestamp = 0;
2367 struct net_device *dev,
2371 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2373 // Schedule an workitem to wake up for ps mode, 070109, by rcnjko.
2376 if(pMgntInfo->mPss != eAwake)
2379 // Using AwkaeTimer to prevent mismatch ps state.
2380 // In the timer the state will be changed according to the RF is being awoke or not. By Bruce, 2007-10-31.
2382 // PlatformScheduleWorkItem( &(pMgntInfo->AwakeWorkItem) );
2383 PlatformSetTimer( Adapter, &(pMgntInfo->AwakeTimer), 0 );
2387 // Indication of disassociation event.
2388 //DrvIFIndicateDisassociation(Adapter, asRsn);
2389 if(IS_DOT11D_ENABLE(priv->ieee80211))
2390 Dot11d_Reset(priv->ieee80211);
2391 // In adhoc mode, update beacon frame.
2392 if( priv->ieee80211->state == IEEE80211_LINKED )
2394 if( priv->ieee80211->iw_mode == IW_MODE_ADHOC )
2396 // RT_TRACE(COMP_MLME, DBG_LOUD, ("MgntDisconnect() ===> MgntDisconnectIBSS\n"));
2397 //printk("MgntDisconnect() ===> MgntDisconnectIBSS\n");
2398 MgntDisconnectIBSS(dev);
2400 if( priv->ieee80211->iw_mode == IW_MODE_INFRA )
2402 // We clear key here instead of MgntDisconnectAP() because that
2403 // MgntActSet_802_11_DISASSOCIATE() is an interface called by OS,
2404 // e.g. OID_802_11_DISASSOCIATE in Windows while as MgntDisconnectAP() is
2405 // used to handle disassociation related things to AP, e.g. send Disassoc
2406 // frame to AP. 2005.01.27, by rcnjko.
2407 // SecClearAllKeys(Adapter);
2409 // RT_TRACE(COMP_MLME, DBG_LOUD, ("MgntDisconnect() ===> MgntDisconnectAP\n"));
2410 //printk("MgntDisconnect() ===> MgntDisconnectAP\n");
2411 MgntDisconnectAP(dev, asRsn);
2414 // Inidicate Disconnect, 2005.02.23, by rcnjko.
2415 // MgntIndicateMediaStatus( Adapter, RT_MEDIA_DISCONNECT, GENERAL_INDICATE);
2422 // Chang RF Power State.
2423 // Note that, only MgntActSet_RF_State() is allowed to set HW_VAR_RF_STATE.
2430 struct net_device *dev,
2431 RT_RF_POWER_STATE eRFPowerState
2434 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2435 bool bResult = false;
2437 // printk("---------> SetRFPowerState(): eRFPowerState(%d)\n", eRFPowerState);
2438 if(eRFPowerState == priv->eRFPowerState)
2440 // printk("<--------- SetRFPowerState(): discard the request for eRFPowerState(%d) is the same.\n", eRFPowerState);
2444 switch(priv->rf_chip)
2448 bResult = SetZebraRFPowerState8185(dev, eRFPowerState);
2452 printk("SetRFPowerState8185(): unknown RFChipID: 0x%X!!!\n", priv->rf_chip);
2455 // printk("<--------- SetRFPowerState(): bResult(%d)\n", bResult);
2460 HalEnableRx8185Dummy(
2461 struct net_device *dev
2466 HalDisableRx8185Dummy(
2467 struct net_device *dev
2473 MgntActSet_RF_State(
2474 struct net_device *dev,
2475 RT_RF_POWER_STATE StateToSet,
2479 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2480 bool bActionAllowed = false;
2481 bool bConnectBySSID = false;
2482 RT_RF_POWER_STATE rtState;
2483 u16 RFWaitCounter = 0;
2485 // printk("===>MgntActSet_RF_State(): StateToSet(%d), ChangeSource(0x%x)\n",StateToSet, ChangeSource);
2487 // Prevent the race condition of RF state change. By Bruce, 2007-11-28.
2488 // Only one thread can change the RF state at one time, and others should wait to be executed.
2493 // down(&priv->rf_state);
2494 spin_lock_irqsave(&priv->rf_ps_lock,flag);
2495 if(priv->RFChangeInProgress)
2497 // printk("====================>haha111111111\n");
2498 // up(&priv->rf_state);
2499 // RT_TRACE(COMP_RF, DBG_LOUD, ("MgntActSet_RF_State(): RF Change in progress! Wait to set..StateToSet(%d).\n", StateToSet));
2500 spin_unlock_irqrestore(&priv->rf_ps_lock,flag);
2501 // Set RF after the previous action is done.
2502 while(priv->RFChangeInProgress)
2505 // RT_TRACE(COMP_RF, DBG_LOUD, ("MgntActSet_RF_State(): Wait 1 ms (%d times)...\n", RFWaitCounter));
2506 udelay(1000); // 1 ms
2508 // Wait too long, return FALSE to avoid to be stuck here.
2509 if(RFWaitCounter > 1000) // 1sec
2511 // RT_ASSERT(FALSE, ("MgntActSet_RF_State(): Wait too logn to set RF\n"));
2512 printk("MgntActSet_RF_State(): Wait too long to set RF\n");
2513 // TODO: Reset RF state?
2520 // printk("========================>haha2\n");
2521 priv->RFChangeInProgress = true;
2522 // up(&priv->rf_state);
2523 spin_unlock_irqrestore(&priv->rf_ps_lock,flag);
2528 rtState = priv->eRFPowerState;
2535 // Turn On RF no matter the IPS setting because we need to update the RF state to Ndis under Vista, or
2536 // the Windows does not allow the driver to perform site survey any more. By Bruce, 2007-10-02.
2538 priv->RfOffReason &= (~ChangeSource);
2540 if(! priv->RfOffReason)
2542 priv->RfOffReason = 0;
2543 bActionAllowed = true;
2545 if(rtState == eRfOff && ChangeSource >=RF_CHANGE_BY_HW && !priv->bInHctTest)
2547 bConnectBySSID = true;
2551 // RT_TRACE(COMP_RF, DBG_LOUD, ("MgntActSet_RF_State - eRfon reject pMgntInfo->RfOffReason= 0x%x, ChangeSource=0x%X\n", pMgntInfo->RfOffReason, ChangeSource));
2556 // 070125, rcnjko: we always keep connected in AP mode.
2558 if (priv->RfOffReason > RF_CHANGE_BY_IPS)
2562 // Disconnect to current BSS when radio off. Asked by QuanTa.
2566 // Calling MgntDisconnect() instead of MgntActSet_802_11_DISASSOCIATE(),
2567 // because we do NOT need to set ssid to dummy ones.
2568 // Revised by Roger, 2007.12.04.
2570 MgntDisconnect( dev, disas_lv_ss );
2572 // Clear content of bssDesc[] and bssDesc4Query[] to avoid reporting old bss to UI.
2573 // 2007.05.28, by shien chang.
2574 // PlatformZeroMemory( pMgntInfo->bssDesc, sizeof(RT_WLAN_BSS)*MAX_BSS_DESC );
2575 // pMgntInfo->NumBssDesc = 0;
2576 // PlatformZeroMemory( pMgntInfo->bssDesc4Query, sizeof(RT_WLAN_BSS)*MAX_BSS_DESC );
2577 // pMgntInfo->NumBssDesc4Query = 0;
2582 priv->RfOffReason |= ChangeSource;
2583 bActionAllowed = true;
2587 priv->RfOffReason |= ChangeSource;
2588 bActionAllowed = true;
2597 // RT_TRACE(COMP_RF, DBG_LOUD, ("MgntActSet_RF_State(): Action is allowed.... StateToSet(%d), RfOffReason(%#X)\n", StateToSet, pMgntInfo->RfOffReason));
2598 // Config HW to the specified mode.
2599 // printk("MgntActSet_RF_State(): Action is allowed.... StateToSet(%d), RfOffReason(%#X)\n", StateToSet, priv->RfOffReason);
2600 SetRFPowerState(dev, StateToSet);
2603 if(StateToSet == eRfOn)
2605 HalEnableRx8185Dummy(dev);
2608 // by amy not supported
2609 // MgntActSet_802_11_SSID(Adapter, Adapter->MgntInfo.Ssid.Octet, Adapter->MgntInfo.Ssid.Length, TRUE );
2613 else if(StateToSet == eRfOff)
2615 HalDisableRx8185Dummy(dev);
2620 // printk("MgntActSet_RF_State(): Action is rejected.... StateToSet(%d), ChangeSource(%#X), RfOffReason(%#X)\n", StateToSet, ChangeSource, priv->RfOffReason);
2623 // Release RF spinlock
2624 // down(&priv->rf_state);
2625 spin_lock_irqsave(&priv->rf_ps_lock,flag);
2626 priv->RFChangeInProgress = false;
2627 // up(&priv->rf_state);
2628 spin_unlock_irqrestore(&priv->rf_ps_lock,flag);
2629 // printk("<===MgntActSet_RF_State()\n");
2630 return bActionAllowed;
2634 struct net_device *dev
2637 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2641 // This flag "bSwRfProcessing", indicates the status of IPS procedure, should be set if the IPS workitem
2642 // is really scheduled.
2643 // The old code, sets this flag before scheduling the IPS workitem and however, at the same time the
2644 // previous IPS workitem did not end yet, fails to schedule the current workitem. Thus, bSwRfProcessing
2645 // blocks the IPS procedure of switching RF.
2646 // By Bruce, 2007-12-25.
2648 priv->bSwRfProcessing = true;
2650 MgntActSet_RF_State(dev, priv->eInactivePowerState, RF_CHANGE_BY_IPS);
2653 // To solve CAM values miss in RF OFF, rewrite CAM values after RF ON. By Bruce, 2007-09-20.
2658 if( ( pMgntInfo->SecurityInfo.PairwiseEncAlgorithm == WEP104_Encryption ) ||
2659 (pMgntInfo->SecurityInfo.PairwiseEncAlgorithm == WEP40_Encryption) )
2661 if( pMgntInfo->SecurityInfo.KeyLen[index] != 0)
2662 pAdapter->HalFunc.SetKeyHandler(pAdapter, index, 0, FALSE, pMgntInfo->SecurityInfo.PairwiseEncAlgorithm, TRUE, FALSE);
2668 priv->bSwRfProcessing = false;
2673 // Enter the inactive power save mode. RF will be off
2674 // 2007.08.17, by shien chang.
2678 struct net_device *dev
2681 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2682 RT_RF_POWER_STATE rtState;
2683 //printk("==============================>enter IPS\n");
2684 if (priv->bInactivePs)
2686 rtState = priv->eRFPowerState;
2689 // Added by Bruce, 2007-12-25.
2690 // Do not enter IPS in the following conditions:
2691 // (1) RF is already OFF or Sleep
2692 // (2) bSwRfProcessing (indicates the IPS is still under going)
2693 // (3) Connectted (only disconnected can trigger IPS)
2694 // (4) IBSS (send Beacon)
2695 // (5) AP mode (send Beacon)
2697 if (rtState == eRfOn && !priv->bSwRfProcessing
2698 && (priv->ieee80211->state != IEEE80211_LINKED ))
2700 // printk("IPSEnter(): Turn off RF.\n");
2701 priv->eInactivePowerState = eRfOff;
2702 InactivePowerSave(dev);
2705 // printk("priv->eRFPowerState is %d\n",priv->eRFPowerState);
2709 struct net_device *dev
2712 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2713 RT_RF_POWER_STATE rtState;
2714 //printk("===================================>leave IPS\n");
2715 if (priv->bInactivePs)
2717 rtState = priv->eRFPowerState;
2718 if ((rtState == eRfOff || rtState == eRfSleep) && (!priv->bSwRfProcessing) && priv->RfOffReason <= RF_CHANGE_BY_IPS)
2720 // printk("IPSLeave(): Turn on RF.\n");
2721 priv->eInactivePowerState = eRfOn;
2722 InactivePowerSave(dev);
2725 // printk("priv->eRFPowerState is %d\n",priv->eRFPowerState);
2727 //by amy for power save
2728 void rtl8185b_adapter_start(struct net_device *dev)
2730 struct r8180_priv *priv = ieee80211_priv(dev);
2731 struct ieee80211_device *ieee = priv->ieee80211;
2733 u8 SupportedWirelessMode;
2734 u8 InitWirelessMode;
2735 u8 bInvalidWirelessMode = 0;
2743 //rtl8180_rtx_disable(dev);
2745 write_nic_byte(dev,0x24e, (BIT5|BIT6|BIT0));
2749 priv->dma_poll_mask = 0;
2750 priv->dma_poll_stop_mask = 0;
2752 //rtl8180_beacon_tx_disable(dev);
2754 HwConfigureRTL8185(dev);
2756 write_nic_dword(dev, MAC0, ((u32*)dev->dev_addr)[0]);
2757 write_nic_word(dev, MAC4, ((u32*)dev->dev_addr)[1] & 0xffff );
2759 write_nic_byte(dev, MSR, read_nic_byte(dev, MSR) & 0xf3); // default network type to 'No Link'
2761 //write_nic_byte(dev, BRSR, 0x0); // Set BRSR= 1M
2763 write_nic_word(dev, BcnItv, 100);
2764 write_nic_word(dev, AtimWnd, 2);
2766 //PlatformEFIOWrite2Byte(dev, FEMR, 0xFFFF);
2767 PlatformIOWrite2Byte(dev, FEMR, 0xFFFF);
2769 write_nic_byte(dev, WPA_CONFIG, 0);
2771 MacConfig_85BASIC(dev);
2773 // Override the RFSW_CTRL (MAC offset 0x272-0x273), 2006.06.07, by rcnjko.
2774 // BT_DEMO_BOARD type
2775 PlatformIOWrite2Byte(dev, RFSW_CTRL, 0x569a);
2777 //#ifdef CONFIG_RTL818X_S
2778 // for jong required
2779 // PlatformIOWrite2Byte(dev, RFSW_CTRL, 0x9a56);
2783 //PlatformIOWrite2Byte(dev, RFSW_CTRL, 0x9a56);
2785 //-----------------------------------------------------------------------------
2786 // Set up PHY related.
2787 //-----------------------------------------------------------------------------
2788 // Enable Config3.PARAM_En to revise AnaaParm.
2789 write_nic_byte(dev, CR9346, 0xc0); // enable config register write
2791 tmpu8 = read_nic_byte(dev, CONFIG3);
2792 write_nic_byte(dev, CONFIG3, (tmpu8 |CONFIG3_PARM_En) );
2794 // Turn on Analog power.
2795 // Asked for by William, otherwise, MAC 3-wire can't work, 2006.06.27, by rcnjko.
2796 write_nic_dword(dev, ANAPARAM2, ANAPARM2_ASIC_ON);
2797 write_nic_dword(dev, ANAPARAM, ANAPARM_ASIC_ON);
2799 write_nic_word(dev, ANAPARAM3, 0x0010);
2802 write_nic_byte(dev, CONFIG3, tmpu8);
2803 write_nic_byte(dev, CR9346, 0x00);
2804 //{by amy 080312 for led
2805 // enable EEM0 and EEM1 in 9346CR
2806 btCR9346 = read_nic_byte(dev, CR9346);
2807 write_nic_byte(dev, CR9346, (btCR9346|0xC0) );
2809 // B cut use LED1 to control HW RF on/off
2810 TmpU1b = read_nic_byte(dev, CONFIG5);
2811 TmpU1b = TmpU1b & ~BIT3;
2812 write_nic_byte(dev,CONFIG5, TmpU1b);
2814 // disable EEM0 and EEM1 in 9346CR
2815 btCR9346 &= ~(0xC0);
2816 write_nic_byte(dev, CR9346, btCR9346);
2818 //Enable Led (suggested by Jong)
2819 // B-cut RF Radio on/off 5e[3]=0
2820 btPSR = read_nic_byte(dev, PSR);
2821 write_nic_byte(dev, PSR, (btPSR | BIT3));
2822 //by amy 080312 for led}
2823 // setup initial timing for RFE.
2824 write_nic_word(dev, RFPinsOutput, 0x0480);
2825 SetOutputEnableOfRfPins(dev);
2826 write_nic_word(dev, RFPinsSelect, 0x2488);
2831 // We assume RegWirelessMode has already been initialized before,
2832 // however, we has to validate the wireless mode here and provide a reasonble
2833 // initialized value if necessary. 2005.01.13, by rcnjko.
2834 SupportedWirelessMode = GetSupportedWirelessMode8185(dev);
2835 if( (ieee->mode != WIRELESS_MODE_B) &&
2836 (ieee->mode != WIRELESS_MODE_G) &&
2837 (ieee->mode != WIRELESS_MODE_A) &&
2838 (ieee->mode != WIRELESS_MODE_AUTO))
2839 { // It should be one of B, G, A, or AUTO.
2840 bInvalidWirelessMode = 1;
2843 { // One of B, G, A, or AUTO.
2844 // Check if the wireless mode is supported by RF.
2845 if( (ieee->mode != WIRELESS_MODE_AUTO) &&
2846 (ieee->mode & SupportedWirelessMode) == 0 )
2848 bInvalidWirelessMode = 1;
2852 if(bInvalidWirelessMode || ieee->mode==WIRELESS_MODE_AUTO)
2853 { // Auto or other invalid value.
2854 // Assigne a wireless mode to initialize.
2855 if((SupportedWirelessMode & WIRELESS_MODE_A))
2857 InitWirelessMode = WIRELESS_MODE_A;
2859 else if((SupportedWirelessMode & WIRELESS_MODE_G))
2861 InitWirelessMode = WIRELESS_MODE_G;
2863 else if((SupportedWirelessMode & WIRELESS_MODE_B))
2865 InitWirelessMode = WIRELESS_MODE_B;
2869 DMESGW("InitializeAdapter8185(): No valid wireless mode supported, SupportedWirelessMode(%x)!!!\n",
2870 SupportedWirelessMode);
2871 InitWirelessMode = WIRELESS_MODE_B;
2874 // Initialize RegWirelessMode if it is not a valid one.
2875 if(bInvalidWirelessMode)
2877 ieee->mode = (WIRELESS_MODE)InitWirelessMode;
2881 { // One of B, G, A.
2882 InitWirelessMode = ieee->mode;
2884 //by amy for power save
2886 // printk("initialize ENABLE_IPS\n");
2887 priv->eRFPowerState = eRfOff;
2888 priv->RfOffReason = 0;
2891 // u32 tmp = jiffies;
2892 MgntActSet_RF_State(dev, eRfOn, 0);
2894 // printk("rf on cost jiffies:%lx\n", (tmp2-tmp)*1000/HZ);
2896 // DrvIFIndicateCurrentPhyStatus(priv);
2898 // If inactive power mode is enabled, disable rf while in disconnected state.
2899 // 2007.07.16, by shien chang.
2901 if (priv->bInactivePs)
2904 // u32 tmp = jiffies;
2905 MgntActSet_RF_State(dev,eRfOff, RF_CHANGE_BY_IPS);
2907 // printk("rf off cost jiffies:%lx\n", (tmp2-tmp)*1000/HZ);
2912 //by amy for power save
2914 // Turn off RF if necessary. 2005.08.23, by rcnjko.
2915 // We shall turn off RF after setting CMDR, otherwise,
2916 // RF will be turnned on after we enable MAC Tx/Rx.
2917 if(Adapter->MgntInfo.RegRfOff == TRUE)
2919 SetRFPowerState8185(Adapter, RF_OFF);
2923 SetRFPowerState8185(Adapter, RF_ON);
2927 /* //these is equal with above TODO.
2928 write_nic_byte(dev, CR9346, 0xc0); // enable config register write
2929 write_nic_byte(dev, CONFIG3, read_nic_byte(dev, CONFIG3) | CONFIG3_PARM_En);
2930 RF_WriteReg(dev, 0x4, 0x9FF);
2931 write_nic_dword(dev, ANAPARAM2, ANAPARM2_ASIC_ON);
2932 write_nic_dword(dev, ANAPARAM, ANAPARM_ASIC_ON);
2933 write_nic_byte(dev, CONFIG3, (read_nic_byte(dev, CONFIG3)&(~CONFIG3_PARM_En)));
2934 write_nic_byte(dev, CR9346, 0x00);
2937 ActSetWirelessMode8185(dev, (u8)(InitWirelessMode));
2939 //-----------------------------------------------------------------------------
2941 rtl8185b_irq_enable(dev);
2943 netif_start_queue(dev);
2948 void rtl8185b_rx_enable(struct net_device *dev)
2952 /* for now we accept data, management & ctl frame*/
2953 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2955 rxconf=read_nic_dword(dev,RX_CONF);
2956 rxconf = rxconf &~ MAC_FILTER_MASK;
2957 rxconf = rxconf | (1<<ACCEPT_MNG_FRAME_SHIFT);
2958 rxconf = rxconf | (1<<ACCEPT_DATA_FRAME_SHIFT);
2959 rxconf = rxconf | (1<<ACCEPT_BCAST_FRAME_SHIFT);
2960 rxconf = rxconf | (1<<ACCEPT_MCAST_FRAME_SHIFT);
2961 // rxconf = rxconf | (1<<ACCEPT_CRCERR_FRAME_SHIFT);
2962 if (dev->flags & IFF_PROMISC) DMESG ("NIC in promisc mode");
2964 if(priv->ieee80211->iw_mode == IW_MODE_MONITOR || \
2965 dev->flags & IFF_PROMISC){
2966 rxconf = rxconf | (1<<ACCEPT_ALLMAC_FRAME_SHIFT);
2968 rxconf = rxconf | (1<<ACCEPT_NICMAC_FRAME_SHIFT);
2969 if(priv->card_8185 == 0)
2970 rxconf = rxconf | (1<<RX_CHECK_BSSID_SHIFT);
2973 /*if(priv->ieee80211->iw_mode == IW_MODE_MASTER){
2974 rxconf = rxconf | (1<<ACCEPT_ALLMAC_FRAME_SHIFT);
2975 rxconf = rxconf | (1<<RX_CHECK_BSSID_SHIFT);
2978 if(priv->ieee80211->iw_mode == IW_MODE_MONITOR){
2979 rxconf = rxconf | (1<<ACCEPT_CTL_FRAME_SHIFT);
2980 rxconf = rxconf | (1<<ACCEPT_ICVERR_FRAME_SHIFT);
2981 rxconf = rxconf | (1<<ACCEPT_PWR_FRAME_SHIFT);
2984 if( priv->crcmon == 1 && priv->ieee80211->iw_mode == IW_MODE_MONITOR)
2985 rxconf = rxconf | (1<<ACCEPT_CRCERR_FRAME_SHIFT);
2987 //if(!priv->card_8185){
2988 rxconf = rxconf &~ RX_FIFO_THRESHOLD_MASK;
2989 rxconf = rxconf | (RX_FIFO_THRESHOLD_NONE<<RX_FIFO_THRESHOLD_SHIFT);
2992 rxconf = rxconf | (1<<RX_AUTORESETPHY_SHIFT);
2993 rxconf = rxconf &~ MAX_RX_DMA_MASK;
2994 rxconf = rxconf | (MAX_RX_DMA_2048<<MAX_RX_DMA_SHIFT);
2996 //if(!priv->card_8185)
2997 rxconf = rxconf | RCR_ONLYERLPKT;
2999 rxconf = rxconf &~ RCR_CS_MASK;
3000 if(!priv->card_8185)
3001 rxconf |= (priv->rcr_csense<<RCR_CS_SHIFT);
3002 // rxconf &=~ 0xfff00000;
3003 // rxconf |= 0x90100000;//9014f76f;
3004 write_nic_dword(dev, RX_CONF, rxconf);
3007 if (dev->flags & IFF_PROMISC) DMESG ("NIC in promisc mode");
3009 if(priv->ieee80211->iw_mode == IW_MODE_MONITOR || \
3010 dev->flags & IFF_PROMISC){
3011 priv->ReceiveConfig = priv->ReceiveConfig & (~RCR_APM);
3012 priv->ReceiveConfig = priv->ReceiveConfig | RCR_AAP;
3015 /*if(priv->ieee80211->iw_mode == IW_MODE_MASTER){
3016 rxconf = rxconf | (1<<ACCEPT_ALLMAC_FRAME_SHIFT);
3017 rxconf = rxconf | (1<<RX_CHECK_BSSID_SHIFT);
3020 if(priv->ieee80211->iw_mode == IW_MODE_MONITOR){
3021 priv->ReceiveConfig = priv->ReceiveConfig | RCR_ACF | RCR_APWRMGT | RCR_AICV;
3024 if( priv->crcmon == 1 && priv->ieee80211->iw_mode == IW_MODE_MONITOR)
3025 priv->ReceiveConfig = priv->ReceiveConfig | RCR_ACRC32;
3027 write_nic_dword(dev, RCR, priv->ReceiveConfig);
3032 DMESG("rxconf: %x %x",priv->ReceiveConfig ,read_nic_dword(dev,RCR));
3034 cmd=read_nic_byte(dev,CMD);
3035 write_nic_byte(dev,CMD,cmd | (1<<CMD_RX_ENABLE_SHIFT));
3039 void rtl8185b_tx_enable(struct net_device *dev)
3045 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3048 txconf= read_nic_dword(dev,TX_CONF);
3049 if(priv->card_8185){
3052 byte = read_nic_byte(dev,CW_CONF);
3053 byte &= ~(1<<CW_CONF_PERPACKET_CW_SHIFT);
3054 byte &= ~(1<<CW_CONF_PERPACKET_RETRY_SHIFT);
3055 write_nic_byte(dev, CW_CONF, byte);
3057 tx_agc_ctl = read_nic_byte(dev, TX_AGC_CTL);
3058 tx_agc_ctl &= ~(1<<TX_AGC_CTL_PERPACKET_GAIN_SHIFT);
3059 tx_agc_ctl &= ~(1<<TX_AGC_CTL_PERPACKET_ANTSEL_SHIFT);
3060 tx_agc_ctl |=(1<<TX_AGC_CTL_FEEDBACK_ANT);
3061 write_nic_byte(dev, TX_AGC_CTL, tx_agc_ctl);
3063 write_nic_word(dev, 0x5e, 0x01);
3064 force_pci_posting(dev);
3066 write_nic_word(dev, 0xfe, 0x10);
3067 force_pci_posting(dev);
3069 write_nic_word(dev, 0x5e, 0x00);
3070 force_pci_posting(dev);
3073 write_nic_byte(dev, 0xec, 0x3f); /* Disable early TX */
3076 if(priv->card_8185){
3078 txconf = txconf &~ (1<<TCR_PROBE_NOTIMESTAMP_SHIFT);
3083 txconf= txconf &~ (1<<TX_CONF_HEADER_AUTOICREMENT_SHIFT);
3085 txconf= txconf | (1<<TX_CONF_HEADER_AUTOICREMENT_SHIFT);
3088 txconf = txconf &~ TX_LOOPBACK_MASK;
3089 txconf = txconf | (TX_LOOPBACK_NONE <<TX_LOOPBACK_SHIFT);
3090 txconf = txconf &~ TCR_DPRETRY_MASK;
3091 txconf = txconf &~ TCR_RTSRETRY_MASK;
3092 txconf = txconf | (priv->retry_data<<TX_DPRETRY_SHIFT);
3093 txconf = txconf | (priv->retry_rts<<TX_RTSRETRY_SHIFT);
3094 txconf = txconf &~ (1<<TX_NOCRC_SHIFT);
3096 if(priv->card_8185){
3097 if(priv->hw_plcp_len)
3098 txconf = txconf &~ TCR_PLCP_LEN;
3100 txconf = txconf | TCR_PLCP_LEN;
3102 txconf = txconf &~ TCR_SAT;
3104 txconf = txconf &~ TCR_MXDMA_MASK;
3105 txconf = txconf | (TCR_MXDMA_2048<<TCR_MXDMA_SHIFT);
3106 txconf = txconf | TCR_CWMIN;
3107 txconf = txconf | TCR_DISCW;
3109 // if(priv->ieee80211->hw_wep)
3110 // txconf=txconf &~ (1<<TX_NOICV_SHIFT);
3112 txconf=txconf | (1<<TX_NOICV_SHIFT);
3114 write_nic_dword(dev,TX_CONF,txconf);
3117 write_nic_dword(dev, TCR, priv->TransmitConfig);
3118 byte = read_nic_byte(dev, MSR);
3119 byte |= MSR_LINK_ENEDCA;
3120 write_nic_byte(dev, MSR, byte);
3125 DMESG("txconf: %x %x",priv->TransmitConfig,read_nic_dword(dev,TCR));
3128 cmd=read_nic_byte(dev,CMD);
3129 write_nic_byte(dev,CMD,cmd | (1<<CMD_TX_ENABLE_SHIFT));
3131 //write_nic_dword(dev,TX_CONF,txconf);
3135 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
3136 write_nic_byte(dev, TX_DMA_POLLING, priv->dma_poll_mask);
3137 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);