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 panic("HwThreeWire(): CmdReg: %#X RE|WE bits are not clear!!\n", u1bTmp);
274 // RTL8187S HSSI Read/Write Function
275 u1bTmp = read_nic_byte(dev, RF_SW_CONFIG);
279 u1bTmp |= RF_SW_CFG_SI; //reg08[1]=1 Serial Interface(SI)
282 u1bTmp &= ~RF_SW_CFG_SI; //reg08[1]=0 Parallel Interface(PI)
285 write_nic_byte(dev, RF_SW_CONFIG, u1bTmp);
289 // jong: HW SI read must set reg84[3]=0.
290 u1bTmp = read_nic_byte(dev, RFPinsSelect);
292 write_nic_byte(dev, RFPinsSelect, u1bTmp );
294 // Fill up data buffer for write operation.
298 if(nDataBufBitCnt == 16)
300 write_nic_word(dev, SW_3W_DB0, *((u16*)pDataBuf));
302 else if(nDataBufBitCnt == 64) // RTL8187S shouldn't enter this case
304 write_nic_dword(dev, SW_3W_DB0, *((u32*)pDataBuf));
305 write_nic_dword(dev, SW_3W_DB1, *((u32*)(pDataBuf + 4)));
310 int ByteCnt = nDataBufBitCnt / 8;
311 //printk("%d\n",nDataBufBitCnt);
312 if ((nDataBufBitCnt % 8) != 0)
313 panic("HwThreeWire(): nDataBufBitCnt(%d) should be multiple of 8!!!\n",
316 if (nDataBufBitCnt > 64)
317 panic("HwThreeWire(): nDataBufBitCnt(%d) should <= 64!!!\n",
320 for(idx = 0; idx < ByteCnt; idx++)
322 write_nic_byte(dev, (SW_3W_DB0+idx), *(pDataBuf+idx));
330 // SI - reg274[3:0] : RF register's Address
331 write_nic_word(dev, SW_3W_DB0, *((u16*)pDataBuf) );
335 // PI - reg274[15:12] : RF register's Address
336 write_nic_word(dev, SW_3W_DB0, (*((u16*)pDataBuf)) << 12);
340 // Set up command: WE or RE.
343 write_nic_byte(dev, SW_3W_CMD1, SW_3W_CMD1_WE);
347 write_nic_byte(dev, SW_3W_CMD1, SW_3W_CMD1_RE);
350 // Check if DONE is set.
351 for(TryCnt = 0; TryCnt < TC_3W_POLL_MAX_TRY_CNT; TryCnt++)
353 u1bTmp = read_nic_byte(dev, SW_3W_CMD1);
354 if( (u1bTmp & SW_3W_CMD1_DONE) != 0 )
361 write_nic_byte(dev, SW_3W_CMD1, 0);
363 // Read back data for read operation.
368 //Serial Interface : reg363_362[11:0]
369 *((u16*)pDataBuf) = read_nic_word(dev, SI_DATA_READ) ;
373 //Parallel Interface : reg361_360[11:0]
374 *((u16*)pDataBuf) = read_nic_word(dev, PI_DATA_READ);
377 *((u16*)pDataBuf) &= 0x0FFF;
386 RF_WriteReg(struct net_device *dev, u8 offset, u32 data)
391 /* Pure HW 3-wire. */
392 data2Write = (data << 4) | (u32)(offset & 0x0f);
395 HwHSSIThreeWire(dev, (u8 *)(&data2Write), len, 1, 1);
398 u32 RF_ReadReg(struct net_device *dev, u8 offset)
404 data2Write = ((u32)(offset & 0x0f));
406 HwHSSIThreeWire(dev, (u8 *)(&data2Write), wlen, 1, 0);
407 dataRead = data2Write;
413 // by Owen on 04/07/14 for writing BB register successfully
416 struct net_device *dev,
424 UCharData = (u8)((Data & 0x0000ff00) >> 8);
425 PlatformIOWrite4Byte(dev, PhyAddr, Data);
426 //for(TimeoutCounter = 10; TimeoutCounter > 0; TimeoutCounter--)
428 PlatformIOWrite4Byte(dev, PhyAddr, Data & 0xffffff7f);
429 RegisterContent = PlatformIORead1Byte(dev, PhyDataR);
430 //if(UCharData == RegisterContent)
437 struct net_device *dev,
444 PlatformIOWrite4Byte(dev, PhyAddr, addr & 0xffffff7f);
445 RegisterContent = PlatformIORead1Byte(dev, PhyDataR);
447 return RegisterContent;
452 // Perform Antenna settings with antenna diversity on 87SE.
453 // Created by Roger, 2008.01.25.
456 SetAntennaConfig87SE(
457 struct net_device *dev,
458 u8 DefaultAnt, // 0: Main, 1: Aux.
459 bool bAntDiversity // 1:Enable, 0: Disable.
462 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
463 bool bAntennaSwitched = true;
465 //printk("SetAntennaConfig87SE(): DefaultAnt(%d), bAntDiversity(%d)\n", DefaultAnt, bAntDiversity);
467 // Threshold for antenna diversity.
468 write_phy_cck(dev, 0x0c, 0x09); // Reg0c : 09
470 if( bAntDiversity ) // Enable Antenna Diversity.
472 if( DefaultAnt == 1 ) // aux antenna
474 // Mac register, aux antenna
475 write_nic_byte(dev, ANTSEL, 0x00);
477 // Config CCK RX antenna.
478 write_phy_cck(dev, 0x11, 0xbb); // Reg11 : bb
479 write_phy_cck(dev, 0x01, 0xc7); // Reg01 : c7
481 // Config OFDM RX antenna.
482 write_phy_ofdm(dev, 0x0D, 0x54); // Reg0d : 54
483 write_phy_ofdm(dev, 0x18, 0xb2); // Reg18 : b2
485 else // use main antenna
487 // Mac register, main antenna
488 write_nic_byte(dev, ANTSEL, 0x03);
490 // Config CCK RX antenna.
491 write_phy_cck(dev, 0x11, 0x9b); // Reg11 : 9b
492 write_phy_cck(dev, 0x01, 0xc7); // Reg01 : c7
494 // Config OFDM RX antenna.
495 write_phy_ofdm(dev, 0x0d, 0x5c); // Reg0d : 5c
496 write_phy_ofdm(dev, 0x18, 0xb2); // Reg18 : b2
499 else // Disable Antenna Diversity.
501 if( DefaultAnt == 1 ) // aux Antenna
503 // Mac register, aux antenna
504 write_nic_byte(dev, ANTSEL, 0x00);
506 // Config CCK RX antenna.
507 write_phy_cck(dev, 0x11, 0xbb); // Reg11 : bb
508 write_phy_cck(dev, 0x01, 0x47); // Reg01 : 47
510 // Config OFDM RX antenna.
511 write_phy_ofdm(dev, 0x0D, 0x54); // Reg0d : 54
512 write_phy_ofdm(dev, 0x18, 0x32); // Reg18 : 32
516 // Mac register, main antenna
517 write_nic_byte(dev, ANTSEL, 0x03);
519 // Config CCK RX antenna.
520 write_phy_cck(dev, 0x11, 0x9b); // Reg11 : 9b
521 write_phy_cck(dev, 0x01, 0x47); // Reg01 : 47
523 // Config OFDM RX antenna.
524 write_phy_ofdm(dev, 0x0D, 0x5c); // Reg0d : 5c
525 write_phy_ofdm(dev, 0x18, 0x32); // Reg18 : 32
528 priv->CurrAntennaIndex = DefaultAnt; // Update default settings.
529 return bAntennaSwitched;
532 /*---------------------------------------------------------------
533 * Hardware Initialization.
534 * the code is ported from Windows source code
535 ----------------------------------------------------------------*/
538 ZEBRA_Config_85BASIC_HardCode(
539 struct net_device *dev
543 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
546 u32 u4bRegOffset, u4bRegValue, u4bRF23, u4bRF24;
551 //=============================================================================
552 // 87S_PCIE :: RADIOCFG.TXT
553 //=============================================================================
556 // Page1 : reg16-reg30
557 RF_WriteReg(dev, 0x00, 0x013f); mdelay(1); // switch to page1
558 u4bRF23= RF_ReadReg(dev, 0x08); mdelay(1);
559 u4bRF24= RF_ReadReg(dev, 0x09); mdelay(1);
561 if (u4bRF23 == 0x818 && u4bRF24 == 0x70C) {
563 printk(KERN_INFO "rtl8187se: card type changed from C- to D-cut\n");
566 // Page0 : reg0-reg15
568 RF_WriteReg(dev, 0x00, 0x009f); mdelay(1);// 1
570 RF_WriteReg(dev, 0x01, 0x06e0); mdelay(1);
572 RF_WriteReg(dev, 0x02, 0x004d); mdelay(1);// 2
574 RF_WriteReg(dev, 0x03, 0x07f1); mdelay(1);// 3
576 RF_WriteReg(dev, 0x04, 0x0975); mdelay(1);
577 RF_WriteReg(dev, 0x05, 0x0c72); mdelay(1);
578 RF_WriteReg(dev, 0x06, 0x0ae6); mdelay(1);
579 RF_WriteReg(dev, 0x07, 0x00ca); mdelay(1);
580 RF_WriteReg(dev, 0x08, 0x0e1c); mdelay(1);
581 RF_WriteReg(dev, 0x09, 0x02f0); mdelay(1);
582 RF_WriteReg(dev, 0x0a, 0x09d0); mdelay(1);
583 RF_WriteReg(dev, 0x0b, 0x01ba); mdelay(1);
584 RF_WriteReg(dev, 0x0c, 0x0640); mdelay(1);
585 RF_WriteReg(dev, 0x0d, 0x08df); mdelay(1);
586 RF_WriteReg(dev, 0x0e, 0x0020); mdelay(1);
587 RF_WriteReg(dev, 0x0f, 0x0990); mdelay(1);
590 // Page1 : reg16-reg30
591 RF_WriteReg(dev, 0x00, 0x013f); mdelay(1);
593 RF_WriteReg(dev, 0x03, 0x0806); mdelay(1);
595 RF_WriteReg(dev, 0x04, 0x03a7); mdelay(1);
596 RF_WriteReg(dev, 0x05, 0x059b); mdelay(1);
597 RF_WriteReg(dev, 0x06, 0x0081); mdelay(1);
600 RF_WriteReg(dev, 0x07, 0x01A0); mdelay(1);
601 // Don't write RF23/RF24 to make a difference between 87S C cut and D cut. asked by SD3 stevenl.
602 RF_WriteReg(dev, 0x0a, 0x0001); mdelay(1);
603 RF_WriteReg(dev, 0x0b, 0x0418); mdelay(1);
606 RF_WriteReg(dev, 0x0c, 0x0fbe); mdelay(1);
607 RF_WriteReg(dev, 0x0d, 0x0008); mdelay(1);
608 RF_WriteReg(dev, 0x0e, 0x0807); mdelay(1); // RX LO buffer
610 RF_WriteReg(dev, 0x0c, 0x0fbe); mdelay(1);
611 RF_WriteReg(dev, 0x0d, 0x0008); mdelay(1);
612 RF_WriteReg(dev, 0x0e, 0x0806); mdelay(1); // RX LO buffer
615 RF_WriteReg(dev, 0x0f, 0x0acc); mdelay(1);
617 RF_WriteReg(dev, 0x00, 0x01d7); mdelay(1);// 6
619 RF_WriteReg(dev, 0x03, 0x0e00); mdelay(1);
620 RF_WriteReg(dev, 0x04, 0x0e50); mdelay(1);
623 RF_WriteReg(dev, 0x01, i); mdelay(1);
624 RF_WriteReg(dev, 0x02, ZEBRA_RF_RX_GAIN_TABLE[i]); mdelay(1);
627 RF_WriteReg(dev, 0x05, 0x0203); mdelay(1); /// 203, 343
628 RF_WriteReg(dev, 0x06, 0x0200); mdelay(1); // 400
630 RF_WriteReg(dev, 0x00, 0x0137); mdelay(1); // switch to reg16-reg30, and HSSI disable 137
631 mdelay(10); // Deay 10 ms. //0xfd
633 RF_WriteReg(dev, 0x0d, 0x0008); mdelay(1); // Z4 synthesizer loop filter setting, 392
634 mdelay(10); // Deay 10 ms. //0xfd
636 RF_WriteReg(dev, 0x00, 0x0037); mdelay(1); // switch to reg0-reg15, and HSSI disable
637 mdelay(10); // Deay 10 ms. //0xfd
639 RF_WriteReg(dev, 0x04, 0x0160); mdelay(1); // CBC on, Tx Rx disable, High gain
640 mdelay(10); // Deay 10 ms. //0xfd
642 RF_WriteReg(dev, 0x07, 0x0080); mdelay(1); // Z4 setted channel 1
643 mdelay(10); // Deay 10 ms. //0xfd
645 RF_WriteReg(dev, 0x02, 0x088D); mdelay(1); // LC calibration
646 mdelay(200); // Deay 200 ms. //0xfd
647 mdelay(10); // Deay 10 ms. //0xfd
648 mdelay(10); // Deay 10 ms. //0xfd
650 RF_WriteReg(dev, 0x00, 0x0137); mdelay(1); // switch to reg16-reg30 137, and HSSI disable 137
651 mdelay(10); // Deay 10 ms. //0xfd
653 RF_WriteReg(dev, 0x07, 0x0000); mdelay(1);
654 RF_WriteReg(dev, 0x07, 0x0180); mdelay(1);
655 RF_WriteReg(dev, 0x07, 0x0220); mdelay(1);
656 RF_WriteReg(dev, 0x07, 0x03E0); mdelay(1);
658 // DAC calibration off 20070702
659 RF_WriteReg(dev, 0x06, 0x00c1); mdelay(1);
660 RF_WriteReg(dev, 0x0a, 0x0001); mdelay(1);
662 // For crystal calibration, added by Roger, 2007.12.11.
663 if( priv->bXtalCalibration ) // reg 30.
664 { // enable crystal calibration.
665 // RF Reg[30], (1)Xin:[12:9], Xout:[8:5], addr[4:0].
666 // (2)PA Pwr delay timer[15:14], default: 2.4us, set BIT15=0
667 // (3)RF signal on/off when calibration[13], default: on, set BIT13=0.
668 // So we should minus 4 BITs offset.
669 RF_WriteReg(dev, 0x0f, (priv->XtalCal_Xin<<5)|(priv->XtalCal_Xout<<1)|BIT11|BIT9); mdelay(1);
670 printk("ZEBRA_Config_85BASIC_HardCode(): (%02x)\n",
671 (priv->XtalCal_Xin<<5) | (priv->XtalCal_Xout<<1) | BIT11| BIT9);
674 { // using default value. Xin=6, Xout=6.
675 RF_WriteReg(dev, 0x0f, 0x0acc); mdelay(1);
679 RF_WriteReg(dev, 0x00, 0x00bf); mdelay(1); // switch to reg0-reg15, and HSSI enable
680 RF_WriteReg(dev, 0x0d, 0x08df); mdelay(1); // Rx BB start calibration, 00c//+edward
681 RF_WriteReg(dev, 0x02, 0x004d); mdelay(1); // temperature meter off
682 RF_WriteReg(dev, 0x04, 0x0975); mdelay(1); // Rx mode
683 mdelay(10); // Deay 10 ms. //0xfe
684 mdelay(10); // Deay 10 ms. //0xfe
685 mdelay(10); // Deay 10 ms. //0xfe
686 RF_WriteReg(dev, 0x00, 0x0197); mdelay(1); // Rx mode//+edward
687 RF_WriteReg(dev, 0x05, 0x05ab); mdelay(1); // Rx mode//+edward
688 RF_WriteReg(dev, 0x00, 0x009f); mdelay(1); // Rx mode//+edward
690 RF_WriteReg(dev, 0x01, 0x0000); mdelay(1); // Rx mode//+edward
691 RF_WriteReg(dev, 0x02, 0x0000); mdelay(1); // Rx mode//+edward
692 //power save parameters.
693 u1b24E = read_nic_byte(dev, 0x24E);
694 write_nic_byte(dev, 0x24E, (u1b24E & (~(BIT5|BIT6))));
696 //=============================================================================
698 //=============================================================================
700 //=============================================================================
702 /* [POWER SAVE] Power Saving Parameters by jong. 2007-11-27
703 CCK reg0x00[7]=1'b1 :power saving for TX (default)
704 CCK reg0x00[6]=1'b1: power saving for RX (default)
705 CCK reg0x06[4]=1'b1: turn off channel estimation related circuits if not doing channel estimation.
706 CCK reg0x06[3]=1'b1: turn off unused circuits before cca = 1
707 CCK reg0x06[2]=1'b1: turn off cck's circuit if macrst =0
710 write_phy_cck(dev,0x00,0xc8);
711 write_phy_cck(dev,0x06,0x1c);
712 write_phy_cck(dev,0x10,0x78);
713 write_phy_cck(dev,0x2e,0xd0);
714 write_phy_cck(dev,0x2f,0x06);
715 write_phy_cck(dev,0x01,0x46);
718 write_nic_byte(dev, CCK_TXAGC, 0x10);
719 write_nic_byte(dev, OFDM_TXAGC, 0x1B);
720 write_nic_byte(dev, ANTSEL, 0x03);
724 //=============================================================================
726 //=============================================================================
728 write_phy_ofdm(dev, 0x00, 0x12);
730 for (i=0; i<128; i++)
733 data = ZEBRA_AGC[i+1];
735 data = data | 0x0000008F;
737 addr = i + 0x80; //enable writing AGC table
739 addr = addr | 0x0000008E;
741 WriteBBPortUchar(dev, data);
742 WriteBBPortUchar(dev, addr);
743 WriteBBPortUchar(dev, 0x0000008E);
746 PlatformIOWrite4Byte( dev, PhyAddr, 0x00001080); // Annie, 2006-05-05
748 //=============================================================================
750 //=============================================================================
752 //=============================================================================
757 u4bRegValue=OFDM_CONFIG[i];
759 WriteBBPortUchar(dev,
761 (u4bRegOffset & 0x7f) |
762 ((u4bRegValue & 0xff) << 8)));
765 //=============================================================================
767 //=============================================================================
769 // Config Sw/Hw Combinational Antenna Diversity. Added by Roger, 2008.02.26.
770 SetAntennaConfig87SE(dev, priv->bDefaultAntenna1, priv->bSwAntennaDiverity);
778 struct net_device *dev
781 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
784 if(priv->eRFPowerState != eRfOn)
786 //Don't access BB/RF under disable PLL situation.
787 //RT_TRACE(COMP_DIG, DBG_LOUD, ("UpdateInitialGain - pHalData->eRFPowerState!=eRfOn\n"));
788 // Back to the original state
789 priv->InitialGain= priv->InitialGainBackUp;
793 switch (priv->InitialGain) {
794 case 1: /* m861dBm */
795 write_phy_ofdm(dev, 0x17, 0x26); mdelay(1);
796 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
797 write_phy_ofdm(dev, 0x05, 0xfa); mdelay(1);
800 case 2: /* m862dBm */
801 write_phy_ofdm(dev, 0x17, 0x36); mdelay(1);
802 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
803 write_phy_ofdm(dev, 0x05, 0xfa); mdelay(1);
806 case 3: /* m863dBm */
807 write_phy_ofdm(dev, 0x17, 0x36); mdelay(1);
808 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
809 write_phy_ofdm(dev, 0x05, 0xfb); mdelay(1);
812 case 4: /* m864dBm */
813 write_phy_ofdm(dev, 0x17, 0x46); mdelay(1);
814 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
815 write_phy_ofdm(dev, 0x05, 0xfb); mdelay(1);
819 write_phy_ofdm(dev, 0x17, 0x46); mdelay(1);
820 write_phy_ofdm(dev, 0x24, 0x96); mdelay(1);
821 write_phy_ofdm(dev, 0x05, 0xfb); mdelay(1);
825 write_phy_ofdm(dev, 0x17, 0x56); mdelay(1);
826 write_phy_ofdm(dev, 0x24, 0x96); mdelay(1);
827 write_phy_ofdm(dev, 0x05, 0xfc); mdelay(1);
831 write_phy_ofdm(dev, 0x17, 0x56); mdelay(1);
832 write_phy_ofdm(dev, 0x24, 0xa6); mdelay(1);
833 write_phy_ofdm(dev, 0x05, 0xfc); mdelay(1);
837 write_phy_ofdm(dev, 0x17, 0x66); mdelay(1);
838 write_phy_ofdm(dev, 0x24, 0xb6); mdelay(1);
839 write_phy_ofdm(dev, 0x05, 0xfc); mdelay(1);
843 write_phy_ofdm(dev, 0x17, 0x26); mdelay(1);
844 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
845 write_phy_ofdm(dev, 0x05, 0xfa); mdelay(1);
851 // Tx Power tracking mechanism routine on 87SE.
852 // Created by Roger, 2007.12.11.
855 InitTxPwrTracking87SE(
856 struct net_device *dev
861 u4bRfReg = RF_ReadReg(dev, 0x02);
863 // Enable Thermal meter indication.
864 RF_WriteReg(dev, 0x02, u4bRfReg|PWR_METER_EN); mdelay(1);
869 struct net_device *dev
872 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
873 write_nic_dword(dev, RCR, priv->ReceiveConfig);
874 priv->RFProgType = read_nic_byte(dev, CONFIG4) & 0x03;
876 ZEBRA_Config_85BASIC_HardCode(dev);
878 // Set default initial gain state to 4, approved by SD3 DZ, by Bruce, 2007-06-06.
879 if(priv->bDigMechanism)
881 if(priv->InitialGain == 0)
882 priv->InitialGain = 4;
886 // Enable thermal meter indication to implement TxPower tracking on 87SE.
887 // We initialize thermal meter here to avoid unsuccessful configuration.
888 // Added by Roger, 2007.12.11.
890 if(priv->bTxPowerTrack)
891 InitTxPwrTracking87SE(dev);
894 priv->InitialGainBackUp= priv->InitialGain;
895 UpdateInitialGain(dev);
902 struct net_device *dev
905 //RTL8185_TODO: Determine Retrylimit, TxAGC, AutoRateFallback control.
906 u8 bUNIVERSAL_CONTROL_RL = 0;
907 u8 bUNIVERSAL_CONTROL_AGC = 1;
908 u8 bUNIVERSAL_CONTROL_ANT = 1;
909 u8 bAUTO_RATE_FALLBACK_CTL = 1;
911 write_nic_word(dev, BRSR, 0x0fff);
913 val8 = read_nic_byte(dev, CW_CONF);
915 if(bUNIVERSAL_CONTROL_RL)
920 write_nic_byte(dev, CW_CONF, val8);
923 val8 = read_nic_byte(dev, TXAGC_CTL);
924 if(bUNIVERSAL_CONTROL_AGC)
926 write_nic_byte(dev, CCK_TXAGC, 128);
927 write_nic_byte(dev, OFDM_TXAGC, 128);
936 write_nic_byte(dev, TXAGC_CTL, val8);
938 // Tx Antenna including Feedback control
939 val8 = read_nic_byte(dev, TXAGC_CTL );
941 if(bUNIVERSAL_CONTROL_ANT)
943 write_nic_byte(dev, ANTSEL, 0x00);
948 val8 = val8 & (val8|0x02); //xiong-2006-11-15
951 write_nic_byte(dev, TXAGC_CTL, val8);
953 // Auto Rate fallback control
954 val8 = read_nic_byte(dev, RATE_FALLBACK);
956 if( bAUTO_RATE_FALLBACK_CTL )
958 val8 |= RATE_FALLBACK_CTL_ENABLE | RATE_FALLBACK_CTL_AUTO_STEP1;
960 // <RJ_TODO_8185B> We shall set up the ARFR according to user's setting.
961 PlatformIOWrite2Byte(dev, ARFR, 0x0fff); //set 1M ~ 54Mbps.
963 write_nic_byte(dev, RATE_FALLBACK, val8);
967 MacConfig_85BASIC_HardCode(
968 struct net_device *dev)
970 //============================================================================
972 //============================================================================
975 u32 u4bRegOffset, u4bRegValue,u4bPageIndex = 0;
978 nLinesRead=sizeof(MAC_REG_TABLE)/2;
980 for(i = 0; i < nLinesRead; i++) //nLinesRead=101
982 u4bRegOffset=MAC_REG_TABLE[i][0];
983 u4bRegValue=MAC_REG_TABLE[i][1];
985 if(u4bRegOffset == 0x5e)
987 u4bPageIndex = u4bRegValue;
991 u4bRegOffset |= (u4bPageIndex << 8);
993 write_nic_byte(dev, u4bRegOffset, (u8)u4bRegValue);
995 //============================================================================
1000 struct net_device *dev)
1004 MacConfig_85BASIC_HardCode(dev);
1006 //============================================================================
1008 // Follow TID_AC_MAP of WMac.
1009 write_nic_word(dev, TID_AC_MAP, 0xfa50);
1011 // Interrupt Migration, Jong suggested we use set 0x0000 first, 2005.12.14, by rcnjko.
1012 write_nic_word(dev, IntMig, 0x0000);
1014 // Prevent TPC to cause CRC error. Added by Annie, 2006-06-10.
1015 PlatformIOWrite4Byte(dev, 0x1F0, 0x00000000);
1016 PlatformIOWrite4Byte(dev, 0x1F4, 0x00000000);
1017 PlatformIOWrite1Byte(dev, 0x1F8, 0x00);
1019 // Asked for by SD3 CM Lin, 2006.06.27, by rcnjko.
1020 // power save parameter based on "87SE power save parameters 20071127.doc", as follow.
1022 //Enable DA10 TX power saving
1023 u1DA = read_nic_byte(dev, PHYPR);
1024 write_nic_byte(dev, PHYPR, (u1DA | BIT2) );
1027 write_nic_word(dev, 0x360, 0x1000);
1028 write_nic_word(dev, 0x362, 0x1000);
1031 write_nic_word(dev, 0x370, 0x0560);
1032 write_nic_word(dev, 0x372, 0x0560);
1033 write_nic_word(dev, 0x374, 0x0DA4);
1034 write_nic_word(dev, 0x376, 0x0DA4);
1035 write_nic_word(dev, 0x378, 0x0560);
1036 write_nic_word(dev, 0x37A, 0x0560);
1037 write_nic_word(dev, 0x37C, 0x00EC);
1038 write_nic_word(dev, 0x37E, 0x00EC);//+edward
1039 write_nic_byte(dev, 0x24E,0x01);
1043 GetSupportedWirelessMode8185(
1044 struct net_device *dev
1047 u8 btSupportedWirelessMode = 0;
1049 btSupportedWirelessMode = (WIRELESS_MODE_B | WIRELESS_MODE_G);
1050 return btSupportedWirelessMode;
1054 ActUpdateChannelAccessSetting(
1055 struct net_device *dev,
1056 WIRELESS_MODE WirelessMode,
1057 PCHANNEL_ACCESS_SETTING ChnlAccessSetting
1060 struct r8180_priv *priv = ieee80211_priv(dev);
1061 struct ieee80211_device *ieee = priv->ieee80211;
1064 u8 bFollowLegacySetting = 0;
1069 // TODO: We still don't know how to set up these registers, just follow WMAC to
1070 // verify 8185B FPAG.
1073 // Jong said CWmin/CWmax register are not functional in 8185B,
1074 // so we shall fill channel access realted register into AC parameter registers,
1077 ChnlAccessSetting->SIFS_Timer = 0x22; // Suggested by Jong, 2005.12.08.
1078 ChnlAccessSetting->DIFS_Timer = 0x1C; // 2006.06.02, by rcnjko.
1079 ChnlAccessSetting->SlotTimeTimer = 9; // 2006.06.02, by rcnjko.
1080 ChnlAccessSetting->EIFS_Timer = 0x5B; // Suggested by wcchu, it is the default value of EIFS register, 2005.12.08.
1081 ChnlAccessSetting->CWminIndex = 3; // 2006.06.02, by rcnjko.
1082 ChnlAccessSetting->CWmaxIndex = 7; // 2006.06.02, by rcnjko.
1084 write_nic_byte(dev, SIFS, ChnlAccessSetting->SIFS_Timer);
1085 write_nic_byte(dev, SLOT, ChnlAccessSetting->SlotTimeTimer); // Rewrited from directly use PlatformEFIOWrite1Byte(), by Annie, 2006-03-29.
1087 u1bAIFS = aSifsTime + (2 * ChnlAccessSetting->SlotTimeTimer );
1089 write_nic_byte(dev, EIFS, ChnlAccessSetting->EIFS_Timer);
1091 write_nic_byte(dev, AckTimeOutReg, 0x5B); // <RJ_EXPR_QOS> Suggested by wcchu, it is the default value of EIFS register, 2005.12.08.
1094 bFollowLegacySetting = 1;
1098 // this setting is copied from rtl8187B. xiong-2006-11-13
1099 if(bFollowLegacySetting)
1104 // Follow 802.11 seeting to AC parameter, all AC shall use the same parameter.
1105 // 2005.12.01, by rcnjko.
1107 AcParam.longData = 0;
1108 AcParam.f.AciAifsn.f.AIFSN = 2; // Follow 802.11 DIFS.
1109 AcParam.f.AciAifsn.f.ACM = 0;
1110 AcParam.f.Ecw.f.ECWmin = ChnlAccessSetting->CWminIndex; // Follow 802.11 CWmin.
1111 AcParam.f.Ecw.f.ECWmax = ChnlAccessSetting->CWmaxIndex; // Follow 802.11 CWmax.
1112 AcParam.f.TXOPLimit = 0;
1114 //lzm reserved 080826
1115 // For turbo mode setting. port from 87B by Isaiah 2008-08-01
1116 if( ieee->current_network.Turbo_Enable == 1 )
1117 AcParam.f.TXOPLimit = 0x01FF;
1118 // For 87SE with Intel 4965 Ad-Hoc mode have poor throughput (19MB)
1119 if (ieee->iw_mode == IW_MODE_ADHOC)
1120 AcParam.f.TXOPLimit = 0x0020;
1122 for(eACI = 0; eACI < AC_MAX; eACI++)
1124 AcParam.f.AciAifsn.f.ACI = (u8)eACI;
1126 PAC_PARAM pAcParam = (PAC_PARAM)(&AcParam);
1131 // Retrive paramters to udpate.
1132 eACI = pAcParam->f.AciAifsn.f.ACI;
1133 u1bAIFS = pAcParam->f.AciAifsn.f.AIFSN * ChnlAccessSetting->SlotTimeTimer + aSifsTime;
1134 u4bAcParam = ( (((u32)(pAcParam->f.TXOPLimit)) << AC_PARAM_TXOP_LIMIT_OFFSET) |
1135 (((u32)(pAcParam->f.Ecw.f.ECWmax)) << AC_PARAM_ECW_MAX_OFFSET) |
1136 (((u32)(pAcParam->f.Ecw.f.ECWmin)) << AC_PARAM_ECW_MIN_OFFSET) |
1137 (((u32)u1bAIFS) << AC_PARAM_AIFS_OFFSET));
1142 //write_nic_dword(dev, AC_BK_PARAM, u4bAcParam);
1146 //write_nic_dword(dev, AC_BE_PARAM, u4bAcParam);
1150 //write_nic_dword(dev, AC_VI_PARAM, u4bAcParam);
1154 //write_nic_dword(dev, AC_VO_PARAM, u4bAcParam);
1158 DMESGW( "SetHwReg8185(): invalid ACI: %d !\n", eACI);
1163 // If it is set, immediately set ACM control bit to downgrading AC for passing WMM testplan. Annie, 2005-12-13.
1165 PACI_AIFSN pAciAifsn = (PACI_AIFSN)(&pAcParam->f.AciAifsn);
1166 AC_CODING eACI = pAciAifsn->f.ACI;
1169 //for 8187B AsynIORead issue
1171 if( pAciAifsn->f.ACM )
1176 AcmCtrl |= (BEQ_ACM_EN|BEQ_ACM_CTL|ACM_HW_EN); // or 0x21
1180 AcmCtrl |= (VIQ_ACM_EN|VIQ_ACM_CTL|ACM_HW_EN); // or 0x42
1184 AcmCtrl |= (VOQ_ACM_EN|VOQ_ACM_CTL|ACM_HW_EN); // or 0x84
1188 DMESGW("SetHwReg8185(): [HW_VAR_ACM_CTRL] ACM set failed: eACI is %d\n", eACI );
1197 AcmCtrl &= ( (~BEQ_ACM_EN) & (~BEQ_ACM_CTL) & (~ACM_HW_EN) ); // and 0xDE
1201 AcmCtrl &= ( (~VIQ_ACM_EN) & (~VIQ_ACM_CTL) & (~ACM_HW_EN) ); // and 0xBD
1205 AcmCtrl &= ( (~VOQ_ACM_EN) & (~VOQ_ACM_CTL) & (~ACM_HW_EN) ); // and 0x7B
1212 write_nic_byte(dev, ACM_CONTROL, 0);
1220 ActSetWirelessMode8185(
1221 struct net_device *dev,
1225 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1226 struct ieee80211_device *ieee = priv->ieee80211;
1227 u8 btSupportedWirelessMode = GetSupportedWirelessMode8185(dev);
1229 if( (btWirelessMode & btSupportedWirelessMode) == 0 )
1230 { // Don't switch to unsupported wireless mode, 2006.02.15, by rcnjko.
1231 DMESGW("ActSetWirelessMode8185(): WirelessMode(%d) is not supported (%d)!\n",
1232 btWirelessMode, btSupportedWirelessMode);
1236 // 1. Assign wireless mode to swtich if necessary.
1237 if (btWirelessMode == WIRELESS_MODE_AUTO)
1239 if((btSupportedWirelessMode & WIRELESS_MODE_A))
1241 btWirelessMode = WIRELESS_MODE_A;
1243 else if((btSupportedWirelessMode & WIRELESS_MODE_G))
1245 btWirelessMode = WIRELESS_MODE_G;
1247 else if((btSupportedWirelessMode & WIRELESS_MODE_B))
1249 btWirelessMode = WIRELESS_MODE_B;
1253 DMESGW("ActSetWirelessMode8185(): No valid wireless mode supported, btSupportedWirelessMode(%x)!!!\n",
1254 btSupportedWirelessMode);
1255 btWirelessMode = WIRELESS_MODE_B;
1259 /* 2. Swtich band: RF or BB specific actions,
1260 * for example, refresh tables in omc8255, or change initial gain if necessary.
1261 * Nothing to do for Zebra to switch band.
1262 * Update current wireless mode if we swtich to specified band successfully. */
1263 ieee->mode = (WIRELESS_MODE)btWirelessMode;
1265 // 3. Change related setting.
1266 if( ieee->mode == WIRELESS_MODE_A ){
1267 DMESG("WIRELESS_MODE_A\n");
1269 else if( ieee->mode == WIRELESS_MODE_B ){
1270 DMESG("WIRELESS_MODE_B\n");
1272 else if( ieee->mode == WIRELESS_MODE_G ){
1273 DMESG("WIRELESS_MODE_G\n");
1275 ActUpdateChannelAccessSetting( dev, ieee->mode, &priv->ChannelAccessSetting);
1278 void rtl8185b_irq_enable(struct net_device *dev)
1280 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1282 priv->irq_enabled = 1;
1283 write_nic_dword(dev, IMR, priv->IntrMask);
1285 //by amy for power save
1287 DrvIFIndicateDisassociation(
1288 struct net_device *dev,
1292 // nothing is needed after disassociation request.
1296 struct net_device *dev
1299 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1302 DrvIFIndicateDisassociation(dev, unspec_reason);
1303 for(i=0;i<6;i++) priv->ieee80211->current_network.bssid[i] = 0x55;
1305 priv->ieee80211->state = IEEE80211_NOLINK;
1309 // Vista add a Adhoc profile, HW radio off untill OID_DOT11_RESET_REQUEST
1310 // Driver would set MSR=NO_LINK, then HW Radio ON, MgntQueue Stuck.
1311 // Because Bcn DMA isn't complete, mgnt queue would stuck until Bcn packet send.
1313 // Disable Beacon Queue Own bit, suggested by jong
1314 ieee80211_stop_send_beacons(priv->ieee80211);
1316 priv->ieee80211->link_change(dev);
1317 notify_wx_assoc_event(priv->ieee80211);
1320 MlmeDisassociateRequest(
1321 struct net_device *dev,
1326 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1329 SendDisassociation(priv->ieee80211, asSta, asRsn );
1331 if( memcmp(priv->ieee80211->current_network.bssid, asSta, 6 ) == 0 ){
1332 //ShuChen TODO: change media status.
1333 //ShuChen TODO: What to do when disassociate.
1334 DrvIFIndicateDisassociation(dev, unspec_reason);
1337 for(i=0;i<6;i++) priv->ieee80211->current_network.bssid[i] = 0x22;
1338 ieee80211_disassociate(priv->ieee80211);
1345 struct net_device *dev,
1349 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1352 // Commented out by rcnjko, 2005.01.27:
1353 // I move SecClearAllKeys() to MgntActSet_802_11_DISASSOCIATE().
1355 // //2004/09/15, kcwu, the key should be cleared, or the new handshaking will not success
1357 // In WPA WPA2 need to Clear all key ... because new key will set after new handshaking.
1358 // 2004.10.11, by rcnjko.
1359 MlmeDisassociateRequest( dev, priv->ieee80211->current_network.bssid, asRsn );
1361 priv->ieee80211->state = IEEE80211_NOLINK;
1365 struct net_device *dev,
1369 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1371 // Schedule an workitem to wake up for ps mode, 070109, by rcnjko.
1374 if(IS_DOT11D_ENABLE(priv->ieee80211))
1375 Dot11d_Reset(priv->ieee80211);
1376 // In adhoc mode, update beacon frame.
1377 if( priv->ieee80211->state == IEEE80211_LINKED )
1379 if( priv->ieee80211->iw_mode == IW_MODE_ADHOC )
1381 MgntDisconnectIBSS(dev);
1383 if( priv->ieee80211->iw_mode == IW_MODE_INFRA )
1385 // We clear key here instead of MgntDisconnectAP() because that
1386 // MgntActSet_802_11_DISASSOCIATE() is an interface called by OS,
1387 // e.g. OID_802_11_DISASSOCIATE in Windows while as MgntDisconnectAP() is
1388 // used to handle disassociation related things to AP, e.g. send Disassoc
1389 // frame to AP. 2005.01.27, by rcnjko.
1390 MgntDisconnectAP(dev, asRsn);
1392 // Inidicate Disconnect, 2005.02.23, by rcnjko.
1398 // Chang RF Power State.
1399 // Note that, only MgntActSet_RF_State() is allowed to set HW_VAR_RF_STATE.
1406 struct net_device *dev,
1407 RT_RF_POWER_STATE eRFPowerState
1410 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1411 bool bResult = false;
1413 if(eRFPowerState == priv->eRFPowerState)
1418 bResult = SetZebraRFPowerState8185(dev, eRFPowerState);
1423 HalEnableRx8185Dummy(
1424 struct net_device *dev
1429 HalDisableRx8185Dummy(
1430 struct net_device *dev
1436 MgntActSet_RF_State(
1437 struct net_device *dev,
1438 RT_RF_POWER_STATE StateToSet,
1442 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1443 bool bActionAllowed = false;
1444 bool bConnectBySSID = false;
1445 RT_RF_POWER_STATE rtState;
1446 u16 RFWaitCounter = 0;
1449 // Prevent the race condition of RF state change. By Bruce, 2007-11-28.
1450 // Only one thread can change the RF state at one time, and others should wait to be executed.
1454 spin_lock_irqsave(&priv->rf_ps_lock,flag);
1455 if(priv->RFChangeInProgress)
1457 spin_unlock_irqrestore(&priv->rf_ps_lock,flag);
1458 // Set RF after the previous action is done.
1459 while(priv->RFChangeInProgress)
1462 udelay(1000); // 1 ms
1464 // Wait too long, return FALSE to avoid to be stuck here.
1465 if(RFWaitCounter > 1000) // 1sec
1467 printk("MgntActSet_RF_State(): Wait too long to set RF\n");
1468 // TODO: Reset RF state?
1475 priv->RFChangeInProgress = true;
1476 spin_unlock_irqrestore(&priv->rf_ps_lock,flag);
1480 rtState = priv->eRFPowerState;
1486 // Turn On RF no matter the IPS setting because we need to update the RF state to Ndis under Vista, or
1487 // the Windows does not allow the driver to perform site survey any more. By Bruce, 2007-10-02.
1489 priv->RfOffReason &= (~ChangeSource);
1491 if(! priv->RfOffReason)
1493 priv->RfOffReason = 0;
1494 bActionAllowed = true;
1496 if(rtState == eRfOff && ChangeSource >=RF_CHANGE_BY_HW && !priv->bInHctTest)
1498 bConnectBySSID = true;
1506 // 070125, rcnjko: we always keep connected in AP mode.
1508 if (priv->RfOffReason > RF_CHANGE_BY_IPS)
1512 // Disconnect to current BSS when radio off. Asked by QuanTa.
1516 // Calling MgntDisconnect() instead of MgntActSet_802_11_DISASSOCIATE(),
1517 // because we do NOT need to set ssid to dummy ones.
1519 MgntDisconnect( dev, disas_lv_ss );
1521 // Clear content of bssDesc[] and bssDesc4Query[] to avoid reporting old bss to UI.
1524 priv->RfOffReason |= ChangeSource;
1525 bActionAllowed = true;
1528 priv->RfOffReason |= ChangeSource;
1529 bActionAllowed = true;
1537 // Config HW to the specified mode.
1538 SetRFPowerState(dev, StateToSet);
1541 if(StateToSet == eRfOn)
1543 HalEnableRx8185Dummy(dev);
1546 // by amy not supported
1550 else if(StateToSet == eRfOff)
1552 HalDisableRx8185Dummy(dev);
1556 // Release RF spinlock
1557 spin_lock_irqsave(&priv->rf_ps_lock,flag);
1558 priv->RFChangeInProgress = false;
1559 spin_unlock_irqrestore(&priv->rf_ps_lock,flag);
1560 return bActionAllowed;
1564 struct net_device *dev
1567 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1569 // This flag "bSwRfProcessing", indicates the status of IPS procedure, should be set if the IPS workitem
1570 // is really scheduled.
1571 // The old code, sets this flag before scheduling the IPS workitem and however, at the same time the
1572 // previous IPS workitem did not end yet, fails to schedule the current workitem. Thus, bSwRfProcessing
1573 // blocks the IPS procedure of switching RF.
1575 priv->bSwRfProcessing = true;
1577 MgntActSet_RF_State(dev, priv->eInactivePowerState, RF_CHANGE_BY_IPS);
1580 // To solve CAM values miss in RF OFF, rewrite CAM values after RF ON. By Bruce, 2007-09-20.
1583 priv->bSwRfProcessing = false;
1588 // Enter the inactive power save mode. RF will be off
1592 struct net_device *dev
1595 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1596 RT_RF_POWER_STATE rtState;
1597 if (priv->bInactivePs)
1599 rtState = priv->eRFPowerState;
1602 // Do not enter IPS in the following conditions:
1603 // (1) RF is already OFF or Sleep
1604 // (2) bSwRfProcessing (indicates the IPS is still under going)
1605 // (3) Connectted (only disconnected can trigger IPS)
1606 // (4) IBSS (send Beacon)
1607 // (5) AP mode (send Beacon)
1609 if (rtState == eRfOn && !priv->bSwRfProcessing
1610 && (priv->ieee80211->state != IEEE80211_LINKED ))
1612 priv->eInactivePowerState = eRfOff;
1613 InactivePowerSave(dev);
1619 struct net_device *dev
1622 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1623 RT_RF_POWER_STATE rtState;
1624 if (priv->bInactivePs)
1626 rtState = priv->eRFPowerState;
1627 if ((rtState == eRfOff || rtState == eRfSleep) && (!priv->bSwRfProcessing) && priv->RfOffReason <= RF_CHANGE_BY_IPS)
1629 priv->eInactivePowerState = eRfOn;
1630 InactivePowerSave(dev);
1635 void rtl8185b_adapter_start(struct net_device *dev)
1637 struct r8180_priv *priv = ieee80211_priv(dev);
1638 struct ieee80211_device *ieee = priv->ieee80211;
1640 u8 SupportedWirelessMode;
1641 u8 InitWirelessMode;
1642 u8 bInvalidWirelessMode = 0;
1648 write_nic_byte(dev,0x24e, (BIT5|BIT6|BIT0));
1651 priv->dma_poll_mask = 0;
1652 priv->dma_poll_stop_mask = 0;
1654 HwConfigureRTL8185(dev);
1655 write_nic_dword(dev, MAC0, ((u32*)dev->dev_addr)[0]);
1656 write_nic_word(dev, MAC4, ((u32*)dev->dev_addr)[1] & 0xffff );
1657 write_nic_byte(dev, MSR, read_nic_byte(dev, MSR) & 0xf3); // default network type to 'No Link'
1658 write_nic_word(dev, BcnItv, 100);
1659 write_nic_word(dev, AtimWnd, 2);
1660 PlatformIOWrite2Byte(dev, FEMR, 0xFFFF);
1661 write_nic_byte(dev, WPA_CONFIG, 0);
1662 MacConfig_85BASIC(dev);
1663 // Override the RFSW_CTRL (MAC offset 0x272-0x273), 2006.06.07, by rcnjko.
1664 // BT_DEMO_BOARD type
1665 PlatformIOWrite2Byte(dev, RFSW_CTRL, 0x569a);
1667 //-----------------------------------------------------------------------------
1668 // Set up PHY related.
1669 //-----------------------------------------------------------------------------
1670 // Enable Config3.PARAM_En to revise AnaaParm.
1671 write_nic_byte(dev, CR9346, 0xc0); // enable config register write
1672 tmpu8 = read_nic_byte(dev, CONFIG3);
1673 write_nic_byte(dev, CONFIG3, (tmpu8 |CONFIG3_PARM_En) );
1674 // Turn on Analog power.
1675 // Asked for by William, otherwise, MAC 3-wire can't work, 2006.06.27, by rcnjko.
1676 write_nic_dword(dev, ANAPARAM2, ANAPARM2_ASIC_ON);
1677 write_nic_dword(dev, ANAPARAM, ANAPARM_ASIC_ON);
1678 write_nic_word(dev, ANAPARAM3, 0x0010);
1680 write_nic_byte(dev, CONFIG3, tmpu8);
1681 write_nic_byte(dev, CR9346, 0x00);
1682 // enable EEM0 and EEM1 in 9346CR
1683 btCR9346 = read_nic_byte(dev, CR9346);
1684 write_nic_byte(dev, CR9346, (btCR9346|0xC0) );
1686 // B cut use LED1 to control HW RF on/off
1687 TmpU1b = read_nic_byte(dev, CONFIG5);
1688 TmpU1b = TmpU1b & ~BIT3;
1689 write_nic_byte(dev,CONFIG5, TmpU1b);
1691 // disable EEM0 and EEM1 in 9346CR
1692 btCR9346 &= ~(0xC0);
1693 write_nic_byte(dev, CR9346, btCR9346);
1695 //Enable Led (suggested by Jong)
1696 // B-cut RF Radio on/off 5e[3]=0
1697 btPSR = read_nic_byte(dev, PSR);
1698 write_nic_byte(dev, PSR, (btPSR | BIT3));
1699 // setup initial timing for RFE.
1700 write_nic_word(dev, RFPinsOutput, 0x0480);
1701 SetOutputEnableOfRfPins(dev);
1702 write_nic_word(dev, RFPinsSelect, 0x2488);
1707 // We assume RegWirelessMode has already been initialized before,
1708 // however, we has to validate the wireless mode here and provide a
1709 // reasonable initialized value if necessary. 2005.01.13, by rcnjko.
1710 SupportedWirelessMode = GetSupportedWirelessMode8185(dev);
1711 if( (ieee->mode != WIRELESS_MODE_B) &&
1712 (ieee->mode != WIRELESS_MODE_G) &&
1713 (ieee->mode != WIRELESS_MODE_A) &&
1714 (ieee->mode != WIRELESS_MODE_AUTO))
1715 { // It should be one of B, G, A, or AUTO.
1716 bInvalidWirelessMode = 1;
1719 { // One of B, G, A, or AUTO.
1720 // Check if the wireless mode is supported by RF.
1721 if( (ieee->mode != WIRELESS_MODE_AUTO) &&
1722 (ieee->mode & SupportedWirelessMode) == 0 )
1724 bInvalidWirelessMode = 1;
1728 if(bInvalidWirelessMode || ieee->mode==WIRELESS_MODE_AUTO)
1729 { // Auto or other invalid value.
1730 // Assigne a wireless mode to initialize.
1731 if((SupportedWirelessMode & WIRELESS_MODE_A))
1733 InitWirelessMode = WIRELESS_MODE_A;
1735 else if((SupportedWirelessMode & WIRELESS_MODE_G))
1737 InitWirelessMode = WIRELESS_MODE_G;
1739 else if((SupportedWirelessMode & WIRELESS_MODE_B))
1741 InitWirelessMode = WIRELESS_MODE_B;
1745 DMESGW("InitializeAdapter8185(): No valid wireless mode supported, SupportedWirelessMode(%x)!!!\n",
1746 SupportedWirelessMode);
1747 InitWirelessMode = WIRELESS_MODE_B;
1750 // Initialize RegWirelessMode if it is not a valid one.
1751 if(bInvalidWirelessMode)
1753 ieee->mode = (WIRELESS_MODE)InitWirelessMode;
1757 { // One of B, G, A.
1758 InitWirelessMode = ieee->mode;
1760 //by amy for power save
1761 priv->eRFPowerState = eRfOff;
1762 priv->RfOffReason = 0;
1764 MgntActSet_RF_State(dev, eRfOn, 0);
1767 // If inactive power mode is enabled, disable rf while in disconnected state.
1769 if (priv->bInactivePs)
1771 MgntActSet_RF_State(dev,eRfOff, RF_CHANGE_BY_IPS);
1773 //by amy for power save
1775 ActSetWirelessMode8185(dev, (u8)(InitWirelessMode));
1777 //-----------------------------------------------------------------------------
1779 rtl8185b_irq_enable(dev);
1781 netif_start_queue(dev);
1784 void rtl8185b_rx_enable(struct net_device *dev)
1787 /* for now we accept data, management & ctl frame*/
1788 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1790 if (dev->flags & IFF_PROMISC) DMESG ("NIC in promisc mode");
1792 if(priv->ieee80211->iw_mode == IW_MODE_MONITOR || \
1793 dev->flags & IFF_PROMISC){
1794 priv->ReceiveConfig = priv->ReceiveConfig & (~RCR_APM);
1795 priv->ReceiveConfig = priv->ReceiveConfig | RCR_AAP;
1798 if(priv->ieee80211->iw_mode == IW_MODE_MONITOR){
1799 priv->ReceiveConfig = priv->ReceiveConfig | RCR_ACF | RCR_APWRMGT | RCR_AICV;
1802 if( priv->crcmon == 1 && priv->ieee80211->iw_mode == IW_MODE_MONITOR)
1803 priv->ReceiveConfig = priv->ReceiveConfig | RCR_ACRC32;
1805 write_nic_dword(dev, RCR, priv->ReceiveConfig);
1809 cmd=read_nic_byte(dev,CMD);
1810 write_nic_byte(dev,CMD,cmd | (1<<CMD_RX_ENABLE_SHIFT));
1814 void rtl8185b_tx_enable(struct net_device *dev)
1818 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1820 write_nic_dword(dev, TCR, priv->TransmitConfig);
1821 byte = read_nic_byte(dev, MSR);
1822 byte |= MSR_LINK_ENEDCA;
1823 write_nic_byte(dev, MSR, byte);
1827 cmd=read_nic_byte(dev,CMD);
1828 write_nic_byte(dev,CMD,cmd | (1<<CMD_TX_ENABLE_SHIFT));