nsc-ircc.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  1. /*********************************************************************
  2. *
  3. * Filename: nsc-ircc.h
  4. * Version:
  5. * Description:
  6. * Status: Experimental.
  7. * Author: Dag Brattli <dagb@cs.uit.no>
  8. * Created at: Fri Nov 13 14:37:40 1998
  9. * Modified at: Sun Jan 23 17:47:00 2000
  10. * Modified by: Dag Brattli <dagb@cs.uit.no>
  11. *
  12. * Copyright (c) 1998-2000 Dag Brattli <dagb@cs.uit.no>
  13. * Copyright (c) 1998 Lichen Wang, <lwang@actisys.com>
  14. * Copyright (c) 1998 Actisys Corp., www.actisys.com
  15. * All Rights Reserved
  16. *
  17. * This program is free software; you can redistribute it and/or
  18. * modify it under the terms of the GNU General Public License as
  19. * published by the Free Software Foundation; either version 2 of
  20. * the License, or (at your option) any later version.
  21. *
  22. * Neither Dag Brattli nor University of Tromsø admit liability nor
  23. * provide warranty for any of this software. This material is
  24. * provided "AS-IS" and at no charge.
  25. *
  26. ********************************************************************/
  27. #ifndef NSC_IRCC_H
  28. #define NSC_IRCC_H
  29. #include <linux/ktime.h>
  30. #include <linux/spinlock.h>
  31. #include <linux/pm.h>
  32. #include <linux/types.h>
  33. #include <asm/io.h>
  34. /* Features for chips (set in driver_data) */
  35. #define NSC_FORCE_DONGLE_TYPE9 0x00000001
  36. /* DMA modes needed */
  37. #define DMA_TX_MODE 0x08 /* Mem to I/O, ++, demand. */
  38. #define DMA_RX_MODE 0x04 /* I/O to mem, ++, demand. */
  39. /* Config registers for the '108 */
  40. #define CFG_108_BAIC 0x00
  41. #define CFG_108_CSRT 0x01
  42. #define CFG_108_MCTL 0x02
  43. /* Config registers for the '338 */
  44. #define CFG_338_FER 0x00
  45. #define CFG_338_FAR 0x01
  46. #define CFG_338_PTR 0x02
  47. #define CFG_338_PNP0 0x1b
  48. #define CFG_338_PNP1 0x1c
  49. #define CFG_338_PNP3 0x4f
  50. /* Config registers for the '39x (in the logical device bank) */
  51. #define CFG_39X_LDN 0x07 /* Logical device number (Super I/O bank) */
  52. #define CFG_39X_SIOCF1 0x21 /* SuperI/O Config */
  53. #define CFG_39X_ACT 0x30 /* Device activation */
  54. #define CFG_39X_BASEH 0x60 /* Device base address (high bits) */
  55. #define CFG_39X_BASEL 0x61 /* Device base address (low bits) */
  56. #define CFG_39X_IRQNUM 0x70 /* Interrupt number & wake up enable */
  57. #define CFG_39X_IRQSEL 0x71 /* Interrupt select (edge/level + polarity) */
  58. #define CFG_39X_DMA0 0x74 /* DMA 0 configuration */
  59. #define CFG_39X_DMA1 0x75 /* DMA 1 configuration */
  60. #define CFG_39X_SPC 0xF0 /* Serial port configuration register */
  61. /* Flags for configuration register CRF0 */
  62. #define APEDCRC 0x02
  63. #define ENBNKSEL 0x01
  64. /* Set 0 */
  65. #define TXD 0x00 /* Transmit data port */
  66. #define RXD 0x00 /* Receive data port */
  67. /* Register 1 */
  68. #define IER 0x01 /* Interrupt Enable Register*/
  69. #define IER_RXHDL_IE 0x01 /* Receiver high data level interrupt */
  70. #define IER_TXLDL_IE 0x02 /* Transeiver low data level interrupt */
  71. #define IER_LS_IE 0x04//* Link Status Interrupt */
  72. #define IER_ETXURI 0x04 /* Tx underrun */
  73. #define IER_DMA_IE 0x10 /* DMA finished interrupt */
  74. #define IER_TXEMP_IE 0x20
  75. #define IER_SFIF_IE 0x40 /* Frame status FIFO intr */
  76. #define IER_TMR_IE 0x80 /* Timer event */
  77. #define FCR 0x02 /* (write only) */
  78. #define FCR_FIFO_EN 0x01 /* Enable FIFO's */
  79. #define FCR_RXSR 0x02 /* Rx FIFO soft reset */
  80. #define FCR_TXSR 0x04 /* Tx FIFO soft reset */
  81. #define FCR_RXTH 0x40 /* Rx FIFO threshold (set to 16) */
  82. #define FCR_TXTH 0x20 /* Tx FIFO threshold (set to 17) */
  83. #define EIR 0x02 /* (read only) */
  84. #define EIR_RXHDL_EV 0x01
  85. #define EIR_TXLDL_EV 0x02
  86. #define EIR_LS_EV 0x04
  87. #define EIR_DMA_EV 0x10
  88. #define EIR_TXEMP_EV 0x20
  89. #define EIR_SFIF_EV 0x40
  90. #define EIR_TMR_EV 0x80
  91. #define LCR 0x03 /* Link control register */
  92. #define LCR_WLS_8 0x03 /* 8 bits */
  93. #define BSR 0x03 /* Bank select register */
  94. #define BSR_BKSE 0x80
  95. #define BANK0 LCR_WLS_8 /* Must make sure that we set 8N1 */
  96. #define BANK1 0x80
  97. #define BANK2 0xe0
  98. #define BANK3 0xe4
  99. #define BANK4 0xe8
  100. #define BANK5 0xec
  101. #define BANK6 0xf0
  102. #define BANK7 0xf4
  103. #define MCR 0x04 /* Mode Control Register */
  104. #define MCR_MODE_MASK ~(0xd0)
  105. #define MCR_UART 0x00
  106. #define MCR_RESERVED 0x20
  107. #define MCR_SHARP_IR 0x40
  108. #define MCR_SIR 0x60
  109. #define MCR_MIR 0x80
  110. #define MCR_FIR 0xa0
  111. #define MCR_CEIR 0xb0
  112. #define MCR_IR_PLS 0x10
  113. #define MCR_DMA_EN 0x04
  114. #define MCR_EN_IRQ 0x08
  115. #define MCR_TX_DFR 0x08
  116. #define LSR 0x05 /* Link status register */
  117. #define LSR_RXDA 0x01 /* Receiver data available */
  118. #define LSR_TXRDY 0x20 /* Transmitter ready */
  119. #define LSR_TXEMP 0x40 /* Transmitter empty */
  120. #define ASCR 0x07 /* Auxiliary Status and Control Register */
  121. #define ASCR_RXF_TOUT 0x01 /* Rx FIFO timeout */
  122. #define ASCR_FEND_INF 0x02 /* Frame end bytes in rx FIFO */
  123. #define ASCR_S_EOT 0x04 /* Set end of transmission */
  124. #define ASCT_RXBSY 0x20 /* Rx busy */
  125. #define ASCR_TXUR 0x40 /* Transeiver underrun */
  126. #define ASCR_CTE 0x80 /* Clear timer event */
  127. /* Bank 2 */
  128. #define BGDL 0x00 /* Baud Generator Divisor Port (Low Byte) */
  129. #define BGDH 0x01 /* Baud Generator Divisor Port (High Byte) */
  130. #define ECR1 0x02 /* Extended Control Register 1 */
  131. #define ECR1_EXT_SL 0x01 /* Extended Mode Select */
  132. #define ECR1_DMANF 0x02 /* DMA Fairness */
  133. #define ECR1_DMATH 0x04 /* DMA Threshold */
  134. #define ECR1_DMASWP 0x08 /* DMA Swap */
  135. #define EXCR2 0x04
  136. #define EXCR2_TFSIZ 0x01 /* Rx FIFO size = 32 */
  137. #define EXCR2_RFSIZ 0x04 /* Tx FIFO size = 32 */
  138. #define TXFLV 0x06 /* Tx FIFO level */
  139. #define RXFLV 0x07 /* Rx FIFO level */
  140. /* Bank 3 */
  141. #define MID 0x00
  142. /* Bank 4 */
  143. #define TMRL 0x00 /* Timer low byte */
  144. #define TMRH 0x01 /* Timer high byte */
  145. #define IRCR1 0x02 /* Infrared control register 1 */
  146. #define IRCR1_TMR_EN 0x01 /* Timer enable */
  147. #define TFRLL 0x04
  148. #define TFRLH 0x05
  149. #define RFRLL 0x06
  150. #define RFRLH 0x07
  151. /* Bank 5 */
  152. #define IRCR2 0x04 /* Infrared control register 2 */
  153. #define IRCR2_MDRS 0x04 /* MIR data rate select */
  154. #define IRCR2_FEND_MD 0x20 /* */
  155. #define FRM_ST 0x05 /* Frame status FIFO */
  156. #define FRM_ST_VLD 0x80 /* Frame status FIFO data valid */
  157. #define FRM_ST_ERR_MSK 0x5f
  158. #define FRM_ST_LOST_FR 0x40 /* Frame lost */
  159. #define FRM_ST_MAX_LEN 0x10 /* Max frame len exceeded */
  160. #define FRM_ST_PHY_ERR 0x08 /* Physical layer error */
  161. #define FRM_ST_BAD_CRC 0x04
  162. #define FRM_ST_OVR1 0x02 /* Rx FIFO overrun */
  163. #define FRM_ST_OVR2 0x01 /* Frame status FIFO overrun */
  164. #define RFLFL 0x06
  165. #define RFLFH 0x07
  166. /* Bank 6 */
  167. #define IR_CFG2 0x00
  168. #define IR_CFG2_DIS_CRC 0x02
  169. /* Bank 7 */
  170. #define IRM_CR 0x07 /* Infrared module control register */
  171. #define IRM_CR_IRX_MSL 0x40
  172. #define IRM_CR_AF_MNT 0x80 /* Automatic format */
  173. /* NSC chip information */
  174. struct nsc_chip {
  175. char *name; /* Name of chipset */
  176. int cfg[3]; /* Config registers */
  177. u_int8_t cid_index; /* Chip identification index reg */
  178. u_int8_t cid_value; /* Chip identification expected value */
  179. u_int8_t cid_mask; /* Chip identification revision mask */
  180. /* Functions for probing and initializing the specific chip */
  181. int (*probe)(struct nsc_chip *chip, chipio_t *info);
  182. int (*init)(struct nsc_chip *chip, chipio_t *info);
  183. };
  184. typedef struct nsc_chip nsc_chip_t;
  185. /* For storing entries in the status FIFO */
  186. struct st_fifo_entry {
  187. int status;
  188. int len;
  189. };
  190. #define MAX_TX_WINDOW 7
  191. #define MAX_RX_WINDOW 7
  192. struct st_fifo {
  193. struct st_fifo_entry entries[MAX_RX_WINDOW];
  194. int pending_bytes;
  195. int head;
  196. int tail;
  197. int len;
  198. };
  199. struct frame_cb {
  200. void *start; /* Start of frame in DMA mem */
  201. int len; /* Length of frame in DMA mem */
  202. };
  203. struct tx_fifo {
  204. struct frame_cb queue[MAX_TX_WINDOW]; /* Info about frames in queue */
  205. int ptr; /* Currently being sent */
  206. int len; /* Length of queue */
  207. int free; /* Next free slot */
  208. void *tail; /* Next free start in DMA mem */
  209. };
  210. /* Private data for each instance */
  211. struct nsc_ircc_cb {
  212. struct st_fifo st_fifo; /* Info about received frames */
  213. struct tx_fifo tx_fifo; /* Info about frames to be transmitted */
  214. struct net_device *netdev; /* Yes! we are some kind of netdevice */
  215. struct irlap_cb *irlap; /* The link layer we are binded to */
  216. struct qos_info qos; /* QoS capabilities for this device */
  217. chipio_t io; /* IrDA controller information */
  218. iobuff_t tx_buff; /* Transmit buffer */
  219. iobuff_t rx_buff; /* Receive buffer */
  220. dma_addr_t tx_buff_dma;
  221. dma_addr_t rx_buff_dma;
  222. __u8 ier; /* Interrupt enable register */
  223. ktime_t stamp;
  224. spinlock_t lock; /* For serializing operations */
  225. __u32 new_speed;
  226. int index; /* Instance index */
  227. struct platform_device *pldev;
  228. };
  229. static inline void switch_bank(int iobase, int bank)
  230. {
  231. outb(bank, iobase+BSR);
  232. }
  233. #endif /* NSC_IRCC_H */