bfin_serial.h 10 KB

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