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"
38 //#define CONFIG_RTL8180_IO_MAP
40 #define TC_3W_POLL_MAX_TRY_CNT 5
41 static u8 MAC_REG_TABLE[][2]={
43 // 0x34(BRSR), 0xBE(RATE_FALLBACK_CTL), 0x1E0(ARFR) would set in HwConfigureRTL8185()
44 // 0x272(RFSW_CTRL), 0x1CE(AESMSK_QC) set in InitializeAdapter8185().
45 // 0x1F0~0x1F8 set in MacConfig_85BASIC()
46 {0x08, 0xae}, {0x0a, 0x72}, {0x5b, 0x42},
47 {0x84, 0x88}, {0x85, 0x24}, {0x88, 0x54}, {0x8b, 0xb8}, {0x8c, 0x03},
48 {0x8d, 0x40}, {0x8e, 0x00}, {0x8f, 0x00}, {0x5b, 0x18}, {0x91, 0x03},
49 {0x94, 0x0F}, {0x95, 0x32},
50 {0x96, 0x00}, {0x97, 0x07}, {0xb4, 0x22}, {0xdb, 0x00},
51 {0xf0, 0x32}, {0xf1, 0x32}, {0xf2, 0x00}, {0xf3, 0x00}, {0xf4, 0x32},
52 {0xf5, 0x43}, {0xf6, 0x00}, {0xf7, 0x00}, {0xf8, 0x46}, {0xf9, 0xa4},
53 {0xfa, 0x00}, {0xfb, 0x00}, {0xfc, 0x96}, {0xfd, 0xa4}, {0xfe, 0x00},
57 // For Flextronics system Logo PCIHCT failure:
58 // 0x1C4~0x1CD set no-zero value to avoid PCI configuration space 0x45[7]=1
60 {0x58, 0x00}, {0x59, 0x00}, {0x5a, 0x04}, {0x5b, 0x00}, {0x60, 0x24},
61 {0x61, 0x97}, {0x62, 0xF0}, {0x63, 0x09}, {0x80, 0x0F}, {0x81, 0xFF},
62 {0x82, 0xFF}, {0x83, 0x03},
63 {0xC4, 0x22}, {0xC5, 0x22}, {0xC6, 0x22}, {0xC7, 0x22}, {0xC8, 0x22}, //lzm add 080826
64 {0xC9, 0x22}, {0xCA, 0x22}, {0xCB, 0x22}, {0xCC, 0x22}, {0xCD, 0x22},//lzm add 080826
70 {0x0c, 0x04}, {0x4c, 0x30}, {0x4d, 0x08}, {0x50, 0x05}, {0x51, 0xf5},
71 {0x52, 0x04}, {0x53, 0xa0}, {0x54, 0xff}, {0x55, 0xff}, {0x56, 0xff},
72 {0x57, 0xff}, {0x58, 0x08}, {0x59, 0x08}, {0x5a, 0x08}, {0x5b, 0x08},
73 {0x60, 0x08}, {0x61, 0x08}, {0x62, 0x08}, {0x63, 0x08}, {0x64, 0x2f},
74 {0x8c, 0x3f}, {0x8d, 0x3f}, {0x8e, 0x3f},
75 {0x8f, 0x3f}, {0xc4, 0xff}, {0xc5, 0xff}, {0xc6, 0xff}, {0xc7, 0xff},
76 {0xc8, 0x00}, {0xc9, 0x00}, {0xca, 0x80}, {0xcb, 0x00},
79 {0x5e, 0x00},{0x9f, 0x03}
83 static u8 ZEBRA_AGC[]={
85 0x7E,0x7E,0x7E,0x7E,0x7D,0x7C,0x7B,0x7A,0x79,0x78,0x77,0x76,0x75,0x74,0x73,0x72,
86 0x71,0x70,0x6F,0x6E,0x6D,0x6C,0x6B,0x6A,0x69,0x68,0x67,0x66,0x65,0x64,0x63,0x62,
87 0x48,0x47,0x46,0x45,0x44,0x29,0x28,0x27,0x26,0x25,0x24,0x23,0x22,0x21,0x08,0x07,
88 0x06,0x05,0x04,0x03,0x02,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
89 0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x10,0x11,0x12,0x13,0x15,0x16,
90 0x17,0x17,0x18,0x18,0x19,0x1a,0x1a,0x1b,0x1b,0x1c,0x1c,0x1d,0x1d,0x1d,0x1e,0x1e,
91 0x1f,0x1f,0x1f,0x20,0x20,0x20,0x20,0x21,0x21,0x21,0x22,0x22,0x22,0x23,0x23,0x24,
92 0x24,0x25,0x25,0x25,0x26,0x26,0x27,0x27,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F
95 static u32 ZEBRA_RF_RX_GAIN_TABLE[]={
96 0x0096,0x0076,0x0056,0x0036,0x0016,0x01f6,0x01d6,0x01b6,
97 0x0196,0x0176,0x00F7,0x00D7,0x00B7,0x0097,0x0077,0x0057,
98 0x0037,0x00FB,0x00DB,0x00BB,0x00FF,0x00E3,0x00C3,0x00A3,
99 0x0083,0x0063,0x0043,0x0023,0x0003,0x01E3,0x01C3,0x01A3,
100 0x0183,0x0163,0x0143,0x0123,0x0103
103 static u8 OFDM_CONFIG[]={
104 // OFDM reg0x06[7:0]=0xFF: Enable power saving mode in RX
105 // OFDM reg0x3C[4]=1'b1: Enable RX power saving mode
106 // ofdm 0x3a = 0x7b ,(original : 0xfb) For ECS shielding room TP test
109 0x10, 0x0F, 0x0A, 0x0C, 0x14, 0xFA, 0xFF, 0x50,
110 0x00, 0x50, 0x00, 0x00, 0x00, 0x5C, 0x00, 0x00,
112 0x40, 0x00, 0x40, 0x00, 0x00, 0x00, 0xA8, 0x26,
113 0x32, 0x33, 0x06, 0xA5, 0x6F, 0x55, 0xC8, 0xBB,
115 0x0A, 0xE1, 0x2C, 0x4A, 0x86, 0x83, 0x34, 0x00,
116 0x4F, 0x24, 0x6F, 0xC2, 0x03, 0x40, 0x80, 0x00,
118 0xC0, 0xC1, 0x58, 0xF1, 0x00, 0xC4, 0x90, 0x3e,
119 0xD8, 0x3C, 0x7B, 0x10, 0x10
122 /*---------------------------------------------------------------
124 * the code is ported from Windows source code
125 ----------------------------------------------------------------*/
128 PlatformIOWrite1Byte(
129 struct net_device *dev,
134 #ifndef CONFIG_RTL8180_IO_MAP
135 write_nic_byte(dev, offset, data);
136 read_nic_byte(dev, offset); // To make sure write operation is completed, 2005.11.09, by rcnjko.
139 u32 Page = (offset >> 8);
144 write_nic_byte(dev, offset, data);
151 u8 psr = read_nic_byte(dev, PSR);
153 write_nic_byte(dev, PSR, ((psr & 0xfc) | (u8)Page)); // Switch to page N.
154 write_nic_byte(dev, (offset & 0xff), data);
155 write_nic_byte(dev, PSR, (psr & 0xfc)); // Switch to page 0.
160 // Illegal page number.
161 DMESGE("PlatformIOWrite1Byte(): illegal page number: %d, offset: %#X", Page, offset);
168 PlatformIOWrite2Byte(
169 struct net_device *dev,
174 #ifndef CONFIG_RTL8180_IO_MAP
175 write_nic_word(dev, offset, data);
176 read_nic_word(dev, offset); // To make sure write operation is completed, 2005.11.09, by rcnjko.
180 u32 Page = (offset >> 8);
185 write_nic_word(dev, offset, data);
192 u8 psr = read_nic_byte(dev, PSR);
194 write_nic_byte(dev, PSR, ((psr & 0xfc) | (u8)Page)); // Switch to page N.
195 write_nic_word(dev, (offset & 0xff), data);
196 write_nic_byte(dev, PSR, (psr & 0xfc)); // Switch to page 0.
201 // Illegal page number.
202 DMESGE("PlatformIOWrite2Byte(): illegal page number: %d, offset: %#X", Page, offset);
207 u8 PlatformIORead1Byte(struct net_device *dev, u32 offset);
210 PlatformIOWrite4Byte(
211 struct net_device *dev,
216 #ifndef CONFIG_RTL8180_IO_MAP
218 if (offset == PhyAddr)
219 {//For Base Band configuration.
220 unsigned char cmdByte;
221 unsigned long dataBytes;
225 cmdByte = (u8)(data & 0x000000ff);
230 // The critical section is only BB read/write race condition.
232 // 1. We assume NO one will access BB at DIRQL, otherwise, system will crash for
233 // acquiring the spinlock in such context.
234 // 2. PlatformIOWrite4Byte() MUST NOT be recursive.
236 // NdisAcquireSpinLock( &(pDevice->IoSpinLock) );
238 for(idx = 0; idx < 30; idx++)
239 { // Make sure command bit is clear before access it.
240 u1bTmp = PlatformIORead1Byte(dev, PhyAddr);
241 if((u1bTmp & BIT7) == 0)
247 for(idx=0; idx < 3; idx++)
249 PlatformIOWrite1Byte(dev,offset+1+idx,((u8*)&dataBytes)[idx] );
251 write_nic_byte(dev, offset, cmdByte);
253 // NdisReleaseSpinLock( &(pDevice->IoSpinLock) );
257 write_nic_dword(dev, offset, data);
258 read_nic_dword(dev, offset); // To make sure write operation is completed, 2005.11.09, by rcnjko.
261 u32 Page = (offset >> 8);
266 write_nic_word(dev, offset, data);
273 u8 psr = read_nic_byte(dev, PSR);
275 write_nic_byte(dev, PSR, ((psr & 0xfc) | (u8)Page)); // Switch to page N.
276 write_nic_dword(dev, (offset & 0xff), data);
277 write_nic_byte(dev, PSR, (psr & 0xfc)); // Switch to page 0.
282 // Illegal page number.
283 DMESGE("PlatformIOWrite4Byte(): illegal page number: %d, offset: %#X", Page, offset);
291 struct net_device *dev,
297 #ifndef CONFIG_RTL8180_IO_MAP
298 data = read_nic_byte(dev, offset);
301 u32 Page = (offset >> 8);
306 data = read_nic_byte(dev, offset);
313 u8 psr = read_nic_byte(dev, PSR);
315 write_nic_byte(dev, PSR, ((psr & 0xfc) | (u8)Page)); // Switch to page N.
316 data = read_nic_byte(dev, (offset & 0xff));
317 write_nic_byte(dev, PSR, (psr & 0xfc)); // Switch to page 0.
322 // Illegal page number.
323 DMESGE("PlatformIORead1Byte(): illegal page number: %d, offset: %#X", Page, offset);
333 struct net_device *dev,
339 #ifndef CONFIG_RTL8180_IO_MAP
340 data = read_nic_word(dev, offset);
343 u32 Page = (offset >> 8);
348 data = read_nic_word(dev, offset);
355 u8 psr = read_nic_byte(dev, PSR);
357 write_nic_byte(dev, PSR, ((psr & 0xfc) | (u8)Page)); // Switch to page N.
358 data = read_nic_word(dev, (offset & 0xff));
359 write_nic_byte(dev, PSR, (psr & 0xfc)); // Switch to page 0.
364 // Illegal page number.
365 DMESGE("PlatformIORead2Byte(): illegal page number: %d, offset: %#X", Page, offset);
375 struct net_device *dev,
381 #ifndef CONFIG_RTL8180_IO_MAP
382 data = read_nic_dword(dev, offset);
385 u32 Page = (offset >> 8);
390 data = read_nic_dword(dev, offset);
397 u8 psr = read_nic_byte(dev, PSR);
399 write_nic_byte(dev, PSR, ((psr & 0xfc) | (u8)Page)); // Switch to page N.
400 data = read_nic_dword(dev, (offset & 0xff));
401 write_nic_byte(dev, PSR, (psr & 0xfc)); // Switch to page 0.
406 // Illegal page number.
407 DMESGE("PlatformIORead4Byte(): illegal page number: %d, offset: %#X\n", Page, offset);
416 SetOutputEnableOfRfPins(
417 struct net_device *dev
420 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
422 switch(priv->rf_chip)
424 case RFCHIPID_RTL8225:
427 write_nic_word(dev, RFPinsEnable, 0x1bff);
428 //write_nic_word(dev, RFPinsEnable, 0x1fff);
435 struct net_device *dev,
443 u16 oval,oval2,oval3;
448 // RTL8187S HSSI Read/Write Function
449 u1bTmp = read_nic_byte(dev, RF_SW_CONFIG);
450 u1bTmp |= RF_SW_CFG_SI; //reg08[1]=1 Serial Interface(SI)
451 write_nic_byte(dev, RF_SW_CONFIG, u1bTmp);
452 UshortBuffer = read_nic_word(dev, RFPinsOutput);
453 oval = UshortBuffer & 0xfff8; // We shall clear bit0, 1, 2 first, 2005.10.28, by rcnjko.
455 oval2 = read_nic_word(dev, RFPinsEnable);
456 oval3 = read_nic_word(dev, RFPinsSelect);
458 // <RJ_NOTE> 3-wire should be controled by HW when we finish SW 3-wire programming. 2005.08.10, by rcnjko.
461 write_nic_word(dev, RFPinsEnable, (oval2|0x0007)); // Set To Output Enable
462 write_nic_word(dev, RFPinsSelect, (oval3|0x0007)); // Set To SW Switch
465 // Add this to avoid hardware and software 3-wire conflict.
466 // 2005.03.01, by rcnjko.
468 twreg.struc.enableB = 1;
469 write_nic_word(dev, RFPinsOutput, (twreg.longData|oval)); // Set SI_EN (RFLE)
471 twreg.struc.enableB = 0;
472 write_nic_word(dev, RFPinsOutput, (twreg.longData|oval)); // Clear SI_EN (RFLE)
475 mask = (low2high)?0x01:((u32)0x01<<(totalLength-1));
477 for(i=0; i<totalLength/2; i++)
479 twreg.struc.data = ((data2Write&mask)!=0) ? 1 : 0;
480 write_nic_word(dev, RFPinsOutput, (twreg.longData|oval));
482 write_nic_word(dev, RFPinsOutput, (twreg.longData|oval));
483 write_nic_word(dev, RFPinsOutput, (twreg.longData|oval));
485 mask = (low2high)?(mask<<1):(mask>>1);
486 twreg.struc.data = ((data2Write&mask)!=0) ? 1 : 0;
487 write_nic_word(dev, RFPinsOutput, (twreg.longData|oval));
488 write_nic_word(dev, RFPinsOutput, (twreg.longData|oval));
490 write_nic_word(dev, RFPinsOutput, (twreg.longData|oval));
491 mask = (low2high)?(mask<<1):(mask>>1);
494 twreg.struc.enableB = 1;
496 twreg.struc.data = 0;
497 write_nic_word(dev, RFPinsOutput, twreg.longData|oval);
500 write_nic_word(dev, RFPinsOutput, oval|0x0004);
501 write_nic_word(dev, RFPinsSelect, oval3|0x0000);
503 SetOutputEnableOfRfPins(dev);
510 struct net_device *dev,
523 // Check if WE and RE are cleared.
524 for(TryCnt = 0; TryCnt < TC_3W_POLL_MAX_TRY_CNT; TryCnt++)
526 u1bTmp = read_nic_byte(dev, SW_3W_CMD1);
527 if( (u1bTmp & (SW_3W_CMD1_RE|SW_3W_CMD1_WE)) == 0 )
533 if (TryCnt == TC_3W_POLL_MAX_TRY_CNT)
534 panic("HwThreeWire(): CmdReg: %#X RE|WE bits are not clear!!\n", u1bTmp);
536 // RTL8187S HSSI Read/Write Function
537 u1bTmp = read_nic_byte(dev, RF_SW_CONFIG);
541 u1bTmp |= RF_SW_CFG_SI; //reg08[1]=1 Serial Interface(SI)
544 u1bTmp &= ~RF_SW_CFG_SI; //reg08[1]=0 Parallel Interface(PI)
547 write_nic_byte(dev, RF_SW_CONFIG, u1bTmp);
551 // jong: HW SI read must set reg84[3]=0.
552 u1bTmp = read_nic_byte(dev, RFPinsSelect);
554 write_nic_byte(dev, RFPinsSelect, u1bTmp );
556 // Fill up data buffer for write operation.
560 if(nDataBufBitCnt == 16)
562 write_nic_word(dev, SW_3W_DB0, *((u16*)pDataBuf));
564 else if(nDataBufBitCnt == 64) // RTL8187S shouldn't enter this case
566 write_nic_dword(dev, SW_3W_DB0, *((u32*)pDataBuf));
567 write_nic_dword(dev, SW_3W_DB1, *((u32*)(pDataBuf + 4)));
572 int ByteCnt = nDataBufBitCnt / 8;
573 //printk("%d\n",nDataBufBitCnt);
574 if ((nDataBufBitCnt % 8) != 0)
575 panic("HwThreeWire(): nDataBufBitCnt(%d) should be multiple of 8!!!\n",
578 if (nDataBufBitCnt > 64)
579 panic("HwThreeWire(): nDataBufBitCnt(%d) should <= 64!!!\n",
582 for(idx = 0; idx < ByteCnt; idx++)
584 write_nic_byte(dev, (SW_3W_DB0+idx), *(pDataBuf+idx));
592 // SI - reg274[3:0] : RF register's Address
593 write_nic_word(dev, SW_3W_DB0, *((u16*)pDataBuf) );
597 // PI - reg274[15:12] : RF register's Address
598 write_nic_word(dev, SW_3W_DB0, (*((u16*)pDataBuf)) << 12);
602 // Set up command: WE or RE.
605 write_nic_byte(dev, SW_3W_CMD1, SW_3W_CMD1_WE);
609 write_nic_byte(dev, SW_3W_CMD1, SW_3W_CMD1_RE);
612 // Check if DONE is set.
613 for(TryCnt = 0; TryCnt < TC_3W_POLL_MAX_TRY_CNT; TryCnt++)
615 u1bTmp = read_nic_byte(dev, SW_3W_CMD1);
616 if( (u1bTmp & SW_3W_CMD1_DONE) != 0 )
623 write_nic_byte(dev, SW_3W_CMD1, 0);
625 // Read back data for read operation.
630 //Serial Interface : reg363_362[11:0]
631 *((u16*)pDataBuf) = read_nic_word(dev, SI_DATA_READ) ;
635 //Parallel Interface : reg361_360[11:0]
636 *((u16*)pDataBuf) = read_nic_word(dev, PI_DATA_READ);
639 *((u16*)pDataBuf) &= 0x0FFF;
650 struct net_device *dev,
663 // Check if WE and RE are cleared.
664 for(TryCnt = 0; TryCnt < TC_3W_POLL_MAX_TRY_CNT; TryCnt++)
666 u1bTmp = read_nic_byte(dev, SW_3W_CMD1);
667 if( (u1bTmp & (SW_3W_CMD1_RE|SW_3W_CMD1_WE)) == 0 )
673 if (TryCnt == TC_3W_POLL_MAX_TRY_CNT)
674 panic("HwThreeWire(): CmdReg: %#X RE|WE bits are not clear!!\n", u1bTmp);
676 // Fill up data buffer for write operation.
677 if(nDataBufBitCnt == 16)
679 write_nic_word(dev, SW_3W_DB0, *((u16 *)pDataBuf));
681 else if(nDataBufBitCnt == 64)
683 write_nic_dword(dev, SW_3W_DB0, *((u32 *)pDataBuf));
684 write_nic_dword(dev, SW_3W_DB1, *((u32 *)(pDataBuf + 4)));
689 int ByteCnt = nDataBufBitCnt / 8;
691 if ((nDataBufBitCnt % 8) != 0)
692 panic("HwThreeWire(): nDataBufBitCnt(%d) should be multiple of 8!!!\n",
695 if (nDataBufBitCnt > 64)
696 panic("HwThreeWire(): nDataBufBitCnt(%d) should <= 64!!!\n",
699 for(idx = 0; idx < ByteCnt; idx++)
701 write_nic_byte(dev, (SW_3W_DB0+idx), *(pDataBuf+idx));
705 // Fill up length field.
706 u1bTmp = (u8)(nDataBufBitCnt - 1); // Number of bits - 1.
708 u1bTmp |= SW_3W_CMD0_HOLD;
709 write_nic_byte(dev, SW_3W_CMD0, u1bTmp);
711 // Set up command: WE or RE.
714 write_nic_byte(dev, SW_3W_CMD1, SW_3W_CMD1_WE);
718 write_nic_byte(dev, SW_3W_CMD1, SW_3W_CMD1_RE);
721 // Check if WE and RE are cleared and DONE is set.
722 for(TryCnt = 0; TryCnt < TC_3W_POLL_MAX_TRY_CNT; TryCnt++)
724 u1bTmp = read_nic_byte(dev, SW_3W_CMD1);
725 if( (u1bTmp & (SW_3W_CMD1_RE|SW_3W_CMD1_WE)) == 0 &&
726 (u1bTmp & SW_3W_CMD1_DONE) != 0 )
732 if(TryCnt == TC_3W_POLL_MAX_TRY_CNT)
734 //RT_ASSERT(TryCnt != TC_3W_POLL_MAX_TRY_CNT,
735 // ("HwThreeWire(): CmdReg: %#X RE|WE bits are not clear or DONE is not set!!\n", u1bTmp));
736 // Workaround suggested by wcchu: clear WE here. 2006.07.07, by rcnjko.
737 write_nic_byte(dev, SW_3W_CMD1, 0);
740 // Read back data for read operation.
741 // <RJ_TODO> I am not sure if this is correct output format of a read operation.
744 if(nDataBufBitCnt == 16)
746 *((u16 *)pDataBuf) = read_nic_word(dev, SW_3W_DB0);
748 else if(nDataBufBitCnt == 64)
750 *((u32 *)pDataBuf) = read_nic_dword(dev, SW_3W_DB0);
751 *((u32 *)(pDataBuf + 4)) = read_nic_dword(dev, SW_3W_DB1);
756 int ByteCnt = nDataBufBitCnt / 8;
758 if ((nDataBufBitCnt % 8) != 0)
759 panic("HwThreeWire(): nDataBufBitCnt(%d) should be multiple of 8!!!\n",
762 if (nDataBufBitCnt > 64)
763 panic("HwThreeWire(): nDataBufBitCnt(%d) should <= 64!!!\n",
766 for(idx = 0; idx < ByteCnt; idx++)
768 *(pDataBuf+idx) = read_nic_byte(dev, (SW_3W_DB0+idx));
781 struct net_device *dev,
791 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
794 switch(priv->rf_chip)
796 case RFCHIPID_RTL8225:
797 case RF_ZEBRA2: // Annie 2006-05-12.
798 case RF_ZEBRA4: //by amy
799 switch(priv->RegThreeWireMode)
802 { // Perform SW 3-wire programming by driver.
803 data2Write = (data << 4) | (u32)(offset & 0x0f);
806 ZEBRA_RFSerialWrite(dev, data2Write, len, low2high);
812 data2Write = (data << 4) | (u32)(offset & 0x0f);
816 (u8 *)(&data2Write), // pDataBuf,
817 len, // nDataBufBitCnt,
822 case HW_THREE_WIRE_PI: //Parallel Interface
824 data2Write = (data << 4) | (u32)(offset & 0x0f);
828 (u8*)(&data2Write), // pDataBuf,
829 len, // nDataBufBitCnt,
837 case HW_THREE_WIRE_SI: //Serial Interface
839 data2Write = (data << 4) | (u32)(offset & 0x0f);
841 // printk(" enter ZEBRA_RFSerialWrite\n ");
843 // ZEBRA_RFSerialWrite(dev, data2Write, len, low2high);
847 (u8*)(&data2Write), // pDataBuf,
848 len, // nDataBufBitCnt,
852 // printk(" exit ZEBRA_RFSerialWrite\n ");
858 DMESGE("RF_WriteReg(): invalid RegThreeWireMode(%d) !!!", priv->RegThreeWireMode);
864 DMESGE("RF_WriteReg(): unknown RFChipID: %#X", priv->rf_chip);
872 struct net_device *dev,
882 u16 oval,oval2,oval3,tmp, wReg80;
886 //PHAL_DATA_8187 pHalData = GetHalData8187(pAdapter);
887 { // RTL8187S HSSI Read/Write Function
888 u1bTmp = read_nic_byte(dev, RF_SW_CONFIG);
889 u1bTmp |= RF_SW_CFG_SI; //reg08[1]=1 Serial Interface(SI)
890 write_nic_byte(dev, RF_SW_CONFIG, u1bTmp);
893 wReg80 = oval = read_nic_word(dev, RFPinsOutput);
894 oval2 = read_nic_word(dev, RFPinsEnable);
895 oval3 = read_nic_word(dev, RFPinsSelect);
897 write_nic_word(dev, RFPinsEnable, oval2|0xf);
898 write_nic_word(dev, RFPinsSelect, oval3|0xf);
902 // We must clear BIT0-3 here, otherwise,
903 // SW_Enalbe will be true when we first call ZEBRA_RFSerialRead() after 8187MPVC open,
904 // which will cause the value read become 0. 2005.04.11, by rcnjko.
907 // Avoid collision with hardware three-wire.
909 twreg.struc.enableB = 1;
910 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(4);
913 twreg.struc.enableB = 0;
915 twreg.struc.read_write = 0;
916 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(5);
918 mask = (low2high) ? 0x01 : ((u32)0x01<<(32-1));
919 for(i = 0; i < wLength/2; i++)
921 twreg.struc.data = ((data2Write&mask) != 0) ? 1 : 0;
922 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(1);
924 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
925 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
927 mask = (low2high) ? (mask<<1): (mask>>1);
931 // 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.
932 //PlatformEFIOWrite2Byte(pAdapter, RFPinsEnable, 0xe); // turn off data enable
933 //PlatformEFIOWrite2Byte(pAdapter, RFPinsSelect, 0xe);
935 twreg.struc.read_write=1;
936 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
938 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
941 twreg.struc.data = ((data2Write&mask) != 0) ? 1: 0;
942 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
943 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
946 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(1);
948 mask = (low2high) ? (mask<<1) : (mask>>1);
952 twreg.struc.data = 0;
953 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
954 mask = (low2high) ? 0x01 : ((u32)0x01 << (12-1));
957 // 061016, by rcnjko:
958 // We must set data pin to HW controled, otherwise RF can't driver it and
959 // value RF register won't be able to read back properly.
961 write_nic_word(dev, RFPinsEnable, ( ((oval2|0x0E) & (~0x01))) );
963 for(i = 0; i < rLength; i++)
965 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(1);
967 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
968 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
969 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
970 tmp = read_nic_word(dev, RFPinsInput);
971 tdata.longData = tmp;
972 *data2Read |= tdata.struc.clk ? mask : 0;
975 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
977 mask = (low2high) ? (mask<<1) : (mask>>1);
979 twreg.struc.enableB = 1;
981 twreg.struc.data = 0;
982 twreg.struc.read_write = 1;
983 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
985 //PlatformEFIOWrite2Byte(pAdapter, RFPinsEnable, oval2|0x8); // Set To Output Enable
986 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.
987 //PlatformEFIOWrite2Byte(pAdapter, RFPinsEnable, 0x1bff);
988 write_nic_word(dev, RFPinsSelect, oval3); // Set To SW Switch
989 //PlatformEFIOWrite2Byte(pAdapter, RFPinsSelect, 0x0488);
990 write_nic_word(dev, RFPinsOutput, 0x3a0);
991 //PlatformEFIOWrite2Byte(pAdapter, RFPinsOutput, 0x0480);
997 struct net_device *dev,
1001 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1008 switch(priv->rf_chip)
1010 case RFCHIPID_RTL8225:
1013 switch(priv->RegThreeWireMode)
1015 case HW_THREE_WIRE_PI: // For 87S Parallel Interface.
1017 data2Write = ((u32)(offset&0x0f));
1021 (u8*)(&data2Write), // pDataBuf,
1022 wlen, // nDataBufBitCnt,
1025 dataRead= data2Write;
1029 case HW_THREE_WIRE_SI: // For 87S Serial Interface.
1031 data2Write = ((u32)(offset&0x0f)) ;
1035 (u8*)(&data2Write), // pDataBuf,
1036 wlen, // nDataBufBitCnt,
1040 dataRead= data2Write;
1044 // Perform SW 3-wire programming by driver.
1047 data2Write = ((u32)(offset&0x1f)) << 27; // For Zebra E-cut. 2005.04.11, by rcnjko.
1051 ZEBRA_RFSerialRead(dev, data2Write, wlen,&dataRead,rlen, low2high);
1065 // by Owen on 04/07/14 for writing BB register successfully
1068 struct net_device *dev,
1072 //u8 TimeoutCounter;
1076 UCharData = (u8)((Data & 0x0000ff00) >> 8);
1077 PlatformIOWrite4Byte(dev, PhyAddr, Data);
1078 //for(TimeoutCounter = 10; TimeoutCounter > 0; TimeoutCounter--)
1080 PlatformIOWrite4Byte(dev, PhyAddr, Data & 0xffffff7f);
1081 RegisterContent = PlatformIORead1Byte(dev, PhyDataR);
1082 //if(UCharData == RegisterContent)
1089 struct net_device *dev,
1093 //u8 TimeoutCounter;
1096 PlatformIOWrite4Byte(dev, PhyAddr, addr & 0xffffff7f);
1097 RegisterContent = PlatformIORead1Byte(dev, PhyDataR);
1099 return RegisterContent;
1104 // Perform Antenna settings with antenna diversity on 87SE.
1105 // Created by Roger, 2008.01.25.
1108 SetAntennaConfig87SE(
1109 struct net_device *dev,
1110 u8 DefaultAnt, // 0: Main, 1: Aux.
1111 bool bAntDiversity // 1:Enable, 0: Disable.
1114 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1115 bool bAntennaSwitched = true;
1117 //printk("SetAntennaConfig87SE(): DefaultAnt(%d), bAntDiversity(%d)\n", DefaultAnt, bAntDiversity);
1119 // Threshold for antenna diversity.
1120 write_phy_cck(dev, 0x0c, 0x09); // Reg0c : 09
1122 if( bAntDiversity ) // Enable Antenna Diversity.
1124 if( DefaultAnt == 1 ) // aux antenna
1126 // Mac register, aux antenna
1127 write_nic_byte(dev, ANTSEL, 0x00);
1129 // Config CCK RX antenna.
1130 write_phy_cck(dev, 0x11, 0xbb); // Reg11 : bb
1131 write_phy_cck(dev, 0x01, 0xc7); // Reg01 : c7
1133 // Config OFDM RX antenna.
1134 write_phy_ofdm(dev, 0x0D, 0x54); // Reg0d : 54
1135 write_phy_ofdm(dev, 0x18, 0xb2); // Reg18 : b2
1137 else // use main antenna
1139 // Mac register, main antenna
1140 write_nic_byte(dev, ANTSEL, 0x03);
1142 // Config CCK RX antenna.
1143 write_phy_cck(dev, 0x11, 0x9b); // Reg11 : 9b
1144 write_phy_cck(dev, 0x01, 0xc7); // Reg01 : c7
1146 // Config OFDM RX antenna.
1147 write_phy_ofdm(dev, 0x0d, 0x5c); // Reg0d : 5c
1148 write_phy_ofdm(dev, 0x18, 0xb2); // Reg18 : b2
1151 else // Disable Antenna Diversity.
1153 if( DefaultAnt == 1 ) // aux Antenna
1155 // Mac register, aux antenna
1156 write_nic_byte(dev, ANTSEL, 0x00);
1158 // Config CCK RX antenna.
1159 write_phy_cck(dev, 0x11, 0xbb); // Reg11 : bb
1160 write_phy_cck(dev, 0x01, 0x47); // Reg01 : 47
1162 // Config OFDM RX antenna.
1163 write_phy_ofdm(dev, 0x0D, 0x54); // Reg0d : 54
1164 write_phy_ofdm(dev, 0x18, 0x32); // Reg18 : 32
1166 else // main Antenna
1168 // Mac register, main antenna
1169 write_nic_byte(dev, ANTSEL, 0x03);
1171 // Config CCK RX antenna.
1172 write_phy_cck(dev, 0x11, 0x9b); // Reg11 : 9b
1173 write_phy_cck(dev, 0x01, 0x47); // Reg01 : 47
1175 // Config OFDM RX antenna.
1176 write_phy_ofdm(dev, 0x0D, 0x5c); // Reg0d : 5c
1177 write_phy_ofdm(dev, 0x18, 0x32); // Reg18 : 32
1180 priv->CurrAntennaIndex = DefaultAnt; // Update default settings.
1181 return bAntennaSwitched;
1184 /*---------------------------------------------------------------
1185 * Hardware Initialization.
1186 * the code is ported from Windows source code
1187 ----------------------------------------------------------------*/
1190 ZEBRA_Config_85BASIC_HardCode(
1191 struct net_device *dev
1195 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1198 u32 u4bRegOffset, u4bRegValue, u4bRF23, u4bRF24;
1202 //=============================================================================
1203 // 87S_PCIE :: RADIOCFG.TXT
1204 //=============================================================================
1207 // Page1 : reg16-reg30
1208 RF_WriteReg(dev, 0x00, 0x013f); mdelay(1); // switch to page1
1209 u4bRF23= RF_ReadReg(dev, 0x08); mdelay(1);
1210 u4bRF24= RF_ReadReg(dev, 0x09); mdelay(1);
1212 if (u4bRF23==0x818 && u4bRF24==0x70C && priv->card_8185 == VERSION_8187S_C)
1213 priv->card_8185 = VERSION_8187S_D;
1215 // Page0 : reg0-reg15
1217 // RF_WriteReg(dev, 0x00, 0x003f); mdelay(1);//1
1218 RF_WriteReg(dev, 0x00, 0x009f); mdelay(1);// 1
1220 RF_WriteReg(dev, 0x01, 0x06e0); mdelay(1);
1222 // RF_WriteReg(dev, 0x02, 0x004c); mdelay(1);//2
1223 RF_WriteReg(dev, 0x02, 0x004d); mdelay(1);// 2
1225 // RF_WriteReg(dev, 0x03, 0x0000); mdelay(1);//3
1226 RF_WriteReg(dev, 0x03, 0x07f1); mdelay(1);// 3
1228 RF_WriteReg(dev, 0x04, 0x0975); mdelay(1);
1229 RF_WriteReg(dev, 0x05, 0x0c72); mdelay(1);
1230 RF_WriteReg(dev, 0x06, 0x0ae6); mdelay(1);
1231 RF_WriteReg(dev, 0x07, 0x00ca); mdelay(1);
1232 RF_WriteReg(dev, 0x08, 0x0e1c); mdelay(1);
1233 RF_WriteReg(dev, 0x09, 0x02f0); mdelay(1);
1234 RF_WriteReg(dev, 0x0a, 0x09d0); mdelay(1);
1235 RF_WriteReg(dev, 0x0b, 0x01ba); mdelay(1);
1236 RF_WriteReg(dev, 0x0c, 0x0640); mdelay(1);
1237 RF_WriteReg(dev, 0x0d, 0x08df); mdelay(1);
1238 RF_WriteReg(dev, 0x0e, 0x0020); mdelay(1);
1239 RF_WriteReg(dev, 0x0f, 0x0990); mdelay(1);
1242 // Page1 : reg16-reg30
1243 RF_WriteReg(dev, 0x00, 0x013f); mdelay(1);
1245 RF_WriteReg(dev, 0x03, 0x0806); mdelay(1);
1247 if(priv->card_8185 < VERSION_8187S_C)
1249 RF_WriteReg(dev, 0x04, 0x03f7); mdelay(1);
1250 RF_WriteReg(dev, 0x05, 0x05ab); mdelay(1);
1251 RF_WriteReg(dev, 0x06, 0x00c1); mdelay(1);
1255 RF_WriteReg(dev, 0x04, 0x03a7); mdelay(1);
1256 RF_WriteReg(dev, 0x05, 0x059b); mdelay(1);
1257 RF_WriteReg(dev, 0x06, 0x0081); mdelay(1);
1261 RF_WriteReg(dev, 0x07, 0x01A0); mdelay(1);
1262 // Don't write RF23/RF24 to make a difference between 87S C cut and D cut. asked by SD3 stevenl.
1263 // RF_WriteReg(dev, 0x08, 0x0597); mdelay(1);
1264 // RF_WriteReg(dev, 0x09, 0x050a); mdelay(1);
1265 RF_WriteReg(dev, 0x0a, 0x0001); mdelay(1);
1266 RF_WriteReg(dev, 0x0b, 0x0418); mdelay(1);
1268 if(priv->card_8185 == VERSION_8187S_D)
1270 RF_WriteReg(dev, 0x0c, 0x0fbe); mdelay(1);
1271 RF_WriteReg(dev, 0x0d, 0x0008); mdelay(1);
1272 RF_WriteReg(dev, 0x0e, 0x0807); mdelay(1); // RX LO buffer
1276 RF_WriteReg(dev, 0x0c, 0x0fbe); mdelay(1);
1277 RF_WriteReg(dev, 0x0d, 0x0008); mdelay(1);
1278 RF_WriteReg(dev, 0x0e, 0x0806); mdelay(1); // RX LO buffer
1281 RF_WriteReg(dev, 0x0f, 0x0acc); mdelay(1);
1283 // RF_WriteReg(dev, 0x00, 0x017f); mdelay(1);//6
1284 RF_WriteReg(dev, 0x00, 0x01d7); mdelay(1);// 6
1286 RF_WriteReg(dev, 0x03, 0x0e00); mdelay(1);
1287 RF_WriteReg(dev, 0x04, 0x0e50); mdelay(1);
1290 RF_WriteReg(dev, 0x01, i); mdelay(1);
1291 RF_WriteReg(dev, 0x02, ZEBRA_RF_RX_GAIN_TABLE[i]); mdelay(1);
1292 //DbgPrint("RF - 0x%x = 0x%x", i, ZEBRA_RF_RX_GAIN_TABLE[i]);
1295 RF_WriteReg(dev, 0x05, 0x0203); mdelay(1); /// 203, 343
1296 //RF_WriteReg(dev, 0x06, 0x0300); mdelay(1); // 400
1297 RF_WriteReg(dev, 0x06, 0x0200); mdelay(1); // 400
1299 RF_WriteReg(dev, 0x00, 0x0137); mdelay(1); // switch to reg16-reg30, and HSSI disable 137
1300 mdelay(10); // Deay 10 ms. //0xfd
1302 // RF_WriteReg(dev, 0x0c, 0x09be); mdelay(1); // 7
1303 //RF_WriteReg(dev, 0x0c, 0x07be); mdelay(1);
1304 //mdelay(10); // Deay 10 ms. //0xfd
1306 RF_WriteReg(dev, 0x0d, 0x0008); mdelay(1); // Z4 synthesizer loop filter setting, 392
1307 mdelay(10); // Deay 10 ms. //0xfd
1309 RF_WriteReg(dev, 0x00, 0x0037); mdelay(1); // switch to reg0-reg15, and HSSI disable
1310 mdelay(10); // Deay 10 ms. //0xfd
1312 RF_WriteReg(dev, 0x04, 0x0160); mdelay(1); // CBC on, Tx Rx disable, High gain
1313 mdelay(10); // Deay 10 ms. //0xfd
1315 RF_WriteReg(dev, 0x07, 0x0080); mdelay(1); // Z4 setted channel 1
1316 mdelay(10); // Deay 10 ms. //0xfd
1318 RF_WriteReg(dev, 0x02, 0x088D); mdelay(1); // LC calibration
1319 mdelay(200); // Deay 200 ms. //0xfd
1320 mdelay(10); // Deay 10 ms. //0xfd
1321 mdelay(10); // Deay 10 ms. //0xfd
1323 RF_WriteReg(dev, 0x00, 0x0137); mdelay(1); // switch to reg16-reg30 137, and HSSI disable 137
1324 mdelay(10); // Deay 10 ms. //0xfd
1326 RF_WriteReg(dev, 0x07, 0x0000); mdelay(1);
1327 RF_WriteReg(dev, 0x07, 0x0180); mdelay(1);
1328 RF_WriteReg(dev, 0x07, 0x0220); mdelay(1);
1329 RF_WriteReg(dev, 0x07, 0x03E0); mdelay(1);
1331 // DAC calibration off 20070702
1332 RF_WriteReg(dev, 0x06, 0x00c1); mdelay(1);
1333 RF_WriteReg(dev, 0x0a, 0x0001); mdelay(1);
1335 // For crystal calibration, added by Roger, 2007.12.11.
1336 if( priv->bXtalCalibration ) // reg 30.
1337 { // enable crystal calibration.
1338 // RF Reg[30], (1)Xin:[12:9], Xout:[8:5], addr[4:0].
1339 // (2)PA Pwr delay timer[15:14], default: 2.4us, set BIT15=0
1340 // (3)RF signal on/off when calibration[13], default: on, set BIT13=0.
1341 // So we should minus 4 BITs offset.
1342 RF_WriteReg(dev, 0x0f, (priv->XtalCal_Xin<<5)|(priv->XtalCal_Xout<<1)|BIT11|BIT9); mdelay(1);
1343 printk("ZEBRA_Config_85BASIC_HardCode(): (%02x)\n",
1344 (priv->XtalCal_Xin<<5) | (priv->XtalCal_Xout<<1) | BIT11| BIT9);
1347 { // using default value. Xin=6, Xout=6.
1348 RF_WriteReg(dev, 0x0f, 0x0acc); mdelay(1);
1351 // RF_WriteReg(dev, 0x0f, 0x0acc); mdelay(1); //-by amy 080312
1353 RF_WriteReg(dev, 0x00, 0x00bf); mdelay(1); // switch to reg0-reg15, and HSSI enable
1354 // RF_WriteReg(dev, 0x0d, 0x009f); mdelay(1); // Rx BB start calibration, 00c//-edward
1355 RF_WriteReg(dev, 0x0d, 0x08df); mdelay(1); // Rx BB start calibration, 00c//+edward
1356 RF_WriteReg(dev, 0x02, 0x004d); mdelay(1); // temperature meter off
1357 RF_WriteReg(dev, 0x04, 0x0975); mdelay(1); // Rx mode
1358 mdelay(10); // Deay 10 ms. //0xfe
1359 mdelay(10); // Deay 10 ms. //0xfe
1360 mdelay(10); // Deay 10 ms. //0xfe
1361 RF_WriteReg(dev, 0x00, 0x0197); mdelay(1); // Rx mode//+edward
1362 RF_WriteReg(dev, 0x05, 0x05ab); mdelay(1); // Rx mode//+edward
1363 RF_WriteReg(dev, 0x00, 0x009f); mdelay(1); // Rx mode//+edward
1366 RF_WriteReg(dev, 0x00, 0x0197); mdelay(1);
1367 RF_WriteReg(dev, 0x05, 0x05ab); mdelay(1);
1368 RF_WriteReg(dev, 0x00, 0x009F); mdelay(1);
1370 RF_WriteReg(dev, 0x01, 0x0000); mdelay(1); // Rx mode//+edward
1371 RF_WriteReg(dev, 0x02, 0x0000); mdelay(1); // Rx mode//+edward
1372 //power save parameters.
1373 u1b24E = read_nic_byte(dev, 0x24E);
1374 write_nic_byte(dev, 0x24E, (u1b24E & (~(BIT5|BIT6))));
1376 //=============================================================================
1378 //=============================================================================
1380 //=============================================================================
1382 /* [POWER SAVE] Power Saving Parameters by jong. 2007-11-27
1383 CCK reg0x00[7]=1'b1 :power saving for TX (default)
1384 CCK reg0x00[6]=1'b1: power saving for RX (default)
1385 CCK reg0x06[4]=1'b1: turn off channel estimation related circuits if not doing channel estimation.
1386 CCK reg0x06[3]=1'b1: turn off unused circuits before cca = 1
1387 CCK reg0x06[2]=1'b1: turn off cck's circuit if macrst =0
1390 write_nic_dword(dev, PHY_ADR, 0x0100c880);
1391 write_nic_dword(dev, PHY_ADR, 0x01001c86);
1392 write_nic_dword(dev, PHY_ADR, 0x01007890);
1393 write_nic_dword(dev, PHY_ADR, 0x0100d0ae);
1394 write_nic_dword(dev, PHY_ADR, 0x010006af);
1395 write_nic_dword(dev, PHY_ADR, 0x01004681);
1397 write_phy_cck(dev,0x00,0xc8);
1398 write_phy_cck(dev,0x06,0x1c);
1399 write_phy_cck(dev,0x10,0x78);
1400 write_phy_cck(dev,0x2e,0xd0);
1401 write_phy_cck(dev,0x2f,0x06);
1402 write_phy_cck(dev,0x01,0x46);
1405 write_nic_byte(dev, CCK_TXAGC, 0x10);
1406 write_nic_byte(dev, OFDM_TXAGC, 0x1B);
1407 write_nic_byte(dev, ANTSEL, 0x03);
1411 //=============================================================================
1413 //=============================================================================
1415 // PlatformIOWrite4Byte( dev, PhyAddr, 0x00001280); // Annie, 2006-05-05
1416 write_phy_ofdm(dev, 0x00, 0x12);
1417 //WriteBBPortUchar(dev, 0x00001280);
1419 for (i=0; i<128; i++)
1421 //DbgPrint("AGC - [%x+1] = 0x%x\n", i, ZEBRA_AGC[i+1]);
1423 data = ZEBRA_AGC[i+1];
1425 data = data | 0x0000008F;
1427 addr = i + 0x80; //enable writing AGC table
1429 addr = addr | 0x0000008E;
1431 WriteBBPortUchar(dev, data);
1432 WriteBBPortUchar(dev, addr);
1433 WriteBBPortUchar(dev, 0x0000008E);
1436 PlatformIOWrite4Byte( dev, PhyAddr, 0x00001080); // Annie, 2006-05-05
1437 //WriteBBPortUchar(dev, 0x00001080);
1439 //=============================================================================
1441 //=============================================================================
1443 //=============================================================================
1448 u4bRegValue=OFDM_CONFIG[i];
1450 //DbgPrint("OFDM - 0x%x = 0x%x\n", u4bRegOffset, u4bRegValue);
1452 WriteBBPortUchar(dev,
1454 (u4bRegOffset & 0x7f) |
1455 ((u4bRegValue & 0xff) << 8)));
1458 //=============================================================================
1459 //by amy for antenna
1460 //=============================================================================
1462 // Config Sw/Hw Combinational Antenna Diversity. Added by Roger, 2008.02.26.
1463 SetAntennaConfig87SE(dev, priv->bDefaultAntenna1, priv->bSwAntennaDiverity);
1466 // Config Sw/Hw Antenna Diversity
1467 if( priv->bSwAntennaDiverity ) // Use SW+Hw Antenna Diversity
1469 if( priv->bDefaultAntenna1 == true ) // aux antenna
1471 // Mac register, aux antenna
1472 write_nic_byte(dev, ANTSEL, 0x00);
1473 // Config CCK RX antenna.
1474 write_phy_cck(dev, 0x11, 0xbb); // Reg11 : bb
1475 write_phy_cck(dev, 0x0c, 0x09); // Reg0c : 09
1476 write_phy_cck(dev, 0x01, 0xc7); // Reg01 : c7
1477 // Config OFDM RX antenna.
1478 write_phy_ofdm(dev, 0x0d, 0x54); // Reg0d : 54
1479 write_phy_ofdm(dev, 0x18, 0xb2); // Reg18 : b2
1481 else // main antenna
1483 // Mac register, main antenna
1484 write_nic_byte(dev, ANTSEL, 0x03);
1486 // Config CCK RX antenna.
1487 write_phy_cck(dev, 0x11, 0x9b); // Reg11 : 9b
1488 write_phy_cck(dev, 0x0c, 0x09); // Reg0c : 09
1489 write_phy_cck(dev, 0x01, 0xc7); // Reg01 : c7
1490 // Config OFDM RX antenna.
1491 write_phy_ofdm(dev, 0x0d, 0x5c); // Reg0d : 5c
1492 write_phy_ofdm(dev, 0x18, 0xb2); // Reg18 : b2
1495 else // Disable Antenna Diversity
1497 if( priv->bDefaultAntenna1 == true ) // aux Antenna
1499 // Mac register, aux antenna
1500 write_nic_byte(dev, ANTSEL, 0x00);
1501 // Config CCK RX antenna.
1502 write_phy_cck(dev, 0x11, 0xbb); // Reg11 : bb
1503 write_phy_cck(dev, 0x0c, 0x09); // Reg0c : 09
1504 write_phy_cck(dev, 0x01, 0x47); // Reg01 : 47
1505 // Config OFDM RX antenna.
1506 write_phy_ofdm(dev, 0x0d, 0x54); // Reg0d : 54
1507 write_phy_ofdm(dev, 0x18, 0x32); // Reg18 : 32
1509 else // main Antenna
1511 // Mac register, main antenna
1512 write_nic_byte(dev, ANTSEL, 0x03);
1513 // Config CCK RX antenna.
1514 write_phy_cck(dev, 0x11, 0x9b); // Reg11 : 9b
1515 write_phy_cck(dev, 0x0c, 0x09); // Reg0c : 09
1516 write_phy_cck(dev, 0x01, 0x47); // Reg01 : 47
1517 // Config OFDM RX antenna.
1518 write_phy_ofdm(dev, 0x0d, 0x5c); // Reg0d : 5c
1519 write_phy_ofdm(dev, 0x18, 0x32); // Reg18 : 32
1523 //by amy for antenna
1529 struct net_device *dev
1532 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1533 //unsigned char* IGTable;
1534 //u8 DIG_CurrentInitialGain = 4;
1535 //unsigned char u1Tmp;
1538 if(priv->eRFPowerState != eRfOn)
1540 //Don't access BB/RF under disable PLL situation.
1541 //RT_TRACE(COMP_DIG, DBG_LOUD, ("UpdateInitialGain - pHalData->eRFPowerState!=eRfOn\n"));
1542 // Back to the original state
1543 priv->InitialGain= priv->InitialGainBackUp;
1547 switch(priv->rf_chip)
1551 // Dynamic set initial gain, by shien chang, 2006.07.14
1552 switch(priv->InitialGain)
1555 DMESG("RTL8185B + 8225 Initial Gain State 1: -82 dBm \n");
1556 write_nic_dword(dev, PhyAddr, 0x2697); mdelay(1);
1557 write_nic_dword(dev, PhyAddr, 0x86a4); mdelay(1);
1558 write_nic_dword(dev, PhyAddr, 0xfa85); mdelay(1);
1562 DMESG("RTL8185B + 8225 Initial Gain State 2: -82 dBm \n");
1563 write_nic_dword(dev, PhyAddr, 0x2697); mdelay(1);
1564 write_nic_dword(dev, PhyAddr, 0x86a4); mdelay(1);
1565 write_nic_dword(dev, PhyAddr, 0xfb85); mdelay(1);
1569 DMESG("RTL8185B + 8225 Initial Gain State 3: -82 dBm \n");
1570 write_nic_dword(dev, PhyAddr, 0x2697); mdelay(1);
1571 write_nic_dword(dev, PhyAddr, 0x96a4); mdelay(1);
1572 write_nic_dword(dev, PhyAddr, 0xfb85); mdelay(1);
1576 DMESG("RTL8185B + 8225 Initial Gain State 4: -78 dBm \n");
1577 write_nic_dword(dev, PhyAddr, 0x2697); mdelay(1);
1578 write_nic_dword(dev, PhyAddr, 0xa6a4); mdelay(1);
1579 write_nic_dword(dev, PhyAddr, 0xfb85); mdelay(1);
1583 DMESG("RTL8185B + 8225 Initial Gain State 5: -74 dBm \n");
1584 write_nic_dword(dev, PhyAddr, 0x3697); mdelay(1);
1585 write_nic_dword(dev, PhyAddr, 0xa6a4); mdelay(1);
1586 write_nic_dword(dev, PhyAddr, 0xfb85); mdelay(1);
1590 DMESG("RTL8185B + 8225 Initial Gain State 6: -70 dBm \n");
1591 write_nic_dword(dev, PhyAddr, 0x4697); mdelay(1);
1592 write_nic_dword(dev, PhyAddr, 0xa6a4); mdelay(1);
1593 write_nic_dword(dev, PhyAddr, 0xfb85); mdelay(1);
1597 DMESG("RTL8185B + 8225 Initial Gain State 7: -66 dBm \n");
1598 write_nic_dword(dev, PhyAddr, 0x5697); mdelay(1);
1599 write_nic_dword(dev, PhyAddr, 0xa6a4); mdelay(1);
1600 write_nic_dword(dev, PhyAddr, 0xfb85); mdelay(1);
1604 DMESG("RTL8185B + 8225 Initial Gain State 1: -82 dBm (default)\n");
1605 write_nic_dword(dev, PhyAddr, 0x2697); mdelay(1);
1606 write_nic_dword(dev, PhyAddr, 0x86a4); mdelay(1);
1607 write_nic_dword(dev, PhyAddr, 0xfa85); mdelay(1);
1613 // Dynamic set initial gain, follow 87B
1614 switch(priv->InitialGain)
1617 //DMESG("RTL8187 + 8225 Initial Gain State 1: -82 dBm \n");
1618 write_phy_ofdm(dev, 0x17, 0x26); mdelay(1);
1619 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
1620 write_phy_ofdm(dev, 0x05, 0xfa); mdelay(1);
1624 //DMESG("RTL8187 + 8225 Initial Gain State 2: -82 dBm \n");
1625 write_phy_ofdm(dev, 0x17, 0x36); mdelay(1);
1626 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
1627 write_phy_ofdm(dev, 0x05, 0xfa); mdelay(1);
1631 //DMESG("RTL8187 + 8225 Initial Gain State 3: -82 dBm \n");
1632 write_phy_ofdm(dev, 0x17, 0x36); mdelay(1);
1633 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
1634 write_phy_ofdm(dev, 0x05, 0xfb); mdelay(1);
1638 //DMESG("RTL8187 + 8225 Initial Gain State 4: -78 dBm \n");
1639 write_phy_ofdm(dev, 0x17, 0x46); mdelay(1);
1640 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
1641 write_phy_ofdm(dev, 0x05, 0xfb); mdelay(1);
1645 //DMESG("RTL8187 + 8225 Initial Gain State 5: -74 dBm \n");
1646 write_phy_ofdm(dev, 0x17, 0x46); mdelay(1);
1647 write_phy_ofdm(dev, 0x24, 0x96); mdelay(1);
1648 write_phy_ofdm(dev, 0x05, 0xfb); mdelay(1);
1652 //DMESG ("RTL8187 + 8225 Initial Gain State 6: -70 dBm \n");
1653 write_phy_ofdm(dev, 0x17, 0x56); mdelay(1);
1654 write_phy_ofdm(dev, 0x24, 0x96); mdelay(1);
1655 write_phy_ofdm(dev, 0x05, 0xfc); mdelay(1);
1659 //DMESG("RTL8187 + 8225 Initial Gain State 7: -66 dBm \n");
1660 write_phy_ofdm(dev, 0x17, 0x56); mdelay(1);
1661 write_phy_ofdm(dev, 0x24, 0xa6); mdelay(1);
1662 write_phy_ofdm(dev, 0x05, 0xfc); mdelay(1);
1666 //DMESG("RTL8187 + 8225 Initial Gain State 8:\n");
1667 write_phy_ofdm(dev, 0x17, 0x66); mdelay(1);
1668 write_phy_ofdm(dev, 0x24, 0xb6); mdelay(1);
1669 write_phy_ofdm(dev, 0x05, 0xfc); mdelay(1);
1674 //DMESG("RTL8187 + 8225 Initial Gain State 1: -82 dBm (default)\n");
1675 write_phy_ofdm(dev, 0x17, 0x26); mdelay(1);
1676 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
1677 write_phy_ofdm(dev, 0x05, 0xfa); mdelay(1);
1684 DMESG("UpdateInitialGain(): unknown RFChipID: %#X\n", priv->rf_chip);
1690 // Tx Power tracking mechanism routine on 87SE.
1691 // Created by Roger, 2007.12.11.
1694 InitTxPwrTracking87SE(
1695 struct net_device *dev
1698 //struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1701 u4bRfReg = RF_ReadReg(dev, 0x02);
1703 // Enable Thermal meter indication.
1704 //printk("InitTxPwrTracking87SE(): Enable thermal meter indication, Write RF[0x02] = %#x", u4bRfReg|PWR_METER_EN);
1705 RF_WriteReg(dev, 0x02, u4bRfReg|PWR_METER_EN); mdelay(1);
1710 struct net_device *dev
1713 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1714 write_nic_dword(dev, RCR, priv->ReceiveConfig);
1715 priv->RFProgType = read_nic_byte(dev, CONFIG4) & 0x03;
1717 switch(priv->rf_chip)
1721 ZEBRA_Config_85BASIC_HardCode( dev);
1725 // Set default initial gain state to 4, approved by SD3 DZ, by Bruce, 2007-06-06.
1726 if(priv->bDigMechanism)
1728 if(priv->InitialGain == 0)
1729 priv->InitialGain = 4;
1730 //printk("PhyConfig8185(): DIG is enabled, set default initial gain index to %d\n", priv->InitialGain);
1734 // Enable thermal meter indication to implement TxPower tracking on 87SE.
1735 // We initialize thermal meter here to avoid unsuccessful configuration.
1736 // Added by Roger, 2007.12.11.
1738 if(priv->bTxPowerTrack)
1739 InitTxPwrTracking87SE(dev);
1742 priv->InitialGainBackUp= priv->InitialGain;
1743 UpdateInitialGain(dev);
1753 struct net_device *dev
1756 //RTL8185_TODO: Determine Retrylimit, TxAGC, AutoRateFallback control.
1757 // u8 bUNIVERSAL_CONTROL_RL = 1;
1758 u8 bUNIVERSAL_CONTROL_RL = 0;
1760 u8 bUNIVERSAL_CONTROL_AGC = 1;
1761 u8 bUNIVERSAL_CONTROL_ANT = 1;
1762 u8 bAUTO_RATE_FALLBACK_CTL = 1;
1764 //struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1765 //struct ieee80211_device *ieee = priv->ieee80211;
1766 //if(IS_WIRELESS_MODE_A(dev) || IS_WIRELESS_MODE_G(dev))
1767 //{by amy 080312 if((ieee->mode == IEEE_G)||(ieee->mode == IEEE_A))
1769 // write_nic_word(dev, BRSR, 0xffff);
1773 // write_nic_word(dev, BRSR, 0x000f);
1776 write_nic_word(dev, BRSR, 0x0fff);
1778 val8 = read_nic_byte(dev, CW_CONF);
1780 if(bUNIVERSAL_CONTROL_RL)
1785 write_nic_byte(dev, CW_CONF, val8);
1788 val8 = read_nic_byte(dev, TXAGC_CTL);
1789 if(bUNIVERSAL_CONTROL_AGC)
1791 write_nic_byte(dev, CCK_TXAGC, 128);
1792 write_nic_byte(dev, OFDM_TXAGC, 128);
1797 val8 = val8 | 0x01 ;
1801 write_nic_byte(dev, TXAGC_CTL, val8);
1803 // Tx Antenna including Feedback control
1804 val8 = read_nic_byte(dev, TXAGC_CTL );
1806 if(bUNIVERSAL_CONTROL_ANT)
1808 write_nic_byte(dev, ANTSEL, 0x00);
1813 val8 = val8 & (val8|0x02); //xiong-2006-11-15
1816 write_nic_byte(dev, TXAGC_CTL, val8);
1818 // Auto Rate fallback control
1819 val8 = read_nic_byte(dev, RATE_FALLBACK);
1821 if( bAUTO_RATE_FALLBACK_CTL )
1823 val8 |= RATE_FALLBACK_CTL_ENABLE | RATE_FALLBACK_CTL_AUTO_STEP1;
1825 // <RJ_TODO_8185B> We shall set up the ARFR according to user's setting.
1826 //write_nic_word(dev, ARFR, 0x0fff); // set 1M ~ 54M
1829 PlatformIOWrite2Byte(dev, ARFR, 0x0fff); // set 1M ~ 54M
1831 // Aadded by Roger, 2007.11.15.
1832 PlatformIOWrite2Byte(dev, ARFR, 0x0fff); //set 1M ~ 54Mbps.
1838 write_nic_byte(dev, RATE_FALLBACK, val8);
1844 MacConfig_85BASIC_HardCode(
1845 struct net_device *dev)
1847 //============================================================================
1849 //============================================================================
1852 u32 u4bRegOffset, u4bRegValue,u4bPageIndex = 0;
1855 nLinesRead=sizeof(MAC_REG_TABLE)/2;
1857 for(i = 0; i < nLinesRead; i++) //nLinesRead=101
1859 u4bRegOffset=MAC_REG_TABLE[i][0];
1860 u4bRegValue=MAC_REG_TABLE[i][1];
1862 if(u4bRegOffset == 0x5e)
1864 u4bPageIndex = u4bRegValue;
1868 u4bRegOffset |= (u4bPageIndex << 8);
1870 //DbgPrint("MAC - 0x%x = 0x%x\n", u4bRegOffset, u4bRegValue);
1871 write_nic_byte(dev, u4bRegOffset, (u8)u4bRegValue);
1873 //============================================================================
1880 struct net_device *dev)
1884 MacConfig_85BASIC_HardCode(dev);
1886 //============================================================================
1888 // Follow TID_AC_MAP of WMac.
1889 write_nic_word(dev, TID_AC_MAP, 0xfa50);
1891 // Interrupt Migration, Jong suggested we use set 0x0000 first, 2005.12.14, by rcnjko.
1892 write_nic_word(dev, IntMig, 0x0000);
1894 // Prevent TPC to cause CRC error. Added by Annie, 2006-06-10.
1895 PlatformIOWrite4Byte(dev, 0x1F0, 0x00000000);
1896 PlatformIOWrite4Byte(dev, 0x1F4, 0x00000000);
1897 PlatformIOWrite1Byte(dev, 0x1F8, 0x00);
1899 // Asked for by SD3 CM Lin, 2006.06.27, by rcnjko.
1900 //PlatformIOWrite4Byte(dev, RFTiming, 0x00004001);
1903 write_nic_dword(dev, RFTiming, 0x00004001);
1905 // power save parameter based on "87SE power save parameters 20071127.doc", as follow.
1907 //Enable DA10 TX power saving
1908 u1DA = read_nic_byte(dev, PHYPR);
1909 write_nic_byte(dev, PHYPR, (u1DA | BIT2) );
1912 write_nic_word(dev, 0x360, 0x1000);
1913 write_nic_word(dev, 0x362, 0x1000);
1916 write_nic_word(dev, 0x370, 0x0560);
1917 write_nic_word(dev, 0x372, 0x0560);
1918 write_nic_word(dev, 0x374, 0x0DA4);
1919 write_nic_word(dev, 0x376, 0x0DA4);
1920 write_nic_word(dev, 0x378, 0x0560);
1921 write_nic_word(dev, 0x37A, 0x0560);
1922 write_nic_word(dev, 0x37C, 0x00EC);
1923 // write_nic_word(dev, 0x37E, 0x00FE);//-edward
1924 write_nic_word(dev, 0x37E, 0x00EC);//+edward
1925 write_nic_byte(dev, 0x24E,0x01);
1934 GetSupportedWirelessMode8185(
1935 struct net_device *dev
1938 u8 btSupportedWirelessMode = 0;
1939 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1941 switch(priv->rf_chip)
1945 btSupportedWirelessMode = (WIRELESS_MODE_B | WIRELESS_MODE_G);
1948 btSupportedWirelessMode = WIRELESS_MODE_B;
1952 return btSupportedWirelessMode;
1956 ActUpdateChannelAccessSetting(
1957 struct net_device *dev,
1958 WIRELESS_MODE WirelessMode,
1959 PCHANNEL_ACCESS_SETTING ChnlAccessSetting
1962 struct r8180_priv *priv = ieee80211_priv(dev);
1963 struct ieee80211_device *ieee = priv->ieee80211;
1966 //PSTA_QOS pStaQos = Adapter->MgntInfo.pStaQos;
1967 u8 bFollowLegacySetting = 0;
1972 // TODO: We still don't know how to set up these registers, just follow WMAC to
1973 // verify 8185B FPAG.
1976 // Jong said CWmin/CWmax register are not functional in 8185B,
1977 // so we shall fill channel access realted register into AC parameter registers,
1980 ChnlAccessSetting->SIFS_Timer = 0x22; // Suggested by Jong, 2005.12.08.
1981 ChnlAccessSetting->DIFS_Timer = 0x1C; // 2006.06.02, by rcnjko.
1982 ChnlAccessSetting->SlotTimeTimer = 9; // 2006.06.02, by rcnjko.
1983 ChnlAccessSetting->EIFS_Timer = 0x5B; // Suggested by wcchu, it is the default value of EIFS register, 2005.12.08.
1984 ChnlAccessSetting->CWminIndex = 3; // 2006.06.02, by rcnjko.
1985 ChnlAccessSetting->CWmaxIndex = 7; // 2006.06.02, by rcnjko.
1987 write_nic_byte(dev, SIFS, ChnlAccessSetting->SIFS_Timer);
1988 //Adapter->HalFunc.SetHwRegHandler( Adapter, HW_VAR_SLOT_TIME, &ChnlAccessSetting->SlotTimeTimer ); // Rewrited from directly use PlatformEFIOWrite1Byte(), by Annie, 2006-03-29.
1989 write_nic_byte(dev, SLOT, ChnlAccessSetting->SlotTimeTimer); // Rewrited from directly use PlatformEFIOWrite1Byte(), by Annie, 2006-03-29.
1991 u1bAIFS = aSifsTime + (2 * ChnlAccessSetting->SlotTimeTimer );
1993 //write_nic_byte(dev, AC_VO_PARAM, u1bAIFS);
1994 //write_nic_byte(dev, AC_VI_PARAM, u1bAIFS);
1995 //write_nic_byte(dev, AC_BE_PARAM, u1bAIFS);
1996 //write_nic_byte(dev, AC_BK_PARAM, u1bAIFS);
1998 write_nic_byte(dev, EIFS, ChnlAccessSetting->EIFS_Timer);
2000 write_nic_byte(dev, AckTimeOutReg, 0x5B); // <RJ_EXPR_QOS> Suggested by wcchu, it is the default value of EIFS register, 2005.12.08.
2003 // <RJ_TODO_NOW_8185B> Update ECWmin/ECWmax, AIFS, TXOP Limit of each AC to the value defined by SPEC.
2004 if( pStaQos->CurrentQosMode > QOS_DISABLE )
2006 if(pStaQos->QBssWirelessMode == WirelessMode)
2008 // Follow AC Parameters of the QBSS.
2009 for(eACI = 0; eACI < AC_MAX; eACI++)
2011 Adapter->HalFunc.SetHwRegHandler(Adapter, HW_VAR_AC_PARAM, (pu1Byte)(&(pStaQos->WMMParamEle.AcParam[eACI])) );
2016 // Follow Default WMM AC Parameters.
2017 bFollowLegacySetting = 1;
2023 bFollowLegacySetting = 1;
2027 // this setting is copied from rtl8187B. xiong-2006-11-13
2028 if(bFollowLegacySetting)
2033 // Follow 802.11 seeting to AC parameter, all AC shall use the same parameter.
2034 // 2005.12.01, by rcnjko.
2036 AcParam.longData = 0;
2037 AcParam.f.AciAifsn.f.AIFSN = 2; // Follow 802.11 DIFS.
2038 AcParam.f.AciAifsn.f.ACM = 0;
2039 AcParam.f.Ecw.f.ECWmin = ChnlAccessSetting->CWminIndex; // Follow 802.11 CWmin.
2040 AcParam.f.Ecw.f.ECWmax = ChnlAccessSetting->CWmaxIndex; // Follow 802.11 CWmax.
2041 AcParam.f.TXOPLimit = 0;
2043 //lzm reserved 080826
2045 // For turbo mode setting. port from 87B by Isaiah 2008-08-01
2046 if( ieee->current_network.Turbo_Enable == 1 )
2047 AcParam.f.TXOPLimit = 0x01FF;
2048 // For 87SE with Intel 4965 Ad-Hoc mode have poor throughput (19MB)
2049 if (ieee->iw_mode == IW_MODE_ADHOC)
2050 AcParam.f.TXOPLimit = 0x0020;
2053 for(eACI = 0; eACI < AC_MAX; eACI++)
2055 AcParam.f.AciAifsn.f.ACI = (u8)eACI;
2057 PAC_PARAM pAcParam = (PAC_PARAM)(&AcParam);
2062 // Retrive paramters to udpate.
2063 eACI = pAcParam->f.AciAifsn.f.ACI;
2064 u1bAIFS = pAcParam->f.AciAifsn.f.AIFSN * ChnlAccessSetting->SlotTimeTimer + aSifsTime;
2065 u4bAcParam = ( (((u32)(pAcParam->f.TXOPLimit)) << AC_PARAM_TXOP_LIMIT_OFFSET) |
2066 (((u32)(pAcParam->f.Ecw.f.ECWmax)) << AC_PARAM_ECW_MAX_OFFSET) |
2067 (((u32)(pAcParam->f.Ecw.f.ECWmin)) << AC_PARAM_ECW_MIN_OFFSET) |
2068 (((u32)u1bAIFS) << AC_PARAM_AIFS_OFFSET));
2073 //write_nic_dword(dev, AC_BK_PARAM, u4bAcParam);
2077 //write_nic_dword(dev, AC_BE_PARAM, u4bAcParam);
2081 //write_nic_dword(dev, AC_VI_PARAM, u4bAcParam);
2085 //write_nic_dword(dev, AC_VO_PARAM, u4bAcParam);
2089 DMESGW( "SetHwReg8185(): invalid ACI: %d !\n", eACI);
2094 // If it is set, immediately set ACM control bit to downgrading AC for passing WMM testplan. Annie, 2005-12-13.
2095 //write_nic_byte(dev, ACM_CONTROL, pAcParam->f.AciAifsn);
2097 PACI_AIFSN pAciAifsn = (PACI_AIFSN)(&pAcParam->f.AciAifsn);
2098 AC_CODING eACI = pAciAifsn->f.ACI;
2101 //for 8187B AsynIORead issue
2103 u8 AcmCtrl = pHalData->AcmControl;
2107 if( pAciAifsn->f.ACM )
2112 AcmCtrl |= (BEQ_ACM_EN|BEQ_ACM_CTL|ACM_HW_EN); // or 0x21
2116 AcmCtrl |= (VIQ_ACM_EN|VIQ_ACM_CTL|ACM_HW_EN); // or 0x42
2120 AcmCtrl |= (VOQ_ACM_EN|VOQ_ACM_CTL|ACM_HW_EN); // or 0x84
2124 DMESGW("SetHwReg8185(): [HW_VAR_ACM_CTRL] ACM set failed: eACI is %d\n", eACI );
2133 AcmCtrl &= ( (~BEQ_ACM_EN) & (~BEQ_ACM_CTL) & (~ACM_HW_EN) ); // and 0xDE
2137 AcmCtrl &= ( (~VIQ_ACM_EN) & (~VIQ_ACM_CTL) & (~ACM_HW_EN) ); // and 0xBD
2141 AcmCtrl &= ( (~VOQ_ACM_EN) & (~VOQ_ACM_CTL) & (~ACM_HW_EN) ); // and 0x7B
2149 //printk(KERN_WARNING "SetHwReg8185(): [HW_VAR_ACM_CTRL] Write 0x%X\n", AcmCtrl);
2152 pHalData->AcmControl = AcmCtrl;
2154 //write_nic_byte(dev, ACM_CONTROL, AcmCtrl);
2155 write_nic_byte(dev, ACM_CONTROL, 0);
2165 ActSetWirelessMode8185(
2166 struct net_device *dev,
2170 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2171 struct ieee80211_device *ieee = priv->ieee80211;
2172 //PMGNT_INFO pMgntInfo = &(Adapter->MgntInfo);
2173 u8 btSupportedWirelessMode = GetSupportedWirelessMode8185(dev);
2175 if( (btWirelessMode & btSupportedWirelessMode) == 0 )
2176 { // Don't switch to unsupported wireless mode, 2006.02.15, by rcnjko.
2177 DMESGW("ActSetWirelessMode8185(): WirelessMode(%d) is not supported (%d)!\n",
2178 btWirelessMode, btSupportedWirelessMode);
2182 // 1. Assign wireless mode to swtich if necessary.
2183 if (btWirelessMode == WIRELESS_MODE_AUTO)
2185 if((btSupportedWirelessMode & WIRELESS_MODE_A))
2187 btWirelessMode = WIRELESS_MODE_A;
2189 else if((btSupportedWirelessMode & WIRELESS_MODE_G))
2191 btWirelessMode = WIRELESS_MODE_G;
2193 else if((btSupportedWirelessMode & WIRELESS_MODE_B))
2195 btWirelessMode = WIRELESS_MODE_B;
2199 DMESGW("ActSetWirelessMode8185(): No valid wireless mode supported, btSupportedWirelessMode(%x)!!!\n",
2200 btSupportedWirelessMode);
2201 btWirelessMode = WIRELESS_MODE_B;
2206 // 2. Swtich band: RF or BB specific actions,
2207 // for example, refresh tables in omc8255, or change initial gain if necessary.
2208 switch(priv->rf_chip)
2213 // Nothing to do for Zebra to switch band.
2214 // Update current wireless mode if we swtich to specified band successfully.
2215 ieee->mode = (WIRELESS_MODE)btWirelessMode;
2220 DMESGW("ActSetWirelessMode8185(): unsupported RF: 0x%X !!!\n", priv->rf_chip);
2224 // 3. Change related setting.
2225 if( ieee->mode == WIRELESS_MODE_A ){
2226 DMESG("WIRELESS_MODE_A\n");
2228 else if( ieee->mode == WIRELESS_MODE_B ){
2229 DMESG("WIRELESS_MODE_B\n");
2231 else if( ieee->mode == WIRELESS_MODE_G ){
2232 DMESG("WIRELESS_MODE_G\n");
2235 ActUpdateChannelAccessSetting( dev, ieee->mode, &priv->ChannelAccessSetting);
2238 void rtl8185b_irq_enable(struct net_device *dev)
2240 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2242 priv->irq_enabled = 1;
2243 write_nic_dword(dev, IMR, priv->IntrMask);
2245 //by amy for power save
2247 DrvIFIndicateDisassociation(
2248 struct net_device *dev,
2252 //printk("==> DrvIFIndicateDisassociation()\n");
2254 // nothing is needed after disassociation request.
2256 //printk("<== DrvIFIndicateDisassociation()\n");
2260 struct net_device *dev
2263 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2266 //printk("XXXXXXXXXX MgntDisconnect IBSS\n");
2268 DrvIFIndicateDisassociation(dev, unspec_reason);
2270 // PlatformZeroMemory( pMgntInfo->Bssid, 6 );
2271 for(i=0;i<6;i++) priv->ieee80211->current_network.bssid[i] = 0x55;
2273 priv->ieee80211->state = IEEE80211_NOLINK;
2277 // Vista add a Adhoc profile, HW radio off untill OID_DOT11_RESET_REQUEST
2278 // Driver would set MSR=NO_LINK, then HW Radio ON, MgntQueue Stuck.
2279 // Because Bcn DMA isn't complete, mgnt queue would stuck until Bcn packet send.
2281 // Disable Beacon Queue Own bit, suggested by jong
2282 // Adapter->HalFunc.SetTxDescOWNHandler(Adapter, BEACON_QUEUE, 0, 0);
2283 ieee80211_stop_send_beacons(priv->ieee80211);
2285 priv->ieee80211->link_change(dev);
2286 notify_wx_assoc_event(priv->ieee80211);
2288 // Stop SW Beacon.Use hw beacon so do not need to do so.by amy
2290 if(pMgntInfo->bEnableSwBeaconTimer)
2292 // SwBeaconTimer will stop if pMgntInfo->mIbss==FALSE, see SwBeaconCallback() for details.
2293 // comment out by haich, 2007.10.01
2294 //#if DEV_BUS_TYPE==USB_INTERFACE
2295 PlatformCancelTimer( Adapter, &pMgntInfo->SwBeaconTimer);
2300 // MgntIndicateMediaStatus( Adapter, RT_MEDIA_DISCONNECT, GENERAL_INDICATE );
2304 MlmeDisassociateRequest(
2305 struct net_device *dev,
2310 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2313 SendDisassociation(priv->ieee80211, asSta, asRsn );
2315 if( memcmp(priv->ieee80211->current_network.bssid, asSta, 6 ) == 0 ){
2316 //ShuChen TODO: change media status.
2317 //ShuChen TODO: What to do when disassociate.
2318 DrvIFIndicateDisassociation(dev, unspec_reason);
2321 // pMgntInfo->AsocTimestamp = 0;
2322 for(i=0;i<6;i++) priv->ieee80211->current_network.bssid[i] = 0x22;
2323 // pMgntInfo->mBrates.Length = 0;
2324 // Adapter->HalFunc.SetHwRegHandler( Adapter, HW_VAR_BASIC_RATE, (pu1Byte)(&pMgntInfo->mBrates) );
2326 ieee80211_disassociate(priv->ieee80211);
2335 struct net_device *dev,
2339 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2342 // Commented out by rcnjko, 2005.01.27:
2343 // I move SecClearAllKeys() to MgntActSet_802_11_DISASSOCIATE().
2345 // //2004/09/15, kcwu, the key should be cleared, or the new handshaking will not success
2346 // SecClearAllKeys(Adapter);
2348 // In WPA WPA2 need to Clear all key ... because new key will set after new handshaking.
2350 if( pMgntInfo->SecurityInfo.AuthMode > RT_802_11AuthModeAutoSwitch ||
2351 (pMgntInfo->bAPSuportCCKM && pMgntInfo->bCCX8021xenable) ) // In CCKM mode will Clear key
2353 SecClearAllKeys(Adapter);
2354 RT_TRACE(COMP_SEC, DBG_LOUD,("======>CCKM clear key..."))
2357 // 2004.10.11, by rcnjko.
2358 //MlmeDisassociateRequest( Adapter, pMgntInfo->Bssid, disas_lv_ss );
2359 MlmeDisassociateRequest( dev, priv->ieee80211->current_network.bssid, asRsn );
2361 priv->ieee80211->state = IEEE80211_NOLINK;
2362 // pMgntInfo->AsocTimestamp = 0;
2366 struct net_device *dev,
2370 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2372 // Schedule an workitem to wake up for ps mode, 070109, by rcnjko.
2375 if(pMgntInfo->mPss != eAwake)
2378 // Using AwkaeTimer to prevent mismatch ps state.
2379 // In the timer the state will be changed according to the RF is being awoke or not. By Bruce, 2007-10-31.
2381 // PlatformScheduleWorkItem( &(pMgntInfo->AwakeWorkItem) );
2382 PlatformSetTimer( Adapter, &(pMgntInfo->AwakeTimer), 0 );
2386 // Indication of disassociation event.
2387 //DrvIFIndicateDisassociation(Adapter, asRsn);
2388 if(IS_DOT11D_ENABLE(priv->ieee80211))
2389 Dot11d_Reset(priv->ieee80211);
2390 // In adhoc mode, update beacon frame.
2391 if( priv->ieee80211->state == IEEE80211_LINKED )
2393 if( priv->ieee80211->iw_mode == IW_MODE_ADHOC )
2395 // RT_TRACE(COMP_MLME, DBG_LOUD, ("MgntDisconnect() ===> MgntDisconnectIBSS\n"));
2396 //printk("MgntDisconnect() ===> MgntDisconnectIBSS\n");
2397 MgntDisconnectIBSS(dev);
2399 if( priv->ieee80211->iw_mode == IW_MODE_INFRA )
2401 // We clear key here instead of MgntDisconnectAP() because that
2402 // MgntActSet_802_11_DISASSOCIATE() is an interface called by OS,
2403 // e.g. OID_802_11_DISASSOCIATE in Windows while as MgntDisconnectAP() is
2404 // used to handle disassociation related things to AP, e.g. send Disassoc
2405 // frame to AP. 2005.01.27, by rcnjko.
2406 // SecClearAllKeys(Adapter);
2408 // RT_TRACE(COMP_MLME, DBG_LOUD, ("MgntDisconnect() ===> MgntDisconnectAP\n"));
2409 //printk("MgntDisconnect() ===> MgntDisconnectAP\n");
2410 MgntDisconnectAP(dev, asRsn);
2413 // Inidicate Disconnect, 2005.02.23, by rcnjko.
2414 // MgntIndicateMediaStatus( Adapter, RT_MEDIA_DISCONNECT, GENERAL_INDICATE);
2421 // Chang RF Power State.
2422 // Note that, only MgntActSet_RF_State() is allowed to set HW_VAR_RF_STATE.
2429 struct net_device *dev,
2430 RT_RF_POWER_STATE eRFPowerState
2433 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2434 bool bResult = false;
2436 // printk("---------> SetRFPowerState(): eRFPowerState(%d)\n", eRFPowerState);
2437 if(eRFPowerState == priv->eRFPowerState)
2439 // printk("<--------- SetRFPowerState(): discard the request for eRFPowerState(%d) is the same.\n", eRFPowerState);
2443 switch(priv->rf_chip)
2447 bResult = SetZebraRFPowerState8185(dev, eRFPowerState);
2451 printk("SetRFPowerState8185(): unknown RFChipID: 0x%X!!!\n", priv->rf_chip);
2454 // printk("<--------- SetRFPowerState(): bResult(%d)\n", bResult);
2459 HalEnableRx8185Dummy(
2460 struct net_device *dev
2465 HalDisableRx8185Dummy(
2466 struct net_device *dev
2472 MgntActSet_RF_State(
2473 struct net_device *dev,
2474 RT_RF_POWER_STATE StateToSet,
2478 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2479 bool bActionAllowed = false;
2480 bool bConnectBySSID = false;
2481 RT_RF_POWER_STATE rtState;
2482 u16 RFWaitCounter = 0;
2484 // printk("===>MgntActSet_RF_State(): StateToSet(%d), ChangeSource(0x%x)\n",StateToSet, ChangeSource);
2486 // Prevent the race condition of RF state change. By Bruce, 2007-11-28.
2487 // Only one thread can change the RF state at one time, and others should wait to be executed.
2492 // down(&priv->rf_state);
2493 spin_lock_irqsave(&priv->rf_ps_lock,flag);
2494 if(priv->RFChangeInProgress)
2496 // printk("====================>haha111111111\n");
2497 // up(&priv->rf_state);
2498 // RT_TRACE(COMP_RF, DBG_LOUD, ("MgntActSet_RF_State(): RF Change in progress! Wait to set..StateToSet(%d).\n", StateToSet));
2499 spin_unlock_irqrestore(&priv->rf_ps_lock,flag);
2500 // Set RF after the previous action is done.
2501 while(priv->RFChangeInProgress)
2504 // RT_TRACE(COMP_RF, DBG_LOUD, ("MgntActSet_RF_State(): Wait 1 ms (%d times)...\n", RFWaitCounter));
2505 udelay(1000); // 1 ms
2507 // Wait too long, return FALSE to avoid to be stuck here.
2508 if(RFWaitCounter > 1000) // 1sec
2510 // RT_ASSERT(FALSE, ("MgntActSet_RF_State(): Wait too logn to set RF\n"));
2511 printk("MgntActSet_RF_State(): Wait too long to set RF\n");
2512 // TODO: Reset RF state?
2519 // printk("========================>haha2\n");
2520 priv->RFChangeInProgress = true;
2521 // up(&priv->rf_state);
2522 spin_unlock_irqrestore(&priv->rf_ps_lock,flag);
2527 rtState = priv->eRFPowerState;
2534 // Turn On RF no matter the IPS setting because we need to update the RF state to Ndis under Vista, or
2535 // the Windows does not allow the driver to perform site survey any more. By Bruce, 2007-10-02.
2537 priv->RfOffReason &= (~ChangeSource);
2539 if(! priv->RfOffReason)
2541 priv->RfOffReason = 0;
2542 bActionAllowed = true;
2544 if(rtState == eRfOff && ChangeSource >=RF_CHANGE_BY_HW && !priv->bInHctTest)
2546 bConnectBySSID = true;
2550 // RT_TRACE(COMP_RF, DBG_LOUD, ("MgntActSet_RF_State - eRfon reject pMgntInfo->RfOffReason= 0x%x, ChangeSource=0x%X\n", pMgntInfo->RfOffReason, ChangeSource));
2555 // 070125, rcnjko: we always keep connected in AP mode.
2557 if (priv->RfOffReason > RF_CHANGE_BY_IPS)
2561 // Disconnect to current BSS when radio off. Asked by QuanTa.
2565 // Calling MgntDisconnect() instead of MgntActSet_802_11_DISASSOCIATE(),
2566 // because we do NOT need to set ssid to dummy ones.
2567 // Revised by Roger, 2007.12.04.
2569 MgntDisconnect( dev, disas_lv_ss );
2571 // Clear content of bssDesc[] and bssDesc4Query[] to avoid reporting old bss to UI.
2572 // 2007.05.28, by shien chang.
2573 // PlatformZeroMemory( pMgntInfo->bssDesc, sizeof(RT_WLAN_BSS)*MAX_BSS_DESC );
2574 // pMgntInfo->NumBssDesc = 0;
2575 // PlatformZeroMemory( pMgntInfo->bssDesc4Query, sizeof(RT_WLAN_BSS)*MAX_BSS_DESC );
2576 // pMgntInfo->NumBssDesc4Query = 0;
2581 priv->RfOffReason |= ChangeSource;
2582 bActionAllowed = true;
2586 priv->RfOffReason |= ChangeSource;
2587 bActionAllowed = true;
2596 // RT_TRACE(COMP_RF, DBG_LOUD, ("MgntActSet_RF_State(): Action is allowed.... StateToSet(%d), RfOffReason(%#X)\n", StateToSet, pMgntInfo->RfOffReason));
2597 // Config HW to the specified mode.
2598 // printk("MgntActSet_RF_State(): Action is allowed.... StateToSet(%d), RfOffReason(%#X)\n", StateToSet, priv->RfOffReason);
2599 SetRFPowerState(dev, StateToSet);
2602 if(StateToSet == eRfOn)
2604 HalEnableRx8185Dummy(dev);
2607 // by amy not supported
2608 // MgntActSet_802_11_SSID(Adapter, Adapter->MgntInfo.Ssid.Octet, Adapter->MgntInfo.Ssid.Length, TRUE );
2612 else if(StateToSet == eRfOff)
2614 HalDisableRx8185Dummy(dev);
2619 // printk("MgntActSet_RF_State(): Action is rejected.... StateToSet(%d), ChangeSource(%#X), RfOffReason(%#X)\n", StateToSet, ChangeSource, priv->RfOffReason);
2622 // Release RF spinlock
2623 // down(&priv->rf_state);
2624 spin_lock_irqsave(&priv->rf_ps_lock,flag);
2625 priv->RFChangeInProgress = false;
2626 // up(&priv->rf_state);
2627 spin_unlock_irqrestore(&priv->rf_ps_lock,flag);
2628 // printk("<===MgntActSet_RF_State()\n");
2629 return bActionAllowed;
2633 struct net_device *dev
2636 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2640 // This flag "bSwRfProcessing", indicates the status of IPS procedure, should be set if the IPS workitem
2641 // is really scheduled.
2642 // The old code, sets this flag before scheduling the IPS workitem and however, at the same time the
2643 // previous IPS workitem did not end yet, fails to schedule the current workitem. Thus, bSwRfProcessing
2644 // blocks the IPS procedure of switching RF.
2645 // By Bruce, 2007-12-25.
2647 priv->bSwRfProcessing = true;
2649 MgntActSet_RF_State(dev, priv->eInactivePowerState, RF_CHANGE_BY_IPS);
2652 // To solve CAM values miss in RF OFF, rewrite CAM values after RF ON. By Bruce, 2007-09-20.
2657 if( ( pMgntInfo->SecurityInfo.PairwiseEncAlgorithm == WEP104_Encryption ) ||
2658 (pMgntInfo->SecurityInfo.PairwiseEncAlgorithm == WEP40_Encryption) )
2660 if( pMgntInfo->SecurityInfo.KeyLen[index] != 0)
2661 pAdapter->HalFunc.SetKeyHandler(pAdapter, index, 0, FALSE, pMgntInfo->SecurityInfo.PairwiseEncAlgorithm, TRUE, FALSE);
2667 priv->bSwRfProcessing = false;
2672 // Enter the inactive power save mode. RF will be off
2673 // 2007.08.17, by shien chang.
2677 struct net_device *dev
2680 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2681 RT_RF_POWER_STATE rtState;
2682 //printk("==============================>enter IPS\n");
2683 if (priv->bInactivePs)
2685 rtState = priv->eRFPowerState;
2688 // Added by Bruce, 2007-12-25.
2689 // Do not enter IPS in the following conditions:
2690 // (1) RF is already OFF or Sleep
2691 // (2) bSwRfProcessing (indicates the IPS is still under going)
2692 // (3) Connectted (only disconnected can trigger IPS)
2693 // (4) IBSS (send Beacon)
2694 // (5) AP mode (send Beacon)
2696 if (rtState == eRfOn && !priv->bSwRfProcessing
2697 && (priv->ieee80211->state != IEEE80211_LINKED ))
2699 // printk("IPSEnter(): Turn off RF.\n");
2700 priv->eInactivePowerState = eRfOff;
2701 InactivePowerSave(dev);
2704 // printk("priv->eRFPowerState is %d\n",priv->eRFPowerState);
2708 struct net_device *dev
2711 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2712 RT_RF_POWER_STATE rtState;
2713 //printk("===================================>leave IPS\n");
2714 if (priv->bInactivePs)
2716 rtState = priv->eRFPowerState;
2717 if ((rtState == eRfOff || rtState == eRfSleep) && (!priv->bSwRfProcessing) && priv->RfOffReason <= RF_CHANGE_BY_IPS)
2719 // printk("IPSLeave(): Turn on RF.\n");
2720 priv->eInactivePowerState = eRfOn;
2721 InactivePowerSave(dev);
2724 // printk("priv->eRFPowerState is %d\n",priv->eRFPowerState);
2726 //by amy for power save
2727 void rtl8185b_adapter_start(struct net_device *dev)
2729 struct r8180_priv *priv = ieee80211_priv(dev);
2730 struct ieee80211_device *ieee = priv->ieee80211;
2732 u8 SupportedWirelessMode;
2733 u8 InitWirelessMode;
2734 u8 bInvalidWirelessMode = 0;
2742 //rtl8180_rtx_disable(dev);
2744 write_nic_byte(dev,0x24e, (BIT5|BIT6|BIT0));
2748 priv->dma_poll_mask = 0;
2749 priv->dma_poll_stop_mask = 0;
2751 //rtl8180_beacon_tx_disable(dev);
2753 HwConfigureRTL8185(dev);
2755 write_nic_dword(dev, MAC0, ((u32*)dev->dev_addr)[0]);
2756 write_nic_word(dev, MAC4, ((u32*)dev->dev_addr)[1] & 0xffff );
2758 write_nic_byte(dev, MSR, read_nic_byte(dev, MSR) & 0xf3); // default network type to 'No Link'
2760 //write_nic_byte(dev, BRSR, 0x0); // Set BRSR= 1M
2762 write_nic_word(dev, BcnItv, 100);
2763 write_nic_word(dev, AtimWnd, 2);
2765 //PlatformEFIOWrite2Byte(dev, FEMR, 0xFFFF);
2766 PlatformIOWrite2Byte(dev, FEMR, 0xFFFF);
2768 write_nic_byte(dev, WPA_CONFIG, 0);
2770 MacConfig_85BASIC(dev);
2772 // Override the RFSW_CTRL (MAC offset 0x272-0x273), 2006.06.07, by rcnjko.
2773 // BT_DEMO_BOARD type
2774 PlatformIOWrite2Byte(dev, RFSW_CTRL, 0x569a);
2776 //#ifdef CONFIG_RTL818X_S
2777 // for jong required
2778 // PlatformIOWrite2Byte(dev, RFSW_CTRL, 0x9a56);
2782 //PlatformIOWrite2Byte(dev, RFSW_CTRL, 0x9a56);
2784 //-----------------------------------------------------------------------------
2785 // Set up PHY related.
2786 //-----------------------------------------------------------------------------
2787 // Enable Config3.PARAM_En to revise AnaaParm.
2788 write_nic_byte(dev, CR9346, 0xc0); // enable config register write
2790 tmpu8 = read_nic_byte(dev, CONFIG3);
2791 write_nic_byte(dev, CONFIG3, (tmpu8 |CONFIG3_PARM_En) );
2793 // Turn on Analog power.
2794 // Asked for by William, otherwise, MAC 3-wire can't work, 2006.06.27, by rcnjko.
2795 write_nic_dword(dev, ANAPARAM2, ANAPARM2_ASIC_ON);
2796 write_nic_dword(dev, ANAPARAM, ANAPARM_ASIC_ON);
2798 write_nic_word(dev, ANAPARAM3, 0x0010);
2801 write_nic_byte(dev, CONFIG3, tmpu8);
2802 write_nic_byte(dev, CR9346, 0x00);
2803 //{by amy 080312 for led
2804 // enable EEM0 and EEM1 in 9346CR
2805 btCR9346 = read_nic_byte(dev, CR9346);
2806 write_nic_byte(dev, CR9346, (btCR9346|0xC0) );
2808 // B cut use LED1 to control HW RF on/off
2809 TmpU1b = read_nic_byte(dev, CONFIG5);
2810 TmpU1b = TmpU1b & ~BIT3;
2811 write_nic_byte(dev,CONFIG5, TmpU1b);
2813 // disable EEM0 and EEM1 in 9346CR
2814 btCR9346 &= ~(0xC0);
2815 write_nic_byte(dev, CR9346, btCR9346);
2817 //Enable Led (suggested by Jong)
2818 // B-cut RF Radio on/off 5e[3]=0
2819 btPSR = read_nic_byte(dev, PSR);
2820 write_nic_byte(dev, PSR, (btPSR | BIT3));
2821 //by amy 080312 for led}
2822 // setup initial timing for RFE.
2823 write_nic_word(dev, RFPinsOutput, 0x0480);
2824 SetOutputEnableOfRfPins(dev);
2825 write_nic_word(dev, RFPinsSelect, 0x2488);
2830 // We assume RegWirelessMode has already been initialized before,
2831 // however, we has to validate the wireless mode here and provide a reasonble
2832 // initialized value if necessary. 2005.01.13, by rcnjko.
2833 SupportedWirelessMode = GetSupportedWirelessMode8185(dev);
2834 if( (ieee->mode != WIRELESS_MODE_B) &&
2835 (ieee->mode != WIRELESS_MODE_G) &&
2836 (ieee->mode != WIRELESS_MODE_A) &&
2837 (ieee->mode != WIRELESS_MODE_AUTO))
2838 { // It should be one of B, G, A, or AUTO.
2839 bInvalidWirelessMode = 1;
2842 { // One of B, G, A, or AUTO.
2843 // Check if the wireless mode is supported by RF.
2844 if( (ieee->mode != WIRELESS_MODE_AUTO) &&
2845 (ieee->mode & SupportedWirelessMode) == 0 )
2847 bInvalidWirelessMode = 1;
2851 if(bInvalidWirelessMode || ieee->mode==WIRELESS_MODE_AUTO)
2852 { // Auto or other invalid value.
2853 // Assigne a wireless mode to initialize.
2854 if((SupportedWirelessMode & WIRELESS_MODE_A))
2856 InitWirelessMode = WIRELESS_MODE_A;
2858 else if((SupportedWirelessMode & WIRELESS_MODE_G))
2860 InitWirelessMode = WIRELESS_MODE_G;
2862 else if((SupportedWirelessMode & WIRELESS_MODE_B))
2864 InitWirelessMode = WIRELESS_MODE_B;
2868 DMESGW("InitializeAdapter8185(): No valid wireless mode supported, SupportedWirelessMode(%x)!!!\n",
2869 SupportedWirelessMode);
2870 InitWirelessMode = WIRELESS_MODE_B;
2873 // Initialize RegWirelessMode if it is not a valid one.
2874 if(bInvalidWirelessMode)
2876 ieee->mode = (WIRELESS_MODE)InitWirelessMode;
2880 { // One of B, G, A.
2881 InitWirelessMode = ieee->mode;
2883 //by amy for power save
2885 // printk("initialize ENABLE_IPS\n");
2886 priv->eRFPowerState = eRfOff;
2887 priv->RfOffReason = 0;
2890 // u32 tmp = jiffies;
2891 MgntActSet_RF_State(dev, eRfOn, 0);
2893 // printk("rf on cost jiffies:%lx\n", (tmp2-tmp)*1000/HZ);
2895 // DrvIFIndicateCurrentPhyStatus(priv);
2897 // If inactive power mode is enabled, disable rf while in disconnected state.
2898 // 2007.07.16, by shien chang.
2900 if (priv->bInactivePs)
2903 // u32 tmp = jiffies;
2904 MgntActSet_RF_State(dev,eRfOff, RF_CHANGE_BY_IPS);
2906 // printk("rf off cost jiffies:%lx\n", (tmp2-tmp)*1000/HZ);
2911 //by amy for power save
2913 // Turn off RF if necessary. 2005.08.23, by rcnjko.
2914 // We shall turn off RF after setting CMDR, otherwise,
2915 // RF will be turnned on after we enable MAC Tx/Rx.
2916 if(Adapter->MgntInfo.RegRfOff == TRUE)
2918 SetRFPowerState8185(Adapter, RF_OFF);
2922 SetRFPowerState8185(Adapter, RF_ON);
2926 /* //these is equal with above TODO.
2927 write_nic_byte(dev, CR9346, 0xc0); // enable config register write
2928 write_nic_byte(dev, CONFIG3, read_nic_byte(dev, CONFIG3) | CONFIG3_PARM_En);
2929 RF_WriteReg(dev, 0x4, 0x9FF);
2930 write_nic_dword(dev, ANAPARAM2, ANAPARM2_ASIC_ON);
2931 write_nic_dword(dev, ANAPARAM, ANAPARM_ASIC_ON);
2932 write_nic_byte(dev, CONFIG3, (read_nic_byte(dev, CONFIG3)&(~CONFIG3_PARM_En)));
2933 write_nic_byte(dev, CR9346, 0x00);
2936 ActSetWirelessMode8185(dev, (u8)(InitWirelessMode));
2938 //-----------------------------------------------------------------------------
2940 rtl8185b_irq_enable(dev);
2942 netif_start_queue(dev);
2947 void rtl8185b_rx_enable(struct net_device *dev)
2951 /* for now we accept data, management & ctl frame*/
2952 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2954 rxconf=read_nic_dword(dev,RX_CONF);
2955 rxconf = rxconf &~ MAC_FILTER_MASK;
2956 rxconf = rxconf | (1<<ACCEPT_MNG_FRAME_SHIFT);
2957 rxconf = rxconf | (1<<ACCEPT_DATA_FRAME_SHIFT);
2958 rxconf = rxconf | (1<<ACCEPT_BCAST_FRAME_SHIFT);
2959 rxconf = rxconf | (1<<ACCEPT_MCAST_FRAME_SHIFT);
2960 // rxconf = rxconf | (1<<ACCEPT_CRCERR_FRAME_SHIFT);
2961 if (dev->flags & IFF_PROMISC) DMESG ("NIC in promisc mode");
2963 if(priv->ieee80211->iw_mode == IW_MODE_MONITOR || \
2964 dev->flags & IFF_PROMISC){
2965 rxconf = rxconf | (1<<ACCEPT_ALLMAC_FRAME_SHIFT);
2967 rxconf = rxconf | (1<<ACCEPT_NICMAC_FRAME_SHIFT);
2968 if(priv->card_8185 == 0)
2969 rxconf = rxconf | (1<<RX_CHECK_BSSID_SHIFT);
2972 /*if(priv->ieee80211->iw_mode == IW_MODE_MASTER){
2973 rxconf = rxconf | (1<<ACCEPT_ALLMAC_FRAME_SHIFT);
2974 rxconf = rxconf | (1<<RX_CHECK_BSSID_SHIFT);
2977 if(priv->ieee80211->iw_mode == IW_MODE_MONITOR){
2978 rxconf = rxconf | (1<<ACCEPT_CTL_FRAME_SHIFT);
2979 rxconf = rxconf | (1<<ACCEPT_ICVERR_FRAME_SHIFT);
2980 rxconf = rxconf | (1<<ACCEPT_PWR_FRAME_SHIFT);
2983 if( priv->crcmon == 1 && priv->ieee80211->iw_mode == IW_MODE_MONITOR)
2984 rxconf = rxconf | (1<<ACCEPT_CRCERR_FRAME_SHIFT);
2986 //if(!priv->card_8185){
2987 rxconf = rxconf &~ RX_FIFO_THRESHOLD_MASK;
2988 rxconf = rxconf | (RX_FIFO_THRESHOLD_NONE<<RX_FIFO_THRESHOLD_SHIFT);
2991 rxconf = rxconf | (1<<RX_AUTORESETPHY_SHIFT);
2992 rxconf = rxconf &~ MAX_RX_DMA_MASK;
2993 rxconf = rxconf | (MAX_RX_DMA_2048<<MAX_RX_DMA_SHIFT);
2995 //if(!priv->card_8185)
2996 rxconf = rxconf | RCR_ONLYERLPKT;
2998 rxconf = rxconf &~ RCR_CS_MASK;
2999 if(!priv->card_8185)
3000 rxconf |= (priv->rcr_csense<<RCR_CS_SHIFT);
3001 // rxconf &=~ 0xfff00000;
3002 // rxconf |= 0x90100000;//9014f76f;
3003 write_nic_dword(dev, RX_CONF, rxconf);
3006 if (dev->flags & IFF_PROMISC) DMESG ("NIC in promisc mode");
3008 if(priv->ieee80211->iw_mode == IW_MODE_MONITOR || \
3009 dev->flags & IFF_PROMISC){
3010 priv->ReceiveConfig = priv->ReceiveConfig & (~RCR_APM);
3011 priv->ReceiveConfig = priv->ReceiveConfig | RCR_AAP;
3014 /*if(priv->ieee80211->iw_mode == IW_MODE_MASTER){
3015 rxconf = rxconf | (1<<ACCEPT_ALLMAC_FRAME_SHIFT);
3016 rxconf = rxconf | (1<<RX_CHECK_BSSID_SHIFT);
3019 if(priv->ieee80211->iw_mode == IW_MODE_MONITOR){
3020 priv->ReceiveConfig = priv->ReceiveConfig | RCR_ACF | RCR_APWRMGT | RCR_AICV;
3023 if( priv->crcmon == 1 && priv->ieee80211->iw_mode == IW_MODE_MONITOR)
3024 priv->ReceiveConfig = priv->ReceiveConfig | RCR_ACRC32;
3026 write_nic_dword(dev, RCR, priv->ReceiveConfig);
3031 DMESG("rxconf: %x %x",priv->ReceiveConfig ,read_nic_dword(dev,RCR));
3033 cmd=read_nic_byte(dev,CMD);
3034 write_nic_byte(dev,CMD,cmd | (1<<CMD_RX_ENABLE_SHIFT));
3038 void rtl8185b_tx_enable(struct net_device *dev)
3044 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
3047 txconf= read_nic_dword(dev,TX_CONF);
3048 if(priv->card_8185){
3051 byte = read_nic_byte(dev,CW_CONF);
3052 byte &= ~(1<<CW_CONF_PERPACKET_CW_SHIFT);
3053 byte &= ~(1<<CW_CONF_PERPACKET_RETRY_SHIFT);
3054 write_nic_byte(dev, CW_CONF, byte);
3056 tx_agc_ctl = read_nic_byte(dev, TX_AGC_CTL);
3057 tx_agc_ctl &= ~(1<<TX_AGC_CTL_PERPACKET_GAIN_SHIFT);
3058 tx_agc_ctl &= ~(1<<TX_AGC_CTL_PERPACKET_ANTSEL_SHIFT);
3059 tx_agc_ctl |=(1<<TX_AGC_CTL_FEEDBACK_ANT);
3060 write_nic_byte(dev, TX_AGC_CTL, tx_agc_ctl);
3062 write_nic_word(dev, 0x5e, 0x01);
3063 force_pci_posting(dev);
3065 write_nic_word(dev, 0xfe, 0x10);
3066 force_pci_posting(dev);
3068 write_nic_word(dev, 0x5e, 0x00);
3069 force_pci_posting(dev);
3072 write_nic_byte(dev, 0xec, 0x3f); /* Disable early TX */
3075 if(priv->card_8185){
3077 txconf = txconf &~ (1<<TCR_PROBE_NOTIMESTAMP_SHIFT);
3082 txconf= txconf &~ (1<<TX_CONF_HEADER_AUTOICREMENT_SHIFT);
3084 txconf= txconf | (1<<TX_CONF_HEADER_AUTOICREMENT_SHIFT);
3087 txconf = txconf &~ TX_LOOPBACK_MASK;
3088 txconf = txconf | (TX_LOOPBACK_NONE <<TX_LOOPBACK_SHIFT);
3089 txconf = txconf &~ TCR_DPRETRY_MASK;
3090 txconf = txconf &~ TCR_RTSRETRY_MASK;
3091 txconf = txconf | (priv->retry_data<<TX_DPRETRY_SHIFT);
3092 txconf = txconf | (priv->retry_rts<<TX_RTSRETRY_SHIFT);
3093 txconf = txconf &~ (1<<TX_NOCRC_SHIFT);
3095 if(priv->card_8185){
3096 if(priv->hw_plcp_len)
3097 txconf = txconf &~ TCR_PLCP_LEN;
3099 txconf = txconf | TCR_PLCP_LEN;
3101 txconf = txconf &~ TCR_SAT;
3103 txconf = txconf &~ TCR_MXDMA_MASK;
3104 txconf = txconf | (TCR_MXDMA_2048<<TCR_MXDMA_SHIFT);
3105 txconf = txconf | TCR_CWMIN;
3106 txconf = txconf | TCR_DISCW;
3108 // if(priv->ieee80211->hw_wep)
3109 // txconf=txconf &~ (1<<TX_NOICV_SHIFT);
3111 txconf=txconf | (1<<TX_NOICV_SHIFT);
3113 write_nic_dword(dev,TX_CONF,txconf);
3116 write_nic_dword(dev, TCR, priv->TransmitConfig);
3117 byte = read_nic_byte(dev, MSR);
3118 byte |= MSR_LINK_ENEDCA;
3119 write_nic_byte(dev, MSR, byte);
3124 DMESG("txconf: %x %x",priv->TransmitConfig,read_nic_dword(dev,TCR));
3127 cmd=read_nic_byte(dev,CMD);
3128 write_nic_byte(dev,CMD,cmd | (1<<CMD_TX_ENABLE_SHIFT));
3130 //write_nic_dword(dev,TX_CONF,txconf);
3134 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
3135 write_nic_byte(dev, TX_DMA_POLLING, priv->dma_poll_mask);
3136 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);