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 write_nic_byte(dev, offset, data);
135 read_nic_byte(dev, offset); // To make sure write operation is completed, 2005.11.09, by rcnjko.
140 PlatformIOWrite2Byte(
141 struct net_device *dev,
146 write_nic_word(dev, offset, data);
147 read_nic_word(dev, offset); // To make sure write operation is completed, 2005.11.09, by rcnjko.
151 u8 PlatformIORead1Byte(struct net_device *dev, u32 offset);
154 PlatformIOWrite4Byte(
155 struct net_device *dev,
161 if (offset == PhyAddr)
162 {//For Base Band configuration.
163 unsigned char cmdByte;
164 unsigned long dataBytes;
168 cmdByte = (u8)(data & 0x000000ff);
173 // The critical section is only BB read/write race condition.
175 // 1. We assume NO one will access BB at DIRQL, otherwise, system will crash for
176 // acquiring the spinlock in such context.
177 // 2. PlatformIOWrite4Byte() MUST NOT be recursive.
179 // NdisAcquireSpinLock( &(pDevice->IoSpinLock) );
181 for(idx = 0; idx < 30; idx++)
182 { // Make sure command bit is clear before access it.
183 u1bTmp = PlatformIORead1Byte(dev, PhyAddr);
184 if((u1bTmp & BIT7) == 0)
190 for(idx=0; idx < 3; idx++)
192 PlatformIOWrite1Byte(dev,offset+1+idx,((u8*)&dataBytes)[idx] );
194 write_nic_byte(dev, offset, cmdByte);
196 // NdisReleaseSpinLock( &(pDevice->IoSpinLock) );
200 write_nic_dword(dev, offset, data);
201 read_nic_dword(dev, offset); // To make sure write operation is completed, 2005.11.09, by rcnjko.
207 struct net_device *dev,
213 data = read_nic_byte(dev, offset);
221 struct net_device *dev,
227 data = read_nic_word(dev, offset);
235 struct net_device *dev,
241 data = read_nic_dword(dev, offset);
248 SetOutputEnableOfRfPins(
249 struct net_device *dev
252 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
254 switch(priv->rf_chip)
256 case RFCHIPID_RTL8225:
259 write_nic_word(dev, RFPinsEnable, 0x1bff);
260 //write_nic_word(dev, RFPinsEnable, 0x1fff);
267 struct net_device *dev,
275 u16 oval,oval2,oval3;
280 // RTL8187S HSSI Read/Write Function
281 u1bTmp = read_nic_byte(dev, RF_SW_CONFIG);
282 u1bTmp |= RF_SW_CFG_SI; //reg08[1]=1 Serial Interface(SI)
283 write_nic_byte(dev, RF_SW_CONFIG, u1bTmp);
284 UshortBuffer = read_nic_word(dev, RFPinsOutput);
285 oval = UshortBuffer & 0xfff8; // We shall clear bit0, 1, 2 first, 2005.10.28, by rcnjko.
287 oval2 = read_nic_word(dev, RFPinsEnable);
288 oval3 = read_nic_word(dev, RFPinsSelect);
290 // <RJ_NOTE> 3-wire should be controled by HW when we finish SW 3-wire programming. 2005.08.10, by rcnjko.
293 write_nic_word(dev, RFPinsEnable, (oval2|0x0007)); // Set To Output Enable
294 write_nic_word(dev, RFPinsSelect, (oval3|0x0007)); // Set To SW Switch
297 // Add this to avoid hardware and software 3-wire conflict.
298 // 2005.03.01, by rcnjko.
300 twreg.struc.enableB = 1;
301 write_nic_word(dev, RFPinsOutput, (twreg.longData|oval)); // Set SI_EN (RFLE)
303 twreg.struc.enableB = 0;
304 write_nic_word(dev, RFPinsOutput, (twreg.longData|oval)); // Clear SI_EN (RFLE)
307 mask = (low2high)?0x01:((u32)0x01<<(totalLength-1));
309 for(i=0; i<totalLength/2; i++)
311 twreg.struc.data = ((data2Write&mask)!=0) ? 1 : 0;
312 write_nic_word(dev, RFPinsOutput, (twreg.longData|oval));
314 write_nic_word(dev, RFPinsOutput, (twreg.longData|oval));
315 write_nic_word(dev, RFPinsOutput, (twreg.longData|oval));
317 mask = (low2high)?(mask<<1):(mask>>1);
318 twreg.struc.data = ((data2Write&mask)!=0) ? 1 : 0;
319 write_nic_word(dev, RFPinsOutput, (twreg.longData|oval));
320 write_nic_word(dev, RFPinsOutput, (twreg.longData|oval));
322 write_nic_word(dev, RFPinsOutput, (twreg.longData|oval));
323 mask = (low2high)?(mask<<1):(mask>>1);
326 twreg.struc.enableB = 1;
328 twreg.struc.data = 0;
329 write_nic_word(dev, RFPinsOutput, twreg.longData|oval);
332 write_nic_word(dev, RFPinsOutput, oval|0x0004);
333 write_nic_word(dev, RFPinsSelect, oval3|0x0000);
335 SetOutputEnableOfRfPins(dev);
342 struct net_device *dev,
355 // Check if WE and RE are cleared.
356 for(TryCnt = 0; TryCnt < TC_3W_POLL_MAX_TRY_CNT; TryCnt++)
358 u1bTmp = read_nic_byte(dev, SW_3W_CMD1);
359 if( (u1bTmp & (SW_3W_CMD1_RE|SW_3W_CMD1_WE)) == 0 )
365 if (TryCnt == TC_3W_POLL_MAX_TRY_CNT)
366 panic("HwThreeWire(): CmdReg: %#X RE|WE bits are not clear!!\n", u1bTmp);
368 // RTL8187S HSSI Read/Write Function
369 u1bTmp = read_nic_byte(dev, RF_SW_CONFIG);
373 u1bTmp |= RF_SW_CFG_SI; //reg08[1]=1 Serial Interface(SI)
376 u1bTmp &= ~RF_SW_CFG_SI; //reg08[1]=0 Parallel Interface(PI)
379 write_nic_byte(dev, RF_SW_CONFIG, u1bTmp);
383 // jong: HW SI read must set reg84[3]=0.
384 u1bTmp = read_nic_byte(dev, RFPinsSelect);
386 write_nic_byte(dev, RFPinsSelect, u1bTmp );
388 // Fill up data buffer for write operation.
392 if(nDataBufBitCnt == 16)
394 write_nic_word(dev, SW_3W_DB0, *((u16*)pDataBuf));
396 else if(nDataBufBitCnt == 64) // RTL8187S shouldn't enter this case
398 write_nic_dword(dev, SW_3W_DB0, *((u32*)pDataBuf));
399 write_nic_dword(dev, SW_3W_DB1, *((u32*)(pDataBuf + 4)));
404 int ByteCnt = nDataBufBitCnt / 8;
405 //printk("%d\n",nDataBufBitCnt);
406 if ((nDataBufBitCnt % 8) != 0)
407 panic("HwThreeWire(): nDataBufBitCnt(%d) should be multiple of 8!!!\n",
410 if (nDataBufBitCnt > 64)
411 panic("HwThreeWire(): nDataBufBitCnt(%d) should <= 64!!!\n",
414 for(idx = 0; idx < ByteCnt; idx++)
416 write_nic_byte(dev, (SW_3W_DB0+idx), *(pDataBuf+idx));
424 // SI - reg274[3:0] : RF register's Address
425 write_nic_word(dev, SW_3W_DB0, *((u16*)pDataBuf) );
429 // PI - reg274[15:12] : RF register's Address
430 write_nic_word(dev, SW_3W_DB0, (*((u16*)pDataBuf)) << 12);
434 // Set up command: WE or RE.
437 write_nic_byte(dev, SW_3W_CMD1, SW_3W_CMD1_WE);
441 write_nic_byte(dev, SW_3W_CMD1, SW_3W_CMD1_RE);
444 // Check if DONE is set.
445 for(TryCnt = 0; TryCnt < TC_3W_POLL_MAX_TRY_CNT; TryCnt++)
447 u1bTmp = read_nic_byte(dev, SW_3W_CMD1);
448 if( (u1bTmp & SW_3W_CMD1_DONE) != 0 )
455 write_nic_byte(dev, SW_3W_CMD1, 0);
457 // Read back data for read operation.
462 //Serial Interface : reg363_362[11:0]
463 *((u16*)pDataBuf) = read_nic_word(dev, SI_DATA_READ) ;
467 //Parallel Interface : reg361_360[11:0]
468 *((u16*)pDataBuf) = read_nic_word(dev, PI_DATA_READ);
471 *((u16*)pDataBuf) &= 0x0FFF;
482 struct net_device *dev,
495 // Check if WE and RE are cleared.
496 for(TryCnt = 0; TryCnt < TC_3W_POLL_MAX_TRY_CNT; TryCnt++)
498 u1bTmp = read_nic_byte(dev, SW_3W_CMD1);
499 if( (u1bTmp & (SW_3W_CMD1_RE|SW_3W_CMD1_WE)) == 0 )
505 if (TryCnt == TC_3W_POLL_MAX_TRY_CNT)
506 panic("HwThreeWire(): CmdReg: %#X RE|WE bits are not clear!!\n", u1bTmp);
508 // Fill up data buffer for write operation.
509 if(nDataBufBitCnt == 16)
511 write_nic_word(dev, SW_3W_DB0, *((u16 *)pDataBuf));
513 else if(nDataBufBitCnt == 64)
515 write_nic_dword(dev, SW_3W_DB0, *((u32 *)pDataBuf));
516 write_nic_dword(dev, SW_3W_DB1, *((u32 *)(pDataBuf + 4)));
521 int ByteCnt = nDataBufBitCnt / 8;
523 if ((nDataBufBitCnt % 8) != 0)
524 panic("HwThreeWire(): nDataBufBitCnt(%d) should be multiple of 8!!!\n",
527 if (nDataBufBitCnt > 64)
528 panic("HwThreeWire(): nDataBufBitCnt(%d) should <= 64!!!\n",
531 for(idx = 0; idx < ByteCnt; idx++)
533 write_nic_byte(dev, (SW_3W_DB0+idx), *(pDataBuf+idx));
537 // Fill up length field.
538 u1bTmp = (u8)(nDataBufBitCnt - 1); // Number of bits - 1.
540 u1bTmp |= SW_3W_CMD0_HOLD;
541 write_nic_byte(dev, SW_3W_CMD0, u1bTmp);
543 // Set up command: WE or RE.
546 write_nic_byte(dev, SW_3W_CMD1, SW_3W_CMD1_WE);
550 write_nic_byte(dev, SW_3W_CMD1, SW_3W_CMD1_RE);
553 // Check if WE and RE are cleared and DONE is set.
554 for(TryCnt = 0; TryCnt < TC_3W_POLL_MAX_TRY_CNT; TryCnt++)
556 u1bTmp = read_nic_byte(dev, SW_3W_CMD1);
557 if( (u1bTmp & (SW_3W_CMD1_RE|SW_3W_CMD1_WE)) == 0 &&
558 (u1bTmp & SW_3W_CMD1_DONE) != 0 )
564 if(TryCnt == TC_3W_POLL_MAX_TRY_CNT)
566 //RT_ASSERT(TryCnt != TC_3W_POLL_MAX_TRY_CNT,
567 // ("HwThreeWire(): CmdReg: %#X RE|WE bits are not clear or DONE is not set!!\n", u1bTmp));
568 // Workaround suggested by wcchu: clear WE here. 2006.07.07, by rcnjko.
569 write_nic_byte(dev, SW_3W_CMD1, 0);
572 // Read back data for read operation.
573 // <RJ_TODO> I am not sure if this is correct output format of a read operation.
576 if(nDataBufBitCnt == 16)
578 *((u16 *)pDataBuf) = read_nic_word(dev, SW_3W_DB0);
580 else if(nDataBufBitCnt == 64)
582 *((u32 *)pDataBuf) = read_nic_dword(dev, SW_3W_DB0);
583 *((u32 *)(pDataBuf + 4)) = read_nic_dword(dev, SW_3W_DB1);
588 int ByteCnt = nDataBufBitCnt / 8;
590 if ((nDataBufBitCnt % 8) != 0)
591 panic("HwThreeWire(): nDataBufBitCnt(%d) should be multiple of 8!!!\n",
594 if (nDataBufBitCnt > 64)
595 panic("HwThreeWire(): nDataBufBitCnt(%d) should <= 64!!!\n",
598 for(idx = 0; idx < ByteCnt; idx++)
600 *(pDataBuf+idx) = read_nic_byte(dev, (SW_3W_DB0+idx));
613 struct net_device *dev,
623 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
626 switch(priv->rf_chip)
628 case RFCHIPID_RTL8225:
629 case RF_ZEBRA2: // Annie 2006-05-12.
630 case RF_ZEBRA4: //by amy
631 switch(priv->RegThreeWireMode)
634 { // Perform SW 3-wire programming by driver.
635 data2Write = (data << 4) | (u32)(offset & 0x0f);
638 ZEBRA_RFSerialWrite(dev, data2Write, len, low2high);
644 data2Write = (data << 4) | (u32)(offset & 0x0f);
648 (u8 *)(&data2Write), // pDataBuf,
649 len, // nDataBufBitCnt,
654 case HW_THREE_WIRE_PI: //Parallel Interface
656 data2Write = (data << 4) | (u32)(offset & 0x0f);
660 (u8*)(&data2Write), // pDataBuf,
661 len, // nDataBufBitCnt,
669 case HW_THREE_WIRE_SI: //Serial Interface
671 data2Write = (data << 4) | (u32)(offset & 0x0f);
673 // printk(" enter ZEBRA_RFSerialWrite\n ");
675 // ZEBRA_RFSerialWrite(dev, data2Write, len, low2high);
679 (u8*)(&data2Write), // pDataBuf,
680 len, // nDataBufBitCnt,
684 // printk(" exit ZEBRA_RFSerialWrite\n ");
690 DMESGE("RF_WriteReg(): invalid RegThreeWireMode(%d) !!!", priv->RegThreeWireMode);
696 DMESGE("RF_WriteReg(): unknown RFChipID: %#X", priv->rf_chip);
704 struct net_device *dev,
714 u16 oval,oval2,oval3,tmp, wReg80;
718 //PHAL_DATA_8187 pHalData = GetHalData8187(pAdapter);
719 { // RTL8187S HSSI Read/Write Function
720 u1bTmp = read_nic_byte(dev, RF_SW_CONFIG);
721 u1bTmp |= RF_SW_CFG_SI; //reg08[1]=1 Serial Interface(SI)
722 write_nic_byte(dev, RF_SW_CONFIG, u1bTmp);
725 wReg80 = oval = read_nic_word(dev, RFPinsOutput);
726 oval2 = read_nic_word(dev, RFPinsEnable);
727 oval3 = read_nic_word(dev, RFPinsSelect);
729 write_nic_word(dev, RFPinsEnable, oval2|0xf);
730 write_nic_word(dev, RFPinsSelect, oval3|0xf);
734 // We must clear BIT0-3 here, otherwise,
735 // SW_Enalbe will be true when we first call ZEBRA_RFSerialRead() after 8187MPVC open,
736 // which will cause the value read become 0. 2005.04.11, by rcnjko.
739 // Avoid collision with hardware three-wire.
741 twreg.struc.enableB = 1;
742 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(4);
745 twreg.struc.enableB = 0;
747 twreg.struc.read_write = 0;
748 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(5);
750 mask = (low2high) ? 0x01 : ((u32)0x01<<(32-1));
751 for(i = 0; i < wLength/2; i++)
753 twreg.struc.data = ((data2Write&mask) != 0) ? 1 : 0;
754 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(1);
756 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
757 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
759 mask = (low2high) ? (mask<<1): (mask>>1);
763 // 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.
764 //PlatformEFIOWrite2Byte(pAdapter, RFPinsEnable, 0xe); // turn off data enable
765 //PlatformEFIOWrite2Byte(pAdapter, RFPinsSelect, 0xe);
767 twreg.struc.read_write=1;
768 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
770 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
773 twreg.struc.data = ((data2Write&mask) != 0) ? 1: 0;
774 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
775 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
778 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(1);
780 mask = (low2high) ? (mask<<1) : (mask>>1);
784 twreg.struc.data = 0;
785 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
786 mask = (low2high) ? 0x01 : ((u32)0x01 << (12-1));
789 // 061016, by rcnjko:
790 // We must set data pin to HW controled, otherwise RF can't driver it and
791 // value RF register won't be able to read back properly.
793 write_nic_word(dev, RFPinsEnable, ( ((oval2|0x0E) & (~0x01))) );
795 for(i = 0; i < rLength; i++)
797 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(1);
799 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
800 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
801 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
802 tmp = read_nic_word(dev, RFPinsInput);
803 tdata.longData = tmp;
804 *data2Read |= tdata.struc.clk ? mask : 0;
807 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
809 mask = (low2high) ? (mask<<1) : (mask>>1);
811 twreg.struc.enableB = 1;
813 twreg.struc.data = 0;
814 twreg.struc.read_write = 1;
815 write_nic_word(dev, RFPinsOutput, twreg.longData|oval); udelay(2);
817 //PlatformEFIOWrite2Byte(pAdapter, RFPinsEnable, oval2|0x8); // Set To Output Enable
818 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.
819 //PlatformEFIOWrite2Byte(pAdapter, RFPinsEnable, 0x1bff);
820 write_nic_word(dev, RFPinsSelect, oval3); // Set To SW Switch
821 //PlatformEFIOWrite2Byte(pAdapter, RFPinsSelect, 0x0488);
822 write_nic_word(dev, RFPinsOutput, 0x3a0);
823 //PlatformEFIOWrite2Byte(pAdapter, RFPinsOutput, 0x0480);
829 struct net_device *dev,
833 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
840 switch(priv->rf_chip)
842 case RFCHIPID_RTL8225:
845 switch(priv->RegThreeWireMode)
847 case HW_THREE_WIRE_PI: // For 87S Parallel Interface.
849 data2Write = ((u32)(offset&0x0f));
853 (u8*)(&data2Write), // pDataBuf,
854 wlen, // nDataBufBitCnt,
857 dataRead= data2Write;
861 case HW_THREE_WIRE_SI: // For 87S Serial Interface.
863 data2Write = ((u32)(offset&0x0f)) ;
867 (u8*)(&data2Write), // pDataBuf,
868 wlen, // nDataBufBitCnt,
872 dataRead= data2Write;
876 // Perform SW 3-wire programming by driver.
879 data2Write = ((u32)(offset&0x1f)) << 27; // For Zebra E-cut. 2005.04.11, by rcnjko.
883 ZEBRA_RFSerialRead(dev, data2Write, wlen,&dataRead,rlen, low2high);
897 // by Owen on 04/07/14 for writing BB register successfully
900 struct net_device *dev,
908 UCharData = (u8)((Data & 0x0000ff00) >> 8);
909 PlatformIOWrite4Byte(dev, PhyAddr, Data);
910 //for(TimeoutCounter = 10; TimeoutCounter > 0; TimeoutCounter--)
912 PlatformIOWrite4Byte(dev, PhyAddr, Data & 0xffffff7f);
913 RegisterContent = PlatformIORead1Byte(dev, PhyDataR);
914 //if(UCharData == RegisterContent)
921 struct net_device *dev,
928 PlatformIOWrite4Byte(dev, PhyAddr, addr & 0xffffff7f);
929 RegisterContent = PlatformIORead1Byte(dev, PhyDataR);
931 return RegisterContent;
936 // Perform Antenna settings with antenna diversity on 87SE.
937 // Created by Roger, 2008.01.25.
940 SetAntennaConfig87SE(
941 struct net_device *dev,
942 u8 DefaultAnt, // 0: Main, 1: Aux.
943 bool bAntDiversity // 1:Enable, 0: Disable.
946 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
947 bool bAntennaSwitched = true;
949 //printk("SetAntennaConfig87SE(): DefaultAnt(%d), bAntDiversity(%d)\n", DefaultAnt, bAntDiversity);
951 // Threshold for antenna diversity.
952 write_phy_cck(dev, 0x0c, 0x09); // Reg0c : 09
954 if( bAntDiversity ) // Enable Antenna Diversity.
956 if( DefaultAnt == 1 ) // aux antenna
958 // Mac register, aux antenna
959 write_nic_byte(dev, ANTSEL, 0x00);
961 // Config CCK RX antenna.
962 write_phy_cck(dev, 0x11, 0xbb); // Reg11 : bb
963 write_phy_cck(dev, 0x01, 0xc7); // Reg01 : c7
965 // Config OFDM RX antenna.
966 write_phy_ofdm(dev, 0x0D, 0x54); // Reg0d : 54
967 write_phy_ofdm(dev, 0x18, 0xb2); // Reg18 : b2
969 else // use main antenna
971 // Mac register, main antenna
972 write_nic_byte(dev, ANTSEL, 0x03);
974 // Config CCK RX antenna.
975 write_phy_cck(dev, 0x11, 0x9b); // Reg11 : 9b
976 write_phy_cck(dev, 0x01, 0xc7); // Reg01 : c7
978 // Config OFDM RX antenna.
979 write_phy_ofdm(dev, 0x0d, 0x5c); // Reg0d : 5c
980 write_phy_ofdm(dev, 0x18, 0xb2); // Reg18 : b2
983 else // Disable Antenna Diversity.
985 if( DefaultAnt == 1 ) // aux Antenna
987 // Mac register, aux antenna
988 write_nic_byte(dev, ANTSEL, 0x00);
990 // Config CCK RX antenna.
991 write_phy_cck(dev, 0x11, 0xbb); // Reg11 : bb
992 write_phy_cck(dev, 0x01, 0x47); // Reg01 : 47
994 // Config OFDM RX antenna.
995 write_phy_ofdm(dev, 0x0D, 0x54); // Reg0d : 54
996 write_phy_ofdm(dev, 0x18, 0x32); // Reg18 : 32
1000 // Mac register, main antenna
1001 write_nic_byte(dev, ANTSEL, 0x03);
1003 // Config CCK RX antenna.
1004 write_phy_cck(dev, 0x11, 0x9b); // Reg11 : 9b
1005 write_phy_cck(dev, 0x01, 0x47); // Reg01 : 47
1007 // Config OFDM RX antenna.
1008 write_phy_ofdm(dev, 0x0D, 0x5c); // Reg0d : 5c
1009 write_phy_ofdm(dev, 0x18, 0x32); // Reg18 : 32
1012 priv->CurrAntennaIndex = DefaultAnt; // Update default settings.
1013 return bAntennaSwitched;
1016 /*---------------------------------------------------------------
1017 * Hardware Initialization.
1018 * the code is ported from Windows source code
1019 ----------------------------------------------------------------*/
1022 ZEBRA_Config_85BASIC_HardCode(
1023 struct net_device *dev
1027 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1030 u32 u4bRegOffset, u4bRegValue, u4bRF23, u4bRF24;
1034 //=============================================================================
1035 // 87S_PCIE :: RADIOCFG.TXT
1036 //=============================================================================
1039 // Page1 : reg16-reg30
1040 RF_WriteReg(dev, 0x00, 0x013f); mdelay(1); // switch to page1
1041 u4bRF23= RF_ReadReg(dev, 0x08); mdelay(1);
1042 u4bRF24= RF_ReadReg(dev, 0x09); mdelay(1);
1044 if (u4bRF23==0x818 && u4bRF24==0x70C && priv->card_8185 == VERSION_8187S_C)
1045 priv->card_8185 = VERSION_8187S_D;
1047 // Page0 : reg0-reg15
1049 // RF_WriteReg(dev, 0x00, 0x003f); mdelay(1);//1
1050 RF_WriteReg(dev, 0x00, 0x009f); mdelay(1);// 1
1052 RF_WriteReg(dev, 0x01, 0x06e0); mdelay(1);
1054 // RF_WriteReg(dev, 0x02, 0x004c); mdelay(1);//2
1055 RF_WriteReg(dev, 0x02, 0x004d); mdelay(1);// 2
1057 // RF_WriteReg(dev, 0x03, 0x0000); mdelay(1);//3
1058 RF_WriteReg(dev, 0x03, 0x07f1); mdelay(1);// 3
1060 RF_WriteReg(dev, 0x04, 0x0975); mdelay(1);
1061 RF_WriteReg(dev, 0x05, 0x0c72); mdelay(1);
1062 RF_WriteReg(dev, 0x06, 0x0ae6); mdelay(1);
1063 RF_WriteReg(dev, 0x07, 0x00ca); mdelay(1);
1064 RF_WriteReg(dev, 0x08, 0x0e1c); mdelay(1);
1065 RF_WriteReg(dev, 0x09, 0x02f0); mdelay(1);
1066 RF_WriteReg(dev, 0x0a, 0x09d0); mdelay(1);
1067 RF_WriteReg(dev, 0x0b, 0x01ba); mdelay(1);
1068 RF_WriteReg(dev, 0x0c, 0x0640); mdelay(1);
1069 RF_WriteReg(dev, 0x0d, 0x08df); mdelay(1);
1070 RF_WriteReg(dev, 0x0e, 0x0020); mdelay(1);
1071 RF_WriteReg(dev, 0x0f, 0x0990); mdelay(1);
1074 // Page1 : reg16-reg30
1075 RF_WriteReg(dev, 0x00, 0x013f); mdelay(1);
1077 RF_WriteReg(dev, 0x03, 0x0806); mdelay(1);
1079 if(priv->card_8185 < VERSION_8187S_C)
1081 RF_WriteReg(dev, 0x04, 0x03f7); mdelay(1);
1082 RF_WriteReg(dev, 0x05, 0x05ab); mdelay(1);
1083 RF_WriteReg(dev, 0x06, 0x00c1); mdelay(1);
1087 RF_WriteReg(dev, 0x04, 0x03a7); mdelay(1);
1088 RF_WriteReg(dev, 0x05, 0x059b); mdelay(1);
1089 RF_WriteReg(dev, 0x06, 0x0081); mdelay(1);
1093 RF_WriteReg(dev, 0x07, 0x01A0); mdelay(1);
1094 // Don't write RF23/RF24 to make a difference between 87S C cut and D cut. asked by SD3 stevenl.
1095 // RF_WriteReg(dev, 0x08, 0x0597); mdelay(1);
1096 // RF_WriteReg(dev, 0x09, 0x050a); mdelay(1);
1097 RF_WriteReg(dev, 0x0a, 0x0001); mdelay(1);
1098 RF_WriteReg(dev, 0x0b, 0x0418); mdelay(1);
1100 if(priv->card_8185 == VERSION_8187S_D)
1102 RF_WriteReg(dev, 0x0c, 0x0fbe); mdelay(1);
1103 RF_WriteReg(dev, 0x0d, 0x0008); mdelay(1);
1104 RF_WriteReg(dev, 0x0e, 0x0807); mdelay(1); // RX LO buffer
1108 RF_WriteReg(dev, 0x0c, 0x0fbe); mdelay(1);
1109 RF_WriteReg(dev, 0x0d, 0x0008); mdelay(1);
1110 RF_WriteReg(dev, 0x0e, 0x0806); mdelay(1); // RX LO buffer
1113 RF_WriteReg(dev, 0x0f, 0x0acc); mdelay(1);
1115 // RF_WriteReg(dev, 0x00, 0x017f); mdelay(1);//6
1116 RF_WriteReg(dev, 0x00, 0x01d7); mdelay(1);// 6
1118 RF_WriteReg(dev, 0x03, 0x0e00); mdelay(1);
1119 RF_WriteReg(dev, 0x04, 0x0e50); mdelay(1);
1122 RF_WriteReg(dev, 0x01, i); mdelay(1);
1123 RF_WriteReg(dev, 0x02, ZEBRA_RF_RX_GAIN_TABLE[i]); mdelay(1);
1124 //DbgPrint("RF - 0x%x = 0x%x", i, ZEBRA_RF_RX_GAIN_TABLE[i]);
1127 RF_WriteReg(dev, 0x05, 0x0203); mdelay(1); /// 203, 343
1128 //RF_WriteReg(dev, 0x06, 0x0300); mdelay(1); // 400
1129 RF_WriteReg(dev, 0x06, 0x0200); mdelay(1); // 400
1131 RF_WriteReg(dev, 0x00, 0x0137); mdelay(1); // switch to reg16-reg30, and HSSI disable 137
1132 mdelay(10); // Deay 10 ms. //0xfd
1134 // RF_WriteReg(dev, 0x0c, 0x09be); mdelay(1); // 7
1135 //RF_WriteReg(dev, 0x0c, 0x07be); mdelay(1);
1136 //mdelay(10); // Deay 10 ms. //0xfd
1138 RF_WriteReg(dev, 0x0d, 0x0008); mdelay(1); // Z4 synthesizer loop filter setting, 392
1139 mdelay(10); // Deay 10 ms. //0xfd
1141 RF_WriteReg(dev, 0x00, 0x0037); mdelay(1); // switch to reg0-reg15, and HSSI disable
1142 mdelay(10); // Deay 10 ms. //0xfd
1144 RF_WriteReg(dev, 0x04, 0x0160); mdelay(1); // CBC on, Tx Rx disable, High gain
1145 mdelay(10); // Deay 10 ms. //0xfd
1147 RF_WriteReg(dev, 0x07, 0x0080); mdelay(1); // Z4 setted channel 1
1148 mdelay(10); // Deay 10 ms. //0xfd
1150 RF_WriteReg(dev, 0x02, 0x088D); mdelay(1); // LC calibration
1151 mdelay(200); // Deay 200 ms. //0xfd
1152 mdelay(10); // Deay 10 ms. //0xfd
1153 mdelay(10); // Deay 10 ms. //0xfd
1155 RF_WriteReg(dev, 0x00, 0x0137); mdelay(1); // switch to reg16-reg30 137, and HSSI disable 137
1156 mdelay(10); // Deay 10 ms. //0xfd
1158 RF_WriteReg(dev, 0x07, 0x0000); mdelay(1);
1159 RF_WriteReg(dev, 0x07, 0x0180); mdelay(1);
1160 RF_WriteReg(dev, 0x07, 0x0220); mdelay(1);
1161 RF_WriteReg(dev, 0x07, 0x03E0); mdelay(1);
1163 // DAC calibration off 20070702
1164 RF_WriteReg(dev, 0x06, 0x00c1); mdelay(1);
1165 RF_WriteReg(dev, 0x0a, 0x0001); mdelay(1);
1167 // For crystal calibration, added by Roger, 2007.12.11.
1168 if( priv->bXtalCalibration ) // reg 30.
1169 { // enable crystal calibration.
1170 // RF Reg[30], (1)Xin:[12:9], Xout:[8:5], addr[4:0].
1171 // (2)PA Pwr delay timer[15:14], default: 2.4us, set BIT15=0
1172 // (3)RF signal on/off when calibration[13], default: on, set BIT13=0.
1173 // So we should minus 4 BITs offset.
1174 RF_WriteReg(dev, 0x0f, (priv->XtalCal_Xin<<5)|(priv->XtalCal_Xout<<1)|BIT11|BIT9); mdelay(1);
1175 printk("ZEBRA_Config_85BASIC_HardCode(): (%02x)\n",
1176 (priv->XtalCal_Xin<<5) | (priv->XtalCal_Xout<<1) | BIT11| BIT9);
1179 { // using default value. Xin=6, Xout=6.
1180 RF_WriteReg(dev, 0x0f, 0x0acc); mdelay(1);
1183 // RF_WriteReg(dev, 0x0f, 0x0acc); mdelay(1); //-by amy 080312
1185 RF_WriteReg(dev, 0x00, 0x00bf); mdelay(1); // switch to reg0-reg15, and HSSI enable
1186 // RF_WriteReg(dev, 0x0d, 0x009f); mdelay(1); // Rx BB start calibration, 00c//-edward
1187 RF_WriteReg(dev, 0x0d, 0x08df); mdelay(1); // Rx BB start calibration, 00c//+edward
1188 RF_WriteReg(dev, 0x02, 0x004d); mdelay(1); // temperature meter off
1189 RF_WriteReg(dev, 0x04, 0x0975); mdelay(1); // Rx mode
1190 mdelay(10); // Deay 10 ms. //0xfe
1191 mdelay(10); // Deay 10 ms. //0xfe
1192 mdelay(10); // Deay 10 ms. //0xfe
1193 RF_WriteReg(dev, 0x00, 0x0197); mdelay(1); // Rx mode//+edward
1194 RF_WriteReg(dev, 0x05, 0x05ab); mdelay(1); // Rx mode//+edward
1195 RF_WriteReg(dev, 0x00, 0x009f); mdelay(1); // Rx mode//+edward
1197 RF_WriteReg(dev, 0x01, 0x0000); mdelay(1); // Rx mode//+edward
1198 RF_WriteReg(dev, 0x02, 0x0000); mdelay(1); // Rx mode//+edward
1199 //power save parameters.
1200 u1b24E = read_nic_byte(dev, 0x24E);
1201 write_nic_byte(dev, 0x24E, (u1b24E & (~(BIT5|BIT6))));
1203 //=============================================================================
1205 //=============================================================================
1207 //=============================================================================
1209 /* [POWER SAVE] Power Saving Parameters by jong. 2007-11-27
1210 CCK reg0x00[7]=1'b1 :power saving for TX (default)
1211 CCK reg0x00[6]=1'b1: power saving for RX (default)
1212 CCK reg0x06[4]=1'b1: turn off channel estimation related circuits if not doing channel estimation.
1213 CCK reg0x06[3]=1'b1: turn off unused circuits before cca = 1
1214 CCK reg0x06[2]=1'b1: turn off cck's circuit if macrst =0
1217 write_phy_cck(dev,0x00,0xc8);
1218 write_phy_cck(dev,0x06,0x1c);
1219 write_phy_cck(dev,0x10,0x78);
1220 write_phy_cck(dev,0x2e,0xd0);
1221 write_phy_cck(dev,0x2f,0x06);
1222 write_phy_cck(dev,0x01,0x46);
1225 write_nic_byte(dev, CCK_TXAGC, 0x10);
1226 write_nic_byte(dev, OFDM_TXAGC, 0x1B);
1227 write_nic_byte(dev, ANTSEL, 0x03);
1231 //=============================================================================
1233 //=============================================================================
1235 // PlatformIOWrite4Byte( dev, PhyAddr, 0x00001280); // Annie, 2006-05-05
1236 write_phy_ofdm(dev, 0x00, 0x12);
1237 //WriteBBPortUchar(dev, 0x00001280);
1239 for (i=0; i<128; i++)
1241 //DbgPrint("AGC - [%x+1] = 0x%x\n", i, ZEBRA_AGC[i+1]);
1243 data = ZEBRA_AGC[i+1];
1245 data = data | 0x0000008F;
1247 addr = i + 0x80; //enable writing AGC table
1249 addr = addr | 0x0000008E;
1251 WriteBBPortUchar(dev, data);
1252 WriteBBPortUchar(dev, addr);
1253 WriteBBPortUchar(dev, 0x0000008E);
1256 PlatformIOWrite4Byte( dev, PhyAddr, 0x00001080); // Annie, 2006-05-05
1257 //WriteBBPortUchar(dev, 0x00001080);
1259 //=============================================================================
1261 //=============================================================================
1263 //=============================================================================
1268 u4bRegValue=OFDM_CONFIG[i];
1270 //DbgPrint("OFDM - 0x%x = 0x%x\n", u4bRegOffset, u4bRegValue);
1272 WriteBBPortUchar(dev,
1274 (u4bRegOffset & 0x7f) |
1275 ((u4bRegValue & 0xff) << 8)));
1278 //=============================================================================
1279 //by amy for antenna
1280 //=============================================================================
1282 // Config Sw/Hw Combinational Antenna Diversity. Added by Roger, 2008.02.26.
1283 SetAntennaConfig87SE(dev, priv->bDefaultAntenna1, priv->bSwAntennaDiverity);
1285 //by amy for antenna
1291 struct net_device *dev
1294 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1295 //unsigned char* IGTable;
1296 //u8 DIG_CurrentInitialGain = 4;
1297 //unsigned char u1Tmp;
1300 if(priv->eRFPowerState != eRfOn)
1302 //Don't access BB/RF under disable PLL situation.
1303 //RT_TRACE(COMP_DIG, DBG_LOUD, ("UpdateInitialGain - pHalData->eRFPowerState!=eRfOn\n"));
1304 // Back to the original state
1305 priv->InitialGain= priv->InitialGainBackUp;
1309 switch(priv->rf_chip)
1312 // Dynamic set initial gain, follow 87B
1313 switch(priv->InitialGain)
1316 //DMESG("RTL8187 + 8225 Initial Gain State 1: -82 dBm \n");
1317 write_phy_ofdm(dev, 0x17, 0x26); mdelay(1);
1318 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
1319 write_phy_ofdm(dev, 0x05, 0xfa); mdelay(1);
1323 //DMESG("RTL8187 + 8225 Initial Gain State 2: -82 dBm \n");
1324 write_phy_ofdm(dev, 0x17, 0x36); mdelay(1);
1325 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
1326 write_phy_ofdm(dev, 0x05, 0xfa); mdelay(1);
1330 //DMESG("RTL8187 + 8225 Initial Gain State 3: -82 dBm \n");
1331 write_phy_ofdm(dev, 0x17, 0x36); mdelay(1);
1332 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
1333 write_phy_ofdm(dev, 0x05, 0xfb); mdelay(1);
1337 //DMESG("RTL8187 + 8225 Initial Gain State 4: -78 dBm \n");
1338 write_phy_ofdm(dev, 0x17, 0x46); mdelay(1);
1339 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
1340 write_phy_ofdm(dev, 0x05, 0xfb); mdelay(1);
1344 //DMESG("RTL8187 + 8225 Initial Gain State 5: -74 dBm \n");
1345 write_phy_ofdm(dev, 0x17, 0x46); mdelay(1);
1346 write_phy_ofdm(dev, 0x24, 0x96); mdelay(1);
1347 write_phy_ofdm(dev, 0x05, 0xfb); mdelay(1);
1351 //DMESG ("RTL8187 + 8225 Initial Gain State 6: -70 dBm \n");
1352 write_phy_ofdm(dev, 0x17, 0x56); mdelay(1);
1353 write_phy_ofdm(dev, 0x24, 0x96); mdelay(1);
1354 write_phy_ofdm(dev, 0x05, 0xfc); mdelay(1);
1358 //DMESG("RTL8187 + 8225 Initial Gain State 7: -66 dBm \n");
1359 write_phy_ofdm(dev, 0x17, 0x56); mdelay(1);
1360 write_phy_ofdm(dev, 0x24, 0xa6); mdelay(1);
1361 write_phy_ofdm(dev, 0x05, 0xfc); mdelay(1);
1365 //DMESG("RTL8187 + 8225 Initial Gain State 8:\n");
1366 write_phy_ofdm(dev, 0x17, 0x66); mdelay(1);
1367 write_phy_ofdm(dev, 0x24, 0xb6); mdelay(1);
1368 write_phy_ofdm(dev, 0x05, 0xfc); mdelay(1);
1373 //DMESG("RTL8187 + 8225 Initial Gain State 1: -82 dBm (default)\n");
1374 write_phy_ofdm(dev, 0x17, 0x26); mdelay(1);
1375 write_phy_ofdm(dev, 0x24, 0x86); mdelay(1);
1376 write_phy_ofdm(dev, 0x05, 0xfa); mdelay(1);
1383 DMESG("UpdateInitialGain(): unknown RFChipID: %#X\n", priv->rf_chip);
1389 // Tx Power tracking mechanism routine on 87SE.
1390 // Created by Roger, 2007.12.11.
1393 InitTxPwrTracking87SE(
1394 struct net_device *dev
1397 //struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1400 u4bRfReg = RF_ReadReg(dev, 0x02);
1402 // Enable Thermal meter indication.
1403 //printk("InitTxPwrTracking87SE(): Enable thermal meter indication, Write RF[0x02] = %#x", u4bRfReg|PWR_METER_EN);
1404 RF_WriteReg(dev, 0x02, u4bRfReg|PWR_METER_EN); mdelay(1);
1409 struct net_device *dev
1412 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1413 write_nic_dword(dev, RCR, priv->ReceiveConfig);
1414 priv->RFProgType = read_nic_byte(dev, CONFIG4) & 0x03;
1416 switch(priv->rf_chip)
1420 ZEBRA_Config_85BASIC_HardCode( dev);
1424 // Set default initial gain state to 4, approved by SD3 DZ, by Bruce, 2007-06-06.
1425 if(priv->bDigMechanism)
1427 if(priv->InitialGain == 0)
1428 priv->InitialGain = 4;
1429 //printk("PhyConfig8185(): DIG is enabled, set default initial gain index to %d\n", priv->InitialGain);
1433 // Enable thermal meter indication to implement TxPower tracking on 87SE.
1434 // We initialize thermal meter here to avoid unsuccessful configuration.
1435 // Added by Roger, 2007.12.11.
1437 if(priv->bTxPowerTrack)
1438 InitTxPwrTracking87SE(dev);
1441 priv->InitialGainBackUp= priv->InitialGain;
1442 UpdateInitialGain(dev);
1452 struct net_device *dev
1455 //RTL8185_TODO: Determine Retrylimit, TxAGC, AutoRateFallback control.
1456 // u8 bUNIVERSAL_CONTROL_RL = 1;
1457 u8 bUNIVERSAL_CONTROL_RL = 0;
1459 u8 bUNIVERSAL_CONTROL_AGC = 1;
1460 u8 bUNIVERSAL_CONTROL_ANT = 1;
1461 u8 bAUTO_RATE_FALLBACK_CTL = 1;
1463 //struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1464 //struct ieee80211_device *ieee = priv->ieee80211;
1465 //if(IS_WIRELESS_MODE_A(dev) || IS_WIRELESS_MODE_G(dev))
1466 //{by amy 080312 if((ieee->mode == IEEE_G)||(ieee->mode == IEEE_A))
1468 // write_nic_word(dev, BRSR, 0xffff);
1472 // write_nic_word(dev, BRSR, 0x000f);
1475 write_nic_word(dev, BRSR, 0x0fff);
1477 val8 = read_nic_byte(dev, CW_CONF);
1479 if(bUNIVERSAL_CONTROL_RL)
1484 write_nic_byte(dev, CW_CONF, val8);
1487 val8 = read_nic_byte(dev, TXAGC_CTL);
1488 if(bUNIVERSAL_CONTROL_AGC)
1490 write_nic_byte(dev, CCK_TXAGC, 128);
1491 write_nic_byte(dev, OFDM_TXAGC, 128);
1496 val8 = val8 | 0x01 ;
1500 write_nic_byte(dev, TXAGC_CTL, val8);
1502 // Tx Antenna including Feedback control
1503 val8 = read_nic_byte(dev, TXAGC_CTL );
1505 if(bUNIVERSAL_CONTROL_ANT)
1507 write_nic_byte(dev, ANTSEL, 0x00);
1512 val8 = val8 & (val8|0x02); //xiong-2006-11-15
1515 write_nic_byte(dev, TXAGC_CTL, val8);
1517 // Auto Rate fallback control
1518 val8 = read_nic_byte(dev, RATE_FALLBACK);
1520 if( bAUTO_RATE_FALLBACK_CTL )
1522 val8 |= RATE_FALLBACK_CTL_ENABLE | RATE_FALLBACK_CTL_AUTO_STEP1;
1524 // <RJ_TODO_8185B> We shall set up the ARFR according to user's setting.
1525 //write_nic_word(dev, ARFR, 0x0fff); // set 1M ~ 54M
1527 // Aadded by Roger, 2007.11.15.
1528 PlatformIOWrite2Byte(dev, ARFR, 0x0fff); //set 1M ~ 54Mbps.
1534 write_nic_byte(dev, RATE_FALLBACK, val8);
1540 MacConfig_85BASIC_HardCode(
1541 struct net_device *dev)
1543 //============================================================================
1545 //============================================================================
1548 u32 u4bRegOffset, u4bRegValue,u4bPageIndex = 0;
1551 nLinesRead=sizeof(MAC_REG_TABLE)/2;
1553 for(i = 0; i < nLinesRead; i++) //nLinesRead=101
1555 u4bRegOffset=MAC_REG_TABLE[i][0];
1556 u4bRegValue=MAC_REG_TABLE[i][1];
1558 if(u4bRegOffset == 0x5e)
1560 u4bPageIndex = u4bRegValue;
1564 u4bRegOffset |= (u4bPageIndex << 8);
1566 //DbgPrint("MAC - 0x%x = 0x%x\n", u4bRegOffset, u4bRegValue);
1567 write_nic_byte(dev, u4bRegOffset, (u8)u4bRegValue);
1569 //============================================================================
1576 struct net_device *dev)
1580 MacConfig_85BASIC_HardCode(dev);
1582 //============================================================================
1584 // Follow TID_AC_MAP of WMac.
1585 write_nic_word(dev, TID_AC_MAP, 0xfa50);
1587 // Interrupt Migration, Jong suggested we use set 0x0000 first, 2005.12.14, by rcnjko.
1588 write_nic_word(dev, IntMig, 0x0000);
1590 // Prevent TPC to cause CRC error. Added by Annie, 2006-06-10.
1591 PlatformIOWrite4Byte(dev, 0x1F0, 0x00000000);
1592 PlatformIOWrite4Byte(dev, 0x1F4, 0x00000000);
1593 PlatformIOWrite1Byte(dev, 0x1F8, 0x00);
1595 // Asked for by SD3 CM Lin, 2006.06.27, by rcnjko.
1596 //PlatformIOWrite4Byte(dev, RFTiming, 0x00004001);
1598 // power save parameter based on "87SE power save parameters 20071127.doc", as follow.
1600 //Enable DA10 TX power saving
1601 u1DA = read_nic_byte(dev, PHYPR);
1602 write_nic_byte(dev, PHYPR, (u1DA | BIT2) );
1605 write_nic_word(dev, 0x360, 0x1000);
1606 write_nic_word(dev, 0x362, 0x1000);
1609 write_nic_word(dev, 0x370, 0x0560);
1610 write_nic_word(dev, 0x372, 0x0560);
1611 write_nic_word(dev, 0x374, 0x0DA4);
1612 write_nic_word(dev, 0x376, 0x0DA4);
1613 write_nic_word(dev, 0x378, 0x0560);
1614 write_nic_word(dev, 0x37A, 0x0560);
1615 write_nic_word(dev, 0x37C, 0x00EC);
1616 // write_nic_word(dev, 0x37E, 0x00FE);//-edward
1617 write_nic_word(dev, 0x37E, 0x00EC);//+edward
1618 write_nic_byte(dev, 0x24E,0x01);
1627 GetSupportedWirelessMode8185(
1628 struct net_device *dev
1631 u8 btSupportedWirelessMode = 0;
1632 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1634 switch(priv->rf_chip)
1638 btSupportedWirelessMode = (WIRELESS_MODE_B | WIRELESS_MODE_G);
1641 btSupportedWirelessMode = WIRELESS_MODE_B;
1645 return btSupportedWirelessMode;
1649 ActUpdateChannelAccessSetting(
1650 struct net_device *dev,
1651 WIRELESS_MODE WirelessMode,
1652 PCHANNEL_ACCESS_SETTING ChnlAccessSetting
1655 struct r8180_priv *priv = ieee80211_priv(dev);
1656 struct ieee80211_device *ieee = priv->ieee80211;
1659 //PSTA_QOS pStaQos = Adapter->MgntInfo.pStaQos;
1660 u8 bFollowLegacySetting = 0;
1665 // TODO: We still don't know how to set up these registers, just follow WMAC to
1666 // verify 8185B FPAG.
1669 // Jong said CWmin/CWmax register are not functional in 8185B,
1670 // so we shall fill channel access realted register into AC parameter registers,
1673 ChnlAccessSetting->SIFS_Timer = 0x22; // Suggested by Jong, 2005.12.08.
1674 ChnlAccessSetting->DIFS_Timer = 0x1C; // 2006.06.02, by rcnjko.
1675 ChnlAccessSetting->SlotTimeTimer = 9; // 2006.06.02, by rcnjko.
1676 ChnlAccessSetting->EIFS_Timer = 0x5B; // Suggested by wcchu, it is the default value of EIFS register, 2005.12.08.
1677 ChnlAccessSetting->CWminIndex = 3; // 2006.06.02, by rcnjko.
1678 ChnlAccessSetting->CWmaxIndex = 7; // 2006.06.02, by rcnjko.
1680 write_nic_byte(dev, SIFS, ChnlAccessSetting->SIFS_Timer);
1681 //Adapter->HalFunc.SetHwRegHandler( Adapter, HW_VAR_SLOT_TIME, &ChnlAccessSetting->SlotTimeTimer ); // Rewrited from directly use PlatformEFIOWrite1Byte(), by Annie, 2006-03-29.
1682 write_nic_byte(dev, SLOT, ChnlAccessSetting->SlotTimeTimer); // Rewrited from directly use PlatformEFIOWrite1Byte(), by Annie, 2006-03-29.
1684 u1bAIFS = aSifsTime + (2 * ChnlAccessSetting->SlotTimeTimer );
1686 //write_nic_byte(dev, AC_VO_PARAM, u1bAIFS);
1687 //write_nic_byte(dev, AC_VI_PARAM, u1bAIFS);
1688 //write_nic_byte(dev, AC_BE_PARAM, u1bAIFS);
1689 //write_nic_byte(dev, AC_BK_PARAM, u1bAIFS);
1691 write_nic_byte(dev, EIFS, ChnlAccessSetting->EIFS_Timer);
1693 write_nic_byte(dev, AckTimeOutReg, 0x5B); // <RJ_EXPR_QOS> Suggested by wcchu, it is the default value of EIFS register, 2005.12.08.
1696 // <RJ_TODO_NOW_8185B> Update ECWmin/ECWmax, AIFS, TXOP Limit of each AC to the value defined by SPEC.
1697 if( pStaQos->CurrentQosMode > QOS_DISABLE )
1699 if(pStaQos->QBssWirelessMode == WirelessMode)
1701 // Follow AC Parameters of the QBSS.
1702 for(eACI = 0; eACI < AC_MAX; eACI++)
1704 Adapter->HalFunc.SetHwRegHandler(Adapter, HW_VAR_AC_PARAM, (pu1Byte)(&(pStaQos->WMMParamEle.AcParam[eACI])) );
1709 // Follow Default WMM AC Parameters.
1710 bFollowLegacySetting = 1;
1716 bFollowLegacySetting = 1;
1720 // this setting is copied from rtl8187B. xiong-2006-11-13
1721 if(bFollowLegacySetting)
1726 // Follow 802.11 seeting to AC parameter, all AC shall use the same parameter.
1727 // 2005.12.01, by rcnjko.
1729 AcParam.longData = 0;
1730 AcParam.f.AciAifsn.f.AIFSN = 2; // Follow 802.11 DIFS.
1731 AcParam.f.AciAifsn.f.ACM = 0;
1732 AcParam.f.Ecw.f.ECWmin = ChnlAccessSetting->CWminIndex; // Follow 802.11 CWmin.
1733 AcParam.f.Ecw.f.ECWmax = ChnlAccessSetting->CWmaxIndex; // Follow 802.11 CWmax.
1734 AcParam.f.TXOPLimit = 0;
1736 //lzm reserved 080826
1738 // For turbo mode setting. port from 87B by Isaiah 2008-08-01
1739 if( ieee->current_network.Turbo_Enable == 1 )
1740 AcParam.f.TXOPLimit = 0x01FF;
1741 // For 87SE with Intel 4965 Ad-Hoc mode have poor throughput (19MB)
1742 if (ieee->iw_mode == IW_MODE_ADHOC)
1743 AcParam.f.TXOPLimit = 0x0020;
1746 for(eACI = 0; eACI < AC_MAX; eACI++)
1748 AcParam.f.AciAifsn.f.ACI = (u8)eACI;
1750 PAC_PARAM pAcParam = (PAC_PARAM)(&AcParam);
1755 // Retrive paramters to udpate.
1756 eACI = pAcParam->f.AciAifsn.f.ACI;
1757 u1bAIFS = pAcParam->f.AciAifsn.f.AIFSN * ChnlAccessSetting->SlotTimeTimer + aSifsTime;
1758 u4bAcParam = ( (((u32)(pAcParam->f.TXOPLimit)) << AC_PARAM_TXOP_LIMIT_OFFSET) |
1759 (((u32)(pAcParam->f.Ecw.f.ECWmax)) << AC_PARAM_ECW_MAX_OFFSET) |
1760 (((u32)(pAcParam->f.Ecw.f.ECWmin)) << AC_PARAM_ECW_MIN_OFFSET) |
1761 (((u32)u1bAIFS) << AC_PARAM_AIFS_OFFSET));
1766 //write_nic_dword(dev, AC_BK_PARAM, u4bAcParam);
1770 //write_nic_dword(dev, AC_BE_PARAM, u4bAcParam);
1774 //write_nic_dword(dev, AC_VI_PARAM, u4bAcParam);
1778 //write_nic_dword(dev, AC_VO_PARAM, u4bAcParam);
1782 DMESGW( "SetHwReg8185(): invalid ACI: %d !\n", eACI);
1787 // If it is set, immediately set ACM control bit to downgrading AC for passing WMM testplan. Annie, 2005-12-13.
1788 //write_nic_byte(dev, ACM_CONTROL, pAcParam->f.AciAifsn);
1790 PACI_AIFSN pAciAifsn = (PACI_AIFSN)(&pAcParam->f.AciAifsn);
1791 AC_CODING eACI = pAciAifsn->f.ACI;
1794 //for 8187B AsynIORead issue
1796 u8 AcmCtrl = pHalData->AcmControl;
1800 if( pAciAifsn->f.ACM )
1805 AcmCtrl |= (BEQ_ACM_EN|BEQ_ACM_CTL|ACM_HW_EN); // or 0x21
1809 AcmCtrl |= (VIQ_ACM_EN|VIQ_ACM_CTL|ACM_HW_EN); // or 0x42
1813 AcmCtrl |= (VOQ_ACM_EN|VOQ_ACM_CTL|ACM_HW_EN); // or 0x84
1817 DMESGW("SetHwReg8185(): [HW_VAR_ACM_CTRL] ACM set failed: eACI is %d\n", eACI );
1826 AcmCtrl &= ( (~BEQ_ACM_EN) & (~BEQ_ACM_CTL) & (~ACM_HW_EN) ); // and 0xDE
1830 AcmCtrl &= ( (~VIQ_ACM_EN) & (~VIQ_ACM_CTL) & (~ACM_HW_EN) ); // and 0xBD
1834 AcmCtrl &= ( (~VOQ_ACM_EN) & (~VOQ_ACM_CTL) & (~ACM_HW_EN) ); // and 0x7B
1842 //printk(KERN_WARNING "SetHwReg8185(): [HW_VAR_ACM_CTRL] Write 0x%X\n", AcmCtrl);
1845 pHalData->AcmControl = AcmCtrl;
1847 //write_nic_byte(dev, ACM_CONTROL, AcmCtrl);
1848 write_nic_byte(dev, ACM_CONTROL, 0);
1858 ActSetWirelessMode8185(
1859 struct net_device *dev,
1863 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1864 struct ieee80211_device *ieee = priv->ieee80211;
1865 //PMGNT_INFO pMgntInfo = &(Adapter->MgntInfo);
1866 u8 btSupportedWirelessMode = GetSupportedWirelessMode8185(dev);
1868 if( (btWirelessMode & btSupportedWirelessMode) == 0 )
1869 { // Don't switch to unsupported wireless mode, 2006.02.15, by rcnjko.
1870 DMESGW("ActSetWirelessMode8185(): WirelessMode(%d) is not supported (%d)!\n",
1871 btWirelessMode, btSupportedWirelessMode);
1875 // 1. Assign wireless mode to swtich if necessary.
1876 if (btWirelessMode == WIRELESS_MODE_AUTO)
1878 if((btSupportedWirelessMode & WIRELESS_MODE_A))
1880 btWirelessMode = WIRELESS_MODE_A;
1882 else if((btSupportedWirelessMode & WIRELESS_MODE_G))
1884 btWirelessMode = WIRELESS_MODE_G;
1886 else if((btSupportedWirelessMode & WIRELESS_MODE_B))
1888 btWirelessMode = WIRELESS_MODE_B;
1892 DMESGW("ActSetWirelessMode8185(): No valid wireless mode supported, btSupportedWirelessMode(%x)!!!\n",
1893 btSupportedWirelessMode);
1894 btWirelessMode = WIRELESS_MODE_B;
1899 // 2. Swtich band: RF or BB specific actions,
1900 // for example, refresh tables in omc8255, or change initial gain if necessary.
1901 switch(priv->rf_chip)
1906 // Nothing to do for Zebra to switch band.
1907 // Update current wireless mode if we swtich to specified band successfully.
1908 ieee->mode = (WIRELESS_MODE)btWirelessMode;
1913 DMESGW("ActSetWirelessMode8185(): unsupported RF: 0x%X !!!\n", priv->rf_chip);
1917 // 3. Change related setting.
1918 if( ieee->mode == WIRELESS_MODE_A ){
1919 DMESG("WIRELESS_MODE_A\n");
1921 else if( ieee->mode == WIRELESS_MODE_B ){
1922 DMESG("WIRELESS_MODE_B\n");
1924 else if( ieee->mode == WIRELESS_MODE_G ){
1925 DMESG("WIRELESS_MODE_G\n");
1928 ActUpdateChannelAccessSetting( dev, ieee->mode, &priv->ChannelAccessSetting);
1931 void rtl8185b_irq_enable(struct net_device *dev)
1933 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1935 priv->irq_enabled = 1;
1936 write_nic_dword(dev, IMR, priv->IntrMask);
1938 //by amy for power save
1940 DrvIFIndicateDisassociation(
1941 struct net_device *dev,
1945 //printk("==> DrvIFIndicateDisassociation()\n");
1947 // nothing is needed after disassociation request.
1949 //printk("<== DrvIFIndicateDisassociation()\n");
1953 struct net_device *dev
1956 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1959 //printk("XXXXXXXXXX MgntDisconnect IBSS\n");
1961 DrvIFIndicateDisassociation(dev, unspec_reason);
1963 // PlatformZeroMemory( pMgntInfo->Bssid, 6 );
1964 for(i=0;i<6;i++) priv->ieee80211->current_network.bssid[i] = 0x55;
1966 priv->ieee80211->state = IEEE80211_NOLINK;
1970 // Vista add a Adhoc profile, HW radio off untill OID_DOT11_RESET_REQUEST
1971 // Driver would set MSR=NO_LINK, then HW Radio ON, MgntQueue Stuck.
1972 // Because Bcn DMA isn't complete, mgnt queue would stuck until Bcn packet send.
1974 // Disable Beacon Queue Own bit, suggested by jong
1975 // Adapter->HalFunc.SetTxDescOWNHandler(Adapter, BEACON_QUEUE, 0, 0);
1976 ieee80211_stop_send_beacons(priv->ieee80211);
1978 priv->ieee80211->link_change(dev);
1979 notify_wx_assoc_event(priv->ieee80211);
1981 // Stop SW Beacon.Use hw beacon so do not need to do so.by amy
1983 // MgntIndicateMediaStatus( Adapter, RT_MEDIA_DISCONNECT, GENERAL_INDICATE );
1987 MlmeDisassociateRequest(
1988 struct net_device *dev,
1993 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
1996 SendDisassociation(priv->ieee80211, asSta, asRsn );
1998 if( memcmp(priv->ieee80211->current_network.bssid, asSta, 6 ) == 0 ){
1999 //ShuChen TODO: change media status.
2000 //ShuChen TODO: What to do when disassociate.
2001 DrvIFIndicateDisassociation(dev, unspec_reason);
2004 // pMgntInfo->AsocTimestamp = 0;
2005 for(i=0;i<6;i++) priv->ieee80211->current_network.bssid[i] = 0x22;
2006 // pMgntInfo->mBrates.Length = 0;
2007 // Adapter->HalFunc.SetHwRegHandler( Adapter, HW_VAR_BASIC_RATE, (pu1Byte)(&pMgntInfo->mBrates) );
2009 ieee80211_disassociate(priv->ieee80211);
2018 struct net_device *dev,
2022 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2025 // Commented out by rcnjko, 2005.01.27:
2026 // I move SecClearAllKeys() to MgntActSet_802_11_DISASSOCIATE().
2028 // //2004/09/15, kcwu, the key should be cleared, or the new handshaking will not success
2029 // SecClearAllKeys(Adapter);
2031 // In WPA WPA2 need to Clear all key ... because new key will set after new handshaking.
2033 if( pMgntInfo->SecurityInfo.AuthMode > RT_802_11AuthModeAutoSwitch ||
2034 (pMgntInfo->bAPSuportCCKM && pMgntInfo->bCCX8021xenable) ) // In CCKM mode will Clear key
2036 SecClearAllKeys(Adapter);
2037 RT_TRACE(COMP_SEC, DBG_LOUD,("======>CCKM clear key..."))
2040 // 2004.10.11, by rcnjko.
2041 //MlmeDisassociateRequest( Adapter, pMgntInfo->Bssid, disas_lv_ss );
2042 MlmeDisassociateRequest( dev, priv->ieee80211->current_network.bssid, asRsn );
2044 priv->ieee80211->state = IEEE80211_NOLINK;
2045 // pMgntInfo->AsocTimestamp = 0;
2049 struct net_device *dev,
2053 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2055 // Schedule an workitem to wake up for ps mode, 070109, by rcnjko.
2058 if(pMgntInfo->mPss != eAwake)
2061 // Using AwkaeTimer to prevent mismatch ps state.
2062 // In the timer the state will be changed according to the RF is being awoke or not. By Bruce, 2007-10-31.
2064 // PlatformScheduleWorkItem( &(pMgntInfo->AwakeWorkItem) );
2065 PlatformSetTimer( Adapter, &(pMgntInfo->AwakeTimer), 0 );
2069 // Indication of disassociation event.
2070 //DrvIFIndicateDisassociation(Adapter, asRsn);
2071 if(IS_DOT11D_ENABLE(priv->ieee80211))
2072 Dot11d_Reset(priv->ieee80211);
2073 // In adhoc mode, update beacon frame.
2074 if( priv->ieee80211->state == IEEE80211_LINKED )
2076 if( priv->ieee80211->iw_mode == IW_MODE_ADHOC )
2078 // RT_TRACE(COMP_MLME, DBG_LOUD, ("MgntDisconnect() ===> MgntDisconnectIBSS\n"));
2079 //printk("MgntDisconnect() ===> MgntDisconnectIBSS\n");
2080 MgntDisconnectIBSS(dev);
2082 if( priv->ieee80211->iw_mode == IW_MODE_INFRA )
2084 // We clear key here instead of MgntDisconnectAP() because that
2085 // MgntActSet_802_11_DISASSOCIATE() is an interface called by OS,
2086 // e.g. OID_802_11_DISASSOCIATE in Windows while as MgntDisconnectAP() is
2087 // used to handle disassociation related things to AP, e.g. send Disassoc
2088 // frame to AP. 2005.01.27, by rcnjko.
2089 // SecClearAllKeys(Adapter);
2091 // RT_TRACE(COMP_MLME, DBG_LOUD, ("MgntDisconnect() ===> MgntDisconnectAP\n"));
2092 //printk("MgntDisconnect() ===> MgntDisconnectAP\n");
2093 MgntDisconnectAP(dev, asRsn);
2096 // Inidicate Disconnect, 2005.02.23, by rcnjko.
2097 // MgntIndicateMediaStatus( Adapter, RT_MEDIA_DISCONNECT, GENERAL_INDICATE);
2104 // Chang RF Power State.
2105 // Note that, only MgntActSet_RF_State() is allowed to set HW_VAR_RF_STATE.
2112 struct net_device *dev,
2113 RT_RF_POWER_STATE eRFPowerState
2116 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2117 bool bResult = false;
2119 // printk("---------> SetRFPowerState(): eRFPowerState(%d)\n", eRFPowerState);
2120 if(eRFPowerState == priv->eRFPowerState)
2122 // printk("<--------- SetRFPowerState(): discard the request for eRFPowerState(%d) is the same.\n", eRFPowerState);
2126 switch(priv->rf_chip)
2130 bResult = SetZebraRFPowerState8185(dev, eRFPowerState);
2134 printk("SetRFPowerState8185(): unknown RFChipID: 0x%X!!!\n", priv->rf_chip);
2137 // printk("<--------- SetRFPowerState(): bResult(%d)\n", bResult);
2142 HalEnableRx8185Dummy(
2143 struct net_device *dev
2148 HalDisableRx8185Dummy(
2149 struct net_device *dev
2155 MgntActSet_RF_State(
2156 struct net_device *dev,
2157 RT_RF_POWER_STATE StateToSet,
2161 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2162 bool bActionAllowed = false;
2163 bool bConnectBySSID = false;
2164 RT_RF_POWER_STATE rtState;
2165 u16 RFWaitCounter = 0;
2167 // printk("===>MgntActSet_RF_State(): StateToSet(%d), ChangeSource(0x%x)\n",StateToSet, ChangeSource);
2169 // Prevent the race condition of RF state change. By Bruce, 2007-11-28.
2170 // Only one thread can change the RF state at one time, and others should wait to be executed.
2175 // down(&priv->rf_state);
2176 spin_lock_irqsave(&priv->rf_ps_lock,flag);
2177 if(priv->RFChangeInProgress)
2179 // printk("====================>haha111111111\n");
2180 // up(&priv->rf_state);
2181 // RT_TRACE(COMP_RF, DBG_LOUD, ("MgntActSet_RF_State(): RF Change in progress! Wait to set..StateToSet(%d).\n", StateToSet));
2182 spin_unlock_irqrestore(&priv->rf_ps_lock,flag);
2183 // Set RF after the previous action is done.
2184 while(priv->RFChangeInProgress)
2187 // RT_TRACE(COMP_RF, DBG_LOUD, ("MgntActSet_RF_State(): Wait 1 ms (%d times)...\n", RFWaitCounter));
2188 udelay(1000); // 1 ms
2190 // Wait too long, return FALSE to avoid to be stuck here.
2191 if(RFWaitCounter > 1000) // 1sec
2193 // RT_ASSERT(FALSE, ("MgntActSet_RF_State(): Wait too logn to set RF\n"));
2194 printk("MgntActSet_RF_State(): Wait too long to set RF\n");
2195 // TODO: Reset RF state?
2202 // printk("========================>haha2\n");
2203 priv->RFChangeInProgress = true;
2204 // up(&priv->rf_state);
2205 spin_unlock_irqrestore(&priv->rf_ps_lock,flag);
2210 rtState = priv->eRFPowerState;
2217 // Turn On RF no matter the IPS setting because we need to update the RF state to Ndis under Vista, or
2218 // the Windows does not allow the driver to perform site survey any more. By Bruce, 2007-10-02.
2220 priv->RfOffReason &= (~ChangeSource);
2222 if(! priv->RfOffReason)
2224 priv->RfOffReason = 0;
2225 bActionAllowed = true;
2227 if(rtState == eRfOff && ChangeSource >=RF_CHANGE_BY_HW && !priv->bInHctTest)
2229 bConnectBySSID = true;
2233 // RT_TRACE(COMP_RF, DBG_LOUD, ("MgntActSet_RF_State - eRfon reject pMgntInfo->RfOffReason= 0x%x, ChangeSource=0x%X\n", pMgntInfo->RfOffReason, ChangeSource));
2238 // 070125, rcnjko: we always keep connected in AP mode.
2240 if (priv->RfOffReason > RF_CHANGE_BY_IPS)
2244 // Disconnect to current BSS when radio off. Asked by QuanTa.
2248 // Calling MgntDisconnect() instead of MgntActSet_802_11_DISASSOCIATE(),
2249 // because we do NOT need to set ssid to dummy ones.
2250 // Revised by Roger, 2007.12.04.
2252 MgntDisconnect( dev, disas_lv_ss );
2254 // Clear content of bssDesc[] and bssDesc4Query[] to avoid reporting old bss to UI.
2255 // 2007.05.28, by shien chang.
2256 // PlatformZeroMemory( pMgntInfo->bssDesc, sizeof(RT_WLAN_BSS)*MAX_BSS_DESC );
2257 // pMgntInfo->NumBssDesc = 0;
2258 // PlatformZeroMemory( pMgntInfo->bssDesc4Query, sizeof(RT_WLAN_BSS)*MAX_BSS_DESC );
2259 // pMgntInfo->NumBssDesc4Query = 0;
2264 priv->RfOffReason |= ChangeSource;
2265 bActionAllowed = true;
2269 priv->RfOffReason |= ChangeSource;
2270 bActionAllowed = true;
2279 // RT_TRACE(COMP_RF, DBG_LOUD, ("MgntActSet_RF_State(): Action is allowed.... StateToSet(%d), RfOffReason(%#X)\n", StateToSet, pMgntInfo->RfOffReason));
2280 // Config HW to the specified mode.
2281 // printk("MgntActSet_RF_State(): Action is allowed.... StateToSet(%d), RfOffReason(%#X)\n", StateToSet, priv->RfOffReason);
2282 SetRFPowerState(dev, StateToSet);
2285 if(StateToSet == eRfOn)
2287 HalEnableRx8185Dummy(dev);
2290 // by amy not supported
2291 // MgntActSet_802_11_SSID(Adapter, Adapter->MgntInfo.Ssid.Octet, Adapter->MgntInfo.Ssid.Length, TRUE );
2295 else if(StateToSet == eRfOff)
2297 HalDisableRx8185Dummy(dev);
2302 // printk("MgntActSet_RF_State(): Action is rejected.... StateToSet(%d), ChangeSource(%#X), RfOffReason(%#X)\n", StateToSet, ChangeSource, priv->RfOffReason);
2305 // Release RF spinlock
2306 // down(&priv->rf_state);
2307 spin_lock_irqsave(&priv->rf_ps_lock,flag);
2308 priv->RFChangeInProgress = false;
2309 // up(&priv->rf_state);
2310 spin_unlock_irqrestore(&priv->rf_ps_lock,flag);
2311 // printk("<===MgntActSet_RF_State()\n");
2312 return bActionAllowed;
2316 struct net_device *dev
2319 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2323 // This flag "bSwRfProcessing", indicates the status of IPS procedure, should be set if the IPS workitem
2324 // is really scheduled.
2325 // The old code, sets this flag before scheduling the IPS workitem and however, at the same time the
2326 // previous IPS workitem did not end yet, fails to schedule the current workitem. Thus, bSwRfProcessing
2327 // blocks the IPS procedure of switching RF.
2328 // By Bruce, 2007-12-25.
2330 priv->bSwRfProcessing = true;
2332 MgntActSet_RF_State(dev, priv->eInactivePowerState, RF_CHANGE_BY_IPS);
2335 // To solve CAM values miss in RF OFF, rewrite CAM values after RF ON. By Bruce, 2007-09-20.
2338 priv->bSwRfProcessing = false;
2343 // Enter the inactive power save mode. RF will be off
2344 // 2007.08.17, by shien chang.
2348 struct net_device *dev
2351 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2352 RT_RF_POWER_STATE rtState;
2353 //printk("==============================>enter IPS\n");
2354 if (priv->bInactivePs)
2356 rtState = priv->eRFPowerState;
2359 // Added by Bruce, 2007-12-25.
2360 // Do not enter IPS in the following conditions:
2361 // (1) RF is already OFF or Sleep
2362 // (2) bSwRfProcessing (indicates the IPS is still under going)
2363 // (3) Connectted (only disconnected can trigger IPS)
2364 // (4) IBSS (send Beacon)
2365 // (5) AP mode (send Beacon)
2367 if (rtState == eRfOn && !priv->bSwRfProcessing
2368 && (priv->ieee80211->state != IEEE80211_LINKED ))
2370 // printk("IPSEnter(): Turn off RF.\n");
2371 priv->eInactivePowerState = eRfOff;
2372 InactivePowerSave(dev);
2375 // printk("priv->eRFPowerState is %d\n",priv->eRFPowerState);
2379 struct net_device *dev
2382 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2383 RT_RF_POWER_STATE rtState;
2384 //printk("===================================>leave IPS\n");
2385 if (priv->bInactivePs)
2387 rtState = priv->eRFPowerState;
2388 if ((rtState == eRfOff || rtState == eRfSleep) && (!priv->bSwRfProcessing) && priv->RfOffReason <= RF_CHANGE_BY_IPS)
2390 // printk("IPSLeave(): Turn on RF.\n");
2391 priv->eInactivePowerState = eRfOn;
2392 InactivePowerSave(dev);
2395 // printk("priv->eRFPowerState is %d\n",priv->eRFPowerState);
2397 //by amy for power save
2398 void rtl8185b_adapter_start(struct net_device *dev)
2400 struct r8180_priv *priv = ieee80211_priv(dev);
2401 struct ieee80211_device *ieee = priv->ieee80211;
2403 u8 SupportedWirelessMode;
2404 u8 InitWirelessMode;
2405 u8 bInvalidWirelessMode = 0;
2413 //rtl8180_rtx_disable(dev);
2415 write_nic_byte(dev,0x24e, (BIT5|BIT6|BIT0));
2419 priv->dma_poll_mask = 0;
2420 priv->dma_poll_stop_mask = 0;
2422 //rtl8180_beacon_tx_disable(dev);
2424 HwConfigureRTL8185(dev);
2426 write_nic_dword(dev, MAC0, ((u32*)dev->dev_addr)[0]);
2427 write_nic_word(dev, MAC4, ((u32*)dev->dev_addr)[1] & 0xffff );
2429 write_nic_byte(dev, MSR, read_nic_byte(dev, MSR) & 0xf3); // default network type to 'No Link'
2431 //write_nic_byte(dev, BRSR, 0x0); // Set BRSR= 1M
2433 write_nic_word(dev, BcnItv, 100);
2434 write_nic_word(dev, AtimWnd, 2);
2436 //PlatformEFIOWrite2Byte(dev, FEMR, 0xFFFF);
2437 PlatformIOWrite2Byte(dev, FEMR, 0xFFFF);
2439 write_nic_byte(dev, WPA_CONFIG, 0);
2441 MacConfig_85BASIC(dev);
2443 // Override the RFSW_CTRL (MAC offset 0x272-0x273), 2006.06.07, by rcnjko.
2444 // BT_DEMO_BOARD type
2445 PlatformIOWrite2Byte(dev, RFSW_CTRL, 0x569a);
2447 //#ifdef CONFIG_RTL818X_S
2448 // for jong required
2449 // PlatformIOWrite2Byte(dev, RFSW_CTRL, 0x9a56);
2453 //PlatformIOWrite2Byte(dev, RFSW_CTRL, 0x9a56);
2455 //-----------------------------------------------------------------------------
2456 // Set up PHY related.
2457 //-----------------------------------------------------------------------------
2458 // Enable Config3.PARAM_En to revise AnaaParm.
2459 write_nic_byte(dev, CR9346, 0xc0); // enable config register write
2461 tmpu8 = read_nic_byte(dev, CONFIG3);
2462 write_nic_byte(dev, CONFIG3, (tmpu8 |CONFIG3_PARM_En) );
2464 // Turn on Analog power.
2465 // Asked for by William, otherwise, MAC 3-wire can't work, 2006.06.27, by rcnjko.
2466 write_nic_dword(dev, ANAPARAM2, ANAPARM2_ASIC_ON);
2467 write_nic_dword(dev, ANAPARAM, ANAPARM_ASIC_ON);
2469 write_nic_word(dev, ANAPARAM3, 0x0010);
2472 write_nic_byte(dev, CONFIG3, tmpu8);
2473 write_nic_byte(dev, CR9346, 0x00);
2474 //{by amy 080312 for led
2475 // enable EEM0 and EEM1 in 9346CR
2476 btCR9346 = read_nic_byte(dev, CR9346);
2477 write_nic_byte(dev, CR9346, (btCR9346|0xC0) );
2479 // B cut use LED1 to control HW RF on/off
2480 TmpU1b = read_nic_byte(dev, CONFIG5);
2481 TmpU1b = TmpU1b & ~BIT3;
2482 write_nic_byte(dev,CONFIG5, TmpU1b);
2484 // disable EEM0 and EEM1 in 9346CR
2485 btCR9346 &= ~(0xC0);
2486 write_nic_byte(dev, CR9346, btCR9346);
2488 //Enable Led (suggested by Jong)
2489 // B-cut RF Radio on/off 5e[3]=0
2490 btPSR = read_nic_byte(dev, PSR);
2491 write_nic_byte(dev, PSR, (btPSR | BIT3));
2492 //by amy 080312 for led}
2493 // setup initial timing for RFE.
2494 write_nic_word(dev, RFPinsOutput, 0x0480);
2495 SetOutputEnableOfRfPins(dev);
2496 write_nic_word(dev, RFPinsSelect, 0x2488);
2501 // We assume RegWirelessMode has already been initialized before,
2502 // however, we has to validate the wireless mode here and provide a reasonble
2503 // initialized value if necessary. 2005.01.13, by rcnjko.
2504 SupportedWirelessMode = GetSupportedWirelessMode8185(dev);
2505 if( (ieee->mode != WIRELESS_MODE_B) &&
2506 (ieee->mode != WIRELESS_MODE_G) &&
2507 (ieee->mode != WIRELESS_MODE_A) &&
2508 (ieee->mode != WIRELESS_MODE_AUTO))
2509 { // It should be one of B, G, A, or AUTO.
2510 bInvalidWirelessMode = 1;
2513 { // One of B, G, A, or AUTO.
2514 // Check if the wireless mode is supported by RF.
2515 if( (ieee->mode != WIRELESS_MODE_AUTO) &&
2516 (ieee->mode & SupportedWirelessMode) == 0 )
2518 bInvalidWirelessMode = 1;
2522 if(bInvalidWirelessMode || ieee->mode==WIRELESS_MODE_AUTO)
2523 { // Auto or other invalid value.
2524 // Assigne a wireless mode to initialize.
2525 if((SupportedWirelessMode & WIRELESS_MODE_A))
2527 InitWirelessMode = WIRELESS_MODE_A;
2529 else if((SupportedWirelessMode & WIRELESS_MODE_G))
2531 InitWirelessMode = WIRELESS_MODE_G;
2533 else if((SupportedWirelessMode & WIRELESS_MODE_B))
2535 InitWirelessMode = WIRELESS_MODE_B;
2539 DMESGW("InitializeAdapter8185(): No valid wireless mode supported, SupportedWirelessMode(%x)!!!\n",
2540 SupportedWirelessMode);
2541 InitWirelessMode = WIRELESS_MODE_B;
2544 // Initialize RegWirelessMode if it is not a valid one.
2545 if(bInvalidWirelessMode)
2547 ieee->mode = (WIRELESS_MODE)InitWirelessMode;
2551 { // One of B, G, A.
2552 InitWirelessMode = ieee->mode;
2554 //by amy for power save
2556 // printk("initialize ENABLE_IPS\n");
2557 priv->eRFPowerState = eRfOff;
2558 priv->RfOffReason = 0;
2561 // u32 tmp = jiffies;
2562 MgntActSet_RF_State(dev, eRfOn, 0);
2564 // printk("rf on cost jiffies:%lx\n", (tmp2-tmp)*1000/HZ);
2566 // DrvIFIndicateCurrentPhyStatus(priv);
2568 // If inactive power mode is enabled, disable rf while in disconnected state.
2569 // 2007.07.16, by shien chang.
2571 if (priv->bInactivePs)
2574 // u32 tmp = jiffies;
2575 MgntActSet_RF_State(dev,eRfOff, RF_CHANGE_BY_IPS);
2577 // printk("rf off cost jiffies:%lx\n", (tmp2-tmp)*1000/HZ);
2582 //by amy for power save
2584 // Turn off RF if necessary. 2005.08.23, by rcnjko.
2585 // We shall turn off RF after setting CMDR, otherwise,
2586 // RF will be turnned on after we enable MAC Tx/Rx.
2587 if(Adapter->MgntInfo.RegRfOff == TRUE)
2589 SetRFPowerState8185(Adapter, RF_OFF);
2593 SetRFPowerState8185(Adapter, RF_ON);
2597 /* //these is equal with above TODO.
2598 write_nic_byte(dev, CR9346, 0xc0); // enable config register write
2599 write_nic_byte(dev, CONFIG3, read_nic_byte(dev, CONFIG3) | CONFIG3_PARM_En);
2600 RF_WriteReg(dev, 0x4, 0x9FF);
2601 write_nic_dword(dev, ANAPARAM2, ANAPARM2_ASIC_ON);
2602 write_nic_dword(dev, ANAPARAM, ANAPARM_ASIC_ON);
2603 write_nic_byte(dev, CONFIG3, (read_nic_byte(dev, CONFIG3)&(~CONFIG3_PARM_En)));
2604 write_nic_byte(dev, CR9346, 0x00);
2607 ActSetWirelessMode8185(dev, (u8)(InitWirelessMode));
2609 //-----------------------------------------------------------------------------
2611 rtl8185b_irq_enable(dev);
2613 netif_start_queue(dev);
2618 void rtl8185b_rx_enable(struct net_device *dev)
2622 /* for now we accept data, management & ctl frame*/
2623 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2625 if (dev->flags & IFF_PROMISC) DMESG ("NIC in promisc mode");
2627 if(priv->ieee80211->iw_mode == IW_MODE_MONITOR || \
2628 dev->flags & IFF_PROMISC){
2629 priv->ReceiveConfig = priv->ReceiveConfig & (~RCR_APM);
2630 priv->ReceiveConfig = priv->ReceiveConfig | RCR_AAP;
2633 /*if(priv->ieee80211->iw_mode == IW_MODE_MASTER){
2634 rxconf = rxconf | (1<<ACCEPT_ALLMAC_FRAME_SHIFT);
2635 rxconf = rxconf | (1<<RX_CHECK_BSSID_SHIFT);
2638 if(priv->ieee80211->iw_mode == IW_MODE_MONITOR){
2639 priv->ReceiveConfig = priv->ReceiveConfig | RCR_ACF | RCR_APWRMGT | RCR_AICV;
2642 if( priv->crcmon == 1 && priv->ieee80211->iw_mode == IW_MODE_MONITOR)
2643 priv->ReceiveConfig = priv->ReceiveConfig | RCR_ACRC32;
2645 write_nic_dword(dev, RCR, priv->ReceiveConfig);
2650 DMESG("rxconf: %x %x",priv->ReceiveConfig ,read_nic_dword(dev,RCR));
2652 cmd=read_nic_byte(dev,CMD);
2653 write_nic_byte(dev,CMD,cmd | (1<<CMD_RX_ENABLE_SHIFT));
2657 void rtl8185b_tx_enable(struct net_device *dev)
2663 struct r8180_priv *priv = (struct r8180_priv *)ieee80211_priv(dev);
2665 write_nic_dword(dev, TCR, priv->TransmitConfig);
2666 byte = read_nic_byte(dev, MSR);
2667 byte |= MSR_LINK_ENEDCA;
2668 write_nic_byte(dev, MSR, byte);
2673 DMESG("txconf: %x %x",priv->TransmitConfig,read_nic_dword(dev,TCR));
2676 cmd=read_nic_byte(dev,CMD);
2677 write_nic_byte(dev,CMD,cmd | (1<<CMD_TX_ENABLE_SHIFT));
2679 //write_nic_dword(dev,TX_CONF,txconf);
2683 rtl8180_set_mode(dev,EPROM_CMD_CONFIG);
2684 write_nic_byte(dev, TX_DMA_POLLING, priv->dma_poll_mask);
2685 rtl8180_set_mode(dev,EPROM_CMD_NORMAL);