bfin_serial_5xx.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. #include <linux/serial.h>
  2. #include <asm/dma.h>
  3. #include <asm/portmux.h>
  4. #define NR_PORTS 1
  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_GCTL(uart) bfin_read16(((uart)->port.membase + OFFSET_GCTL))
  24. #define UART_PUT_CHAR(uart,v) bfin_write16(((uart)->port.membase + OFFSET_THR),v)
  25. #define UART_PUT_DLL(uart,v) bfin_write16(((uart)->port.membase + OFFSET_DLL),v)
  26. #define UART_PUT_IER(uart,v) bfin_write16(((uart)->port.membase + OFFSET_IER),v)
  27. #define UART_PUT_DLH(uart,v) bfin_write16(((uart)->port.membase + OFFSET_DLH),v)
  28. #define UART_PUT_LCR(uart,v) bfin_write16(((uart)->port.membase + OFFSET_LCR),v)
  29. #define UART_PUT_GCTL(uart,v) bfin_write16(((uart)->port.membase + OFFSET_GCTL),v)
  30. #ifdef CONFIG_BFIN_UART0_CTSRTS
  31. # define CONFIG_SERIAL_BFIN_CTSRTS
  32. # ifndef CONFIG_UART0_CTS_PIN
  33. # define CONFIG_UART0_CTS_PIN -1
  34. # endif
  35. # ifndef CONFIG_UART0_RTS_PIN
  36. # define CONFIG_UART0_RTS_PIN -1
  37. # endif
  38. #endif
  39. struct bfin_serial_port {
  40. struct uart_port port;
  41. unsigned int old_status;
  42. unsigned int lsr;
  43. #ifdef CONFIG_SERIAL_BFIN_DMA
  44. int tx_done;
  45. int tx_count;
  46. struct circ_buf rx_dma_buf;
  47. struct timer_list rx_dma_timer;
  48. int rx_dma_nrows;
  49. unsigned int tx_dma_channel;
  50. unsigned int rx_dma_channel;
  51. struct work_struct tx_dma_workqueue;
  52. #else
  53. # if ANOMALY_05000230
  54. unsigned int anomaly_threshold;
  55. # endif
  56. #endif
  57. #ifdef CONFIG_SERIAL_BFIN_CTSRTS
  58. struct work_struct cts_workqueue;
  59. int cts_pin;
  60. int rts_pin;
  61. #endif
  62. };
  63. /* The hardware clears the LSR bits upon read, so we need to cache
  64. * some of the more fun bits in software so they don't get lost
  65. * when checking the LSR in other code paths (TX).
  66. */
  67. static inline unsigned int UART_GET_LSR(struct bfin_serial_port *uart)
  68. {
  69. unsigned int lsr = bfin_read16(uart->port.membase + OFFSET_LSR);
  70. uart->lsr |= (lsr & (BI|FE|PE|OE));
  71. return lsr | uart->lsr;
  72. }
  73. static inline void UART_CLEAR_LSR(struct bfin_serial_port *uart)
  74. {
  75. uart->lsr = 0;
  76. bfin_write16(uart->port.membase + OFFSET_LSR, -1);
  77. }
  78. struct bfin_serial_port bfin_serial_ports[NR_PORTS];
  79. struct bfin_serial_res {
  80. unsigned long uart_base_addr;
  81. int uart_irq;
  82. #ifdef CONFIG_SERIAL_BFIN_DMA
  83. unsigned int uart_tx_dma_channel;
  84. unsigned int uart_rx_dma_channel;
  85. #endif
  86. #ifdef CONFIG_SERIAL_BFIN_CTSRTS
  87. int uart_cts_pin;
  88. int uart_rts_pin;
  89. #endif
  90. };
  91. struct bfin_serial_res bfin_serial_resource[] = {
  92. {
  93. 0xFFC00400,
  94. IRQ_UART_RX,
  95. #ifdef CONFIG_SERIAL_BFIN_DMA
  96. CH_UART_TX,
  97. CH_UART_RX,
  98. #endif
  99. #ifdef CONFIG_BFIN_UART0_CTSRTS
  100. CONFIG_UART0_CTS_PIN,
  101. CONFIG_UART0_RTS_PIN,
  102. #endif
  103. }
  104. };
  105. #define DRIVER_NAME "bfin-uart"
  106. int nr_ports = NR_PORTS;
  107. static void bfin_serial_hw_init(struct bfin_serial_port *uart)
  108. {
  109. #ifdef CONFIG_SERIAL_BFIN_UART0
  110. peripheral_request(P_UART0_TX, DRIVER_NAME);
  111. peripheral_request(P_UART0_RX, DRIVER_NAME);
  112. #endif
  113. #ifdef CONFIG_SERIAL_BFIN_CTSRTS
  114. if (uart->cts_pin >= 0) {
  115. gpio_request(uart->cts_pin, DRIVER_NAME);
  116. gpio_direction_input(uart->cts_pin);
  117. }
  118. if (uart->rts_pin >= 0) {
  119. gpio_request(uart->rts_pin, DRIVER_NAME);
  120. gpio_direction_input(uart->rts_pin, 0);
  121. }
  122. #endif
  123. }