linux/drivers/tty/serial/fsl_lpuart.c

// SPDX-License-Identifier: GPL-2.0+
/*
 *  Freescale lpuart serial port driver
 *
 *  Copyright 2012-2014 Freescale Semiconductor, Inc.
 */

#include <linux/bitfield.h>
#include <linux/bits.h>
#include <linux/circ_buf.h>
#include <linux/clk.h>
#include <linux/console.h>
#include <linux/delay.h>
#include <linux/dma-mapping.h>
#include <linux/dmaengine.h>
#include <linux/dmapool.h>
#include <linux/io.h>
#include <linux/iopoll.h>
#include <linux/irq.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/of_dma.h>
#include <linux/pinctrl/consumer.h>
#include <linux/platform_device.h>
#include <linux/pm_runtime.h>
#include <linux/serial_core.h>
#include <linux/slab.h>
#include <linux/tty_flip.h>

/* All registers are 8-bit width */
#define UARTBDH
#define UARTBDL
#define UARTCR1
#define UARTCR2
#define UARTSR1
#define UARTCR3
#define UARTDR
#define UARTCR4
#define UARTCR5
#define UARTMODEM
#define UARTPFIFO
#define UARTCFIFO
#define UARTSFIFO
#define UARTTWFIFO
#define UARTTCFIFO
#define UARTRWFIFO

#define UARTBDH_LBKDIE
#define UARTBDH_RXEDGIE
#define UARTBDH_SBR_MASK

#define UARTCR1_LOOPS
#define UARTCR1_RSRC
#define UARTCR1_M
#define UARTCR1_WAKE
#define UARTCR1_ILT
#define UARTCR1_PE
#define UARTCR1_PT

#define UARTCR2_TIE
#define UARTCR2_TCIE
#define UARTCR2_RIE
#define UARTCR2_ILIE
#define UARTCR2_TE
#define UARTCR2_RE
#define UARTCR2_RWU
#define UARTCR2_SBK

#define UARTSR1_TDRE
#define UARTSR1_TC
#define UARTSR1_RDRF
#define UARTSR1_IDLE
#define UARTSR1_OR
#define UARTSR1_NF
#define UARTSR1_FE
#define UARTSR1_PE

#define UARTCR3_R8
#define UARTCR3_T8
#define UARTCR3_TXDIR
#define UARTCR3_TXINV
#define UARTCR3_ORIE
#define UARTCR3_NEIE
#define UARTCR3_FEIE
#define UARTCR3_PEIE

#define UARTCR4_MAEN1
#define UARTCR4_MAEN2
#define UARTCR4_M10
#define UARTCR4_BRFA_MASK
#define UARTCR4_BRFA_OFF

#define UARTCR5_TDMAS
#define UARTCR5_RDMAS

#define UARTMODEM_RXRTSE
#define UARTMODEM_TXRTSPOL
#define UARTMODEM_TXRTSE
#define UARTMODEM_TXCTSE

#define UARTPFIFO_TXFE
#define UARTPFIFO_FIFOSIZE_MASK
#define UARTPFIFO_TXSIZE_OFF
#define UARTPFIFO_RXFE
#define UARTPFIFO_RXSIZE_OFF

#define UARTCFIFO_TXFLUSH
#define UARTCFIFO_RXFLUSH
#define UARTCFIFO_RXOFE
#define UARTCFIFO_TXOFE
#define UARTCFIFO_RXUFE

#define UARTSFIFO_TXEMPT
#define UARTSFIFO_RXEMPT
#define UARTSFIFO_RXOF
#define UARTSFIFO_TXOF
#define UARTSFIFO_RXUF

/* 32-bit global registers only for i.MX7ULP/i.MX8x
 * Used to reset all internal logic and registers, except the Global Register.
 */
#define UART_GLOBAL

/* 32-bit register definition */
#define UARTBAUD
#define UARTSTAT
#define UARTCTRL
#define UARTDATA
#define UARTMATCH
#define UARTMODIR
#define UARTFIFO
#define UARTWATER

