bfin_serial_5xx.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #include <linux/serial.h>
  2. #include <asm/dma.h>
  3. #define NR_PORTS 2
  4. #define OFFSET_THR 0x00 /* Transmit Holding register */
  5. #define OFFSET_RBR 0x00 /* Receive Buffer register */
  6. #define OFFSET_DLL 0x00 /* Divisor Latch (Low-Byte) */
  7. #define OFFSET_IER 0x04 /* Interrupt Enable Register */
  8. #define OFFSET_DLH 0x04 /* Divisor Latch (High-Byte) */
  9. #define OFFSET_IIR 0x08 /* Interrupt Identification Register */
  10. #define OFFSET_LCR 0x0C /* Line Control Register */
  11. #define OFFSET_MCR 0x10 /* Modem Control Register */
  12. #define OFFSET_LSR 0x14 /* Line Status Register */
  13. #define OFFSET_MSR 0x18 /* Modem Status Register */
  14. #define OFFSET_SCR 0x1C /* SCR Scratch Register */
  15. #define OFFSET_GCTL 0x24 /* Global Control 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_IER(uart) bfin_read16(((uart)->port.membase + OFFSET_IER))
  19. #define UART_GET_DLH(uart) bfin_read16(((uart)->port.membase + OFFSET_DLH))
  20. #define UART_GET_IIR(uart) bfin_read16(((uart)->port.membase + OFFSET_IIR))
  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_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. #if defined(CONFIG_BFIN_UART0_CTSRTS) || defined(CONFIG_BFIN_UART1_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. # ifndef CONFIG_UART1_CTS_PIN
  39. # define CONFIG_UART1_CTS_PIN -1
  40. # endif
  41. # ifndef CONFIG_UART1_RTS_PIN
  42. # define CONFIG_UART1_RTS_PIN -1
  43. # endif
  44. #endif
  45. /*
  46. * The pin configuration is different from schematic
  47. */
  48. struct bfin_serial_port {
  49. struct uart_port port;
  50. unsigned int old_status;
  51. #ifdef CONFIG_SERIAL_BFIN_DMA
  52. int tx_done;
  53. int tx_count;
  54. struct circ_buf rx_dma_buf;
  55. struct timer_list rx_dma_timer;
  56. int rx_dma_nrows;
  57. unsigned int tx_dma_channel;
  58. unsigned int rx_dma_channel;
  59. struct work_struct tx_dma_workqueue;
  60. #else
  61. struct work_struct cts_workqueue;
  62. #endif
  63. #ifdef CONFIG_SERIAL_BFIN_CTSRTS
  64. int cts_pin;
  65. int rts_pin;
  66. #endif
  67. };
  68. struct bfin_serial_port bfin_serial_ports[NR_PORTS];
  69. struct bfin_serial_res {
  70. unsigned long uart_base_addr;
  71. int uart_irq;
  72. #ifdef CONFIG_SERIAL_BFIN_DMA
  73. unsigned int uart_tx_dma_channel;
  74. unsigned int uart_rx_dma_channel;
  75. #endif
  76. #ifdef CONFIG_SERIAL_BFIN_CTSRTS
  77. int uart_cts_pin;
  78. int uart_rts_pin;
  79. #endif
  80. };
  81. struct bfin_serial_res bfin_serial_resource[] = {
  82. #ifdef CONFIG_SERIAL_BFIN_UART0
  83. {
  84. 0xFFC00400,
  85. IRQ_UART0_RX,
  86. #ifdef CONFIG_SERIAL_BFIN_DMA
  87. CH_UART0_TX,
  88. CH_UART0_RX,
  89. #endif
  90. #ifdef CONFIG_BFIN_UART0_CTSRTS
  91. CONFIG_UART0_CTS_PIN,
  92. CONFIG_UART0_RTS_PIN,
  93. #endif
  94. },
  95. #endif
  96. #ifdef CONFIG_SERIAL_BFIN_UART1
  97. {
  98. 0xFFC02000,
  99. IRQ_UART1_RX,
  100. #ifdef CONFIG_SERIAL_BFIN_DMA
  101. CH_UART1_TX,
  102. CH_UART1_RX,
  103. #endif
  104. #ifdef CONFIG_BFIN_UART1_CTSRTS
  105. CONFIG_UART1_CTS_PIN,
  106. CONFIG_UART1_RTS_PIN,
  107. #endif
  108. },
  109. #endif
  110. };
  111. int nr_ports = ARRAY_SIZE(bfin_serial_resource);
  112. static void bfin_serial_hw_init(struct bfin_serial_port *uart)
  113. {
  114. unsigned short val;
  115. val = bfin_read16(BFIN_PORT_MUX);
  116. val &= ~(PFDE | PFTE);
  117. bfin_write16(BFIN_PORT_MUX, val);
  118. val = bfin_read16(PORTF_FER);
  119. val |= 0xF;
  120. bfin_write16(PORTF_FER, val);
  121. #ifdef CONFIG_SERIAL_BFIN_CTSRTS
  122. if (uart->cts_pin >= 0) {
  123. gpio_request(uart->cts_pin, NULL);
  124. gpio_direction_input(uart->cts_pin);
  125. }
  126. if (uart->rts_pin >= 0) {
  127. gpio_request(uart->rts_pin, NULL);
  128. gpio_direction_output(uart->rts_pin);
  129. }
  130. #endif
  131. }