bfin_serial_5xx.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Copyright 2007-2009 Analog Devices Inc.
  3. *
  4. * Licensed under the GPL-2 or later.
  5. */
  6. #include <linux/serial.h>
  7. #include <asm/dma.h>
  8. #include <asm/portmux.h>
  9. #define UART_GET_CHAR(uart) bfin_read16(((uart)->port.membase + OFFSET_RBR))
  10. #define UART_GET_DLL(uart) bfin_read16(((uart)->port.membase + OFFSET_DLL))
  11. #define UART_GET_DLH(uart) bfin_read16(((uart)->port.membase + OFFSET_DLH))
  12. #define UART_GET_IER(uart) bfin_read16(((uart)->port.membase + OFFSET_IER_SET))
  13. #define UART_GET_LCR(uart) bfin_read16(((uart)->port.membase + OFFSET_LCR))
  14. #define UART_GET_LSR(uart) bfin_read16(((uart)->port.membase + OFFSET_LSR))
  15. #define UART_GET_GCTL(uart) bfin_read16(((uart)->port.membase + OFFSET_GCTL))
  16. #define UART_GET_MSR(uart) bfin_read16(((uart)->port.membase + OFFSET_MSR))
  17. #define UART_GET_MCR(uart) bfin_read16(((uart)->port.membase + OFFSET_MCR))
  18. #define UART_PUT_CHAR(uart,v) bfin_write16(((uart)->port.membase + OFFSET_THR),v)
  19. #define UART_PUT_DLL(uart,v) bfin_write16(((uart)->port.membase + OFFSET_DLL),v)
  20. #define UART_SET_IER(uart,v) bfin_write16(((uart)->port.membase + OFFSET_IER_SET),v)
  21. #define UART_CLEAR_IER(uart,v) bfin_write16(((uart)->port.membase + OFFSET_IER_CLEAR),v)
  22. #define UART_PUT_DLH(uart,v) bfin_write16(((uart)->port.membase + OFFSET_DLH),v)
  23. #define UART_PUT_LSR(uart,v) bfin_write16(((uart)->port.membase + OFFSET_LSR),v)
  24. #define UART_PUT_LCR(uart,v) bfin_write16(((uart)->port.membase + OFFSET_LCR),v)
  25. #define UART_CLEAR_LSR(uart) bfin_write16(((uart)->port.membase + OFFSET_LSR), -1)
  26. #define UART_PUT_GCTL(uart,v) bfin_write16(((uart)->port.membase + OFFSET_GCTL),v)
  27. #define UART_PUT_MCR(uart,v) bfin_write16(((uart)->port.membase + OFFSET_MCR),v)
  28. #define UART_CLEAR_SCTS(uart) bfin_write16(((uart)->port.membase + OFFSET_MSR),SCTS)
  29. #define UART_SET_DLAB(uart) /* MMRs not muxed on BF54x */
  30. #define UART_CLEAR_DLAB(uart) /* MMRs not muxed on BF54x */
  31. #define UART_GET_CTS(x) (UART_GET_MSR(x) & CTS)
  32. #define UART_DISABLE_RTS(x) UART_PUT_MCR(x, UART_GET_MCR(x) & ~(ARTS|MRTS))
  33. #define UART_ENABLE_RTS(x) UART_PUT_MCR(x, UART_GET_MCR(x) | MRTS | ARTS)
  34. #define UART_ENABLE_INTS(x, v) UART_SET_IER(x, v)
  35. #define UART_DISABLE_INTS(x) UART_CLEAR_IER(x, 0xF)
  36. #if defined(CONFIG_BFIN_UART0_CTSRTS) || defined(CONFIG_BFIN_UART1_CTSRTS) || \
  37. defined(CONFIG_BFIN_UART2_CTSRTS) || defined(CONFIG_BFIN_UART3_CTSRTS)
  38. # define CONFIG_SERIAL_BFIN_HARD_CTSRTS
  39. #endif
  40. #define BFIN_UART_TX_FIFO_SIZE 2
  41. /*
  42. * The pin configuration is different from schematic
  43. */
  44. struct bfin_serial_port {
  45. struct uart_port port;
  46. unsigned int old_status;
  47. int status_irq;
  48. #ifdef CONFIG_SERIAL_BFIN_DMA
  49. int tx_done;
  50. int tx_count;
  51. struct circ_buf rx_dma_buf;
  52. struct timer_list rx_dma_timer;
  53. int rx_dma_nrows;
  54. unsigned int tx_dma_channel;
  55. unsigned int rx_dma_channel;
  56. struct work_struct tx_dma_workqueue;
  57. #endif
  58. #ifdef CONFIG_SERIAL_BFIN_HARD_CTSRTS
  59. int scts;
  60. int cts_pin;
  61. int rts_pin;
  62. #endif
  63. };
  64. struct bfin_serial_res {
  65. unsigned long uart_base_addr;
  66. int uart_irq;
  67. int uart_status_irq;
  68. #ifdef CONFIG_SERIAL_BFIN_DMA
  69. unsigned int uart_tx_dma_channel;
  70. unsigned int uart_rx_dma_channel;
  71. #endif
  72. #ifdef CONFIG_SERIAL_BFIN_HARD_CTSRTS
  73. int uart_cts_pin;
  74. int uart_rts_pin;
  75. #endif
  76. };
  77. struct bfin_serial_res bfin_serial_resource[] = {
  78. #ifdef CONFIG_SERIAL_BFIN_UART0
  79. {
  80. 0xFFC00400,
  81. IRQ_UART0_RX,
  82. IRQ_UART0_ERROR,
  83. #ifdef CONFIG_SERIAL_BFIN_DMA
  84. CH_UART0_TX,
  85. CH_UART0_RX,
  86. #endif
  87. #ifdef CONFIG_SERIAL_BFIN_HARD_CTSRTS
  88. 0,
  89. 0,
  90. #endif
  91. },
  92. #endif
  93. #ifdef CONFIG_SERIAL_BFIN_UART1
  94. {
  95. 0xFFC02000,
  96. IRQ_UART1_RX,
  97. IRQ_UART1_ERROR,
  98. #ifdef CONFIG_SERIAL_BFIN_DMA
  99. CH_UART1_TX,
  100. CH_UART1_RX,
  101. #endif
  102. #ifdef CONFIG_SERIAL_BFIN_HARD_CTSRTS
  103. GPIO_PE10,
  104. GPIO_PE9,
  105. #endif
  106. },
  107. #endif
  108. #ifdef CONFIG_SERIAL_BFIN_UART2
  109. {
  110. 0xFFC02100,
  111. IRQ_UART2_RX,
  112. IRQ_UART2_ERROR,
  113. #ifdef CONFIG_SERIAL_BFIN_DMA
  114. CH_UART2_TX,
  115. CH_UART2_RX,
  116. #endif
  117. #ifdef CONFIG_SERIAL_BFIN_HARD_CTSRTS
  118. 0,
  119. 0,
  120. #endif
  121. },
  122. #endif
  123. #ifdef CONFIG_SERIAL_BFIN_UART3
  124. {
  125. 0xFFC03100,
  126. IRQ_UART3_RX,
  127. IRQ_UART3_ERROR,
  128. #ifdef CONFIG_SERIAL_BFIN_DMA
  129. CH_UART3_TX,
  130. CH_UART3_RX,
  131. #endif
  132. #ifdef CONFIG_SERIAL_BFIN_HARD_CTSRTS
  133. GPIO_PB3,
  134. GPIO_PB2,
  135. #endif
  136. },
  137. #endif
  138. };
  139. #define DRIVER_NAME "bfin-uart"