#define UARTBAUD_MAEN1
#define UARTBAUD_MAEN2
#define UARTBAUD_M10
#define UARTBAUD_TDMAE
#define UARTBAUD_RDMAE
#define UARTBAUD_MATCFG
#define UARTBAUD_BOTHEDGE
#define UARTBAUD_RESYNCDIS
#define UARTBAUD_LBKDIE
#define UARTBAUD_RXEDGIE
#define UARTBAUD_SBNS
#define UARTBAUD_SBR
#define UARTBAUD_SBR_MASK
#define UARTBAUD_OSR_MASK
#define UARTBAUD_OSR_SHIFT

#define UARTSTAT_LBKDIF
#define UARTSTAT_RXEDGIF
#define UARTSTAT_MSBF
#define UARTSTAT_RXINV
#define UARTSTAT_RWUID
#define UARTSTAT_BRK13
#define UARTSTAT_LBKDE
#define UARTSTAT_RAF
#define UARTSTAT_TDRE
#define UARTSTAT_TC
#define UARTSTAT_RDRF
#define UARTSTAT_IDLE
#define UARTSTAT_OR
#define UARTSTAT_NF
#define UARTSTAT_FE
#define UARTSTAT_PE
#define UARTSTAT_MA1F
#define UARTSTAT_M21F

#define UARTCTRL_R8T9
#define UARTCTRL_R9T8
#define UARTCTRL_TXDIR
#define UARTCTRL_TXINV
#define UARTCTRL_ORIE
#define UARTCTRL_NEIE
#define UARTCTRL_FEIE
#define UARTCTRL_PEIE
#define UARTCTRL_TIE
#define UARTCTRL_TCIE
#define UARTCTRL_RIE
#define UARTCTRL_ILIE
#define UARTCTRL_TE
#define UARTCTRL_RE
#define UARTCTRL_RWU
#define UARTCTRL_SBK
#define UARTCTRL_MA1IE
#define UARTCTRL_MA2IE
#define UARTCTRL_IDLECFG
#define UARTCTRL_LOOPS
#define UARTCTRL_DOZEEN
#define UARTCTRL_RSRC
#define UARTCTRL_M
#define UARTCTRL_WAKE
#define UARTCTRL_ILT
#define UARTCTRL_PE
#define UARTCTRL_PT

#define UARTDATA_NOISY
#define UARTDATA_PARITYE
#define UARTDATA_FRETSC
#define UARTDATA_RXEMPT
#define UARTDATA_IDLINE
#define UARTDATA_MASK

#define UARTMODIR_IREN
#define UARTMODIR_RTSWATER
#define UARTMODIR_TXCTSSRC
#define UARTMODIR_TXCTSC
#define UARTMODIR_RXRTSE
#define UARTMODIR_TXRTSPOL
#define UARTMODIR_TXRTSE
#define UARTMODIR_TXCTSE

#define UARTFIFO_TXEMPT
#define UARTFIFO_RXEMPT
#define UARTFIFO_TXOF
#define UARTFIFO_RXUF
#define UARTFIFO_TXFLUSH
#define UARTFIFO_RXFLUSH
#define UARTFIFO_RXIDEN
#define UARTFIFO_TXOFE
#define UARTFIFO_RXUFE
#define UARTFIFO_TXFE
#define UARTFIFO_FIFOSIZE_MASK
#define UARTFIFO_TXSIZE_OFF
#define UARTFIFO_RXFE
#define UARTFIFO_RXSIZE_OFF
#define UARTFIFO_DEPTH(x)

#define UARTWATER_COUNT_MASK
#define UARTWATER_TXCNT_OFF
#define UARTWATER_RXCNT_OFF
#define UARTWATER_WATER_MASK
#define UARTWATER_TXWATER_OFF
#define UARTWATER_RXWATER_OFF

#define UART_GLOBAL_RST
#define GLOBAL_RST_MIN_US
#define GLOBAL_RST_MAX_US

/* Rx DMA timeout in ms, which is used to calculate Rx ring buffer size */
#define DMA_RX_TIMEOUT
#define DMA_RX_IDLE_CHARS
#define UART_AUTOSUSPEND_TIMEOUT

