ucc_slow.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /*
  2. * Copyright (C) 2006 Freescale Semicondutor, 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 <asm/immap_qe.h>
  19. #include <asm/qe.h>
  20. #include "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. enum qe_clock rx_clock;
  137. enum qe_clock tx_clock;
  138. u32 regs;
  139. int irq;
  140. u16 uccm_mask;
  141. int data_mem_part;
  142. int init_tx;
  143. int init_rx;
  144. u32 tx_bd_ring_len;
  145. u32 rx_bd_ring_len;
  146. int rx_interrupts;
  147. int brkpt_support;
  148. int grant_support;
  149. int tsa;
  150. int cdp;
  151. int cds;
  152. int ctsp;
  153. int ctss;
  154. int rinv;
  155. int tinv;
  156. int rtsm;
  157. int rfw;
  158. int tci;
  159. int tend;
  160. int tfl;
  161. int txsy;
  162. u16 max_rx_buf_length;
  163. enum ucc_slow_transparent_tcrc tcrc;
  164. enum ucc_slow_channel_protocol_mode mode;
  165. enum ucc_slow_diag_mode diag;
  166. enum ucc_slow_tx_oversampling_rate tdcr;
  167. enum ucc_slow_rx_oversampling_rate rdcr;
  168. enum ucc_slow_tx_encoding_method tenc;
  169. enum ucc_slow_rx_decoding_method renc;
  170. };
  171. struct ucc_slow_private {
  172. struct ucc_slow_info *us_info;
  173. struct ucc_slow *us_regs; /* a pointer to memory map of UCC regs */
  174. struct ucc_slow_pram *us_pram; /* a pointer to the parameter RAM */
  175. u32 us_pram_offset;
  176. int enabled_tx; /* Whether channel is enabled for Tx (ENT) */
  177. int enabled_rx; /* Whether channel is enabled for Rx (ENR) */
  178. int stopped_tx; /* Whether channel has been stopped for Tx
  179. (STOP_TX, etc.) */
  180. int stopped_rx; /* Whether channel has been stopped for Rx */
  181. struct list_head confQ; /* frames passed to chip waiting for tx */
  182. u32 first_tx_bd_mask; /* mask is used in Tx routine to save status
  183. and length for first BD in a frame */
  184. u32 tx_base_offset; /* first BD in Tx BD table offset (In MURAM) */
  185. u32 rx_base_offset; /* first BD in Rx BD table offset (In MURAM) */
  186. struct qe_bd *confBd; /* next BD for confirm after Tx */
  187. struct qe_bd *tx_bd; /* next BD for new Tx request */
  188. struct qe_bd *rx_bd; /* next BD to collect after Rx */
  189. void *p_rx_frame; /* accumulating receive frame */
  190. u16 *p_ucce; /* a pointer to the event register in memory.
  191. */
  192. u16 *p_uccm; /* a pointer to the mask register in memory */
  193. u16 saved_uccm; /* a saved mask for the RX Interrupt bits */
  194. #ifdef STATISTICS
  195. u32 tx_frames; /* Transmitted frames counters */
  196. u32 rx_frames; /* Received frames counters (only frames
  197. passed to application) */
  198. u32 rx_discarded; /* Discarded frames counters (frames that
  199. were discarded by the driver due to
  200. errors) */
  201. #endif /* STATISTICS */
  202. };
  203. /* ucc_slow_init
  204. * Initializes Slow UCC according to provided parameters.
  205. *
  206. * us_info - (In) pointer to the slow UCC info structure.
  207. * uccs_ret - (Out) pointer to the slow UCC structure.
  208. */
  209. int ucc_slow_init(struct ucc_slow_info * us_info, struct ucc_slow_private ** uccs_ret);
  210. /* ucc_slow_free
  211. * Frees all resources for slow UCC.
  212. *
  213. * uccs - (In) pointer to the slow UCC structure.
  214. */
  215. void ucc_slow_free(struct ucc_slow_private * uccs);
  216. /* ucc_slow_enable
  217. * Enables a fast UCC port.
  218. * This routine enables Tx and/or Rx through the General UCC Mode Register.
  219. *
  220. * uccs - (In) pointer to the slow UCC structure.
  221. * mode - (In) TX, RX, or both.
  222. */
  223. void ucc_slow_enable(struct ucc_slow_private * uccs, enum comm_dir mode);
  224. /* ucc_slow_disable
  225. * Disables a fast UCC port.
  226. * This routine disables Tx and/or Rx through the General UCC Mode Register.
  227. *
  228. * uccs - (In) pointer to the slow UCC structure.
  229. * mode - (In) TX, RX, or both.
  230. */
  231. void ucc_slow_disable(struct ucc_slow_private * uccs, enum comm_dir mode);
  232. /* ucc_slow_poll_transmitter_now
  233. * Immediately forces a poll of the transmitter for data to be sent.
  234. * Typically, the hardware performs a periodic poll for data that the
  235. * transmit routine has set up to be transmitted. In cases where
  236. * this polling cycle is not soon enough, this optional routine can
  237. * be invoked to force a poll right away, instead. Proper use for
  238. * each transmission for which this functionality is desired is to
  239. * call the transmit routine and then this routine right after.
  240. *
  241. * uccs - (In) pointer to the slow UCC structure.
  242. */
  243. void ucc_slow_poll_transmitter_now(struct ucc_slow_private * uccs);
  244. /* ucc_slow_graceful_stop_tx
  245. * Smoothly stops transmission on a specified slow UCC.
  246. *
  247. * uccs - (In) pointer to the slow UCC structure.
  248. */
  249. void ucc_slow_graceful_stop_tx(struct ucc_slow_private * uccs);
  250. /* ucc_slow_stop_tx
  251. * Stops transmission on a specified slow UCC.
  252. *
  253. * uccs - (In) pointer to the slow UCC structure.
  254. */
  255. void ucc_slow_stop_tx(struct ucc_slow_private * uccs);
  256. /* ucc_slow_restart_x
  257. * Restarts transmitting on a specified slow UCC.
  258. *
  259. * uccs - (In) pointer to the slow UCC structure.
  260. */
  261. void ucc_slow_restart_x(struct ucc_slow_private * uccs);
  262. u32 ucc_slow_get_qe_cr_subblock(int uccs_num);
  263. #endif /* __UCC_SLOW_H__ */