serial_8250.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * linux/include/linux/serial_8250.h
  4. *
  5. * Copyright (C) 2004 Russell King
  6. */
  7. #ifndef _LINUX_SERIAL_8250_H
  8. #define _LINUX_SERIAL_8250_H
  9. #include <linux/serial_core.h>
  10. #include <linux/serial_reg.h>
  11. #include <linux/platform_device.h>
  12. /*
  13. * This is the platform device platform_data structure
  14. */
  15. struct plat_serial8250_port {
  16. unsigned long iobase; /* io base address */
  17. void __iomem *membase; /* ioremap cookie or NULL */
  18. resource_size_t mapbase; /* resource base */
  19. unsigned int irq; /* interrupt number */
  20. unsigned long irqflags; /* request_irq flags */
  21. unsigned int uartclk; /* UART clock rate */
  22. void *private_data;
  23. unsigned char regshift; /* register shift */
  24. unsigned char iotype; /* UPIO_* */
  25. unsigned char hub6;
  26. unsigned char has_sysrq; /* supports magic SysRq */
  27. upf_t flags; /* UPF_* flags */
  28. unsigned int type; /* If UPF_FIXED_TYPE */
  29. unsigned int (*serial_in)(struct uart_port *, int);
  30. void (*serial_out)(struct uart_port *, int, int);
  31. void (*set_termios)(struct uart_port *,
  32. struct ktermios *new,
  33. struct ktermios *old);
  34. void (*set_ldisc)(struct uart_port *,
  35. struct ktermios *);
  36. unsigned int (*get_mctrl)(struct uart_port *);
  37. int (*handle_irq)(struct uart_port *);
  38. void (*pm)(struct uart_port *, unsigned int state,
  39. unsigned old);
  40. void (*handle_break)(struct uart_port *);
  41. };
  42. /*
  43. * Allocate 8250 platform device IDs. Nothing is implied by
  44. * the numbering here, except for the legacy entry being -1.
  45. */
  46. enum {
  47. PLAT8250_DEV_LEGACY = -1,
  48. PLAT8250_DEV_PLATFORM,
  49. PLAT8250_DEV_PLATFORM1,
  50. PLAT8250_DEV_PLATFORM2,
  51. PLAT8250_DEV_FOURPORT,
  52. PLAT8250_DEV_ACCENT,
  53. PLAT8250_DEV_BOCA,
  54. PLAT8250_DEV_EXAR_ST16C554,
  55. PLAT8250_DEV_HUB6,
  56. PLAT8250_DEV_AU1X00,
  57. PLAT8250_DEV_SM501,
  58. };
  59. struct uart_8250_dma;
  60. struct uart_8250_port;
  61. /**
  62. * 8250 core driver operations
  63. *
  64. * @setup_irq() Setup irq handling. The universal 8250 driver links this
  65. * port to the irq chain. Other drivers may @request_irq().
  66. * @release_irq() Undo irq handling. The universal 8250 driver unlinks
  67. * the port from the irq chain.
  68. */
  69. struct uart_8250_ops {
  70. int (*setup_irq)(struct uart_8250_port *);
  71. void (*release_irq)(struct uart_8250_port *);
  72. };
  73. struct uart_8250_em485 {
  74. struct hrtimer start_tx_timer; /* "rs485 start tx" timer */
  75. struct hrtimer stop_tx_timer; /* "rs485 stop tx" timer */
  76. struct hrtimer *active_timer; /* pointer to active timer */
  77. struct uart_8250_port *port; /* for hrtimer callbacks */
  78. unsigned int tx_stopped:1; /* tx is currently stopped */
  79. };
  80. /*
  81. * This should be used by drivers which want to register
  82. * their own 8250 ports without registering their own
  83. * platform device. Using these will make your driver
  84. * dependent on the 8250 driver.
  85. */
  86. struct uart_8250_port {
  87. struct uart_port port;
  88. struct timer_list timer; /* "no irq" timer */
  89. struct list_head list; /* ports on this IRQ */
  90. u32 capabilities; /* port capabilities */
  91. unsigned short bugs; /* port bugs */
  92. bool fifo_bug; /* min RX trigger if enabled */
  93. unsigned int tx_loadsz; /* transmit fifo load size */
  94. unsigned char acr;
  95. unsigned char fcr;
  96. unsigned char ier;
  97. unsigned char lcr;
  98. unsigned char mcr;
  99. unsigned char mcr_mask; /* mask of user bits */
  100. unsigned char mcr_force; /* mask of forced bits */
  101. unsigned char cur_iotype; /* Running I/O type */
  102. unsigned int rpm_tx_active;
  103. unsigned char canary; /* non-zero during system sleep
  104. * if no_console_suspend
  105. */
  106. unsigned char probe;
  107. struct mctrl_gpios *gpios;
  108. #define UART_PROBE_RSA (1 << 0)
  109. /*
  110. * Some bits in registers are cleared on a read, so they must
  111. * be saved whenever the register is read but the bits will not
  112. * be immediately processed.
  113. */
  114. #define LSR_SAVE_FLAGS UART_LSR_BRK_ERROR_BITS
  115. unsigned char lsr_saved_flags;
  116. #define MSR_SAVE_FLAGS UART_MSR_ANY_DELTA
  117. unsigned char msr_saved_flags;
  118. struct uart_8250_dma *dma;
  119. const struct uart_8250_ops *ops;
  120. /* 8250 specific callbacks */
  121. int (*dl_read)(struct uart_8250_port *);
  122. void (*dl_write)(struct uart_8250_port *, int);
  123. struct uart_8250_em485 *em485;
  124. void (*rs485_start_tx)(struct uart_8250_port *);
  125. void (*rs485_stop_tx)(struct uart_8250_port *);
  126. /* Serial port overrun backoff */
  127. struct delayed_work overrun_backoff;
  128. u32 overrun_backoff_time_ms;
  129. };
  130. static inline struct uart_8250_port *up_to_u8250p(struct uart_port *up)
  131. {
  132. return container_of(up, struct uart_8250_port, port);
  133. }
  134. int serial8250_register_8250_port(struct uart_8250_port *);
  135. void serial8250_unregister_port(int line);
  136. void serial8250_suspend_port(int line);
  137. void serial8250_resume_port(int line);
  138. extern int early_serial_setup(struct uart_port *port);
  139. extern int early_serial8250_setup(struct earlycon_device *device,
  140. const char *options);
  141. extern void serial8250_update_uartclk(struct uart_port *port,
  142. unsigned int uartclk);
  143. extern void serial8250_do_set_termios(struct uart_port *port,
  144. struct ktermios *termios, struct ktermios *old);
  145. extern void serial8250_do_set_ldisc(struct uart_port *port,
  146. struct ktermios *termios);
  147. extern unsigned int serial8250_do_get_mctrl(struct uart_port *port);
  148. extern int serial8250_do_startup(struct uart_port *port);
  149. extern void serial8250_do_shutdown(struct uart_port *port);
  150. extern void serial8250_do_pm(struct uart_port *port, unsigned int state,
  151. unsigned int oldstate);
  152. extern void serial8250_do_set_mctrl(struct uart_port *port, unsigned int mctrl);
  153. extern void serial8250_do_set_divisor(struct uart_port *port, unsigned int baud,
  154. unsigned int quot,
  155. unsigned int quot_frac);
  156. extern int fsl8250_handle_irq(struct uart_port *port);
  157. int serial8250_handle_irq(struct uart_port *port, unsigned int iir);
  158. unsigned char serial8250_rx_chars(struct uart_8250_port *up, unsigned char lsr);
  159. void serial8250_read_char(struct uart_8250_port *up, unsigned char lsr);
  160. void serial8250_tx_chars(struct uart_8250_port *up);
  161. unsigned int serial8250_modem_status(struct uart_8250_port *up);
  162. void serial8250_init_port(struct uart_8250_port *up);
  163. void serial8250_set_defaults(struct uart_8250_port *up);
  164. void serial8250_console_write(struct uart_8250_port *up, const char *s,
  165. unsigned int count);
  166. int serial8250_console_setup(struct uart_port *port, char *options, bool probe);
  167. int serial8250_console_exit(struct uart_port *port);
  168. extern void serial8250_set_isa_configurator(void (*v)
  169. (int port, struct uart_port *up,
  170. u32 *capabilities));
  171. #endif