#define DRIVER_NAME
#define DEV_NAME
#define UART_NR

/* IMX lpuart has four extra unused regs located at the beginning */
#define IMX_REG_OFF

enum lpuart_type {};

struct lpuart_port {};

struct lpuart_soc_data {};

static const struct lpuart_soc_data vf_data =;

static const struct lpuart_soc_data ls1021a_data =;

static const struct lpuart_soc_data ls1028a_data =;

static struct lpuart_soc_data imx7ulp_data =;

static struct lpuart_soc_data imx8ulp_data =;

static struct lpuart_soc_data imx8qxp_data =;
static struct lpuart_soc_data imxrt1050_data =;

static const struct of_device_id lpuart_dt_ids[] =;
MODULE_DEVICE_TABLE(of, lpuart_dt_ids);

/* Forward declare this for the dma callbacks*/
static void lpuart_dma_tx_complete(void *arg);

static inline bool is_layerscape_lpuart(struct lpuart_port *sport)
{}

static inline bool is_imx7ulp_lpuart(struct lpuart_port *sport)
{}

static inline bool is_imx8ulp_lpuart(struct lpuart_port *sport)
{}

static inline bool is_imx8qxp_lpuart(struct lpuart_port *sport)
{}

static inline u32 lpuart32_read(struct uart_port *port, u32 off)
{}

static inline void lpuart32_write(struct uart_port *port, u32 val,
				  u32 off)
{}

static int __lpuart_enable_clks(struct lpuart_port *sport, bool is_en)
{}

static unsigned int lpuart_get_baud_clk_rate(struct lpuart_port *sport)
{}

#define lpuart_enable_clks(x)
#define lpuart_disable_clks(x)

static void lpuart_stop_tx(struct uart_port *port)
{}

static void lpuart32_stop_tx(struct uart_port *port)
{}

static void lpuart_stop_rx(struct uart_port *port)
{}

static void lpuart32_stop_rx(struct uart_port *port)
{}

static void lpuart_dma_tx(struct lpuart_port *sport)
{}

static bool lpuart_stopped_or_empty(struct uart_port *port)
{}

static void lpuart_dma_tx_complete(void *arg)
{}

static dma_addr_t lpuart_dma_datareg_addr(struct lpuart_port *sport)
{}

static int lpuart_dma_tx_request(struct uart_port *port)
{}

static bool lpuart_is_32(struct lpuart_port *sport)
{}

static void lpuart_flush_buffer(struct uart_port *port)
{}

static void lpuart_wait_bit_set(struct uart_port *port, unsigned int offset,
				u8 bit)
{}

static void lpuart32_wait_bit_set(struct uart_port *port, unsigned int offset,
				  u32 bit)
{}

#if defined(CONFIG_CONSOLE_POLL)

static int lpuart_poll_init(struct uart_port *port)
{}

static void lpuart_poll_put_char(struct uart_port *port, unsigned char c)
{}

static int lpuart_poll_get_char(struct uart_port *port)
{}

static int lpuart32_poll_init(struct uart_port *port)
{}

static void lpuart32_poll_put_char(struct uart_port *port, unsigned char c)
{}

static int lpuart32_poll_get_char(struct uart_port *port)
{}
#endif

static inline void lpuart_transmit_buffer(struct lpuart_port *sport)
{}

static inline void lpuart32_transmit_buffer(struct lpuart_port *sport)
{}

static void lpuart_start_tx(struct uart_port *port)
{}

static void lpuart32_start_tx(struct uart_port *port)
{}

static void
lpuart_uart_pm(struct uart_port *port, unsigned int state, unsigned int oldstate)
{}

/* return TIOCSER_TEMT when transmitter is not busy */
static unsigned int lpuart_tx_empty(struct uart_port *port)
{}

static unsigned int lpuart32_tx_empty(struct uart_port *port)
{}

static void lpuart_txint(struct lpuart_port *sport)
{}

static void lpuart_rxint(struct lpuart_port *sport)
{}

