bfin_serial.h 10 KB

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