via-ircc.h 21 KB

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