static void lpuart32_txint(struct lpuart_port *sport)
{}

static void lpuart32_rxint(struct lpuart_port *sport)
{}

static irqreturn_t lpuart_int(int irq, void *dev_id)
{}

static inline void lpuart_handle_sysrq_chars(struct uart_port *port,
					     unsigned char *p, int count)
{}

static void lpuart_handle_sysrq(struct lpuart_port *sport)
{}

static int lpuart_tty_insert_flip_string(struct tty_port *port,
	unsigned char *chars, size_t size, bool is_cs7)
{}

static void lpuart_copy_rx_to_tty(struct lpuart_port *sport)
{}

static void lpuart_dma_rx_complete(void *arg)
{}

static void lpuart32_dma_idleint(struct lpuart_port *sport)
{}

static irqreturn_t lpuart32_int(int irq, void *dev_id)
{}

/*
 * Timer function to simulate the hardware EOP (End Of Package) event.
 * The timer callback is to check for new RX data and copy to TTY buffer.
 * If no new data are received since last interval, the EOP condition is
 * met, complete the DMA transfer by copying the data. Otherwise, just
 * restart timer.
 */
static void lpuart_timer_func(struct timer_list *t)
{}

static inline int lpuart_start_rx_dma(struct lpuart_port *sport)
{}

static void lpuart_dma_rx_free(struct uart_port *port)
{}

static int lpuart_config_rs485(struct uart_port *port, struct ktermios *termios,
			struct serial_rs485 *rs485)
{}

static int lpuart32_config_rs485(struct uart_port *port, struct ktermios *termios,
			struct serial_rs485 *rs485)
{}

static unsigned int lpuart_get_mctrl(struct uart_port *port)
{}

static unsigned int lpuart32_get_mctrl(struct uart_port *port)
{}

static void lpuart_set_mctrl(struct uart_port *port, unsigned int mctrl)
{}

static void lpuart32_set_mctrl(struct uart_port *port, unsigned int mctrl)
{}

static void lpuart_break_ctl(struct uart_port *port, int break_state)
{}

static void lpuart32_break_ctl(struct uart_port *port, int break_state)
{}

static void lpuart_setup_watermark(struct lpuart_port *sport)
{}

static void lpuart_setup_watermark_enable(struct lpuart_port *sport)
{}

static void lpuart32_setup_watermark(struct lpuart_port *sport)
{}

static void lpuart32_setup_watermark_enable(struct lpuart_port *sport)
{}

static void rx_dma_timer_init(struct lpuart_port *sport)
{}

static void lpuart_request_dma(struct lpuart_port *sport)
{}

static void lpuart_tx_dma_startup(struct lpuart_port *sport)
{}

static void lpuart_rx_dma_startup(struct lpuart_port *sport)
{}

static void lpuart_hw_setup(struct lpuart_port *sport)
{}

static int lpuart_startup(struct uart_port *port)
{}

static void lpuart32_hw_disable(struct lpuart_port *sport)
{}

static void lpuart32_configure(struct lpuart_port *sport)
{}

static void lpuart32_hw_setup(struct lpuart_port *sport)
{}

static int lpuart32_startup(struct uart_port *port)
{}

static void lpuart_dma_shutdown(struct lpuart_port *sport)
{}

static void lpuart_shutdown(struct uart_port *port)
{}

static void lpuart32_shutdown(struct uart_port *port)
{}

static void
lpuart_set_termios(struct uart_port *port, struct ktermios *termios,
		   const struct ktermios *old)
{}

static void __lpuart32_serial_setbrg(struct uart_port *port,
				     unsigned int baudrate, bool use_rx_dma,
				     bool use_tx_dma)
{}

static void lpuart32_serial_setbrg(struct lpuart_port *sport,
				   unsigned int baudrate)
{}


static void
lpuart32_set_termios(struct uart_port *port, struct ktermios *termios,
		     const struct ktermios *old)
{}

static const char *lpuart_type(struct uart_port *port)
{}

static void lpuart_release_port(struct uart_port *port)
{}

static int lpuart_request_port(struct uart_port *port)
{}

