ucc_slow.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /*
  2. * Copyright (C) 2006 Freescale Semiconductor, Inc. All rights reserved.
  3. *
  4. * Authors: Shlomi Gridish <gridish@freescale.com>
  5. * Li Yang <leoli@freescale.com>
  6. *
  7. * Description:
  8. * Internal header file for UCC SLOW unit routines.
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the
  12. * Free Software Foundation; either version 2 of the License, or (at your
  13. * option) any later version.
  14. */
  15. #ifndef __UCC_SLOW_H__
  16. #define __UCC_SLOW_H__
  17. #include <linux/kernel.h>
  18. #include <soc/fsl/qe/immap_qe.h>
  19. #include <soc/fsl/qe/qe.h>
  20. #include <soc/fsl/qe/ucc.h>
  21. /* transmit BD's status */
  22. #define T_R 0x80000000 /* ready bit */
  23. #define T_PAD 0x40000000 /* add pads to short frames */
  24. #define T_W 0x20000000 /* wrap bit */
  25. #define T_I 0x10000000 /* interrupt on completion */
  26. #define T_L 0x08000000 /* last */
  27. #define T_A 0x04000000 /* Address - the data transmitted as address
  28. chars */
  29. #define T_TC 0x04000000 /* transmit CRC */
  30. #define T_CM 0x02000000 /* continuous mode */
  31. #define T_DEF 0x02000000 /* collision on previous attempt to transmit */
  32. #define T_P 0x01000000 /* Preamble - send Preamble sequence before
  33. data */
  34. #define T_HB 0x01000000 /* heartbeat */
  35. #define T_NS 0x00800000 /* No Stop */
  36. #define T_LC 0x00800000 /* late collision */
  37. #define T_RL 0x00400000 /* retransmission limit */
  38. #define T_UN 0x00020000 /* underrun */
  39. #define T_CT 0x00010000 /* CTS lost */
  40. #define T_CSL 0x00010000 /* carrier sense lost */
  41. #define T_RC 0x003c0000 /* retry count */
  42. /* Receive BD's status */
  43. #define R_E 0x80000000 /* buffer empty */
  44. #define R_W 0x20000000 /* wrap bit */
  45. #define R_I 0x10000000 /* interrupt on reception */
  46. #define R_L 0x08000000 /* last */
  47. #define R_C 0x08000000 /* the last byte in this buffer is a cntl
  48. char */
  49. #define R_F 0x04000000 /* first */
  50. #define R_A 0x04000000 /* the first byte in this buffer is address
  51. byte */
  52. #define R_CM 0x02000000 /* continuous mode */
  53. #define R_ID 0x01000000 /* buffer close on reception of idles */
  54. #define R_M 0x01000000 /* Frame received because of promiscuous
  55. mode */
  56. #define R_AM 0x00800000 /* Address match */
  57. #define R_DE 0x00800000 /* Address match */
  58. #define R_LG 0x00200000 /* Break received */
  59. #define R_BR 0x00200000 /* Frame length violation */
  60. #define R_NO 0x00100000 /* Rx Non Octet Aligned Packet */
  61. #define R_FR 0x00100000 /* Framing Error (no stop bit) character
  62. received */
  63. #define R_PR 0x00080000 /* Parity Error character received */
  64. #define R_AB 0x00080000 /* Frame Aborted */
  65. #define R_SH 0x00080000 /* frame is too short */
  66. #define R_CR 0x00040000 /* CRC Error */
  67. #define R_OV 0x00020000 /* Overrun */
  68. #define R_CD 0x00010000 /* CD lost */
  69. #define R_CL 0x00010000 /* this frame is closed because of a
  70. collision */
  71. /* Rx Data buffer must be 4 bytes aligned in most cases.*/
  72. #define UCC_SLOW_RX_ALIGN 4
  73. #define UCC_SLOW_MRBLR_ALIGNMENT 4
  74. #define UCC_SLOW_PRAM_SIZE 0x100
  75. #define ALIGNMENT_OF_UCC_SLOW_PRAM 64
  76. /* UCC Slow Channel Protocol Mode */
  77. enum ucc_slow_channel_protocol_mode {
  78. UCC_SLOW_CHANNEL_PROTOCOL_MODE_QMC = 0x00000002,
  79. UCC_SLOW_CHANNEL_PROTOCOL_MODE_UART = 0x00000004,
  80. UCC_SLOW_CHANNEL_PROTOCOL_MODE_BISYNC = 0x00000008,
  81. };
  82. /* UCC Slow Transparent Transmit CRC (TCRC) */
  83. enum ucc_slow_transparent_tcrc {
  84. /* 16-bit CCITT CRC (HDLC). (X16 + X12 + X5 + 1) */
  85. UCC_SLOW_TRANSPARENT_TCRC_CCITT_CRC16 = 0x00000000,
  86. /* CRC16 (BISYNC). (X16 + X15 + X2 + 1) */
  87. UCC_SLOW_TRANSPARENT_TCRC_CRC16 = 0x00004000,
  88. /* 32-bit CCITT CRC (Ethernet and HDLC) */
  89. UCC_SLOW_TRANSPARENT_TCRC_CCITT_CRC32 = 0x00008000,
  90. };
  91. /* UCC Slow oversampling rate for transmitter (TDCR) */
  92. enum ucc_slow_tx_oversampling_rate {
  93. /* 1x clock mode */
  94. UCC_SLOW_OVERSAMPLING_RATE_TX_TDCR_1 = 0x00000000,
  95. /* 8x clock mode */
  96. UCC_SLOW_OVERSAMPLING_RATE_TX_TDCR_8 = 0x00010000,
  97. /* 16x clock mode */
  98. UCC_SLOW_OVERSAMPLING_RATE_TX_TDCR_16 = 0x00020000,
  99. /* 32x clock mode */
  100. UCC_SLOW_OVERSAMPLING_RATE_TX_TDCR_32 = 0x00030000,
  101. };
  102. /* UCC Slow Oversampling rate for receiver (RDCR)
  103. */
  104. enum ucc_slow_rx_oversampling_rate {
  105. /* 1x clock mode */
  106. UCC_SLOW_OVERSAMPLING_RATE_RX_RDCR_1 = 0x00000000,
  107. /* 8x clock mode */
  108. UCC_SLOW_OVERSAMPLING_RATE_RX_RDCR_8 = 0x00004000,
  109. /* 16x clock mode */
  110. UCC_SLOW_OVERSAMPLING_RATE_RX_RDCR_16 = 0x00008000,
  111. /* 32x clock mode */
  112. UCC_SLOW_OVERSAMPLING_RATE_RX_RDCR_32 = 0x0000c000,
  113. };
  114. /* UCC Slow Transmitter encoding method (TENC)
  115. */
  116. enum ucc_slow_tx_encoding_method {
  117. UCC_SLOW_TRANSMITTER_ENCODING_METHOD_TENC_NRZ = 0x00000000,
  118. UCC_SLOW_TRANSMITTER_ENCODING_METHOD_TENC_NRZI = 0x00000100
  119. };
  120. /* UCC Slow Receiver decoding method (RENC)
  121. */
  122. enum ucc_slow_rx_decoding_method {
  123. UCC_SLOW_RECEIVER_DECODING_METHOD_RENC_NRZ = 0x00000000,
  124. UCC_SLOW_RECEIVER_DECODING_METHOD_RENC_NRZI = 0x00000800
  125. };
  126. /* UCC Slow Diagnostic mode (DIAG)
  127. */
  128. enum ucc_slow_diag_mode {
  129. UCC_SLOW_DIAG_MODE_NORMAL = 0x00000000,
  130. UCC_SLOW_DIAG_MODE_LOOPBACK = 0x00000040,
  131. UCC_SLOW_DIAG_MODE_ECHO = 0x00000080,
  132. UCC_SLOW_DIAG_MODE_LOOPBACK_ECHO = 0x000000c0
  133. };
  134. struct ucc_slow_info {
  135. int ucc_num;
  136. int protocol; /* QE_CR_PROTOCOL_xxx */
  137. enum qe_clock rx_clock;
  138. enum qe_clock tx_clock;
  139. phys_addr_t regs;
  140. int irq;
  141. u16 uccm_mask;
  142. int data_mem_part;
  143. int init_tx;
  144. int init_rx;
  145. u32 tx_bd_ring_len;
  146. u32 rx_bd_ring_len;
  147. int rx_interrupts;
  148. int brkpt_support;
  149. int grant_support;
  150. int tsa;
  151. int cdp;
  152. int cds;
  153. int ctsp;
  154. int ctss;
  155. int rinv;
  156. int tinv;
  157. int rtsm;
  158. int rfw;
  159. int tci;
  160. int tend;
  161. int tfl;
  162. int txsy;
  163. u16 max_rx_buf_length;
  164. enum ucc_slow_transparent_tcrc tcrc;
  165. enum ucc_slow_channel_protocol_mode mode;
  166. enum ucc_slow_diag_mode diag;
  167. enum ucc_slow_tx_oversampling_rate tdcr;
  168. enum ucc_slow_rx_oversampling_rate rdcr;
  169. enum ucc_slow_tx_encoding_method tenc;
  170. enum ucc_slow_rx_decoding_method renc;
  171. };
  172. struct ucc_slow_private {
  173. struct ucc_slow_info *us_info;
  174. struct ucc_slow __iomem *us_regs; /* Ptr to memory map of UCC regs */
  175. struct ucc_slow_pram *us_pram; /* a pointer to the parameter RAM */
  176. u32 us_pram_offset;
  177. int enabled_tx; /* Whether channel is enabled for Tx (ENT) */
  178. int enabled_rx; /* Whether channel is enabled for Rx (ENR) */
  179. int stopped_tx; /* Whether channel has been stopped for Tx
  180. (STOP_TX, etc.) */
  181. int stopped_rx; /* Whether channel has been stopped for Rx */
  182. struct list_head confQ; /* frames passed to chip waiting for tx */
  183. u32 first_tx_bd_mask; /* mask is used in Tx routine to save status
  184. and length for first BD in a frame */
  185. u32 tx_base_offset; /* first BD in Tx BD table offset (In MURAM) */
  186. u32 rx_base_offset; /* first BD in Rx BD table offset (In MURAM) */
  187. struct qe_bd *confBd; /* next BD for confirm after Tx */
  188. struct qe_bd *tx_bd; /* next BD for new Tx request */
  189. struct qe_bd *rx_bd; /* next BD to collect after Rx */
  190. void *p_rx_frame; /* accumulating receive frame */
  191. u16 *p_ucce; /* a pointer to the event register in memory.
  192. */
  193. u16 *p_uccm; /* a pointer to the mask register in memory */
  194. u16 saved_uccm; /* a saved mask for the RX Interrupt bits */
  195. #ifdef STATISTICS
  196. u32 tx_frames; /* Transmitted frames counters */
  197. u32 rx_frames; /* Received frames counters (only frames
  198. passed to application) */
  199. u32 rx_discarded; /* Discarded frames counters (frames that
  200. were discarded by the driver due to
  201. errors) */
  202. #endif /* STATISTICS */
  203. };
  204. /* ucc_slow_init
  205. * Initializes Slow UCC according to provided parameters.
  206. *
  207. * us_info - (In) pointer to the slow UCC info structure.
  208. * uccs_ret - (Out) pointer to the slow UCC structure.
  209. */
  210. int ucc_slow_init(struct ucc_slow_info * us_info, struct ucc_slow_private ** uccs_ret);
  211. /* ucc_slow_free
  212. * Frees all resources for slow UCC.
  213. *
  214. * uccs - (In) pointer to the slow UCC structure.
  215. */
  216. void ucc_slow_free(struct ucc_slow_private * uccs);
  217. /* ucc_slow_enable
  218. * Enables a fast UCC port.
  219. * This routine enables Tx and/or Rx through the General UCC Mode Register.
  220. *
  221. * uccs - (In) pointer to the slow UCC structure.
  222. * mode - (In) TX, RX, or both.
  223. */
  224. void ucc_slow_enable(struct ucc_slow_private * uccs, enum comm_dir mode);
  225. /* ucc_slow_disable
  226. * Disables a fast UCC port.
  227. * This routine disables Tx and/or Rx through the General UCC Mode Register.
  228. *
  229. * uccs - (In) pointer to the slow UCC structure.
  230. * mode - (In) TX, RX, or both.
  231. */
  232. void ucc_slow_disable(struct ucc_slow_private * uccs, enum comm_dir mode);
  233. /* ucc_slow_graceful_stop_tx
  234. * Smoothly stops transmission on a specified slow UCC.
  235. *
  236. * uccs - (In) pointer to the slow UCC structure.
  237. */
  238. void ucc_slow_graceful_stop_tx(struct ucc_slow_private * uccs);
  239. /* ucc_slow_stop_tx
  240. * Stops transmission on a specified slow UCC.
  241. *
  242. * uccs - (In) pointer to the slow UCC structure.
  243. */
  244. void ucc_slow_stop_tx(struct ucc_slow_private * uccs);
  245. /* ucc_slow_restart_tx
  246. * Restarts transmitting on a specified slow UCC.
  247. *
  248. * uccs - (In) pointer to the slow UCC structure.
  249. */
  250. void ucc_slow_restart_tx(struct ucc_slow_private *uccs);
  251. u32 ucc_slow_get_qe_cr_subblock(int uccs_num);
  252. #endif /* __UCC_SLOW_H__ */