bfin_serial.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /*
  2. * bfin_serial.h - Blackfin UART/Serial definitions
  3. *
  4. * Copyright 2006-2010 Analog Devices Inc.
  5. *
  6. * Licensed under the GPL-2 or later.
  7. */
  8. #ifndef __BFIN_ASM_SERIAL_H__
  9. #define __BFIN_ASM_SERIAL_H__
  10. #include <linux/serial_core.h>
  11. #include <mach/anomaly.h>
  12. #include <mach/bfin_serial.h>
  13. #if defined(CONFIG_BFIN_UART0_CTSRTS) || \
  14. defined(CONFIG_BFIN_UART1_CTSRTS) || \
  15. defined(CONFIG_BFIN_UART2_CTSRTS) || \
  16. defined(CONFIG_BFIN_UART3_CTSRTS)
  17. # ifdef BFIN_UART_BF54X_STYLE
  18. # define CONFIG_SERIAL_BFIN_HARD_CTSRTS
  19. # else
  20. # define CONFIG_SERIAL_BFIN_CTSRTS
  21. # endif
  22. #endif
  23. struct circ_buf;
  24. struct timer_list;
  25. struct work_struct;
  26. struct bfin_serial_port {
  27. struct uart_port port;
  28. unsigned int old_status;
  29. int status_irq;
  30. #ifndef BFIN_UART_BF54X_STYLE
  31. unsigned int lsr;
  32. #endif
  33. #ifdef CONFIG_SERIAL_BFIN_DMA
  34. int tx_done;
  35. int tx_count;
  36. struct circ_buf rx_dma_buf;
  37. struct timer_list rx_dma_timer;
  38. int rx_dma_nrows;
  39. unsigned int tx_dma_channel;
  40. unsigned int rx_dma_channel;
  41. struct work_struct tx_dma_workqueue;
  42. #elif ANOMALY_05000363
  43. unsigned int anomaly_threshold;
  44. #endif
  45. #ifdef CONFIG_SERIAL_BFIN_HARD_CTSRTS
  46. int scts;
  47. #endif
  48. #if defined(CONFIG_SERIAL_BFIN_CTSRTS) || \
  49. defined(CONFIG_SERIAL_BFIN_HARD_CTSRTS)
  50. int cts_pin;
  51. int rts_pin;
  52. #endif
  53. };
  54. /* UART_LCR Masks */
  55. #define WLS(x) (((x)-5) & 0x03) /* Word Length Select */
  56. #define STB 0x04 /* Stop Bits */
  57. #define PEN 0x08 /* Parity Enable */
  58. #define EPS 0x10 /* Even Parity Select */
  59. #define STP 0x20 /* Stick Parity */
  60. #define SB 0x40 /* Set Break */
  61. #define DLAB 0x80 /* Divisor Latch Access */
  62. /* UART_LSR Masks */
  63. #define DR 0x01 /* Data Ready */
  64. #define OE 0x02 /* Overrun Error */
  65. #define PE 0x04 /* Parity Error */
  66. #define FE 0x08 /* Framing Error */
  67. #define BI 0x10 /* Break Interrupt */
  68. #define THRE 0x20 /* THR Empty */
  69. #define TEMT 0x40 /* TSR and UART_THR Empty */
  70. #define TFI 0x80 /* Transmission Finished Indicator */
  71. /* UART_IER Masks */
  72. #define ERBFI 0x01 /* Enable Receive Buffer Full Interrupt */
  73. #define ETBEI 0x02 /* Enable Transmit Buffer Empty Interrupt */
  74. #define ELSI 0x04 /* Enable RX Status Interrupt */
  75. #define EDSSI 0x08 /* Enable Modem Status Interrupt */
  76. #define EDTPTI 0x10 /* Enable DMA Transmit PIRQ Interrupt */
  77. #define ETFI 0x20 /* Enable Transmission Finished Interrupt */
  78. #define ERFCI 0x40 /* Enable Receive FIFO Count Interrupt */
  79. /* UART_MCR Masks */
  80. #define XOFF 0x01 /* Transmitter Off */
  81. #define MRTS 0x02 /* Manual Request To Send */
  82. #define RFIT 0x04 /* Receive FIFO IRQ Threshold */
  83. #define RFRT 0x08 /* Receive FIFO RTS Threshold */
  84. #define LOOP_ENA 0x10 /* Loopback Mode Enable */
  85. #define FCPOL 0x20 /* Flow Control Pin Polarity */
  86. #define ARTS 0x40 /* Automatic Request To Send */
  87. #define ACTS 0x80 /* Automatic Clear To Send */
  88. /* UART_MSR Masks */
  89. #define SCTS 0x01 /* Sticky CTS */
  90. #define CTS 0x10 /* Clear To Send */
  91. #define RFCS 0x20 /* Receive FIFO Count Status */
  92. /* UART_GCTL Masks */
  93. #define UCEN 0x01 /* Enable UARTx Clocks */
  94. #define IREN 0x02 /* Enable IrDA Mode */
  95. #define TPOLC 0x04 /* IrDA TX Polarity Change */
  96. #define RPOLC 0x08 /* IrDA RX Polarity Change */
  97. #define FPE 0x10 /* Force Parity Error On Transmit */
  98. #define FFE 0x20 /* Force Framing Error On Transmit */
  99. #ifdef BFIN_UART_BF54X_STYLE
  100. # define OFFSET_DLL 0x00 /* Divisor Latch (Low-Byte) */
  101. # define OFFSET_DLH 0x04 /* Divisor Latch (High-Byte) */
  102. # define OFFSET_GCTL 0x08 /* Global Control Register */
  103. # define OFFSET_LCR 0x0C /* Line Control Register */
  104. # define OFFSET_MCR 0x10 /* Modem Control Register */
  105. # define OFFSET_LSR 0x14 /* Line Status Register */
  106. # define OFFSET_MSR 0x18 /* Modem Status Register */
  107. # define OFFSET_SCR 0x1C /* SCR Scratch Register */
  108. # define OFFSET_IER_SET 0x20 /* Set Interrupt Enable Register */
  109. # define OFFSET_IER_CLEAR 0x24 /* Clear Interrupt Enable Register */
  110. # define OFFSET_THR 0x28 /* Transmit Holding register */
  111. # define OFFSET_RBR 0x2C /* Receive Buffer register */
  112. #else /* BF533 style */
  113. # define OFFSET_THR 0x00 /* Transmit Holding register */
  114. # define OFFSET_RBR 0x00 /* Receive Buffer register */
  115. # define OFFSET_DLL 0x00 /* Divisor Latch (Low-Byte) */
  116. # define OFFSET_DLH 0x04 /* Divisor Latch (High-Byte) */
  117. # define OFFSET_IER 0x04 /* Interrupt Enable Register */
  118. # define OFFSET_IIR 0x08 /* Interrupt Identification Register */
  119. # define OFFSET_LCR 0x0C /* Line Control Register */
  120. # define OFFSET_MCR 0x10 /* Modem Control Register */
  121. # define OFFSET_LSR 0x14 /* Line Status Register */
  122. # define OFFSET_MSR 0x18 /* Modem Status Register */
  123. # define OFFSET_SCR 0x1C /* SCR Scratch Register */
  124. # define OFFSET_GCTL 0x24 /* Global Control Register */
  125. /* code should not need IIR, so force build error if they use it */
  126. # undef OFFSET_IIR
  127. #endif
  128. /*
  129. * All Blackfin system MMRs are padded to 32bits even if the register
  130. * itself is only 16bits. So use a helper macro to streamline this.
  131. */
  132. #define __BFP(m) u16 m; u16 __pad_##m
  133. struct bfin_uart_regs {
  134. #ifdef BFIN_UART_BF54X_STYLE
  135. __BFP(dll);
  136. __BFP(dlh);
  137. __BFP(gctl);
  138. __BFP(lcr);
  139. __BFP(mcr);
  140. __BFP(lsr);
  141. __BFP(msr);
  142. __BFP(scr);
  143. __BFP(ier_set);
  144. __BFP(ier_clear);
  145. __BFP(thr);
  146. __BFP(rbr);
  147. #else
  148. union {
  149. u16 dll;
  150. u16 thr;
  151. const u16 rbr;
  152. };
  153. const u16 __pad0;
  154. union {
  155. u16 dlh;
  156. u16 ier;
  157. };
  158. const u16 __pad1;
  159. const __BFP(iir);
  160. __BFP(lcr);
  161. __BFP(mcr);
  162. __BFP(lsr);
  163. __BFP(msr);
  164. __BFP(scr);
  165. const u32 __pad2;
  166. __BFP(gctl);
  167. #endif
  168. };
  169. #undef __BFP
  170. #ifndef port_membase
  171. # define port_membase(p) (((struct bfin_serial_port *)(p))->port.membase)
  172. #endif
  173. #define UART_GET_CHAR(p) bfin_read16(port_membase(p) + OFFSET_RBR)
  174. #define UART_GET_DLL(p) bfin_read16(port_membase(p) + OFFSET_DLL)
  175. #define UART_GET_DLH(p) bfin_read16(port_membase(p) + OFFSET_DLH)
  176. #define UART_GET_GCTL(p) bfin_read16(port_membase(p) + OFFSET_GCTL)
  177. #define UART_GET_LCR(p) bfin_read16(port_membase(p) + OFFSET_LCR)
  178. #define UART_GET_MCR(p) bfin_read16(port_membase(p) + OFFSET_MCR)
  179. #define UART_GET_MSR(p) bfin_read16(port_membase(p) + OFFSET_MSR)
  180. #define UART_PUT_CHAR(p, v) bfin_write16(port_membase(p) + OFFSET_THR, v)
  181. #define UART_PUT_DLL(p, v) bfin_write16(port_membase(p) + OFFSET_DLL, v)
  182. #define UART_PUT_DLH(p, v) bfin_write16(port_membase(p) + OFFSET_DLH, v)
  183. #define UART_PUT_GCTL(p, v) bfin_write16(port_membase(p) + OFFSET_GCTL, v)
  184. #define UART_PUT_LCR(p, v) bfin_write16(port_membase(p) + OFFSET_LCR, v)
  185. #define UART_PUT_MCR(p, v) bfin_write16(port_membase(p) + OFFSET_MCR, v)
  186. #ifdef BFIN_UART_BF54X_STYLE
  187. #define UART_CLEAR_IER(p, v) bfin_write16(port_membase(p) + OFFSET_IER_CLEAR, v)
  188. #define UART_GET_IER(p) bfin_read16(port_membase(p) + OFFSET_IER_SET)
  189. #define UART_SET_IER(p, v) bfin_write16(port_membase(p) + OFFSET_IER_SET, v)
  190. #define UART_CLEAR_DLAB(p) /* MMRs not muxed on BF54x */
  191. #define UART_SET_DLAB(p) /* MMRs not muxed on BF54x */
  192. #define UART_CLEAR_LSR(p) bfin_write16(port_membase(p) + OFFSET_LSR, -1)
  193. #define UART_GET_LSR(p) bfin_read16(port_membase(p) + OFFSET_LSR)
  194. #define UART_PUT_LSR(p, v) bfin_write16(port_membase(p) + OFFSET_LSR, v)
  195. /* This handles hard CTS/RTS */
  196. #define BFIN_UART_CTSRTS_HARD
  197. #define UART_CLEAR_SCTS(p) bfin_write16((port_membase(p) + OFFSET_MSR), SCTS)
  198. #define UART_GET_CTS(x) (UART_GET_MSR(x) & CTS)
  199. #define UART_DISABLE_RTS(x) UART_PUT_MCR(x, UART_GET_MCR(x) & ~(ARTS | MRTS))
  200. #define UART_ENABLE_RTS(x) UART_PUT_MCR(x, UART_GET_MCR(x) | MRTS | ARTS)
  201. #define UART_ENABLE_INTS(x, v) UART_SET_IER(x, v)
  202. #define UART_DISABLE_INTS(x) UART_CLEAR_IER(x, 0xF)
  203. #else /* BF533 style */
  204. #define UART_CLEAR_IER(p, v) UART_PUT_IER(p, UART_GET_IER(p) & ~(v))
  205. #define UART_GET_IER(p) bfin_read16(port_membase(p) + OFFSET_IER)
  206. #define UART_PUT_IER(p, v) bfin_write16(port_membase(p) + OFFSET_IER, v)
  207. #define UART_SET_IER(p, v) UART_PUT_IER(p, UART_GET_IER(p) | (v))
  208. #define UART_CLEAR_DLAB(p) do { UART_PUT_LCR(p, UART_GET_LCR(p) & ~DLAB); SSYNC(); } while (0)
  209. #define UART_SET_DLAB(p) do { UART_PUT_LCR(p, UART_GET_LCR(p) | DLAB); SSYNC(); } while (0)
  210. #ifndef put_lsr_cache
  211. # define put_lsr_cache(p, v) (((struct bfin_serial_port *)(p))->lsr = (v))
  212. #endif
  213. #ifndef get_lsr_cache
  214. # define get_lsr_cache(p) (((struct bfin_serial_port *)(p))->lsr)
  215. #endif
  216. /* The hardware clears the LSR bits upon read, so we need to cache
  217. * some of the more fun bits in software so they don't get lost
  218. * when checking the LSR in other code paths (TX).
  219. */
  220. static inline void UART_CLEAR_LSR(void *p)
  221. {
  222. put_lsr_cache(p, 0);
  223. bfin_write16(port_membase(p) + OFFSET_LSR, -1);
  224. }
  225. static inline unsigned int UART_GET_LSR(void *p)
  226. {
  227. unsigned int lsr = bfin_read16(port_membase(p) + OFFSET_LSR);
  228. put_lsr_cache(p, get_lsr_cache(p) | (lsr & (BI|FE|PE|OE)));
  229. return lsr | get_lsr_cache(p);
  230. }
  231. static inline void UART_PUT_LSR(void *p, uint16_t val)
  232. {
  233. put_lsr_cache(p, get_lsr_cache(p) & ~val);
  234. }
  235. /* This handles soft CTS/RTS */
  236. #define UART_GET_CTS(x) gpio_get_value((x)->cts_pin)
  237. #define UART_DISABLE_RTS(x) gpio_set_value((x)->rts_pin, 1)
  238. #define UART_ENABLE_RTS(x) gpio_set_value((x)->rts_pin, 0)
  239. #define UART_ENABLE_INTS(x, v) UART_PUT_IER(x, v)
  240. #define UART_DISABLE_INTS(x) UART_PUT_IER(x, 0)
  241. #endif
  242. #ifndef BFIN_UART_TX_FIFO_SIZE
  243. # define BFIN_UART_TX_FIFO_SIZE 2
  244. #endif
  245. #endif /* __BFIN_ASM_SERIAL_H__ */