1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * linux/include/linux/serial_8250.h
5 * Copyright (C) 2004 Russell King
7 #ifndef _LINUX_SERIAL_8250_H
8 #define _LINUX_SERIAL_8250_H
10 #include <linux/errno.h>
11 #include <linux/serial_core.h>
12 #include <linux/serial_reg.h>
13 #include <linux/platform_device.h>
15 struct uart_8250_port;
18 * This is the platform device platform_data structure
20 * @mapsize: Port size for ioremap()
23 * @dl_read: ``u32 ()(struct uart_8250_port *up)``
25 * UART divisor latch read.
27 * @dl_write: ``void ()(struct uart_8250_port *up, u32 value)``
29 * Write @value into UART divisor latch.
31 * Locking: Caller holds port's lock.
33 struct plat_serial8250_port {
34 unsigned long iobase; /* io base address */
35 void __iomem *membase; /* ioremap cookie or NULL */
36 resource_size_t mapbase; /* resource base */
37 resource_size_t mapsize;
38 unsigned int uartclk; /* UART clock rate */
39 unsigned int irq; /* interrupt number */
40 unsigned long irqflags; /* request_irq flags */
42 unsigned char regshift; /* register shift */
43 unsigned char iotype; /* UPIO_* */
45 unsigned char has_sysrq; /* supports magic SysRq */
46 unsigned int type; /* If UPF_FIXED_TYPE */
47 upf_t flags; /* UPF_* flags */
48 u16 bugs; /* port bugs */
49 unsigned int (*serial_in)(struct uart_port *, int);
50 void (*serial_out)(struct uart_port *, int, int);
51 u32 (*dl_read)(struct uart_8250_port *up);
52 void (*dl_write)(struct uart_8250_port *up, u32 value);
53 void (*set_termios)(struct uart_port *,
55 const struct ktermios *old);
56 void (*set_ldisc)(struct uart_port *,
58 unsigned int (*get_mctrl)(struct uart_port *);
59 int (*handle_irq)(struct uart_port *);
60 void (*pm)(struct uart_port *, unsigned int state,
62 void (*handle_break)(struct uart_port *);
66 * Allocate 8250 platform device IDs. Nothing is implied by
67 * the numbering here, except for the legacy entry being -1.
70 PLAT8250_DEV_LEGACY = -1,
71 PLAT8250_DEV_PLATFORM,
72 PLAT8250_DEV_PLATFORM1,
73 PLAT8250_DEV_PLATFORM2,
74 PLAT8250_DEV_FOURPORT,
77 PLAT8250_DEV_EXAR_ST16C554,
84 struct uart_8250_port;
87 * 8250 core driver operations
89 * @setup_irq() Setup irq handling. The universal 8250 driver links this
90 * port to the irq chain. Other drivers may @request_irq().
91 * @release_irq() Undo irq handling. The universal 8250 driver unlinks
92 * the port from the irq chain.
94 struct uart_8250_ops {
95 int (*setup_irq)(struct uart_8250_port *);
96 void (*release_irq)(struct uart_8250_port *);
97 void (*setup_timer)(struct uart_8250_port *);
100 struct uart_8250_em485 {
101 struct hrtimer start_tx_timer; /* "rs485 start tx" timer */
102 struct hrtimer stop_tx_timer; /* "rs485 stop tx" timer */
103 struct hrtimer *active_timer; /* pointer to active timer */
104 struct uart_8250_port *port; /* for hrtimer callbacks */
105 unsigned int tx_stopped:1; /* tx is currently stopped */
109 * This should be used by drivers which want to register
110 * their own 8250 ports without registering their own
111 * platform device. Using these will make your driver
112 * dependent on the 8250 driver.
114 * @dl_read: ``u32 ()(struct uart_8250_port *port)``
116 * UART divisor latch read.
118 * @dl_write: ``void ()(struct uart_8250_port *port, u32 value)``
120 * Write @value into UART divisor latch.
122 * Locking: Caller holds port's lock.
124 struct uart_8250_port {
125 struct uart_port port;
126 struct timer_list timer; /* "no irq" timer */
127 struct list_head list; /* ports on this IRQ */
128 u32 capabilities; /* port capabilities */
129 u16 bugs; /* port bugs */
130 unsigned int tx_loadsz; /* transmit fifo load size */
136 unsigned char cur_iotype; /* Running I/O type */
137 unsigned int rpm_tx_active;
138 unsigned char canary; /* non-zero during system sleep
139 * if no_console_suspend
142 struct mctrl_gpios *gpios;
143 #define UART_PROBE_RSA (1 << 0)
146 * Some bits in registers are cleared on a read, so they must
147 * be saved whenever the register is read but the bits will not
148 * be immediately processed.
150 #define LSR_SAVE_FLAGS UART_LSR_BRK_ERROR_BITS
153 #define MSR_SAVE_FLAGS UART_MSR_ANY_DELTA
154 unsigned char msr_saved_flags;
156 struct uart_8250_dma *dma;
157 const struct uart_8250_ops *ops;
159 /* 8250 specific callbacks */
160 u32 (*dl_read)(struct uart_8250_port *up);
161 void (*dl_write)(struct uart_8250_port *up, u32 value);
163 struct uart_8250_em485 *em485;
164 void (*rs485_start_tx)(struct uart_8250_port *);
165 void (*rs485_stop_tx)(struct uart_8250_port *);
167 /* Serial port overrun backoff */
168 struct delayed_work overrun_backoff;
169 u32 overrun_backoff_time_ms;
172 static inline struct uart_8250_port *up_to_u8250p(struct uart_port *up)
174 return container_of(up, struct uart_8250_port, port);
177 int serial8250_register_8250_port(const struct uart_8250_port *);
178 void serial8250_unregister_port(int line);
179 void serial8250_suspend_port(int line);
180 void serial8250_resume_port(int line);
182 int early_serial_setup(struct uart_port *port);
183 int early_serial8250_setup(struct earlycon_device *device, const char *options);
185 void serial8250_update_uartclk(struct uart_port *port, unsigned int uartclk);
186 void serial8250_do_set_termios(struct uart_port *port, struct ktermios *termios,
187 const struct ktermios *old);
188 void serial8250_do_set_ldisc(struct uart_port *port, struct ktermios *termios);
189 unsigned int serial8250_do_get_mctrl(struct uart_port *port);
190 int serial8250_do_startup(struct uart_port *port);
191 void serial8250_do_shutdown(struct uart_port *port);
192 void serial8250_do_pm(struct uart_port *port, unsigned int state,
193 unsigned int oldstate);
194 void serial8250_do_set_mctrl(struct uart_port *port, unsigned int mctrl);
195 void serial8250_do_set_divisor(struct uart_port *port, unsigned int baud,
196 unsigned int quot, unsigned int quot_frac);
197 int fsl8250_handle_irq(struct uart_port *port);
198 int serial8250_handle_irq(struct uart_port *port, unsigned int iir);
199 u16 serial8250_rx_chars(struct uart_8250_port *up, u16 lsr);
200 void serial8250_read_char(struct uart_8250_port *up, u16 lsr);
201 void serial8250_tx_chars(struct uart_8250_port *up);
202 unsigned int serial8250_modem_status(struct uart_8250_port *up);
203 void serial8250_init_port(struct uart_8250_port *up);
204 void serial8250_set_defaults(struct uart_8250_port *up);
205 void serial8250_console_write(struct uart_8250_port *up, const char *s,
207 int serial8250_console_setup(struct uart_port *port, char *options, bool probe);
208 int serial8250_console_exit(struct uart_port *port);
210 void serial8250_set_isa_configurator(void (*v)(int port, struct uart_port *up,
213 #ifdef CONFIG_SERIAL_8250_RT288X
214 int rt288x_setup(struct uart_port *p);
215 int au_platform_setup(struct plat_serial8250_port *p);
217 static inline int rt288x_setup(struct uart_port *p) { return -ENODEV; }
218 static inline int au_platform_setup(struct plat_serial8250_port *p) { return -ENODEV; }