bfin_serial_5xx.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. #include <linux/serial.h>
  2. #include <asm/dma.h>
  3. #include <asm/portmux.h>
  4. #define NR_PORTS 2
  5. #define OFFSET_THR 0x00 /* Transmit Holding register */
  6. #define OFFSET_RBR 0x00 /* Receive Buffer register */
  7. #define OFFSET_DLL 0x00 /* Divisor Latch (Low-Byte) */
  8. #define OFFSET_IER 0x04 /* Interrupt Enable Register */
  9. #define OFFSET_DLH 0x04 /* Divisor Latch (High-Byte) */
  10. #define OFFSET_IIR 0x08 /* Interrupt Identification Register */
  11. #define OFFSET_LCR 0x0C /* Line Control Register */
  12. #define OFFSET_MCR 0x10 /* Modem Control Register */
  13. #define OFFSET_LSR 0x14 /* Line Status Register */
  14. #define OFFSET_MSR 0x18 /* Modem Status Register */
  15. #define OFFSET_SCR 0x1C /* SCR Scratch Register */
  16. #define OFFSET_GCTL 0x24 /* Global Control 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_IER(uart) bfin_read16(((uart)->port.membase + OFFSET_IER))
  20. #define UART_GET_DLH(uart) bfin_read16(((uart)->port.membase + OFFSET_DLH))
  21. #define UART_GET_IIR(uart) bfin_read16(((uart)->port.membase + OFFSET_IIR))
  22. #define UART_GET_LCR(uart) bfin_read16(((uart)->port.membase + OFFSET_LCR))
  23. #define UART_GET_LSR(uart) bfin_read16(((uart)->port.membase + OFFSET_LSR))
  24. #define UART_GET_GCTL(uart) bfin_read16(((uart)->port.membase + OFFSET_GCTL))
  25. #define UART_PUT_CHAR(uart, v) bfin_write16(((uart)->port.membase + OFFSET_THR), v)
  26. #define UART_PUT_DLL(uart, v) bfin_write16(((uart)->port.membase + OFFSET_DLL), v)
  27. #define UART_PUT_IER(uart, v) bfin_write16(((uart)->port.membase + OFFSET_IER), v)
  28. #define UART_PUT_DLH(uart, v) bfin_write16(((uart)->port.membase + OFFSET_DLH), 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. #ifdef CONFIG_BFIN_UART1_CTSRTS
  106. CONFIG_UART1_CTS_PIN,
  107. CONFIG_UART1_RTS_PIN,
  108. #endif
  109. },
  110. #endif
  111. };
  112. int nr_ports = ARRAY_SIZE(bfin_serial_resource);
  113. #define DRIVER_NAME "bfin-uart"
  114. static void bfin_serial_hw_init(struct bfin_serial_port *uart)
  115. {
  116. #ifdef CONFIG_SERIAL_BFIN_UART0
  117. peripheral_request(P_UART0_TX, DRIVER_NAME);
  118. peripheral_request(P_UART0_RX, DRIVER_NAME);
  119. #endif
  120. #ifdef CONFIG_SERIAL_BFIN_UART1
  121. peripheral_request(P_UART1_TX, DRIVER_NAME);
  122. peripheral_request(P_UART1_RX, DRIVER_NAME);
  123. #endif
  124. #ifdef CONFIG_SERIAL_BFIN_CTSRTS
  125. if (uart->cts_pin >= 0) {
  126. gpio_request(uart->cts_pin, DRIVER_NAME);
  127. gpio_direction_input(uart->cts_pin);
  128. }
  129. if (uart->rts_pin >= 0) {
  130. gpio_request(uart->rts_pin, DRIVER_NAME);
  131. gpio_direction_output(uart->rts_pin);
  132. }
  133. #endif
  134. }