2017-11-06 17:11:51 +00:00
|
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2013-06-07 01:20:40 +00:00
|
|
|
|
/*
|
|
|
|
|
* Freescale lpuart serial port driver
|
|
|
|
|
*
|
2014-07-14 09:41:11 +00:00
|
|
|
|
* Copyright 2012-2014 Freescale Semiconductor, Inc.
|
2013-06-07 01:20:40 +00:00
|
|
|
|
*/
|
|
|
|
|
|
2014-02-17 05:28:07 +00:00
|
|
|
|
#include <linux/clk.h>
|
|
|
|
|
#include <linux/console.h>
|
|
|
|
|
#include <linux/dma-mapping.h>
|
|
|
|
|
#include <linux/dmaengine.h>
|
|
|
|
|
#include <linux/dmapool.h>
|
2013-06-07 01:20:40 +00:00
|
|
|
|
#include <linux/io.h>
|
|
|
|
|
#include <linux/irq.h>
|
2014-02-17 05:28:07 +00:00
|
|
|
|
#include <linux/module.h>
|
2013-06-07 01:20:40 +00:00
|
|
|
|
#include <linux/of.h>
|
|
|
|
|
#include <linux/of_device.h>
|
2014-02-17 05:28:07 +00:00
|
|
|
|
#include <linux/of_dma.h>
|
2013-06-07 01:20:40 +00:00
|
|
|
|
#include <linux/serial_core.h>
|
2014-02-17 05:28:07 +00:00
|
|
|
|
#include <linux/slab.h>
|
2013-06-07 01:20:40 +00:00
|
|
|
|
#include <linux/tty_flip.h>
|
|
|
|
|
|
|
|
|
|
/* All registers are 8-bit width */
|
|
|
|
|
#define UARTBDH 0x00
|
|
|
|
|
#define UARTBDL 0x01
|
|
|
|
|
#define UARTCR1 0x02
|
|
|
|
|
#define UARTCR2 0x03
|
|
|
|
|
#define UARTSR1 0x04
|
|
|
|
|
#define UARTCR3 0x06
|
|
|
|
|
#define UARTDR 0x07
|
|
|
|
|
#define UARTCR4 0x0a
|
|
|
|
|
#define UARTCR5 0x0b
|
|
|
|
|
#define UARTMODEM 0x0d
|
|
|
|
|
#define UARTPFIFO 0x10
|
|
|
|
|
#define UARTCFIFO 0x11
|
|
|
|
|
#define UARTSFIFO 0x12
|
|
|
|
|
#define UARTTWFIFO 0x13
|
|
|
|
|
#define UARTTCFIFO 0x14
|
|
|
|
|
#define UARTRWFIFO 0x15
|
|
|
|
|
|
|
|
|
|
#define UARTBDH_LBKDIE 0x80
|
|
|
|
|
#define UARTBDH_RXEDGIE 0x40
|
|
|
|
|
#define UARTBDH_SBR_MASK 0x1f
|
|
|
|
|
|
|
|
|
|
#define UARTCR1_LOOPS 0x80
|
|
|
|
|
#define UARTCR1_RSRC 0x20
|
|
|
|
|
#define UARTCR1_M 0x10
|
|
|
|
|
#define UARTCR1_WAKE 0x08
|
|
|
|
|
#define UARTCR1_ILT 0x04
|
|
|
|
|
#define UARTCR1_PE 0x02
|
|
|
|
|
#define UARTCR1_PT 0x01
|
|
|
|
|
|
|
|
|
|
#define UARTCR2_TIE 0x80
|
|
|
|
|
#define UARTCR2_TCIE 0x40
|
|
|
|
|
#define UARTCR2_RIE 0x20
|
|
|
|
|
#define UARTCR2_ILIE 0x10
|
|
|
|
|
#define UARTCR2_TE 0x08
|
|
|
|
|
#define UARTCR2_RE 0x04
|
|
|
|
|
#define UARTCR2_RWU 0x02
|
|
|
|
|
#define UARTCR2_SBK 0x01
|
|
|
|
|
|
|
|
|
|
#define UARTSR1_TDRE 0x80
|
|
|
|
|
#define UARTSR1_TC 0x40
|
|
|
|
|
#define UARTSR1_RDRF 0x20
|
|
|
|
|
#define UARTSR1_IDLE 0x10
|
|
|
|
|
#define UARTSR1_OR 0x08
|
|
|
|
|
#define UARTSR1_NF 0x04
|
|
|
|
|
#define UARTSR1_FE 0x02
|
|
|
|
|
#define UARTSR1_PE 0x01
|
|
|
|
|
|
|
|
|
|
#define UARTCR3_R8 0x80
|
|
|
|
|
#define UARTCR3_T8 0x40
|
|
|
|
|
#define UARTCR3_TXDIR 0x20
|
|
|
|
|
#define UARTCR3_TXINV 0x10
|
|
|
|
|
#define UARTCR3_ORIE 0x08
|
|
|
|
|
#define UARTCR3_NEIE 0x04
|
|
|
|
|
#define UARTCR3_FEIE 0x02
|
|
|
|
|
#define UARTCR3_PEIE 0x01
|
|
|
|
|
|
|
|
|
|
#define UARTCR4_MAEN1 0x80
|
|
|
|
|
#define UARTCR4_MAEN2 0x40
|
|
|
|
|
#define UARTCR4_M10 0x20
|
|
|
|
|
#define UARTCR4_BRFA_MASK 0x1f
|
|
|
|
|
#define UARTCR4_BRFA_OFF 0
|
|
|
|
|
|
|
|
|
|
#define UARTCR5_TDMAS 0x80
|
|
|
|
|
#define UARTCR5_RDMAS 0x20
|
|
|
|
|
|
|
|
|
|
#define UARTMODEM_RXRTSE 0x08
|
|
|
|
|
#define UARTMODEM_TXRTSPOL 0x04
|
|
|
|
|
#define UARTMODEM_TXRTSE 0x02
|
|
|
|
|
#define UARTMODEM_TXCTSE 0x01
|
|
|
|
|
|
|
|
|
|
#define UARTPFIFO_TXFE 0x80
|
|
|
|
|
#define UARTPFIFO_FIFOSIZE_MASK 0x7
|
|
|
|
|
#define UARTPFIFO_TXSIZE_OFF 4
|
|
|
|
|
#define UARTPFIFO_RXFE 0x08
|
|
|
|
|
#define UARTPFIFO_RXSIZE_OFF 0
|
|
|
|
|
|
|
|
|
|
#define UARTCFIFO_TXFLUSH 0x80
|
|
|
|
|
#define UARTCFIFO_RXFLUSH 0x40
|
|
|
|
|
#define UARTCFIFO_RXOFE 0x04
|
|
|
|
|
#define UARTCFIFO_TXOFE 0x02
|
|
|
|
|
#define UARTCFIFO_RXUFE 0x01
|
|
|
|
|
|
|
|
|
|
#define UARTSFIFO_TXEMPT 0x80
|
|
|
|
|
#define UARTSFIFO_RXEMPT 0x40
|
|
|
|
|
#define UARTSFIFO_RXOF 0x04
|
|
|
|
|
#define UARTSFIFO_TXOF 0x02
|
|
|
|
|
#define UARTSFIFO_RXUF 0x01
|
|
|
|
|
|
2017-07-15 22:00:58 +00:00
|
|
|
|
/* 32-bit register definition */
|
2014-07-14 09:41:11 +00:00
|
|
|
|
#define UARTBAUD 0x00
|
|
|
|
|
#define UARTSTAT 0x04
|
|
|
|
|
#define UARTCTRL 0x08
|
|
|
|
|
#define UARTDATA 0x0C
|
|
|
|
|
#define UARTMATCH 0x10
|
|
|
|
|
#define UARTMODIR 0x14
|
|
|
|
|
#define UARTFIFO 0x18
|
|
|
|
|
#define UARTWATER 0x1c
|
|
|
|
|
|
|
|
|
|
#define UARTBAUD_MAEN1 0x80000000
|
|
|
|
|
#define UARTBAUD_MAEN2 0x40000000
|
|
|
|
|
#define UARTBAUD_M10 0x20000000
|
|
|
|
|
#define UARTBAUD_TDMAE 0x00800000
|
|
|
|
|
#define UARTBAUD_RDMAE 0x00200000
|
|
|
|
|
#define UARTBAUD_MATCFG 0x00400000
|
|
|
|
|
#define UARTBAUD_BOTHEDGE 0x00020000
|
|
|
|
|
#define UARTBAUD_RESYNCDIS 0x00010000
|
|
|
|
|
#define UARTBAUD_LBKDIE 0x00008000
|
|
|
|
|
#define UARTBAUD_RXEDGIE 0x00004000
|
|
|
|
|
#define UARTBAUD_SBNS 0x00002000
|
|
|
|
|
#define UARTBAUD_SBR 0x00000000
|
|
|
|
|
#define UARTBAUD_SBR_MASK 0x1fff
|
2017-06-13 02:55:54 +00:00
|
|
|
|
#define UARTBAUD_OSR_MASK 0x1f
|
|
|
|
|
#define UARTBAUD_OSR_SHIFT 24
|
2014-07-14 09:41:11 +00:00
|
|
|
|
|
|
|
|
|
#define UARTSTAT_LBKDIF 0x80000000
|
|
|
|
|
#define UARTSTAT_RXEDGIF 0x40000000
|
|
|
|
|
#define UARTSTAT_MSBF 0x20000000
|
|
|
|
|
#define UARTSTAT_RXINV 0x10000000
|
|
|
|
|
#define UARTSTAT_RWUID 0x08000000
|
|
|
|
|
#define UARTSTAT_BRK13 0x04000000
|
|
|
|
|
#define UARTSTAT_LBKDE 0x02000000
|
|
|
|
|
#define UARTSTAT_RAF 0x01000000
|
|
|
|
|
#define UARTSTAT_TDRE 0x00800000
|
|
|
|
|
#define UARTSTAT_TC 0x00400000
|
|
|
|
|
#define UARTSTAT_RDRF 0x00200000
|
|
|
|
|
#define UARTSTAT_IDLE 0x00100000
|
|
|
|
|
#define UARTSTAT_OR 0x00080000
|
|
|
|
|
#define UARTSTAT_NF 0x00040000
|
|
|
|
|
#define UARTSTAT_FE 0x00020000
|
|
|
|
|
#define UARTSTAT_PE 0x00010000
|
|
|
|
|
#define UARTSTAT_MA1F 0x00008000
|
|
|
|
|
#define UARTSTAT_M21F 0x00004000
|
|
|
|
|
|
|
|
|
|
#define UARTCTRL_R8T9 0x80000000
|
|
|
|
|
#define UARTCTRL_R9T8 0x40000000
|
|
|
|
|
#define UARTCTRL_TXDIR 0x20000000
|
|
|
|
|
#define UARTCTRL_TXINV 0x10000000
|
|
|
|
|
#define UARTCTRL_ORIE 0x08000000
|
|
|
|
|
#define UARTCTRL_NEIE 0x04000000
|
|
|
|
|
#define UARTCTRL_FEIE 0x02000000
|
|
|
|
|
#define UARTCTRL_PEIE 0x01000000
|
|
|
|
|
#define UARTCTRL_TIE 0x00800000
|
|
|
|
|
#define UARTCTRL_TCIE 0x00400000
|
|
|
|
|
#define UARTCTRL_RIE 0x00200000
|
|
|
|
|
#define UARTCTRL_ILIE 0x00100000
|
|
|
|
|
#define UARTCTRL_TE 0x00080000
|
|
|
|
|
#define UARTCTRL_RE 0x00040000
|
|
|
|
|
#define UARTCTRL_RWU 0x00020000
|
|
|
|
|
#define UARTCTRL_SBK 0x00010000
|
|
|
|
|
#define UARTCTRL_MA1IE 0x00008000
|
|
|
|
|
#define UARTCTRL_MA2IE 0x00004000
|
|
|
|
|
#define UARTCTRL_IDLECFG 0x00000100
|
|
|
|
|
#define UARTCTRL_LOOPS 0x00000080
|
|
|
|
|
#define UARTCTRL_DOZEEN 0x00000040
|
|
|
|
|
#define UARTCTRL_RSRC 0x00000020
|
|
|
|
|
#define UARTCTRL_M 0x00000010
|
|
|
|
|
#define UARTCTRL_WAKE 0x00000008
|
|
|
|
|
#define UARTCTRL_ILT 0x00000004
|
|
|
|
|
#define UARTCTRL_PE 0x00000002
|
|
|
|
|
#define UARTCTRL_PT 0x00000001
|
|
|
|
|
|
|
|
|
|
#define UARTDATA_NOISY 0x00008000
|
|
|
|
|
#define UARTDATA_PARITYE 0x00004000
|
|
|
|
|
#define UARTDATA_FRETSC 0x00002000
|
|
|
|
|
#define UARTDATA_RXEMPT 0x00001000
|
|
|
|
|
#define UARTDATA_IDLINE 0x00000800
|
|
|
|
|
#define UARTDATA_MASK 0x3ff
|
|
|
|
|
|
|
|
|
|
#define UARTMODIR_IREN 0x00020000
|
|
|
|
|
#define UARTMODIR_TXCTSSRC 0x00000020
|
|
|
|
|
#define UARTMODIR_TXCTSC 0x00000010
|
|
|
|
|
#define UARTMODIR_RXRTSE 0x00000008
|
|
|
|
|
#define UARTMODIR_TXRTSPOL 0x00000004
|
|
|
|
|
#define UARTMODIR_TXRTSE 0x00000002
|
|
|
|
|
#define UARTMODIR_TXCTSE 0x00000001
|
|
|
|
|
|
|
|
|
|
#define UARTFIFO_TXEMPT 0x00800000
|
|
|
|
|
#define UARTFIFO_RXEMPT 0x00400000
|
|
|
|
|
#define UARTFIFO_TXOF 0x00020000
|
|
|
|
|
#define UARTFIFO_RXUF 0x00010000
|
|
|
|
|
#define UARTFIFO_TXFLUSH 0x00008000
|
|
|
|
|
#define UARTFIFO_RXFLUSH 0x00004000
|
|
|
|
|
#define UARTFIFO_TXOFE 0x00000200
|
|
|
|
|
#define UARTFIFO_RXUFE 0x00000100
|
|
|
|
|
#define UARTFIFO_TXFE 0x00000080
|
|
|
|
|
#define UARTFIFO_FIFOSIZE_MASK 0x7
|
|
|
|
|
#define UARTFIFO_TXSIZE_OFF 4
|
|
|
|
|
#define UARTFIFO_RXFE 0x00000008
|
|
|
|
|
#define UARTFIFO_RXSIZE_OFF 0
|
2019-07-17 05:19:30 +00:00
|
|
|
|
#define UARTFIFO_DEPTH(x) (0x1 << ((x) ? ((x) + 1) : 0))
|
2014-07-14 09:41:11 +00:00
|
|
|
|
|
|
|
|
|
#define UARTWATER_COUNT_MASK 0xff
|
|
|
|
|
#define UARTWATER_TXCNT_OFF 8
|
|
|
|
|
#define UARTWATER_RXCNT_OFF 24
|
|
|
|
|
#define UARTWATER_WATER_MASK 0xff
|
|
|
|
|
#define UARTWATER_TXWATER_OFF 0
|
|
|
|
|
#define UARTWATER_RXWATER_OFF 16
|
|
|
|
|
|
2016-07-19 07:43:07 +00:00
|
|
|
|
/* Rx DMA timeout in ms, which is used to calculate Rx ring buffer size */
|
|
|
|
|
#define DMA_RX_TIMEOUT (10)
|
2014-02-17 05:28:07 +00:00
|
|
|
|
|
2013-06-07 01:20:40 +00:00
|
|
|
|
#define DRIVER_NAME "fsl-lpuart"
|
|
|
|
|
#define DEV_NAME "ttyLP"
|
|
|
|
|
#define UART_NR 6
|
|
|
|
|
|
2017-06-13 02:55:52 +00:00
|
|
|
|
/* IMX lpuart has four extra unused regs located at the beginning */
|
|
|
|
|
#define IMX_REG_OFF 0x10
|
|
|
|
|
|
2018-10-09 22:26:16 +00:00
|
|
|
|
static DEFINE_IDA(fsl_lpuart_ida);
|
|
|
|
|
|
2019-07-04 13:40:07 +00:00
|
|
|
|
enum lpuart_type {
|
|
|
|
|
VF610_LPUART,
|
|
|
|
|
LS1021A_LPUART,
|
2020-03-06 21:44:32 +00:00
|
|
|
|
LS1028A_LPUART,
|
2019-07-04 13:40:07 +00:00
|
|
|
|
IMX7ULP_LPUART,
|
|
|
|
|
IMX8QXP_LPUART,
|
|
|
|
|
};
|
|
|
|
|
|
2013-06-07 01:20:40 +00:00
|
|
|
|
struct lpuart_port {
|
|
|
|
|
struct uart_port port;
|
2019-07-04 13:40:07 +00:00
|
|
|
|
enum lpuart_type devtype;
|
|
|
|
|
struct clk *ipg_clk;
|
|
|
|
|
struct clk *baud_clk;
|
2013-06-07 01:20:40 +00:00
|
|
|
|
unsigned int txfifo_size;
|
|
|
|
|
unsigned int rxfifo_size;
|
2014-02-17 05:28:07 +00:00
|
|
|
|
|
2015-01-10 08:33:45 +00:00
|
|
|
|
bool lpuart_dma_tx_use;
|
|
|
|
|
bool lpuart_dma_rx_use;
|
2014-02-17 05:28:07 +00:00
|
|
|
|
struct dma_chan *dma_tx_chan;
|
|
|
|
|
struct dma_chan *dma_rx_chan;
|
|
|
|
|
struct dma_async_tx_descriptor *dma_tx_desc;
|
|
|
|
|
struct dma_async_tx_descriptor *dma_rx_desc;
|
|
|
|
|
dma_cookie_t dma_tx_cookie;
|
|
|
|
|
dma_cookie_t dma_rx_cookie;
|
|
|
|
|
unsigned int dma_tx_bytes;
|
|
|
|
|
unsigned int dma_rx_bytes;
|
2016-07-19 07:43:08 +00:00
|
|
|
|
bool dma_tx_in_progress;
|
2014-02-17 05:28:07 +00:00
|
|
|
|
unsigned int dma_rx_timeout;
|
|
|
|
|
struct timer_list lpuart_timer;
|
2016-07-19 07:43:08 +00:00
|
|
|
|
struct scatterlist rx_sgl, tx_sgl[2];
|
2016-07-19 07:43:07 +00:00
|
|
|
|
struct circ_buf rx_ring;
|
|
|
|
|
int rx_dma_rng_buf_len;
|
2016-07-19 07:43:08 +00:00
|
|
|
|
unsigned int dma_tx_nents;
|
|
|
|
|
wait_queue_head_t dma_wait;
|
2020-03-03 17:42:59 +00:00
|
|
|
|
bool id_allocated;
|
2013-06-07 01:20:40 +00:00
|
|
|
|
};
|
|
|
|
|
|
2017-06-13 02:55:48 +00:00
|
|
|
|
struct lpuart_soc_data {
|
2019-07-04 13:40:07 +00:00
|
|
|
|
enum lpuart_type devtype;
|
|
|
|
|
char iotype;
|
|
|
|
|
u8 reg_off;
|
2017-06-13 02:55:48 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const struct lpuart_soc_data vf_data = {
|
2019-07-04 13:40:07 +00:00
|
|
|
|
.devtype = VF610_LPUART,
|
2017-06-13 02:55:48 +00:00
|
|
|
|
.iotype = UPIO_MEM,
|
|
|
|
|
};
|
|
|
|
|
|
2020-03-06 21:44:32 +00:00
|
|
|
|
static const struct lpuart_soc_data ls1021a_data = {
|
2019-07-04 13:40:07 +00:00
|
|
|
|
.devtype = LS1021A_LPUART,
|
2017-06-13 02:55:48 +00:00
|
|
|
|
.iotype = UPIO_MEM32BE,
|
|
|
|
|
};
|
|
|
|
|
|
2020-03-06 21:44:32 +00:00
|
|
|
|
static const struct lpuart_soc_data ls1028a_data = {
|
|
|
|
|
.devtype = LS1028A_LPUART,
|
|
|
|
|
.iotype = UPIO_MEM32,
|
|
|
|
|
};
|
|
|
|
|
|
2019-07-04 13:40:07 +00:00
|
|
|
|
static struct lpuart_soc_data imx7ulp_data = {
|
|
|
|
|
.devtype = IMX7ULP_LPUART,
|
|
|
|
|
.iotype = UPIO_MEM32,
|
|
|
|
|
.reg_off = IMX_REG_OFF,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static struct lpuart_soc_data imx8qxp_data = {
|
|
|
|
|
.devtype = IMX8QXP_LPUART,
|
2017-06-13 02:55:52 +00:00
|
|
|
|
.iotype = UPIO_MEM32,
|
|
|
|
|
.reg_off = IMX_REG_OFF,
|
|
|
|
|
};
|
|
|
|
|
|
2015-03-16 19:17:11 +00:00
|
|
|
|
static const struct of_device_id lpuart_dt_ids[] = {
|
2017-06-13 02:55:48 +00:00
|
|
|
|
{ .compatible = "fsl,vf610-lpuart", .data = &vf_data, },
|
2020-03-06 21:44:32 +00:00
|
|
|
|
{ .compatible = "fsl,ls1021a-lpuart", .data = &ls1021a_data, },
|
|
|
|
|
{ .compatible = "fsl,ls1028a-lpuart", .data = &ls1028a_data, },
|
2019-07-04 13:40:07 +00:00
|
|
|
|
{ .compatible = "fsl,imx7ulp-lpuart", .data = &imx7ulp_data, },
|
|
|
|
|
{ .compatible = "fsl,imx8qxp-lpuart", .data = &imx8qxp_data, },
|
2013-06-07 01:20:40 +00:00
|
|
|
|
{ /* sentinel */ }
|
|
|
|
|
};
|
|
|
|
|
MODULE_DEVICE_TABLE(of, lpuart_dt_ids);
|
|
|
|
|
|
2014-02-17 05:28:07 +00:00
|
|
|
|
/* Forward declare this for the dma callbacks*/
|
|
|
|
|
static void lpuart_dma_tx_complete(void *arg);
|
|
|
|
|
|
tty: serial: fsl_lpuart: LS1021A has a FIFO size of 16 words, like LS1028A
Prior to the commit that this one fixes, the FIFO size was derived from
the read-only register LPUARTx_FIFO[TXFIFOSIZE] using the following
formula:
TX FIFO size = 2 ^ (LPUARTx_FIFO[TXFIFOSIZE] - 1)
The documentation for LS1021A is a mess. Under chapter 26.1.3 LS1021A
LPUART module special consideration, it mentions TXFIFO_SZ and RXFIFO_SZ
being equal to 4, and in the register description for LPUARTx_FIFO, it
shows the out-of-reset value of TXFIFOSIZE and RXFIFOSIZE fields as "011",
even though these registers read as "101" in reality.
And when LPUART on LS1021A was working, the "101" value did correspond
to "16 datawords", by applying the formula above, even though the
documentation is wrong again (!!!!) and says that "101" means 64 datawords
(hint: it doesn't).
So the "new" formula created by commit f77ebb241ce0 has all the premises
of being wrong for LS1021A, because it relied only on false data and no
actual experimentation.
Interestingly, in commit c2f448cff22a ("tty: serial: fsl_lpuart: add
LS1028A support"), Michael Walle applied a workaround to this by manually
setting the FIFO widths for LS1028A. It looks like the same values are
used by LS1021A as well, in fact.
When the driver thinks that it has a deeper FIFO than it really has,
getty (user space) output gets truncated.
Many thanks to Michael for pointing out where to look.
Fixes: f77ebb241ce0 ("tty: serial: fsl_lpuart: correct the FIFO depth size")
Suggested-by: Michael Walle <michael@walle.cc>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Link: https://lore.kernel.org/r/20201023013429.3551026-1-vladimir.oltean@nxp.com
Reviewed-by:Fugang Duan <fugang.duan@nxp.com>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-10-23 01:34:29 +00:00
|
|
|
|
static inline bool is_layerscape_lpuart(struct lpuart_port *sport)
|
2020-03-06 21:44:32 +00:00
|
|
|
|
{
|
tty: serial: fsl_lpuart: LS1021A has a FIFO size of 16 words, like LS1028A
Prior to the commit that this one fixes, the FIFO size was derived from
the read-only register LPUARTx_FIFO[TXFIFOSIZE] using the following
formula:
TX FIFO size = 2 ^ (LPUARTx_FIFO[TXFIFOSIZE] - 1)
The documentation for LS1021A is a mess. Under chapter 26.1.3 LS1021A
LPUART module special consideration, it mentions TXFIFO_SZ and RXFIFO_SZ
being equal to 4, and in the register description for LPUARTx_FIFO, it
shows the out-of-reset value of TXFIFOSIZE and RXFIFOSIZE fields as "011",
even though these registers read as "101" in reality.
And when LPUART on LS1021A was working, the "101" value did correspond
to "16 datawords", by applying the formula above, even though the
documentation is wrong again (!!!!) and says that "101" means 64 datawords
(hint: it doesn't).
So the "new" formula created by commit f77ebb241ce0 has all the premises
of being wrong for LS1021A, because it relied only on false data and no
actual experimentation.
Interestingly, in commit c2f448cff22a ("tty: serial: fsl_lpuart: add
LS1028A support"), Michael Walle applied a workaround to this by manually
setting the FIFO widths for LS1028A. It looks like the same values are
used by LS1021A as well, in fact.
When the driver thinks that it has a deeper FIFO than it really has,
getty (user space) output gets truncated.
Many thanks to Michael for pointing out where to look.
Fixes: f77ebb241ce0 ("tty: serial: fsl_lpuart: correct the FIFO depth size")
Suggested-by: Michael Walle <michael@walle.cc>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Link: https://lore.kernel.org/r/20201023013429.3551026-1-vladimir.oltean@nxp.com
Reviewed-by:Fugang Duan <fugang.duan@nxp.com>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-10-23 01:34:29 +00:00
|
|
|
|
return (sport->devtype == LS1021A_LPUART ||
|
|
|
|
|
sport->devtype == LS1028A_LPUART);
|
2020-03-06 21:44:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-04 13:40:07 +00:00
|
|
|
|
static inline bool is_imx8qxp_lpuart(struct lpuart_port *sport)
|
|
|
|
|
{
|
|
|
|
|
return sport->devtype == IMX8QXP_LPUART;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-13 02:55:50 +00:00
|
|
|
|
static inline u32 lpuart32_read(struct uart_port *port, u32 off)
|
|
|
|
|
{
|
|
|
|
|
switch (port->iotype) {
|
|
|
|
|
case UPIO_MEM32:
|
|
|
|
|
return readl(port->membase + off);
|
|
|
|
|
case UPIO_MEM32BE:
|
|
|
|
|
return ioread32be(port->membase + off);
|
|
|
|
|
default:
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2014-07-14 09:41:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-13 02:55:49 +00:00
|
|
|
|
static inline void lpuart32_write(struct uart_port *port, u32 val,
|
2017-06-13 02:55:50 +00:00
|
|
|
|
u32 off)
|
|
|
|
|
{
|
|
|
|
|
switch (port->iotype) {
|
|
|
|
|
case UPIO_MEM32:
|
|
|
|
|
writel(val, port->membase + off);
|
|
|
|
|
break;
|
|
|
|
|
case UPIO_MEM32BE:
|
|
|
|
|
iowrite32be(val, port->membase + off);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2014-07-14 09:41:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-04 13:40:07 +00:00
|
|
|
|
static int __lpuart_enable_clks(struct lpuart_port *sport, bool is_en)
|
|
|
|
|
{
|
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
|
|
if (is_en) {
|
|
|
|
|
ret = clk_prepare_enable(sport->ipg_clk);
|
|
|
|
|
if (ret)
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
ret = clk_prepare_enable(sport->baud_clk);
|
|
|
|
|
if (ret) {
|
|
|
|
|
clk_disable_unprepare(sport->ipg_clk);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
clk_disable_unprepare(sport->baud_clk);
|
|
|
|
|
clk_disable_unprepare(sport->ipg_clk);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static unsigned int lpuart_get_baud_clk_rate(struct lpuart_port *sport)
|
|
|
|
|
{
|
|
|
|
|
if (is_imx8qxp_lpuart(sport))
|
|
|
|
|
return clk_get_rate(sport->baud_clk);
|
|
|
|
|
|
|
|
|
|
return clk_get_rate(sport->ipg_clk);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#define lpuart_enable_clks(x) __lpuart_enable_clks(x, true)
|
|
|
|
|
#define lpuart_disable_clks(x) __lpuart_enable_clks(x, false)
|
|
|
|
|
|
2013-06-07 01:20:40 +00:00
|
|
|
|
static void lpuart_stop_tx(struct uart_port *port)
|
|
|
|
|
{
|
|
|
|
|
unsigned char temp;
|
|
|
|
|
|
|
|
|
|
temp = readb(port->membase + UARTCR2);
|
|
|
|
|
temp &= ~(UARTCR2_TIE | UARTCR2_TCIE);
|
|
|
|
|
writeb(temp, port->membase + UARTCR2);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-14 09:41:11 +00:00
|
|
|
|
static void lpuart32_stop_tx(struct uart_port *port)
|
|
|
|
|
{
|
|
|
|
|
unsigned long temp;
|
|
|
|
|
|
2017-06-13 02:55:49 +00:00
|
|
|
|
temp = lpuart32_read(port, UARTCTRL);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
temp &= ~(UARTCTRL_TIE | UARTCTRL_TCIE);
|
2017-06-13 02:55:49 +00:00
|
|
|
|
lpuart32_write(port, temp, UARTCTRL);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-07 01:20:40 +00:00
|
|
|
|
static void lpuart_stop_rx(struct uart_port *port)
|
|
|
|
|
{
|
|
|
|
|
unsigned char temp;
|
|
|
|
|
|
|
|
|
|
temp = readb(port->membase + UARTCR2);
|
|
|
|
|
writeb(temp & ~UARTCR2_RE, port->membase + UARTCR2);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-14 09:41:11 +00:00
|
|
|
|
static void lpuart32_stop_rx(struct uart_port *port)
|
|
|
|
|
{
|
|
|
|
|
unsigned long temp;
|
|
|
|
|
|
2017-06-13 02:55:49 +00:00
|
|
|
|
temp = lpuart32_read(port, UARTCTRL);
|
|
|
|
|
lpuart32_write(port, temp & ~UARTCTRL_RE, UARTCTRL);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-19 07:43:08 +00:00
|
|
|
|
static void lpuart_dma_tx(struct lpuart_port *sport)
|
2014-02-17 05:28:07 +00:00
|
|
|
|
{
|
|
|
|
|
struct circ_buf *xmit = &sport->port.state->xmit;
|
2016-07-19 07:43:08 +00:00
|
|
|
|
struct scatterlist *sgl = sport->tx_sgl;
|
|
|
|
|
struct device *dev = sport->port.dev;
|
2020-03-06 21:44:31 +00:00
|
|
|
|
struct dma_chan *chan = sport->dma_tx_chan;
|
2016-07-19 07:43:08 +00:00
|
|
|
|
int ret;
|
2014-02-17 05:28:07 +00:00
|
|
|
|
|
2016-07-19 07:43:08 +00:00
|
|
|
|
if (sport->dma_tx_in_progress)
|
|
|
|
|
return;
|
2014-02-17 05:28:07 +00:00
|
|
|
|
|
2016-07-19 07:43:08 +00:00
|
|
|
|
sport->dma_tx_bytes = uart_circ_chars_pending(xmit);
|
2014-02-17 05:28:07 +00:00
|
|
|
|
|
2016-10-06 22:13:04 +00:00
|
|
|
|
if (xmit->tail < xmit->head || xmit->head == 0) {
|
2016-07-19 07:43:08 +00:00
|
|
|
|
sport->dma_tx_nents = 1;
|
|
|
|
|
sg_init_one(sgl, xmit->buf + xmit->tail, sport->dma_tx_bytes);
|
|
|
|
|
} else {
|
|
|
|
|
sport->dma_tx_nents = 2;
|
|
|
|
|
sg_init_table(sgl, 2);
|
|
|
|
|
sg_set_buf(sgl, xmit->buf + xmit->tail,
|
|
|
|
|
UART_XMIT_SIZE - xmit->tail);
|
|
|
|
|
sg_set_buf(sgl + 1, xmit->buf, xmit->head);
|
|
|
|
|
}
|
2014-02-17 05:28:07 +00:00
|
|
|
|
|
2020-03-06 21:44:31 +00:00
|
|
|
|
ret = dma_map_sg(chan->device->dev, sgl, sport->dma_tx_nents,
|
|
|
|
|
DMA_TO_DEVICE);
|
2016-07-19 07:43:08 +00:00
|
|
|
|
if (!ret) {
|
|
|
|
|
dev_err(dev, "DMA mapping error for TX.\n");
|
|
|
|
|
return;
|
|
|
|
|
}
|
2014-02-17 05:28:07 +00:00
|
|
|
|
|
2020-03-06 21:44:31 +00:00
|
|
|
|
sport->dma_tx_desc = dmaengine_prep_slave_sg(chan, sgl,
|
2019-11-05 05:51:10 +00:00
|
|
|
|
ret, DMA_MEM_TO_DEV,
|
|
|
|
|
DMA_PREP_INTERRUPT);
|
2014-02-17 05:28:07 +00:00
|
|
|
|
if (!sport->dma_tx_desc) {
|
2020-03-06 21:44:31 +00:00
|
|
|
|
dma_unmap_sg(chan->device->dev, sgl, sport->dma_tx_nents,
|
|
|
|
|
DMA_TO_DEVICE);
|
2016-07-19 07:43:08 +00:00
|
|
|
|
dev_err(dev, "Cannot prepare TX slave DMA!\n");
|
|
|
|
|
return;
|
2014-02-17 05:28:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sport->dma_tx_desc->callback = lpuart_dma_tx_complete;
|
|
|
|
|
sport->dma_tx_desc->callback_param = sport;
|
2016-07-19 07:43:08 +00:00
|
|
|
|
sport->dma_tx_in_progress = true;
|
2014-02-17 05:28:07 +00:00
|
|
|
|
sport->dma_tx_cookie = dmaengine_submit(sport->dma_tx_desc);
|
2020-03-06 21:44:31 +00:00
|
|
|
|
dma_async_issue_pending(chan);
|
2014-02-17 05:28:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-29 19:52:18 +00:00
|
|
|
|
static bool lpuart_stopped_or_empty(struct uart_port *port)
|
|
|
|
|
{
|
|
|
|
|
return uart_circ_empty(&port->state->xmit) || uart_tx_stopped(port);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-17 05:28:07 +00:00
|
|
|
|
static void lpuart_dma_tx_complete(void *arg)
|
|
|
|
|
{
|
|
|
|
|
struct lpuart_port *sport = arg;
|
2016-07-19 07:43:08 +00:00
|
|
|
|
struct scatterlist *sgl = &sport->tx_sgl[0];
|
2014-02-17 05:28:07 +00:00
|
|
|
|
struct circ_buf *xmit = &sport->port.state->xmit;
|
2020-03-06 21:44:31 +00:00
|
|
|
|
struct dma_chan *chan = sport->dma_tx_chan;
|
2014-02-17 05:28:07 +00:00
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
|
|
spin_lock_irqsave(&sport->port.lock, flags);
|
|
|
|
|
|
2020-03-06 21:44:31 +00:00
|
|
|
|
dma_unmap_sg(chan->device->dev, sgl, sport->dma_tx_nents,
|
|
|
|
|
DMA_TO_DEVICE);
|
2016-07-19 07:43:08 +00:00
|
|
|
|
|
2014-02-17 05:28:07 +00:00
|
|
|
|
xmit->tail = (xmit->tail + sport->dma_tx_bytes) & (UART_XMIT_SIZE - 1);
|
2016-07-19 07:43:08 +00:00
|
|
|
|
|
|
|
|
|
sport->port.icount.tx += sport->dma_tx_bytes;
|
|
|
|
|
sport->dma_tx_in_progress = false;
|
|
|
|
|
spin_unlock_irqrestore(&sport->port.lock, flags);
|
2014-02-17 05:28:07 +00:00
|
|
|
|
|
|
|
|
|
if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
|
|
|
|
|
uart_write_wakeup(&sport->port);
|
|
|
|
|
|
2016-07-19 07:43:08 +00:00
|
|
|
|
if (waitqueue_active(&sport->dma_wait)) {
|
|
|
|
|
wake_up(&sport->dma_wait);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
spin_lock_irqsave(&sport->port.lock, flags);
|
|
|
|
|
|
2019-07-29 19:52:18 +00:00
|
|
|
|
if (!lpuart_stopped_or_empty(&sport->port))
|
2016-07-19 07:43:08 +00:00
|
|
|
|
lpuart_dma_tx(sport);
|
2014-02-17 05:28:07 +00:00
|
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&sport->port.lock, flags);
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-23 03:20:17 +00:00
|
|
|
|
static dma_addr_t lpuart_dma_datareg_addr(struct lpuart_port *sport)
|
|
|
|
|
{
|
|
|
|
|
switch (sport->port.iotype) {
|
|
|
|
|
case UPIO_MEM32:
|
|
|
|
|
return sport->port.mapbase + UARTDATA;
|
|
|
|
|
case UPIO_MEM32BE:
|
|
|
|
|
return sport->port.mapbase + UARTDATA + sizeof(u32) - 1;
|
|
|
|
|
}
|
|
|
|
|
return sport->port.mapbase + UARTDR;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-19 07:43:08 +00:00
|
|
|
|
static int lpuart_dma_tx_request(struct uart_port *port)
|
|
|
|
|
{
|
|
|
|
|
struct lpuart_port *sport = container_of(port,
|
|
|
|
|
struct lpuart_port, port);
|
|
|
|
|
struct dma_slave_config dma_tx_sconfig = {};
|
|
|
|
|
int ret;
|
|
|
|
|
|
2019-01-23 03:20:17 +00:00
|
|
|
|
dma_tx_sconfig.dst_addr = lpuart_dma_datareg_addr(sport);
|
2016-07-19 07:43:08 +00:00
|
|
|
|
dma_tx_sconfig.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
|
|
|
|
|
dma_tx_sconfig.dst_maxburst = 1;
|
|
|
|
|
dma_tx_sconfig.direction = DMA_MEM_TO_DEV;
|
|
|
|
|
ret = dmaengine_slave_config(sport->dma_tx_chan, &dma_tx_sconfig);
|
|
|
|
|
|
|
|
|
|
if (ret) {
|
|
|
|
|
dev_err(sport->port.dev,
|
|
|
|
|
"DMA slave config failed, err = %d\n", ret);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-29 19:52:05 +00:00
|
|
|
|
static bool lpuart_is_32(struct lpuart_port *sport)
|
|
|
|
|
{
|
|
|
|
|
return sport->port.iotype == UPIO_MEM32 ||
|
|
|
|
|
sport->port.iotype == UPIO_MEM32BE;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-26 00:10:16 +00:00
|
|
|
|
static void lpuart_flush_buffer(struct uart_port *port)
|
|
|
|
|
{
|
|
|
|
|
struct lpuart_port *sport = container_of(port, struct lpuart_port, port);
|
2020-03-06 21:44:31 +00:00
|
|
|
|
struct dma_chan *chan = sport->dma_tx_chan;
|
2019-07-29 19:52:05 +00:00
|
|
|
|
u32 val;
|
2016-07-19 07:43:08 +00:00
|
|
|
|
|
2015-01-26 00:10:16 +00:00
|
|
|
|
if (sport->lpuart_dma_tx_use) {
|
2016-07-19 07:43:08 +00:00
|
|
|
|
if (sport->dma_tx_in_progress) {
|
2020-03-06 21:44:31 +00:00
|
|
|
|
dma_unmap_sg(chan->device->dev, &sport->tx_sgl[0],
|
2016-07-19 07:43:08 +00:00
|
|
|
|
sport->dma_tx_nents, DMA_TO_DEVICE);
|
|
|
|
|
sport->dma_tx_in_progress = false;
|
|
|
|
|
}
|
2020-03-06 21:44:31 +00:00
|
|
|
|
dmaengine_terminate_all(chan);
|
2015-01-26 00:10:16 +00:00
|
|
|
|
}
|
2019-07-29 19:52:05 +00:00
|
|
|
|
|
|
|
|
|
if (lpuart_is_32(sport)) {
|
|
|
|
|
val = lpuart32_read(&sport->port, UARTFIFO);
|
|
|
|
|
val |= UARTFIFO_TXFLUSH | UARTFIFO_RXFLUSH;
|
|
|
|
|
lpuart32_write(&sport->port, val, UARTFIFO);
|
|
|
|
|
} else {
|
2019-10-04 21:55:37 +00:00
|
|
|
|
val = readb(sport->port.membase + UARTCFIFO);
|
2019-07-29 19:52:05 +00:00
|
|
|
|
val |= UARTCFIFO_TXFLUSH | UARTCFIFO_RXFLUSH;
|
|
|
|
|
writeb(val, sport->port.membase + UARTCFIFO);
|
|
|
|
|
}
|
2015-01-26 00:10:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-29 19:52:16 +00:00
|
|
|
|
static void lpuart_wait_bit_set(struct uart_port *port, unsigned int offset,
|
|
|
|
|
u8 bit)
|
|
|
|
|
{
|
|
|
|
|
while (!(readb(port->membase + offset) & bit))
|
2019-07-29 19:52:17 +00:00
|
|
|
|
cpu_relax();
|
2019-07-29 19:52:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void lpuart32_wait_bit_set(struct uart_port *port, unsigned int offset,
|
|
|
|
|
u32 bit)
|
|
|
|
|
{
|
|
|
|
|
while (!(lpuart32_read(port, offset) & bit))
|
2019-07-29 19:52:17 +00:00
|
|
|
|
cpu_relax();
|
2019-07-29 19:52:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-04 12:46:16 +00:00
|
|
|
|
#if defined(CONFIG_CONSOLE_POLL)
|
|
|
|
|
|
|
|
|
|
static int lpuart_poll_init(struct uart_port *port)
|
|
|
|
|
{
|
|
|
|
|
struct lpuart_port *sport = container_of(port,
|
|
|
|
|
struct lpuart_port, port);
|
|
|
|
|
unsigned long flags;
|
|
|
|
|
unsigned char temp;
|
|
|
|
|
|
|
|
|
|
sport->port.fifosize = 0;
|
|
|
|
|
|
|
|
|
|
spin_lock_irqsave(&sport->port.lock, flags);
|
|
|
|
|
/* Disable Rx & Tx */
|
|
|
|
|
writeb(0, sport->port.membase + UARTCR2);
|
|
|
|
|
|
|
|
|
|
temp = readb(sport->port.membase + UARTPFIFO);
|
|
|
|
|
/* Enable Rx and Tx FIFO */
|
|
|
|
|
writeb(temp | UARTPFIFO_RXFE | UARTPFIFO_TXFE,
|
|
|
|
|
sport->port.membase + UARTPFIFO);
|
|
|
|
|
|
|
|
|
|
/* flush Tx and Rx FIFO */
|
|
|
|
|
writeb(UARTCFIFO_TXFLUSH | UARTCFIFO_RXFLUSH,
|
|
|
|
|
sport->port.membase + UARTCFIFO);
|
|
|
|
|
|
|
|
|
|
/* explicitly clear RDRF */
|
|
|
|
|
if (readb(sport->port.membase + UARTSR1) & UARTSR1_RDRF) {
|
|
|
|
|
readb(sport->port.membase + UARTDR);
|
|
|
|
|
writeb(UARTSFIFO_RXUF, sport->port.membase + UARTSFIFO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
writeb(0, sport->port.membase + UARTTWFIFO);
|
|
|
|
|
writeb(1, sport->port.membase + UARTRWFIFO);
|
|
|
|
|
|
|
|
|
|
/* Enable Rx and Tx */
|
|
|
|
|
writeb(UARTCR2_RE | UARTCR2_TE, sport->port.membase + UARTCR2);
|
|
|
|
|
spin_unlock_irqrestore(&sport->port.lock, flags);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void lpuart_poll_put_char(struct uart_port *port, unsigned char c)
|
|
|
|
|
{
|
|
|
|
|
/* drain */
|
2019-07-29 19:52:16 +00:00
|
|
|
|
lpuart_wait_bit_set(port, UARTSR1, UARTSR1_TDRE);
|
2016-10-04 12:46:16 +00:00
|
|
|
|
writeb(c, port->membase + UARTDR);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int lpuart_poll_get_char(struct uart_port *port)
|
|
|
|
|
{
|
|
|
|
|
if (!(readb(port->membase + UARTSR1) & UARTSR1_RDRF))
|
|
|
|
|
return NO_POLL_CHAR;
|
|
|
|
|
|
|
|
|
|
return readb(port->membase + UARTDR);
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-15 22:00:58 +00:00
|
|
|
|
static int lpuart32_poll_init(struct uart_port *port)
|
|
|
|
|
{
|
|
|
|
|
unsigned long flags;
|
|
|
|
|
struct lpuart_port *sport = container_of(port, struct lpuart_port, port);
|
|
|
|
|
u32 temp;
|
|
|
|
|
|
|
|
|
|
sport->port.fifosize = 0;
|
|
|
|
|
|
|
|
|
|
spin_lock_irqsave(&sport->port.lock, flags);
|
|
|
|
|
|
|
|
|
|
/* Disable Rx & Tx */
|
2020-09-29 09:19:20 +00:00
|
|
|
|
lpuart32_write(&sport->port, 0, UARTCTRL);
|
2017-07-15 22:00:58 +00:00
|
|
|
|
|
2019-07-29 19:52:15 +00:00
|
|
|
|
temp = lpuart32_read(&sport->port, UARTFIFO);
|
2017-07-15 22:00:58 +00:00
|
|
|
|
|
|
|
|
|
/* Enable Rx and Tx FIFO */
|
2020-09-29 09:19:20 +00:00
|
|
|
|
lpuart32_write(&sport->port, temp | UARTFIFO_RXFE | UARTFIFO_TXFE, UARTFIFO);
|
2017-07-15 22:00:58 +00:00
|
|
|
|
|
|
|
|
|
/* flush Tx and Rx FIFO */
|
2020-09-29 09:19:20 +00:00
|
|
|
|
lpuart32_write(&sport->port, UARTFIFO_TXFLUSH | UARTFIFO_RXFLUSH, UARTFIFO);
|
2017-07-15 22:00:58 +00:00
|
|
|
|
|
|
|
|
|
/* explicitly clear RDRF */
|
2019-07-29 19:52:15 +00:00
|
|
|
|
if (lpuart32_read(&sport->port, UARTSTAT) & UARTSTAT_RDRF) {
|
|
|
|
|
lpuart32_read(&sport->port, UARTDATA);
|
2020-09-29 09:19:20 +00:00
|
|
|
|
lpuart32_write(&sport->port, UARTFIFO_RXUF, UARTFIFO);
|
2017-07-15 22:00:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Enable Rx and Tx */
|
2020-09-29 09:19:20 +00:00
|
|
|
|
lpuart32_write(&sport->port, UARTCTRL_RE | UARTCTRL_TE, UARTCTRL);
|
2017-07-15 22:00:58 +00:00
|
|
|
|
spin_unlock_irqrestore(&sport->port.lock, flags);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void lpuart32_poll_put_char(struct uart_port *port, unsigned char c)
|
|
|
|
|
{
|
2019-07-29 19:52:16 +00:00
|
|
|
|
lpuart32_wait_bit_set(port, UARTSTAT, UARTSTAT_TDRE);
|
2020-09-29 09:19:20 +00:00
|
|
|
|
lpuart32_write(port, c, UARTDATA);
|
2017-07-15 22:00:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int lpuart32_poll_get_char(struct uart_port *port)
|
|
|
|
|
{
|
2020-09-29 09:55:09 +00:00
|
|
|
|
if (!(lpuart32_read(port, UARTWATER) >> UARTWATER_RXCNT_OFF))
|
2017-07-15 22:00:58 +00:00
|
|
|
|
return NO_POLL_CHAR;
|
|
|
|
|
|
2019-07-29 19:52:15 +00:00
|
|
|
|
return lpuart32_read(port, UARTDATA);
|
2017-07-15 22:00:58 +00:00
|
|
|
|
}
|
2016-10-04 12:46:16 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
2013-06-07 01:20:40 +00:00
|
|
|
|
static inline void lpuart_transmit_buffer(struct lpuart_port *sport)
|
|
|
|
|
{
|
|
|
|
|
struct circ_buf *xmit = &sport->port.state->xmit;
|
|
|
|
|
|
2019-07-29 19:52:11 +00:00
|
|
|
|
if (sport->port.x_char) {
|
|
|
|
|
writeb(sport->port.x_char, sport->port.membase + UARTDR);
|
|
|
|
|
sport->port.icount.tx++;
|
|
|
|
|
sport->port.x_char = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-29 19:52:18 +00:00
|
|
|
|
if (lpuart_stopped_or_empty(&sport->port)) {
|
2019-07-29 19:52:11 +00:00
|
|
|
|
lpuart_stop_tx(&sport->port);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-07 01:20:40 +00:00
|
|
|
|
while (!uart_circ_empty(xmit) &&
|
|
|
|
|
(readb(sport->port.membase + UARTTCFIFO) < sport->txfifo_size)) {
|
|
|
|
|
writeb(xmit->buf[xmit->tail], sport->port.membase + UARTDR);
|
|
|
|
|
xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
|
|
|
|
|
sport->port.icount.tx++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
|
|
|
|
|
uart_write_wakeup(&sport->port);
|
|
|
|
|
|
|
|
|
|
if (uart_circ_empty(xmit))
|
|
|
|
|
lpuart_stop_tx(&sport->port);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-14 09:41:11 +00:00
|
|
|
|
static inline void lpuart32_transmit_buffer(struct lpuart_port *sport)
|
|
|
|
|
{
|
|
|
|
|
struct circ_buf *xmit = &sport->port.state->xmit;
|
|
|
|
|
unsigned long txcnt;
|
|
|
|
|
|
2019-07-29 19:52:11 +00:00
|
|
|
|
if (sport->port.x_char) {
|
|
|
|
|
lpuart32_write(&sport->port, sport->port.x_char, UARTDATA);
|
|
|
|
|
sport->port.icount.tx++;
|
|
|
|
|
sport->port.x_char = 0;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-29 19:52:18 +00:00
|
|
|
|
if (lpuart_stopped_or_empty(&sport->port)) {
|
2019-07-29 19:52:11 +00:00
|
|
|
|
lpuart32_stop_tx(&sport->port);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-13 02:55:49 +00:00
|
|
|
|
txcnt = lpuart32_read(&sport->port, UARTWATER);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
txcnt = txcnt >> UARTWATER_TXCNT_OFF;
|
|
|
|
|
txcnt &= UARTWATER_COUNT_MASK;
|
|
|
|
|
while (!uart_circ_empty(xmit) && (txcnt < sport->txfifo_size)) {
|
2017-06-13 02:55:49 +00:00
|
|
|
|
lpuart32_write(&sport->port, xmit->buf[xmit->tail], UARTDATA);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
|
|
|
|
|
sport->port.icount.tx++;
|
2017-06-13 02:55:49 +00:00
|
|
|
|
txcnt = lpuart32_read(&sport->port, UARTWATER);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
txcnt = txcnt >> UARTWATER_TXCNT_OFF;
|
|
|
|
|
txcnt &= UARTWATER_COUNT_MASK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
|
|
|
|
|
uart_write_wakeup(&sport->port);
|
|
|
|
|
|
|
|
|
|
if (uart_circ_empty(xmit))
|
|
|
|
|
lpuart32_stop_tx(&sport->port);
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-07 01:20:40 +00:00
|
|
|
|
static void lpuart_start_tx(struct uart_port *port)
|
|
|
|
|
{
|
2014-02-17 05:28:07 +00:00
|
|
|
|
struct lpuart_port *sport = container_of(port,
|
|
|
|
|
struct lpuart_port, port);
|
2013-06-07 01:20:40 +00:00
|
|
|
|
unsigned char temp;
|
|
|
|
|
|
|
|
|
|
temp = readb(port->membase + UARTCR2);
|
|
|
|
|
writeb(temp | UARTCR2_TIE, port->membase + UARTCR2);
|
|
|
|
|
|
2015-01-10 08:33:45 +00:00
|
|
|
|
if (sport->lpuart_dma_tx_use) {
|
2019-07-29 19:52:18 +00:00
|
|
|
|
if (!lpuart_stopped_or_empty(port))
|
2016-07-19 07:43:08 +00:00
|
|
|
|
lpuart_dma_tx(sport);
|
2014-02-17 05:28:07 +00:00
|
|
|
|
} else {
|
|
|
|
|
if (readb(port->membase + UARTSR1) & UARTSR1_TDRE)
|
|
|
|
|
lpuart_transmit_buffer(sport);
|
|
|
|
|
}
|
2013-06-07 01:20:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-14 09:41:11 +00:00
|
|
|
|
static void lpuart32_start_tx(struct uart_port *port)
|
|
|
|
|
{
|
|
|
|
|
struct lpuart_port *sport = container_of(port, struct lpuart_port, port);
|
|
|
|
|
unsigned long temp;
|
|
|
|
|
|
2019-01-23 03:20:17 +00:00
|
|
|
|
if (sport->lpuart_dma_tx_use) {
|
2019-07-29 19:52:18 +00:00
|
|
|
|
if (!lpuart_stopped_or_empty(port))
|
2019-01-23 03:20:17 +00:00
|
|
|
|
lpuart_dma_tx(sport);
|
|
|
|
|
} else {
|
|
|
|
|
temp = lpuart32_read(port, UARTCTRL);
|
|
|
|
|
lpuart32_write(port, temp | UARTCTRL_TIE, UARTCTRL);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
|
2019-01-23 03:20:17 +00:00
|
|
|
|
if (lpuart32_read(port, UARTSTAT) & UARTSTAT_TDRE)
|
|
|
|
|
lpuart32_transmit_buffer(sport);
|
|
|
|
|
}
|
2014-07-14 09:41:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-07-19 07:43:08 +00:00
|
|
|
|
/* return TIOCSER_TEMT when transmitter is not busy */
|
|
|
|
|
static unsigned int lpuart_tx_empty(struct uart_port *port)
|
|
|
|
|
{
|
|
|
|
|
struct lpuart_port *sport = container_of(port,
|
|
|
|
|
struct lpuart_port, port);
|
|
|
|
|
unsigned char sr1 = readb(port->membase + UARTSR1);
|
|
|
|
|
unsigned char sfifo = readb(port->membase + UARTSFIFO);
|
|
|
|
|
|
|
|
|
|
if (sport->dma_tx_in_progress)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (sr1 & UARTSR1_TC && sfifo & UARTSFIFO_TXEMPT)
|
|
|
|
|
return TIOCSER_TEMT;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static unsigned int lpuart32_tx_empty(struct uart_port *port)
|
|
|
|
|
{
|
2019-01-21 08:37:28 +00:00
|
|
|
|
struct lpuart_port *sport = container_of(port,
|
|
|
|
|
struct lpuart_port, port);
|
|
|
|
|
unsigned long stat = lpuart32_read(port, UARTSTAT);
|
|
|
|
|
unsigned long sfifo = lpuart32_read(port, UARTFIFO);
|
|
|
|
|
|
|
|
|
|
if (sport->dma_tx_in_progress)
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
|
if (stat & UARTSTAT_TC && sfifo & UARTFIFO_TXEMPT)
|
|
|
|
|
return TIOCSER_TEMT;
|
|
|
|
|
|
|
|
|
|
return 0;
|
2016-07-19 07:43:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-07-29 19:52:06 +00:00
|
|
|
|
static void lpuart_txint(struct lpuart_port *sport)
|
2013-06-07 01:20:40 +00:00
|
|
|
|
{
|
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
|
|
spin_lock_irqsave(&sport->port.lock, flags);
|
2019-07-29 19:52:11 +00:00
|
|
|
|
lpuart_transmit_buffer(sport);
|
2013-06-07 01:20:40 +00:00
|
|
|
|
spin_unlock_irqrestore(&sport->port.lock, flags);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-29 19:52:06 +00:00
|
|
|
|
static void lpuart_rxint(struct lpuart_port *sport)
|
2013-06-07 01:20:40 +00:00
|
|
|
|
{
|
2019-07-29 19:52:04 +00:00
|
|
|
|
unsigned int flg, ignored = 0, overrun = 0;
|
2013-06-07 01:20:40 +00:00
|
|
|
|
struct tty_port *port = &sport->port.state->port;
|
|
|
|
|
unsigned long flags;
|
|
|
|
|
unsigned char rx, sr;
|
|
|
|
|
|
|
|
|
|
spin_lock_irqsave(&sport->port.lock, flags);
|
|
|
|
|
|
|
|
|
|
while (!(readb(sport->port.membase + UARTSFIFO) & UARTSFIFO_RXEMPT)) {
|
|
|
|
|
flg = TTY_NORMAL;
|
|
|
|
|
sport->port.icount.rx++;
|
|
|
|
|
/*
|
|
|
|
|
* to clear the FE, OR, NF, FE, PE flags,
|
|
|
|
|
* read SR1 then read DR
|
|
|
|
|
*/
|
|
|
|
|
sr = readb(sport->port.membase + UARTSR1);
|
|
|
|
|
rx = readb(sport->port.membase + UARTDR);
|
|
|
|
|
|
|
|
|
|
if (uart_handle_sysrq_char(&sport->port, (unsigned char)rx))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (sr & (UARTSR1_PE | UARTSR1_OR | UARTSR1_FE)) {
|
|
|
|
|
if (sr & UARTSR1_PE)
|
|
|
|
|
sport->port.icount.parity++;
|
|
|
|
|
else if (sr & UARTSR1_FE)
|
|
|
|
|
sport->port.icount.frame++;
|
|
|
|
|
|
|
|
|
|
if (sr & UARTSR1_OR)
|
2019-07-29 19:52:04 +00:00
|
|
|
|
overrun++;
|
2013-06-07 01:20:40 +00:00
|
|
|
|
|
|
|
|
|
if (sr & sport->port.ignore_status_mask) {
|
|
|
|
|
if (++ignored > 100)
|
|
|
|
|
goto out;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sr &= sport->port.read_status_mask;
|
|
|
|
|
|
|
|
|
|
if (sr & UARTSR1_PE)
|
|
|
|
|
flg = TTY_PARITY;
|
|
|
|
|
else if (sr & UARTSR1_FE)
|
|
|
|
|
flg = TTY_FRAME;
|
|
|
|
|
|
|
|
|
|
if (sr & UARTSR1_OR)
|
|
|
|
|
flg = TTY_OVERRUN;
|
|
|
|
|
|
|
|
|
|
sport->port.sysrq = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tty_insert_flip_char(port, rx, flg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out:
|
2019-07-29 19:52:04 +00:00
|
|
|
|
if (overrun) {
|
|
|
|
|
sport->port.icount.overrun += overrun;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Overruns cause FIFO pointers to become missaligned.
|
|
|
|
|
* Flushing the receive FIFO reinitializes the pointers.
|
|
|
|
|
*/
|
|
|
|
|
writeb(UARTCFIFO_RXFLUSH, sport->port.membase + UARTCFIFO);
|
|
|
|
|
writeb(UARTSFIFO_RXOF, sport->port.membase + UARTSFIFO);
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-07 01:20:40 +00:00
|
|
|
|
spin_unlock_irqrestore(&sport->port.lock, flags);
|
|
|
|
|
|
|
|
|
|
tty_flip_buffer_push(port);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-29 19:52:11 +00:00
|
|
|
|
static void lpuart32_txint(struct lpuart_port *sport)
|
|
|
|
|
{
|
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
|
|
spin_lock_irqsave(&sport->port.lock, flags);
|
|
|
|
|
lpuart32_transmit_buffer(sport);
|
|
|
|
|
spin_unlock_irqrestore(&sport->port.lock, flags);
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-29 19:52:06 +00:00
|
|
|
|
static void lpuart32_rxint(struct lpuart_port *sport)
|
2014-07-14 09:41:11 +00:00
|
|
|
|
{
|
|
|
|
|
unsigned int flg, ignored = 0;
|
|
|
|
|
struct tty_port *port = &sport->port.state->port;
|
|
|
|
|
unsigned long flags;
|
|
|
|
|
unsigned long rx, sr;
|
|
|
|
|
|
|
|
|
|
spin_lock_irqsave(&sport->port.lock, flags);
|
|
|
|
|
|
2017-06-13 02:55:49 +00:00
|
|
|
|
while (!(lpuart32_read(&sport->port, UARTFIFO) & UARTFIFO_RXEMPT)) {
|
2014-07-14 09:41:11 +00:00
|
|
|
|
flg = TTY_NORMAL;
|
|
|
|
|
sport->port.icount.rx++;
|
|
|
|
|
/*
|
|
|
|
|
* to clear the FE, OR, NF, FE, PE flags,
|
|
|
|
|
* read STAT then read DATA reg
|
|
|
|
|
*/
|
2017-06-13 02:55:49 +00:00
|
|
|
|
sr = lpuart32_read(&sport->port, UARTSTAT);
|
|
|
|
|
rx = lpuart32_read(&sport->port, UARTDATA);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
rx &= 0x3ff;
|
|
|
|
|
|
|
|
|
|
if (uart_handle_sysrq_char(&sport->port, (unsigned char)rx))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (sr & (UARTSTAT_PE | UARTSTAT_OR | UARTSTAT_FE)) {
|
|
|
|
|
if (sr & UARTSTAT_PE)
|
|
|
|
|
sport->port.icount.parity++;
|
|
|
|
|
else if (sr & UARTSTAT_FE)
|
|
|
|
|
sport->port.icount.frame++;
|
|
|
|
|
|
|
|
|
|
if (sr & UARTSTAT_OR)
|
|
|
|
|
sport->port.icount.overrun++;
|
|
|
|
|
|
|
|
|
|
if (sr & sport->port.ignore_status_mask) {
|
|
|
|
|
if (++ignored > 100)
|
|
|
|
|
goto out;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sr &= sport->port.read_status_mask;
|
|
|
|
|
|
|
|
|
|
if (sr & UARTSTAT_PE)
|
|
|
|
|
flg = TTY_PARITY;
|
|
|
|
|
else if (sr & UARTSTAT_FE)
|
|
|
|
|
flg = TTY_FRAME;
|
|
|
|
|
|
|
|
|
|
if (sr & UARTSTAT_OR)
|
|
|
|
|
flg = TTY_OVERRUN;
|
|
|
|
|
|
|
|
|
|
sport->port.sysrq = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tty_insert_flip_char(port, rx, flg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
out:
|
|
|
|
|
spin_unlock_irqrestore(&sport->port.lock, flags);
|
|
|
|
|
|
|
|
|
|
tty_flip_buffer_push(port);
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-07 01:20:40 +00:00
|
|
|
|
static irqreturn_t lpuart_int(int irq, void *dev_id)
|
|
|
|
|
{
|
|
|
|
|
struct lpuart_port *sport = dev_id;
|
2016-07-19 07:43:07 +00:00
|
|
|
|
unsigned char sts;
|
2013-06-07 01:20:40 +00:00
|
|
|
|
|
|
|
|
|
sts = readb(sport->port.membase + UARTSR1);
|
|
|
|
|
|
2020-10-04 16:11:44 +00:00
|
|
|
|
/* SysRq, using dma, check for linebreak by framing err. */
|
|
|
|
|
if (sts & UARTSR1_FE && sport->lpuart_dma_rx_use) {
|
|
|
|
|
readb(sport->port.membase + UARTDR);
|
|
|
|
|
uart_handle_break(&sport->port);
|
|
|
|
|
/* linebreak produces some garbage, removing it */
|
|
|
|
|
writeb(UARTCFIFO_RXFLUSH, sport->port.membase + UARTCFIFO);
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-05 18:57:01 +00:00
|
|
|
|
if (sts & UARTSR1_RDRF && !sport->lpuart_dma_rx_use)
|
2019-07-29 19:52:06 +00:00
|
|
|
|
lpuart_rxint(sport);
|
2016-07-19 07:43:07 +00:00
|
|
|
|
|
2019-08-05 18:57:01 +00:00
|
|
|
|
if (sts & UARTSR1_TDRE && !sport->lpuart_dma_tx_use)
|
2019-07-29 19:52:06 +00:00
|
|
|
|
lpuart_txint(sport);
|
2013-06-07 01:20:40 +00:00
|
|
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-14 09:41:11 +00:00
|
|
|
|
static irqreturn_t lpuart32_int(int irq, void *dev_id)
|
|
|
|
|
{
|
|
|
|
|
struct lpuart_port *sport = dev_id;
|
|
|
|
|
unsigned long sts, rxcount;
|
|
|
|
|
|
2017-06-13 02:55:49 +00:00
|
|
|
|
sts = lpuart32_read(&sport->port, UARTSTAT);
|
|
|
|
|
rxcount = lpuart32_read(&sport->port, UARTWATER);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
rxcount = rxcount >> UARTWATER_RXCNT_OFF;
|
|
|
|
|
|
2019-01-23 03:20:17 +00:00
|
|
|
|
if ((sts & UARTSTAT_RDRF || rxcount > 0) && !sport->lpuart_dma_rx_use)
|
2019-07-29 19:52:06 +00:00
|
|
|
|
lpuart32_rxint(sport);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
|
2019-01-23 03:20:17 +00:00
|
|
|
|
if ((sts & UARTSTAT_TDRE) && !sport->lpuart_dma_tx_use)
|
2019-07-29 19:52:11 +00:00
|
|
|
|
lpuart32_txint(sport);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
|
2017-06-13 02:55:49 +00:00
|
|
|
|
lpuart32_write(&sport->port, sts, UARTSTAT);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-04 16:11:44 +00:00
|
|
|
|
|
|
|
|
|
static inline void lpuart_handle_sysrq_chars(struct uart_port *port,
|
|
|
|
|
unsigned char *p, int count)
|
|
|
|
|
{
|
|
|
|
|
while (count--) {
|
|
|
|
|
if (*p && uart_handle_sysrq_char(port, *p))
|
|
|
|
|
return;
|
|
|
|
|
p++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void lpuart_handle_sysrq(struct lpuart_port *sport)
|
|
|
|
|
{
|
|
|
|
|
struct circ_buf *ring = &sport->rx_ring;
|
|
|
|
|
int count;
|
|
|
|
|
|
|
|
|
|
if (ring->head < ring->tail) {
|
|
|
|
|
count = sport->rx_sgl.length - ring->tail;
|
|
|
|
|
lpuart_handle_sysrq_chars(&sport->port,
|
|
|
|
|
ring->buf + ring->tail, count);
|
|
|
|
|
ring->tail = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ring->head > ring->tail) {
|
|
|
|
|
count = ring->head - ring->tail;
|
|
|
|
|
lpuart_handle_sysrq_chars(&sport->port,
|
|
|
|
|
ring->buf + ring->tail, count);
|
|
|
|
|
ring->tail = ring->head;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-19 07:43:07 +00:00
|
|
|
|
static void lpuart_copy_rx_to_tty(struct lpuart_port *sport)
|
|
|
|
|
{
|
|
|
|
|
struct tty_port *port = &sport->port.state->port;
|
|
|
|
|
struct dma_tx_state state;
|
|
|
|
|
enum dma_status dmastat;
|
2020-03-06 21:44:31 +00:00
|
|
|
|
struct dma_chan *chan = sport->dma_rx_chan;
|
2016-07-19 07:43:07 +00:00
|
|
|
|
struct circ_buf *ring = &sport->rx_ring;
|
|
|
|
|
unsigned long flags;
|
|
|
|
|
int count = 0;
|
|
|
|
|
|
2019-01-23 03:20:17 +00:00
|
|
|
|
if (lpuart_is_32(sport)) {
|
|
|
|
|
unsigned long sr = lpuart32_read(&sport->port, UARTSTAT);
|
2016-07-19 07:43:07 +00:00
|
|
|
|
|
2019-01-23 03:20:17 +00:00
|
|
|
|
if (sr & (UARTSTAT_PE | UARTSTAT_FE)) {
|
|
|
|
|
/* Read DR to clear the error flags */
|
|
|
|
|
lpuart32_read(&sport->port, UARTDATA);
|
|
|
|
|
|
|
|
|
|
if (sr & UARTSTAT_PE)
|
|
|
|
|
sport->port.icount.parity++;
|
|
|
|
|
else if (sr & UARTSTAT_FE)
|
|
|
|
|
sport->port.icount.frame++;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
unsigned char sr = readb(sport->port.membase + UARTSR1);
|
|
|
|
|
|
|
|
|
|
if (sr & (UARTSR1_PE | UARTSR1_FE)) {
|
2019-07-29 19:52:03 +00:00
|
|
|
|
unsigned char cr2;
|
|
|
|
|
|
|
|
|
|
/* Disable receiver during this operation... */
|
|
|
|
|
cr2 = readb(sport->port.membase + UARTCR2);
|
|
|
|
|
cr2 &= ~UARTCR2_RE;
|
|
|
|
|
writeb(cr2, sport->port.membase + UARTCR2);
|
|
|
|
|
|
2019-01-23 03:20:17 +00:00
|
|
|
|
/* Read DR to clear the error flags */
|
|
|
|
|
readb(sport->port.membase + UARTDR);
|
2016-07-19 07:43:07 +00:00
|
|
|
|
|
2019-01-23 03:20:17 +00:00
|
|
|
|
if (sr & UARTSR1_PE)
|
|
|
|
|
sport->port.icount.parity++;
|
|
|
|
|
else if (sr & UARTSR1_FE)
|
|
|
|
|
sport->port.icount.frame++;
|
2019-07-29 19:52:03 +00:00
|
|
|
|
/*
|
|
|
|
|
* At this point parity/framing error is
|
|
|
|
|
* cleared However, since the DMA already read
|
|
|
|
|
* the data register and we had to read it
|
|
|
|
|
* again after reading the status register to
|
|
|
|
|
* properly clear the flags, the FIFO actually
|
|
|
|
|
* underflowed... This requires a clearing of
|
|
|
|
|
* the FIFO...
|
|
|
|
|
*/
|
|
|
|
|
if (readb(sport->port.membase + UARTSFIFO) &
|
|
|
|
|
UARTSFIFO_RXUF) {
|
|
|
|
|
writeb(UARTSFIFO_RXUF,
|
|
|
|
|
sport->port.membase + UARTSFIFO);
|
|
|
|
|
writeb(UARTCFIFO_RXFLUSH,
|
|
|
|
|
sport->port.membase + UARTCFIFO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cr2 |= UARTCR2_RE;
|
|
|
|
|
writeb(cr2, sport->port.membase + UARTCR2);
|
2019-01-23 03:20:17 +00:00
|
|
|
|
}
|
2016-07-19 07:43:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async_tx_ack(sport->dma_rx_desc);
|
|
|
|
|
|
|
|
|
|
spin_lock_irqsave(&sport->port.lock, flags);
|
|
|
|
|
|
2020-03-06 21:44:31 +00:00
|
|
|
|
dmastat = dmaengine_tx_status(chan, sport->dma_rx_cookie, &state);
|
2016-07-19 07:43:07 +00:00
|
|
|
|
if (dmastat == DMA_ERROR) {
|
|
|
|
|
dev_err(sport->port.dev, "Rx DMA transfer failed!\n");
|
|
|
|
|
spin_unlock_irqrestore(&sport->port.lock, flags);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* CPU claims ownership of RX DMA buffer */
|
2020-03-06 21:44:31 +00:00
|
|
|
|
dma_sync_sg_for_cpu(chan->device->dev, &sport->rx_sgl, 1,
|
|
|
|
|
DMA_FROM_DEVICE);
|
2016-07-19 07:43:07 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* ring->head points to the end of data already written by the DMA.
|
|
|
|
|
* ring->tail points to the beginning of data to be read by the
|
|
|
|
|
* framework.
|
|
|
|
|
* The current transfer size should not be larger than the dma buffer
|
|
|
|
|
* length.
|
|
|
|
|
*/
|
|
|
|
|
ring->head = sport->rx_sgl.length - state.residue;
|
|
|
|
|
BUG_ON(ring->head > sport->rx_sgl.length);
|
2020-10-04 16:11:44 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Silent handling of keys pressed in the sysrq timeframe
|
|
|
|
|
*/
|
|
|
|
|
if (sport->port.sysrq) {
|
|
|
|
|
lpuart_handle_sysrq(sport);
|
|
|
|
|
goto exit;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-19 07:43:07 +00:00
|
|
|
|
/*
|
|
|
|
|
* At this point ring->head may point to the first byte right after the
|
|
|
|
|
* last byte of the dma buffer:
|
|
|
|
|
* 0 <= ring->head <= sport->rx_sgl.length
|
|
|
|
|
*
|
|
|
|
|
* However ring->tail must always points inside the dma buffer:
|
|
|
|
|
* 0 <= ring->tail <= sport->rx_sgl.length - 1
|
|
|
|
|
*
|
|
|
|
|
* Since we use a ring buffer, we have to handle the case
|
|
|
|
|
* where head is lower than tail. In such a case, we first read from
|
|
|
|
|
* tail to the end of the buffer then reset tail.
|
|
|
|
|
*/
|
|
|
|
|
if (ring->head < ring->tail) {
|
|
|
|
|
count = sport->rx_sgl.length - ring->tail;
|
|
|
|
|
|
|
|
|
|
tty_insert_flip_string(port, ring->buf + ring->tail, count);
|
|
|
|
|
ring->tail = 0;
|
|
|
|
|
sport->port.icount.rx += count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Finally we read data from tail to head */
|
|
|
|
|
if (ring->tail < ring->head) {
|
|
|
|
|
count = ring->head - ring->tail;
|
|
|
|
|
tty_insert_flip_string(port, ring->buf + ring->tail, count);
|
|
|
|
|
/* Wrap ring->head if needed */
|
|
|
|
|
if (ring->head >= sport->rx_sgl.length)
|
|
|
|
|
ring->head = 0;
|
|
|
|
|
ring->tail = ring->head;
|
|
|
|
|
sport->port.icount.rx += count;
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-04 16:11:44 +00:00
|
|
|
|
exit:
|
2020-03-06 21:44:31 +00:00
|
|
|
|
dma_sync_sg_for_device(chan->device->dev, &sport->rx_sgl, 1,
|
2016-07-19 07:43:07 +00:00
|
|
|
|
DMA_FROM_DEVICE);
|
|
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&sport->port.lock, flags);
|
|
|
|
|
|
|
|
|
|
tty_flip_buffer_push(port);
|
|
|
|
|
mod_timer(&sport->lpuart_timer, jiffies + sport->dma_rx_timeout);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void lpuart_dma_rx_complete(void *arg)
|
|
|
|
|
{
|
|
|
|
|
struct lpuart_port *sport = arg;
|
|
|
|
|
|
|
|
|
|
lpuart_copy_rx_to_tty(sport);
|
|
|
|
|
}
|
|
|
|
|
|
treewide: setup_timer() -> timer_setup()
This converts all remaining cases of the old setup_timer() API into using
timer_setup(), where the callback argument is the structure already
holding the struct timer_list. These should have no behavioral changes,
since they just change which pointer is passed into the callback with
the same available pointers after conversion. It handles the following
examples, in addition to some other variations.
Casting from unsigned long:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
setup_timer(&ptr->my_timer, my_callback, ptr);
and forced object casts:
void my_callback(struct something *ptr)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, (unsigned long)ptr);
become:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
Direct function assignments:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
ptr->my_timer.function = my_callback;
have a temporary cast added, along with converting the args:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
ptr->my_timer.function = (TIMER_FUNC_TYPE)my_callback;
And finally, callbacks without a data assignment:
void my_callback(unsigned long data)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, 0);
have their argument renamed to verify they're unused during conversion:
void my_callback(struct timer_list *unused)
{
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
The conversion is done with the following Coccinelle script:
spatch --very-quiet --all-includes --include-headers \
-I ./arch/x86/include -I ./arch/x86/include/generated \
-I ./include -I ./arch/x86/include/uapi \
-I ./arch/x86/include/generated/uapi -I ./include/uapi \
-I ./include/generated/uapi --include ./include/linux/kconfig.h \
--dir . \
--cocci-file ~/src/data/timer_setup.cocci
@fix_address_of@
expression e;
@@
setup_timer(
-&(e)
+&e
, ...)
// Update any raw setup_timer() usages that have a NULL callback, but
// would otherwise match change_timer_function_usage, since the latter
// will update all function assignments done in the face of a NULL
// function initialization in setup_timer().
@change_timer_function_usage_NULL@
expression _E;
identifier _timer;
type _cast_data;
@@
(
-setup_timer(&_E->_timer, NULL, _E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E->_timer, NULL, (_cast_data)_E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, &_E);
+timer_setup(&_E._timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, (_cast_data)&_E);
+timer_setup(&_E._timer, NULL, 0);
)
@change_timer_function_usage@
expression _E;
identifier _timer;
struct timer_list _stl;
identifier _callback;
type _cast_func, _cast_data;
@@
(
-setup_timer(&_E->_timer, _callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
_E->_timer@_stl.function = _callback;
|
_E->_timer@_stl.function = &_callback;
|
_E->_timer@_stl.function = (_cast_func)_callback;
|
_E->_timer@_stl.function = (_cast_func)&_callback;
|
_E._timer@_stl.function = _callback;
|
_E._timer@_stl.function = &_callback;
|
_E._timer@_stl.function = (_cast_func)_callback;
|
_E._timer@_stl.function = (_cast_func)&_callback;
)
// callback(unsigned long arg)
@change_callback_handle_cast
depends on change_timer_function_usage@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
identifier _handle;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
(
... when != _origarg
_handletype *_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
)
}
// callback(unsigned long arg) without existing variable
@change_callback_handle_cast_no_arg
depends on change_timer_function_usage &&
!change_callback_handle_cast@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
+ _handletype *_origarg = from_timer(_origarg, t, _timer);
+
... when != _origarg
- (_handletype *)_origarg
+ _origarg
... when != _origarg
}
// Avoid already converted callbacks.
@match_callback_converted
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier t;
@@
void _callback(struct timer_list *t)
{ ... }
// callback(struct something *handle)
@change_callback_handle_arg
depends on change_timer_function_usage &&
!match_callback_converted &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
@@
void _callback(
-_handletype *_handle
+struct timer_list *t
)
{
+ _handletype *_handle = from_timer(_handle, t, _timer);
...
}
// If change_callback_handle_arg ran on an empty function, remove
// the added handler.
@unchange_callback_handle_arg
depends on change_timer_function_usage &&
change_callback_handle_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
identifier t;
@@
void _callback(struct timer_list *t)
{
- _handletype *_handle = from_timer(_handle, t, _timer);
}
// We only want to refactor the setup_timer() data argument if we've found
// the matching callback. This undoes changes in change_timer_function_usage.
@unchange_timer_function_usage
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg &&
!change_callback_handle_arg@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type change_timer_function_usage._cast_data;
@@
(
-timer_setup(&_E->_timer, _callback, 0);
+setup_timer(&_E->_timer, _callback, (_cast_data)_E);
|
-timer_setup(&_E._timer, _callback, 0);
+setup_timer(&_E._timer, _callback, (_cast_data)&_E);
)
// If we fixed a callback from a .function assignment, fix the
// assignment cast now.
@change_timer_function_assignment
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_func;
typedef TIMER_FUNC_TYPE;
@@
(
_E->_timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-&_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
)
// Sometimes timer functions are called directly. Replace matched args.
@change_timer_function_calls
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression _E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_data;
@@
_callback(
(
-(_cast_data)_E
+&_E->_timer
|
-(_cast_data)&_E
+&_E._timer
|
-_E
+&_E->_timer
)
)
// If a timer has been configured without a data argument, it can be
// converted without regard to the callback argument, since it is unused.
@match_timer_function_unused_data@
expression _E;
identifier _timer;
identifier _callback;
@@
(
-setup_timer(&_E->_timer, _callback, 0);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0L);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0UL);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0L);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0UL);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0L);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0UL);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0L);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0UL);
+timer_setup(_timer, _callback, 0);
)
@change_callback_unused_data
depends on match_timer_function_unused_data@
identifier match_timer_function_unused_data._callback;
type _origtype;
identifier _origarg;
@@
void _callback(
-_origtype _origarg
+struct timer_list *unused
)
{
... when != _origarg
}
Signed-off-by: Kees Cook <keescook@chromium.org>
2017-10-16 21:43:17 +00:00
|
|
|
|
static void lpuart_timer_func(struct timer_list *t)
|
2016-07-19 07:43:07 +00:00
|
|
|
|
{
|
treewide: setup_timer() -> timer_setup()
This converts all remaining cases of the old setup_timer() API into using
timer_setup(), where the callback argument is the structure already
holding the struct timer_list. These should have no behavioral changes,
since they just change which pointer is passed into the callback with
the same available pointers after conversion. It handles the following
examples, in addition to some other variations.
Casting from unsigned long:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
setup_timer(&ptr->my_timer, my_callback, ptr);
and forced object casts:
void my_callback(struct something *ptr)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, (unsigned long)ptr);
become:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
Direct function assignments:
void my_callback(unsigned long data)
{
struct something *ptr = (struct something *)data;
...
}
...
ptr->my_timer.function = my_callback;
have a temporary cast added, along with converting the args:
void my_callback(struct timer_list *t)
{
struct something *ptr = from_timer(ptr, t, my_timer);
...
}
...
ptr->my_timer.function = (TIMER_FUNC_TYPE)my_callback;
And finally, callbacks without a data assignment:
void my_callback(unsigned long data)
{
...
}
...
setup_timer(&ptr->my_timer, my_callback, 0);
have their argument renamed to verify they're unused during conversion:
void my_callback(struct timer_list *unused)
{
...
}
...
timer_setup(&ptr->my_timer, my_callback, 0);
The conversion is done with the following Coccinelle script:
spatch --very-quiet --all-includes --include-headers \
-I ./arch/x86/include -I ./arch/x86/include/generated \
-I ./include -I ./arch/x86/include/uapi \
-I ./arch/x86/include/generated/uapi -I ./include/uapi \
-I ./include/generated/uapi --include ./include/linux/kconfig.h \
--dir . \
--cocci-file ~/src/data/timer_setup.cocci
@fix_address_of@
expression e;
@@
setup_timer(
-&(e)
+&e
, ...)
// Update any raw setup_timer() usages that have a NULL callback, but
// would otherwise match change_timer_function_usage, since the latter
// will update all function assignments done in the face of a NULL
// function initialization in setup_timer().
@change_timer_function_usage_NULL@
expression _E;
identifier _timer;
type _cast_data;
@@
(
-setup_timer(&_E->_timer, NULL, _E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E->_timer, NULL, (_cast_data)_E);
+timer_setup(&_E->_timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, &_E);
+timer_setup(&_E._timer, NULL, 0);
|
-setup_timer(&_E._timer, NULL, (_cast_data)&_E);
+timer_setup(&_E._timer, NULL, 0);
)
@change_timer_function_usage@
expression _E;
identifier _timer;
struct timer_list _stl;
identifier _callback;
type _cast_func, _cast_data;
@@
(
-setup_timer(&_E->_timer, _callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, &_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, _E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, &_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)_E);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, (_cast_func)&_callback, (_cast_data)&_E);
+timer_setup(&_E._timer, _callback, 0);
|
_E->_timer@_stl.function = _callback;
|
_E->_timer@_stl.function = &_callback;
|
_E->_timer@_stl.function = (_cast_func)_callback;
|
_E->_timer@_stl.function = (_cast_func)&_callback;
|
_E._timer@_stl.function = _callback;
|
_E._timer@_stl.function = &_callback;
|
_E._timer@_stl.function = (_cast_func)_callback;
|
_E._timer@_stl.function = (_cast_func)&_callback;
)
// callback(unsigned long arg)
@change_callback_handle_cast
depends on change_timer_function_usage@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
identifier _handle;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
(
... when != _origarg
_handletype *_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(_handletype *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
|
... when != _origarg
_handletype *_handle;
... when != _handle
_handle =
-(void *)_origarg;
+from_timer(_handle, t, _timer);
... when != _origarg
)
}
// callback(unsigned long arg) without existing variable
@change_callback_handle_cast_no_arg
depends on change_timer_function_usage &&
!change_callback_handle_cast@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _origtype;
identifier _origarg;
type _handletype;
@@
void _callback(
-_origtype _origarg
+struct timer_list *t
)
{
+ _handletype *_origarg = from_timer(_origarg, t, _timer);
+
... when != _origarg
- (_handletype *)_origarg
+ _origarg
... when != _origarg
}
// Avoid already converted callbacks.
@match_callback_converted
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier t;
@@
void _callback(struct timer_list *t)
{ ... }
// callback(struct something *handle)
@change_callback_handle_arg
depends on change_timer_function_usage &&
!match_callback_converted &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
@@
void _callback(
-_handletype *_handle
+struct timer_list *t
)
{
+ _handletype *_handle = from_timer(_handle, t, _timer);
...
}
// If change_callback_handle_arg ran on an empty function, remove
// the added handler.
@unchange_callback_handle_arg
depends on change_timer_function_usage &&
change_callback_handle_arg@
identifier change_timer_function_usage._callback;
identifier change_timer_function_usage._timer;
type _handletype;
identifier _handle;
identifier t;
@@
void _callback(struct timer_list *t)
{
- _handletype *_handle = from_timer(_handle, t, _timer);
}
// We only want to refactor the setup_timer() data argument if we've found
// the matching callback. This undoes changes in change_timer_function_usage.
@unchange_timer_function_usage
depends on change_timer_function_usage &&
!change_callback_handle_cast &&
!change_callback_handle_cast_no_arg &&
!change_callback_handle_arg@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type change_timer_function_usage._cast_data;
@@
(
-timer_setup(&_E->_timer, _callback, 0);
+setup_timer(&_E->_timer, _callback, (_cast_data)_E);
|
-timer_setup(&_E._timer, _callback, 0);
+setup_timer(&_E._timer, _callback, (_cast_data)&_E);
)
// If we fixed a callback from a .function assignment, fix the
// assignment cast now.
@change_timer_function_assignment
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression change_timer_function_usage._E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_func;
typedef TIMER_FUNC_TYPE;
@@
(
_E->_timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E->_timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-&_callback;
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)_callback
+(TIMER_FUNC_TYPE)_callback
;
|
_E._timer.function =
-(_cast_func)&_callback
+(TIMER_FUNC_TYPE)_callback
;
)
// Sometimes timer functions are called directly. Replace matched args.
@change_timer_function_calls
depends on change_timer_function_usage &&
(change_callback_handle_cast ||
change_callback_handle_cast_no_arg ||
change_callback_handle_arg)@
expression _E;
identifier change_timer_function_usage._timer;
identifier change_timer_function_usage._callback;
type _cast_data;
@@
_callback(
(
-(_cast_data)_E
+&_E->_timer
|
-(_cast_data)&_E
+&_E._timer
|
-_E
+&_E->_timer
)
)
// If a timer has been configured without a data argument, it can be
// converted without regard to the callback argument, since it is unused.
@match_timer_function_unused_data@
expression _E;
identifier _timer;
identifier _callback;
@@
(
-setup_timer(&_E->_timer, _callback, 0);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0L);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E->_timer, _callback, 0UL);
+timer_setup(&_E->_timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0L);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_E._timer, _callback, 0UL);
+timer_setup(&_E._timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0L);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(&_timer, _callback, 0UL);
+timer_setup(&_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0L);
+timer_setup(_timer, _callback, 0);
|
-setup_timer(_timer, _callback, 0UL);
+timer_setup(_timer, _callback, 0);
)
@change_callback_unused_data
depends on match_timer_function_unused_data@
identifier match_timer_function_unused_data._callback;
type _origtype;
identifier _origarg;
@@
void _callback(
-_origtype _origarg
+struct timer_list *unused
)
{
... when != _origarg
}
Signed-off-by: Kees Cook <keescook@chromium.org>
2017-10-16 21:43:17 +00:00
|
|
|
|
struct lpuart_port *sport = from_timer(sport, t, lpuart_timer);
|
2016-07-19 07:43:07 +00:00
|
|
|
|
|
|
|
|
|
lpuart_copy_rx_to_tty(sport);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline int lpuart_start_rx_dma(struct lpuart_port *sport)
|
|
|
|
|
{
|
|
|
|
|
struct dma_slave_config dma_rx_sconfig = {};
|
|
|
|
|
struct circ_buf *ring = &sport->rx_ring;
|
|
|
|
|
int ret, nent;
|
|
|
|
|
int bits, baud;
|
2018-08-28 10:44:24 +00:00
|
|
|
|
struct tty_port *port = &sport->port.state->port;
|
|
|
|
|
struct tty_struct *tty = port->tty;
|
2016-07-19 07:43:07 +00:00
|
|
|
|
struct ktermios *termios = &tty->termios;
|
2020-03-06 21:44:31 +00:00
|
|
|
|
struct dma_chan *chan = sport->dma_rx_chan;
|
2016-07-19 07:43:07 +00:00
|
|
|
|
|
|
|
|
|
baud = tty_get_baud_rate(tty);
|
|
|
|
|
|
|
|
|
|
bits = (termios->c_cflag & CSIZE) == CS7 ? 9 : 10;
|
|
|
|
|
if (termios->c_cflag & PARENB)
|
|
|
|
|
bits++;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Calculate length of one DMA buffer size to keep latency below
|
|
|
|
|
* 10ms at any baud rate.
|
|
|
|
|
*/
|
|
|
|
|
sport->rx_dma_rng_buf_len = (DMA_RX_TIMEOUT * baud / bits / 1000) * 2;
|
|
|
|
|
sport->rx_dma_rng_buf_len = (1 << (fls(sport->rx_dma_rng_buf_len) - 1));
|
|
|
|
|
if (sport->rx_dma_rng_buf_len < 16)
|
|
|
|
|
sport->rx_dma_rng_buf_len = 16;
|
|
|
|
|
|
2019-07-17 05:19:28 +00:00
|
|
|
|
ring->buf = kzalloc(sport->rx_dma_rng_buf_len, GFP_ATOMIC);
|
2019-06-11 13:03:39 +00:00
|
|
|
|
if (!ring->buf)
|
2016-07-19 07:43:07 +00:00
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
|
|
sg_init_one(&sport->rx_sgl, ring->buf, sport->rx_dma_rng_buf_len);
|
2020-03-06 21:44:31 +00:00
|
|
|
|
nent = dma_map_sg(chan->device->dev, &sport->rx_sgl, 1,
|
|
|
|
|
DMA_FROM_DEVICE);
|
2016-07-19 07:43:07 +00:00
|
|
|
|
|
|
|
|
|
if (!nent) {
|
|
|
|
|
dev_err(sport->port.dev, "DMA Rx mapping error\n");
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
2019-01-23 03:20:17 +00:00
|
|
|
|
dma_rx_sconfig.src_addr = lpuart_dma_datareg_addr(sport);
|
2016-07-19 07:43:07 +00:00
|
|
|
|
dma_rx_sconfig.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
|
|
|
|
|
dma_rx_sconfig.src_maxburst = 1;
|
|
|
|
|
dma_rx_sconfig.direction = DMA_DEV_TO_MEM;
|
2020-03-06 21:44:31 +00:00
|
|
|
|
ret = dmaengine_slave_config(chan, &dma_rx_sconfig);
|
2016-07-19 07:43:07 +00:00
|
|
|
|
|
|
|
|
|
if (ret < 0) {
|
|
|
|
|
dev_err(sport->port.dev,
|
|
|
|
|
"DMA Rx slave config failed, err = %d\n", ret);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-06 21:44:31 +00:00
|
|
|
|
sport->dma_rx_desc = dmaengine_prep_dma_cyclic(chan,
|
2016-07-19 07:43:07 +00:00
|
|
|
|
sg_dma_address(&sport->rx_sgl),
|
|
|
|
|
sport->rx_sgl.length,
|
|
|
|
|
sport->rx_sgl.length / 2,
|
|
|
|
|
DMA_DEV_TO_MEM,
|
|
|
|
|
DMA_PREP_INTERRUPT);
|
|
|
|
|
if (!sport->dma_rx_desc) {
|
|
|
|
|
dev_err(sport->port.dev, "Cannot prepare cyclic DMA\n");
|
|
|
|
|
return -EFAULT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sport->dma_rx_desc->callback = lpuart_dma_rx_complete;
|
|
|
|
|
sport->dma_rx_desc->callback_param = sport;
|
|
|
|
|
sport->dma_rx_cookie = dmaengine_submit(sport->dma_rx_desc);
|
2020-03-06 21:44:31 +00:00
|
|
|
|
dma_async_issue_pending(chan);
|
2016-07-19 07:43:07 +00:00
|
|
|
|
|
2019-01-23 03:20:17 +00:00
|
|
|
|
if (lpuart_is_32(sport)) {
|
|
|
|
|
unsigned long temp = lpuart32_read(&sport->port, UARTBAUD);
|
|
|
|
|
|
|
|
|
|
lpuart32_write(&sport->port, temp | UARTBAUD_RDMAE, UARTBAUD);
|
|
|
|
|
} else {
|
|
|
|
|
writeb(readb(sport->port.membase + UARTCR5) | UARTCR5_RDMAS,
|
|
|
|
|
sport->port.membase + UARTCR5);
|
|
|
|
|
}
|
2016-07-19 07:43:07 +00:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void lpuart_dma_rx_free(struct uart_port *port)
|
|
|
|
|
{
|
|
|
|
|
struct lpuart_port *sport = container_of(port,
|
|
|
|
|
struct lpuart_port, port);
|
2020-03-06 21:44:31 +00:00
|
|
|
|
struct dma_chan *chan = sport->dma_rx_chan;
|
2016-07-19 07:43:07 +00:00
|
|
|
|
|
2020-04-03 17:49:42 +00:00
|
|
|
|
dmaengine_terminate_all(chan);
|
2020-03-06 21:44:31 +00:00
|
|
|
|
dma_unmap_sg(chan->device->dev, &sport->rx_sgl, 1, DMA_FROM_DEVICE);
|
2016-07-19 07:43:07 +00:00
|
|
|
|
kfree(sport->rx_ring.buf);
|
|
|
|
|
sport->rx_ring.tail = 0;
|
|
|
|
|
sport->rx_ring.head = 0;
|
|
|
|
|
sport->dma_rx_desc = NULL;
|
|
|
|
|
sport->dma_rx_cookie = -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-19 07:43:10 +00:00
|
|
|
|
static int lpuart_config_rs485(struct uart_port *port,
|
|
|
|
|
struct serial_rs485 *rs485)
|
|
|
|
|
{
|
|
|
|
|
struct lpuart_port *sport = container_of(port,
|
|
|
|
|
struct lpuart_port, port);
|
|
|
|
|
|
|
|
|
|
u8 modem = readb(sport->port.membase + UARTMODEM) &
|
|
|
|
|
~(UARTMODEM_TXRTSPOL | UARTMODEM_TXRTSE);
|
|
|
|
|
writeb(modem, sport->port.membase + UARTMODEM);
|
|
|
|
|
|
2017-07-18 10:59:40 +00:00
|
|
|
|
/* clear unsupported configurations */
|
|
|
|
|
rs485->delay_rts_before_send = 0;
|
|
|
|
|
rs485->delay_rts_after_send = 0;
|
|
|
|
|
rs485->flags &= ~SER_RS485_RX_DURING_TX;
|
|
|
|
|
|
2016-07-19 07:43:10 +00:00
|
|
|
|
if (rs485->flags & SER_RS485_ENABLED) {
|
|
|
|
|
/* Enable auto RS-485 RTS mode */
|
|
|
|
|
modem |= UARTMODEM_TXRTSE;
|
|
|
|
|
|
|
|
|
|
/*
|
2020-08-18 22:44:57 +00:00
|
|
|
|
* RTS needs to be logic HIGH either during transfer _or_ after
|
2016-07-19 07:43:10 +00:00
|
|
|
|
* transfer, other variants are not supported by the hardware.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (!(rs485->flags & (SER_RS485_RTS_ON_SEND |
|
|
|
|
|
SER_RS485_RTS_AFTER_SEND)))
|
|
|
|
|
rs485->flags |= SER_RS485_RTS_ON_SEND;
|
|
|
|
|
|
|
|
|
|
if (rs485->flags & SER_RS485_RTS_ON_SEND &&
|
|
|
|
|
rs485->flags & SER_RS485_RTS_AFTER_SEND)
|
|
|
|
|
rs485->flags &= ~SER_RS485_RTS_AFTER_SEND;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The hardware defaults to RTS logic HIGH while transfer.
|
|
|
|
|
* Switch polarity in case RTS shall be logic HIGH
|
|
|
|
|
* after transfer.
|
|
|
|
|
* Note: UART is assumed to be active high.
|
|
|
|
|
*/
|
|
|
|
|
if (rs485->flags & SER_RS485_RTS_ON_SEND)
|
|
|
|
|
modem &= ~UARTMODEM_TXRTSPOL;
|
|
|
|
|
else if (rs485->flags & SER_RS485_RTS_AFTER_SEND)
|
|
|
|
|
modem |= UARTMODEM_TXRTSPOL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Store the new configuration */
|
|
|
|
|
sport->port.rs485 = *rs485;
|
|
|
|
|
|
|
|
|
|
writeb(modem, sport->port.membase + UARTMODEM);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-17 14:14:42 +00:00
|
|
|
|
static int lpuart32_config_rs485(struct uart_port *port,
|
|
|
|
|
struct serial_rs485 *rs485)
|
|
|
|
|
{
|
|
|
|
|
struct lpuart_port *sport = container_of(port,
|
|
|
|
|
struct lpuart_port, port);
|
|
|
|
|
|
|
|
|
|
unsigned long modem = lpuart32_read(&sport->port, UARTMODIR)
|
|
|
|
|
& ~(UARTMODEM_TXRTSPOL | UARTMODEM_TXRTSE);
|
|
|
|
|
lpuart32_write(&sport->port, modem, UARTMODIR);
|
|
|
|
|
|
|
|
|
|
/* clear unsupported configurations */
|
|
|
|
|
rs485->delay_rts_before_send = 0;
|
|
|
|
|
rs485->delay_rts_after_send = 0;
|
|
|
|
|
rs485->flags &= ~SER_RS485_RX_DURING_TX;
|
|
|
|
|
|
|
|
|
|
if (rs485->flags & SER_RS485_ENABLED) {
|
|
|
|
|
/* Enable auto RS-485 RTS mode */
|
|
|
|
|
modem |= UARTMODEM_TXRTSE;
|
|
|
|
|
|
|
|
|
|
/*
|
2020-08-18 22:44:57 +00:00
|
|
|
|
* RTS needs to be logic HIGH either during transfer _or_ after
|
2019-10-17 14:14:42 +00:00
|
|
|
|
* transfer, other variants are not supported by the hardware.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (!(rs485->flags & (SER_RS485_RTS_ON_SEND |
|
|
|
|
|
SER_RS485_RTS_AFTER_SEND)))
|
|
|
|
|
rs485->flags |= SER_RS485_RTS_ON_SEND;
|
|
|
|
|
|
|
|
|
|
if (rs485->flags & SER_RS485_RTS_ON_SEND &&
|
|
|
|
|
rs485->flags & SER_RS485_RTS_AFTER_SEND)
|
|
|
|
|
rs485->flags &= ~SER_RS485_RTS_AFTER_SEND;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The hardware defaults to RTS logic HIGH while transfer.
|
|
|
|
|
* Switch polarity in case RTS shall be logic HIGH
|
|
|
|
|
* after transfer.
|
|
|
|
|
* Note: UART is assumed to be active high.
|
|
|
|
|
*/
|
|
|
|
|
if (rs485->flags & SER_RS485_RTS_ON_SEND)
|
|
|
|
|
modem &= ~UARTMODEM_TXRTSPOL;
|
|
|
|
|
else if (rs485->flags & SER_RS485_RTS_AFTER_SEND)
|
|
|
|
|
modem |= UARTMODEM_TXRTSPOL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Store the new configuration */
|
|
|
|
|
sport->port.rs485 = *rs485;
|
|
|
|
|
|
|
|
|
|
lpuart32_write(&sport->port, modem, UARTMODIR);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-07 01:20:40 +00:00
|
|
|
|
static unsigned int lpuart_get_mctrl(struct uart_port *port)
|
|
|
|
|
{
|
|
|
|
|
unsigned int temp = 0;
|
|
|
|
|
unsigned char reg;
|
|
|
|
|
|
|
|
|
|
reg = readb(port->membase + UARTMODEM);
|
|
|
|
|
if (reg & UARTMODEM_TXCTSE)
|
|
|
|
|
temp |= TIOCM_CTS;
|
|
|
|
|
|
|
|
|
|
if (reg & UARTMODEM_RXRTSE)
|
|
|
|
|
temp |= TIOCM_RTS;
|
|
|
|
|
|
|
|
|
|
return temp;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-14 09:41:11 +00:00
|
|
|
|
static unsigned int lpuart32_get_mctrl(struct uart_port *port)
|
|
|
|
|
{
|
|
|
|
|
unsigned int temp = 0;
|
|
|
|
|
unsigned long reg;
|
|
|
|
|
|
2017-06-13 02:55:49 +00:00
|
|
|
|
reg = lpuart32_read(port, UARTMODIR);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
if (reg & UARTMODIR_TXCTSE)
|
|
|
|
|
temp |= TIOCM_CTS;
|
|
|
|
|
|
|
|
|
|
if (reg & UARTMODIR_RXRTSE)
|
|
|
|
|
temp |= TIOCM_RTS;
|
|
|
|
|
|
|
|
|
|
return temp;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-07 01:20:40 +00:00
|
|
|
|
static void lpuart_set_mctrl(struct uart_port *port, unsigned int mctrl)
|
|
|
|
|
{
|
|
|
|
|
unsigned char temp;
|
2016-07-19 07:43:10 +00:00
|
|
|
|
struct lpuart_port *sport = container_of(port,
|
|
|
|
|
struct lpuart_port, port);
|
2013-06-07 01:20:40 +00:00
|
|
|
|
|
2016-07-19 07:43:10 +00:00
|
|
|
|
/* Make sure RXRTSE bit is not set when RS485 is enabled */
|
|
|
|
|
if (!(sport->port.rs485.flags & SER_RS485_ENABLED)) {
|
|
|
|
|
temp = readb(sport->port.membase + UARTMODEM) &
|
2013-06-07 01:20:40 +00:00
|
|
|
|
~(UARTMODEM_RXRTSE | UARTMODEM_TXCTSE);
|
|
|
|
|
|
2016-07-19 07:43:10 +00:00
|
|
|
|
if (mctrl & TIOCM_RTS)
|
|
|
|
|
temp |= UARTMODEM_RXRTSE;
|
2013-06-07 01:20:40 +00:00
|
|
|
|
|
2016-07-19 07:43:10 +00:00
|
|
|
|
if (mctrl & TIOCM_CTS)
|
|
|
|
|
temp |= UARTMODEM_TXCTSE;
|
2013-06-07 01:20:40 +00:00
|
|
|
|
|
2016-07-19 07:43:10 +00:00
|
|
|
|
writeb(temp, port->membase + UARTMODEM);
|
|
|
|
|
}
|
2013-06-07 01:20:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-14 09:41:11 +00:00
|
|
|
|
static void lpuart32_set_mctrl(struct uart_port *port, unsigned int mctrl)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-07 01:20:40 +00:00
|
|
|
|
static void lpuart_break_ctl(struct uart_port *port, int break_state)
|
|
|
|
|
{
|
|
|
|
|
unsigned char temp;
|
|
|
|
|
|
|
|
|
|
temp = readb(port->membase + UARTCR2) & ~UARTCR2_SBK;
|
|
|
|
|
|
|
|
|
|
if (break_state != 0)
|
|
|
|
|
temp |= UARTCR2_SBK;
|
|
|
|
|
|
|
|
|
|
writeb(temp, port->membase + UARTCR2);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-14 09:41:11 +00:00
|
|
|
|
static void lpuart32_break_ctl(struct uart_port *port, int break_state)
|
|
|
|
|
{
|
|
|
|
|
unsigned long temp;
|
|
|
|
|
|
2017-06-13 02:55:49 +00:00
|
|
|
|
temp = lpuart32_read(port, UARTCTRL) & ~UARTCTRL_SBK;
|
2014-07-14 09:41:11 +00:00
|
|
|
|
|
|
|
|
|
if (break_state != 0)
|
|
|
|
|
temp |= UARTCTRL_SBK;
|
|
|
|
|
|
2017-06-13 02:55:49 +00:00
|
|
|
|
lpuart32_write(port, temp, UARTCTRL);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-07 01:20:40 +00:00
|
|
|
|
static void lpuart_setup_watermark(struct lpuart_port *sport)
|
|
|
|
|
{
|
|
|
|
|
unsigned char val, cr2;
|
2013-07-08 07:53:38 +00:00
|
|
|
|
unsigned char cr2_saved;
|
2013-06-07 01:20:40 +00:00
|
|
|
|
|
|
|
|
|
cr2 = readb(sport->port.membase + UARTCR2);
|
2013-07-08 07:53:38 +00:00
|
|
|
|
cr2_saved = cr2;
|
2013-06-07 01:20:40 +00:00
|
|
|
|
cr2 &= ~(UARTCR2_TIE | UARTCR2_TCIE | UARTCR2_TE |
|
|
|
|
|
UARTCR2_RIE | UARTCR2_RE);
|
|
|
|
|
writeb(cr2, sport->port.membase + UARTCR2);
|
|
|
|
|
|
|
|
|
|
val = readb(sport->port.membase + UARTPFIFO);
|
|
|
|
|
writeb(val | UARTPFIFO_TXFE | UARTPFIFO_RXFE,
|
|
|
|
|
sport->port.membase + UARTPFIFO);
|
|
|
|
|
|
|
|
|
|
/* flush Tx and Rx FIFO */
|
|
|
|
|
writeb(UARTCFIFO_TXFLUSH | UARTCFIFO_RXFLUSH,
|
|
|
|
|
sport->port.membase + UARTCFIFO);
|
|
|
|
|
|
2016-07-19 07:43:05 +00:00
|
|
|
|
/* explicitly clear RDRF */
|
|
|
|
|
if (readb(sport->port.membase + UARTSR1) & UARTSR1_RDRF) {
|
|
|
|
|
readb(sport->port.membase + UARTDR);
|
|
|
|
|
writeb(UARTSFIFO_RXUF, sport->port.membase + UARTSFIFO);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-17 05:28:07 +00:00
|
|
|
|
writeb(0, sport->port.membase + UARTTWFIFO);
|
2013-06-07 01:20:40 +00:00
|
|
|
|
writeb(1, sport->port.membase + UARTRWFIFO);
|
2013-07-08 07:53:38 +00:00
|
|
|
|
|
|
|
|
|
/* Restore cr2 */
|
|
|
|
|
writeb(cr2_saved, sport->port.membase + UARTCR2);
|
2013-06-07 01:20:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-05 18:56:59 +00:00
|
|
|
|
static void lpuart_setup_watermark_enable(struct lpuart_port *sport)
|
|
|
|
|
{
|
|
|
|
|
unsigned char cr2;
|
|
|
|
|
|
|
|
|
|
lpuart_setup_watermark(sport);
|
|
|
|
|
|
|
|
|
|
cr2 = readb(sport->port.membase + UARTCR2);
|
2019-08-05 18:57:00 +00:00
|
|
|
|
cr2 |= UARTCR2_RIE | UARTCR2_RE | UARTCR2_TE;
|
2019-08-05 18:56:59 +00:00
|
|
|
|
writeb(cr2, sport->port.membase + UARTCR2);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-14 09:41:11 +00:00
|
|
|
|
static void lpuart32_setup_watermark(struct lpuart_port *sport)
|
|
|
|
|
{
|
|
|
|
|
unsigned long val, ctrl;
|
|
|
|
|
unsigned long ctrl_saved;
|
|
|
|
|
|
2017-06-13 02:55:49 +00:00
|
|
|
|
ctrl = lpuart32_read(&sport->port, UARTCTRL);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
ctrl_saved = ctrl;
|
|
|
|
|
ctrl &= ~(UARTCTRL_TIE | UARTCTRL_TCIE | UARTCTRL_TE |
|
|
|
|
|
UARTCTRL_RIE | UARTCTRL_RE);
|
2017-06-13 02:55:49 +00:00
|
|
|
|
lpuart32_write(&sport->port, ctrl, UARTCTRL);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
|
|
|
|
|
/* enable FIFO mode */
|
2017-06-13 02:55:49 +00:00
|
|
|
|
val = lpuart32_read(&sport->port, UARTFIFO);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
val |= UARTFIFO_TXFE | UARTFIFO_RXFE;
|
|
|
|
|
val |= UARTFIFO_TXFLUSH | UARTFIFO_RXFLUSH;
|
2017-06-13 02:55:49 +00:00
|
|
|
|
lpuart32_write(&sport->port, val, UARTFIFO);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
|
|
|
|
|
/* set the watermark */
|
|
|
|
|
val = (0x1 << UARTWATER_RXWATER_OFF) | (0x0 << UARTWATER_TXWATER_OFF);
|
2017-06-13 02:55:49 +00:00
|
|
|
|
lpuart32_write(&sport->port, val, UARTWATER);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
|
|
|
|
|
/* Restore cr2 */
|
2017-06-13 02:55:49 +00:00
|
|
|
|
lpuart32_write(&sport->port, ctrl_saved, UARTCTRL);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-05 18:56:59 +00:00
|
|
|
|
static void lpuart32_setup_watermark_enable(struct lpuart_port *sport)
|
|
|
|
|
{
|
|
|
|
|
u32 temp;
|
|
|
|
|
|
|
|
|
|
lpuart32_setup_watermark(sport);
|
|
|
|
|
|
|
|
|
|
temp = lpuart32_read(&sport->port, UARTCTRL);
|
|
|
|
|
temp |= UARTCTRL_RE | UARTCTRL_TE | UARTCTRL_ILIE;
|
|
|
|
|
lpuart32_write(&sport->port, temp, UARTCTRL);
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-19 07:43:07 +00:00
|
|
|
|
static void rx_dma_timer_init(struct lpuart_port *sport)
|
2014-02-17 05:28:07 +00:00
|
|
|
|
{
|
2019-07-29 19:52:07 +00:00
|
|
|
|
timer_setup(&sport->lpuart_timer, lpuart_timer_func, 0);
|
|
|
|
|
sport->lpuart_timer.expires = jiffies + sport->dma_rx_timeout;
|
|
|
|
|
add_timer(&sport->lpuart_timer);
|
2014-02-17 05:28:07 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-25 09:06:57 +00:00
|
|
|
|
static void lpuart_request_dma(struct lpuart_port *sport)
|
2019-08-05 18:56:56 +00:00
|
|
|
|
{
|
2020-03-06 21:44:30 +00:00
|
|
|
|
sport->dma_tx_chan = dma_request_chan(sport->port.dev, "tx");
|
|
|
|
|
if (IS_ERR(sport->dma_tx_chan)) {
|
2020-04-16 15:34:53 +00:00
|
|
|
|
dev_dbg_once(sport->port.dev,
|
|
|
|
|
"DMA tx channel request failed, operating without tx DMA (%ld)\n",
|
|
|
|
|
PTR_ERR(sport->dma_tx_chan));
|
2020-03-06 21:44:30 +00:00
|
|
|
|
sport->dma_tx_chan = NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-25 09:06:57 +00:00
|
|
|
|
sport->dma_rx_chan = dma_request_chan(sport->port.dev, "rx");
|
|
|
|
|
if (IS_ERR(sport->dma_rx_chan)) {
|
2020-04-16 15:34:53 +00:00
|
|
|
|
dev_dbg_once(sport->port.dev,
|
|
|
|
|
"DMA rx channel request failed, operating without rx DMA (%ld)\n",
|
|
|
|
|
PTR_ERR(sport->dma_rx_chan));
|
2020-03-25 09:06:57 +00:00
|
|
|
|
sport->dma_rx_chan = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void lpuart_tx_dma_startup(struct lpuart_port *sport)
|
|
|
|
|
{
|
|
|
|
|
u32 uartbaud;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
if (!sport->dma_tx_chan)
|
|
|
|
|
goto err;
|
|
|
|
|
|
2020-03-06 21:44:30 +00:00
|
|
|
|
ret = lpuart_dma_tx_request(&sport->port);
|
2020-03-25 09:06:58 +00:00
|
|
|
|
if (ret)
|
2020-03-06 21:44:30 +00:00
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
|
|
init_waitqueue_head(&sport->dma_wait);
|
|
|
|
|
sport->lpuart_dma_tx_use = true;
|
|
|
|
|
if (lpuart_is_32(sport)) {
|
|
|
|
|
uartbaud = lpuart32_read(&sport->port, UARTBAUD);
|
|
|
|
|
lpuart32_write(&sport->port,
|
|
|
|
|
uartbaud | UARTBAUD_TDMAE, UARTBAUD);
|
2019-08-05 18:56:56 +00:00
|
|
|
|
} else {
|
2020-03-06 21:44:30 +00:00
|
|
|
|
writeb(readb(sport->port.membase + UARTCR5) |
|
|
|
|
|
UARTCR5_TDMAS, sport->port.membase + UARTCR5);
|
2019-08-05 18:56:56 +00:00
|
|
|
|
}
|
2020-03-06 21:44:30 +00:00
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
err:
|
|
|
|
|
sport->lpuart_dma_tx_use = false;
|
2019-08-05 18:56:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-08-05 18:56:57 +00:00
|
|
|
|
static void lpuart_rx_dma_startup(struct lpuart_port *sport)
|
|
|
|
|
{
|
2020-03-06 21:44:30 +00:00
|
|
|
|
int ret;
|
2020-10-04 16:11:44 +00:00
|
|
|
|
unsigned char cr3;
|
2019-08-05 18:56:57 +00:00
|
|
|
|
|
2020-03-25 09:06:57 +00:00
|
|
|
|
if (!sport->dma_rx_chan)
|
2020-03-06 21:44:30 +00:00
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
|
|
ret = lpuart_start_rx_dma(sport);
|
|
|
|
|
if (ret)
|
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
|
|
/* set Rx DMA timeout */
|
|
|
|
|
sport->dma_rx_timeout = msecs_to_jiffies(DMA_RX_TIMEOUT);
|
|
|
|
|
if (!sport->dma_rx_timeout)
|
|
|
|
|
sport->dma_rx_timeout = 1;
|
|
|
|
|
|
|
|
|
|
sport->lpuart_dma_rx_use = true;
|
|
|
|
|
rx_dma_timer_init(sport);
|
|
|
|
|
|
2020-10-04 16:11:44 +00:00
|
|
|
|
if (sport->port.has_sysrq) {
|
|
|
|
|
cr3 = readb(sport->port.membase + UARTCR3);
|
|
|
|
|
cr3 |= UARTCR3_FEIE;
|
|
|
|
|
writeb(cr3, sport->port.membase + UARTCR3);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-06 21:44:30 +00:00
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
err:
|
|
|
|
|
sport->lpuart_dma_rx_use = false;
|
2019-08-05 18:56:57 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-07 01:20:40 +00:00
|
|
|
|
static int lpuart_startup(struct uart_port *port)
|
|
|
|
|
{
|
|
|
|
|
struct lpuart_port *sport = container_of(port, struct lpuart_port, port);
|
|
|
|
|
unsigned long flags;
|
|
|
|
|
unsigned char temp;
|
|
|
|
|
|
2014-07-02 16:02:57 +00:00
|
|
|
|
/* determine FIFO size and enable FIFO mode */
|
|
|
|
|
temp = readb(sport->port.membase + UARTPFIFO);
|
|
|
|
|
|
2019-07-17 05:19:30 +00:00
|
|
|
|
sport->txfifo_size = UARTFIFO_DEPTH((temp >> UARTPFIFO_TXSIZE_OFF) &
|
|
|
|
|
UARTPFIFO_FIFOSIZE_MASK);
|
2015-03-13 13:51:50 +00:00
|
|
|
|
sport->port.fifosize = sport->txfifo_size;
|
|
|
|
|
|
2019-07-17 05:19:30 +00:00
|
|
|
|
sport->rxfifo_size = UARTFIFO_DEPTH((temp >> UARTPFIFO_RXSIZE_OFF) &
|
|
|
|
|
UARTPFIFO_FIFOSIZE_MASK);
|
2014-07-02 16:02:57 +00:00
|
|
|
|
|
2020-03-25 09:06:57 +00:00
|
|
|
|
lpuart_request_dma(sport);
|
|
|
|
|
|
2013-06-07 01:20:40 +00:00
|
|
|
|
spin_lock_irqsave(&sport->port.lock, flags);
|
|
|
|
|
|
2019-08-05 18:56:59 +00:00
|
|
|
|
lpuart_setup_watermark_enable(sport);
|
2013-06-07 01:20:40 +00:00
|
|
|
|
|
2019-08-05 18:56:57 +00:00
|
|
|
|
lpuart_rx_dma_startup(sport);
|
2019-08-05 18:56:56 +00:00
|
|
|
|
lpuart_tx_dma_startup(sport);
|
2016-07-19 07:43:07 +00:00
|
|
|
|
|
2013-06-07 01:20:40 +00:00
|
|
|
|
spin_unlock_irqrestore(&sport->port.lock, flags);
|
2016-07-19 07:43:07 +00:00
|
|
|
|
|
2013-06-07 01:20:40 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-05 18:56:58 +00:00
|
|
|
|
static void lpuart32_configure(struct lpuart_port *sport)
|
|
|
|
|
{
|
|
|
|
|
unsigned long temp;
|
|
|
|
|
|
|
|
|
|
if (sport->lpuart_dma_rx_use) {
|
|
|
|
|
/* RXWATER must be 0 */
|
|
|
|
|
temp = lpuart32_read(&sport->port, UARTWATER);
|
|
|
|
|
temp &= ~(UARTWATER_WATER_MASK << UARTWATER_RXWATER_OFF);
|
|
|
|
|
lpuart32_write(&sport->port, temp, UARTWATER);
|
|
|
|
|
}
|
|
|
|
|
temp = lpuart32_read(&sport->port, UARTCTRL);
|
|
|
|
|
if (!sport->lpuart_dma_rx_use)
|
|
|
|
|
temp |= UARTCTRL_RIE;
|
|
|
|
|
if (!sport->lpuart_dma_tx_use)
|
|
|
|
|
temp |= UARTCTRL_TIE;
|
|
|
|
|
lpuart32_write(&sport->port, temp, UARTCTRL);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-14 09:41:11 +00:00
|
|
|
|
static int lpuart32_startup(struct uart_port *port)
|
|
|
|
|
{
|
|
|
|
|
struct lpuart_port *sport = container_of(port, struct lpuart_port, port);
|
|
|
|
|
unsigned long flags;
|
|
|
|
|
unsigned long temp;
|
|
|
|
|
|
|
|
|
|
/* determine FIFO size */
|
2017-06-13 02:55:49 +00:00
|
|
|
|
temp = lpuart32_read(&sport->port, UARTFIFO);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
|
2019-07-17 05:19:30 +00:00
|
|
|
|
sport->txfifo_size = UARTFIFO_DEPTH((temp >> UARTFIFO_TXSIZE_OFF) &
|
|
|
|
|
UARTFIFO_FIFOSIZE_MASK);
|
2019-01-21 08:36:21 +00:00
|
|
|
|
sport->port.fifosize = sport->txfifo_size;
|
|
|
|
|
|
2019-07-17 05:19:30 +00:00
|
|
|
|
sport->rxfifo_size = UARTFIFO_DEPTH((temp >> UARTFIFO_RXSIZE_OFF) &
|
|
|
|
|
UARTFIFO_FIFOSIZE_MASK);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
|
2020-03-06 21:44:32 +00:00
|
|
|
|
/*
|
tty: serial: fsl_lpuart: LS1021A has a FIFO size of 16 words, like LS1028A
Prior to the commit that this one fixes, the FIFO size was derived from
the read-only register LPUARTx_FIFO[TXFIFOSIZE] using the following
formula:
TX FIFO size = 2 ^ (LPUARTx_FIFO[TXFIFOSIZE] - 1)
The documentation for LS1021A is a mess. Under chapter 26.1.3 LS1021A
LPUART module special consideration, it mentions TXFIFO_SZ and RXFIFO_SZ
being equal to 4, and in the register description for LPUARTx_FIFO, it
shows the out-of-reset value of TXFIFOSIZE and RXFIFOSIZE fields as "011",
even though these registers read as "101" in reality.
And when LPUART on LS1021A was working, the "101" value did correspond
to "16 datawords", by applying the formula above, even though the
documentation is wrong again (!!!!) and says that "101" means 64 datawords
(hint: it doesn't).
So the "new" formula created by commit f77ebb241ce0 has all the premises
of being wrong for LS1021A, because it relied only on false data and no
actual experimentation.
Interestingly, in commit c2f448cff22a ("tty: serial: fsl_lpuart: add
LS1028A support"), Michael Walle applied a workaround to this by manually
setting the FIFO widths for LS1028A. It looks like the same values are
used by LS1021A as well, in fact.
When the driver thinks that it has a deeper FIFO than it really has,
getty (user space) output gets truncated.
Many thanks to Michael for pointing out where to look.
Fixes: f77ebb241ce0 ("tty: serial: fsl_lpuart: correct the FIFO depth size")
Suggested-by: Michael Walle <michael@walle.cc>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Link: https://lore.kernel.org/r/20201023013429.3551026-1-vladimir.oltean@nxp.com
Reviewed-by:Fugang Duan <fugang.duan@nxp.com>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-10-23 01:34:29 +00:00
|
|
|
|
* The LS1021A and LS1028A have a fixed FIFO depth of 16 words.
|
|
|
|
|
* Although they support the RX/TXSIZE fields, their encoding is
|
|
|
|
|
* different. Eg the reference manual states 0b101 is 16 words.
|
2020-03-06 21:44:32 +00:00
|
|
|
|
*/
|
tty: serial: fsl_lpuart: LS1021A has a FIFO size of 16 words, like LS1028A
Prior to the commit that this one fixes, the FIFO size was derived from
the read-only register LPUARTx_FIFO[TXFIFOSIZE] using the following
formula:
TX FIFO size = 2 ^ (LPUARTx_FIFO[TXFIFOSIZE] - 1)
The documentation for LS1021A is a mess. Under chapter 26.1.3 LS1021A
LPUART module special consideration, it mentions TXFIFO_SZ and RXFIFO_SZ
being equal to 4, and in the register description for LPUARTx_FIFO, it
shows the out-of-reset value of TXFIFOSIZE and RXFIFOSIZE fields as "011",
even though these registers read as "101" in reality.
And when LPUART on LS1021A was working, the "101" value did correspond
to "16 datawords", by applying the formula above, even though the
documentation is wrong again (!!!!) and says that "101" means 64 datawords
(hint: it doesn't).
So the "new" formula created by commit f77ebb241ce0 has all the premises
of being wrong for LS1021A, because it relied only on false data and no
actual experimentation.
Interestingly, in commit c2f448cff22a ("tty: serial: fsl_lpuart: add
LS1028A support"), Michael Walle applied a workaround to this by manually
setting the FIFO widths for LS1028A. It looks like the same values are
used by LS1021A as well, in fact.
When the driver thinks that it has a deeper FIFO than it really has,
getty (user space) output gets truncated.
Many thanks to Michael for pointing out where to look.
Fixes: f77ebb241ce0 ("tty: serial: fsl_lpuart: correct the FIFO depth size")
Suggested-by: Michael Walle <michael@walle.cc>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Link: https://lore.kernel.org/r/20201023013429.3551026-1-vladimir.oltean@nxp.com
Reviewed-by:Fugang Duan <fugang.duan@nxp.com>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2020-10-23 01:34:29 +00:00
|
|
|
|
if (is_layerscape_lpuart(sport)) {
|
2020-03-06 21:44:32 +00:00
|
|
|
|
sport->rxfifo_size = 16;
|
|
|
|
|
sport->txfifo_size = 16;
|
|
|
|
|
sport->port.fifosize = sport->txfifo_size;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-25 09:06:57 +00:00
|
|
|
|
lpuart_request_dma(sport);
|
|
|
|
|
|
2014-07-14 09:41:11 +00:00
|
|
|
|
spin_lock_irqsave(&sport->port.lock, flags);
|
|
|
|
|
|
2019-08-05 18:56:59 +00:00
|
|
|
|
lpuart32_setup_watermark_enable(sport);
|
2019-01-23 03:20:17 +00:00
|
|
|
|
|
2019-08-05 18:56:57 +00:00
|
|
|
|
lpuart_rx_dma_startup(sport);
|
2019-08-05 18:56:56 +00:00
|
|
|
|
lpuart_tx_dma_startup(sport);
|
2019-01-23 03:20:17 +00:00
|
|
|
|
|
2019-08-05 18:56:58 +00:00
|
|
|
|
lpuart32_configure(sport);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&sport->port.lock, flags);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-29 19:52:20 +00:00
|
|
|
|
static void lpuart_dma_shutdown(struct lpuart_port *sport)
|
|
|
|
|
{
|
|
|
|
|
if (sport->lpuart_dma_rx_use) {
|
|
|
|
|
del_timer_sync(&sport->lpuart_timer);
|
|
|
|
|
lpuart_dma_rx_free(&sport->port);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sport->lpuart_dma_tx_use) {
|
|
|
|
|
if (wait_event_interruptible(sport->dma_wait,
|
|
|
|
|
!sport->dma_tx_in_progress) != false) {
|
|
|
|
|
sport->dma_tx_in_progress = false;
|
|
|
|
|
dmaengine_terminate_all(sport->dma_tx_chan);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-03-06 21:44:30 +00:00
|
|
|
|
|
|
|
|
|
if (sport->dma_tx_chan)
|
|
|
|
|
dma_release_channel(sport->dma_tx_chan);
|
|
|
|
|
if (sport->dma_rx_chan)
|
|
|
|
|
dma_release_channel(sport->dma_rx_chan);
|
2019-07-29 19:52:20 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-07 01:20:40 +00:00
|
|
|
|
static void lpuart_shutdown(struct uart_port *port)
|
|
|
|
|
{
|
|
|
|
|
struct lpuart_port *sport = container_of(port, struct lpuart_port, port);
|
|
|
|
|
unsigned char temp;
|
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
|
|
spin_lock_irqsave(&port->lock, flags);
|
|
|
|
|
|
|
|
|
|
/* disable Rx/Tx and interrupts */
|
|
|
|
|
temp = readb(port->membase + UARTCR2);
|
|
|
|
|
temp &= ~(UARTCR2_TE | UARTCR2_RE |
|
|
|
|
|
UARTCR2_TIE | UARTCR2_TCIE | UARTCR2_RIE);
|
|
|
|
|
writeb(temp, port->membase + UARTCR2);
|
|
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&port->lock, flags);
|
|
|
|
|
|
2019-07-29 19:52:20 +00:00
|
|
|
|
lpuart_dma_shutdown(sport);
|
2013-06-07 01:20:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-14 09:41:11 +00:00
|
|
|
|
static void lpuart32_shutdown(struct uart_port *port)
|
|
|
|
|
{
|
2019-01-23 03:20:17 +00:00
|
|
|
|
struct lpuart_port *sport =
|
|
|
|
|
container_of(port, struct lpuart_port, port);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
unsigned long temp;
|
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
|
|
spin_lock_irqsave(&port->lock, flags);
|
|
|
|
|
|
|
|
|
|
/* disable Rx/Tx and interrupts */
|
2017-06-13 02:55:49 +00:00
|
|
|
|
temp = lpuart32_read(port, UARTCTRL);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
temp &= ~(UARTCTRL_TE | UARTCTRL_RE |
|
|
|
|
|
UARTCTRL_TIE | UARTCTRL_TCIE | UARTCTRL_RIE);
|
2017-06-13 02:55:49 +00:00
|
|
|
|
lpuart32_write(port, temp, UARTCTRL);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&port->lock, flags);
|
2019-01-23 03:20:17 +00:00
|
|
|
|
|
2019-07-29 19:52:20 +00:00
|
|
|
|
lpuart_dma_shutdown(sport);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-07 01:20:40 +00:00
|
|
|
|
static void
|
|
|
|
|
lpuart_set_termios(struct uart_port *port, struct ktermios *termios,
|
|
|
|
|
struct ktermios *old)
|
|
|
|
|
{
|
|
|
|
|
struct lpuart_port *sport = container_of(port, struct lpuart_port, port);
|
|
|
|
|
unsigned long flags;
|
2016-07-19 07:43:06 +00:00
|
|
|
|
unsigned char cr1, old_cr1, old_cr2, cr3, cr4, bdh, modem;
|
2013-06-07 01:20:40 +00:00
|
|
|
|
unsigned int baud;
|
|
|
|
|
unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8;
|
|
|
|
|
unsigned int sbr, brfa;
|
|
|
|
|
|
|
|
|
|
cr1 = old_cr1 = readb(sport->port.membase + UARTCR1);
|
|
|
|
|
old_cr2 = readb(sport->port.membase + UARTCR2);
|
2016-07-19 07:43:06 +00:00
|
|
|
|
cr3 = readb(sport->port.membase + UARTCR3);
|
2013-06-07 01:20:40 +00:00
|
|
|
|
cr4 = readb(sport->port.membase + UARTCR4);
|
|
|
|
|
bdh = readb(sport->port.membase + UARTBDH);
|
|
|
|
|
modem = readb(sport->port.membase + UARTMODEM);
|
|
|
|
|
/*
|
|
|
|
|
* only support CS8 and CS7, and for CS7 must enable PE.
|
|
|
|
|
* supported mode:
|
|
|
|
|
* - (7,e/o,1)
|
|
|
|
|
* - (8,n,1)
|
|
|
|
|
* - (8,m/s,1)
|
|
|
|
|
* - (8,e/o,1)
|
|
|
|
|
*/
|
|
|
|
|
while ((termios->c_cflag & CSIZE) != CS8 &&
|
|
|
|
|
(termios->c_cflag & CSIZE) != CS7) {
|
|
|
|
|
termios->c_cflag &= ~CSIZE;
|
|
|
|
|
termios->c_cflag |= old_csize;
|
|
|
|
|
old_csize = CS8;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((termios->c_cflag & CSIZE) == CS8 ||
|
|
|
|
|
(termios->c_cflag & CSIZE) == CS7)
|
|
|
|
|
cr1 = old_cr1 & ~UARTCR1_M;
|
|
|
|
|
|
|
|
|
|
if (termios->c_cflag & CMSPAR) {
|
|
|
|
|
if ((termios->c_cflag & CSIZE) != CS8) {
|
|
|
|
|
termios->c_cflag &= ~CSIZE;
|
|
|
|
|
termios->c_cflag |= CS8;
|
|
|
|
|
}
|
|
|
|
|
cr1 |= UARTCR1_M;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-19 07:43:10 +00:00
|
|
|
|
/*
|
|
|
|
|
* When auto RS-485 RTS mode is enabled,
|
|
|
|
|
* hardware flow control need to be disabled.
|
|
|
|
|
*/
|
|
|
|
|
if (sport->port.rs485.flags & SER_RS485_ENABLED)
|
|
|
|
|
termios->c_cflag &= ~CRTSCTS;
|
|
|
|
|
|
2019-07-29 19:52:12 +00:00
|
|
|
|
if (termios->c_cflag & CRTSCTS)
|
2019-07-29 19:52:13 +00:00
|
|
|
|
modem |= UARTMODEM_RXRTSE | UARTMODEM_TXCTSE;
|
2019-07-29 19:52:12 +00:00
|
|
|
|
else
|
2013-06-07 01:20:40 +00:00
|
|
|
|
modem &= ~(UARTMODEM_RXRTSE | UARTMODEM_TXCTSE);
|
|
|
|
|
|
2019-07-29 19:52:14 +00:00
|
|
|
|
termios->c_cflag &= ~CSTOPB;
|
2013-06-07 01:20:40 +00:00
|
|
|
|
|
|
|
|
|
/* parity must be enabled when CS7 to match 8-bits format */
|
|
|
|
|
if ((termios->c_cflag & CSIZE) == CS7)
|
|
|
|
|
termios->c_cflag |= PARENB;
|
|
|
|
|
|
2019-07-29 19:52:13 +00:00
|
|
|
|
if (termios->c_cflag & PARENB) {
|
2013-06-07 01:20:40 +00:00
|
|
|
|
if (termios->c_cflag & CMSPAR) {
|
|
|
|
|
cr1 &= ~UARTCR1_PE;
|
2016-07-19 07:43:06 +00:00
|
|
|
|
if (termios->c_cflag & PARODD)
|
|
|
|
|
cr3 |= UARTCR3_T8;
|
|
|
|
|
else
|
|
|
|
|
cr3 &= ~UARTCR3_T8;
|
2013-06-07 01:20:40 +00:00
|
|
|
|
} else {
|
|
|
|
|
cr1 |= UARTCR1_PE;
|
|
|
|
|
if ((termios->c_cflag & CSIZE) == CS8)
|
|
|
|
|
cr1 |= UARTCR1_M;
|
|
|
|
|
if (termios->c_cflag & PARODD)
|
|
|
|
|
cr1 |= UARTCR1_PT;
|
|
|
|
|
else
|
|
|
|
|
cr1 &= ~UARTCR1_PT;
|
|
|
|
|
}
|
2018-10-16 07:32:22 +00:00
|
|
|
|
} else {
|
|
|
|
|
cr1 &= ~UARTCR1_PE;
|
2013-06-07 01:20:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ask the core to calculate the divisor */
|
|
|
|
|
baud = uart_get_baud_rate(port, termios, old, 50, port->uartclk / 16);
|
|
|
|
|
|
2016-12-04 15:49:28 +00:00
|
|
|
|
/*
|
|
|
|
|
* Need to update the Ring buffer length according to the selected
|
|
|
|
|
* baud rate and restart Rx DMA path.
|
|
|
|
|
*
|
|
|
|
|
* Since timer function acqures sport->port.lock, need to stop before
|
|
|
|
|
* acquring same lock because otherwise del_timer_sync() can deadlock.
|
|
|
|
|
*/
|
|
|
|
|
if (old && sport->lpuart_dma_rx_use) {
|
|
|
|
|
del_timer_sync(&sport->lpuart_timer);
|
|
|
|
|
lpuart_dma_rx_free(&sport->port);
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-07 01:20:40 +00:00
|
|
|
|
spin_lock_irqsave(&sport->port.lock, flags);
|
|
|
|
|
|
|
|
|
|
sport->port.read_status_mask = 0;
|
|
|
|
|
if (termios->c_iflag & INPCK)
|
2019-07-29 19:52:13 +00:00
|
|
|
|
sport->port.read_status_mask |= UARTSR1_FE | UARTSR1_PE;
|
2014-06-16 12:10:41 +00:00
|
|
|
|
if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK))
|
2013-06-07 01:20:40 +00:00
|
|
|
|
sport->port.read_status_mask |= UARTSR1_FE;
|
|
|
|
|
|
|
|
|
|
/* characters to ignore */
|
|
|
|
|
sport->port.ignore_status_mask = 0;
|
|
|
|
|
if (termios->c_iflag & IGNPAR)
|
|
|
|
|
sport->port.ignore_status_mask |= UARTSR1_PE;
|
|
|
|
|
if (termios->c_iflag & IGNBRK) {
|
|
|
|
|
sport->port.ignore_status_mask |= UARTSR1_FE;
|
|
|
|
|
/*
|
|
|
|
|
* if we're ignoring parity and break indicators,
|
|
|
|
|
* ignore overruns too (for real raw support).
|
|
|
|
|
*/
|
|
|
|
|
if (termios->c_iflag & IGNPAR)
|
|
|
|
|
sport->port.ignore_status_mask |= UARTSR1_OR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* update the per-port timeout */
|
|
|
|
|
uart_update_timeout(port, termios->c_cflag, baud);
|
|
|
|
|
|
|
|
|
|
/* wait transmit engin complete */
|
2019-07-29 19:52:16 +00:00
|
|
|
|
lpuart_wait_bit_set(&sport->port, UARTSR1, UARTSR1_TC);
|
2013-06-07 01:20:40 +00:00
|
|
|
|
|
|
|
|
|
/* disable transmit and receive */
|
|
|
|
|
writeb(old_cr2 & ~(UARTCR2_TE | UARTCR2_RE),
|
|
|
|
|
sport->port.membase + UARTCR2);
|
|
|
|
|
|
|
|
|
|
sbr = sport->port.uartclk / (16 * baud);
|
|
|
|
|
brfa = ((sport->port.uartclk - (16 * sbr * baud)) * 2) / baud;
|
|
|
|
|
bdh &= ~UARTBDH_SBR_MASK;
|
|
|
|
|
bdh |= (sbr >> 8) & 0x1F;
|
|
|
|
|
cr4 &= ~UARTCR4_BRFA_MASK;
|
|
|
|
|
brfa &= UARTCR4_BRFA_MASK;
|
|
|
|
|
writeb(cr4 | brfa, sport->port.membase + UARTCR4);
|
|
|
|
|
writeb(bdh, sport->port.membase + UARTBDH);
|
|
|
|
|
writeb(sbr & 0xFF, sport->port.membase + UARTBDL);
|
2016-07-19 07:43:06 +00:00
|
|
|
|
writeb(cr3, sport->port.membase + UARTCR3);
|
2013-06-07 01:20:40 +00:00
|
|
|
|
writeb(cr1, sport->port.membase + UARTCR1);
|
|
|
|
|
writeb(modem, sport->port.membase + UARTMODEM);
|
|
|
|
|
|
|
|
|
|
/* restore control register */
|
|
|
|
|
writeb(old_cr2, sport->port.membase + UARTCR2);
|
|
|
|
|
|
2016-12-04 15:49:28 +00:00
|
|
|
|
if (old && sport->lpuart_dma_rx_use) {
|
|
|
|
|
if (!lpuart_start_rx_dma(sport))
|
2016-07-19 07:43:07 +00:00
|
|
|
|
rx_dma_timer_init(sport);
|
2016-12-04 15:49:28 +00:00
|
|
|
|
else
|
2016-07-19 07:43:07 +00:00
|
|
|
|
sport->lpuart_dma_rx_use = false;
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-07 01:20:40 +00:00
|
|
|
|
spin_unlock_irqrestore(&sport->port.lock, flags);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-06 21:44:33 +00:00
|
|
|
|
static void __lpuart32_serial_setbrg(struct uart_port *port,
|
|
|
|
|
unsigned int baudrate, bool use_rx_dma,
|
|
|
|
|
bool use_tx_dma)
|
2017-06-13 02:55:54 +00:00
|
|
|
|
{
|
|
|
|
|
u32 sbr, osr, baud_diff, tmp_osr, tmp_sbr, tmp_diff, tmp;
|
2020-03-06 21:44:33 +00:00
|
|
|
|
u32 clk = port->uartclk;
|
2017-06-13 02:55:54 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* The idea is to use the best OSR (over-sampling rate) possible.
|
|
|
|
|
* Note, OSR is typically hard-set to 16 in other LPUART instantiations.
|
|
|
|
|
* Loop to find the best OSR value possible, one that generates minimum
|
|
|
|
|
* baud_diff iterate through the rest of the supported values of OSR.
|
|
|
|
|
*
|
|
|
|
|
* Calculation Formula:
|
|
|
|
|
* Baud Rate = baud clock / ((OSR+1) × SBR)
|
|
|
|
|
*/
|
|
|
|
|
baud_diff = baudrate;
|
|
|
|
|
osr = 0;
|
|
|
|
|
sbr = 0;
|
|
|
|
|
|
|
|
|
|
for (tmp_osr = 4; tmp_osr <= 32; tmp_osr++) {
|
|
|
|
|
/* calculate the temporary sbr value */
|
|
|
|
|
tmp_sbr = (clk / (baudrate * tmp_osr));
|
|
|
|
|
if (tmp_sbr == 0)
|
|
|
|
|
tmp_sbr = 1;
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* calculate the baud rate difference based on the temporary
|
|
|
|
|
* osr and sbr values
|
|
|
|
|
*/
|
|
|
|
|
tmp_diff = clk / (tmp_osr * tmp_sbr) - baudrate;
|
|
|
|
|
|
|
|
|
|
/* select best values between sbr and sbr+1 */
|
|
|
|
|
tmp = clk / (tmp_osr * (tmp_sbr + 1));
|
|
|
|
|
if (tmp_diff > (baudrate - tmp)) {
|
|
|
|
|
tmp_diff = baudrate - tmp;
|
|
|
|
|
tmp_sbr++;
|
|
|
|
|
}
|
|
|
|
|
|
2020-06-26 11:20:34 +00:00
|
|
|
|
if (tmp_sbr > UARTBAUD_SBR_MASK)
|
|
|
|
|
continue;
|
|
|
|
|
|
2017-06-13 02:55:54 +00:00
|
|
|
|
if (tmp_diff <= baud_diff) {
|
|
|
|
|
baud_diff = tmp_diff;
|
|
|
|
|
osr = tmp_osr;
|
|
|
|
|
sbr = tmp_sbr;
|
|
|
|
|
|
|
|
|
|
if (!baud_diff)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* handle buadrate outside acceptable rate */
|
|
|
|
|
if (baud_diff > ((baudrate / 100) * 3))
|
2020-03-06 21:44:33 +00:00
|
|
|
|
dev_warn(port->dev,
|
2017-06-13 02:55:54 +00:00
|
|
|
|
"unacceptable baud rate difference of more than 3%%\n");
|
|
|
|
|
|
2020-03-06 21:44:33 +00:00
|
|
|
|
tmp = lpuart32_read(port, UARTBAUD);
|
2017-06-13 02:55:54 +00:00
|
|
|
|
|
|
|
|
|
if ((osr > 3) && (osr < 8))
|
|
|
|
|
tmp |= UARTBAUD_BOTHEDGE;
|
|
|
|
|
|
|
|
|
|
tmp &= ~(UARTBAUD_OSR_MASK << UARTBAUD_OSR_SHIFT);
|
2019-07-29 19:52:13 +00:00
|
|
|
|
tmp |= ((osr-1) & UARTBAUD_OSR_MASK) << UARTBAUD_OSR_SHIFT;
|
2017-06-13 02:55:54 +00:00
|
|
|
|
|
|
|
|
|
tmp &= ~UARTBAUD_SBR_MASK;
|
|
|
|
|
tmp |= sbr & UARTBAUD_SBR_MASK;
|
|
|
|
|
|
2020-03-06 21:44:33 +00:00
|
|
|
|
if (!use_rx_dma)
|
2019-01-23 03:20:17 +00:00
|
|
|
|
tmp &= ~UARTBAUD_RDMAE;
|
2020-03-06 21:44:33 +00:00
|
|
|
|
if (!use_tx_dma)
|
2019-01-23 03:20:17 +00:00
|
|
|
|
tmp &= ~UARTBAUD_TDMAE;
|
2017-06-13 02:55:54 +00:00
|
|
|
|
|
2020-03-06 21:44:33 +00:00
|
|
|
|
lpuart32_write(port, tmp, UARTBAUD);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void lpuart32_serial_setbrg(struct lpuart_port *sport,
|
|
|
|
|
unsigned int baudrate)
|
|
|
|
|
{
|
|
|
|
|
__lpuart32_serial_setbrg(&sport->port, baudrate,
|
|
|
|
|
sport->lpuart_dma_rx_use,
|
|
|
|
|
sport->lpuart_dma_tx_use);
|
2017-06-13 02:55:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-06 21:44:33 +00:00
|
|
|
|
|
2014-07-14 09:41:11 +00:00
|
|
|
|
static void
|
|
|
|
|
lpuart32_set_termios(struct uart_port *port, struct ktermios *termios,
|
|
|
|
|
struct ktermios *old)
|
|
|
|
|
{
|
|
|
|
|
struct lpuart_port *sport = container_of(port, struct lpuart_port, port);
|
|
|
|
|
unsigned long flags;
|
2017-09-18 11:33:28 +00:00
|
|
|
|
unsigned long ctrl, old_ctrl, modem;
|
2014-07-14 09:41:11 +00:00
|
|
|
|
unsigned int baud;
|
|
|
|
|
unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8;
|
|
|
|
|
|
2017-06-13 02:55:49 +00:00
|
|
|
|
ctrl = old_ctrl = lpuart32_read(&sport->port, UARTCTRL);
|
|
|
|
|
modem = lpuart32_read(&sport->port, UARTMODIR);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
/*
|
|
|
|
|
* only support CS8 and CS7, and for CS7 must enable PE.
|
|
|
|
|
* supported mode:
|
|
|
|
|
* - (7,e/o,1)
|
|
|
|
|
* - (8,n,1)
|
|
|
|
|
* - (8,m/s,1)
|
|
|
|
|
* - (8,e/o,1)
|
|
|
|
|
*/
|
|
|
|
|
while ((termios->c_cflag & CSIZE) != CS8 &&
|
|
|
|
|
(termios->c_cflag & CSIZE) != CS7) {
|
|
|
|
|
termios->c_cflag &= ~CSIZE;
|
|
|
|
|
termios->c_cflag |= old_csize;
|
|
|
|
|
old_csize = CS8;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((termios->c_cflag & CSIZE) == CS8 ||
|
|
|
|
|
(termios->c_cflag & CSIZE) == CS7)
|
|
|
|
|
ctrl = old_ctrl & ~UARTCTRL_M;
|
|
|
|
|
|
|
|
|
|
if (termios->c_cflag & CMSPAR) {
|
|
|
|
|
if ((termios->c_cflag & CSIZE) != CS8) {
|
|
|
|
|
termios->c_cflag &= ~CSIZE;
|
|
|
|
|
termios->c_cflag |= CS8;
|
|
|
|
|
}
|
|
|
|
|
ctrl |= UARTCTRL_M;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-17 14:14:42 +00:00
|
|
|
|
/*
|
|
|
|
|
* When auto RS-485 RTS mode is enabled,
|
|
|
|
|
* hardware flow control need to be disabled.
|
|
|
|
|
*/
|
|
|
|
|
if (sport->port.rs485.flags & SER_RS485_ENABLED)
|
|
|
|
|
termios->c_cflag &= ~CRTSCTS;
|
|
|
|
|
|
2014-07-14 09:41:11 +00:00
|
|
|
|
if (termios->c_cflag & CRTSCTS) {
|
2019-10-17 14:14:40 +00:00
|
|
|
|
modem |= (UARTMODIR_RXRTSE | UARTMODIR_TXCTSE);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
} else {
|
|
|
|
|
termios->c_cflag &= ~CRTSCTS;
|
2019-10-17 14:14:40 +00:00
|
|
|
|
modem &= ~(UARTMODIR_RXRTSE | UARTMODIR_TXCTSE);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (termios->c_cflag & CSTOPB)
|
|
|
|
|
termios->c_cflag &= ~CSTOPB;
|
|
|
|
|
|
|
|
|
|
/* parity must be enabled when CS7 to match 8-bits format */
|
|
|
|
|
if ((termios->c_cflag & CSIZE) == CS7)
|
|
|
|
|
termios->c_cflag |= PARENB;
|
|
|
|
|
|
|
|
|
|
if ((termios->c_cflag & PARENB)) {
|
|
|
|
|
if (termios->c_cflag & CMSPAR) {
|
|
|
|
|
ctrl &= ~UARTCTRL_PE;
|
|
|
|
|
ctrl |= UARTCTRL_M;
|
|
|
|
|
} else {
|
2018-10-16 07:32:19 +00:00
|
|
|
|
ctrl |= UARTCTRL_PE;
|
2014-07-14 09:41:11 +00:00
|
|
|
|
if ((termios->c_cflag & CSIZE) == CS8)
|
|
|
|
|
ctrl |= UARTCTRL_M;
|
|
|
|
|
if (termios->c_cflag & PARODD)
|
|
|
|
|
ctrl |= UARTCTRL_PT;
|
|
|
|
|
else
|
|
|
|
|
ctrl &= ~UARTCTRL_PT;
|
|
|
|
|
}
|
2018-10-16 07:32:22 +00:00
|
|
|
|
} else {
|
|
|
|
|
ctrl &= ~UARTCTRL_PE;
|
2014-07-14 09:41:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* ask the core to calculate the divisor */
|
2019-01-21 08:34:16 +00:00
|
|
|
|
baud = uart_get_baud_rate(port, termios, old, 50, port->uartclk / 4);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
|
2019-01-23 03:20:17 +00:00
|
|
|
|
/*
|
|
|
|
|
* Need to update the Ring buffer length according to the selected
|
|
|
|
|
* baud rate and restart Rx DMA path.
|
|
|
|
|
*
|
|
|
|
|
* Since timer function acqures sport->port.lock, need to stop before
|
|
|
|
|
* acquring same lock because otherwise del_timer_sync() can deadlock.
|
|
|
|
|
*/
|
|
|
|
|
if (old && sport->lpuart_dma_rx_use) {
|
|
|
|
|
del_timer_sync(&sport->lpuart_timer);
|
|
|
|
|
lpuart_dma_rx_free(&sport->port);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-14 09:41:11 +00:00
|
|
|
|
spin_lock_irqsave(&sport->port.lock, flags);
|
|
|
|
|
|
|
|
|
|
sport->port.read_status_mask = 0;
|
|
|
|
|
if (termios->c_iflag & INPCK)
|
2019-07-29 19:52:13 +00:00
|
|
|
|
sport->port.read_status_mask |= UARTSTAT_FE | UARTSTAT_PE;
|
2014-07-14 09:41:11 +00:00
|
|
|
|
if (termios->c_iflag & (IGNBRK | BRKINT | PARMRK))
|
|
|
|
|
sport->port.read_status_mask |= UARTSTAT_FE;
|
|
|
|
|
|
|
|
|
|
/* characters to ignore */
|
|
|
|
|
sport->port.ignore_status_mask = 0;
|
|
|
|
|
if (termios->c_iflag & IGNPAR)
|
|
|
|
|
sport->port.ignore_status_mask |= UARTSTAT_PE;
|
|
|
|
|
if (termios->c_iflag & IGNBRK) {
|
|
|
|
|
sport->port.ignore_status_mask |= UARTSTAT_FE;
|
|
|
|
|
/*
|
|
|
|
|
* if we're ignoring parity and break indicators,
|
|
|
|
|
* ignore overruns too (for real raw support).
|
|
|
|
|
*/
|
|
|
|
|
if (termios->c_iflag & IGNPAR)
|
|
|
|
|
sport->port.ignore_status_mask |= UARTSTAT_OR;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* update the per-port timeout */
|
|
|
|
|
uart_update_timeout(port, termios->c_cflag, baud);
|
|
|
|
|
|
|
|
|
|
/* wait transmit engin complete */
|
2019-07-29 19:52:16 +00:00
|
|
|
|
lpuart32_wait_bit_set(&sport->port, UARTSTAT, UARTSTAT_TC);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
|
|
|
|
|
/* disable transmit and receive */
|
2017-06-13 02:55:49 +00:00
|
|
|
|
lpuart32_write(&sport->port, old_ctrl & ~(UARTCTRL_TE | UARTCTRL_RE),
|
|
|
|
|
UARTCTRL);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
|
2017-06-13 02:55:54 +00:00
|
|
|
|
lpuart32_serial_setbrg(sport, baud);
|
2017-06-13 02:55:49 +00:00
|
|
|
|
lpuart32_write(&sport->port, modem, UARTMODIR);
|
|
|
|
|
lpuart32_write(&sport->port, ctrl, UARTCTRL);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
/* restore control register */
|
|
|
|
|
|
2019-01-23 03:20:17 +00:00
|
|
|
|
if (old && sport->lpuart_dma_rx_use) {
|
|
|
|
|
if (!lpuart_start_rx_dma(sport))
|
|
|
|
|
rx_dma_timer_init(sport);
|
|
|
|
|
else
|
|
|
|
|
sport->lpuart_dma_rx_use = false;
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-14 09:41:11 +00:00
|
|
|
|
spin_unlock_irqrestore(&sport->port.lock, flags);
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-07 01:20:40 +00:00
|
|
|
|
static const char *lpuart_type(struct uart_port *port)
|
|
|
|
|
{
|
|
|
|
|
return "FSL_LPUART";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void lpuart_release_port(struct uart_port *port)
|
|
|
|
|
{
|
|
|
|
|
/* nothing to do */
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int lpuart_request_port(struct uart_port *port)
|
|
|
|
|
{
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* configure/autoconfigure the port */
|
|
|
|
|
static void lpuart_config_port(struct uart_port *port, int flags)
|
|
|
|
|
{
|
|
|
|
|
if (flags & UART_CONFIG_TYPE)
|
|
|
|
|
port->type = PORT_LPUART;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int lpuart_verify_port(struct uart_port *port, struct serial_struct *ser)
|
|
|
|
|
{
|
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
|
|
if (ser->type != PORT_UNKNOWN && ser->type != PORT_LPUART)
|
|
|
|
|
ret = -EINVAL;
|
|
|
|
|
if (port->irq != ser->irq)
|
|
|
|
|
ret = -EINVAL;
|
|
|
|
|
if (ser->io_type != UPIO_MEM)
|
|
|
|
|
ret = -EINVAL;
|
|
|
|
|
if (port->uartclk / 16 != ser->baud_base)
|
|
|
|
|
ret = -EINVAL;
|
|
|
|
|
if (port->iobase != ser->port)
|
|
|
|
|
ret = -EINVAL;
|
|
|
|
|
if (ser->hub6 != 0)
|
|
|
|
|
ret = -EINVAL;
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-01 17:51:35 +00:00
|
|
|
|
static const struct uart_ops lpuart_pops = {
|
2013-06-07 01:20:40 +00:00
|
|
|
|
.tx_empty = lpuart_tx_empty,
|
|
|
|
|
.set_mctrl = lpuart_set_mctrl,
|
|
|
|
|
.get_mctrl = lpuart_get_mctrl,
|
|
|
|
|
.stop_tx = lpuart_stop_tx,
|
|
|
|
|
.start_tx = lpuart_start_tx,
|
|
|
|
|
.stop_rx = lpuart_stop_rx,
|
|
|
|
|
.break_ctl = lpuart_break_ctl,
|
|
|
|
|
.startup = lpuart_startup,
|
|
|
|
|
.shutdown = lpuart_shutdown,
|
|
|
|
|
.set_termios = lpuart_set_termios,
|
|
|
|
|
.type = lpuart_type,
|
|
|
|
|
.request_port = lpuart_request_port,
|
|
|
|
|
.release_port = lpuart_release_port,
|
|
|
|
|
.config_port = lpuart_config_port,
|
|
|
|
|
.verify_port = lpuart_verify_port,
|
2015-01-26 00:10:16 +00:00
|
|
|
|
.flush_buffer = lpuart_flush_buffer,
|
2016-10-04 12:46:16 +00:00
|
|
|
|
#if defined(CONFIG_CONSOLE_POLL)
|
|
|
|
|
.poll_init = lpuart_poll_init,
|
|
|
|
|
.poll_get_char = lpuart_poll_get_char,
|
|
|
|
|
.poll_put_char = lpuart_poll_put_char,
|
|
|
|
|
#endif
|
2013-06-07 01:20:40 +00:00
|
|
|
|
};
|
|
|
|
|
|
2016-09-01 17:51:35 +00:00
|
|
|
|
static const struct uart_ops lpuart32_pops = {
|
2014-07-14 09:41:11 +00:00
|
|
|
|
.tx_empty = lpuart32_tx_empty,
|
|
|
|
|
.set_mctrl = lpuart32_set_mctrl,
|
|
|
|
|
.get_mctrl = lpuart32_get_mctrl,
|
|
|
|
|
.stop_tx = lpuart32_stop_tx,
|
|
|
|
|
.start_tx = lpuart32_start_tx,
|
|
|
|
|
.stop_rx = lpuart32_stop_rx,
|
|
|
|
|
.break_ctl = lpuart32_break_ctl,
|
|
|
|
|
.startup = lpuart32_startup,
|
|
|
|
|
.shutdown = lpuart32_shutdown,
|
|
|
|
|
.set_termios = lpuart32_set_termios,
|
|
|
|
|
.type = lpuart_type,
|
|
|
|
|
.request_port = lpuart_request_port,
|
|
|
|
|
.release_port = lpuart_release_port,
|
|
|
|
|
.config_port = lpuart_config_port,
|
|
|
|
|
.verify_port = lpuart_verify_port,
|
2015-01-26 00:10:16 +00:00
|
|
|
|
.flush_buffer = lpuart_flush_buffer,
|
2017-07-15 22:00:58 +00:00
|
|
|
|
#if defined(CONFIG_CONSOLE_POLL)
|
|
|
|
|
.poll_init = lpuart32_poll_init,
|
|
|
|
|
.poll_get_char = lpuart32_poll_get_char,
|
|
|
|
|
.poll_put_char = lpuart32_poll_put_char,
|
|
|
|
|
#endif
|
2014-07-14 09:41:11 +00:00
|
|
|
|
};
|
|
|
|
|
|
2013-06-07 01:20:40 +00:00
|
|
|
|
static struct lpuart_port *lpuart_ports[UART_NR];
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_SERIAL_FSL_LPUART_CONSOLE
|
|
|
|
|
static void lpuart_console_putchar(struct uart_port *port, int ch)
|
|
|
|
|
{
|
2019-07-29 19:52:16 +00:00
|
|
|
|
lpuart_wait_bit_set(port, UARTSR1, UARTSR1_TDRE);
|
2013-06-07 01:20:40 +00:00
|
|
|
|
writeb(ch, port->membase + UARTDR);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-14 09:41:11 +00:00
|
|
|
|
static void lpuart32_console_putchar(struct uart_port *port, int ch)
|
|
|
|
|
{
|
2019-07-29 19:52:16 +00:00
|
|
|
|
lpuart32_wait_bit_set(port, UARTSTAT, UARTSTAT_TDRE);
|
2017-06-13 02:55:49 +00:00
|
|
|
|
lpuart32_write(port, ch, UARTDATA);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-07 01:20:40 +00:00
|
|
|
|
static void
|
|
|
|
|
lpuart_console_write(struct console *co, const char *s, unsigned int count)
|
|
|
|
|
{
|
|
|
|
|
struct lpuart_port *sport = lpuart_ports[co->index];
|
|
|
|
|
unsigned char old_cr2, cr2;
|
2017-03-24 18:33:46 +00:00
|
|
|
|
unsigned long flags;
|
|
|
|
|
int locked = 1;
|
|
|
|
|
|
|
|
|
|
if (sport->port.sysrq || oops_in_progress)
|
|
|
|
|
locked = spin_trylock_irqsave(&sport->port.lock, flags);
|
|
|
|
|
else
|
|
|
|
|
spin_lock_irqsave(&sport->port.lock, flags);
|
2013-06-07 01:20:40 +00:00
|
|
|
|
|
|
|
|
|
/* first save CR2 and then disable interrupts */
|
|
|
|
|
cr2 = old_cr2 = readb(sport->port.membase + UARTCR2);
|
2019-07-29 19:52:13 +00:00
|
|
|
|
cr2 |= UARTCR2_TE | UARTCR2_RE;
|
2013-06-07 01:20:40 +00:00
|
|
|
|
cr2 &= ~(UARTCR2_TIE | UARTCR2_TCIE | UARTCR2_RIE);
|
|
|
|
|
writeb(cr2, sport->port.membase + UARTCR2);
|
|
|
|
|
|
|
|
|
|
uart_console_write(&sport->port, s, count, lpuart_console_putchar);
|
|
|
|
|
|
|
|
|
|
/* wait for transmitter finish complete and restore CR2 */
|
2019-07-29 19:52:16 +00:00
|
|
|
|
lpuart_wait_bit_set(&sport->port, UARTSR1, UARTSR1_TC);
|
2013-06-07 01:20:40 +00:00
|
|
|
|
|
|
|
|
|
writeb(old_cr2, sport->port.membase + UARTCR2);
|
2017-03-24 18:33:46 +00:00
|
|
|
|
|
|
|
|
|
if (locked)
|
|
|
|
|
spin_unlock_irqrestore(&sport->port.lock, flags);
|
2013-06-07 01:20:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-07-14 09:41:11 +00:00
|
|
|
|
static void
|
|
|
|
|
lpuart32_console_write(struct console *co, const char *s, unsigned int count)
|
|
|
|
|
{
|
|
|
|
|
struct lpuart_port *sport = lpuart_ports[co->index];
|
|
|
|
|
unsigned long old_cr, cr;
|
2017-03-24 18:33:46 +00:00
|
|
|
|
unsigned long flags;
|
|
|
|
|
int locked = 1;
|
|
|
|
|
|
|
|
|
|
if (sport->port.sysrq || oops_in_progress)
|
|
|
|
|
locked = spin_trylock_irqsave(&sport->port.lock, flags);
|
|
|
|
|
else
|
|
|
|
|
spin_lock_irqsave(&sport->port.lock, flags);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
|
|
|
|
|
/* first save CR2 and then disable interrupts */
|
2017-06-13 02:55:49 +00:00
|
|
|
|
cr = old_cr = lpuart32_read(&sport->port, UARTCTRL);
|
2019-07-29 19:52:13 +00:00
|
|
|
|
cr |= UARTCTRL_TE | UARTCTRL_RE;
|
2014-07-14 09:41:11 +00:00
|
|
|
|
cr &= ~(UARTCTRL_TIE | UARTCTRL_TCIE | UARTCTRL_RIE);
|
2017-06-13 02:55:49 +00:00
|
|
|
|
lpuart32_write(&sport->port, cr, UARTCTRL);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
|
|
|
|
|
uart_console_write(&sport->port, s, count, lpuart32_console_putchar);
|
|
|
|
|
|
|
|
|
|
/* wait for transmitter finish complete and restore CR2 */
|
2019-07-29 19:52:16 +00:00
|
|
|
|
lpuart32_wait_bit_set(&sport->port, UARTSTAT, UARTSTAT_TC);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
|
2017-06-13 02:55:49 +00:00
|
|
|
|
lpuart32_write(&sport->port, old_cr, UARTCTRL);
|
2017-03-24 18:33:46 +00:00
|
|
|
|
|
|
|
|
|
if (locked)
|
|
|
|
|
spin_unlock_irqrestore(&sport->port.lock, flags);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2013-06-07 01:20:40 +00:00
|
|
|
|
/*
|
|
|
|
|
* 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)
|
|
|
|
|
{
|
|
|
|
|
unsigned char cr, bdh, bdl, brfa;
|
|
|
|
|
unsigned int sbr, uartclk, baud_raw;
|
|
|
|
|
|
|
|
|
|
cr = readb(sport->port.membase + UARTCR2);
|
|
|
|
|
cr &= UARTCR2_TE | UARTCR2_RE;
|
|
|
|
|
if (!cr)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* ok, the port was enabled */
|
|
|
|
|
|
|
|
|
|
cr = readb(sport->port.membase + UARTCR1);
|
|
|
|
|
|
|
|
|
|
*parity = 'n';
|
|
|
|
|
if (cr & UARTCR1_PE) {
|
|
|
|
|
if (cr & UARTCR1_PT)
|
|
|
|
|
*parity = 'o';
|
|
|
|
|
else
|
|
|
|
|
*parity = 'e';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cr & UARTCR1_M)
|
|
|
|
|
*bits = 9;
|
|
|
|
|
else
|
|
|
|
|
*bits = 8;
|
|
|
|
|
|
|
|
|
|
bdh = readb(sport->port.membase + UARTBDH);
|
|
|
|
|
bdh &= UARTBDH_SBR_MASK;
|
|
|
|
|
bdl = readb(sport->port.membase + UARTBDL);
|
|
|
|
|
sbr = bdh;
|
|
|
|
|
sbr <<= 8;
|
|
|
|
|
sbr |= bdl;
|
|
|
|
|
brfa = readb(sport->port.membase + UARTCR4);
|
|
|
|
|
brfa &= UARTCR4_BRFA_MASK;
|
|
|
|
|
|
2019-07-04 13:40:07 +00:00
|
|
|
|
uartclk = lpuart_get_baud_clk_rate(sport);
|
2013-06-07 01:20:40 +00:00
|
|
|
|
/*
|
|
|
|
|
* baud = mod_clk/(16*(sbr[13]+(brfa)/32)
|
|
|
|
|
*/
|
|
|
|
|
baud_raw = uartclk / (16 * (sbr + brfa / 32));
|
|
|
|
|
|
|
|
|
|
if (*baud != baud_raw)
|
2019-06-04 03:31:38 +00:00
|
|
|
|
dev_info(sport->port.dev, "Serial: Console lpuart rounded baud rate"
|
2013-06-07 01:20:40 +00:00
|
|
|
|
"from %d to %d\n", baud_raw, *baud);
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-14 09:41:11 +00:00
|
|
|
|
static void __init
|
|
|
|
|
lpuart32_console_get_options(struct lpuart_port *sport, int *baud,
|
|
|
|
|
int *parity, int *bits)
|
|
|
|
|
{
|
|
|
|
|
unsigned long cr, bd;
|
|
|
|
|
unsigned int sbr, uartclk, baud_raw;
|
|
|
|
|
|
2017-06-13 02:55:49 +00:00
|
|
|
|
cr = lpuart32_read(&sport->port, UARTCTRL);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
cr &= UARTCTRL_TE | UARTCTRL_RE;
|
|
|
|
|
if (!cr)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
/* ok, the port was enabled */
|
|
|
|
|
|
2017-06-13 02:55:49 +00:00
|
|
|
|
cr = lpuart32_read(&sport->port, UARTCTRL);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
|
|
|
|
|
*parity = 'n';
|
|
|
|
|
if (cr & UARTCTRL_PE) {
|
|
|
|
|
if (cr & UARTCTRL_PT)
|
|
|
|
|
*parity = 'o';
|
|
|
|
|
else
|
|
|
|
|
*parity = 'e';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (cr & UARTCTRL_M)
|
|
|
|
|
*bits = 9;
|
|
|
|
|
else
|
|
|
|
|
*bits = 8;
|
|
|
|
|
|
2017-06-13 02:55:49 +00:00
|
|
|
|
bd = lpuart32_read(&sport->port, UARTBAUD);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
bd &= UARTBAUD_SBR_MASK;
|
2021-04-27 02:12:26 +00:00
|
|
|
|
if (!bd)
|
|
|
|
|
return;
|
|
|
|
|
|
2014-07-14 09:41:11 +00:00
|
|
|
|
sbr = bd;
|
2019-07-04 13:40:07 +00:00
|
|
|
|
uartclk = lpuart_get_baud_clk_rate(sport);
|
2014-07-14 09:41:11 +00:00
|
|
|
|
/*
|
|
|
|
|
* baud = mod_clk/(16*(sbr[13]+(brfa)/32)
|
|
|
|
|
*/
|
|
|
|
|
baud_raw = uartclk / (16 * sbr);
|
|
|
|
|
|
|
|
|
|
if (*baud != baud_raw)
|
2019-06-04 03:31:38 +00:00
|
|
|
|
dev_info(sport->port.dev, "Serial: Console lpuart rounded baud rate"
|
2014-07-14 09:41:11 +00:00
|
|
|
|
"from %d to %d\n", baud_raw, *baud);
|
|
|
|
|
}
|
|
|
|
|
|
2013-06-07 01:20:40 +00:00
|
|
|
|
static int __init lpuart_console_setup(struct console *co, char *options)
|
|
|
|
|
{
|
|
|
|
|
struct lpuart_port *sport;
|
|
|
|
|
int baud = 115200;
|
|
|
|
|
int bits = 8;
|
|
|
|
|
int parity = 'n';
|
|
|
|
|
int flow = 'n';
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* check whether an invalid uart number has been specified, and
|
|
|
|
|
* if so, search for the first available port that does have
|
|
|
|
|
* console support.
|
|
|
|
|
*/
|
|
|
|
|
if (co->index == -1 || co->index >= ARRAY_SIZE(lpuart_ports))
|
|
|
|
|
co->index = 0;
|
|
|
|
|
|
|
|
|
|
sport = lpuart_ports[co->index];
|
|
|
|
|
if (sport == NULL)
|
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
|
|
if (options)
|
|
|
|
|
uart_parse_options(options, &baud, &parity, &bits, &flow);
|
|
|
|
|
else
|
2017-07-11 11:03:43 +00:00
|
|
|
|
if (lpuart_is_32(sport))
|
2014-07-14 09:41:11 +00:00
|
|
|
|
lpuart32_console_get_options(sport, &baud, &parity, &bits);
|
|
|
|
|
else
|
|
|
|
|
lpuart_console_get_options(sport, &baud, &parity, &bits);
|
2013-06-07 01:20:40 +00:00
|
|
|
|
|
2017-07-11 11:03:43 +00:00
|
|
|
|
if (lpuart_is_32(sport))
|
2014-07-14 09:41:11 +00:00
|
|
|
|
lpuart32_setup_watermark(sport);
|
|
|
|
|
else
|
|
|
|
|
lpuart_setup_watermark(sport);
|
2013-06-07 01:20:40 +00:00
|
|
|
|
|
|
|
|
|
return uart_set_options(&sport->port, co, baud, parity, bits, flow);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static struct uart_driver lpuart_reg;
|
|
|
|
|
static struct console lpuart_console = {
|
|
|
|
|
.name = DEV_NAME,
|
|
|
|
|
.write = lpuart_console_write,
|
|
|
|
|
.device = uart_console_device,
|
|
|
|
|
.setup = lpuart_console_setup,
|
|
|
|
|
.flags = CON_PRINTBUFFER,
|
|
|
|
|
.index = -1,
|
|
|
|
|
.data = &lpuart_reg,
|
|
|
|
|
};
|
|
|
|
|
|
2014-07-14 09:41:11 +00:00
|
|
|
|
static struct console lpuart32_console = {
|
|
|
|
|
.name = DEV_NAME,
|
|
|
|
|
.write = lpuart32_console_write,
|
|
|
|
|
.device = uart_console_device,
|
|
|
|
|
.setup = lpuart_console_setup,
|
|
|
|
|
.flags = CON_PRINTBUFFER,
|
|
|
|
|
.index = -1,
|
|
|
|
|
.data = &lpuart_reg,
|
|
|
|
|
};
|
|
|
|
|
|
2015-10-17 07:45:55 +00:00
|
|
|
|
static void lpuart_early_write(struct console *con, const char *s, unsigned n)
|
|
|
|
|
{
|
|
|
|
|
struct earlycon_device *dev = con->data;
|
|
|
|
|
|
|
|
|
|
uart_console_write(&dev->port, s, n, lpuart_console_putchar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void lpuart32_early_write(struct console *con, const char *s, unsigned n)
|
|
|
|
|
{
|
|
|
|
|
struct earlycon_device *dev = con->data;
|
|
|
|
|
|
|
|
|
|
uart_console_write(&dev->port, s, n, lpuart32_console_putchar);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int __init lpuart_early_console_setup(struct earlycon_device *device,
|
|
|
|
|
const char *opt)
|
|
|
|
|
{
|
|
|
|
|
if (!device->port.membase)
|
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
|
|
device->con->write = lpuart_early_write;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int __init lpuart32_early_console_setup(struct earlycon_device *device,
|
|
|
|
|
const char *opt)
|
|
|
|
|
{
|
|
|
|
|
if (!device->port.membase)
|
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
2019-12-20 06:13:36 +00:00
|
|
|
|
if (device->port.iotype != UPIO_MEM32)
|
|
|
|
|
device->port.iotype = UPIO_MEM32BE;
|
|
|
|
|
|
2015-10-17 07:45:55 +00:00
|
|
|
|
device->con->write = lpuart32_early_write;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-06 21:44:33 +00:00
|
|
|
|
static int __init ls1028a_early_console_setup(struct earlycon_device *device,
|
|
|
|
|
const char *opt)
|
|
|
|
|
{
|
|
|
|
|
u32 cr;
|
|
|
|
|
|
|
|
|
|
if (!device->port.membase)
|
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
|
|
device->port.iotype = UPIO_MEM32;
|
|
|
|
|
device->con->write = lpuart32_early_write;
|
|
|
|
|
|
|
|
|
|
/* set the baudrate */
|
|
|
|
|
if (device->port.uartclk && device->baud)
|
|
|
|
|
__lpuart32_serial_setbrg(&device->port, device->baud,
|
|
|
|
|
false, false);
|
|
|
|
|
|
|
|
|
|
/* enable transmitter */
|
|
|
|
|
cr = lpuart32_read(&device->port, UARTCTRL);
|
|
|
|
|
cr |= UARTCTRL_TE;
|
|
|
|
|
lpuart32_write(&device->port, cr, UARTCTRL);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-13 02:55:53 +00:00
|
|
|
|
static int __init lpuart32_imx_early_console_setup(struct earlycon_device *device,
|
|
|
|
|
const char *opt)
|
|
|
|
|
{
|
|
|
|
|
if (!device->port.membase)
|
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
|
|
device->port.iotype = UPIO_MEM32;
|
|
|
|
|
device->port.membase += IMX_REG_OFF;
|
|
|
|
|
device->con->write = lpuart32_early_write;
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2015-10-17 07:45:55 +00:00
|
|
|
|
OF_EARLYCON_DECLARE(lpuart, "fsl,vf610-lpuart", lpuart_early_console_setup);
|
|
|
|
|
OF_EARLYCON_DECLARE(lpuart32, "fsl,ls1021a-lpuart", lpuart32_early_console_setup);
|
2020-03-06 21:44:33 +00:00
|
|
|
|
OF_EARLYCON_DECLARE(lpuart32, "fsl,ls1028a-lpuart", ls1028a_early_console_setup);
|
2017-06-13 02:55:53 +00:00
|
|
|
|
OF_EARLYCON_DECLARE(lpuart32, "fsl,imx7ulp-lpuart", lpuart32_imx_early_console_setup);
|
2020-03-03 17:42:58 +00:00
|
|
|
|
EARLYCON_DECLARE(lpuart, lpuart_early_console_setup);
|
|
|
|
|
EARLYCON_DECLARE(lpuart32, lpuart32_early_console_setup);
|
2015-10-17 07:45:55 +00:00
|
|
|
|
|
2013-06-07 01:20:40 +00:00
|
|
|
|
#define LPUART_CONSOLE (&lpuart_console)
|
2014-07-14 09:41:11 +00:00
|
|
|
|
#define LPUART32_CONSOLE (&lpuart32_console)
|
2013-06-07 01:20:40 +00:00
|
|
|
|
#else
|
|
|
|
|
#define LPUART_CONSOLE NULL
|
2014-07-14 09:41:11 +00:00
|
|
|
|
#define LPUART32_CONSOLE NULL
|
2013-06-07 01:20:40 +00:00
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
static struct uart_driver lpuart_reg = {
|
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
|
.driver_name = DRIVER_NAME,
|
|
|
|
|
.dev_name = DEV_NAME,
|
|
|
|
|
.nr = ARRAY_SIZE(lpuart_ports),
|
|
|
|
|
.cons = LPUART_CONSOLE,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int lpuart_probe(struct platform_device *pdev)
|
|
|
|
|
{
|
2021-01-18 12:44:47 +00:00
|
|
|
|
const struct lpuart_soc_data *sdata = of_device_get_match_data(&pdev->dev);
|
2013-06-07 01:20:40 +00:00
|
|
|
|
struct device_node *np = pdev->dev.of_node;
|
|
|
|
|
struct lpuart_port *sport;
|
|
|
|
|
struct resource *res;
|
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
|
|
sport = devm_kzalloc(&pdev->dev, sizeof(*sport), GFP_KERNEL);
|
|
|
|
|
if (!sport)
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
2014-11-07 02:23:13 +00:00
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
2013-06-07 01:20:40 +00:00
|
|
|
|
sport->port.membase = devm_ioremap_resource(&pdev->dev, res);
|
|
|
|
|
if (IS_ERR(sport->port.membase))
|
|
|
|
|
return PTR_ERR(sport->port.membase);
|
|
|
|
|
|
2017-06-13 02:55:52 +00:00
|
|
|
|
sport->port.membase += sdata->reg_off;
|
2014-11-07 02:23:13 +00:00
|
|
|
|
sport->port.mapbase = res->start;
|
2013-06-07 01:20:40 +00:00
|
|
|
|
sport->port.dev = &pdev->dev;
|
|
|
|
|
sport->port.type = PORT_LPUART;
|
2019-07-04 13:40:07 +00:00
|
|
|
|
sport->devtype = sdata->devtype;
|
2016-05-09 07:23:35 +00:00
|
|
|
|
ret = platform_get_irq(pdev, 0);
|
2019-07-30 18:15:44 +00:00
|
|
|
|
if (ret < 0)
|
2016-05-09 07:23:35 +00:00
|
|
|
|
return ret;
|
|
|
|
|
sport->port.irq = ret;
|
2017-06-13 02:55:48 +00:00
|
|
|
|
sport->port.iotype = sdata->iotype;
|
2017-07-11 11:03:43 +00:00
|
|
|
|
if (lpuart_is_32(sport))
|
2014-07-14 09:41:11 +00:00
|
|
|
|
sport->port.ops = &lpuart32_pops;
|
|
|
|
|
else
|
|
|
|
|
sport->port.ops = &lpuart_pops;
|
2019-12-13 00:06:17 +00:00
|
|
|
|
sport->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_FSL_LPUART_CONSOLE);
|
2013-06-07 01:20:40 +00:00
|
|
|
|
sport->port.flags = UPF_BOOT_AUTOCONF;
|
|
|
|
|
|
2019-10-17 14:14:42 +00:00
|
|
|
|
if (lpuart_is_32(sport))
|
|
|
|
|
sport->port.rs485_config = lpuart32_config_rs485;
|
|
|
|
|
else
|
|
|
|
|
sport->port.rs485_config = lpuart_config_rs485;
|
2016-07-19 07:43:10 +00:00
|
|
|
|
|
2019-07-04 13:40:07 +00:00
|
|
|
|
sport->ipg_clk = devm_clk_get(&pdev->dev, "ipg");
|
|
|
|
|
if (IS_ERR(sport->ipg_clk)) {
|
|
|
|
|
ret = PTR_ERR(sport->ipg_clk);
|
|
|
|
|
dev_err(&pdev->dev, "failed to get uart ipg clk: %d\n", ret);
|
2013-06-07 01:20:40 +00:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-04 13:40:07 +00:00
|
|
|
|
sport->baud_clk = NULL;
|
|
|
|
|
if (is_imx8qxp_lpuart(sport)) {
|
|
|
|
|
sport->baud_clk = devm_clk_get(&pdev->dev, "baud");
|
|
|
|
|
if (IS_ERR(sport->baud_clk)) {
|
|
|
|
|
ret = PTR_ERR(sport->baud_clk);
|
|
|
|
|
dev_err(&pdev->dev, "failed to get uart baud clk: %d\n", ret);
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
2013-06-07 01:20:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-03-03 17:42:59 +00:00
|
|
|
|
ret = of_alias_get_id(np, "serial");
|
|
|
|
|
if (ret < 0) {
|
|
|
|
|
ret = ida_simple_get(&fsl_lpuart_ida, 0, UART_NR, GFP_KERNEL);
|
|
|
|
|
if (ret < 0) {
|
|
|
|
|
dev_err(&pdev->dev, "port line is full, add device failed\n");
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
sport->id_allocated = true;
|
|
|
|
|
}
|
|
|
|
|
if (ret >= ARRAY_SIZE(lpuart_ports)) {
|
|
|
|
|
dev_err(&pdev->dev, "serial%d out of range\n", ret);
|
|
|
|
|
ret = -EINVAL;
|
|
|
|
|
goto failed_out_of_range;
|
|
|
|
|
}
|
|
|
|
|
sport->port.line = ret;
|
|
|
|
|
|
2019-07-04 13:40:07 +00:00
|
|
|
|
ret = lpuart_enable_clks(sport);
|
|
|
|
|
if (ret)
|
2020-03-03 17:42:59 +00:00
|
|
|
|
goto failed_clock_enable;
|
2019-07-04 13:40:07 +00:00
|
|
|
|
sport->port.uartclk = lpuart_get_baud_clk_rate(sport);
|
2013-06-07 01:20:40 +00:00
|
|
|
|
|
|
|
|
|
lpuart_ports[sport->port.line] = sport;
|
|
|
|
|
|
|
|
|
|
platform_set_drvdata(pdev, &sport->port);
|
|
|
|
|
|
2017-09-04 11:20:24 +00:00
|
|
|
|
if (lpuart_is_32(sport)) {
|
2014-07-14 09:41:11 +00:00
|
|
|
|
lpuart_reg.cons = LPUART32_CONSOLE;
|
2017-09-04 11:20:24 +00:00
|
|
|
|
ret = devm_request_irq(&pdev->dev, sport->port.irq, lpuart32_int, 0,
|
|
|
|
|
DRIVER_NAME, sport);
|
|
|
|
|
} else {
|
2014-07-14 09:41:11 +00:00
|
|
|
|
lpuart_reg.cons = LPUART_CONSOLE;
|
2017-09-04 11:20:24 +00:00
|
|
|
|
ret = devm_request_irq(&pdev->dev, sport->port.irq, lpuart_int, 0,
|
|
|
|
|
DRIVER_NAME, sport);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
|
goto failed_irq_request;
|
2014-07-14 09:41:11 +00:00
|
|
|
|
|
2013-06-07 01:20:40 +00:00
|
|
|
|
ret = uart_add_one_port(&lpuart_reg, &sport->port);
|
2017-09-04 11:20:24 +00:00
|
|
|
|
if (ret)
|
|
|
|
|
goto failed_attach_port;
|
2013-06-07 01:20:40 +00:00
|
|
|
|
|
2020-05-12 12:40:02 +00:00
|
|
|
|
ret = uart_get_rs485_mode(&sport->port);
|
|
|
|
|
if (ret)
|
|
|
|
|
goto failed_get_rs485;
|
2017-09-13 08:18:29 +00:00
|
|
|
|
|
2017-11-24 22:26:40 +00:00
|
|
|
|
if (sport->port.rs485.flags & SER_RS485_RX_DURING_TX)
|
2017-09-13 08:18:29 +00:00
|
|
|
|
dev_err(&pdev->dev, "driver doesn't support RX during TX\n");
|
|
|
|
|
|
|
|
|
|
if (sport->port.rs485.delay_rts_before_send ||
|
2017-11-24 22:26:40 +00:00
|
|
|
|
sport->port.rs485.delay_rts_after_send)
|
2017-09-13 08:18:29 +00:00
|
|
|
|
dev_err(&pdev->dev, "driver doesn't support RTS delays\n");
|
|
|
|
|
|
2019-10-17 14:14:42 +00:00
|
|
|
|
sport->port.rs485_config(&sport->port, &sport->port.rs485);
|
2017-09-13 08:18:29 +00:00
|
|
|
|
|
2013-06-07 01:20:40 +00:00
|
|
|
|
return 0;
|
2017-09-04 11:20:24 +00:00
|
|
|
|
|
2020-05-12 12:40:02 +00:00
|
|
|
|
failed_get_rs485:
|
2017-09-04 11:20:24 +00:00
|
|
|
|
failed_attach_port:
|
|
|
|
|
failed_irq_request:
|
2019-07-04 13:40:07 +00:00
|
|
|
|
lpuart_disable_clks(sport);
|
2020-03-03 17:42:59 +00:00
|
|
|
|
failed_clock_enable:
|
|
|
|
|
failed_out_of_range:
|
|
|
|
|
if (sport->id_allocated)
|
|
|
|
|
ida_simple_remove(&fsl_lpuart_ida, sport->port.line);
|
2017-09-04 11:20:24 +00:00
|
|
|
|
return ret;
|
2013-06-07 01:20:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int lpuart_remove(struct platform_device *pdev)
|
|
|
|
|
{
|
|
|
|
|
struct lpuart_port *sport = platform_get_drvdata(pdev);
|
|
|
|
|
|
|
|
|
|
uart_remove_one_port(&lpuart_reg, &sport->port);
|
|
|
|
|
|
2020-03-03 17:42:59 +00:00
|
|
|
|
if (sport->id_allocated)
|
|
|
|
|
ida_simple_remove(&fsl_lpuart_ida, sport->port.line);
|
2018-10-09 22:26:16 +00:00
|
|
|
|
|
2019-07-04 13:40:07 +00:00
|
|
|
|
lpuart_disable_clks(sport);
|
2013-06-07 01:20:40 +00:00
|
|
|
|
|
2015-01-10 08:33:45 +00:00
|
|
|
|
if (sport->dma_tx_chan)
|
|
|
|
|
dma_release_channel(sport->dma_tx_chan);
|
|
|
|
|
|
|
|
|
|
if (sport->dma_rx_chan)
|
|
|
|
|
dma_release_channel(sport->dma_rx_chan);
|
|
|
|
|
|
2013-06-07 01:20:40 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-15 12:58:01 +00:00
|
|
|
|
static int __maybe_unused lpuart_suspend(struct device *dev)
|
2013-06-07 01:20:40 +00:00
|
|
|
|
{
|
|
|
|
|
struct lpuart_port *sport = dev_get_drvdata(dev);
|
2015-01-23 09:48:54 +00:00
|
|
|
|
unsigned long temp;
|
2017-08-13 14:47:39 +00:00
|
|
|
|
bool irq_wake;
|
2015-01-23 09:48:54 +00:00
|
|
|
|
|
2017-07-11 11:03:43 +00:00
|
|
|
|
if (lpuart_is_32(sport)) {
|
2015-01-23 09:48:54 +00:00
|
|
|
|
/* disable Rx/Tx and interrupts */
|
2017-06-13 02:55:49 +00:00
|
|
|
|
temp = lpuart32_read(&sport->port, UARTCTRL);
|
2015-01-23 09:48:54 +00:00
|
|
|
|
temp &= ~(UARTCTRL_TE | UARTCTRL_TIE | UARTCTRL_TCIE);
|
2017-06-13 02:55:49 +00:00
|
|
|
|
lpuart32_write(&sport->port, temp, UARTCTRL);
|
2015-01-23 09:48:54 +00:00
|
|
|
|
} else {
|
|
|
|
|
/* disable Rx/Tx and interrupts */
|
|
|
|
|
temp = readb(sport->port.membase + UARTCR2);
|
|
|
|
|
temp &= ~(UARTCR2_TE | UARTCR2_TIE | UARTCR2_TCIE);
|
|
|
|
|
writeb(temp, sport->port.membase + UARTCR2);
|
|
|
|
|
}
|
2013-06-07 01:20:40 +00:00
|
|
|
|
|
|
|
|
|
uart_suspend_port(&lpuart_reg, &sport->port);
|
2016-07-19 07:43:09 +00:00
|
|
|
|
|
2017-08-13 14:47:39 +00:00
|
|
|
|
/* uart_suspend_port() might set wakeup flag */
|
|
|
|
|
irq_wake = irqd_is_wakeup_set(irq_get_irq_data(sport->port.irq));
|
|
|
|
|
|
2016-07-19 07:43:09 +00:00
|
|
|
|
if (sport->lpuart_dma_rx_use) {
|
|
|
|
|
/*
|
|
|
|
|
* EDMA driver during suspend will forcefully release any
|
|
|
|
|
* non-idle DMA channels. If port wakeup is enabled or if port
|
|
|
|
|
* is console port or 'no_console_suspend' is set the Rx DMA
|
|
|
|
|
* cannot resume as as expected, hence gracefully release the
|
|
|
|
|
* Rx DMA path before suspend and start Rx DMA path on resume.
|
|
|
|
|
*/
|
2017-08-13 14:47:39 +00:00
|
|
|
|
if (irq_wake) {
|
2016-07-19 07:43:09 +00:00
|
|
|
|
del_timer_sync(&sport->lpuart_timer);
|
|
|
|
|
lpuart_dma_rx_free(&sport->port);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Disable Rx DMA to use UART port as wakeup source */
|
2019-01-23 03:20:17 +00:00
|
|
|
|
if (lpuart_is_32(sport)) {
|
|
|
|
|
temp = lpuart32_read(&sport->port, UARTBAUD);
|
|
|
|
|
lpuart32_write(&sport->port, temp & ~UARTBAUD_RDMAE,
|
|
|
|
|
UARTBAUD);
|
|
|
|
|
} else {
|
|
|
|
|
writeb(readb(sport->port.membase + UARTCR5) &
|
|
|
|
|
~UARTCR5_RDMAS, sport->port.membase + UARTCR5);
|
|
|
|
|
}
|
2016-07-19 07:43:09 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (sport->lpuart_dma_tx_use) {
|
|
|
|
|
sport->dma_tx_in_progress = false;
|
|
|
|
|
dmaengine_terminate_all(sport->dma_tx_chan);
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-13 14:47:39 +00:00
|
|
|
|
if (sport->port.suspended && !irq_wake)
|
2019-07-04 13:40:07 +00:00
|
|
|
|
lpuart_disable_clks(sport);
|
2013-06-07 01:20:40 +00:00
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-15 12:58:01 +00:00
|
|
|
|
static int __maybe_unused lpuart_resume(struct device *dev)
|
2013-06-07 01:20:40 +00:00
|
|
|
|
{
|
|
|
|
|
struct lpuart_port *sport = dev_get_drvdata(dev);
|
2017-08-13 14:47:39 +00:00
|
|
|
|
bool irq_wake = irqd_is_wakeup_set(irq_get_irq_data(sport->port.irq));
|
2014-10-24 09:20:49 +00:00
|
|
|
|
|
2017-08-13 14:47:39 +00:00
|
|
|
|
if (sport->port.suspended && !irq_wake)
|
2019-07-04 13:40:07 +00:00
|
|
|
|
lpuart_enable_clks(sport);
|
2016-07-19 07:43:04 +00:00
|
|
|
|
|
2019-08-05 18:56:59 +00:00
|
|
|
|
if (lpuart_is_32(sport))
|
|
|
|
|
lpuart32_setup_watermark_enable(sport);
|
|
|
|
|
else
|
|
|
|
|
lpuart_setup_watermark_enable(sport);
|
2013-06-07 01:20:40 +00:00
|
|
|
|
|
2016-07-19 07:43:09 +00:00
|
|
|
|
if (sport->lpuart_dma_rx_use) {
|
2017-08-13 14:47:39 +00:00
|
|
|
|
if (irq_wake) {
|
2016-12-04 15:49:28 +00:00
|
|
|
|
if (!lpuart_start_rx_dma(sport))
|
2016-07-19 07:43:09 +00:00
|
|
|
|
rx_dma_timer_init(sport);
|
2016-12-04 15:49:28 +00:00
|
|
|
|
else
|
2016-07-19 07:43:09 +00:00
|
|
|
|
sport->lpuart_dma_rx_use = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-05 18:56:56 +00:00
|
|
|
|
lpuart_tx_dma_startup(sport);
|
2016-07-19 07:43:09 +00:00
|
|
|
|
|
2019-08-05 18:56:58 +00:00
|
|
|
|
if (lpuart_is_32(sport))
|
|
|
|
|
lpuart32_configure(sport);
|
2019-01-23 03:20:17 +00:00
|
|
|
|
|
2013-06-07 01:20:40 +00:00
|
|
|
|
uart_resume_port(&lpuart_reg, &sport->port);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static SIMPLE_DEV_PM_OPS(lpuart_pm_ops, lpuart_suspend, lpuart_resume);
|
|
|
|
|
|
|
|
|
|
static struct platform_driver lpuart_driver = {
|
|
|
|
|
.probe = lpuart_probe,
|
|
|
|
|
.remove = lpuart_remove,
|
|
|
|
|
.driver = {
|
|
|
|
|
.name = "fsl-lpuart",
|
|
|
|
|
.of_match_table = lpuart_dt_ids,
|
|
|
|
|
.pm = &lpuart_pm_ops,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static int __init lpuart_serial_init(void)
|
|
|
|
|
{
|
2014-11-07 02:23:14 +00:00
|
|
|
|
int ret = uart_register_driver(&lpuart_reg);
|
2013-06-07 01:20:40 +00:00
|
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
|
|
ret = platform_driver_register(&lpuart_driver);
|
|
|
|
|
if (ret)
|
|
|
|
|
uart_unregister_driver(&lpuart_reg);
|
|
|
|
|
|
2013-07-22 01:12:36 +00:00
|
|
|
|
return ret;
|
2013-06-07 01:20:40 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void __exit lpuart_serial_exit(void)
|
|
|
|
|
{
|
2018-10-09 22:26:16 +00:00
|
|
|
|
ida_destroy(&fsl_lpuart_ida);
|
2013-06-07 01:20:40 +00:00
|
|
|
|
platform_driver_unregister(&lpuart_driver);
|
|
|
|
|
uart_unregister_driver(&lpuart_reg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module_init(lpuart_serial_init);
|
|
|
|
|
module_exit(lpuart_serial_exit);
|
|
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("Freescale lpuart serial port driver");
|
|
|
|
|
MODULE_LICENSE("GPL v2");
|