bfin_serial.h 10 KB

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