bfin_serial_5xx.h 5.8 KB

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