8250.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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);
  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. /* Device address base for DMA operations */
  29. phys_addr_t rx_dma_addr;
  30. phys_addr_t tx_dma_addr;
  31. /* DMA address of the buffer in memory */
  32. dma_addr_t rx_addr;
  33. dma_addr_t tx_addr;
  34. dma_cookie_t rx_cookie;
  35. dma_cookie_t tx_cookie;
  36. void *rx_buf;
  37. size_t rx_size;
  38. size_t tx_size;
  39. unsigned char tx_running;
  40. unsigned char tx_err;
  41. unsigned char rx_running;
  42. };
  43. struct old_serial_port {
  44. unsigned int uart;
  45. unsigned int baud_base;
  46. unsigned int port;
  47. unsigned int irq;
  48. upf_t flags;
  49. unsigned char io_type;
  50. unsigned char __iomem *iomem_base;
  51. unsigned short iomem_reg_shift;
  52. };
  53. struct serial8250_config {
  54. const char *name;
  55. unsigned short fifo_size;
  56. unsigned short tx_loadsz;
  57. unsigned char fcr;
  58. unsigned char rxtrig_bytes[UART_FCR_R_TRIG_MAX_STATE];
  59. unsigned int flags;
  60. };
  61. #define UART_CAP_FIFO (1 << 8) /* UART has FIFO */
  62. #define UART_CAP_EFR (1 << 9) /* UART has EFR */
  63. #define UART_CAP_SLEEP (1 << 10) /* UART has IER sleep */
  64. #define UART_CAP_AFE (1 << 11) /* MCR-based hw flow control */
  65. #define UART_CAP_UUE (1 << 12) /* UART needs IER bit 6 set (Xscale) */
  66. #define UART_CAP_RTOIE (1 << 13) /* UART needs IER bit 4 set (Xscale, Tegra) */
  67. #define UART_CAP_HFIFO (1 << 14) /* UART has a "hidden" FIFO */
  68. #define UART_CAP_RPM (1 << 15) /* Runtime PM is active while idle */
  69. #define UART_CAP_IRDA (1 << 16) /* UART supports IrDA line discipline */
  70. #define UART_BUG_QUOT (1 << 0) /* UART has buggy quot LSB */
  71. #define UART_BUG_TXEN (1 << 1) /* UART has buggy TX IIR status */
  72. #define UART_BUG_NOMSR (1 << 2) /* UART has buggy MSR status bits (Au1x00) */
  73. #define UART_BUG_THRE (1 << 3) /* UART has buggy THRE reassertion */
  74. #define UART_BUG_PARITY (1 << 4) /* UART mishandles parity if FIFO enabled */
  75. #ifdef CONFIG_SERIAL_8250_SHARE_IRQ
  76. #define SERIAL8250_SHARE_IRQS 1
  77. #else
  78. #define SERIAL8250_SHARE_IRQS 0
  79. #endif
  80. #define SERIAL8250_PORT_FLAGS(_base, _irq, _flags) \
  81. { \
  82. .iobase = _base, \
  83. .irq = _irq, \
  84. .uartclk = 1843200, \
  85. .iotype = UPIO_PORT, \
  86. .flags = UPF_BOOT_AUTOCONF | (_flags), \
  87. }
  88. #define SERIAL8250_PORT(_base, _irq) SERIAL8250_PORT_FLAGS(_base, _irq, 0)
  89. static inline int serial_in(struct uart_8250_port *up, int offset)
  90. {
  91. return up->port.serial_in(&up->port, offset);
  92. }
  93. static inline void serial_out(struct uart_8250_port *up, int offset, int value)
  94. {
  95. up->port.serial_out(&up->port, offset, value);
  96. }
  97. void serial8250_clear_and_reinit_fifos(struct uart_8250_port *p);
  98. static inline int serial_dl_read(struct uart_8250_port *up)
  99. {
  100. return up->dl_read(up);
  101. }
  102. static inline void serial_dl_write(struct uart_8250_port *up, int value)
  103. {
  104. up->dl_write(up, value);
  105. }
  106. struct uart_8250_port *serial8250_get_port(int line);
  107. void serial8250_rpm_get(struct uart_8250_port *p);
  108. void serial8250_rpm_put(struct uart_8250_port *p);
  109. void serial8250_rpm_get_tx(struct uart_8250_port *p);
  110. void serial8250_rpm_put_tx(struct uart_8250_port *p);
  111. int serial8250_em485_init(struct uart_8250_port *p);
  112. void serial8250_em485_destroy(struct uart_8250_port *p);
  113. static inline void serial8250_out_MCR(struct uart_8250_port *up, int value)
  114. {
  115. serial_out(up, UART_MCR, value);
  116. }
  117. static inline int serial8250_in_MCR(struct uart_8250_port *up)
  118. {
  119. return serial_in(up, UART_MCR);
  120. }
  121. #if defined(__alpha__) && !defined(CONFIG_PCI)
  122. /*
  123. * Digital did something really horribly wrong with the OUT1 and OUT2
  124. * lines on at least some ALPHA's. The failure mode is that if either
  125. * is cleared, the machine locks up with endless interrupts.
  126. */
  127. #define ALPHA_KLUDGE_MCR (UART_MCR_OUT2 | UART_MCR_OUT1)
  128. #else
  129. #define ALPHA_KLUDGE_MCR 0
  130. #endif
  131. #ifdef CONFIG_SERIAL_8250_PNP
  132. int serial8250_pnp_init(void);
  133. void serial8250_pnp_exit(void);
  134. #else
  135. static inline int serial8250_pnp_init(void) { return 0; }
  136. static inline void serial8250_pnp_exit(void) { }
  137. #endif
  138. #ifdef CONFIG_SERIAL_8250_FINTEK
  139. int fintek_8250_probe(struct uart_8250_port *uart);
  140. #else
  141. static inline int fintek_8250_probe(struct uart_8250_port *uart) { return 0; }
  142. #endif
  143. #ifdef CONFIG_ARCH_OMAP1
  144. static inline int is_omap1_8250(struct uart_8250_port *pt)
  145. {
  146. int res;
  147. switch (pt->port.mapbase) {
  148. case OMAP1_UART1_BASE:
  149. case OMAP1_UART2_BASE:
  150. case OMAP1_UART3_BASE:
  151. res = 1;
  152. break;
  153. default:
  154. res = 0;
  155. break;
  156. }
  157. return res;
  158. }
  159. static inline int is_omap1510_8250(struct uart_8250_port *pt)
  160. {
  161. if (!cpu_is_omap1510())
  162. return 0;
  163. return is_omap1_8250(pt);
  164. }
  165. #else
  166. static inline int is_omap1_8250(struct uart_8250_port *pt)
  167. {
  168. return 0;
  169. }
  170. static inline int is_omap1510_8250(struct uart_8250_port *pt)
  171. {
  172. return 0;
  173. }
  174. #endif
  175. #ifdef CONFIG_SERIAL_8250_DMA
  176. extern int serial8250_tx_dma(struct uart_8250_port *);
  177. extern int serial8250_rx_dma(struct uart_8250_port *);
  178. extern void serial8250_rx_dma_flush(struct uart_8250_port *);
  179. extern int serial8250_request_dma(struct uart_8250_port *);
  180. extern void serial8250_release_dma(struct uart_8250_port *);
  181. #else
  182. static inline int serial8250_tx_dma(struct uart_8250_port *p)
  183. {
  184. return -1;
  185. }
  186. static inline int serial8250_rx_dma(struct uart_8250_port *p)
  187. {
  188. return -1;
  189. }
  190. static inline void serial8250_rx_dma_flush(struct uart_8250_port *p) { }
  191. static inline int serial8250_request_dma(struct uart_8250_port *p)
  192. {
  193. return -1;
  194. }
  195. static inline void serial8250_release_dma(struct uart_8250_port *p) { }
  196. #endif
  197. static inline int ns16550a_goto_highspeed(struct uart_8250_port *up)
  198. {
  199. unsigned char status;
  200. status = serial_in(up, 0x04); /* EXCR2 */
  201. #define PRESL(x) ((x) & 0x30)
  202. if (PRESL(status) == 0x10) {
  203. /* already in high speed mode */
  204. return 0;
  205. } else {
  206. status &= ~0xB0; /* Disable LOCK, mask out PRESL[01] */
  207. status |= 0x10; /* 1.625 divisor for baud_base --> 921600 */
  208. serial_out(up, 0x04, status);
  209. }
  210. return 1;
  211. }
  212. static inline int serial_index(struct uart_port *port)
  213. {
  214. return port->minor - 64;
  215. }