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_rtl8225.h" /* RTL8225 Radio frontend */
26 #include "r8180_93cx6.h" /* Card EEPROM */
29 #include "ieee80211/dot11d.h"
32 //#define CONFIG_RTL8180_IO_MAP
34 #define TC_3W_POLL_MAX_TRY_CNT 5
35 static u8 MAC_REG_TABLE[][2]={
37 // 0x34(BRSR), 0xBE(RATE_FALLBACK_CTL), 0x1E0(ARFR) would set in HwConfigureRTL8185()
38 // 0x272(RFSW_CTRL), 0x1CE(AESMSK_QC) set in InitializeAdapter8185().
39 // 0x1F0~0x1F8 set in MacConfig_85BASIC()
40 {0x08, 0xae}, {0x0a, 0x72}, {0x5b, 0x42},
41 {0x84, 0x88}, {0x85, 0x24}, {0x88, 0x54}, {0x8b, 0xb8}, {0x8c, 0x03},
42 {0x8d, 0x40}, {0x8e, 0x00}, {0x8f, 0x00}, {0x5b, 0x18}, {0x91, 0x03},
43 {0x94, 0x0F}, {0x95, 0x32},
44 {0x96, 0x00}, {0x97, 0x07}, {0xb4, 0x22}, {0xdb, 0x00},
45 {0xf0, 0x32}, {0xf1, 0x32}, {0xf2, 0x00}, {0xf3, 0x00}, {0xf4, 0x32},
46 {0xf5, 0x43}, {0xf6, 0x00}, {0xf7, 0x00}, {0xf8, 0x46}, {0xf9, 0xa4},
47 {0xfa, 0x00}, {0xfb, 0x00}, {0xfc, 0x96}, {0xfd, 0xa4}, {0xfe, 0x00},
51 // For Flextronics system Logo PCIHCT failure:
52 // 0x1C4~0x1CD set no-zero value to avoid PCI configuration space 0x45[7]=1
54 {0x58, 0x00}, {0x59, 0x00}, {0x5a, 0x04}, {0x5b, 0x00}, {0x60, 0x24},
55 {0x61, 0x97}, {0x62, 0xF0}, {0x63, 0x09}, {0x80, 0x0F}, {0x81, 0xFF},
56 {0x82, 0xFF}, {0x83, 0x03},
57 {0xC4, 0x22}, {0xC5, 0x22}, {0xC6, 0x22}, {0xC7, 0x22}, {0xC8, 0x22}, //lzm add 080826
58 {0xC9, 0x22}, {0xCA, 0x22}, {0xCB, 0x22}, {0xCC, 0x22}, {0xCD, 0x22},//lzm add 080826
64 {0x0c, 0x04}, {0x4c, 0x30}, {0x4d, 0x08}, {0x50, 0x05}, {0x51, 0xf5},
65 {0x52, 0x04}, {0x53, 0xa0}, {0x54, 0xff}, {0x55, 0xff}, {0x56, 0xff},
66 {0x57, 0xff}, {0x58, 0x08}, {0x59, 0x08}, {0x5a, 0x08}, {0x5b, 0x08},
67 {0x60, 0x08}, {0x61, 0x08}, {0x62, 0x08}, {0x63, 0x08}, {0x64, 0x2f},
68 {0x8c, 0x3f}, {0x8d, 0x3f}, {0x8e, 0x3f},
69 {0x8f, 0x3f}, {0xc4, 0xff}, {0xc5, 0xff}, {0xc6, 0xff}, {0xc7, 0xff},
70 {0xc8, 0x00}, {0xc9, 0x00}, {0xca, 0x80}, {0xcb, 0x00},
73 {0x5e, 0x00},{0x9f, 0x03}
77 static u8 ZEBRA_AGC[]={
79 0x7E,0x7E,0x7E,0x7E,0x7D,0x7C,0x7B,0x7A,0x79,0x78,0x77,0x76,0x75,0x74,0x73,0x72,
80 0x71,0x70,0x6F,0x6E,0x6D,0x6C,0x6B,0x6A,0x69,0x68,0x67,0x66,0x65,0x64,0x63,0x62,
81 0x48,0x47,0x46,0x45,0x44,0x29,0x28,0x27,0x26,0x25,0x24,0x23,0x22,0x21,0x08,0x07,
82 0x06,0x05,0x04,0x03,0x02,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
83 0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x10,0x11,0x12,0x13,0x15,0x16,
84 0x17,0x17,0x18,0x18,0x19,0x1a,0x1a,0x1b,0x1b,0x1c,0x1c,0x1d,0x1d,0x1d,0x1e,0x1e,
85 0x1f,0x1f,0x1f,0x20,0x20,0x20,0x20,0x21,0x21,0x21,0x22,0x22,0x22,0x23,0x23,0x24,
86 0x24,0x25,0x25,0x25,0x26,0x26,0x27,0x27,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F,0x2F
89 static u32 ZEBRA_RF_RX_GAIN_TABLE[]={
90 0x0096,0x0076,0x0056,0x0036,0x0016,0x01f6,0x01d6,0x01b6,
91 0x0196,0x0176,0x00F7,0x00D7,0x00B7,0x0097,0x0077,0x0057,
92 0x0037,0x00FB,0x00DB,0x00BB,0x00FF,0x00E3,0x00C3,0x00A3,
93 0x0083,0x0063,0x0043,0x0023,0x0003,0x01E3,0x01C3,0x01A3,
94 0x0183,0x0163,0x0143,0x0123,0x0103
97 static u8 OFDM_CONFIG[]={
98 // OFDM reg0x06[7:0]=0xFF: Enable power saving mode in RX
99 // OFDM reg0x3C[4]=1'b1: Enable RX power saving mode
100 // ofdm 0x3a = 0x7b ,(original : 0xfb) For ECS shielding room TP test
103 0x10, 0x0F, 0x0A, 0x0C, 0x14, 0xFA, 0xFF, 0x50,
104 0x00, 0x50, 0x00, 0x00, 0x00, 0x5C, 0x00, 0x00,
106 0x40, 0x00, 0x40, 0x00, 0x00, 0x00, 0xA8, 0x26,
107 0x32, 0x33, 0x06, 0xA5, 0x6F, 0x55, 0xC8, 0xBB,
109 0x0A, 0xE1, 0x2C, 0x4A, 0x86, 0x83, 0x34, 0x00,
110 0x4F, 0x24, 0x6F, 0xC2, 0x03, 0x40, 0x80, 0x00,
112 0xC0, 0xC1, 0x58, 0xF1, 0x00, 0xC4, 0x90, 0x3e,
113 0xD8, 0x3C, 0x7B, 0x10, 0x10
116 /*---------------------------------------------------------------
118 * the code is ported from Windows source code
119 ----------------------------------------------------------------*/
122 PlatformIOWrite1Byte(
123 struct net_device *dev,
128 write_nic_byte(dev, offset, data);
129 read_nic_byte(dev, offset); // To make sure write operation is completed, 2005.11.09, by rcnjko.
134 PlatformIOWrite2Byte(
135 struct net_device *dev,
140 write_nic_word(dev, offset, data);
141 read_nic_word(dev, offset); // To make sure write operation is completed, 2005.11.09, by rcnjko.
145 u8 PlatformIORead1Byte(struct net_device *dev, u32 offset);
148 PlatformIOWrite4Byte(
149 struct net_device *dev,
155 if (offset == PhyAddr)
156 {//For Base Band configuration.
157 unsigned char cmdByte;
158 unsigned long dataBytes;
162 cmdByte = (u8)(data & 0x000000ff);
167 // The critical section is only BB read/write race condition.
169 // 1. We assume NO one will access BB at DIRQL, otherwise, system will crash for
170 // acquiring the spinlock in such context.
171 // 2. PlatformIOWrite4Byte() MUST NOT be recursive.
173 // NdisAcquireSpinLock( &(pDevice->IoSpinLock) );
175 for(idx = 0; idx < 30; idx++)
176 { // Make sure command bit is clear before access it.
177 u1bTmp = PlatformIORead1Byte(dev, PhyAddr);
178 if((u1bTmp & BIT7) == 0)
184 for(idx=0; idx < 3; idx++)
186 PlatformIOWrite1Byte(dev,offset+1+idx,((u8*)&dataBytes)[idx] );
188 write_nic_byte(dev, offset, cmdByte);
190 // NdisReleaseSpinLock( &(pDevice->IoSpinLock) );
194 write_nic_dword(dev, offset, data);
195 read_nic_dword(dev, offset); // To make sure write operation is completed, 2005.11.09, by rcnjko.
201 struct net_device *dev,
207 data = read_nic_byte(dev, offset);
215 struct net_device *dev,
221 data = read_nic_word(dev, offset);
229 struct net_device *dev,
235 data = read_nic_dword(dev, offset);
241 void SetOutputEnableOfRfPins(struct net_device *dev)
243 write_nic_word(dev, RFPinsEnable, 0x1bff);
248 struct net_device *dev,
261 // Check if WE and RE are cleared.
262 for(TryCnt = 0; TryCnt < TC_3W_POLL_MAX_TRY_CNT; TryCnt++)
264 u1bTmp = read_nic_byte(dev, SW_3W_CMD1);
265 if( (u1bTmp & (SW_3W_CMD1_RE|SW_3W_CMD1_WE)) == 0 )
271 if (TryCnt == TC_3W_POLL_MAX_TRY_CNT) {
272 printk(KERN_ERR "rtl8187se: HwThreeWire(): CmdReg:"
273 " %#X RE|WE bits are not clear!!\n", u1bTmp);
278 // RTL8187S HSSI Read/Write Function
279 u1bTmp = read_nic_byte(dev, RF_SW_CONFIG);
283 u1bTmp |= RF_SW_CFG_SI; //reg08[1]=1 Serial Interface(SI)
286 u1bTmp &= ~RF_SW_CFG_SI; //reg08[1]=0 Parallel Interface(PI)
289 write_nic_byte(dev, RF_SW_CONFIG, u1bTmp);
293 // jong: HW SI read must set reg84[3]=0.
294 u1bTmp = read_nic_byte(dev, RFPinsSelect);
296 write_nic_byte(dev, RFPinsSelect, u1bTmp );
298 // Fill up data buffer for write operation.
302 if(nDataBufBitCnt == 16)
304 write_nic_word(dev, SW_3W_DB0, *((u16*)pDataBuf));
306 else if(nDataBufBitCnt == 64) // RTL8187S shouldn't enter this case
308 write_nic_dword(dev, SW_3W_DB0, *((u32*)pDataBuf));
309 write_nic_dword(dev, SW_3W_DB1, *((u32*)(pDataBuf + 4)));
314 int ByteCnt = nDataBufBitCnt / 8;
315 //printk("%d\n",nDataBufBitCnt);
316 if ((nDataBufBitCnt % 8) != 0) {
317 printk(KERN_ERR "rtl8187se: "
318 "HwThreeWire(): nDataBufBitCnt(%d)"
319 " should be multiple of 8!!!\n",
323 nDataBufBitCnt &= ~7;
326 if (nDataBufBitCnt > 64) {
327 printk(KERN_ERR "rtl8187se: HwThreeWire():"
328 " nDataBufBitCnt(%d) should <= 64!!!\n",
334 for(idx = 0; idx < ByteCnt; idx++)
336 write_nic_byte(dev, (SW_3W_DB0+idx), *(pDataBuf+idx));
344 // SI - reg274[3:0] : RF register's Address
345 write_nic_word(dev, SW_3W_DB0, *((u16*)pDataBuf) );
349 // PI - reg274[15:12] : RF register's Address
350 write_nic_word(dev, SW_3W_DB0, (*((u16*)pDataBuf)) << 12);
354 // Set up command: WE or RE.
357 write_nic_byte(dev, SW_3W_CMD1, SW_3W_CMD1_WE);
361 write_nic_byte(dev, SW_3W_CMD1, SW_3W_CMD1_RE);
364 // Check if DONE is set.
365 for(TryCnt = 0; TryCnt < TC_3W_POLL_MAX_TRY_CNT; TryCnt++)
367 u1bTmp = read_nic_byte(dev, SW_3W_CMD1);
368 if( (u1bTmp & SW_3W_CMD1_DONE) != 0 )
375 write_nic_byte(dev, SW_3W_CMD1, 0);
377 // Read back data for read operation.
382 //Serial Interface : reg363_362[11:0]
383 *((u16*)pDataBuf) = read_nic_word(dev, SI_DATA_READ) ;
387 //Parallel Interface : reg361_360[11:0]
388 *((u16*)pDataBuf) = read_nic_word(dev, PI_DATA_READ);
391 *((u16*)pDataBuf) &= 0x0FFF;
400 RF_WriteReg(struct net_device *dev, u8 offset, u32 data)
405 /* Pure HW 3-wire. */
406 data2Write = (data << 4) | (u32)(offset & 0x0f);
409 HwHSSIThreeWire(dev, (u8 *)(&data2Write), len, 1, 1);
412 u32 RF_ReadReg(struct net_device *dev, u8 offset)
418 data2Write = ((u32)(offset & 0x0f));
420 HwHSSIThreeWire(dev, (u8 *)(&data2Write), wlen, 1, 0);
421 dataRead = data2Write;
427 // by Owen on 04/07/14 for writing BB register successfully
430 struct net_device *dev,
438 UCharData = (u8)((Data & 0x0000ff00) >> 8);
439 PlatformIOWrite4Byte(dev, PhyAddr, Data);
440 //for(TimeoutCounter = 10; TimeoutCounter > 0; TimeoutCounter--)
442 PlatformIOWrite4Byte(dev, PhyAddr, Data & 0xffffff7f);
443 RegisterContent = PlatformIORead1Byte(dev, PhyDataR);
444 //if(UCharData == RegisterContent)
451 struct net_device *dev,
458 PlatformIOWrite4Byte(dev, PhyAddr, addr & 0xffffff7f);
459 RegisterContent = PlatformIORead1Byte(dev, PhyDataR);
461 return RegisterContent;
466 // Perform Antenna settings with antenna diversity on 87SE.
467 // Created by Roger, 2008.01.25.
470 SetAntennaConfig87SE(
471 struct net_device *dev,
472 u8 DefaultAnt, // 0: Main, 1: Aux.
473 bool bAntDiversity // 1:Enable, 0: Disable.
476 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
477 bool bAntennaSwitched = true;
479 //printk("SetAntennaConfig87SE(): DefaultAnt(%d), bAntDiversity(%d)\n", DefaultAnt, bAntDiversity);
481 // Threshold for antenna diversity.
482 write_phy_cck(dev, 0x0c, 0x09); // Reg0c : 09
484 if( bAntDiversity ) // Enable Antenna Diversity.
486 if( DefaultAnt == 1 ) // aux antenna
488 // Mac register, aux antenna
489 write_nic_byte(dev, ANTSEL, 0x00);
491 // Config CCK RX antenna.
492 write_phy_cck(dev, 0x11, 0xbb); // Reg11 : bb
493 write_phy_cck(dev, 0x01, 0xc7); // Reg01 : c7
495 // Config OFDM RX antenna.
496 write_phy_ofdm(dev, 0x0D, 0x54); // Reg0d : 54
497 write_phy_ofdm(dev, 0x18, 0xb2); // Reg18 : b2
499 else // use main antenna
501 // Mac register, main antenna
502 write_nic_byte(dev, ANTSEL, 0x03);
504 // Config CCK RX antenna.
505 write_phy_cck(dev, 0x11, 0x9b); // Reg11 : 9b
506 write_phy_cck(dev, 0x01, 0xc7); // Reg01 : c7
508 // Config OFDM RX antenna.
509 write_phy_ofdm(dev, 0x0d, 0x5c); // Reg0d : 5c
510 write_phy_ofdm(dev, 0x18, 0xb2); // Reg18 : b2
513 else // Disable Antenna Diversity.
515 if( DefaultAnt == 1 ) // aux Antenna
517 // Mac register, aux antenna
518 write_nic_byte(dev, ANTSEL, 0x00);
520 // Config CCK RX antenna.
521 write_phy_cck(dev, 0x11, 0xbb); // Reg11 : bb
522 write_phy_cck(dev, 0x01, 0x47); // Reg01 : 47
524 // Config OFDM RX antenna.
525 write_phy_ofdm(dev, 0x0D, 0x54); // Reg0d : 54
526 write_phy_ofdm(dev, 0x18, 0x32); // Reg18 : 32
530 // Mac register, main antenna
531 write_nic_byte(dev, ANTSEL, 0x03);
533 // Config CCK RX antenna.
534 write_phy_cck(dev, 0x11, 0x9b); // Reg11 : 9b
535 write_phy_cck(dev, 0x01, 0x47); // Reg01 : 47
537 // Config OFDM RX antenna.
538 write_phy_ofdm(dev, 0x0D, 0x5c); // Reg0d : 5c
539 write_phy_ofdm(dev, 0x18, 0x32); // Reg18 : 32
542 priv->CurrAntennaIndex = DefaultAnt; // Update default settings.
543 return bAntennaSwitched;
546 /*---------------------------------------------------------------
547 * Hardware Initialization.
548 * the code is ported from Windows source code
549 ----------------------------------------------------------------*/
552 ZEBRA_Config_85BASIC_HardCode(
553 struct net_device *dev
557 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
560 u32 u4bRegOffset, u4bRegValue, u4bRF23, u4bRF24;
565 //=============================================================================
566 // 87S_PCIE :: RADIOCFG.TXT
567 //=============================================================================
570 // Page1 : reg16-reg30
571 RF_WriteReg(dev, 0x00, 0x013f); mdelay(1); // switch to page1
572 u4bRF23= RF_ReadReg(dev, 0x08); mdelay(1);
573 u4bRF24= RF_ReadReg(dev, 0x09); mdelay(1);
575 if (u4bRF23 == 0x818 && u4bRF24 == 0x70C) {
577 printk(KERN_INFO "rtl8187se: card type changed from C- to D-cut\n");
580 // Page0 : reg0-reg15
582 RF_WriteReg(dev, 0x00, 0x009f); mdelay(1);// 1
584 RF_WriteReg(dev, 0x01, 0x06e0); mdelay(1);
586 RF_WriteReg(dev, 0x02, 0x004d); mdelay(1);// 2
588 RF_WriteReg(dev, 0x03, 0x07f1); mdelay(1);// 3
590 RF_WriteReg(dev, 0x04, 0x0975); mdelay(1);
591 RF_WriteReg(dev, 0x05, 0x0c72); mdelay(1);
592 RF_WriteReg(dev, 0x06, 0x0ae6); mdelay(1);
593 RF_WriteReg(dev, 0x07, 0x00ca); mdelay(1);
594 RF_WriteReg(dev, 0x08, 0x0e1c); mdelay(1);
595 RF_WriteReg(dev, 0x09, 0x02f0); mdelay(1);
596 RF_WriteReg(dev, 0x0a, 0x09d0); mdelay(1);
597 RF_WriteReg(dev, 0x0b, 0x01ba); mdelay(1);
598 RF_WriteReg(dev, 0x0c, 0x0640); mdelay(1);
599 RF_WriteReg(dev, 0x0d, 0x08df); mdelay(1);
600 RF_WriteReg(dev, 0x0e, 0x0020); mdelay(1);
601 RF_WriteReg(dev, 0x0f, 0x0990); mdelay(1);
604 // Page1 : reg16-reg30
605 RF_WriteReg(dev, 0x00, 0x013f); mdelay(1);
607 RF_WriteReg(dev, 0x03, 0x0806); mdelay(1);
609 RF_WriteReg(dev, 0x04, 0x03a7); mdelay(1);
610 RF_WriteReg(dev, 0x05, 0x059b); mdelay(1);
611 RF_WriteReg(dev, 0x06, 0x0081); mdelay(1);
614 RF_WriteReg(dev, 0x07, 0x01A0); mdelay(1);
615 // Don't write RF23/RF24 to make a difference between 87S C cut and D cut. asked by SD3 stevenl.
616 RF_WriteReg(dev, 0x0a, 0x0001); mdelay(1);
617 RF_WriteReg(dev, 0x0b, 0x0418); mdelay(1);
620 RF_WriteReg(dev, 0x0c, 0x0fbe); mdelay(1);
621 RF_WriteReg(dev, 0x0d, 0x0008); mdelay(1);
622 RF_WriteReg(dev, 0x0e, 0x0807); mdelay(1); // RX LO buffer
624 RF_WriteReg(dev, 0x0c, 0x0fbe); mdelay(1);
625 RF_WriteReg(dev, 0x0d, 0x0008); mdelay(1);
626 RF_WriteReg(dev, 0x0e, 0x0806); mdelay(1); // RX LO buffer
629 RF_WriteReg(dev, 0x0f, 0x0acc); mdelay(1);
631 RF_WriteReg(dev, 0x00, 0x01d7); mdelay(1);// 6
633 RF_WriteReg(dev, 0x03, 0x0e00); mdelay(1);
634 RF_WriteReg(dev, 0x04, 0x0e50); mdelay(1);
637 RF_WriteReg(dev, 0x01, i); mdelay(1);
638 RF_WriteReg(dev, 0x02, ZEBRA_RF_RX_GAIN_TABLE[i]); mdelay(1);
641 RF_WriteReg(dev, 0x05, 0x0203); mdelay(1); /// 203, 343
642 RF_WriteReg(dev, 0x06, 0x0200); mdelay(1); // 400
644 RF_WriteReg(dev, 0x00, 0x0137); mdelay(1); // switch to reg16-reg30, and HSSI disable 137
645 mdelay(10); // Deay 10 ms. //0xfd
647 RF_WriteReg(dev, 0x0d, 0x0008); mdelay(1); // Z4 synthesizer loop filter setting, 392
648 mdelay(10); // Deay 10 ms. //0xfd
650 RF_WriteReg(dev, 0x00, 0x0037); mdelay(1); // switch to reg0-reg15, and HSSI disable
651 mdelay(10); // Deay 10 ms. //0xfd
653 RF_WriteReg(dev, 0x04, 0x0160); mdelay(1); // CBC on, Tx Rx disable, High gain
654 mdelay(10); // Deay 10 ms. //0xfd
656 RF_WriteReg(dev, 0x07, 0x0080); mdelay(1); // Z4 setted channel 1
657 mdelay(10); // Deay 10 ms. //0xfd
659 RF_WriteReg(dev, 0x02, 0x088D); mdelay(1); // LC calibration
660 mdelay(200); // Deay 200 ms. //0xfd
661 mdelay(10); // Deay 10 ms. //0xfd
662 mdelay(10); // Deay 10 ms. //0xfd
664 RF_WriteReg(dev, 0x00, 0x0137); mdelay(1); // switch to reg16-reg30 137, and HSSI disable 137
665 mdelay(10); // Deay 10 ms. //0xfd
667 RF_WriteReg(dev, 0x07, 0x0000); mdelay(1);
668 RF_WriteReg(dev, 0x07, 0x0180); mdelay(1);
669 RF_WriteReg(dev, 0x07, 0x0220); mdelay(1);
670 RF_WriteReg(dev, 0x07, 0x03E0); mdelay(1);
672 // DAC calibration off 20070702
673 RF_WriteReg(dev, 0x06, 0x00c1); mdelay(1);
674 RF_WriteReg(dev, 0x0a, 0x0001); mdelay(1);
676 // For crystal calibration, added by Roger, 2007.12.11.
677 if( priv->bXtalCalibration ) // reg 30.
678 { // enable crystal calibration.
679 // RF Reg[30], (1)Xin:[12:9], Xout:[8:5], addr[4:0].
680 // (2)PA Pwr delay timer[15:14], default: 2.4us, set BIT15=0
681 // (3)RF signal on/off when calibration[13], default: on, set BIT13=0.
682 // So we should minus 4 BITs offset.
683 RF_WriteReg(dev, 0x0f, (priv->XtalCal_Xin<<5)|(priv->XtalCal_Xout<<1)|BIT11|BIT9); mdelay(1);
684 printk("ZEBRA_Config_85BASIC_HardCode(): (%02x)\n",
685 (priv->XtalCal_Xin<<5) | (priv->XtalCal_Xout<<1) | BIT11| BIT9);
688 { // using default value. Xin=6, Xout=6.
689 RF_WriteReg(dev, 0x0f, 0x0acc); mdelay(1);
693 RF_WriteReg(dev, 0x00, 0x00bf); mdelay(1); // switch to reg0-reg15, and HSSI enable
694 RF_WriteReg(dev, 0x0d, 0x08df); mdelay(1); // Rx BB start calibration, 00c//+edward
695 RF_WriteReg(dev, 0x02, 0x004d); mdelay(1); // temperature meter off
696 RF_WriteReg(dev, 0x04, 0x0975); mdelay(1); // Rx mode
697 mdelay(10); // Deay 10 ms. //0xfe
698 mdelay(10); // Deay 10 ms. //0xfe
699 mdelay(10); // Deay 10 ms. //0xfe
700 RF_WriteReg(dev, 0x00, 0x0197); mdelay(1); // Rx mode//+edward
701 RF_WriteReg(dev, 0x05, 0x05ab); mdelay(1); // Rx mode//+edward
702 RF_WriteReg(dev, 0x00, 0x009f); mdelay(1); // Rx mode//+edward
704 RF_WriteReg(dev, 0x01, 0x0000); mdelay(1); // Rx mode//+edward
705 RF_WriteReg(dev, 0x02, 0x0000); mdelay(1); // Rx mode//+edward
706 //power save parameters.
707 u1b24E = read_nic_byte(dev, 0x24E);
708 write_nic_byte(dev, 0x24E, (u1b24E & (~(BIT5|BIT6))));
710 //=============================================================================
712 //=============================================================================
714 //=============================================================================
716 /* [POWER SAVE] Power Saving Parameters by jong. 2007-11-27
717 CCK reg0x00[7]=1'b1 :power saving for TX (default)
718 CCK reg0x00[6]=1'b1: power saving for RX (default)
719 CCK reg0x06[4]=1'b1: turn off channel estimation related circuits if not doing channel estimation.
720 CCK reg0x06[3]=1'b1: turn off unused circuits before cca = 1
721 CCK reg0x06[2]=1'b1: turn off cck's circuit if macrst =0
724 write_phy_cck(dev,0x00,0xc8);
725 write_phy_cck(dev,0x06,0x1c);
726 write_phy_cck(dev,0x10,0x78);
727 write_phy_cck(dev,0x2e,0xd0);
728 write_phy_cck(dev,0x2f,0x06);
729 write_phy_cck(dev,0x01,0x46);
732 write_nic_byte(dev, CCK_TXAGC, 0x10);
733 write_nic_byte(dev, OFDM_TXAGC, 0x1B);
734 write_nic_byte(dev, ANTSEL, 0x03);
738 //=============================================================================
740 //=============================================================================
742 write_phy_ofdm(dev, 0x00, 0x12);
744 for (i=0; i<128; i++)
747 data = ZEBRA_AGC[i+1];
749 data = data | 0x0000008F;
751 addr = i + 0x80; //enable writing AGC table
753 addr = addr | 0x0000008E;
755 WriteBBPortUchar(dev, data);
756 WriteBBPortUchar(dev, addr);
757 WriteBBPortUchar(dev, 0x0000008E);
760 PlatformIOWrite4Byte( dev, PhyAddr, 0x00001080); // Annie, 2006-05-05
762 //=============================================================================
764 //=============================================================================
766 //=============================================================================
771 u4bRegValue=OFDM_CONFIG[i];
773 WriteBBPortUchar(dev,
775 (u4bRegOffset & 0x7f) |
776 ((u4bRegValue & 0xff) << 8)));
779 //=============================================================================
781 //=============================================================================
783 // Config Sw/Hw Combinational Antenna Diversity. Added by Roger, 2008.02.26.
784 SetAntennaConfig87SE(dev, priv->bDefaultAntenna1, priv->bSwAntennaDiverity);
792 struct net_device *dev
795 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
798 if(priv->eRFPowerState != eRfOn)
800 //Don't access BB/RF under disable PLL situation.
801 //RT_TRACE(COMP_DIG, DBG_LOUD, ("UpdateInitialGain - pHalData->eRFPowerState!=eRfOn\n"));
802 // Back to the original state
803 priv->InitialGain= priv->InitialGainBackUp;
807 switch (priv->InitialGain) {
808 case 1: /* m861dBm */
809 write_phy_ofdm(dev, 0x17, 0x26); mdelay(1);
810 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
811 write_phy_ofdm(dev, 0x05, 0xfa); mdelay(1);
814 case 2: /* m862dBm */
815 write_phy_ofdm(dev, 0x17, 0x36); mdelay(1);
816 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
817 write_phy_ofdm(dev, 0x05, 0xfa); mdelay(1);
820 case 3: /* m863dBm */
821 write_phy_ofdm(dev, 0x17, 0x36); mdelay(1);
822 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
823 write_phy_ofdm(dev, 0x05, 0xfb); mdelay(1);
826 case 4: /* m864dBm */
827 write_phy_ofdm(dev, 0x17, 0x46); mdelay(1);
828 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
829 write_phy_ofdm(dev, 0x05, 0xfb); mdelay(1);
833 write_phy_ofdm(dev, 0x17, 0x46); mdelay(1);
834 write_phy_ofdm(dev, 0x24, 0x96); mdelay(1);
835 write_phy_ofdm(dev, 0x05, 0xfb); mdelay(1);
839 write_phy_ofdm(dev, 0x17, 0x56); mdelay(1);
840 write_phy_ofdm(dev, 0x24, 0x96); mdelay(1);
841 write_phy_ofdm(dev, 0x05, 0xfc); mdelay(1);
845 write_phy_ofdm(dev, 0x17, 0x56); mdelay(1);
846 write_phy_ofdm(dev, 0x24, 0xa6); mdelay(1);
847 write_phy_ofdm(dev, 0x05, 0xfc); mdelay(1);
851 write_phy_ofdm(dev, 0x17, 0x66); mdelay(1);
852 write_phy_ofdm(dev, 0x24, 0xb6); mdelay(1);
853 write_phy_ofdm(dev, 0x05, 0xfc); mdelay(1);
857 write_phy_ofdm(dev, 0x17, 0x26); mdelay(1);
858 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
859 write_phy_ofdm(dev, 0x05, 0xfa); mdelay(1);
865 // Tx Power tracking mechanism routine on 87SE.
866 // Created by Roger, 2007.12.11.
869 InitTxPwrTracking87SE(
870 struct net_device *dev
875 u4bRfReg = RF_ReadReg(dev, 0x02);
877 // Enable Thermal meter indication.
878 RF_WriteReg(dev, 0x02, u4bRfReg|PWR_METER_EN); mdelay(1);
883 struct net_device *dev
886 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
887 write_nic_dword(dev, RCR, priv->ReceiveConfig);
888 priv->RFProgType = read_nic_byte(dev, CONFIG4) & 0x03;
890 ZEBRA_Config_85BASIC_HardCode(dev);
892 // Set default initial gain state to 4, approved by SD3 DZ, by Bruce, 2007-06-06.
893 if(priv->bDigMechanism)
895 if(priv->InitialGain == 0)
896 priv->InitialGain = 4;
900 // Enable thermal meter indication to implement TxPower tracking on 87SE.
901 // We initialize thermal meter here to avoid unsuccessful configuration.
902 // Added by Roger, 2007.12.11.
904 if(priv->bTxPowerTrack)
905 InitTxPwrTracking87SE(dev);
908 priv->InitialGainBackUp= priv->InitialGain;
909 UpdateInitialGain(dev);
916 struct net_device *dev
919 //RTL8185_TODO: Determine Retrylimit, TxAGC, AutoRateFallback control.
920 u8 bUNIVERSAL_CONTROL_RL = 0;
921 u8 bUNIVERSAL_CONTROL_AGC = 1;
922 u8 bUNIVERSAL_CONTROL_ANT = 1;
923 u8 bAUTO_RATE_FALLBACK_CTL = 1;
925 write_nic_word(dev, BRSR, 0x0fff);
927 val8 = read_nic_byte(dev, CW_CONF);
929 if(bUNIVERSAL_CONTROL_RL)
934 write_nic_byte(dev, CW_CONF, val8);
937 val8 = read_nic_byte(dev, TXAGC_CTL);
938 if(bUNIVERSAL_CONTROL_AGC)
940 write_nic_byte(dev, CCK_TXAGC, 128);
941 write_nic_byte(dev, OFDM_TXAGC, 128);
950 write_nic_byte(dev, TXAGC_CTL, val8);
952 // Tx Antenna including Feedback control
953 val8 = read_nic_byte(dev, TXAGC_CTL );
955 if(bUNIVERSAL_CONTROL_ANT)
957 write_nic_byte(dev, ANTSEL, 0x00);
962 val8 = val8 & (val8|0x02); //xiong-2006-11-15
965 write_nic_byte(dev, TXAGC_CTL, val8);
967 // Auto Rate fallback control
968 val8 = read_nic_byte(dev, RATE_FALLBACK);
970 if( bAUTO_RATE_FALLBACK_CTL )
972 val8 |= RATE_FALLBACK_CTL_ENABLE | RATE_FALLBACK_CTL_AUTO_STEP1;
974 // <RJ_TODO_8185B> We shall set up the ARFR according to user's setting.
975 PlatformIOWrite2Byte(dev, ARFR, 0x0fff); //set 1M ~ 54Mbps.
977 write_nic_byte(dev, RATE_FALLBACK, val8);
981 MacConfig_85BASIC_HardCode(
982 struct net_device *dev)
984 //============================================================================
986 //============================================================================
989 u32 u4bRegOffset, u4bRegValue,u4bPageIndex = 0;
992 nLinesRead=sizeof(MAC_REG_TABLE)/2;
994 for(i = 0; i < nLinesRead; i++) //nLinesRead=101
996 u4bRegOffset=MAC_REG_TABLE[i][0];
997 u4bRegValue=MAC_REG_TABLE[i][1];
999 if(u4bRegOffset == 0x5e)
1001 u4bPageIndex = u4bRegValue;
1005 u4bRegOffset |= (u4bPageIndex << 8);
1007 write_nic_byte(dev, u4bRegOffset, (u8)u4bRegValue);
1009 //============================================================================
1014 struct net_device *dev)
1018 MacConfig_85BASIC_HardCode(dev);
1020 //============================================================================
1022 // Follow TID_AC_MAP of WMac.
1023 write_nic_word(dev, TID_AC_MAP, 0xfa50);
1025 // Interrupt Migration, Jong suggested we use set 0x0000 first, 2005.12.14, by rcnjko.
1026 write_nic_word(dev, IntMig, 0x0000);
1028 // Prevent TPC to cause CRC error. Added by Annie, 2006-06-10.
1029 PlatformIOWrite4Byte(dev, 0x1F0, 0x00000000);
1030 PlatformIOWrite4Byte(dev, 0x1F4, 0x00000000);
1031 PlatformIOWrite1Byte(dev, 0x1F8, 0x00);
1033 // Asked for by SD3 CM Lin, 2006.06.27, by rcnjko.
1034 // power save parameter based on "87SE power save parameters 20071127.doc", as follow.
1036 //Enable DA10 TX power saving
1037 u1DA = read_nic_byte(dev, PHYPR);
1038 write_nic_byte(dev, PHYPR, (u1DA | BIT2) );
1041 write_nic_word(dev, 0x360, 0x1000);
1042 write_nic_word(dev, 0x362, 0x1000);
1045 write_nic_word(dev, 0x370, 0x0560);
1046 write_nic_word(dev, 0x372, 0x0560);
1047 write_nic_word(dev, 0x374, 0x0DA4);
1048 write_nic_word(dev, 0x376, 0x0DA4);
1049 write_nic_word(dev, 0x378, 0x0560);
1050 write_nic_word(dev, 0x37A, 0x0560);
1051 write_nic_word(dev, 0x37C, 0x00EC);
1052 write_nic_word(dev, 0x37E, 0x00EC);//+edward
1053 write_nic_byte(dev, 0x24E,0x01);
1057 GetSupportedWirelessMode8185(
1058 struct net_device *dev
1061 u8 btSupportedWirelessMode = 0;
1063 btSupportedWirelessMode = (WIRELESS_MODE_B | WIRELESS_MODE_G);
1064 return btSupportedWirelessMode;
1068 ActUpdateChannelAccessSetting(
1069 struct net_device *dev,
1070 WIRELESS_MODE WirelessMode,
1071 PCHANNEL_ACCESS_SETTING ChnlAccessSetting
1074 struct r8180_priv *priv = ieee80211_priv(dev);
1075 struct ieee80211_device *ieee = priv->ieee80211;
1078 u8 bFollowLegacySetting = 0;
1083 // TODO: We still don't know how to set up these registers, just follow WMAC to
1084 // verify 8185B FPAG.
1087 // Jong said CWmin/CWmax register are not functional in 8185B,
1088 // so we shall fill channel access realted register into AC parameter registers,
1091 ChnlAccessSetting->SIFS_Timer = 0x22; // Suggested by Jong, 2005.12.08.
1092 ChnlAccessSetting->DIFS_Timer = 0x1C; // 2006.06.02, by rcnjko.
1093 ChnlAccessSetting->SlotTimeTimer = 9; // 2006.06.02, by rcnjko.
1094 ChnlAccessSetting->EIFS_Timer = 0x5B; // Suggested by wcchu, it is the default value of EIFS register, 2005.12.08.
1095 ChnlAccessSetting->CWminIndex = 3; // 2006.06.02, by rcnjko.
1096 ChnlAccessSetting->CWmaxIndex = 7; // 2006.06.02, by rcnjko.
1098 write_nic_byte(dev, SIFS, ChnlAccessSetting->SIFS_Timer);
1099 write_nic_byte(dev, SLOT, ChnlAccessSetting->SlotTimeTimer); // Rewrited from directly use PlatformEFIOWrite1Byte(), by Annie, 2006-03-29.
1101 u1bAIFS = aSifsTime + (2 * ChnlAccessSetting->SlotTimeTimer );
1103 write_nic_byte(dev, EIFS, ChnlAccessSetting->EIFS_Timer);
1105 write_nic_byte(dev, AckTimeOutReg, 0x5B); // <RJ_EXPR_QOS> Suggested by wcchu, it is the default value of EIFS register, 2005.12.08.
1108 bFollowLegacySetting = 1;
1112 // this setting is copied from rtl8187B. xiong-2006-11-13
1113 if(bFollowLegacySetting)
1118 // Follow 802.11 seeting to AC parameter, all AC shall use the same parameter.
1119 // 2005.12.01, by rcnjko.
1121 AcParam.longData = 0;
1122 AcParam.f.AciAifsn.f.AIFSN = 2; // Follow 802.11 DIFS.
1123 AcParam.f.AciAifsn.f.ACM = 0;
1124 AcParam.f.Ecw.f.ECWmin = ChnlAccessSetting->CWminIndex; // Follow 802.11 CWmin.
1125 AcParam.f.Ecw.f.ECWmax = ChnlAccessSetting->CWmaxIndex; // Follow 802.11 CWmax.
1126 AcParam.f.TXOPLimit = 0;
1128 //lzm reserved 080826
1129 // For turbo mode setting. port from 87B by Isaiah 2008-08-01
1130 if( ieee->current_network.Turbo_Enable == 1 )
1131 AcParam.f.TXOPLimit = 0x01FF;
1132 // For 87SE with Intel 4965 Ad-Hoc mode have poor throughput (19MB)
1133 if (ieee->iw_mode == IW_MODE_ADHOC)
1134 AcParam.f.TXOPLimit = 0x0020;
1136 for(eACI = 0; eACI < AC_MAX; eACI++)
1138 AcParam.f.AciAifsn.f.ACI = (u8)eACI;
1140 PAC_PARAM pAcParam = (PAC_PARAM)(&AcParam);
1145 // Retrive paramters to udpate.
1146 eACI = pAcParam->f.AciAifsn.f.ACI;
1147 u1bAIFS = pAcParam->f.AciAifsn.f.AIFSN * ChnlAccessSetting->SlotTimeTimer + aSifsTime;
1148 u4bAcParam = ( (((u32)(pAcParam->f.TXOPLimit)) << AC_PARAM_TXOP_LIMIT_OFFSET) |
1149 (((u32)(pAcParam->f.Ecw.f.ECWmax)) << AC_PARAM_ECW_MAX_OFFSET) |
1150 (((u32)(pAcParam->f.Ecw.f.ECWmin)) << AC_PARAM_ECW_MIN_OFFSET) |
1151 (((u32)u1bAIFS) << AC_PARAM_AIFS_OFFSET));
1156 //write_nic_dword(dev, AC_BK_PARAM, u4bAcParam);
1160 //write_nic_dword(dev, AC_BE_PARAM, u4bAcParam);
1164 //write_nic_dword(dev, AC_VI_PARAM, u4bAcParam);
1168 //write_nic_dword(dev, AC_VO_PARAM, u4bAcParam);
1172 DMESGW( "SetHwReg8185(): invalid ACI: %d !\n", eACI);
1177 // If it is set, immediately set ACM control bit to downgrading AC for passing WMM testplan. Annie, 2005-12-13.
1179 PACI_AIFSN pAciAifsn = (PACI_AIFSN)(&pAcParam->f.AciAifsn);
1180 AC_CODING eACI = pAciAifsn->f.ACI;
1183 //for 8187B AsynIORead issue
1185 if( pAciAifsn->f.ACM )
1190 AcmCtrl |= (BEQ_ACM_EN|BEQ_ACM_CTL|ACM_HW_EN); // or 0x21
1194 AcmCtrl |= (VIQ_ACM_EN|VIQ_ACM_CTL|ACM_HW_EN); // or 0x42
1198 AcmCtrl |= (VOQ_ACM_EN|VOQ_ACM_CTL|ACM_HW_EN); // or 0x84
1202 DMESGW("SetHwReg8185(): [HW_VAR_ACM_CTRL] ACM set failed: eACI is %d\n", eACI );
1211 AcmCtrl &= ( (~BEQ_ACM_EN) & (~BEQ_ACM_CTL) & (~ACM_HW_EN) ); // and 0xDE
1215 AcmCtrl &= ( (~VIQ_ACM_EN) & (~VIQ_ACM_CTL) & (~ACM_HW_EN) ); // and 0xBD
1219 AcmCtrl &= ( (~VOQ_ACM_EN) & (~VOQ_ACM_CTL) & (~ACM_HW_EN) ); // and 0x7B
1226 write_nic_byte(dev, ACM_CONTROL, 0);
1234 ActSetWirelessMode8185(
1235 struct net_device *dev,
1239 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1240 struct ieee80211_device *ieee = priv->ieee80211;
1241 u8 btSupportedWirelessMode = GetSupportedWirelessMode8185(dev);
1243 if( (btWirelessMode & btSupportedWirelessMode) == 0 )
1244 { // Don't switch to unsupported wireless mode, 2006.02.15, by rcnjko.
1245 DMESGW("ActSetWirelessMode8185(): WirelessMode(%d) is not supported (%d)!\n",
1246 btWirelessMode, btSupportedWirelessMode);
1250 // 1. Assign wireless mode to swtich if necessary.
1251 if (btWirelessMode == WIRELESS_MODE_AUTO)
1253 if((btSupportedWirelessMode & WIRELESS_MODE_A))
1255 btWirelessMode = WIRELESS_MODE_A;
1257 else if((btSupportedWirelessMode & WIRELESS_MODE_G))
1259 btWirelessMode = WIRELESS_MODE_G;
1261 else if((btSupportedWirelessMode & WIRELESS_MODE_B))
1263 btWirelessMode = WIRELESS_MODE_B;
1267 DMESGW("ActSetWirelessMode8185(): No valid wireless mode supported, btSupportedWirelessMode(%x)!!!\n",
1268 btSupportedWirelessMode);
1269 btWirelessMode = WIRELESS_MODE_B;
1273 /* 2. Swtich band: RF or BB specific actions,
1274 * for example, refresh tables in omc8255, or change initial gain if necessary.
1275 * Nothing to do for Zebra to switch band.
1276 * Update current wireless mode if we swtich to specified band successfully. */
1277 ieee->mode = (WIRELESS_MODE)btWirelessMode;
1279 // 3. Change related setting.
1280 if( ieee->mode == WIRELESS_MODE_A ){
1281 DMESG("WIRELESS_MODE_A\n");
1283 else if( ieee->mode == WIRELESS_MODE_B ){
1284 DMESG("WIRELESS_MODE_B\n");
1286 else if( ieee->mode == WIRELESS_MODE_G ){
1287 DMESG("WIRELESS_MODE_G\n");
1289 ActUpdateChannelAccessSetting( dev, ieee->mode, &priv->ChannelAccessSetting);
1292 void rtl8185b_irq_enable(struct net_device *dev)
1294 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1296 priv->irq_enabled = 1;
1297 write_nic_dword(dev, IMR, priv->IntrMask);
1299 //by amy for power save
1301 DrvIFIndicateDisassociation(
1302 struct net_device *dev,
1306 // nothing is needed after disassociation request.
1310 struct net_device *dev
1313 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1316 DrvIFIndicateDisassociation(dev, unspec_reason);
1317 for(i=0;i<6;i++) priv->ieee80211->current_network.bssid[i] = 0x55;
1319 priv->ieee80211->state = IEEE80211_NOLINK;
1323 // Vista add a Adhoc profile, HW radio off untill OID_DOT11_RESET_REQUEST
1324 // Driver would set MSR=NO_LINK, then HW Radio ON, MgntQueue Stuck.
1325 // Because Bcn DMA isn't complete, mgnt queue would stuck until Bcn packet send.
1327 // Disable Beacon Queue Own bit, suggested by jong
1328 ieee80211_stop_send_beacons(priv->ieee80211);
1330 priv->ieee80211->link_change(dev);
1331 notify_wx_assoc_event(priv->ieee80211);
1334 MlmeDisassociateRequest(
1335 struct net_device *dev,
1340 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1343 SendDisassociation(priv->ieee80211, asSta, asRsn );
1345 if( memcmp(priv->ieee80211->current_network.bssid, asSta, 6 ) == 0 ){
1346 //ShuChen TODO: change media status.
1347 //ShuChen TODO: What to do when disassociate.
1348 DrvIFIndicateDisassociation(dev, unspec_reason);
1351 for(i=0;i<6;i++) priv->ieee80211->current_network.bssid[i] = 0x22;
1352 ieee80211_disassociate(priv->ieee80211);
1359 struct net_device *dev,
1363 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1366 // Commented out by rcnjko, 2005.01.27:
1367 // I move SecClearAllKeys() to MgntActSet_802_11_DISASSOCIATE().
1369 // //2004/09/15, kcwu, the key should be cleared, or the new handshaking will not success
1371 // In WPA WPA2 need to Clear all key ... because new key will set after new handshaking.
1372 // 2004.10.11, by rcnjko.
1373 MlmeDisassociateRequest( dev, priv->ieee80211->current_network.bssid, asRsn );
1375 priv->ieee80211->state = IEEE80211_NOLINK;
1379 struct net_device *dev,
1383 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1385 // Schedule an workitem to wake up for ps mode, 070109, by rcnjko.
1388 if(IS_DOT11D_ENABLE(priv->ieee80211))
1389 Dot11d_Reset(priv->ieee80211);
1390 // In adhoc mode, update beacon frame.
1391 if( priv->ieee80211->state == IEEE80211_LINKED )
1393 if( priv->ieee80211->iw_mode == IW_MODE_ADHOC )
1395 MgntDisconnectIBSS(dev);
1397 if( priv->ieee80211->iw_mode == IW_MODE_INFRA )
1399 // We clear key here instead of MgntDisconnectAP() because that
1400 // MgntActSet_802_11_DISASSOCIATE() is an interface called by OS,
1401 // e.g. OID_802_11_DISASSOCIATE in Windows while as MgntDisconnectAP() is
1402 // used to handle disassociation related things to AP, e.g. send Disassoc
1403 // frame to AP. 2005.01.27, by rcnjko.
1404 MgntDisconnectAP(dev, asRsn);
1406 // Inidicate Disconnect, 2005.02.23, by rcnjko.
1412 // Chang RF Power State.
1413 // Note that, only MgntActSet_RF_State() is allowed to set HW_VAR_RF_STATE.
1420 struct net_device *dev,
1421 RT_RF_POWER_STATE eRFPowerState
1424 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1425 bool bResult = false;
1427 if(eRFPowerState == priv->eRFPowerState)
1432 bResult = SetZebraRFPowerState8185(dev, eRFPowerState);
1437 HalEnableRx8185Dummy(
1438 struct net_device *dev
1443 HalDisableRx8185Dummy(
1444 struct net_device *dev
1450 MgntActSet_RF_State(
1451 struct net_device *dev,
1452 RT_RF_POWER_STATE StateToSet,
1456 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1457 bool bActionAllowed = false;
1458 bool bConnectBySSID = false;
1459 RT_RF_POWER_STATE rtState;
1460 u16 RFWaitCounter = 0;
1463 // Prevent the race condition of RF state change. By Bruce, 2007-11-28.
1464 // Only one thread can change the RF state at one time, and others should wait to be executed.
1468 spin_lock_irqsave(&priv->rf_ps_lock,flag);
1469 if(priv->RFChangeInProgress)
1471 spin_unlock_irqrestore(&priv->rf_ps_lock,flag);
1472 // Set RF after the previous action is done.
1473 while(priv->RFChangeInProgress)
1476 udelay(1000); // 1 ms
1478 // Wait too long, return FALSE to avoid to be stuck here.
1479 if(RFWaitCounter > 1000) // 1sec
1481 printk("MgntActSet_RF_State(): Wait too long to set RF\n");
1482 // TODO: Reset RF state?
1489 priv->RFChangeInProgress = true;
1490 spin_unlock_irqrestore(&priv->rf_ps_lock,flag);
1494 rtState = priv->eRFPowerState;
1500 // Turn On RF no matter the IPS setting because we need to update the RF state to Ndis under Vista, or
1501 // the Windows does not allow the driver to perform site survey any more. By Bruce, 2007-10-02.
1503 priv->RfOffReason &= (~ChangeSource);
1505 if(! priv->RfOffReason)
1507 priv->RfOffReason = 0;
1508 bActionAllowed = true;
1510 if(rtState == eRfOff && ChangeSource >=RF_CHANGE_BY_HW && !priv->bInHctTest)
1512 bConnectBySSID = true;
1520 // 070125, rcnjko: we always keep connected in AP mode.
1522 if (priv->RfOffReason > RF_CHANGE_BY_IPS)
1526 // Disconnect to current BSS when radio off. Asked by QuanTa.
1530 // Calling MgntDisconnect() instead of MgntActSet_802_11_DISASSOCIATE(),
1531 // because we do NOT need to set ssid to dummy ones.
1533 MgntDisconnect( dev, disas_lv_ss );
1535 // Clear content of bssDesc[] and bssDesc4Query[] to avoid reporting old bss to UI.
1538 priv->RfOffReason |= ChangeSource;
1539 bActionAllowed = true;
1542 priv->RfOffReason |= ChangeSource;
1543 bActionAllowed = true;
1551 // Config HW to the specified mode.
1552 SetRFPowerState(dev, StateToSet);
1555 if(StateToSet == eRfOn)
1557 HalEnableRx8185Dummy(dev);
1560 // by amy not supported
1564 else if(StateToSet == eRfOff)
1566 HalDisableRx8185Dummy(dev);
1570 // Release RF spinlock
1571 spin_lock_irqsave(&priv->rf_ps_lock,flag);
1572 priv->RFChangeInProgress = false;
1573 spin_unlock_irqrestore(&priv->rf_ps_lock,flag);
1574 return bActionAllowed;
1578 struct net_device *dev
1581 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1583 // This flag "bSwRfProcessing", indicates the status of IPS procedure, should be set if the IPS workitem
1584 // is really scheduled.
1585 // The old code, sets this flag before scheduling the IPS workitem and however, at the same time the
1586 // previous IPS workitem did not end yet, fails to schedule the current workitem. Thus, bSwRfProcessing
1587 // blocks the IPS procedure of switching RF.
1589 priv->bSwRfProcessing = true;
1591 MgntActSet_RF_State(dev, priv->eInactivePowerState, RF_CHANGE_BY_IPS);
1594 // To solve CAM values miss in RF OFF, rewrite CAM values after RF ON. By Bruce, 2007-09-20.
1597 priv->bSwRfProcessing = false;
1602 // Enter the inactive power save mode. RF will be off
1606 struct net_device *dev
1609 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1610 RT_RF_POWER_STATE rtState;
1611 if (priv->bInactivePs)
1613 rtState = priv->eRFPowerState;
1616 // Do not enter IPS in the following conditions:
1617 // (1) RF is already OFF or Sleep
1618 // (2) bSwRfProcessing (indicates the IPS is still under going)
1619 // (3) Connectted (only disconnected can trigger IPS)
1620 // (4) IBSS (send Beacon)
1621 // (5) AP mode (send Beacon)
1623 if (rtState == eRfOn && !priv->bSwRfProcessing
1624 && (priv->ieee80211->state != IEEE80211_LINKED ))
1626 priv->eInactivePowerState = eRfOff;
1627 InactivePowerSave(dev);
1633 struct net_device *dev
1636 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1637 RT_RF_POWER_STATE rtState;
1638 if (priv->bInactivePs)
1640 rtState = priv->eRFPowerState;
1641 if ((rtState == eRfOff || rtState == eRfSleep) && (!priv->bSwRfProcessing) && priv->RfOffReason <= RF_CHANGE_BY_IPS)
1643 priv->eInactivePowerState = eRfOn;
1644 InactivePowerSave(dev);
1649 void rtl8185b_adapter_start(struct net_device *dev)
1651 struct r8180_priv *priv = ieee80211_priv(dev);
1652 struct ieee80211_device *ieee = priv->ieee80211;
1654 u8 SupportedWirelessMode;
1655 u8 InitWirelessMode;
1656 u8 bInvalidWirelessMode = 0;
1662 write_nic_byte(dev,0x24e, (BIT5|BIT6|BIT0));
1665 priv->dma_poll_mask = 0;
1666 priv->dma_poll_stop_mask = 0;
1668 HwConfigureRTL8185(dev);
1669 write_nic_dword(dev, MAC0, ((u32*)dev->dev_addr)[0]);
1670 write_nic_word(dev, MAC4, ((u32*)dev->dev_addr)[1] & 0xffff );
1671 write_nic_byte(dev, MSR, read_nic_byte(dev, MSR) & 0xf3); // default network type to 'No Link'
1672 write_nic_word(dev, BcnItv, 100);
1673 write_nic_word(dev, AtimWnd, 2);
1674 PlatformIOWrite2Byte(dev, FEMR, 0xFFFF);
1675 write_nic_byte(dev, WPA_CONFIG, 0);
1676 MacConfig_85BASIC(dev);
1677 // Override the RFSW_CTRL (MAC offset 0x272-0x273), 2006.06.07, by rcnjko.
1678 // BT_DEMO_BOARD type
1679 PlatformIOWrite2Byte(dev, RFSW_CTRL, 0x569a);
1681 //-----------------------------------------------------------------------------
1682 // Set up PHY related.
1683 //-----------------------------------------------------------------------------
1684 // Enable Config3.PARAM_En to revise AnaaParm.
1685 write_nic_byte(dev, CR9346, 0xc0); // enable config register write
1686 tmpu8 = read_nic_byte(dev, CONFIG3);
1687 write_nic_byte(dev, CONFIG3, (tmpu8 |CONFIG3_PARM_En) );
1688 // Turn on Analog power.
1689 // Asked for by William, otherwise, MAC 3-wire can't work, 2006.06.27, by rcnjko.
1690 write_nic_dword(dev, ANAPARAM2, ANAPARM2_ASIC_ON);
1691 write_nic_dword(dev, ANAPARAM, ANAPARM_ASIC_ON);
1692 write_nic_word(dev, ANAPARAM3, 0x0010);
1694 write_nic_byte(dev, CONFIG3, tmpu8);
1695 write_nic_byte(dev, CR9346, 0x00);
1696 // enable EEM0 and EEM1 in 9346CR
1697 btCR9346 = read_nic_byte(dev, CR9346);
1698 write_nic_byte(dev, CR9346, (btCR9346|0xC0) );
1700 // B cut use LED1 to control HW RF on/off
1701 TmpU1b = read_nic_byte(dev, CONFIG5);
1702 TmpU1b = TmpU1b & ~BIT3;
1703 write_nic_byte(dev,CONFIG5, TmpU1b);
1705 // disable EEM0 and EEM1 in 9346CR
1706 btCR9346 &= ~(0xC0);
1707 write_nic_byte(dev, CR9346, btCR9346);
1709 //Enable Led (suggested by Jong)
1710 // B-cut RF Radio on/off 5e[3]=0
1711 btPSR = read_nic_byte(dev, PSR);
1712 write_nic_byte(dev, PSR, (btPSR | BIT3));
1713 // setup initial timing for RFE.
1714 write_nic_word(dev, RFPinsOutput, 0x0480);
1715 SetOutputEnableOfRfPins(dev);
1716 write_nic_word(dev, RFPinsSelect, 0x2488);
1721 // We assume RegWirelessMode has already been initialized before,
1722 // however, we has to validate the wireless mode here and provide a
1723 // reasonable initialized value if necessary. 2005.01.13, by rcnjko.
1724 SupportedWirelessMode = GetSupportedWirelessMode8185(dev);
1725 if( (ieee->mode != WIRELESS_MODE_B) &&
1726 (ieee->mode != WIRELESS_MODE_G) &&
1727 (ieee->mode != WIRELESS_MODE_A) &&
1728 (ieee->mode != WIRELESS_MODE_AUTO))
1729 { // It should be one of B, G, A, or AUTO.
1730 bInvalidWirelessMode = 1;
1733 { // One of B, G, A, or AUTO.
1734 // Check if the wireless mode is supported by RF.
1735 if( (ieee->mode != WIRELESS_MODE_AUTO) &&
1736 (ieee->mode & SupportedWirelessMode) == 0 )
1738 bInvalidWirelessMode = 1;
1742 if(bInvalidWirelessMode || ieee->mode==WIRELESS_MODE_AUTO)
1743 { // Auto or other invalid value.
1744 // Assigne a wireless mode to initialize.
1745 if((SupportedWirelessMode & WIRELESS_MODE_A))
1747 InitWirelessMode = WIRELESS_MODE_A;
1749 else if((SupportedWirelessMode & WIRELESS_MODE_G))
1751 InitWirelessMode = WIRELESS_MODE_G;
1753 else if((SupportedWirelessMode & WIRELESS_MODE_B))
1755 InitWirelessMode = WIRELESS_MODE_B;
1759 DMESGW("InitializeAdapter8185(): No valid wireless mode supported, SupportedWirelessMode(%x)!!!\n",
1760 SupportedWirelessMode);
1761 InitWirelessMode = WIRELESS_MODE_B;
1764 // Initialize RegWirelessMode if it is not a valid one.
1765 if(bInvalidWirelessMode)
1767 ieee->mode = (WIRELESS_MODE)InitWirelessMode;
1771 { // One of B, G, A.
1772 InitWirelessMode = ieee->mode;
1774 //by amy for power save
1775 priv->eRFPowerState = eRfOff;
1776 priv->RfOffReason = 0;
1778 MgntActSet_RF_State(dev, eRfOn, 0);
1781 // If inactive power mode is enabled, disable rf while in disconnected state.
1783 if (priv->bInactivePs)
1785 MgntActSet_RF_State(dev,eRfOff, RF_CHANGE_BY_IPS);
1787 //by amy for power save
1789 ActSetWirelessMode8185(dev, (u8)(InitWirelessMode));
1791 //-----------------------------------------------------------------------------
1793 rtl8185b_irq_enable(dev);
1795 netif_start_queue(dev);
1798 void rtl8185b_rx_enable(struct net_device *dev)
1801 /* for now we accept data, management & ctl frame*/
1802 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1804 if (dev->flags & IFF_PROMISC) DMESG ("NIC in promisc mode");
1806 if(priv->ieee80211->iw_mode == IW_MODE_MONITOR || \
1807 dev->flags & IFF_PROMISC){
1808 priv->ReceiveConfig = priv->ReceiveConfig & (~RCR_APM);
1809 priv->ReceiveConfig = priv->ReceiveConfig | RCR_AAP;
1812 if(priv->ieee80211->iw_mode == IW_MODE_MONITOR){
1813 priv->ReceiveConfig = priv->ReceiveConfig | RCR_ACF | RCR_APWRMGT | RCR_AICV;
1816 if( priv->crcmon == 1 && priv->ieee80211->iw_mode == IW_MODE_MONITOR)
1817 priv->ReceiveConfig = priv->ReceiveConfig | RCR_ACRC32;
1819 write_nic_dword(dev, RCR, priv->ReceiveConfig);
1823 cmd=read_nic_byte(dev,CMD);
1824 write_nic_byte(dev,CMD,cmd | (1<<CMD_RX_ENABLE_SHIFT));
1828 void rtl8185b_tx_enable(struct net_device *dev)
1832 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1834 write_nic_dword(dev, TCR, priv->TransmitConfig);
1835 byte = read_nic_byte(dev, MSR);
1836 byte |= MSR_LINK_ENEDCA;
1837 write_nic_byte(dev, MSR, byte);
1841 cmd=read_nic_byte(dev,CMD);
1842 write_nic_byte(dev,CMD,cmd | (1<<CMD_TX_ENABLE_SHIFT));