8250.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /*
  2. * Driver for 8250/16550-type serial ports
  3. *
  4. * Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
  5. *
  6. * Copyright (C) 2001 Russell King.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. */
  13. #include <linux/serial_8250.h>
  14. #include <linux/serial_reg.h>
  15. #include <linux/dmaengine.h>
  16. struct uart_8250_dma {
  17. int (*tx_dma)(struct uart_8250_port *p);
  18. int (*rx_dma)(struct uart_8250_port *p, unsigned int iir);
  19. /* Filter function */
  20. dma_filter_fn fn;
  21. /* Parameter to the filter function */
  22. void *rx_param;
  23. void *tx_param;
  24. struct dma_slave_config rxconf;
  25. struct dma_slave_config txconf;
  26. struct dma_chan *rxchan;
  27. struct dma_chan *txchan;
  28. dma_addr_t rx_addr;
  29. dma_addr_t tx_addr;
  30. dma_cookie_t rx_cookie;
  31. dma_cookie_t tx_cookie;
  32. void *rx_buf;
  33. size_t rx_size;
  34. size_t tx_size;
  35. unsigned char tx_running;
  36. unsigned char tx_err;
  37. unsigned char rx_running;
  38. };
  39. struct old_serial_port {
  40. unsigned int uart;
  41. unsigned int baud_base;
  42. unsigned int port;
  43. unsigned int irq;
  44. upf_t flags;
  45. unsigned char hub6;
  46. unsigned char io_type;
  47. unsigned char __iomem *iomem_base;
  48. unsigned short iomem_reg_shift;
  49. unsigned long irqflags;
  50. };
  51. struct serial8250_config {
  52. const char *name;
  53. unsigned short fifo_size;
  54. unsigned short tx_loadsz;
  55. unsigned char fcr;
  56. unsigned char rxtrig_bytes[UART_FCR_R_TRIG_MAX_STATE];
  57. unsigned int flags;
  58. };
  59. #define UART_CAP_FIFO (1 << 8) /* UART has FIFO */
  60. #define UART_CAP_EFR (1 << 9) /* UART has EFR */
  61. #define UART_CAP_SLEEP (1 << 10) /* UART has IER sleep */
  62. #define UART_CAP_AFE (1 << 11) /* MCR-based hw flow control */
  63. #define UART_CAP_UUE (1 << 12) /* UART needs IER bit 6 set (Xscale) */
  64. #define UART_CAP_RTOIE (1 << 13) /* UART needs IER bit 4 set (Xscale, Tegra) */
  65. #define UART_CAP_HFIFO (1 << 14) /* UART has a "hidden" FIFO */
  66. #define UART_CAP_RPM (1 << 15) /* Runtime PM is active while idle */
  67. #define UART_BUG_QUOT (1 << 0) /* UART has buggy quot LSB */
  68. #define UART_BUG_TXEN (1 << 1) /* UART has buggy TX IIR status */
  69. #define UART_BUG_NOMSR (1 << 2) /* UART has buggy MSR status bits (Au1x00) */
  70. #define UART_BUG_THRE (1 << 3) /* UART has buggy THRE reassertion */
  71. #define UART_BUG_PARITY (1 << 4) /* UART mishandles parity if FIFO enabled */
  72. #define HIGH_BITS_OFFSET ((sizeof(long)-sizeof(int))*8)
  73. #ifdef CONFIG_SERIAL_8250_SHARE_IRQ
  74. #define SERIAL8250_SHARE_IRQS 1
  75. #else
  76. #define SERIAL8250_SHARE_IRQS 0
  77. #endif
  78. static inline int serial_in(struct uart_8250_port *up, int offset)
  79. {
  80. return up->port.serial_in(&up->port, offset);
  81. }
  82. static inline void serial_out(struct uart_8250_port *up, int offset, int value)
  83. {
  84. up->port.serial_out(&up->port, offset, value);
  85. }
  86. void serial8250_clear_and_reinit_fifos(struct uart_8250_port *p);
  87. static inline int serial_dl_read(struct uart_8250_port *up)
  88. {
  89. return up->dl_read(up);
  90. }
  91. static inline void serial_dl_write(struct uart_8250_port *up, int value)
  92. {
  93. up->dl_write(up, value);
  94. }
  95. struct uart_8250_port *serial8250_get_port(int line);
  96. void serial8250_rpm_get(struct uart_8250_port *p);
  97. void serial8250_rpm_put(struct uart_8250_port *p);
  98. #if defined(__alpha__) && !defined(CONFIG_PCI)
  99. /*
  100. * Digital did something really horribly wrong with the OUT1 and OUT2
  101. * lines on at least some ALPHA's. The failure mode is that if either
  102. * is cleared, the machine locks up with endless interrupts.
  103. */
  104. #define ALPHA_KLUDGE_MCR (UART_MCR_OUT2 | UART_MCR_OUT1)
  105. #else
  106. #define ALPHA_KLUDGE_MCR 0
  107. #endif
  108. #ifdef CONFIG_SERIAL_8250_PNP
  109. int serial8250_pnp_init(void);
  110. void serial8250_pnp_exit(void);
  111. #else
  112. static inline int serial8250_pnp_init(void) { return 0; }
  113. static inline void serial8250_pnp_exit(void) { }
  114. #endif
  115. #ifdef CONFIG_ARCH_OMAP1
  116. static inline int is_omap1_8250(struct uart_8250_port *pt)
  117. {
  118. int res;
  119. switch (pt->port.mapbase) {
  120. case OMAP1_UART1_BASE:
  121. case OMAP1_UART2_BASE:
  122. case OMAP1_UART3_BASE:
  123. res = 1;
  124. break;
  125. default:
  126. res = 0;
  127. break;
  128. }
  129. return res;
  130. }
  131. static inline int is_omap1510_8250(struct uart_8250_port *pt)
  132. {
  133. if (!cpu_is_omap1510())
  134. return 0;
  135. return is_omap1_8250(pt);
  136. }
  137. #else
  138. static inline int is_omap1_8250(struct uart_8250_port *pt)
  139. {
  140. return 0;
  141. }
  142. static inline int is_omap1510_8250(struct uart_8250_port *pt)
  143. {
  144. return 0;
  145. }
  146. #endif
  147. #ifdef CONFIG_SERIAL_8250_DMA
  148. extern int serial8250_tx_dma(struct uart_8250_port *);
  149. extern int serial8250_rx_dma(struct uart_8250_port *, unsigned int iir);
  150. extern int serial8250_request_dma(struct uart_8250_port *);
  151. extern void serial8250_release_dma(struct uart_8250_port *);
  152. #else
  153. static inline int serial8250_tx_dma(struct uart_8250_port *p)
  154. {
  155. return -1;
  156. }
  157. static inline int serial8250_rx_dma(struct uart_8250_port *p, unsigned int iir)
  158. {
  159. return -1;
  160. }
  161. static inline int serial8250_request_dma(struct uart_8250_port *p)
  162. {
  163. return -1;
  164. }
  165. static inline void serial8250_release_dma(struct uart_8250_port *p) { }
  166. #endif
  167. static inline int ns16550a_goto_highspeed(struct uart_8250_port *up)
  168. {
  169. unsigned char status;
  170. status = serial_in(up, 0x04); /* EXCR2 */
  171. #define PRESL(x) ((x) & 0x30)
  172. if (PRESL(status) == 0x10) {
  173. /* already in high speed mode */
  174. return 0;
  175. } else {
  176. status &= ~0xB0; /* Disable LOCK, mask out PRESL[01] */
  177. status |= 0x10; /* 1.625 divisor for baud_base --> 921600 */
  178. serial_out(up, 0x04, status);
  179. }
  180. return 1;
  181. }
  182. static inline int serial_index(struct uart_port *port)
  183. {
  184. return port->minor - 64;
  185. }
  186. #if 0
  187. #define DEBUG_INTR(fmt...) printk(fmt)
  188. #else
  189. #define DEBUG_INTR(fmt...) do { } while (0)
  190. #endif