33 #include <linux/time.h>
36 #include <linux/types.h>
39 #define MAX_TX_WINDOW 7
40 #define MAX_RX_WINDOW 7
129 #define I_CF_L_0 0x10
130 #define I_CF_H_0 0x11
131 #define I_SIR_BOF 0x12
132 #define I_SIR_EOF 0x13
133 #define I_ST_CT_0 0x15
134 #define I_ST_L_1 0x16
135 #define I_ST_H_1 0x17
136 #define I_CF_L_1 0x18
137 #define I_CF_H_1 0x19
138 #define I_CF_L_2 0x1a
139 #define I_CF_H_2 0x1b
163 #define StartAddr 0x10 // the first register address
164 #define EndAddr 0x3f // the last register address
165 #define GetBit(val,bit) val = (unsigned char) ((val>>bit) & 0x1)
167 #define SetBit(val,bit) val= (unsigned char ) (val | (0x1 << bit))
169 #define ResetBit(val,bit) val= (unsigned char ) (val & ~(0x1 << bit))
174 #define DMA_TX_MODE 0x08
175 #define DMA_RX_MODE 0x04
179 #define MASK1 DMA1+0x0a
180 #define MASK2 DMA2+0x14
184 #define Rd_Valid 0x08
187 static void DisableDmaChannel(
unsigned int channel)
216 static unsigned char ReadLPCReg(
int iRegNum)
229 static void WriteLPCReg(
int iRegNum,
unsigned char iVal)
239 static __u8 ReadReg(
unsigned int BaseAddr,
int iRegNum)
241 return (
__u8)
inb(BaseAddr + iRegNum);
244 static void WriteReg(
unsigned int BaseAddr,
int iRegNum,
unsigned char iVal)
246 outb(iVal, BaseAddr + iRegNum);
249 static int WriteRegBit(
unsigned int BaseAddr,
unsigned char RegNum,
250 unsigned char BitPos,
unsigned char value)
259 Rtemp = ReadReg(BaseAddr, RegNum);
264 Wtemp =
SetBit(Rtemp, BitPos);
268 WriteReg(BaseAddr, RegNum, Wtemp);
272 static __u8 CheckRegBit(
unsigned int BaseAddr,
unsigned char RegNum,
273 unsigned char BitPos)
282 temp = ReadReg(BaseAddr, RegNum);
283 return GetBit(temp, BitPos);
289 if ((size & 0xe000) == 0) {
291 high = (size & 0x1f00) >> 8;
301 static void SetFIFO(
__u16 iobase,
__u16 value)
305 WriteRegBit(iobase, 0x11, 0, 0);
306 WriteRegBit(iobase, 0x11, 7, 1);
309 WriteRegBit(iobase, 0x11, 0, 0);
310 WriteRegBit(iobase, 0x11, 7, 0);
313 WriteRegBit(iobase, 0x11, 0, 1);
314 WriteRegBit(iobase, 0x11, 7, 0);
317 WriteRegBit(iobase, 0x11, 0, 0);
318 WriteRegBit(iobase, 0x11, 7, 0);
323 #define CRC16(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_L_0,7,val) //0 for 32 CRC
330 #define SIRFilter(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_L_0,3,val)
331 #define Filter(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_L_0,2,val)
332 #define InvertTX(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_L_0,1,val)
333 #define InvertRX(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_L_0,0,val)
335 #define EnableTX(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_H_0,4,val)
336 #define EnableRX(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_H_0,3,val)
337 #define EnableDMA(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_H_0,2,val)
338 #define SIRRecvAny(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_H_0,1,val)
339 #define DiableTrans(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_H_0,0,val)
341 #define SetSIRBOF(BaseAddr,val) WriteReg(BaseAddr,I_SIR_BOF,val)
342 #define SetSIREOF(BaseAddr,val) WriteReg(BaseAddr,I_SIR_EOF,val)
343 #define GetSIRBOF(BaseAddr) ReadReg(BaseAddr,I_SIR_BOF)
344 #define GetSIREOF(BaseAddr) ReadReg(BaseAddr,I_SIR_EOF)
346 #define EnPhys(BaseAddr,val) WriteRegBit(BaseAddr,I_ST_CT_0,7,val)
347 #define IsModeError(BaseAddr) CheckRegBit(BaseAddr,I_ST_CT_0,6) //RO
348 #define IsVFIROn(BaseAddr) CheckRegBit(BaseAddr,0x14,0) //RO for VT1211 only
349 #define IsFIROn(BaseAddr) CheckRegBit(BaseAddr,I_ST_CT_0,5) //RO
350 #define IsMIROn(BaseAddr) CheckRegBit(BaseAddr,I_ST_CT_0,4) //RO
351 #define IsSIROn(BaseAddr) CheckRegBit(BaseAddr,I_ST_CT_0,3) //RO
352 #define IsEnableTX(BaseAddr) CheckRegBit(BaseAddr,I_ST_CT_0,2) //RO
353 #define IsEnableRX(BaseAddr) CheckRegBit(BaseAddr,I_ST_CT_0,1) //RO
354 #define Is16CRC(BaseAddr) CheckRegBit(BaseAddr,I_ST_CT_0,0) //RO
356 #define DisableAdjacentPulseWidth(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_3,5,val) //1 disable
357 #define DisablePulseWidthAdjust(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_3,4,val) //1 disable
358 #define UseOneRX(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_3,1,val) //0 use two RX
359 #define SlowIRRXLowActive(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_3,0,val) //0 show RX high=1 in SIR
361 #define EnAllInt(BaseAddr,val) WriteRegBit(BaseAddr,H_CT,7,val)
362 #define TXStart(BaseAddr,val) WriteRegBit(BaseAddr,H_CT,6,val)
363 #define RXStart(BaseAddr,val) WriteRegBit(BaseAddr,H_CT,5,val)
364 #define ClearRXInt(BaseAddr,val) WriteRegBit(BaseAddr,H_CT,4,val) // 1 clear
366 #define IsRXInt(BaseAddr) CheckRegBit(BaseAddr,H_ST,4)
367 #define GetIntIndentify(BaseAddr) ((ReadReg(BaseAddr,H_ST)&0xf1) >>1)
368 #define IsHostBusy(BaseAddr) CheckRegBit(BaseAddr,H_ST,0)
369 #define GetHostStatus(BaseAddr) ReadReg(BaseAddr,H_ST) //RO
371 #define EnTXDMA(BaseAddr,val) WriteRegBit(BaseAddr,M_CT,7,val)
372 #define EnRXDMA(BaseAddr,val) WriteRegBit(BaseAddr,M_CT,6,val)
373 #define SwapDMA(BaseAddr,val) WriteRegBit(BaseAddr,M_CT,5,val)
374 #define EnInternalLoop(BaseAddr,val) WriteRegBit(BaseAddr,M_CT,4,val)
375 #define EnExternalLoop(BaseAddr,val) WriteRegBit(BaseAddr,M_CT,3,val)
377 #define EnTXFIFOHalfLevelInt(BaseAddr,val) WriteRegBit(BaseAddr,TX_CT_1,4,val) //half empty int (1 half)
378 #define EnTXFIFOUnderrunEOMInt(BaseAddr,val) WriteRegBit(BaseAddr,TX_CT_1,5,val)
379 #define EnTXFIFOReadyInt(BaseAddr,val) WriteRegBit(BaseAddr,TX_CT_1,6,val) //int when reach it threshold (setting by bit 4)
381 #define ForceUnderrun(BaseAddr,val) WriteRegBit(BaseAddr,TX_CT_2,7,val) // force an underrun int
382 #define EnTXCRC(BaseAddr,val) WriteRegBit(BaseAddr,TX_CT_2,6,val) //1 for FIR,MIR...0 (not SIR)
383 #define ForceBADCRC(BaseAddr,val) WriteRegBit(BaseAddr,TX_CT_2,5,val) //force an bad CRC
384 #define SendSIP(BaseAddr,val) WriteRegBit(BaseAddr,TX_CT_2,4,val) //send indication pulse for prevent SIR disturb
385 #define ClearEnTX(BaseAddr,val) WriteRegBit(BaseAddr,TX_CT_2,3,val) // opposite to EnTX
387 #define GetTXStatus(BaseAddr) ReadReg(BaseAddr,TX_ST) //RO
389 #define EnRXSpecInt(BaseAddr,val) WriteRegBit(BaseAddr,RX_CT,0,val)
390 #define EnRXFIFOReadyInt(BaseAddr,val) WriteRegBit(BaseAddr,RX_CT,1,val) //enable int when reach it threshold (setting by bit 7)
391 #define EnRXFIFOHalfLevelInt(BaseAddr,val) WriteRegBit(BaseAddr,RX_CT,7,val) //enable int when (1) half full...or (0) just not full
393 #define GetRXStatus(BaseAddr) ReadReg(BaseAddr,RX_ST) //RO
395 #define SetPacketAddr(BaseAddr,addr) WriteReg(BaseAddr,P_ADDR,addr)
397 #define EnGPIOtoRX2(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_4,7,val)
398 #define EnTimerInt(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_4,1,val)
399 #define ClearTimerInt(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_4,0,val)
401 #define WriteGIO(BaseAddr,val) WriteRegBit(BaseAddr,I_T_C_L,7,val)
402 #define ReadGIO(BaseAddr) CheckRegBit(BaseAddr,I_T_C_L,7)
403 #define ReadRX(BaseAddr) CheckRegBit(BaseAddr,I_T_C_L,3) //RO
404 #define WriteTX(BaseAddr,val) WriteRegBit(BaseAddr,I_T_C_L,0,val)
406 #define EnRX2(BaseAddr,val) WriteRegBit(BaseAddr,I_T_C_H,7,val)
407 #define ReadRX2(BaseAddr) CheckRegBit(BaseAddr,I_T_C_H,7)
409 #define GetFIRVersion(BaseAddr) ReadReg(BaseAddr,VERSION)
415 WriteReg(iobase,
TIMER, count);
424 if ((count & 0xf000) == 0) {
425 low = count & 0x00ff;
426 high = (count & 0x0f00) >> 8;
427 WriteReg(iobase,
TX_C_L, low);
428 WriteReg(iobase,
TX_C_H, high);
436 value = (type + 2) << 4;
437 WriteReg(iobase,
RESET, type);
443 __u16 wTmp = 0, wTmp1 = 0, wTmp_new = 0;
445 low = ReadReg(iobase,
RX_C_L);
446 high = ReadReg(iobase,
RX_C_H);
448 wTmp = (wTmp1 << 8) | low;
450 low = ReadReg(iobase,
RX_C_L);
451 high = ReadReg(iobase,
RX_C_H);
453 wTmp_new = (wTmp1 << 8) | low;
454 if (wTmp_new != wTmp)
464 __u16 wTmp = 0, wTmp1 = 0;
466 low = ReadReg(iobase,
RX_P_L);
467 high = ReadReg(iobase,
RX_P_H);
469 wTmp = (wTmp1 << 8) | low;
482 low = ReadReg(iobase,
RX_P_L);
483 high = ReadReg(iobase,
RX_P_H);
485 wTmp = (wTmp1 << 8) | low;
488 if (wTmp >= self->RxLastCount)
489 ret = wTmp -
self->RxLastCount;
491 ret = (0x8000 -
self->RxLastCount) + wTmp;
492 self->RxLastCount = wTmp;
507 static void Sdelay(
__u16 scale)
512 for (j = 0; j < scale; j++) {
513 for (i = 0; i < 0x20; i++) {
520 static void Tdelay(
__u16 scale)
525 for (j = 0; j < scale; j++) {
526 for (i = 0; i < 0x50; i++) {
534 static void ActClk(
__u16 iobase,
__u8 value)
537 bTmp = ReadReg(iobase, 0x34);
539 WriteReg(iobase, 0x34, bTmp |
Clk_bit);
541 WriteReg(iobase, 0x34, bTmp & ~
Clk_bit);
548 bTmp = ReadReg(iobase, 0x34);
555 WriteReg(iobase, 0x34, bTmp);
563 WriteReg(iobase, 0x34, bTmp);
578 for (i = 0; i < 8; i++) {
580 if ((bData >> i) & 0x01) {
594 __u8 data = 0, bTmp, data_bit;
597 bTmp = addr | (index << 1) | 0;
602 Wr_Byte(iobase, bTmp);
606 for (i = 0; i < 10; i++) {
613 bTmp = ReadReg(iobase, 0x34);
618 for (i = 0; i < 8; i++) {
622 bTmp = ReadReg(iobase, 0x34);
631 for (i = 0; i < 2; i++) {
637 bTmp = ReadReg(iobase, 0x34);
639 for (i = 0; i < 1; i++) {
647 for (i = 0; i < 3; i++) {
665 bTmp = addr | (index << 1) | 1;
666 Wr_Byte(iobase, bTmp);
667 Wr_Byte(iobase, data);
668 for (i = 0; i < 2; i++) {
677 static void ResetDongle(
__u16 iobase)
682 for (i = 0; i < 30; i++) {
691 static void SetSITmode(
__u16 iobase)
696 bTmp = ReadLPCReg(0x28);
697 WriteLPCReg(0x28, bTmp | 0x10);
698 bTmp = ReadReg(iobase, 0x35);
699 WriteReg(iobase, 0x35, bTmp | 0x40);
700 WriteReg(iobase, 0x28, bTmp | 0x80);
703 static void SI_SetMode(
__u16 iobase,
int mode)
708 WriteLPCReg(0x28, 0x70);
712 Wr_Indx(iobase, 0x40, 0x0, 0x17);
713 Wr_Indx(iobase, 0x40, 0x1, mode);
714 Wr_Indx(iobase, 0x40, 0x2, 0xff);
715 bTmp = Rd_Indx(iobase, 0x40, 1);
718 static void InitCard(
__u16 iobase)
720 ResetChip(iobase, 5);
726 static void CommonInit(
__u16 iobase)
730 SetMaxRxPacketSize(iobase, 0x0fff);
783 temp = (ReadReg(iobase,
I_CF_H_1) & 0x03);
792 temp = (ReadReg(iobase,
I_CF_L_1) & 0x1f);
793 temp1 = (ReadReg(iobase,
I_CF_H_1) & 0xfc);
794 temp2 = (width & 0x07) << 5;
796 temp2 = (width & 0x18) >> 3;
802 static void SetSendPreambleCount(
__u16 iobase,
__u8 count)
806 temp = ReadReg(iobase,
I_CF_L_1) & 0xe0;
817 WriteReg(BaseAddr,
I_CF_L_0, tmp & 0x8f);
818 WriteRegBit(BaseAddr,
I_CF_H_0, 5, val);
825 WriteRegBit(BaseAddr,
I_CF_H_0, 5, 0);
827 WriteReg(BaseAddr,
I_CF_L_0, tmp & 0x8f);
828 WriteRegBit(BaseAddr,
I_CF_L_0, 6, val);
835 WriteRegBit(BaseAddr,
I_CF_H_0, 5, 0);
837 WriteReg(BaseAddr,
I_CF_L_0, tmp & 0x8f);
838 WriteRegBit(BaseAddr,
I_CF_L_0, 5, val);
845 WriteRegBit(BaseAddr,
I_CF_H_0, 5, 0);
847 WriteReg(BaseAddr,
I_CF_L_0, tmp & 0x8f);
848 WriteRegBit(BaseAddr,
I_CF_L_0, 4, val);