ali-ircc.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /*********************************************************************
  2. *
  3. * Filename: ali-ircc.h
  4. * Version: 0.5
  5. * Description: Driver for the ALI M1535D and M1543C FIR Controller
  6. * Status: Experimental.
  7. * Author: Benjamin Kong <benjamin_kong@ali.com.tw>
  8. * Created at: 2000/10/16 03:46PM
  9. * Modified at: 2001/1/3 02:56PM
  10. * Modified by: Benjamin Kong <benjamin_kong@ali.com.tw>
  11. *
  12. * Copyright (c) 2000 Benjamin Kong <benjamin_kong@ali.com.tw>
  13. * All Rights Reserved
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License as
  17. * published by the Free Software Foundation; either version 2 of
  18. * the License, or (at your option) any later version.
  19. *
  20. ********************************************************************/
  21. #ifndef ALI_IRCC_H
  22. #define ALI_IRCC_H
  23. #include <linux/ktime.h>
  24. #include <linux/spinlock.h>
  25. #include <linux/pm.h>
  26. #include <linux/types.h>
  27. #include <asm/io.h>
  28. /* SIR Register */
  29. /* Usr definition of linux/serial_reg.h */
  30. /* FIR Register */
  31. #define BANK0 0x20
  32. #define BANK1 0x21
  33. #define BANK2 0x22
  34. #define BANK3 0x23
  35. #define FIR_MCR 0x07 /* Master Control Register */
  36. /* Bank 0 */
  37. #define FIR_DR 0x00 /* Alias 0, FIR Data Register (R/W) */
  38. #define FIR_IER 0x01 /* Alias 1, FIR Interrupt Enable Register (R/W) */
  39. #define FIR_IIR 0x02 /* Alias 2, FIR Interrupt Identification Register (Read only) */
  40. #define FIR_LCR_A 0x03 /* Alias 3, FIR Line Control Register A (R/W) */
  41. #define FIR_LCR_B 0x04 /* Alias 4, FIR Line Control Register B (R/W) */
  42. #define FIR_LSR 0x05 /* Alias 5, FIR Line Status Register (R/W) */
  43. #define FIR_BSR 0x06 /* Alias 6, FIR Bus Status Register (Read only) */
  44. /* Alias 1 */
  45. #define IER_FIFO 0x10 /* FIR FIFO Interrupt Enable */
  46. #define IER_TIMER 0x20 /* Timer Interrupt Enable */
  47. #define IER_EOM 0x40 /* End of Message Interrupt Enable */
  48. #define IER_ACT 0x80 /* Active Frame Interrupt Enable */
  49. /* Alias 2 */
  50. #define IIR_FIFO 0x10 /* FIR FIFO Interrupt */
  51. #define IIR_TIMER 0x20 /* Timer Interrupt */
  52. #define IIR_EOM 0x40 /* End of Message Interrupt */
  53. #define IIR_ACT 0x80 /* Active Frame Interrupt */
  54. /* Alias 3 */
  55. #define LCR_A_FIFO_RESET 0x80 /* FIFO Reset */
  56. /* Alias 4 */
  57. #define LCR_B_BW 0x10 /* Brick Wall */
  58. #define LCR_B_SIP 0x20 /* SIP Enable */
  59. #define LCR_B_TX_MODE 0x40 /* Transmit Mode */
  60. #define LCR_B_RX_MODE 0x80 /* Receive Mode */
  61. /* Alias 5 */
  62. #define LSR_FIR_LSA 0x00 /* FIR Line Status Address */
  63. #define LSR_FRAME_ABORT 0x08 /* Frame Abort */
  64. #define LSR_CRC_ERROR 0x10 /* CRC Error */
  65. #define LSR_SIZE_ERROR 0x20 /* Size Error */
  66. #define LSR_FRAME_ERROR 0x40 /* Frame Error */
  67. #define LSR_FIFO_UR 0x80 /* FIFO Underrun */
  68. #define LSR_FIFO_OR 0x80 /* FIFO Overrun */
  69. /* Alias 6 */
  70. #define BSR_FIFO_NOT_EMPTY 0x80 /* FIFO Not Empty */
  71. /* Bank 1 */
  72. #define FIR_CR 0x00 /* Alias 0, FIR Configuration Register (R/W) */
  73. #define FIR_FIFO_TR 0x01 /* Alias 1, FIR FIFO Threshold Register (R/W) */
  74. #define FIR_DMA_TR 0x02 /* Alias 2, FIR DMA Threshold Register (R/W) */
  75. #define FIR_TIMER_IIR 0x03 /* Alias 3, FIR Timer interrupt interval register (W/O) */
  76. #define FIR_FIFO_FR 0x03 /* Alias 3, FIR FIFO Flag register (R/O) */
  77. #define FIR_FIFO_RAR 0x04 /* Alias 4, FIR FIFO Read Address register (R/O) */
  78. #define FIR_FIFO_WAR 0x05 /* Alias 5, FIR FIFO Write Address register (R/O) */
  79. #define FIR_TR 0x06 /* Alias 6, Test REgister (W/O) */
  80. /* Alias 0 */
  81. #define CR_DMA_EN 0x01 /* DMA Enable */
  82. #define CR_DMA_BURST 0x02 /* DMA Burst Mode */
  83. #define CR_TIMER_EN 0x08 /* Timer Enable */
  84. /* Alias 3 */
  85. #define TIMER_IIR_500 0x00 /* 500 us */
  86. #define TIMER_IIR_1ms 0x01 /* 1 ms */
  87. #define TIMER_IIR_2ms 0x02 /* 2 ms */
  88. #define TIMER_IIR_4ms 0x03 /* 4 ms */
  89. /* Bank 2 */
  90. #define FIR_IRDA_CR 0x00 /* Alias 0, IrDA Control Register (R/W) */
  91. #define FIR_BOF_CR 0x01 /* Alias 1, BOF Count Register (R/W) */
  92. #define FIR_BW_CR 0x02 /* Alias 2, Brick Wall Count Register (R/W) */
  93. #define FIR_TX_DSR_HI 0x03 /* Alias 3, TX Data Size Register (high) (R/W) */
  94. #define FIR_TX_DSR_LO 0x04 /* Alias 4, TX Data Size Register (low) (R/W) */
  95. #define FIR_RX_DSR_HI 0x05 /* Alias 5, RX Data Size Register (high) (R/W) */
  96. #define FIR_RX_DSR_LO 0x06 /* Alias 6, RX Data Size Register (low) (R/W) */
  97. /* Alias 0 */
  98. #define IRDA_CR_HDLC1152 0x80 /* 1.152Mbps HDLC Select */
  99. #define IRDA_CR_CRC 0X40 /* CRC Select. */
  100. #define IRDA_CR_HDLC 0x20 /* HDLC select. */
  101. #define IRDA_CR_HP_MODE 0x10 /* HP mode (read only) */
  102. #define IRDA_CR_SD_ST 0x08 /* SD/MODE State. */
  103. #define IRDA_CR_FIR_SIN 0x04 /* FIR SIN Select. */
  104. #define IRDA_CR_ITTX_0 0x02 /* SOUT State. IRTX force to 0 */
  105. #define IRDA_CR_ITTX_1 0x03 /* SOUT State. IRTX force to 1 */
  106. /* Bank 3 */
  107. #define FIR_ID_VR 0x00 /* Alias 0, FIR ID Version Register (R/O) */
  108. #define FIR_MODULE_CR 0x01 /* Alias 1, FIR Module Control Register (R/W) */
  109. #define FIR_IO_BASE_HI 0x02 /* Alias 2, FIR Higher I/O Base Address Register (R/O) */
  110. #define FIR_IO_BASE_LO 0x03 /* Alias 3, FIR Lower I/O Base Address Register (R/O) */
  111. #define FIR_IRQ_CR 0x04 /* Alias 4, FIR IRQ Channel Register (R/O) */
  112. #define FIR_DMA_CR 0x05 /* Alias 5, FIR DMA Channel Register (R/O) */
  113. struct ali_chip {
  114. char *name;
  115. int cfg[2];
  116. unsigned char entr1;
  117. unsigned char entr2;
  118. unsigned char cid_index;
  119. unsigned char cid_value;
  120. int (*probe)(struct ali_chip *chip, chipio_t *info);
  121. int (*init)(struct ali_chip *chip, chipio_t *info);
  122. };
  123. typedef struct ali_chip ali_chip_t;
  124. /* DMA modes needed */
  125. #define DMA_TX_MODE 0x08 /* Mem to I/O, ++, demand. */
  126. #define DMA_RX_MODE 0x04 /* I/O to mem, ++, demand. */
  127. #define MAX_TX_WINDOW 7
  128. #define MAX_RX_WINDOW 7
  129. #define TX_FIFO_Threshold 8
  130. #define RX_FIFO_Threshold 1
  131. #define TX_DMA_Threshold 1
  132. #define RX_DMA_Threshold 1
  133. /* For storing entries in the status FIFO */
  134. struct st_fifo_entry {
  135. int status;
  136. int len;
  137. };
  138. struct st_fifo {
  139. struct st_fifo_entry entries[MAX_RX_WINDOW];
  140. int pending_bytes;
  141. int head;
  142. int tail;
  143. int len;
  144. };
  145. struct frame_cb {
  146. void *start; /* Start of frame in DMA mem */
  147. int len; /* Length of frame in DMA mem */
  148. };
  149. struct tx_fifo {
  150. struct frame_cb queue[MAX_TX_WINDOW]; /* Info about frames in queue */
  151. int ptr; /* Currently being sent */
  152. int len; /* Length of queue */
  153. int free; /* Next free slot */
  154. void *tail; /* Next free start in DMA mem */
  155. };
  156. /* Private data for each instance */
  157. struct ali_ircc_cb {
  158. struct st_fifo st_fifo; /* Info about received frames */
  159. struct tx_fifo tx_fifo; /* Info about frames to be transmitted */
  160. struct net_device *netdev; /* Yes! we are some kind of netdevice */
  161. struct irlap_cb *irlap; /* The link layer we are binded to */
  162. struct qos_info qos; /* QoS capabilities for this device */
  163. chipio_t io; /* IrDA controller information */
  164. iobuff_t tx_buff; /* Transmit buffer */
  165. iobuff_t rx_buff; /* Receive buffer */
  166. dma_addr_t tx_buff_dma;
  167. dma_addr_t rx_buff_dma;
  168. __u8 ier; /* Interrupt enable register */
  169. __u8 InterruptID; /* Interrupt ID */
  170. __u8 BusStatus; /* Bus Status */
  171. __u8 LineStatus; /* Line Status */
  172. unsigned char rcvFramesOverflow;
  173. ktime_t stamp;
  174. spinlock_t lock; /* For serializing operations */
  175. __u32 new_speed;
  176. int index; /* Instance index */
  177. unsigned char fifo_opti_buf;
  178. };
  179. static inline void switch_bank(int iobase, int bank)
  180. {
  181. outb(bank, iobase+FIR_MCR);
  182. }
  183. #endif /* ALI_IRCC_H */