mpsc.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /*
  2. * drivers/serial/mpsc.h
  3. *
  4. * Author: Mark A. Greer <mgreer@mvista.com>
  5. *
  6. * 2004 (c) MontaVista, Software, Inc. This file is licensed under
  7. * the terms of the GNU General Public License version 2. This program
  8. * is licensed "as is" without any warranty of any kind, whether express
  9. * or implied.
  10. */
  11. #ifndef __MPSC_H__
  12. #define __MPSC_H__
  13. #include <linux/config.h>
  14. #include <linux/module.h>
  15. #include <linux/moduleparam.h>
  16. #include <linux/tty.h>
  17. #include <linux/tty_flip.h>
  18. #include <linux/ioport.h>
  19. #include <linux/init.h>
  20. #include <linux/console.h>
  21. #include <linux/sysrq.h>
  22. #include <linux/serial.h>
  23. #include <linux/serial_core.h>
  24. #include <linux/delay.h>
  25. #include <linux/device.h>
  26. #include <linux/dma-mapping.h>
  27. #include <linux/mv643xx.h>
  28. #include <asm/io.h>
  29. #include <asm/irq.h>
  30. #if defined(CONFIG_SERIAL_MPSC_CONSOLE) && defined(CONFIG_MAGIC_SYSRQ)
  31. #define SUPPORT_SYSRQ
  32. #endif
  33. #define MPSC_NUM_CTLRS 2
  34. /*
  35. * Descriptors and buffers must be cache line aligned.
  36. * Buffers lengths must be multiple of cache line size.
  37. * Number of Tx & Rx descriptors must be powers of 2.
  38. */
  39. #define MPSC_RXR_ENTRIES 32
  40. #define MPSC_RXRE_SIZE dma_get_cache_alignment()
  41. #define MPSC_RXR_SIZE (MPSC_RXR_ENTRIES * MPSC_RXRE_SIZE)
  42. #define MPSC_RXBE_SIZE dma_get_cache_alignment()
  43. #define MPSC_RXB_SIZE (MPSC_RXR_ENTRIES * MPSC_RXBE_SIZE)
  44. #define MPSC_TXR_ENTRIES 32
  45. #define MPSC_TXRE_SIZE dma_get_cache_alignment()
  46. #define MPSC_TXR_SIZE (MPSC_TXR_ENTRIES * MPSC_TXRE_SIZE)
  47. #define MPSC_TXBE_SIZE dma_get_cache_alignment()
  48. #define MPSC_TXB_SIZE (MPSC_TXR_ENTRIES * MPSC_TXBE_SIZE)
  49. #define MPSC_DMA_ALLOC_SIZE (MPSC_RXR_SIZE + MPSC_RXB_SIZE + \
  50. MPSC_TXR_SIZE + MPSC_TXB_SIZE + \
  51. dma_get_cache_alignment() /* for alignment */)
  52. /* Rx and Tx Ring entry descriptors -- assume entry size is <= cacheline size */
  53. struct mpsc_rx_desc {
  54. u16 bufsize;
  55. u16 bytecnt;
  56. u32 cmdstat;
  57. u32 link;
  58. u32 buf_ptr;
  59. } __attribute((packed));
  60. struct mpsc_tx_desc {
  61. u16 bytecnt;
  62. u16 shadow;
  63. u32 cmdstat;
  64. u32 link;
  65. u32 buf_ptr;
  66. } __attribute((packed));
  67. /*
  68. * Some regs that have the erratum that you can't read them are are shared
  69. * between the two MPSC controllers. This struct contains those shared regs.
  70. */
  71. struct mpsc_shared_regs {
  72. phys_addr_t mpsc_routing_base_p;
  73. phys_addr_t sdma_intr_base_p;
  74. void __iomem *mpsc_routing_base;
  75. void __iomem *sdma_intr_base;
  76. u32 MPSC_MRR_m;
  77. u32 MPSC_RCRR_m;
  78. u32 MPSC_TCRR_m;
  79. u32 SDMA_INTR_CAUSE_m;
  80. u32 SDMA_INTR_MASK_m;
  81. };
  82. /* The main driver data structure */
  83. struct mpsc_port_info {
  84. struct uart_port port; /* Overlay uart_port structure */
  85. /* Internal driver state for this ctlr */
  86. u8 ready;
  87. u8 rcv_data;
  88. tcflag_t c_iflag; /* save termios->c_iflag */
  89. tcflag_t c_cflag; /* save termios->c_cflag */
  90. /* Info passed in from platform */
  91. u8 mirror_regs; /* Need to mirror regs? */
  92. u8 cache_mgmt; /* Need manual cache mgmt? */
  93. u8 brg_can_tune; /* BRG has baud tuning? */
  94. u32 brg_clk_src;
  95. u16 mpsc_max_idle;
  96. int default_baud;
  97. int default_bits;
  98. int default_parity;
  99. int default_flow;
  100. /* Physical addresses of various blocks of registers (from platform) */
  101. phys_addr_t mpsc_base_p;
  102. phys_addr_t sdma_base_p;
  103. phys_addr_t brg_base_p;
  104. /* Virtual addresses of various blocks of registers (from platform) */
  105. void __iomem *mpsc_base;
  106. void __iomem *sdma_base;
  107. void __iomem *brg_base;
  108. /* Descriptor ring and buffer allocations */
  109. void *dma_region;
  110. dma_addr_t dma_region_p;
  111. dma_addr_t rxr; /* Rx descriptor ring */
  112. dma_addr_t rxr_p; /* Phys addr of rxr */
  113. u8 *rxb; /* Rx Ring I/O buf */
  114. u8 *rxb_p; /* Phys addr of rxb */
  115. u32 rxr_posn; /* First desc w/ Rx data */
  116. dma_addr_t txr; /* Tx descriptor ring */
  117. dma_addr_t txr_p; /* Phys addr of txr */
  118. u8 *txb; /* Tx Ring I/O buf */
  119. u8 *txb_p; /* Phys addr of txb */
  120. int txr_head; /* Where new data goes */
  121. int txr_tail; /* Where sent data comes off */
  122. /* Mirrored values of regs we can't read (if 'mirror_regs' set) */
  123. u32 MPSC_MPCR_m;
  124. u32 MPSC_CHR_1_m;
  125. u32 MPSC_CHR_2_m;
  126. u32 MPSC_CHR_10_m;
  127. u32 BRG_BCR_m;
  128. struct mpsc_shared_regs *shared_regs;
  129. };
  130. /* Hooks to platform-specific code */
  131. int mpsc_platform_register_driver(void);
  132. void mpsc_platform_unregister_driver(void);
  133. /* Hooks back in to mpsc common to be called by platform-specific code */
  134. struct mpsc_port_info *mpsc_device_probe(int index);
  135. struct mpsc_port_info *mpsc_device_remove(int index);
  136. /*
  137. *****************************************************************************
  138. *
  139. * Multi-Protocol Serial Controller Interface Registers
  140. *
  141. *****************************************************************************
  142. */
  143. /* Main Configuratino Register Offsets */
  144. #define MPSC_MMCRL 0x0000
  145. #define MPSC_MMCRH 0x0004
  146. #define MPSC_MPCR 0x0008
  147. #define MPSC_CHR_1 0x000c
  148. #define MPSC_CHR_2 0x0010
  149. #define MPSC_CHR_3 0x0014
  150. #define MPSC_CHR_4 0x0018
  151. #define MPSC_CHR_5 0x001c
  152. #define MPSC_CHR_6 0x0020
  153. #define MPSC_CHR_7 0x0024
  154. #define MPSC_CHR_8 0x0028
  155. #define MPSC_CHR_9 0x002c
  156. #define MPSC_CHR_10 0x0030
  157. #define MPSC_CHR_11 0x0034
  158. #define MPSC_MPCR_FRZ (1 << 9)
  159. #define MPSC_MPCR_CL_5 0
  160. #define MPSC_MPCR_CL_6 1
  161. #define MPSC_MPCR_CL_7 2
  162. #define MPSC_MPCR_CL_8 3
  163. #define MPSC_MPCR_SBL_1 0
  164. #define MPSC_MPCR_SBL_2 1
  165. #define MPSC_CHR_2_TEV (1<<1)
  166. #define MPSC_CHR_2_TA (1<<7)
  167. #define MPSC_CHR_2_TTCS (1<<9)
  168. #define MPSC_CHR_2_REV (1<<17)
  169. #define MPSC_CHR_2_RA (1<<23)
  170. #define MPSC_CHR_2_CRD (1<<25)
  171. #define MPSC_CHR_2_EH (1<<31)
  172. #define MPSC_CHR_2_PAR_ODD 0
  173. #define MPSC_CHR_2_PAR_SPACE 1
  174. #define MPSC_CHR_2_PAR_EVEN 2
  175. #define MPSC_CHR_2_PAR_MARK 3
  176. /* MPSC Signal Routing */
  177. #define MPSC_MRR 0x0000
  178. #define MPSC_RCRR 0x0004
  179. #define MPSC_TCRR 0x0008
  180. /*
  181. *****************************************************************************
  182. *
  183. * Serial DMA Controller Interface Registers
  184. *
  185. *****************************************************************************
  186. */
  187. #define SDMA_SDC 0x0000
  188. #define SDMA_SDCM 0x0008
  189. #define SDMA_RX_DESC 0x0800
  190. #define SDMA_RX_BUF_PTR 0x0808
  191. #define SDMA_SCRDP 0x0810
  192. #define SDMA_TX_DESC 0x0c00
  193. #define SDMA_SCTDP 0x0c10
  194. #define SDMA_SFTDP 0x0c14
  195. #define SDMA_DESC_CMDSTAT_PE (1<<0)
  196. #define SDMA_DESC_CMDSTAT_CDL (1<<1)
  197. #define SDMA_DESC_CMDSTAT_FR (1<<3)
  198. #define SDMA_DESC_CMDSTAT_OR (1<<6)
  199. #define SDMA_DESC_CMDSTAT_BR (1<<9)
  200. #define SDMA_DESC_CMDSTAT_MI (1<<10)
  201. #define SDMA_DESC_CMDSTAT_A (1<<11)
  202. #define SDMA_DESC_CMDSTAT_AM (1<<12)
  203. #define SDMA_DESC_CMDSTAT_CT (1<<13)
  204. #define SDMA_DESC_CMDSTAT_C (1<<14)
  205. #define SDMA_DESC_CMDSTAT_ES (1<<15)
  206. #define SDMA_DESC_CMDSTAT_L (1<<16)
  207. #define SDMA_DESC_CMDSTAT_F (1<<17)
  208. #define SDMA_DESC_CMDSTAT_P (1<<18)
  209. #define SDMA_DESC_CMDSTAT_EI (1<<23)
  210. #define SDMA_DESC_CMDSTAT_O (1<<31)
  211. #define SDMA_DESC_DFLT (SDMA_DESC_CMDSTAT_O | \
  212. SDMA_DESC_CMDSTAT_EI)
  213. #define SDMA_SDC_RFT (1<<0)
  214. #define SDMA_SDC_SFM (1<<1)
  215. #define SDMA_SDC_BLMR (1<<6)
  216. #define SDMA_SDC_BLMT (1<<7)
  217. #define SDMA_SDC_POVR (1<<8)
  218. #define SDMA_SDC_RIFB (1<<9)
  219. #define SDMA_SDCM_ERD (1<<7)
  220. #define SDMA_SDCM_AR (1<<15)
  221. #define SDMA_SDCM_STD (1<<16)
  222. #define SDMA_SDCM_TXD (1<<23)
  223. #define SDMA_SDCM_AT (1<<31)
  224. #define SDMA_0_CAUSE_RXBUF (1<<0)
  225. #define SDMA_0_CAUSE_RXERR (1<<1)
  226. #define SDMA_0_CAUSE_TXBUF (1<<2)
  227. #define SDMA_0_CAUSE_TXEND (1<<3)
  228. #define SDMA_1_CAUSE_RXBUF (1<<8)
  229. #define SDMA_1_CAUSE_RXERR (1<<9)
  230. #define SDMA_1_CAUSE_TXBUF (1<<10)
  231. #define SDMA_1_CAUSE_TXEND (1<<11)
  232. #define SDMA_CAUSE_RX_MASK (SDMA_0_CAUSE_RXBUF | SDMA_0_CAUSE_RXERR | \
  233. SDMA_1_CAUSE_RXBUF | SDMA_1_CAUSE_RXERR)
  234. #define SDMA_CAUSE_TX_MASK (SDMA_0_CAUSE_TXBUF | SDMA_0_CAUSE_TXEND | \
  235. SDMA_1_CAUSE_TXBUF | SDMA_1_CAUSE_TXEND)
  236. /* SDMA Interrupt registers */
  237. #define SDMA_INTR_CAUSE 0x0000
  238. #define SDMA_INTR_MASK 0x0080
  239. /*
  240. *****************************************************************************
  241. *
  242. * Baud Rate Generator Interface Registers
  243. *
  244. *****************************************************************************
  245. */
  246. #define BRG_BCR 0x0000
  247. #define BRG_BTR 0x0004
  248. #endif /* __MPSC_H__ */