/* configure/autoconfigure the port */
static void lpuart_config_port(struct uart_port *port, int flags)
{}

static int lpuart_verify_port(struct uart_port *port, struct serial_struct *ser)
{}

static const struct uart_ops lpuart_pops =;

static const struct uart_ops lpuart32_pops =;

static struct lpuart_port *lpuart_ports[UART_NR];

#ifdef CONFIG_SERIAL_FSL_LPUART_CONSOLE
static void lpuart_console_putchar(struct uart_port *port, unsigned char ch)
{}

static void lpuart32_console_putchar(struct uart_port *port, unsigned char ch)
{}

static void
lpuart_console_write(struct console *co, const char *s, unsigned int count)
{}

static void
lpuart32_console_write(struct console *co, const char *s, unsigned int count)
{}

/*
 * if the port was already initialised (eg, by a boot loader),
 * try to determine the current setup.
 */
static void __init
lpuart_console_get_options(struct lpuart_port *sport, int *baud,
			   int *parity, int *bits)
{}

static void __init
lpuart32_console_get_options(struct lpuart_port *sport, int *baud,
			   int *parity, int *bits)
{}

static int __init lpuart_console_setup(struct console *co, char *options)
{}

static struct uart_driver lpuart_reg;
static struct console lpuart_console =;

static struct console lpuart32_console =;

static void lpuart_early_write(struct console *con, const char *s, unsigned n)
{}

static void lpuart32_early_write(struct console *con, const char *s, unsigned n)
{}

static int __init lpuart_early_console_setup(struct earlycon_device *device,
					  const char *opt)
{}

static int __init lpuart32_early_console_setup(struct earlycon_device *device,
					  const char *opt)
{}

static int __init ls1028a_early_console_setup(struct earlycon_device *device,
					      const char *opt)
{}

static int __init lpuart32_imx_early_console_setup(struct earlycon_device *device,
						   const char *opt)
{}
OF_EARLYCON_DECLARE();
OF_EARLYCON_DECLARE();
OF_EARLYCON_DECLARE();
OF_EARLYCON_DECLARE();
OF_EARLYCON_DECLARE();
OF_EARLYCON_DECLARE();
OF_EARLYCON_DECLARE();
EARLYCON_DECLARE();
EARLYCON_DECLARE();

#define LPUART_CONSOLE
#define LPUART32_CONSOLE
#else
#define LPUART_CONSOLE
#define LPUART32_CONSOLE
#endif

static struct uart_driver lpuart_reg =;

static const struct serial_rs485 lpuart_rs485_supported =;

static int lpuart_global_reset(struct lpuart_port *sport)
{}

static int lpuart_probe(struct platform_device *pdev)
{}

static void lpuart_remove(struct platform_device *pdev)
{}

static int lpuart_runtime_suspend(struct device *dev)
{
	struct platform_device *pdev = to_platform_device(dev);
	struct lpuart_port *sport = platform_get_drvdata(pdev);

	lpuart_disable_clks(sport);

	return 0;
};

static int lpuart_runtime_resume(struct device *dev)
{
	struct platform_device *pdev = to_platform_device(dev);
	struct lpuart_port *sport = platform_get_drvdata(pdev);

	return lpuart_enable_clks(sport);
};

static void serial_lpuart_enable_wakeup(struct lpuart_port *sport, bool on)
{}

static bool lpuart_uport_is_active(struct lpuart_port *sport)
{}

static int lpuart_suspend_noirq(struct device *dev)
{}

static int lpuart_resume_noirq(struct device *dev)
{}

static int lpuart_suspend(struct device *dev)
{}

static void lpuart_console_fixup(struct lpuart_port *sport)
{}

static int lpuart_resume(struct device *dev)
{}

static const struct dev_pm_ops lpuart_pm_ops =;

static struct platform_driver lpuart_driver =;

static int __init lpuart_serial_init(void)
{}

static void __exit lpuart_serial_exit(void)
{}

module_init();
module_exit(lpuart_serial_exit);

MODULE_DESCRIPTION();
MODULE_LICENSE();