via-ircc.h 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  1. /*********************************************************************
  2. *
  3. * Filename: via-ircc.h
  4. * Version: 1.0
  5. * Description: Driver for the VIA VT8231/VT8233 IrDA chipsets
  6. * Author: VIA Technologies, inc
  7. * Date : 08/06/2003
  8. Copyright (c) 1998-2003 VIA Technologies, Inc.
  9. This program is free software; you can redistribute it and/or modify it under
  10. the terms of the GNU General Public License as published by the Free Software
  11. Foundation; either version 2, or (at your option) any later version.
  12. This program is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTIES OR REPRESENTATIONS; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. See the GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License along with
  17. this program; if not, write to the Free Software Foundation, Inc.,
  18. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  19. * Comment:
  20. * jul/08/2002 : Rx buffer length should use Rx ring ptr.
  21. * Oct/28/2002 : Add SB id for 3147 and 3177.
  22. * jul/09/2002 : only implement two kind of dongle currently.
  23. * Oct/02/2002 : work on VT8231 and VT8233 .
  24. * Aug/06/2003 : change driver format to pci driver .
  25. ********************************************************************/
  26. #ifndef via_IRCC_H
  27. #define via_IRCC_H
  28. #include <linux/time.h>
  29. #include <linux/spinlock.h>
  30. #include <linux/pm.h>
  31. #include <linux/types.h>
  32. #include <asm/io.h>
  33. #define MAX_TX_WINDOW 7
  34. #define MAX_RX_WINDOW 7
  35. struct st_fifo_entry {
  36. int status;
  37. int len;
  38. };
  39. struct st_fifo {
  40. struct st_fifo_entry entries[MAX_RX_WINDOW + 2];
  41. int pending_bytes;
  42. int head;
  43. int tail;
  44. int len;
  45. };
  46. struct frame_cb {
  47. void *start; /* Start of frame in DMA mem */
  48. int len; /* Length of frame in DMA mem */
  49. };
  50. struct tx_fifo {
  51. struct frame_cb queue[MAX_TX_WINDOW + 2]; /* Info about frames in queue */
  52. int ptr; /* Currently being sent */
  53. int len; /* Length of queue */
  54. int free; /* Next free slot */
  55. void *tail; /* Next free start in DMA mem */
  56. };
  57. struct eventflag // for keeping track of Interrupt Events
  58. {
  59. //--------tx part
  60. unsigned char TxFIFOUnderRun;
  61. unsigned char EOMessage;
  62. unsigned char TxFIFOReady;
  63. unsigned char EarlyEOM;
  64. //--------rx part
  65. unsigned char PHYErr;
  66. unsigned char CRCErr;
  67. unsigned char RxFIFOOverRun;
  68. unsigned char EOPacket;
  69. unsigned char RxAvail;
  70. unsigned char TooLargePacket;
  71. unsigned char SIRBad;
  72. //--------unknown
  73. unsigned char Unknown;
  74. //----------
  75. unsigned char TimeOut;
  76. unsigned char RxDMATC;
  77. unsigned char TxDMATC;
  78. };
  79. /* Private data for each instance */
  80. struct via_ircc_cb {
  81. struct st_fifo st_fifo; /* Info about received frames */
  82. struct tx_fifo tx_fifo; /* Info about frames to be transmitted */
  83. struct net_device *netdev; /* Yes! we are some kind of netdevice */
  84. struct irlap_cb *irlap; /* The link layer we are binded to */
  85. struct qos_info qos; /* QoS capabilities for this device */
  86. chipio_t io; /* IrDA controller information */
  87. iobuff_t tx_buff; /* Transmit buffer */
  88. iobuff_t rx_buff; /* Receive buffer */
  89. dma_addr_t tx_buff_dma;
  90. dma_addr_t rx_buff_dma;
  91. __u8 ier; /* Interrupt enable register */
  92. struct timeval stamp;
  93. struct timeval now;
  94. spinlock_t lock; /* For serializing operations */
  95. __u32 flags; /* Interface flags */
  96. __u32 new_speed;
  97. int index; /* Instance index */
  98. struct eventflag EventFlag;
  99. unsigned int chip_id; /* to remember chip id */
  100. unsigned int RetryCount;
  101. unsigned int RxDataReady;
  102. unsigned int RxLastCount;
  103. };
  104. //---------I=Infrared, H=Host, M=Misc, T=Tx, R=Rx, ST=Status,
  105. // CF=Config, CT=Control, L=Low, H=High, C=Count
  106. #define I_CF_L_0 0x10
  107. #define I_CF_H_0 0x11
  108. #define I_SIR_BOF 0x12
  109. #define I_SIR_EOF 0x13
  110. #define I_ST_CT_0 0x15
  111. #define I_ST_L_1 0x16
  112. #define I_ST_H_1 0x17
  113. #define I_CF_L_1 0x18
  114. #define I_CF_H_1 0x19
  115. #define I_CF_L_2 0x1a
  116. #define I_CF_H_2 0x1b
  117. #define I_CF_3 0x1e
  118. #define H_CT 0x20
  119. #define H_ST 0x21
  120. #define M_CT 0x22
  121. #define TX_CT_1 0x23
  122. #define TX_CT_2 0x24
  123. #define TX_ST 0x25
  124. #define RX_CT 0x26
  125. #define RX_ST 0x27
  126. #define RESET 0x28
  127. #define P_ADDR 0x29
  128. #define RX_C_L 0x2a
  129. #define RX_C_H 0x2b
  130. #define RX_P_L 0x2c
  131. #define RX_P_H 0x2d
  132. #define TX_C_L 0x2e
  133. #define TX_C_H 0x2f
  134. #define TIMER 0x32
  135. #define I_CF_4 0x33
  136. #define I_T_C_L 0x34
  137. #define I_T_C_H 0x35
  138. #define VERSION 0x3f
  139. //-------------------------------
  140. #define StartAddr 0x10 // the first register address
  141. #define EndAddr 0x3f // the last register address
  142. #define GetBit(val,bit) val = (unsigned char) ((val>>bit) & 0x1)
  143. // Returns the bit
  144. #define SetBit(val,bit) val= (unsigned char ) (val | (0x1 << bit))
  145. // Sets bit to 1
  146. #define ResetBit(val,bit) val= (unsigned char ) (val & ~(0x1 << bit))
  147. // Sets bit to 0
  148. #define OFF 0
  149. #define ON 1
  150. #define DMA_TX_MODE 0x08
  151. #define DMA_RX_MODE 0x04
  152. #define DMA1 0
  153. #define DMA2 0xc0
  154. #define MASK1 DMA1+0x0a
  155. #define MASK2 DMA2+0x14
  156. #define Clk_bit 0x40
  157. #define Tx_bit 0x01
  158. #define Rd_Valid 0x08
  159. #define RxBit 0x08
  160. static void DisableDmaChannel(unsigned int channel)
  161. {
  162. switch (channel) { // 8 Bit DMA channels DMAC1
  163. case 0:
  164. outb(4, MASK1); //mask channel 0
  165. break;
  166. case 1:
  167. outb(5, MASK1); //Mask channel 1
  168. break;
  169. case 2:
  170. outb(6, MASK1); //Mask channel 2
  171. break;
  172. case 3:
  173. outb(7, MASK1); //Mask channel 3
  174. break;
  175. case 5:
  176. outb(5, MASK2); //Mask channel 5
  177. break;
  178. case 6:
  179. outb(6, MASK2); //Mask channel 6
  180. break;
  181. case 7:
  182. outb(7, MASK2); //Mask channel 7
  183. break;
  184. default:
  185. break;
  186. }
  187. }
  188. static unsigned char ReadLPCReg(int iRegNum)
  189. {
  190. unsigned char iVal;
  191. outb(0x87, 0x2e);
  192. outb(0x87, 0x2e);
  193. outb(iRegNum, 0x2e);
  194. iVal = inb(0x2f);
  195. outb(0xaa, 0x2e);
  196. return iVal;
  197. }
  198. static void WriteLPCReg(int iRegNum, unsigned char iVal)
  199. {
  200. outb(0x87, 0x2e);
  201. outb(0x87, 0x2e);
  202. outb(iRegNum, 0x2e);
  203. outb(iVal, 0x2f);
  204. outb(0xAA, 0x2e);
  205. }
  206. static __u8 ReadReg(unsigned int BaseAddr, int iRegNum)
  207. {
  208. return (__u8) inb(BaseAddr + iRegNum);
  209. }
  210. static void WriteReg(unsigned int BaseAddr, int iRegNum, unsigned char iVal)
  211. {
  212. outb(iVal, BaseAddr + iRegNum);
  213. }
  214. static int WriteRegBit(unsigned int BaseAddr, unsigned char RegNum,
  215. unsigned char BitPos, unsigned char value)
  216. {
  217. __u8 Rtemp, Wtemp;
  218. if (BitPos > 7) {
  219. return -1;
  220. }
  221. if ((RegNum < StartAddr) || (RegNum > EndAddr))
  222. return -1;
  223. Rtemp = ReadReg(BaseAddr, RegNum);
  224. if (value == 0)
  225. Wtemp = ResetBit(Rtemp, BitPos);
  226. else {
  227. if (value == 1)
  228. Wtemp = SetBit(Rtemp, BitPos);
  229. else
  230. return -1;
  231. }
  232. WriteReg(BaseAddr, RegNum, Wtemp);
  233. return 0;
  234. }
  235. static __u8 CheckRegBit(unsigned int BaseAddr, unsigned char RegNum,
  236. unsigned char BitPos)
  237. {
  238. __u8 temp;
  239. if (BitPos > 7)
  240. return 0xff;
  241. if ((RegNum < StartAddr) || (RegNum > EndAddr)) {
  242. // printf("what is the register %x!\n",RegNum);
  243. }
  244. temp = ReadReg(BaseAddr, RegNum);
  245. return GetBit(temp, BitPos);
  246. }
  247. static void SetMaxRxPacketSize(__u16 iobase, __u16 size)
  248. {
  249. __u16 low, high;
  250. if ((size & 0xe000) == 0) {
  251. low = size & 0x00ff;
  252. high = (size & 0x1f00) >> 8;
  253. WriteReg(iobase, I_CF_L_2, low);
  254. WriteReg(iobase, I_CF_H_2, high);
  255. }
  256. }
  257. //for both Rx and Tx
  258. static void SetFIFO(__u16 iobase, __u16 value)
  259. {
  260. switch (value) {
  261. case 128:
  262. WriteRegBit(iobase, 0x11, 0, 0);
  263. WriteRegBit(iobase, 0x11, 7, 1);
  264. break;
  265. case 64:
  266. WriteRegBit(iobase, 0x11, 0, 0);
  267. WriteRegBit(iobase, 0x11, 7, 0);
  268. break;
  269. case 32:
  270. WriteRegBit(iobase, 0x11, 0, 1);
  271. WriteRegBit(iobase, 0x11, 7, 0);
  272. break;
  273. default:
  274. WriteRegBit(iobase, 0x11, 0, 0);
  275. WriteRegBit(iobase, 0x11, 7, 0);
  276. }
  277. }
  278. #define CRC16(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_L_0,7,val) //0 for 32 CRC
  279. /*
  280. #define SetVFIR(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_H_0,5,val)
  281. #define SetFIR(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_L_0,6,val)
  282. #define SetMIR(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_L_0,5,val)
  283. #define SetSIR(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_L_0,4,val)
  284. */
  285. #define SIRFilter(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_L_0,3,val)
  286. #define Filter(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_L_0,2,val)
  287. #define InvertTX(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_L_0,1,val)
  288. #define InvertRX(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_L_0,0,val)
  289. //****************************I_CF_H_0
  290. #define EnableTX(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_H_0,4,val)
  291. #define EnableRX(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_H_0,3,val)
  292. #define EnableDMA(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_H_0,2,val)
  293. #define SIRRecvAny(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_H_0,1,val)
  294. #define DiableTrans(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_H_0,0,val)
  295. //***************************I_SIR_BOF,I_SIR_EOF
  296. #define SetSIRBOF(BaseAddr,val) WriteReg(BaseAddr,I_SIR_BOF,val)
  297. #define SetSIREOF(BaseAddr,val) WriteReg(BaseAddr,I_SIR_EOF,val)
  298. #define GetSIRBOF(BaseAddr) ReadReg(BaseAddr,I_SIR_BOF)
  299. #define GetSIREOF(BaseAddr) ReadReg(BaseAddr,I_SIR_EOF)
  300. //*******************I_ST_CT_0
  301. #define EnPhys(BaseAddr,val) WriteRegBit(BaseAddr,I_ST_CT_0,7,val)
  302. #define IsModeError(BaseAddr) CheckRegBit(BaseAddr,I_ST_CT_0,6) //RO
  303. #define IsVFIROn(BaseAddr) CheckRegBit(BaseAddr,0x14,0) //RO for VT1211 only
  304. #define IsFIROn(BaseAddr) CheckRegBit(BaseAddr,I_ST_CT_0,5) //RO
  305. #define IsMIROn(BaseAddr) CheckRegBit(BaseAddr,I_ST_CT_0,4) //RO
  306. #define IsSIROn(BaseAddr) CheckRegBit(BaseAddr,I_ST_CT_0,3) //RO
  307. #define IsEnableTX(BaseAddr) CheckRegBit(BaseAddr,I_ST_CT_0,2) //RO
  308. #define IsEnableRX(BaseAddr) CheckRegBit(BaseAddr,I_ST_CT_0,1) //RO
  309. #define Is16CRC(BaseAddr) CheckRegBit(BaseAddr,I_ST_CT_0,0) //RO
  310. //***************************I_CF_3
  311. #define DisableAdjacentPulseWidth(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_3,5,val) //1 disable
  312. #define DisablePulseWidthAdjust(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_3,4,val) //1 disable
  313. #define UseOneRX(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_3,1,val) //0 use two RX
  314. #define SlowIRRXLowActive(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_3,0,val) //0 show RX high=1 in SIR
  315. //***************************H_CT
  316. #define EnAllInt(BaseAddr,val) WriteRegBit(BaseAddr,H_CT,7,val)
  317. #define TXStart(BaseAddr,val) WriteRegBit(BaseAddr,H_CT,6,val)
  318. #define RXStart(BaseAddr,val) WriteRegBit(BaseAddr,H_CT,5,val)
  319. #define ClearRXInt(BaseAddr,val) WriteRegBit(BaseAddr,H_CT,4,val) // 1 clear
  320. //*****************H_ST
  321. #define IsRXInt(BaseAddr) CheckRegBit(BaseAddr,H_ST,4)
  322. #define GetIntIndentify(BaseAddr) ((ReadReg(BaseAddr,H_ST)&0xf1) >>1)
  323. #define IsHostBusy(BaseAddr) CheckRegBit(BaseAddr,H_ST,0)
  324. #define GetHostStatus(BaseAddr) ReadReg(BaseAddr,H_ST) //RO
  325. //**************************M_CT
  326. #define EnTXDMA(BaseAddr,val) WriteRegBit(BaseAddr,M_CT,7,val)
  327. #define EnRXDMA(BaseAddr,val) WriteRegBit(BaseAddr,M_CT,6,val)
  328. #define SwapDMA(BaseAddr,val) WriteRegBit(BaseAddr,M_CT,5,val)
  329. #define EnInternalLoop(BaseAddr,val) WriteRegBit(BaseAddr,M_CT,4,val)
  330. #define EnExternalLoop(BaseAddr,val) WriteRegBit(BaseAddr,M_CT,3,val)
  331. //**************************TX_CT_1
  332. #define EnTXFIFOHalfLevelInt(BaseAddr,val) WriteRegBit(BaseAddr,TX_CT_1,4,val) //half empty int (1 half)
  333. #define EnTXFIFOUnderrunEOMInt(BaseAddr,val) WriteRegBit(BaseAddr,TX_CT_1,5,val)
  334. #define EnTXFIFOReadyInt(BaseAddr,val) WriteRegBit(BaseAddr,TX_CT_1,6,val) //int when reach it threshold (setting by bit 4)
  335. //**************************TX_CT_2
  336. #define ForceUnderrun(BaseAddr,val) WriteRegBit(BaseAddr,TX_CT_2,7,val) // force an underrun int
  337. #define EnTXCRC(BaseAddr,val) WriteRegBit(BaseAddr,TX_CT_2,6,val) //1 for FIR,MIR...0 (not SIR)
  338. #define ForceBADCRC(BaseAddr,val) WriteRegBit(BaseAddr,TX_CT_2,5,val) //force an bad CRC
  339. #define SendSIP(BaseAddr,val) WriteRegBit(BaseAddr,TX_CT_2,4,val) //send indication pulse for prevent SIR disturb
  340. #define ClearEnTX(BaseAddr,val) WriteRegBit(BaseAddr,TX_CT_2,3,val) // opposite to EnTX
  341. //*****************TX_ST
  342. #define GetTXStatus(BaseAddr) ReadReg(BaseAddr,TX_ST) //RO
  343. //**************************RX_CT
  344. #define EnRXSpecInt(BaseAddr,val) WriteRegBit(BaseAddr,RX_CT,0,val)
  345. #define EnRXFIFOReadyInt(BaseAddr,val) WriteRegBit(BaseAddr,RX_CT,1,val) //enable int when reach it threshold (setting by bit 7)
  346. #define EnRXFIFOHalfLevelInt(BaseAddr,val) WriteRegBit(BaseAddr,RX_CT,7,val) //enable int when (1) half full...or (0) just not full
  347. //*****************RX_ST
  348. #define GetRXStatus(BaseAddr) ReadReg(BaseAddr,RX_ST) //RO
  349. //***********************P_ADDR
  350. #define SetPacketAddr(BaseAddr,addr) WriteReg(BaseAddr,P_ADDR,addr)
  351. //***********************I_CF_4
  352. #define EnGPIOtoRX2(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_4,7,val)
  353. #define EnTimerInt(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_4,1,val)
  354. #define ClearTimerInt(BaseAddr,val) WriteRegBit(BaseAddr,I_CF_4,0,val)
  355. //***********************I_T_C_L
  356. #define WriteGIO(BaseAddr,val) WriteRegBit(BaseAddr,I_T_C_L,7,val)
  357. #define ReadGIO(BaseAddr) CheckRegBit(BaseAddr,I_T_C_L,7)
  358. #define ReadRX(BaseAddr) CheckRegBit(BaseAddr,I_T_C_L,3) //RO
  359. #define WriteTX(BaseAddr,val) WriteRegBit(BaseAddr,I_T_C_L,0,val)
  360. //***********************I_T_C_H
  361. #define EnRX2(BaseAddr,val) WriteRegBit(BaseAddr,I_T_C_H,7,val)
  362. #define ReadRX2(BaseAddr) CheckRegBit(BaseAddr,I_T_C_H,7)
  363. //**********************Version
  364. #define GetFIRVersion(BaseAddr) ReadReg(BaseAddr,VERSION)
  365. static void SetTimer(__u16 iobase, __u8 count)
  366. {
  367. EnTimerInt(iobase, OFF);
  368. WriteReg(iobase, TIMER, count);
  369. EnTimerInt(iobase, ON);
  370. }
  371. static void SetSendByte(__u16 iobase, __u32 count)
  372. {
  373. __u32 low, high;
  374. if ((count & 0xf000) == 0) {
  375. low = count & 0x00ff;
  376. high = (count & 0x0f00) >> 8;
  377. WriteReg(iobase, TX_C_L, low);
  378. WriteReg(iobase, TX_C_H, high);
  379. }
  380. }
  381. static void ResetChip(__u16 iobase, __u8 type)
  382. {
  383. __u8 value;
  384. value = (type + 2) << 4;
  385. WriteReg(iobase, RESET, type);
  386. }
  387. static int CkRxRecv(__u16 iobase, struct via_ircc_cb *self)
  388. {
  389. __u8 low, high;
  390. __u16 wTmp = 0, wTmp1 = 0, wTmp_new = 0;
  391. low = ReadReg(iobase, RX_C_L);
  392. high = ReadReg(iobase, RX_C_H);
  393. wTmp1 = high;
  394. wTmp = (wTmp1 << 8) | low;
  395. udelay(10);
  396. low = ReadReg(iobase, RX_C_L);
  397. high = ReadReg(iobase, RX_C_H);
  398. wTmp1 = high;
  399. wTmp_new = (wTmp1 << 8) | low;
  400. if (wTmp_new != wTmp)
  401. return 1;
  402. else
  403. return 0;
  404. }
  405. static __u16 RxCurCount(__u16 iobase, struct via_ircc_cb * self)
  406. {
  407. __u8 low, high;
  408. __u16 wTmp = 0, wTmp1 = 0;
  409. low = ReadReg(iobase, RX_P_L);
  410. high = ReadReg(iobase, RX_P_H);
  411. wTmp1 = high;
  412. wTmp = (wTmp1 << 8) | low;
  413. return wTmp;
  414. }
  415. /* This Routine can only use in recevie_complete
  416. * for it will update last count.
  417. */
  418. static __u16 GetRecvByte(__u16 iobase, struct via_ircc_cb * self)
  419. {
  420. __u8 low, high;
  421. __u16 wTmp, wTmp1, ret;
  422. low = ReadReg(iobase, RX_P_L);
  423. high = ReadReg(iobase, RX_P_H);
  424. wTmp1 = high;
  425. wTmp = (wTmp1 << 8) | low;
  426. if (wTmp >= self->RxLastCount)
  427. ret = wTmp - self->RxLastCount;
  428. else
  429. ret = (0x8000 - self->RxLastCount) + wTmp;
  430. self->RxLastCount = wTmp;
  431. /* RX_P is more actually the RX_C
  432. low=ReadReg(iobase,RX_C_L);
  433. high=ReadReg(iobase,RX_C_H);
  434. if(!(high&0xe000)) {
  435. temp=(high<<8)+low;
  436. return temp;
  437. }
  438. else return 0;
  439. */
  440. return ret;
  441. }
  442. static void Sdelay(__u16 scale)
  443. {
  444. __u8 bTmp;
  445. int i, j;
  446. for (j = 0; j < scale; j++) {
  447. for (i = 0; i < 0x20; i++) {
  448. bTmp = inb(0xeb);
  449. outb(bTmp, 0xeb);
  450. }
  451. }
  452. }
  453. static void Tdelay(__u16 scale)
  454. {
  455. __u8 bTmp;
  456. int i, j;
  457. for (j = 0; j < scale; j++) {
  458. for (i = 0; i < 0x50; i++) {
  459. bTmp = inb(0xeb);
  460. outb(bTmp, 0xeb);
  461. }
  462. }
  463. }
  464. static void ActClk(__u16 iobase, __u8 value)
  465. {
  466. __u8 bTmp;
  467. bTmp = ReadReg(iobase, 0x34);
  468. if (value)
  469. WriteReg(iobase, 0x34, bTmp | Clk_bit);
  470. else
  471. WriteReg(iobase, 0x34, bTmp & ~Clk_bit);
  472. }
  473. static void ClkTx(__u16 iobase, __u8 Clk, __u8 Tx)
  474. {
  475. __u8 bTmp;
  476. bTmp = ReadReg(iobase, 0x34);
  477. if (Clk == 0)
  478. bTmp &= ~Clk_bit;
  479. else {
  480. if (Clk == 1)
  481. bTmp |= Clk_bit;
  482. }
  483. WriteReg(iobase, 0x34, bTmp);
  484. Sdelay(1);
  485. if (Tx == 0)
  486. bTmp &= ~Tx_bit;
  487. else {
  488. if (Tx == 1)
  489. bTmp |= Tx_bit;
  490. }
  491. WriteReg(iobase, 0x34, bTmp);
  492. }
  493. static void Wr_Byte(__u16 iobase, __u8 data)
  494. {
  495. __u8 bData = data;
  496. // __u8 btmp;
  497. int i;
  498. ClkTx(iobase, 0, 1);
  499. Tdelay(2);
  500. ActClk(iobase, 1);
  501. Tdelay(1);
  502. for (i = 0; i < 8; i++) { //LDN
  503. if ((bData >> i) & 0x01) {
  504. ClkTx(iobase, 0, 1); //bit data = 1;
  505. } else {
  506. ClkTx(iobase, 0, 0); //bit data = 1;
  507. }
  508. Tdelay(2);
  509. Sdelay(1);
  510. ActClk(iobase, 1); //clk hi
  511. Tdelay(1);
  512. }
  513. }
  514. static __u8 Rd_Indx(__u16 iobase, __u8 addr, __u8 index)
  515. {
  516. __u8 data = 0, bTmp, data_bit;
  517. int i;
  518. bTmp = addr | (index << 1) | 0;
  519. ClkTx(iobase, 0, 0);
  520. Tdelay(2);
  521. ActClk(iobase, 1);
  522. udelay(1);
  523. Wr_Byte(iobase, bTmp);
  524. Sdelay(1);
  525. ClkTx(iobase, 0, 0);
  526. Tdelay(2);
  527. for (i = 0; i < 10; i++) {
  528. ActClk(iobase, 1);
  529. Tdelay(1);
  530. ActClk(iobase, 0);
  531. Tdelay(1);
  532. ClkTx(iobase, 0, 1);
  533. Tdelay(1);
  534. bTmp = ReadReg(iobase, 0x34);
  535. if (!(bTmp & Rd_Valid))
  536. break;
  537. }
  538. if (!(bTmp & Rd_Valid)) {
  539. for (i = 0; i < 8; i++) {
  540. ActClk(iobase, 1);
  541. Tdelay(1);
  542. ActClk(iobase, 0);
  543. bTmp = ReadReg(iobase, 0x34);
  544. data_bit = 1 << i;
  545. if (bTmp & RxBit)
  546. data |= data_bit;
  547. else
  548. data &= ~data_bit;
  549. Tdelay(2);
  550. }
  551. } else {
  552. for (i = 0; i < 2; i++) {
  553. ActClk(iobase, 1);
  554. Tdelay(1);
  555. ActClk(iobase, 0);
  556. Tdelay(2);
  557. }
  558. bTmp = ReadReg(iobase, 0x34);
  559. }
  560. for (i = 0; i < 1; i++) {
  561. ActClk(iobase, 1);
  562. Tdelay(1);
  563. ActClk(iobase, 0);
  564. Tdelay(2);
  565. }
  566. ClkTx(iobase, 0, 0);
  567. Tdelay(1);
  568. for (i = 0; i < 3; i++) {
  569. ActClk(iobase, 1);
  570. Tdelay(1);
  571. ActClk(iobase, 0);
  572. Tdelay(2);
  573. }
  574. return data;
  575. }
  576. static void Wr_Indx(__u16 iobase, __u8 addr, __u8 index, __u8 data)
  577. {
  578. int i;
  579. __u8 bTmp;
  580. ClkTx(iobase, 0, 0);
  581. udelay(2);
  582. ActClk(iobase, 1);
  583. udelay(1);
  584. bTmp = addr | (index << 1) | 1;
  585. Wr_Byte(iobase, bTmp);
  586. Wr_Byte(iobase, data);
  587. for (i = 0; i < 2; i++) {
  588. ClkTx(iobase, 0, 0);
  589. Tdelay(2);
  590. ActClk(iobase, 1);
  591. Tdelay(1);
  592. }
  593. ActClk(iobase, 0);
  594. }
  595. static void ResetDongle(__u16 iobase)
  596. {
  597. int i;
  598. ClkTx(iobase, 0, 0);
  599. Tdelay(1);
  600. for (i = 0; i < 30; i++) {
  601. ActClk(iobase, 1);
  602. Tdelay(1);
  603. ActClk(iobase, 0);
  604. Tdelay(1);
  605. }
  606. ActClk(iobase, 0);
  607. }
  608. static void SetSITmode(__u16 iobase)
  609. {
  610. __u8 bTmp;
  611. bTmp = ReadLPCReg(0x28);
  612. WriteLPCReg(0x28, bTmp | 0x10); //select ITMOFF
  613. bTmp = ReadReg(iobase, 0x35);
  614. WriteReg(iobase, 0x35, bTmp | 0x40); // Driver ITMOFF
  615. WriteReg(iobase, 0x28, bTmp | 0x80); // enable All interrupt
  616. }
  617. static void SI_SetMode(__u16 iobase, int mode)
  618. {
  619. //__u32 dTmp;
  620. __u8 bTmp;
  621. WriteLPCReg(0x28, 0x70); // S/W Reset
  622. SetSITmode(iobase);
  623. ResetDongle(iobase);
  624. udelay(10);
  625. Wr_Indx(iobase, 0x40, 0x0, 0x17); //RX ,APEN enable,Normal power
  626. Wr_Indx(iobase, 0x40, 0x1, mode); //Set Mode
  627. Wr_Indx(iobase, 0x40, 0x2, 0xff); //Set power to FIR VFIR > 1m
  628. bTmp = Rd_Indx(iobase, 0x40, 1);
  629. }
  630. static void InitCard(__u16 iobase)
  631. {
  632. ResetChip(iobase, 5);
  633. WriteReg(iobase, I_ST_CT_0, 0x00); // open CHIP on
  634. SetSIRBOF(iobase, 0xc0); // hardware default value
  635. SetSIREOF(iobase, 0xc1);
  636. }
  637. static void CommonInit(__u16 iobase)
  638. {
  639. // EnTXCRC(iobase,0);
  640. SwapDMA(iobase, OFF);
  641. SetMaxRxPacketSize(iobase, 0x0fff); //set to max:4095
  642. EnRXFIFOReadyInt(iobase, OFF);
  643. EnRXFIFOHalfLevelInt(iobase, OFF);
  644. EnTXFIFOHalfLevelInt(iobase, OFF);
  645. EnTXFIFOUnderrunEOMInt(iobase, ON);
  646. // EnTXFIFOReadyInt(iobase,ON);
  647. InvertTX(iobase, OFF);
  648. InvertRX(iobase, OFF);
  649. // WriteLPCReg(0xF0,0); //(if VT1211 then do this)
  650. if (IsSIROn(iobase)) {
  651. SIRFilter(iobase, ON);
  652. SIRRecvAny(iobase, ON);
  653. } else {
  654. SIRFilter(iobase, OFF);
  655. SIRRecvAny(iobase, OFF);
  656. }
  657. EnRXSpecInt(iobase, ON);
  658. WriteReg(iobase, I_ST_CT_0, 0x80);
  659. EnableDMA(iobase, ON);
  660. }
  661. static void SetBaudRate(__u16 iobase, __u32 rate)
  662. {
  663. __u8 value = 11, temp;
  664. if (IsSIROn(iobase)) {
  665. switch (rate) {
  666. case (__u32) (2400L):
  667. value = 47;
  668. break;
  669. case (__u32) (9600L):
  670. value = 11;
  671. break;
  672. case (__u32) (19200L):
  673. value = 5;
  674. break;
  675. case (__u32) (38400L):
  676. value = 2;
  677. break;
  678. case (__u32) (57600L):
  679. value = 1;
  680. break;
  681. case (__u32) (115200L):
  682. value = 0;
  683. break;
  684. default:
  685. break;
  686. }
  687. } else if (IsMIROn(iobase)) {
  688. value = 0; // will automatically be fixed in 1.152M
  689. } else if (IsFIROn(iobase)) {
  690. value = 0; // will automatically be fixed in 4M
  691. }
  692. temp = (ReadReg(iobase, I_CF_H_1) & 0x03);
  693. temp |= value << 2;
  694. WriteReg(iobase, I_CF_H_1, temp);
  695. }
  696. static void SetPulseWidth(__u16 iobase, __u8 width)
  697. {
  698. __u8 temp, temp1, temp2;
  699. temp = (ReadReg(iobase, I_CF_L_1) & 0x1f);
  700. temp1 = (ReadReg(iobase, I_CF_H_1) & 0xfc);
  701. temp2 = (width & 0x07) << 5;
  702. temp |= temp2;
  703. temp2 = (width & 0x18) >> 3;
  704. temp1 |= temp2;
  705. WriteReg(iobase, I_CF_L_1, temp);
  706. WriteReg(iobase, I_CF_H_1, temp1);
  707. }
  708. static void SetSendPreambleCount(__u16 iobase, __u8 count)
  709. {
  710. __u8 temp;
  711. temp = ReadReg(iobase, I_CF_L_1) & 0xe0;
  712. temp |= count;
  713. WriteReg(iobase, I_CF_L_1, temp);
  714. }
  715. static void SetVFIR(__u16 BaseAddr, __u8 val)
  716. {
  717. __u8 tmp;
  718. tmp = ReadReg(BaseAddr, I_CF_L_0);
  719. WriteReg(BaseAddr, I_CF_L_0, tmp & 0x8f);
  720. WriteRegBit(BaseAddr, I_CF_H_0, 5, val);
  721. }
  722. static void SetFIR(__u16 BaseAddr, __u8 val)
  723. {
  724. __u8 tmp;
  725. WriteRegBit(BaseAddr, I_CF_H_0, 5, 0);
  726. tmp = ReadReg(BaseAddr, I_CF_L_0);
  727. WriteReg(BaseAddr, I_CF_L_0, tmp & 0x8f);
  728. WriteRegBit(BaseAddr, I_CF_L_0, 6, val);
  729. }
  730. static void SetMIR(__u16 BaseAddr, __u8 val)
  731. {
  732. __u8 tmp;
  733. WriteRegBit(BaseAddr, I_CF_H_0, 5, 0);
  734. tmp = ReadReg(BaseAddr, I_CF_L_0);
  735. WriteReg(BaseAddr, I_CF_L_0, tmp & 0x8f);
  736. WriteRegBit(BaseAddr, I_CF_L_0, 5, val);
  737. }
  738. static void SetSIR(__u16 BaseAddr, __u8 val)
  739. {
  740. __u8 tmp;
  741. WriteRegBit(BaseAddr, I_CF_H_0, 5, 0);
  742. tmp = ReadReg(BaseAddr, I_CF_L_0);
  743. WriteReg(BaseAddr, I_CF_L_0, tmp & 0x8f);
  744. WriteRegBit(BaseAddr, I_CF_L_0, 4, val);
  745. }
  746. #endif /* via_IRCC_H */