bfin_serial_5xx.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. #include <linux/serial.h>
  2. #include <asm/dma.h>
  3. #define NR_PORTS 4
  4. #define OFFSET_DLL 0x00 /* Divisor Latch (Low-Byte) */
  5. #define OFFSET_DLH 0x04 /* Divisor Latch (High-Byte) */
  6. #define OFFSET_GCTL 0x08 /* Global Control Register */
  7. #define OFFSET_LCR 0x0C /* Line Control Register */
  8. #define OFFSET_MCR 0x10 /* Modem Control Register */
  9. #define OFFSET_LSR 0x14 /* Line Status Register */
  10. #define OFFSET_MSR 0x18 /* Modem Status Register */
  11. #define OFFSET_SCR 0x1C /* SCR Scratch Register */
  12. #define OFFSET_IER_SET 0x20 /* Set Interrupt Enable Register */
  13. #define OFFSET_IER_CLEAR 0x24 /* Clear Interrupt Enable Register */
  14. #define OFFSET_THR 0x28 /* Transmit Holding register */
  15. #define OFFSET_RBR 0x2C /* Receive Buffer register */
  16. #define UART_GET_CHAR(uart) bfin_read16(((uart)->port.membase + OFFSET_RBR))
  17. #define UART_GET_DLL(uart) bfin_read16(((uart)->port.membase + OFFSET_DLL))
  18. #define UART_GET_DLH(uart) bfin_read16(((uart)->port.membase + OFFSET_DLH))
  19. #define UART_GET_IER(uart) bfin_read16(((uart)->port.membase + OFFSET_IER_SET))
  20. #define UART_GET_LCR(uart) bfin_read16(((uart)->port.membase + OFFSET_LCR))
  21. #define UART_GET_LSR(uart) bfin_read16(((uart)->port.membase + OFFSET_LSR))
  22. #define UART_GET_GCTL(uart) bfin_read16(((uart)->port.membase + OFFSET_GCTL))
  23. #define UART_PUT_CHAR(uart,v) bfin_write16(((uart)->port.membase + OFFSET_THR),v)
  24. #define UART_PUT_DLL(uart,v) bfin_write16(((uart)->port.membase + OFFSET_DLL),v)
  25. #define UART_SET_IER(uart,v) bfin_write16(((uart)->port.membase + OFFSET_IER_SET),v)
  26. #define UART_CLEAR_IER(uart,v) bfin_write16(((uart)->port.membase + OFFSET_IER_CLEAR),v)
  27. #define UART_PUT_DLH(uart,v) bfin_write16(((uart)->port.membase + OFFSET_DLH),v)
  28. #define UART_PUT_LSR(uart,v) bfin_write16(((uart)->port.membase + OFFSET_LSR),v)
  29. #define UART_PUT_LCR(uart,v) bfin_write16(((uart)->port.membase + OFFSET_LCR),v)
  30. #define UART_PUT_GCTL(uart,v) bfin_write16(((uart)->port.membase + OFFSET_GCTL),v)
  31. #if defined(CONFIG_BFIN_UART0_CTSRTS) || defined(CONFIG_BFIN_UART1_CTSRTS)
  32. # define CONFIG_SERIAL_BFIN_CTSRTS
  33. # ifndef CONFIG_UART0_CTS_PIN
  34. # define CONFIG_UART0_CTS_PIN -1
  35. # endif
  36. # ifndef CONFIG_UART0_RTS_PIN
  37. # define CONFIG_UART0_RTS_PIN -1
  38. # endif
  39. # ifndef CONFIG_UART1_CTS_PIN
  40. # define CONFIG_UART1_CTS_PIN -1
  41. # endif
  42. # ifndef CONFIG_UART1_RTS_PIN
  43. # define CONFIG_UART1_RTS_PIN -1
  44. # endif
  45. #endif
  46. /*
  47. * The pin configuration is different from schematic
  48. */
  49. struct bfin_serial_port {
  50. struct uart_port port;
  51. unsigned int old_status;
  52. #ifdef CONFIG_SERIAL_BFIN_DMA
  53. int tx_done;
  54. int tx_count;
  55. struct circ_buf rx_dma_buf;
  56. struct timer_list rx_dma_timer;
  57. int rx_dma_nrows;
  58. unsigned int tx_dma_channel;
  59. unsigned int rx_dma_channel;
  60. struct work_struct tx_dma_workqueue;
  61. #else
  62. struct work_struct cts_workqueue;
  63. #endif
  64. #ifdef CONFIG_SERIAL_BFIN_CTSRTS
  65. int cts_pin;
  66. int rts_pin;
  67. #endif
  68. };
  69. struct bfin_serial_port bfin_serial_ports[NR_PORTS];
  70. struct bfin_serial_res {
  71. unsigned long uart_base_addr;
  72. int uart_irq;
  73. #ifdef CONFIG_SERIAL_BFIN_DMA
  74. unsigned int uart_tx_dma_channel;
  75. unsigned int uart_rx_dma_channel;
  76. #endif
  77. #ifdef CONFIG_SERIAL_BFIN_CTSRTS
  78. int uart_cts_pin;
  79. int uart_rts_pin;
  80. #endif
  81. };
  82. struct bfin_serial_res bfin_serial_resource[] = {
  83. #ifdef CONFIG_SERIAL_BFIN_UART0
  84. {
  85. 0xFFC00400,
  86. IRQ_UART0_RX,
  87. #ifdef CONFIG_SERIAL_BFIN_DMA
  88. CH_UART0_TX,
  89. CH_UART0_RX,
  90. #endif
  91. #ifdef CONFIG_BFIN_UART0_CTSRTS
  92. CONFIG_UART0_CTS_PIN,
  93. CONFIG_UART0_RTS_PIN,
  94. #endif
  95. },
  96. #endif
  97. #ifdef CONFIG_SERIAL_BFIN_UART1
  98. {
  99. 0xFFC02000,
  100. IRQ_UART1_RX,
  101. #ifdef CONFIG_SERIAL_BFIN_DMA
  102. CH_UART1_TX,
  103. CH_UART1_RX,
  104. #endif
  105. },
  106. #endif
  107. #ifdef CONFIG_SERIAL_BFIN_UART2
  108. {
  109. 0xFFC02100,
  110. IRQ_UART2_RX,
  111. #ifdef CONFIG_SERIAL_BFIN_DMA
  112. CH_UART2_TX,
  113. CH_UART2_RX,
  114. #endif
  115. #ifdef CONFIG_BFIN_UART2_CTSRTS
  116. CONFIG_UART2_CTS_PIN,
  117. CONFIG_UART2_RTS_PIN,
  118. #endif
  119. },
  120. #endif
  121. #ifdef CONFIG_SERIAL_BFIN_UART3
  122. {
  123. 0xFFC03100,
  124. IRQ_UART3_RX,
  125. #ifdef CONFIG_SERIAL_BFIN_DMA
  126. CH_UART3_TX,
  127. CH_UART3_RX,
  128. #endif
  129. },
  130. #endif
  131. };
  132. int nr_ports = ARRAY_SIZE(bfin_serial_resource);
  133. static void bfin_serial_hw_init(struct bfin_serial_port *uart)
  134. {
  135. #ifdef CONFIG_SERIAL_BFIN_UART0
  136. /* Enable UART0 RX and TX on pin 7 & 8 of PORT E */
  137. bfin_write_PORTE_FER(0x180 | bfin_read_PORTE_FER());
  138. bfin_write_PORTE_MUX(0x3C000 | bfin_read_PORTE_MUX());
  139. #endif
  140. #ifdef CONFIG_SERIAL_BFIN_UART1
  141. /* Enable UART1 RX and TX on pin 0 & 1 of PORT H */
  142. bfin_write_PORTH_FER(0x3 | bfin_read_PORTH_FER());
  143. bfin_write_PORTH_MUX(~0xF & bfin_read_PORTH_MUX());
  144. #ifdef CONFIG_BFIN_UART1_CTSRTS
  145. /* Enable UART1 RTS and CTS on pin 9 & 10 of PORT E */
  146. bfin_write_PORTE_FER(0x600 | bfin_read_PORTE_FER());
  147. bfin_write_PORTE_MUX(~0x3C0000 & bfin_read_PORTE_MUX());
  148. #endif
  149. #endif
  150. #ifdef CONFIG_SERIAL_BFIN_UART2
  151. /* Enable UART2 RX and TX on pin 4 & 5 of PORT B */
  152. bfin_write_PORTB_FER(0x30 | bfin_read_PORTB_FER());
  153. bfin_write_PORTB_MUX(~0xF00 & bfin_read_PORTB_MUX());
  154. #endif
  155. #ifdef CONFIG_SERIAL_BFIN_UART3
  156. /* Enable UART3 RX and TX on pin 6 & 7 of PORT B */
  157. bfin_write_PORTB_FER(0xC0 | bfin_read_PORTB_FER());
  158. bfin_write_PORTB_MUX(~0xF000 | bfin_read_PORTB_MUX());
  159. #ifdef CONFIG_BFIN_UART3_CTSRTS
  160. /* Enable UART3 RTS and CTS on pin 2 & 3 of PORT B */
  161. bfin_write_PORTB_FER(0xC | bfin_read_PORTB_FER());
  162. bfin_write_PORTB_MUX(~0xF0 | bfin_read_PORTB_MUX());
  163. #endif
  164. #endif
  165. SSYNC();
  166. #ifdef CONFIG_SERIAL_BFIN_CTSRTS
  167. if (uart->cts_pin >= 0) {
  168. gpio_request(uart->cts_pin, NULL);
  169. gpio_direction_input(uart->cts_pin);
  170. }
  171. if (uart->rts_pin >= 0) {
  172. gpio_request(uart->rts_pin, NULL);
  173. gpio_direction_output(uart->rts_pin);
  174. }
  175. #endif
  176. }