ucc_slow.h 8.7 KB

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