18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  linux/include/linux/serial_8250.h
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci *  Copyright (C) 2004 Russell King
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci#ifndef _LINUX_SERIAL_8250_H
88c2ecf20Sopenharmony_ci#define _LINUX_SERIAL_8250_H
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#include <linux/serial_core.h>
118c2ecf20Sopenharmony_ci#include <linux/serial_reg.h>
128c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ci/*
158c2ecf20Sopenharmony_ci * This is the platform device platform_data structure
168c2ecf20Sopenharmony_ci */
178c2ecf20Sopenharmony_cistruct plat_serial8250_port {
188c2ecf20Sopenharmony_ci	unsigned long	iobase;		/* io base address */
198c2ecf20Sopenharmony_ci	void __iomem	*membase;	/* ioremap cookie or NULL */
208c2ecf20Sopenharmony_ci	resource_size_t	mapbase;	/* resource base */
218c2ecf20Sopenharmony_ci	unsigned int	irq;		/* interrupt number */
228c2ecf20Sopenharmony_ci	unsigned long	irqflags;	/* request_irq flags */
238c2ecf20Sopenharmony_ci	unsigned int	uartclk;	/* UART clock rate */
248c2ecf20Sopenharmony_ci	void            *private_data;
258c2ecf20Sopenharmony_ci	unsigned char	regshift;	/* register shift */
268c2ecf20Sopenharmony_ci	unsigned char	iotype;		/* UPIO_* */
278c2ecf20Sopenharmony_ci	unsigned char	hub6;
288c2ecf20Sopenharmony_ci	unsigned char	has_sysrq;	/* supports magic SysRq */
298c2ecf20Sopenharmony_ci	upf_t		flags;		/* UPF_* flags */
308c2ecf20Sopenharmony_ci	unsigned int	type;		/* If UPF_FIXED_TYPE */
318c2ecf20Sopenharmony_ci	unsigned int	(*serial_in)(struct uart_port *, int);
328c2ecf20Sopenharmony_ci	void		(*serial_out)(struct uart_port *, int, int);
338c2ecf20Sopenharmony_ci	void		(*set_termios)(struct uart_port *,
348c2ecf20Sopenharmony_ci			               struct ktermios *new,
358c2ecf20Sopenharmony_ci			               struct ktermios *old);
368c2ecf20Sopenharmony_ci	void		(*set_ldisc)(struct uart_port *,
378c2ecf20Sopenharmony_ci				     struct ktermios *);
388c2ecf20Sopenharmony_ci	unsigned int	(*get_mctrl)(struct uart_port *);
398c2ecf20Sopenharmony_ci	int		(*handle_irq)(struct uart_port *);
408c2ecf20Sopenharmony_ci	void		(*pm)(struct uart_port *, unsigned int state,
418c2ecf20Sopenharmony_ci			      unsigned old);
428c2ecf20Sopenharmony_ci	void		(*handle_break)(struct uart_port *);
438c2ecf20Sopenharmony_ci};
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci/*
468c2ecf20Sopenharmony_ci * Allocate 8250 platform device IDs.  Nothing is implied by
478c2ecf20Sopenharmony_ci * the numbering here, except for the legacy entry being -1.
488c2ecf20Sopenharmony_ci */
498c2ecf20Sopenharmony_cienum {
508c2ecf20Sopenharmony_ci	PLAT8250_DEV_LEGACY = -1,
518c2ecf20Sopenharmony_ci	PLAT8250_DEV_PLATFORM,
528c2ecf20Sopenharmony_ci	PLAT8250_DEV_PLATFORM1,
538c2ecf20Sopenharmony_ci	PLAT8250_DEV_PLATFORM2,
548c2ecf20Sopenharmony_ci	PLAT8250_DEV_FOURPORT,
558c2ecf20Sopenharmony_ci	PLAT8250_DEV_ACCENT,
568c2ecf20Sopenharmony_ci	PLAT8250_DEV_BOCA,
578c2ecf20Sopenharmony_ci	PLAT8250_DEV_EXAR_ST16C554,
588c2ecf20Sopenharmony_ci	PLAT8250_DEV_HUB6,
598c2ecf20Sopenharmony_ci	PLAT8250_DEV_AU1X00,
608c2ecf20Sopenharmony_ci	PLAT8250_DEV_SM501,
618c2ecf20Sopenharmony_ci};
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_cistruct uart_8250_dma;
648c2ecf20Sopenharmony_cistruct uart_8250_port;
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci/**
678c2ecf20Sopenharmony_ci * 8250 core driver operations
688c2ecf20Sopenharmony_ci *
698c2ecf20Sopenharmony_ci * @setup_irq()		Setup irq handling. The universal 8250 driver links this
708c2ecf20Sopenharmony_ci *			port to the irq chain. Other drivers may @request_irq().
718c2ecf20Sopenharmony_ci * @release_irq()	Undo irq handling. The universal 8250 driver unlinks
728c2ecf20Sopenharmony_ci *			the port from the irq chain.
738c2ecf20Sopenharmony_ci */
748c2ecf20Sopenharmony_cistruct uart_8250_ops {
758c2ecf20Sopenharmony_ci	int		(*setup_irq)(struct uart_8250_port *);
768c2ecf20Sopenharmony_ci	void		(*release_irq)(struct uart_8250_port *);
778c2ecf20Sopenharmony_ci	void		(*setup_timer)(struct uart_8250_port *);
788c2ecf20Sopenharmony_ci};
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_cistruct uart_8250_em485 {
818c2ecf20Sopenharmony_ci	struct hrtimer		start_tx_timer; /* "rs485 start tx" timer */
828c2ecf20Sopenharmony_ci	struct hrtimer		stop_tx_timer;  /* "rs485 stop tx" timer */
838c2ecf20Sopenharmony_ci	struct hrtimer		*active_timer;  /* pointer to active timer */
848c2ecf20Sopenharmony_ci	struct uart_8250_port	*port;          /* for hrtimer callbacks */
858c2ecf20Sopenharmony_ci	unsigned int		tx_stopped:1;	/* tx is currently stopped */
868c2ecf20Sopenharmony_ci};
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci/*
898c2ecf20Sopenharmony_ci * This should be used by drivers which want to register
908c2ecf20Sopenharmony_ci * their own 8250 ports without registering their own
918c2ecf20Sopenharmony_ci * platform device.  Using these will make your driver
928c2ecf20Sopenharmony_ci * dependent on the 8250 driver.
938c2ecf20Sopenharmony_ci */
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_cistruct uart_8250_port {
968c2ecf20Sopenharmony_ci	struct uart_port	port;
978c2ecf20Sopenharmony_ci	struct timer_list	timer;		/* "no irq" timer */
988c2ecf20Sopenharmony_ci	struct list_head	list;		/* ports on this IRQ */
998c2ecf20Sopenharmony_ci	u32			capabilities;	/* port capabilities */
1008c2ecf20Sopenharmony_ci	unsigned short		bugs;		/* port bugs */
1018c2ecf20Sopenharmony_ci	unsigned int		tx_loadsz;	/* transmit fifo load size */
1028c2ecf20Sopenharmony_ci	unsigned char		acr;
1038c2ecf20Sopenharmony_ci	unsigned char		fcr;
1048c2ecf20Sopenharmony_ci	unsigned char		ier;
1058c2ecf20Sopenharmony_ci	unsigned char		lcr;
1068c2ecf20Sopenharmony_ci	unsigned char		mcr;
1078c2ecf20Sopenharmony_ci	unsigned char		mcr_mask;	/* mask of user bits */
1088c2ecf20Sopenharmony_ci	unsigned char		mcr_force;	/* mask of forced bits */
1098c2ecf20Sopenharmony_ci	unsigned char		cur_iotype;	/* Running I/O type */
1108c2ecf20Sopenharmony_ci	unsigned int		rpm_tx_active;
1118c2ecf20Sopenharmony_ci	unsigned char		canary;		/* non-zero during system sleep
1128c2ecf20Sopenharmony_ci						 *   if no_console_suspend
1138c2ecf20Sopenharmony_ci						 */
1148c2ecf20Sopenharmony_ci	unsigned char		probe;
1158c2ecf20Sopenharmony_ci	struct mctrl_gpios	*gpios;
1168c2ecf20Sopenharmony_ci#define UART_PROBE_RSA	(1 << 0)
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_ci	/*
1198c2ecf20Sopenharmony_ci	 * Some bits in registers are cleared on a read, so they must
1208c2ecf20Sopenharmony_ci	 * be saved whenever the register is read but the bits will not
1218c2ecf20Sopenharmony_ci	 * be immediately processed.
1228c2ecf20Sopenharmony_ci	 */
1238c2ecf20Sopenharmony_ci#define LSR_SAVE_FLAGS UART_LSR_BRK_ERROR_BITS
1248c2ecf20Sopenharmony_ci	unsigned char		lsr_saved_flags;
1258c2ecf20Sopenharmony_ci#define MSR_SAVE_FLAGS UART_MSR_ANY_DELTA
1268c2ecf20Sopenharmony_ci	unsigned char		msr_saved_flags;
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci	struct uart_8250_dma	*dma;
1298c2ecf20Sopenharmony_ci	const struct uart_8250_ops *ops;
1308c2ecf20Sopenharmony_ci
1318c2ecf20Sopenharmony_ci	/* 8250 specific callbacks */
1328c2ecf20Sopenharmony_ci	int			(*dl_read)(struct uart_8250_port *);
1338c2ecf20Sopenharmony_ci	void			(*dl_write)(struct uart_8250_port *, int);
1348c2ecf20Sopenharmony_ci
1358c2ecf20Sopenharmony_ci	struct uart_8250_em485 *em485;
1368c2ecf20Sopenharmony_ci	void			(*rs485_start_tx)(struct uart_8250_port *);
1378c2ecf20Sopenharmony_ci	void			(*rs485_stop_tx)(struct uart_8250_port *);
1388c2ecf20Sopenharmony_ci
1398c2ecf20Sopenharmony_ci	/* Serial port overrun backoff */
1408c2ecf20Sopenharmony_ci	struct delayed_work overrun_backoff;
1418c2ecf20Sopenharmony_ci	u32 overrun_backoff_time_ms;
1428c2ecf20Sopenharmony_ci};
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_cistatic inline struct uart_8250_port *up_to_u8250p(struct uart_port *up)
1458c2ecf20Sopenharmony_ci{
1468c2ecf20Sopenharmony_ci	return container_of(up, struct uart_8250_port, port);
1478c2ecf20Sopenharmony_ci}
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ciint serial8250_register_8250_port(struct uart_8250_port *);
1508c2ecf20Sopenharmony_civoid serial8250_unregister_port(int line);
1518c2ecf20Sopenharmony_civoid serial8250_suspend_port(int line);
1528c2ecf20Sopenharmony_civoid serial8250_resume_port(int line);
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ciextern int early_serial_setup(struct uart_port *port);
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ciextern int early_serial8250_setup(struct earlycon_device *device,
1578c2ecf20Sopenharmony_ci					 const char *options);
1588c2ecf20Sopenharmony_ciextern void serial8250_update_uartclk(struct uart_port *port,
1598c2ecf20Sopenharmony_ci				      unsigned int uartclk);
1608c2ecf20Sopenharmony_ciextern void serial8250_do_set_termios(struct uart_port *port,
1618c2ecf20Sopenharmony_ci		struct ktermios *termios, struct ktermios *old);
1628c2ecf20Sopenharmony_ciextern void serial8250_do_set_ldisc(struct uart_port *port,
1638c2ecf20Sopenharmony_ci				    struct ktermios *termios);
1648c2ecf20Sopenharmony_ciextern unsigned int serial8250_do_get_mctrl(struct uart_port *port);
1658c2ecf20Sopenharmony_ciextern int serial8250_do_startup(struct uart_port *port);
1668c2ecf20Sopenharmony_ciextern void serial8250_do_shutdown(struct uart_port *port);
1678c2ecf20Sopenharmony_ciextern void serial8250_do_pm(struct uart_port *port, unsigned int state,
1688c2ecf20Sopenharmony_ci			     unsigned int oldstate);
1698c2ecf20Sopenharmony_ciextern void serial8250_do_set_mctrl(struct uart_port *port, unsigned int mctrl);
1708c2ecf20Sopenharmony_ciextern void serial8250_do_set_divisor(struct uart_port *port, unsigned int baud,
1718c2ecf20Sopenharmony_ci				      unsigned int quot,
1728c2ecf20Sopenharmony_ci				      unsigned int quot_frac);
1738c2ecf20Sopenharmony_ciextern int fsl8250_handle_irq(struct uart_port *port);
1748c2ecf20Sopenharmony_ciint serial8250_handle_irq(struct uart_port *port, unsigned int iir);
1758c2ecf20Sopenharmony_ciunsigned char serial8250_rx_chars(struct uart_8250_port *up, unsigned char lsr);
1768c2ecf20Sopenharmony_civoid serial8250_read_char(struct uart_8250_port *up, unsigned char lsr);
1778c2ecf20Sopenharmony_civoid serial8250_tx_chars(struct uart_8250_port *up);
1788c2ecf20Sopenharmony_ciunsigned int serial8250_modem_status(struct uart_8250_port *up);
1798c2ecf20Sopenharmony_civoid serial8250_init_port(struct uart_8250_port *up);
1808c2ecf20Sopenharmony_civoid serial8250_set_defaults(struct uart_8250_port *up);
1818c2ecf20Sopenharmony_civoid serial8250_console_write(struct uart_8250_port *up, const char *s,
1828c2ecf20Sopenharmony_ci			      unsigned int count);
1838c2ecf20Sopenharmony_ciint serial8250_console_setup(struct uart_port *port, char *options, bool probe);
1848c2ecf20Sopenharmony_ciint serial8250_console_exit(struct uart_port *port);
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_ciextern void serial8250_set_isa_configurator(void (*v)
1878c2ecf20Sopenharmony_ci					(int port, struct uart_port *up,
1888c2ecf20Sopenharmony_ci						u32 *capabilities));
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_ci#endif
191