bfin_serial_5xx.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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_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. #ifdef CONFIG_BFIN_UART0_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. #endif
  40. struct bfin_serial_port {
  41. struct uart_port port;
  42. unsigned int old_status;
  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. struct work_struct cts_workqueue;
  54. #endif
  55. #ifdef CONFIG_SERIAL_BFIN_CTSRTS
  56. int cts_pin;
  57. int rts_pin;
  58. #endif
  59. };
  60. struct bfin_serial_port bfin_serial_ports[NR_PORTS];
  61. struct bfin_serial_res {
  62. unsigned long uart_base_addr;
  63. int uart_irq;
  64. #ifdef CONFIG_SERIAL_BFIN_DMA
  65. unsigned int uart_tx_dma_channel;
  66. unsigned int uart_rx_dma_channel;
  67. #endif
  68. #ifdef CONFIG_SERIAL_BFIN_CTSRTS
  69. int uart_cts_pin;
  70. int uart_rts_pin;
  71. #endif
  72. };
  73. struct bfin_serial_res bfin_serial_resource[] = {
  74. {
  75. 0xFFC00400,
  76. IRQ_UART_RX,
  77. #ifdef CONFIG_SERIAL_BFIN_DMA
  78. CH_UART_TX,
  79. CH_UART_RX,
  80. #endif
  81. #ifdef CONFIG_BFIN_UART0_CTSRTS
  82. CONFIG_UART0_CTS_PIN,
  83. CONFIG_UART0_RTS_PIN,
  84. #endif
  85. }
  86. };
  87. #define DRIVER_NAME "bfin-uart"
  88. int nr_ports = NR_PORTS;
  89. static void bfin_serial_hw_init(struct bfin_serial_port *uart)
  90. {
  91. #ifdef CONFIG_SERIAL_BFIN_UART0
  92. peripheral_request(P_UART0_TX, DRIVER_NAME);
  93. peripheral_request(P_UART0_RX, DRIVER_NAME);
  94. #endif
  95. #ifdef CONFIG_SERIAL_BFIN_CTSRTS
  96. if (uart->cts_pin >= 0) {
  97. gpio_request(uart->cts_pin, DRIVER_NAME);
  98. gpio_direction_input(uart->cts_pin);
  99. }
  100. if (uart->rts_pin >= 0) {
  101. gpio_request(uart->rts_pin, DRIVER_NAME);
  102. gpio_direction_input(uart->rts_pin);
  103. }
  104. #endif
  105. }