bfin_serial.h 10 KB

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