2017-11-07 01:11:51 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
2015-02-24 18:17:08 +08:00
|
|
|
* Driver for Motorola/Freescale IMX serial ports
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
2015-02-24 18:17:08 +08:00
|
|
|
* Based on drivers/char/serial.c, by Linus Torvalds, Theodore Ts'o.
|
2005-04-17 06:20:36 +08:00
|
|
|
*
|
2015-02-24 18:17:08 +08:00
|
|
|
* Author: Sascha Hauer <sascha@saschahauer.de>
|
|
|
|
* Copyright (C) 2004 Pengutronix
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/ioport.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/console.h>
|
|
|
|
#include <linux/sysrq.h>
|
2005-10-30 02:07:23 +08:00
|
|
|
#include <linux/platform_device.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
#include <linux/tty.h>
|
|
|
|
#include <linux/tty_flip.h>
|
|
|
|
#include <linux/serial_core.h>
|
|
|
|
#include <linux/serial.h>
|
2008-07-05 16:02:46 +08:00
|
|
|
#include <linux/clk.h>
|
2009-06-11 21:53:18 +08:00
|
|
|
#include <linux/delay.h>
|
2020-07-14 17:30:12 +08:00
|
|
|
#include <linux/ktime.h>
|
2018-09-05 09:24:27 +08:00
|
|
|
#include <linux/pinctrl/consumer.h>
|
2009-06-11 21:52:23 +08:00
|
|
|
#include <linux/rational.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2011-06-25 02:04:34 +08:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_device.h>
|
2013-01-07 12:55:03 +08:00
|
|
|
#include <linux/io.h>
|
2013-07-08 17:14:18 +08:00
|
|
|
#include <linux/dma-mapping.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
#include <asm/irq.h>
|
2012-08-24 21:14:29 +08:00
|
|
|
#include <linux/platform_data/serial-imx.h>
|
2013-07-08 17:14:18 +08:00
|
|
|
#include <linux/platform_data/dma-imx.h>
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-12-13 18:30:03 +08:00
|
|
|
#include "serial_mctrl_gpio.h"
|
|
|
|
|
2007-04-26 15:26:13 +08:00
|
|
|
/* Register definitions */
|
|
|
|
#define URXD0 0x0 /* Receiver Register */
|
|
|
|
#define URTX0 0x40 /* Transmitter Register */
|
|
|
|
#define UCR1 0x80 /* Control Register 1 */
|
|
|
|
#define UCR2 0x84 /* Control Register 2 */
|
|
|
|
#define UCR3 0x88 /* Control Register 3 */
|
|
|
|
#define UCR4 0x8c /* Control Register 4 */
|
|
|
|
#define UFCR 0x90 /* FIFO Control Register */
|
|
|
|
#define USR1 0x94 /* Status Register 1 */
|
|
|
|
#define USR2 0x98 /* Status Register 2 */
|
|
|
|
#define UESC 0x9c /* Escape Character Register */
|
|
|
|
#define UTIM 0xa0 /* Escape Timer Register */
|
|
|
|
#define UBIR 0xa4 /* BRM Incremental Register */
|
|
|
|
#define UBMR 0xa8 /* BRM Modulator Register */
|
|
|
|
#define UBRC 0xac /* Baud Rate Count Register */
|
2011-06-25 02:04:33 +08:00
|
|
|
#define IMX21_ONEMS 0xb0 /* One Millisecond register */
|
|
|
|
#define IMX1_UTS 0xd0 /* UART Test Register on i.mx1 */
|
|
|
|
#define IMX21_UTS 0xb4 /* UART Test Register on all other i.mx*/
|
2007-04-26 15:26:13 +08:00
|
|
|
|
|
|
|
/* UART Control Register Bit Fields.*/
|
2014-12-09 17:11:22 +08:00
|
|
|
#define URXD_DUMMY_READ (1<<16)
|
2013-01-07 12:55:02 +08:00
|
|
|
#define URXD_CHARRDY (1<<15)
|
|
|
|
#define URXD_ERR (1<<14)
|
|
|
|
#define URXD_OVRRUN (1<<13)
|
|
|
|
#define URXD_FRMERR (1<<12)
|
|
|
|
#define URXD_BRK (1<<11)
|
|
|
|
#define URXD_PRERR (1<<10)
|
2014-09-03 19:33:53 +08:00
|
|
|
#define URXD_RX_DATA (0xFF<<0)
|
2013-01-07 12:55:02 +08:00
|
|
|
#define UCR1_ADEN (1<<15) /* Auto detect interrupt */
|
|
|
|
#define UCR1_ADBR (1<<14) /* Auto detect baud rate */
|
|
|
|
#define UCR1_TRDYEN (1<<13) /* Transmitter ready interrupt enable */
|
|
|
|
#define UCR1_IDEN (1<<12) /* Idle condition interrupt */
|
2013-07-08 17:14:18 +08:00
|
|
|
#define UCR1_ICD_REG(x) (((x) & 3) << 10) /* idle condition detect */
|
2013-01-07 12:55:02 +08:00
|
|
|
#define UCR1_RRDYEN (1<<9) /* Recv ready interrupt enable */
|
2018-02-28 05:44:55 +08:00
|
|
|
#define UCR1_RXDMAEN (1<<8) /* Recv ready DMA enable */
|
2013-01-07 12:55:02 +08:00
|
|
|
#define UCR1_IREN (1<<7) /* Infrared interface enable */
|
|
|
|
#define UCR1_TXMPTYEN (1<<6) /* Transimitter empty interrupt enable */
|
|
|
|
#define UCR1_RTSDEN (1<<5) /* RTS delta interrupt enable */
|
|
|
|
#define UCR1_SNDBRK (1<<4) /* Send break */
|
2018-02-28 05:44:55 +08:00
|
|
|
#define UCR1_TXDMAEN (1<<3) /* Transmitter ready DMA enable */
|
2013-01-07 12:55:02 +08:00
|
|
|
#define IMX1_UCR1_UARTCLKEN (1<<2) /* UART clock enabled, i.mx1 only */
|
2013-07-08 17:14:18 +08:00
|
|
|
#define UCR1_ATDMAEN (1<<2) /* Aging DMA Timer Enable */
|
2013-01-07 12:55:02 +08:00
|
|
|
#define UCR1_DOZE (1<<1) /* Doze */
|
|
|
|
#define UCR1_UARTEN (1<<0) /* UART enabled */
|
|
|
|
#define UCR2_ESCI (1<<15) /* Escape seq interrupt enable */
|
|
|
|
#define UCR2_IRTS (1<<14) /* Ignore RTS pin */
|
|
|
|
#define UCR2_CTSC (1<<13) /* CTS pin control */
|
|
|
|
#define UCR2_CTS (1<<12) /* Clear to send */
|
|
|
|
#define UCR2_ESCEN (1<<11) /* Escape enable */
|
|
|
|
#define UCR2_PREN (1<<8) /* Parity enable */
|
|
|
|
#define UCR2_PROE (1<<7) /* Parity odd/even */
|
|
|
|
#define UCR2_STPB (1<<6) /* Stop */
|
|
|
|
#define UCR2_WS (1<<5) /* Word size */
|
|
|
|
#define UCR2_RTSEN (1<<4) /* Request to send interrupt enable */
|
|
|
|
#define UCR2_ATEN (1<<3) /* Aging Timer Enable */
|
|
|
|
#define UCR2_TXEN (1<<2) /* Transmitter enabled */
|
|
|
|
#define UCR2_RXEN (1<<1) /* Receiver enabled */
|
|
|
|
#define UCR2_SRST (1<<0) /* SW reset */
|
|
|
|
#define UCR3_DTREN (1<<13) /* DTR interrupt enable */
|
|
|
|
#define UCR3_PARERREN (1<<12) /* Parity enable */
|
|
|
|
#define UCR3_FRAERREN (1<<11) /* Frame error interrupt enable */
|
|
|
|
#define UCR3_DSR (1<<10) /* Data set ready */
|
|
|
|
#define UCR3_DCD (1<<9) /* Data carrier detect */
|
|
|
|
#define UCR3_RI (1<<8) /* Ring indicator */
|
2014-05-15 02:55:03 +08:00
|
|
|
#define UCR3_ADNIMP (1<<7) /* Autobaud Detection Not Improved */
|
2013-01-07 12:55:02 +08:00
|
|
|
#define UCR3_RXDSEN (1<<6) /* Receive status interrupt enable */
|
|
|
|
#define UCR3_AIRINTEN (1<<5) /* Async IR wake interrupt enable */
|
|
|
|
#define UCR3_AWAKEN (1<<4) /* Async wake interrupt enable */
|
2016-03-24 21:24:25 +08:00
|
|
|
#define UCR3_DTRDEN (1<<3) /* Data Terminal Ready Delta Enable. */
|
2013-01-07 12:55:02 +08:00
|
|
|
#define IMX21_UCR3_RXDMUXSEL (1<<2) /* RXD Muxed Input Select */
|
|
|
|
#define UCR3_INVT (1<<1) /* Inverted Infrared transmission */
|
|
|
|
#define UCR3_BPEN (1<<0) /* Preset registers enable */
|
|
|
|
#define UCR4_CTSTL_SHF 10 /* CTS trigger level shift */
|
|
|
|
#define UCR4_CTSTL_MASK 0x3F /* CTS trigger is 6 bits wide */
|
|
|
|
#define UCR4_INVR (1<<9) /* Inverted infrared reception */
|
|
|
|
#define UCR4_ENIRI (1<<8) /* Serial infrared interrupt enable */
|
|
|
|
#define UCR4_WKEN (1<<7) /* Wake interrupt enable */
|
|
|
|
#define UCR4_REF16 (1<<6) /* Ref freq 16 MHz */
|
2013-07-08 17:14:18 +08:00
|
|
|
#define UCR4_IDDMAEN (1<<6) /* DMA IDLE Condition Detected */
|
2013-01-07 12:55:02 +08:00
|
|
|
#define UCR4_IRSC (1<<5) /* IR special case */
|
|
|
|
#define UCR4_TCEN (1<<3) /* Transmit complete interrupt enable */
|
|
|
|
#define UCR4_BKEN (1<<2) /* Break condition interrupt enable */
|
|
|
|
#define UCR4_OREN (1<<1) /* Receiver overrun interrupt enable */
|
|
|
|
#define UCR4_DREN (1<<0) /* Recv data ready interrupt enable */
|
|
|
|
#define UFCR_RXTL_SHF 0 /* Receiver trigger level shift */
|
|
|
|
#define UFCR_DCEDTE (1<<6) /* DCE/DTE mode select */
|
|
|
|
#define UFCR_RFDIV (7<<7) /* Reference freq divider mask */
|
|
|
|
#define UFCR_RFDIV_REG(x) (((x) < 7 ? 6 - (x) : 6) << 7)
|
|
|
|
#define UFCR_TXTL_SHF 10 /* Transmitter trigger level shift */
|
|
|
|
#define USR1_PARITYERR (1<<15) /* Parity error interrupt flag */
|
|
|
|
#define USR1_RTSS (1<<14) /* RTS pin status */
|
|
|
|
#define USR1_TRDY (1<<13) /* Transmitter ready interrupt/dma flag */
|
|
|
|
#define USR1_RTSD (1<<12) /* RTS delta */
|
|
|
|
#define USR1_ESCF (1<<11) /* Escape seq interrupt flag */
|
|
|
|
#define USR1_FRAMERR (1<<10) /* Frame error interrupt flag */
|
|
|
|
#define USR1_RRDY (1<<9) /* Receiver ready interrupt/dma flag */
|
2015-09-04 23:52:38 +08:00
|
|
|
#define USR1_AGTIM (1<<8) /* Ageing timer interrupt flag */
|
2016-03-24 21:24:25 +08:00
|
|
|
#define USR1_DTRD (1<<7) /* DTR Delta */
|
2013-01-07 12:55:02 +08:00
|
|
|
#define USR1_RXDS (1<<6) /* Receiver idle interrupt flag */
|
|
|
|
#define USR1_AIRINT (1<<5) /* Async IR wake interrupt flag */
|
|
|
|
#define USR1_AWAKE (1<<4) /* Aysnc wake interrupt flag */
|
|
|
|
#define USR2_ADET (1<<15) /* Auto baud rate detect complete */
|
|
|
|
#define USR2_TXFE (1<<14) /* Transmit buffer FIFO empty */
|
|
|
|
#define USR2_DTRF (1<<13) /* DTR edge interrupt flag */
|
|
|
|
#define USR2_IDLE (1<<12) /* Idle condition */
|
2015-10-19 03:34:46 +08:00
|
|
|
#define USR2_RIDELT (1<<10) /* Ring Interrupt Delta */
|
|
|
|
#define USR2_RIIN (1<<9) /* Ring Indicator Input */
|
2013-01-07 12:55:02 +08:00
|
|
|
#define USR2_IRINT (1<<8) /* Serial infrared interrupt flag */
|
|
|
|
#define USR2_WAKE (1<<7) /* Wake */
|
2015-10-19 03:34:46 +08:00
|
|
|
#define USR2_DCDIN (1<<5) /* Data Carrier Detect Input */
|
2013-01-07 12:55:02 +08:00
|
|
|
#define USR2_RTSF (1<<4) /* RTS edge interrupt flag */
|
|
|
|
#define USR2_TXDC (1<<3) /* Transmitter complete */
|
|
|
|
#define USR2_BRCD (1<<2) /* Break condition */
|
|
|
|
#define USR2_ORE (1<<1) /* Overrun error */
|
|
|
|
#define USR2_RDR (1<<0) /* Recv data ready */
|
|
|
|
#define UTS_FRCPERR (1<<13) /* Force parity error */
|
|
|
|
#define UTS_LOOP (1<<12) /* Loop tx and rx */
|
|
|
|
#define UTS_TXEMPTY (1<<6) /* TxFIFO empty */
|
|
|
|
#define UTS_RXEMPTY (1<<5) /* RxFIFO empty */
|
|
|
|
#define UTS_TXFULL (1<<4) /* TxFIFO full */
|
|
|
|
#define UTS_RXFULL (1<<3) /* RxFIFO full */
|
|
|
|
#define UTS_SOFTRST (1<<0) /* Software reset */
|
2007-04-26 15:26:13 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/* We've been assigned a range on the "Low-density serial ports" major */
|
2013-01-07 12:55:02 +08:00
|
|
|
#define SERIAL_IMX_MAJOR 207
|
|
|
|
#define MINOR_START 16
|
2008-07-05 16:02:48 +08:00
|
|
|
#define DEV_NAME "ttymxc"
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This determines how often we check the modem status signals
|
|
|
|
* for any change. They generally aren't connected to an IRQ
|
|
|
|
* so we have to poll them. We also check immediately before
|
|
|
|
* filling the TX fifo incase CTS has been dropped.
|
|
|
|
*/
|
|
|
|
#define MCTRL_TIMEOUT (250*HZ/1000)
|
|
|
|
|
|
|
|
#define DRIVER_NAME "IMX-uart"
|
|
|
|
|
2008-07-05 16:02:45 +08:00
|
|
|
#define UART_NR 8
|
|
|
|
|
2015-02-24 18:17:09 +08:00
|
|
|
/* i.MX21 type uart runs on all i.mx except i.MX1 and i.MX6q */
|
2011-06-25 02:04:33 +08:00
|
|
|
enum imx_uart_type {
|
|
|
|
IMX1_UART,
|
|
|
|
IMX21_UART,
|
2016-09-01 17:30:46 +08:00
|
|
|
IMX53_UART,
|
2013-07-08 17:14:17 +08:00
|
|
|
IMX6Q_UART,
|
2011-06-25 02:04:33 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* device type dependent stuff */
|
|
|
|
struct imx_uart_data {
|
|
|
|
unsigned uts_reg;
|
|
|
|
enum imx_uart_type devtype;
|
|
|
|
};
|
|
|
|
|
2020-07-14 17:30:11 +08:00
|
|
|
enum imx_tx_state {
|
|
|
|
OFF,
|
|
|
|
WAIT_AFTER_RTS,
|
|
|
|
SEND,
|
|
|
|
WAIT_AFTER_SEND,
|
|
|
|
};
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
struct imx_port {
|
|
|
|
struct uart_port port;
|
|
|
|
struct timer_list timer;
|
|
|
|
unsigned int old_status;
|
2009-06-11 21:36:29 +08:00
|
|
|
unsigned int have_rtscts:1;
|
2017-01-08 05:29:13 +08:00
|
|
|
unsigned int have_rtsgpio:1;
|
2013-05-30 14:07:12 +08:00
|
|
|
unsigned int dte_mode:1;
|
2020-02-27 06:23:19 +08:00
|
|
|
unsigned int inverted_tx:1;
|
|
|
|
unsigned int inverted_rx:1;
|
2012-03-07 16:31:43 +08:00
|
|
|
struct clk *clk_ipg;
|
|
|
|
struct clk *clk_per;
|
2012-05-22 03:57:39 +08:00
|
|
|
const struct imx_uart_data *devdata;
|
2013-07-08 17:14:18 +08:00
|
|
|
|
2015-12-13 18:30:03 +08:00
|
|
|
struct mctrl_gpios *gpios;
|
|
|
|
|
2018-03-02 18:07:20 +08:00
|
|
|
/* shadow registers */
|
|
|
|
unsigned int ucr1;
|
|
|
|
unsigned int ucr2;
|
|
|
|
unsigned int ucr3;
|
|
|
|
unsigned int ucr4;
|
|
|
|
unsigned int ufcr;
|
|
|
|
|
2013-07-08 17:14:18 +08:00
|
|
|
/* DMA fields */
|
|
|
|
unsigned int dma_is_enabled:1;
|
|
|
|
unsigned int dma_is_rxing:1;
|
|
|
|
unsigned int dma_is_txing:1;
|
|
|
|
struct dma_chan *dma_chan_rx, *dma_chan_tx;
|
|
|
|
struct scatterlist rx_sgl, tx_sgl[2];
|
|
|
|
void *rx_buf;
|
2016-08-08 20:38:27 +08:00
|
|
|
struct circ_buf rx_ring;
|
|
|
|
unsigned int rx_periods;
|
|
|
|
dma_cookie_t rx_cookie;
|
2013-10-15 15:23:40 +08:00
|
|
|
unsigned int tx_bytes;
|
2013-07-08 17:14:18 +08:00
|
|
|
unsigned int dma_tx_nents;
|
2015-07-30 23:32:36 +08:00
|
|
|
unsigned int saved_reg[10];
|
2015-08-12 01:21:23 +08:00
|
|
|
bool context_saved;
|
2020-07-14 17:30:11 +08:00
|
|
|
|
|
|
|
enum imx_tx_state tx_state;
|
2020-07-14 17:30:12 +08:00
|
|
|
struct hrtimer trigger_start_tx;
|
|
|
|
struct hrtimer trigger_stop_tx;
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2011-12-22 16:57:52 +08:00
|
|
|
struct imx_port_ucrs {
|
|
|
|
unsigned int ucr1;
|
|
|
|
unsigned int ucr2;
|
|
|
|
unsigned int ucr3;
|
|
|
|
};
|
|
|
|
|
2011-06-25 02:04:33 +08:00
|
|
|
static struct imx_uart_data imx_uart_devdata[] = {
|
|
|
|
[IMX1_UART] = {
|
|
|
|
.uts_reg = IMX1_UTS,
|
|
|
|
.devtype = IMX1_UART,
|
|
|
|
},
|
|
|
|
[IMX21_UART] = {
|
|
|
|
.uts_reg = IMX21_UTS,
|
|
|
|
.devtype = IMX21_UART,
|
|
|
|
},
|
2016-09-01 17:30:46 +08:00
|
|
|
[IMX53_UART] = {
|
|
|
|
.uts_reg = IMX21_UTS,
|
|
|
|
.devtype = IMX53_UART,
|
|
|
|
},
|
2013-07-08 17:14:17 +08:00
|
|
|
[IMX6Q_UART] = {
|
|
|
|
.uts_reg = IMX21_UTS,
|
|
|
|
.devtype = IMX6Q_UART,
|
|
|
|
},
|
2011-06-25 02:04:33 +08:00
|
|
|
};
|
|
|
|
|
2015-05-01 23:40:02 +08:00
|
|
|
static const struct platform_device_id imx_uart_devtype[] = {
|
2011-06-25 02:04:33 +08:00
|
|
|
{
|
|
|
|
.name = "imx1-uart",
|
|
|
|
.driver_data = (kernel_ulong_t) &imx_uart_devdata[IMX1_UART],
|
|
|
|
}, {
|
|
|
|
.name = "imx21-uart",
|
|
|
|
.driver_data = (kernel_ulong_t) &imx_uart_devdata[IMX21_UART],
|
2016-09-01 17:30:46 +08:00
|
|
|
}, {
|
|
|
|
.name = "imx53-uart",
|
|
|
|
.driver_data = (kernel_ulong_t) &imx_uart_devdata[IMX53_UART],
|
2013-07-08 17:14:17 +08:00
|
|
|
}, {
|
|
|
|
.name = "imx6q-uart",
|
|
|
|
.driver_data = (kernel_ulong_t) &imx_uart_devdata[IMX6Q_UART],
|
2011-06-25 02:04:33 +08:00
|
|
|
}, {
|
|
|
|
/* sentinel */
|
|
|
|
}
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(platform, imx_uart_devtype);
|
|
|
|
|
2015-02-03 18:46:06 +08:00
|
|
|
static const struct of_device_id imx_uart_dt_ids[] = {
|
2013-07-08 17:14:17 +08:00
|
|
|
{ .compatible = "fsl,imx6q-uart", .data = &imx_uart_devdata[IMX6Q_UART], },
|
2016-09-01 17:30:46 +08:00
|
|
|
{ .compatible = "fsl,imx53-uart", .data = &imx_uart_devdata[IMX53_UART], },
|
2011-06-25 02:04:34 +08:00
|
|
|
{ .compatible = "fsl,imx1-uart", .data = &imx_uart_devdata[IMX1_UART], },
|
|
|
|
{ .compatible = "fsl,imx21-uart", .data = &imx_uart_devdata[IMX21_UART], },
|
|
|
|
{ /* sentinel */ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, imx_uart_dt_ids);
|
|
|
|
|
2018-03-02 18:07:19 +08:00
|
|
|
static void imx_uart_writel(struct imx_port *sport, u32 val, u32 offset)
|
|
|
|
{
|
2018-03-02 18:07:20 +08:00
|
|
|
switch (offset) {
|
|
|
|
case UCR1:
|
|
|
|
sport->ucr1 = val;
|
|
|
|
break;
|
|
|
|
case UCR2:
|
|
|
|
sport->ucr2 = val;
|
|
|
|
break;
|
|
|
|
case UCR3:
|
|
|
|
sport->ucr3 = val;
|
|
|
|
break;
|
|
|
|
case UCR4:
|
|
|
|
sport->ucr4 = val;
|
|
|
|
break;
|
|
|
|
case UFCR:
|
|
|
|
sport->ufcr = val;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2018-03-02 18:07:19 +08:00
|
|
|
writel(val, sport->port.membase + offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32 imx_uart_readl(struct imx_port *sport, u32 offset)
|
|
|
|
{
|
2018-03-02 18:07:20 +08:00
|
|
|
switch (offset) {
|
|
|
|
case UCR1:
|
|
|
|
return sport->ucr1;
|
|
|
|
break;
|
|
|
|
case UCR2:
|
|
|
|
/*
|
|
|
|
* UCR2_SRST is the only bit in the cached registers that might
|
|
|
|
* differ from the value that was last written. As it only
|
2018-06-12 17:58:37 +08:00
|
|
|
* automatically becomes one after being cleared, reread
|
|
|
|
* conditionally.
|
2018-03-02 18:07:20 +08:00
|
|
|
*/
|
2018-04-20 20:44:07 +08:00
|
|
|
if (!(sport->ucr2 & UCR2_SRST))
|
2018-03-02 18:07:20 +08:00
|
|
|
sport->ucr2 = readl(sport->port.membase + offset);
|
|
|
|
return sport->ucr2;
|
|
|
|
break;
|
|
|
|
case UCR3:
|
|
|
|
return sport->ucr3;
|
|
|
|
break;
|
|
|
|
case UCR4:
|
|
|
|
return sport->ucr4;
|
|
|
|
break;
|
|
|
|
case UFCR:
|
|
|
|
return sport->ufcr;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return readl(sport->port.membase + offset);
|
|
|
|
}
|
2018-03-02 18:07:19 +08:00
|
|
|
}
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static inline unsigned imx_uart_uts_reg(struct imx_port *sport)
|
2011-06-25 02:04:33 +08:00
|
|
|
{
|
|
|
|
return sport->devdata->uts_reg;
|
|
|
|
}
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static inline int imx_uart_is_imx1(struct imx_port *sport)
|
2011-06-25 02:04:33 +08:00
|
|
|
{
|
|
|
|
return sport->devdata->devtype == IMX1_UART;
|
|
|
|
}
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static inline int imx_uart_is_imx21(struct imx_port *sport)
|
2011-06-25 02:04:33 +08:00
|
|
|
{
|
|
|
|
return sport->devdata->devtype == IMX21_UART;
|
|
|
|
}
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static inline int imx_uart_is_imx53(struct imx_port *sport)
|
2016-09-01 17:30:46 +08:00
|
|
|
{
|
|
|
|
return sport->devdata->devtype == IMX53_UART;
|
|
|
|
}
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static inline int imx_uart_is_imx6q(struct imx_port *sport)
|
2013-07-08 17:14:17 +08:00
|
|
|
{
|
|
|
|
return sport->devdata->devtype == IMX6Q_UART;
|
|
|
|
}
|
2013-02-07 05:00:02 +08:00
|
|
|
/*
|
|
|
|
* Save and restore functions for UCR1, UCR2 and UCR3 registers
|
|
|
|
*/
|
2020-07-24 15:08:14 +08:00
|
|
|
#if IS_ENABLED(CONFIG_SERIAL_IMX_CONSOLE)
|
2018-03-02 18:07:30 +08:00
|
|
|
static void imx_uart_ucrs_save(struct imx_port *sport,
|
2013-02-07 05:00:02 +08:00
|
|
|
struct imx_port_ucrs *ucr)
|
|
|
|
{
|
|
|
|
/* save control registers */
|
2018-03-02 18:07:19 +08:00
|
|
|
ucr->ucr1 = imx_uart_readl(sport, UCR1);
|
|
|
|
ucr->ucr2 = imx_uart_readl(sport, UCR2);
|
|
|
|
ucr->ucr3 = imx_uart_readl(sport, UCR3);
|
2013-02-07 05:00:02 +08:00
|
|
|
}
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static void imx_uart_ucrs_restore(struct imx_port *sport,
|
2013-02-07 05:00:02 +08:00
|
|
|
struct imx_port_ucrs *ucr)
|
|
|
|
{
|
|
|
|
/* restore control registers */
|
2018-03-02 18:07:19 +08:00
|
|
|
imx_uart_writel(sport, ucr->ucr1, UCR1);
|
|
|
|
imx_uart_writel(sport, ucr->ucr2, UCR2);
|
|
|
|
imx_uart_writel(sport, ucr->ucr3, UCR3);
|
2013-02-07 05:00:02 +08:00
|
|
|
}
|
2013-06-05 11:58:46 +08:00
|
|
|
#endif
|
2013-02-07 05:00:02 +08:00
|
|
|
|
2019-06-11 20:05:24 +08:00
|
|
|
/* called with port.lock taken and irqs caller dependent */
|
2018-03-02 18:07:30 +08:00
|
|
|
static void imx_uart_rts_active(struct imx_port *sport, u32 *ucr2)
|
2015-12-13 18:30:03 +08:00
|
|
|
{
|
2017-01-30 19:12:12 +08:00
|
|
|
*ucr2 &= ~(UCR2_CTSC | UCR2_CTS);
|
2015-12-13 18:30:03 +08:00
|
|
|
|
2017-09-21 16:13:12 +08:00
|
|
|
sport->port.mctrl |= TIOCM_RTS;
|
|
|
|
mctrl_gpio_set(sport->gpios, sport->port.mctrl);
|
2015-12-13 18:30:03 +08:00
|
|
|
}
|
|
|
|
|
2019-06-11 20:05:24 +08:00
|
|
|
/* called with port.lock taken and irqs caller dependent */
|
2018-03-02 18:07:30 +08:00
|
|
|
static void imx_uart_rts_inactive(struct imx_port *sport, u32 *ucr2)
|
2015-12-13 18:30:03 +08:00
|
|
|
{
|
2017-01-30 19:12:12 +08:00
|
|
|
*ucr2 &= ~UCR2_CTSC;
|
|
|
|
*ucr2 |= UCR2_CTS;
|
2015-12-13 18:30:03 +08:00
|
|
|
|
2017-09-21 16:13:12 +08:00
|
|
|
sport->port.mctrl &= ~TIOCM_RTS;
|
|
|
|
mctrl_gpio_set(sport->gpios, sport->port.mctrl);
|
2015-12-13 18:30:03 +08:00
|
|
|
}
|
|
|
|
|
2020-07-14 17:30:12 +08:00
|
|
|
static void start_hrtimer_ms(struct hrtimer *hrt, unsigned long msec)
|
|
|
|
{
|
|
|
|
long sec = msec / MSEC_PER_SEC;
|
|
|
|
long nsec = (msec % MSEC_PER_SEC) * 1000000;
|
|
|
|
ktime_t t = ktime_set(sec, nsec);
|
|
|
|
|
|
|
|
hrtimer_start(hrt, t, HRTIMER_MODE_REL);
|
|
|
|
}
|
|
|
|
|
2018-03-02 18:07:26 +08:00
|
|
|
/* called with port.lock taken and irqs off */
|
2018-03-02 18:07:30 +08:00
|
|
|
static void imx_uart_start_rx(struct uart_port *port)
|
2018-03-02 18:07:26 +08:00
|
|
|
{
|
|
|
|
struct imx_port *sport = (struct imx_port *)port;
|
|
|
|
unsigned int ucr1, ucr2;
|
|
|
|
|
|
|
|
ucr1 = imx_uart_readl(sport, UCR1);
|
|
|
|
ucr2 = imx_uart_readl(sport, UCR2);
|
|
|
|
|
|
|
|
ucr2 |= UCR2_RXEN;
|
|
|
|
|
|
|
|
if (sport->dma_is_enabled) {
|
|
|
|
ucr1 |= UCR1_RXDMAEN | UCR1_ATDMAEN;
|
|
|
|
} else {
|
|
|
|
ucr1 |= UCR1_RRDYEN;
|
2018-03-02 18:07:27 +08:00
|
|
|
ucr2 |= UCR2_ATEN;
|
2018-03-02 18:07:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Write UCR2 first as it includes RXEN */
|
|
|
|
imx_uart_writel(sport, ucr2, UCR2);
|
|
|
|
imx_uart_writel(sport, ucr1, UCR1);
|
|
|
|
}
|
|
|
|
|
2018-02-28 05:44:56 +08:00
|
|
|
/* called with port.lock taken and irqs off */
|
2018-03-02 18:07:30 +08:00
|
|
|
static void imx_uart_stop_tx(struct uart_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct imx_port *sport = (struct imx_port *)port;
|
2020-07-14 17:30:11 +08:00
|
|
|
u32 ucr1, ucr4, usr2;
|
|
|
|
|
|
|
|
if (sport->tx_state == OFF)
|
|
|
|
return;
|
2007-04-26 15:26:13 +08:00
|
|
|
|
2014-05-30 10:30:54 +08:00
|
|
|
/*
|
|
|
|
* We are maybe in the SMP context, so if the DMA TX thread is running
|
|
|
|
* on other cpu, we have to wait for it to finish.
|
|
|
|
*/
|
2018-03-02 18:07:21 +08:00
|
|
|
if (sport->dma_is_txing)
|
2014-05-30 10:30:54 +08:00
|
|
|
return;
|
2013-07-08 17:14:18 +08:00
|
|
|
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr1 = imx_uart_readl(sport, UCR1);
|
2019-08-29 02:37:55 +08:00
|
|
|
imx_uart_writel(sport, ucr1 & ~UCR1_TRDYEN, UCR1);
|
2015-02-24 18:17:11 +08:00
|
|
|
|
2020-07-14 17:30:11 +08:00
|
|
|
usr2 = imx_uart_readl(sport, USR2);
|
|
|
|
if (!(usr2 & USR2_TXDC)) {
|
|
|
|
/* The shifter is still busy, so retry once TC triggers */
|
|
|
|
return;
|
|
|
|
}
|
2015-02-24 18:17:11 +08:00
|
|
|
|
2020-07-14 17:30:11 +08:00
|
|
|
ucr4 = imx_uart_readl(sport, UCR4);
|
|
|
|
ucr4 &= ~UCR4_TCEN;
|
|
|
|
imx_uart_writel(sport, ucr4, UCR4);
|
2018-03-02 18:07:26 +08:00
|
|
|
|
2020-07-14 17:30:11 +08:00
|
|
|
/* in rs485 mode disable transmitter */
|
|
|
|
if (port->rs485.flags & SER_RS485_ENABLED) {
|
|
|
|
if (sport->tx_state == SEND) {
|
|
|
|
sport->tx_state = WAIT_AFTER_SEND;
|
2020-07-14 17:30:12 +08:00
|
|
|
start_hrtimer_ms(&sport->trigger_stop_tx,
|
|
|
|
port->rs485.delay_rts_after_send);
|
|
|
|
return;
|
2020-07-14 17:30:11 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (sport->tx_state == WAIT_AFTER_RTS ||
|
2020-07-14 17:30:12 +08:00
|
|
|
sport->tx_state == WAIT_AFTER_SEND) {
|
2020-07-14 17:30:11 +08:00
|
|
|
u32 ucr2;
|
|
|
|
|
2020-07-14 17:30:12 +08:00
|
|
|
hrtimer_try_to_cancel(&sport->trigger_start_tx);
|
2020-07-14 17:30:11 +08:00
|
|
|
|
|
|
|
ucr2 = imx_uart_readl(sport, UCR2);
|
|
|
|
if (port->rs485.flags & SER_RS485_RTS_AFTER_SEND)
|
|
|
|
imx_uart_rts_active(sport, &ucr2);
|
|
|
|
else
|
|
|
|
imx_uart_rts_inactive(sport, &ucr2);
|
|
|
|
imx_uart_writel(sport, ucr2, UCR2);
|
|
|
|
|
|
|
|
imx_uart_start_rx(port);
|
|
|
|
|
|
|
|
sport->tx_state = OFF;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
sport->tx_state = OFF;
|
2015-02-24 18:17:11 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2018-02-28 05:44:56 +08:00
|
|
|
/* called with port.lock taken and irqs off */
|
2018-03-02 18:07:30 +08:00
|
|
|
static void imx_uart_stop_rx(struct uart_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct imx_port *sport = (struct imx_port *)port;
|
2018-03-02 18:07:23 +08:00
|
|
|
u32 ucr1, ucr2;
|
2007-04-26 15:26:13 +08:00
|
|
|
|
2018-03-02 18:07:26 +08:00
|
|
|
ucr1 = imx_uart_readl(sport, UCR1);
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr2 = imx_uart_readl(sport, UCR2);
|
2014-05-23 12:32:54 +08:00
|
|
|
|
2018-03-02 18:07:26 +08:00
|
|
|
if (sport->dma_is_enabled) {
|
|
|
|
ucr1 &= ~(UCR1_RXDMAEN | UCR1_ATDMAEN);
|
|
|
|
} else {
|
|
|
|
ucr1 &= ~UCR1_RRDYEN;
|
2018-03-02 18:07:27 +08:00
|
|
|
ucr2 &= ~UCR2_ATEN;
|
2018-03-02 18:07:26 +08:00
|
|
|
}
|
|
|
|
imx_uart_writel(sport, ucr1, UCR1);
|
|
|
|
|
|
|
|
ucr2 &= ~UCR2_RXEN;
|
|
|
|
imx_uart_writel(sport, ucr2, UCR2);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2018-02-28 05:44:56 +08:00
|
|
|
/* called with port.lock taken and irqs off */
|
2018-03-02 18:07:30 +08:00
|
|
|
static void imx_uart_enable_ms(struct uart_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct imx_port *sport = (struct imx_port *)port;
|
|
|
|
|
|
|
|
mod_timer(&sport->timer, jiffies);
|
2015-12-13 18:30:03 +08:00
|
|
|
|
|
|
|
mctrl_gpio_enable_ms(sport->gpios);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static void imx_uart_dma_tx(struct imx_port *sport);
|
2018-02-28 05:44:56 +08:00
|
|
|
|
|
|
|
/* called with port.lock taken and irqs off */
|
2018-03-02 18:07:30 +08:00
|
|
|
static inline void imx_uart_transmit_buffer(struct imx_port *sport)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-09-20 04:13:28 +08:00
|
|
|
struct circ_buf *xmit = &sport->port.state->xmit;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-09-03 05:39:12 +08:00
|
|
|
if (sport->port.x_char) {
|
|
|
|
/* Send next char */
|
2018-03-02 18:07:19 +08:00
|
|
|
imx_uart_writel(sport, sport->port.x_char, URTX0);
|
2014-12-09 17:11:35 +08:00
|
|
|
sport->port.icount.tx++;
|
|
|
|
sport->port.x_char = 0;
|
2014-09-03 05:39:12 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (uart_circ_empty(xmit) || uart_tx_stopped(&sport->port)) {
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_stop_tx(&sport->port);
|
2014-09-03 05:39:12 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-09 17:11:36 +08:00
|
|
|
if (sport->dma_is_enabled) {
|
2018-03-02 18:07:23 +08:00
|
|
|
u32 ucr1;
|
2014-12-09 17:11:36 +08:00
|
|
|
/*
|
|
|
|
* We've just sent a X-char Ensure the TX DMA is enabled
|
|
|
|
* and the TX IRQ is disabled.
|
|
|
|
**/
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr1 = imx_uart_readl(sport, UCR1);
|
2019-08-29 02:37:55 +08:00
|
|
|
ucr1 &= ~UCR1_TRDYEN;
|
2014-12-09 17:11:36 +08:00
|
|
|
if (sport->dma_is_txing) {
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr1 |= UCR1_TXDMAEN;
|
|
|
|
imx_uart_writel(sport, ucr1, UCR1);
|
2014-12-09 17:11:36 +08:00
|
|
|
} else {
|
2018-03-02 18:07:23 +08:00
|
|
|
imx_uart_writel(sport, ucr1, UCR1);
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_dma_tx(sport);
|
2014-12-09 17:11:36 +08:00
|
|
|
}
|
|
|
|
|
2017-08-28 16:02:29 +08:00
|
|
|
return;
|
2018-03-02 18:07:22 +08:00
|
|
|
}
|
2017-08-28 16:02:29 +08:00
|
|
|
|
|
|
|
while (!uart_circ_empty(xmit) &&
|
2018-03-02 18:07:30 +08:00
|
|
|
!(imx_uart_readl(sport, imx_uart_uts_reg(sport)) & UTS_TXFULL)) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* send xmit->buf[xmit->tail]
|
|
|
|
* out the port here */
|
2018-03-02 18:07:19 +08:00
|
|
|
imx_uart_writel(sport, xmit->buf[xmit->tail], URTX0);
|
2009-06-11 21:35:01 +08:00
|
|
|
xmit->tail = (xmit->tail + 1) & (UART_XMIT_SIZE - 1);
|
2005-04-17 06:20:36 +08:00
|
|
|
sport->port.icount.tx++;
|
2007-02-06 08:10:16 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2009-06-11 21:37:19 +08:00
|
|
|
if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
|
|
|
|
uart_write_wakeup(&sport->port);
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (uart_circ_empty(xmit))
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_stop_tx(&sport->port);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static void imx_uart_dma_tx_callback(void *data)
|
2013-07-08 17:14:18 +08:00
|
|
|
{
|
|
|
|
struct imx_port *sport = data;
|
|
|
|
struct scatterlist *sgl = &sport->tx_sgl[0];
|
|
|
|
struct circ_buf *xmit = &sport->port.state->xmit;
|
|
|
|
unsigned long flags;
|
2018-03-02 18:07:23 +08:00
|
|
|
u32 ucr1;
|
2013-07-08 17:14:18 +08:00
|
|
|
|
2014-12-09 17:11:28 +08:00
|
|
|
spin_lock_irqsave(&sport->port.lock, flags);
|
2013-07-08 17:14:18 +08:00
|
|
|
|
2014-12-09 17:11:28 +08:00
|
|
|
dma_unmap_sg(sport->port.dev, sgl, sport->dma_tx_nents, DMA_TO_DEVICE);
|
2013-07-08 17:14:18 +08:00
|
|
|
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr1 = imx_uart_readl(sport, UCR1);
|
|
|
|
ucr1 &= ~UCR1_TXDMAEN;
|
|
|
|
imx_uart_writel(sport, ucr1, UCR1);
|
2014-12-09 17:11:31 +08:00
|
|
|
|
2013-07-08 17:14:18 +08:00
|
|
|
/* update the stat */
|
|
|
|
xmit->tail = (xmit->tail + sport->tx_bytes) & (UART_XMIT_SIZE - 1);
|
|
|
|
sport->port.icount.tx += sport->tx_bytes;
|
|
|
|
|
|
|
|
dev_dbg(sport->port.dev, "we finish the TX DMA.\n");
|
|
|
|
|
2014-12-09 17:11:28 +08:00
|
|
|
sport->dma_is_txing = 0;
|
|
|
|
|
2014-12-09 17:11:29 +08:00
|
|
|
if (uart_circ_chars_pending(xmit) < WAKEUP_CHARS)
|
|
|
|
uart_write_wakeup(&sport->port);
|
2014-05-30 10:30:54 +08:00
|
|
|
|
2014-12-09 17:11:30 +08:00
|
|
|
if (!uart_circ_empty(xmit) && !uart_tx_stopped(&sport->port))
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_dma_tx(sport);
|
2018-03-02 18:07:28 +08:00
|
|
|
else if (sport->port.rs485.flags & SER_RS485_ENABLED) {
|
|
|
|
u32 ucr4 = imx_uart_readl(sport, UCR4);
|
|
|
|
ucr4 |= UCR4_TCEN;
|
|
|
|
imx_uart_writel(sport, ucr4, UCR4);
|
|
|
|
}
|
2017-07-18 20:01:52 +08:00
|
|
|
|
2014-12-09 17:11:30 +08:00
|
|
|
spin_unlock_irqrestore(&sport->port.lock, flags);
|
2013-07-08 17:14:18 +08:00
|
|
|
}
|
|
|
|
|
2018-02-28 05:44:56 +08:00
|
|
|
/* called with port.lock taken and irqs off */
|
2018-03-02 18:07:30 +08:00
|
|
|
static void imx_uart_dma_tx(struct imx_port *sport)
|
2013-07-08 17:14:18 +08:00
|
|
|
{
|
|
|
|
struct circ_buf *xmit = &sport->port.state->xmit;
|
|
|
|
struct scatterlist *sgl = sport->tx_sgl;
|
|
|
|
struct dma_async_tx_descriptor *desc;
|
|
|
|
struct dma_chan *chan = sport->dma_chan_tx;
|
|
|
|
struct device *dev = sport->port.dev;
|
2018-03-02 18:07:28 +08:00
|
|
|
u32 ucr1, ucr4;
|
2013-07-08 17:14:18 +08:00
|
|
|
int ret;
|
|
|
|
|
2014-12-09 17:11:28 +08:00
|
|
|
if (sport->dma_is_txing)
|
2013-07-08 17:14:18 +08:00
|
|
|
return;
|
|
|
|
|
2018-03-02 18:07:28 +08:00
|
|
|
ucr4 = imx_uart_readl(sport, UCR4);
|
|
|
|
ucr4 &= ~UCR4_TCEN;
|
|
|
|
imx_uart_writel(sport, ucr4, UCR4);
|
|
|
|
|
2013-07-08 17:14:18 +08:00
|
|
|
sport->tx_bytes = uart_circ_chars_pending(xmit);
|
|
|
|
|
2020-02-11 14:16:01 +08:00
|
|
|
if (xmit->tail < xmit->head || xmit->head == 0) {
|
2014-12-09 17:11:25 +08:00
|
|
|
sport->dma_tx_nents = 1;
|
|
|
|
sg_init_one(sgl, xmit->buf + xmit->tail, sport->tx_bytes);
|
|
|
|
} else {
|
2013-07-08 17:14:18 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = dma_map_sg(dev, sgl, sport->dma_tx_nents, DMA_TO_DEVICE);
|
|
|
|
if (ret == 0) {
|
|
|
|
dev_err(dev, "DMA mapping error for TX.\n");
|
|
|
|
return;
|
|
|
|
}
|
2019-11-07 14:42:53 +08:00
|
|
|
desc = dmaengine_prep_slave_sg(chan, sgl, ret,
|
2013-07-08 17:14:18 +08:00
|
|
|
DMA_MEM_TO_DEV, DMA_PREP_INTERRUPT);
|
|
|
|
if (!desc) {
|
2014-12-09 17:11:26 +08:00
|
|
|
dma_unmap_sg(dev, sgl, sport->dma_tx_nents,
|
|
|
|
DMA_TO_DEVICE);
|
2013-07-08 17:14:18 +08:00
|
|
|
dev_err(dev, "We cannot prepare for the TX slave dma!\n");
|
|
|
|
return;
|
|
|
|
}
|
2018-03-02 18:07:30 +08:00
|
|
|
desc->callback = imx_uart_dma_tx_callback;
|
2013-07-08 17:14:18 +08:00
|
|
|
desc->callback_param = sport;
|
|
|
|
|
|
|
|
dev_dbg(dev, "TX: prepare to send %lu bytes by DMA.\n",
|
|
|
|
uart_circ_chars_pending(xmit));
|
2014-12-09 17:11:31 +08:00
|
|
|
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr1 = imx_uart_readl(sport, UCR1);
|
|
|
|
ucr1 |= UCR1_TXDMAEN;
|
|
|
|
imx_uart_writel(sport, ucr1, UCR1);
|
2014-12-09 17:11:31 +08:00
|
|
|
|
2013-07-08 17:14:18 +08:00
|
|
|
/* fire it */
|
|
|
|
sport->dma_is_txing = 1;
|
|
|
|
dmaengine_submit(desc);
|
|
|
|
dma_async_issue_pending(chan);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-02-28 05:44:56 +08:00
|
|
|
/* called with port.lock taken and irqs off */
|
2018-03-02 18:07:30 +08:00
|
|
|
static void imx_uart_start_tx(struct uart_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct imx_port *sport = (struct imx_port *)port;
|
2018-03-02 18:07:23 +08:00
|
|
|
u32 ucr1;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-03-02 18:07:29 +08:00
|
|
|
if (!sport->port.x_char && uart_circ_empty(&port->state->xmit))
|
|
|
|
return;
|
|
|
|
|
2020-07-14 17:30:11 +08:00
|
|
|
/*
|
|
|
|
* We cannot simply do nothing here if sport->tx_state == SEND already
|
|
|
|
* because UCR1_TXMPTYEN might already have been cleared in
|
|
|
|
* imx_uart_stop_tx(), but tx_state is still SEND.
|
|
|
|
*/
|
|
|
|
|
2015-02-24 18:17:11 +08:00
|
|
|
if (port->rs485.flags & SER_RS485_ENABLED) {
|
2020-07-14 17:30:11 +08:00
|
|
|
if (sport->tx_state == OFF) {
|
|
|
|
u32 ucr2 = imx_uart_readl(sport, UCR2);
|
|
|
|
if (port->rs485.flags & SER_RS485_RTS_ON_SEND)
|
|
|
|
imx_uart_rts_active(sport, &ucr2);
|
|
|
|
else
|
|
|
|
imx_uart_rts_inactive(sport, &ucr2);
|
|
|
|
imx_uart_writel(sport, ucr2, UCR2);
|
2018-03-02 18:07:23 +08:00
|
|
|
|
2020-07-14 17:30:11 +08:00
|
|
|
if (!(port->rs485.flags & SER_RS485_RX_DURING_TX))
|
|
|
|
imx_uart_stop_rx(port);
|
2015-02-24 18:17:11 +08:00
|
|
|
|
2020-07-14 17:30:11 +08:00
|
|
|
sport->tx_state = WAIT_AFTER_RTS;
|
2020-07-14 17:30:12 +08:00
|
|
|
start_hrtimer_ms(&sport->trigger_start_tx,
|
|
|
|
port->rs485.delay_rts_before_send);
|
|
|
|
return;
|
2020-07-14 17:30:11 +08:00
|
|
|
}
|
2018-03-02 18:07:26 +08:00
|
|
|
|
2020-07-14 17:30:12 +08:00
|
|
|
if (sport->tx_state == WAIT_AFTER_SEND
|
|
|
|
|| sport->tx_state == WAIT_AFTER_RTS) {
|
|
|
|
|
|
|
|
hrtimer_try_to_cancel(&sport->trigger_stop_tx);
|
2020-07-14 17:30:11 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable transmitter and shifter empty irq only if DMA
|
|
|
|
* is off. In the DMA case this is done in the
|
|
|
|
* tx-callback.
|
|
|
|
*/
|
|
|
|
if (!sport->dma_is_enabled) {
|
|
|
|
u32 ucr4 = imx_uart_readl(sport, UCR4);
|
|
|
|
ucr4 |= UCR4_TCEN;
|
|
|
|
imx_uart_writel(sport, ucr4, UCR4);
|
|
|
|
}
|
|
|
|
|
|
|
|
sport->tx_state = SEND;
|
2018-03-02 18:07:28 +08:00
|
|
|
}
|
2020-07-14 17:30:11 +08:00
|
|
|
} else {
|
|
|
|
sport->tx_state = SEND;
|
2015-02-24 18:17:11 +08:00
|
|
|
}
|
|
|
|
|
2013-07-08 17:14:18 +08:00
|
|
|
if (!sport->dma_is_enabled) {
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr1 = imx_uart_readl(sport, UCR1);
|
2019-08-29 02:37:55 +08:00
|
|
|
imx_uart_writel(sport, ucr1 | UCR1_TRDYEN, UCR1);
|
2013-07-08 17:14:18 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-07-08 17:14:18 +08:00
|
|
|
if (sport->dma_is_enabled) {
|
2014-12-09 17:11:36 +08:00
|
|
|
if (sport->port.x_char) {
|
|
|
|
/* We have X-char to send, so enable TX IRQ and
|
|
|
|
* disable TX DMA to let TX interrupt to send X-char */
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr1 = imx_uart_readl(sport, UCR1);
|
|
|
|
ucr1 &= ~UCR1_TXDMAEN;
|
2019-08-29 02:37:55 +08:00
|
|
|
ucr1 |= UCR1_TRDYEN;
|
2018-03-02 18:07:23 +08:00
|
|
|
imx_uart_writel(sport, ucr1, UCR1);
|
2014-12-09 17:11:36 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-09-03 05:39:12 +08:00
|
|
|
if (!uart_circ_empty(&port->state->xmit) &&
|
|
|
|
!uart_tx_stopped(port))
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_dma_tx(sport);
|
2013-07-08 17:14:18 +08:00
|
|
|
return;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2020-01-21 15:17:02 +08:00
|
|
|
static irqreturn_t __imx_uart_rtsint(int irq, void *dev_id)
|
2005-10-13 02:58:08 +08:00
|
|
|
{
|
2008-02-06 17:36:20 +08:00
|
|
|
struct imx_port *sport = dev_id;
|
2018-03-02 18:07:23 +08:00
|
|
|
u32 usr1;
|
2005-10-13 02:58:08 +08:00
|
|
|
|
2018-03-02 18:07:19 +08:00
|
|
|
imx_uart_writel(sport, USR1_RTSD, USR1);
|
2018-03-02 18:07:23 +08:00
|
|
|
usr1 = imx_uart_readl(sport, USR1) & USR1_RTSS;
|
|
|
|
uart_handle_cts_change(&sport->port, !!usr1);
|
2009-09-20 04:13:31 +08:00
|
|
|
wake_up_interruptible(&sport->port.state->port.delta_msr_wait);
|
2005-10-13 02:58:08 +08:00
|
|
|
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2020-01-21 15:17:02 +08:00
|
|
|
static irqreturn_t imx_uart_rtsint(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
struct imx_port *sport = dev_id;
|
|
|
|
irqreturn_t ret;
|
|
|
|
|
|
|
|
spin_lock(&sport->port.lock);
|
|
|
|
|
|
|
|
ret = __imx_uart_rtsint(irq, dev_id);
|
|
|
|
|
|
|
|
spin_unlock(&sport->port.lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static irqreturn_t imx_uart_txint(int irq, void *dev_id)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-02-06 17:36:20 +08:00
|
|
|
struct imx_port *sport = dev_id;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-08-27 22:49:04 +08:00
|
|
|
spin_lock(&sport->port.lock);
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_transmit_buffer(sport);
|
2018-08-27 22:49:04 +08:00
|
|
|
spin_unlock(&sport->port.lock);
|
2005-04-17 06:20:36 +08:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2020-01-21 15:17:02 +08:00
|
|
|
static irqreturn_t __imx_uart_rxint(int irq, void *dev_id)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct imx_port *sport = dev_id;
|
2013-01-07 12:55:02 +08:00
|
|
|
unsigned int rx, flg, ignored = 0;
|
2013-01-03 22:53:03 +08:00
|
|
|
struct tty_port *port = &sport->port.state->port;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-03-02 18:07:19 +08:00
|
|
|
while (imx_uart_readl(sport, USR2) & USR2_RDR) {
|
2018-03-02 18:07:23 +08:00
|
|
|
u32 usr2;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
flg = TTY_NORMAL;
|
|
|
|
sport->port.icount.rx++;
|
|
|
|
|
2018-03-02 18:07:19 +08:00
|
|
|
rx = imx_uart_readl(sport, URXD0);
|
2008-04-17 15:43:14 +08:00
|
|
|
|
2018-03-02 18:07:23 +08:00
|
|
|
usr2 = imx_uart_readl(sport, USR2);
|
|
|
|
if (usr2 & USR2_BRCD) {
|
2018-03-02 18:07:19 +08:00
|
|
|
imx_uart_writel(sport, USR2_BRCD, USR2);
|
2008-04-17 15:39:22 +08:00
|
|
|
if (uart_handle_break(&sport->port))
|
|
|
|
continue;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2009-06-11 21:35:01 +08:00
|
|
|
if (uart_handle_sysrq_char(&sport->port, (unsigned char)rx))
|
2008-04-17 15:39:22 +08:00
|
|
|
continue;
|
|
|
|
|
2011-08-24 17:41:47 +08:00
|
|
|
if (unlikely(rx & URXD_ERR)) {
|
|
|
|
if (rx & URXD_BRK)
|
|
|
|
sport->port.icount.brk++;
|
|
|
|
else if (rx & URXD_PRERR)
|
2008-04-17 15:39:22 +08:00
|
|
|
sport->port.icount.parity++;
|
|
|
|
else if (rx & URXD_FRMERR)
|
|
|
|
sport->port.icount.frame++;
|
|
|
|
if (rx & URXD_OVRRUN)
|
|
|
|
sport->port.icount.overrun++;
|
|
|
|
|
|
|
|
if (rx & sport->port.ignore_status_mask) {
|
|
|
|
if (++ignored > 100)
|
|
|
|
goto out;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-12-19 03:37:13 +08:00
|
|
|
rx &= (sport->port.read_status_mask | 0xFF);
|
2008-04-17 15:39:22 +08:00
|
|
|
|
2011-08-24 17:41:47 +08:00
|
|
|
if (rx & URXD_BRK)
|
|
|
|
flg = TTY_BREAK;
|
|
|
|
else if (rx & URXD_PRERR)
|
2008-04-17 15:39:22 +08:00
|
|
|
flg = TTY_PARITY;
|
|
|
|
else if (rx & URXD_FRMERR)
|
|
|
|
flg = TTY_FRAME;
|
|
|
|
if (rx & URXD_OVRRUN)
|
|
|
|
flg = TTY_OVERRUN;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2008-04-17 15:39:22 +08:00
|
|
|
sport->port.sysrq = 0;
|
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2014-12-09 17:11:22 +08:00
|
|
|
if (sport->port.ignore_status_mask & URXD_DUMMY_READ)
|
|
|
|
goto out;
|
|
|
|
|
2015-06-21 01:25:35 +08:00
|
|
|
if (tty_insert_flip_char(port, rx, flg) == 0)
|
|
|
|
sport->port.icount.buf_overrun++;
|
2008-04-17 15:39:22 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
out:
|
2013-01-03 22:53:06 +08:00
|
|
|
tty_flip_buffer_push(port);
|
2020-01-21 15:17:02 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2020-01-21 15:17:02 +08:00
|
|
|
static irqreturn_t imx_uart_rxint(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
struct imx_port *sport = dev_id;
|
|
|
|
irqreturn_t ret;
|
|
|
|
|
|
|
|
spin_lock(&sport->port.lock);
|
|
|
|
|
|
|
|
ret = __imx_uart_rxint(irq, dev_id);
|
|
|
|
|
|
|
|
spin_unlock(&sport->port.lock);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static void imx_uart_clear_rx_errors(struct imx_port *sport);
|
2013-07-08 17:14:18 +08:00
|
|
|
|
2016-03-24 21:24:24 +08:00
|
|
|
/*
|
|
|
|
* We have a modem side uart, so the meanings of RTS and CTS are inverted.
|
|
|
|
*/
|
2018-03-02 18:07:30 +08:00
|
|
|
static unsigned int imx_uart_get_hwmctrl(struct imx_port *sport)
|
2016-03-24 21:24:24 +08:00
|
|
|
{
|
|
|
|
unsigned int tmp = TIOCM_DSR;
|
2018-03-02 18:07:19 +08:00
|
|
|
unsigned usr1 = imx_uart_readl(sport, USR1);
|
|
|
|
unsigned usr2 = imx_uart_readl(sport, USR2);
|
2016-03-24 21:24:24 +08:00
|
|
|
|
|
|
|
if (usr1 & USR1_RTSS)
|
|
|
|
tmp |= TIOCM_CTS;
|
|
|
|
|
|
|
|
/* in DCE mode DCDIN is always 0 */
|
2016-09-26 21:55:31 +08:00
|
|
|
if (!(usr2 & USR2_DCDIN))
|
2016-03-24 21:24:24 +08:00
|
|
|
tmp |= TIOCM_CAR;
|
|
|
|
|
|
|
|
if (sport->dte_mode)
|
2018-03-02 18:07:19 +08:00
|
|
|
if (!(imx_uart_readl(sport, USR2) & USR2_RIIN))
|
2016-03-24 21:24:24 +08:00
|
|
|
tmp |= TIOCM_RI;
|
|
|
|
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle any change of modem status signal since we were last called.
|
|
|
|
*/
|
2018-03-02 18:07:30 +08:00
|
|
|
static void imx_uart_mctrl_check(struct imx_port *sport)
|
2016-03-24 21:24:24 +08:00
|
|
|
{
|
|
|
|
unsigned int status, changed;
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
status = imx_uart_get_hwmctrl(sport);
|
2016-03-24 21:24:24 +08:00
|
|
|
changed = status ^ sport->old_status;
|
|
|
|
|
|
|
|
if (changed == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
sport->old_status = status;
|
|
|
|
|
|
|
|
if (changed & TIOCM_RI && status & TIOCM_RI)
|
|
|
|
sport->port.icount.rng++;
|
|
|
|
if (changed & TIOCM_DSR)
|
|
|
|
sport->port.icount.dsr++;
|
|
|
|
if (changed & TIOCM_CAR)
|
|
|
|
uart_handle_dcd_change(&sport->port, status & TIOCM_CAR);
|
|
|
|
if (changed & TIOCM_CTS)
|
|
|
|
uart_handle_cts_change(&sport->port, status & TIOCM_CTS);
|
|
|
|
|
|
|
|
wake_up_interruptible(&sport->port.state->port.delta_msr_wait);
|
|
|
|
}
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static irqreturn_t imx_uart_int(int irq, void *dev_id)
|
2008-07-05 16:02:48 +08:00
|
|
|
{
|
|
|
|
struct imx_port *sport = dev_id;
|
2018-02-19 05:02:44 +08:00
|
|
|
unsigned int usr1, usr2, ucr1, ucr2, ucr3, ucr4;
|
2016-03-24 21:24:21 +08:00
|
|
|
irqreturn_t ret = IRQ_NONE;
|
2008-07-05 16:02:48 +08:00
|
|
|
|
2020-01-21 15:17:02 +08:00
|
|
|
spin_lock(&sport->port.lock);
|
|
|
|
|
2018-03-02 18:07:19 +08:00
|
|
|
usr1 = imx_uart_readl(sport, USR1);
|
|
|
|
usr2 = imx_uart_readl(sport, USR2);
|
|
|
|
ucr1 = imx_uart_readl(sport, UCR1);
|
|
|
|
ucr2 = imx_uart_readl(sport, UCR2);
|
|
|
|
ucr3 = imx_uart_readl(sport, UCR3);
|
|
|
|
ucr4 = imx_uart_readl(sport, UCR4);
|
2008-07-05 16:02:48 +08:00
|
|
|
|
2018-02-19 05:02:44 +08:00
|
|
|
/*
|
|
|
|
* Even if a condition is true that can trigger an irq only handle it if
|
|
|
|
* the respective irq source is enabled. This prevents some undesired
|
|
|
|
* actions, for example if a character that sits in the RX FIFO and that
|
|
|
|
* should be fetched via DMA is tried to be fetched using PIO. Or the
|
|
|
|
* receiver is currently off and so reading from URXD0 results in an
|
|
|
|
* exception. So just mask the (raw) status bits for disabled irqs.
|
|
|
|
*/
|
|
|
|
if ((ucr1 & UCR1_RRDYEN) == 0)
|
|
|
|
usr1 &= ~USR1_RRDY;
|
|
|
|
if ((ucr2 & UCR2_ATEN) == 0)
|
|
|
|
usr1 &= ~USR1_AGTIM;
|
2019-08-29 02:37:55 +08:00
|
|
|
if ((ucr1 & UCR1_TRDYEN) == 0)
|
2018-02-19 05:02:44 +08:00
|
|
|
usr1 &= ~USR1_TRDY;
|
|
|
|
if ((ucr4 & UCR4_TCEN) == 0)
|
|
|
|
usr2 &= ~USR2_TXDC;
|
|
|
|
if ((ucr3 & UCR3_DTRDEN) == 0)
|
|
|
|
usr1 &= ~USR1_DTRD;
|
|
|
|
if ((ucr1 & UCR1_RTSDEN) == 0)
|
|
|
|
usr1 &= ~USR1_RTSD;
|
|
|
|
if ((ucr3 & UCR3_AWAKEN) == 0)
|
|
|
|
usr1 &= ~USR1_AWAKE;
|
|
|
|
if ((ucr4 & UCR4_OREN) == 0)
|
|
|
|
usr2 &= ~USR2_ORE;
|
|
|
|
|
|
|
|
if (usr1 & (USR1_RRDY | USR1_AGTIM)) {
|
2020-05-28 23:47:47 +08:00
|
|
|
imx_uart_writel(sport, USR1_AGTIM, USR1);
|
|
|
|
|
2020-01-21 15:17:02 +08:00
|
|
|
__imx_uart_rxint(irq, dev_id);
|
2016-03-24 21:24:21 +08:00
|
|
|
ret = IRQ_HANDLED;
|
2013-07-08 17:14:18 +08:00
|
|
|
}
|
2008-07-05 16:02:48 +08:00
|
|
|
|
2018-02-19 05:02:44 +08:00
|
|
|
if ((usr1 & USR1_TRDY) || (usr2 & USR2_TXDC)) {
|
2020-01-21 15:17:02 +08:00
|
|
|
imx_uart_transmit_buffer(sport);
|
2016-03-24 21:24:21 +08:00
|
|
|
ret = IRQ_HANDLED;
|
|
|
|
}
|
2008-07-05 16:02:48 +08:00
|
|
|
|
2018-02-19 05:02:43 +08:00
|
|
|
if (usr1 & USR1_DTRD) {
|
2018-03-02 18:07:19 +08:00
|
|
|
imx_uart_writel(sport, USR1_DTRD, USR1);
|
2016-03-24 21:24:25 +08:00
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_mctrl_check(sport);
|
2016-03-24 21:24:25 +08:00
|
|
|
|
|
|
|
ret = IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
2018-02-19 05:02:43 +08:00
|
|
|
if (usr1 & USR1_RTSD) {
|
2020-01-21 15:17:02 +08:00
|
|
|
__imx_uart_rtsint(irq, dev_id);
|
2016-03-24 21:24:21 +08:00
|
|
|
ret = IRQ_HANDLED;
|
|
|
|
}
|
2008-07-05 16:02:48 +08:00
|
|
|
|
2018-02-19 05:02:43 +08:00
|
|
|
if (usr1 & USR1_AWAKE) {
|
2018-03-02 18:07:19 +08:00
|
|
|
imx_uart_writel(sport, USR1_AWAKE, USR1);
|
2016-03-24 21:24:21 +08:00
|
|
|
ret = IRQ_HANDLED;
|
|
|
|
}
|
2011-12-13 11:23:48 +08:00
|
|
|
|
2018-02-19 05:02:43 +08:00
|
|
|
if (usr2 & USR2_ORE) {
|
2013-05-14 23:06:07 +08:00
|
|
|
sport->port.icount.overrun++;
|
2018-03-02 18:07:19 +08:00
|
|
|
imx_uart_writel(sport, USR2_ORE, USR2);
|
2016-03-24 21:24:21 +08:00
|
|
|
ret = IRQ_HANDLED;
|
2013-05-14 23:06:07 +08:00
|
|
|
}
|
|
|
|
|
2020-01-21 15:17:02 +08:00
|
|
|
spin_unlock(&sport->port.lock);
|
|
|
|
|
2016-03-24 21:24:21 +08:00
|
|
|
return ret;
|
2008-07-05 16:02:48 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Return TIOCSER_TEMT when transmitter is not busy.
|
|
|
|
*/
|
2018-03-02 18:07:30 +08:00
|
|
|
static unsigned int imx_uart_tx_empty(struct uart_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct imx_port *sport = (struct imx_port *)port;
|
2013-10-11 18:30:59 +08:00
|
|
|
unsigned int ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-03-02 18:07:19 +08:00
|
|
|
ret = (imx_uart_readl(sport, USR2) & USR2_TXDC) ? TIOCSER_TEMT : 0;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-10-11 18:30:59 +08:00
|
|
|
/* If the TX DMA is working, return 0. */
|
2018-03-02 18:07:21 +08:00
|
|
|
if (sport->dma_is_txing)
|
2013-10-11 18:30:59 +08:00
|
|
|
ret = 0;
|
|
|
|
|
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2018-02-28 05:44:56 +08:00
|
|
|
/* called with port.lock taken and irqs off */
|
2018-03-02 18:07:30 +08:00
|
|
|
static unsigned int imx_uart_get_mctrl(struct uart_port *port)
|
2015-12-13 18:30:03 +08:00
|
|
|
{
|
|
|
|
struct imx_port *sport = (struct imx_port *)port;
|
2018-03-02 18:07:30 +08:00
|
|
|
unsigned int ret = imx_uart_get_hwmctrl(sport);
|
2015-12-13 18:30:03 +08:00
|
|
|
|
|
|
|
mctrl_gpio_get(sport->gpios, &ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-02-28 05:44:56 +08:00
|
|
|
/* called with port.lock taken and irqs off */
|
2018-03-02 18:07:30 +08:00
|
|
|
static void imx_uart_set_mctrl(struct uart_port *port, unsigned int mctrl)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2009-06-11 21:35:01 +08:00
|
|
|
struct imx_port *sport = (struct imx_port *)port;
|
2018-03-02 18:07:23 +08:00
|
|
|
u32 ucr3, uts;
|
2007-04-26 15:26:13 +08:00
|
|
|
|
2015-02-24 18:17:11 +08:00
|
|
|
if (!(port->rs485.flags & SER_RS485_ENABLED)) {
|
2018-03-02 18:07:23 +08:00
|
|
|
u32 ucr2;
|
|
|
|
|
2019-07-27 02:52:40 +08:00
|
|
|
/*
|
|
|
|
* Turn off autoRTS if RTS is lowered and restore autoRTS
|
|
|
|
* setting if RTS is raised.
|
|
|
|
*/
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr2 = imx_uart_readl(sport, UCR2);
|
|
|
|
ucr2 &= ~(UCR2_CTS | UCR2_CTSC);
|
2019-07-27 02:52:40 +08:00
|
|
|
if (mctrl & TIOCM_RTS) {
|
|
|
|
ucr2 |= UCR2_CTS;
|
|
|
|
/*
|
|
|
|
* UCR2_IRTS is unset if and only if the port is
|
|
|
|
* configured for CRTSCTS, so we use inverted UCR2_IRTS
|
|
|
|
* to get the state to restore to.
|
|
|
|
*/
|
|
|
|
if (!(ucr2 & UCR2_IRTS))
|
|
|
|
ucr2 |= UCR2_CTSC;
|
|
|
|
}
|
2018-03-02 18:07:23 +08:00
|
|
|
imx_uart_writel(sport, ucr2, UCR2);
|
2015-02-24 18:17:11 +08:00
|
|
|
}
|
2013-11-29 17:29:24 +08:00
|
|
|
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr3 = imx_uart_readl(sport, UCR3) & ~UCR3_DSR;
|
2015-10-19 03:34:46 +08:00
|
|
|
if (!(mctrl & TIOCM_DTR))
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr3 |= UCR3_DSR;
|
|
|
|
imx_uart_writel(sport, ucr3, UCR3);
|
2015-10-19 03:34:46 +08:00
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
uts = imx_uart_readl(sport, imx_uart_uts_reg(sport)) & ~UTS_LOOP;
|
2013-11-29 17:29:24 +08:00
|
|
|
if (mctrl & TIOCM_LOOP)
|
2018-03-02 18:07:23 +08:00
|
|
|
uts |= UTS_LOOP;
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_writel(sport, uts, imx_uart_uts_reg(sport));
|
2015-12-13 18:30:03 +08:00
|
|
|
|
|
|
|
mctrl_gpio_set(sport->gpios, mctrl);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Interrupts always disabled.
|
|
|
|
*/
|
2018-03-02 18:07:30 +08:00
|
|
|
static void imx_uart_break_ctl(struct uart_port *port, int break_state)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct imx_port *sport = (struct imx_port *)port;
|
2018-03-02 18:07:23 +08:00
|
|
|
unsigned long flags;
|
|
|
|
u32 ucr1;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
spin_lock_irqsave(&sport->port.lock, flags);
|
|
|
|
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr1 = imx_uart_readl(sport, UCR1) & ~UCR1_SNDBRK;
|
2007-04-26 15:26:13 +08:00
|
|
|
|
2013-01-07 12:55:02 +08:00
|
|
|
if (break_state != 0)
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr1 |= UCR1_SNDBRK;
|
2007-04-26 15:26:13 +08:00
|
|
|
|
2018-03-02 18:07:23 +08:00
|
|
|
imx_uart_writel(sport, ucr1, UCR1);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
spin_unlock_irqrestore(&sport->port.lock, flags);
|
|
|
|
}
|
|
|
|
|
2015-10-19 03:34:47 +08:00
|
|
|
/*
|
|
|
|
* This is our per-port timeout handler, for checking the
|
|
|
|
* modem status signals.
|
|
|
|
*/
|
2018-03-02 18:07:30 +08:00
|
|
|
static void imx_uart_timeout(struct timer_list *t)
|
2015-10-19 03:34:47 +08: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-17 05:43:17 +08:00
|
|
|
struct imx_port *sport = from_timer(sport, t, timer);
|
2015-10-19 03:34:47 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (sport->port.state) {
|
|
|
|
spin_lock_irqsave(&sport->port.lock, flags);
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_mctrl_check(sport);
|
2015-10-19 03:34:47 +08:00
|
|
|
spin_unlock_irqrestore(&sport->port.lock, flags);
|
|
|
|
|
|
|
|
mod_timer(&sport->timer, jiffies + MCTRL_TIMEOUT);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-08 17:14:18 +08:00
|
|
|
/*
|
2015-09-04 23:52:41 +08:00
|
|
|
* There are two kinds of RX DMA interrupts(such as in the MX6Q):
|
2013-07-08 17:14:18 +08:00
|
|
|
* [1] the RX DMA buffer is full.
|
2015-09-04 23:52:41 +08:00
|
|
|
* [2] the aging timer expires
|
2013-07-08 17:14:18 +08:00
|
|
|
*
|
2015-09-04 23:52:41 +08:00
|
|
|
* Condition [2] is triggered when a character has been sitting in the FIFO
|
|
|
|
* for at least 8 byte durations.
|
2013-07-08 17:14:18 +08:00
|
|
|
*/
|
2018-03-02 18:07:30 +08:00
|
|
|
static void imx_uart_dma_rx_callback(void *data)
|
2013-07-08 17:14:18 +08:00
|
|
|
{
|
|
|
|
struct imx_port *sport = data;
|
|
|
|
struct dma_chan *chan = sport->dma_chan_rx;
|
|
|
|
struct scatterlist *sgl = &sport->rx_sgl;
|
2013-10-15 15:23:40 +08:00
|
|
|
struct tty_port *port = &sport->port.state->port;
|
2013-07-08 17:14:18 +08:00
|
|
|
struct dma_tx_state state;
|
2016-08-08 20:38:27 +08:00
|
|
|
struct circ_buf *rx_ring = &sport->rx_ring;
|
2013-07-08 17:14:18 +08:00
|
|
|
enum dma_status status;
|
2016-08-08 20:38:27 +08:00
|
|
|
unsigned int w_bytes = 0;
|
|
|
|
unsigned int r_bytes;
|
|
|
|
unsigned int bd_size;
|
2013-07-08 17:14:18 +08:00
|
|
|
|
2018-06-20 00:56:58 +08:00
|
|
|
status = dmaengine_tx_status(chan, sport->rx_cookie, &state);
|
2015-05-19 16:54:09 +08:00
|
|
|
|
2016-08-08 20:38:27 +08:00
|
|
|
if (status == DMA_ERROR) {
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_clear_rx_errors(sport);
|
2016-08-08 20:38:27 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(sport->port.ignore_status_mask & URXD_DUMMY_READ)) {
|
2013-07-08 17:14:18 +08:00
|
|
|
|
2016-08-08 20:38:27 +08:00
|
|
|
/*
|
|
|
|
* The state-residue variable represents the empty space
|
|
|
|
* relative to the entire buffer. Taking this in consideration
|
|
|
|
* the head is always calculated base on the buffer total
|
|
|
|
* length - DMA transaction residue. The UART script from the
|
|
|
|
* SDMA firmware will jump to the next buffer descriptor,
|
|
|
|
* once a DMA transaction if finalized (IMX53 RM - A.4.1.2.4).
|
|
|
|
* Taking this in consideration the tail is always at the
|
|
|
|
* beginning of the buffer descriptor that contains the head.
|
|
|
|
*/
|
2015-06-21 01:25:35 +08:00
|
|
|
|
2016-08-08 20:38:27 +08:00
|
|
|
/* Calculate the head */
|
|
|
|
rx_ring->head = sg_dma_len(sgl) - state.residue;
|
|
|
|
|
|
|
|
/* Calculate the tail. */
|
|
|
|
bd_size = sg_dma_len(sgl) / sport->rx_periods;
|
|
|
|
rx_ring->tail = ((rx_ring->head-1) / bd_size) * bd_size;
|
|
|
|
|
|
|
|
if (rx_ring->head <= sg_dma_len(sgl) &&
|
|
|
|
rx_ring->head > rx_ring->tail) {
|
|
|
|
|
|
|
|
/* Move data from tail to head */
|
|
|
|
r_bytes = rx_ring->head - rx_ring->tail;
|
|
|
|
|
|
|
|
/* CPU claims ownership of RX DMA buffer */
|
|
|
|
dma_sync_sg_for_cpu(sport->port.dev, sgl, 1,
|
|
|
|
DMA_FROM_DEVICE);
|
|
|
|
|
|
|
|
w_bytes = tty_insert_flip_string(port,
|
|
|
|
sport->rx_buf + rx_ring->tail, r_bytes);
|
|
|
|
|
|
|
|
/* UART retrieves ownership of RX DMA buffer */
|
|
|
|
dma_sync_sg_for_device(sport->port.dev, sgl, 1,
|
|
|
|
DMA_FROM_DEVICE);
|
|
|
|
|
|
|
|
if (w_bytes != r_bytes)
|
2015-06-21 01:25:35 +08:00
|
|
|
sport->port.icount.buf_overrun++;
|
2016-08-08 20:38:27 +08:00
|
|
|
|
|
|
|
sport->port.icount.rx += w_bytes;
|
|
|
|
} else {
|
|
|
|
WARN_ON(rx_ring->head > sg_dma_len(sgl));
|
|
|
|
WARN_ON(rx_ring->head <= rx_ring->tail);
|
2015-06-21 01:25:35 +08:00
|
|
|
}
|
2015-09-04 23:52:39 +08:00
|
|
|
}
|
2013-10-15 15:23:40 +08:00
|
|
|
|
2016-08-08 20:38:27 +08:00
|
|
|
if (w_bytes) {
|
|
|
|
tty_flip_buffer_push(port);
|
|
|
|
dev_dbg(sport->port.dev, "We get %d bytes.\n", w_bytes);
|
|
|
|
}
|
2013-07-08 17:14:18 +08:00
|
|
|
}
|
|
|
|
|
2017-07-17 19:48:58 +08:00
|
|
|
/* RX DMA buffer periods */
|
2019-09-23 21:59:16 +08:00
|
|
|
#define RX_DMA_PERIODS 16
|
|
|
|
#define RX_BUF_SIZE (RX_DMA_PERIODS * PAGE_SIZE / 4)
|
2017-07-17 19:48:58 +08:00
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static int imx_uart_start_rx_dma(struct imx_port *sport)
|
2013-07-08 17:14:18 +08:00
|
|
|
{
|
|
|
|
struct scatterlist *sgl = &sport->rx_sgl;
|
|
|
|
struct dma_chan *chan = sport->dma_chan_rx;
|
|
|
|
struct device *dev = sport->port.dev;
|
|
|
|
struct dma_async_tx_descriptor *desc;
|
|
|
|
int ret;
|
|
|
|
|
2016-08-08 20:38:27 +08:00
|
|
|
sport->rx_ring.head = 0;
|
|
|
|
sport->rx_ring.tail = 0;
|
2017-07-17 19:48:58 +08:00
|
|
|
sport->rx_periods = RX_DMA_PERIODS;
|
2016-08-08 20:38:27 +08:00
|
|
|
|
2017-07-17 19:48:58 +08:00
|
|
|
sg_init_one(sgl, sport->rx_buf, RX_BUF_SIZE);
|
2013-07-08 17:14:18 +08:00
|
|
|
ret = dma_map_sg(dev, sgl, 1, DMA_FROM_DEVICE);
|
|
|
|
if (ret == 0) {
|
|
|
|
dev_err(dev, "DMA mapping error for RX.\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2016-08-08 20:38:27 +08:00
|
|
|
|
|
|
|
desc = dmaengine_prep_dma_cyclic(chan, sg_dma_address(sgl),
|
|
|
|
sg_dma_len(sgl), sg_dma_len(sgl) / sport->rx_periods,
|
|
|
|
DMA_DEV_TO_MEM, DMA_PREP_INTERRUPT);
|
|
|
|
|
2013-07-08 17:14:18 +08:00
|
|
|
if (!desc) {
|
2014-12-09 17:11:26 +08:00
|
|
|
dma_unmap_sg(dev, sgl, 1, DMA_FROM_DEVICE);
|
2013-07-08 17:14:18 +08:00
|
|
|
dev_err(dev, "We cannot prepare for the RX slave dma!\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2018-03-02 18:07:30 +08:00
|
|
|
desc->callback = imx_uart_dma_rx_callback;
|
2013-07-08 17:14:18 +08:00
|
|
|
desc->callback_param = sport;
|
|
|
|
|
|
|
|
dev_dbg(dev, "RX: prepare for the DMA.\n");
|
2017-09-28 18:03:49 +08:00
|
|
|
sport->dma_is_rxing = 1;
|
2016-08-08 20:38:27 +08:00
|
|
|
sport->rx_cookie = dmaengine_submit(desc);
|
2013-07-08 17:14:18 +08:00
|
|
|
dma_async_issue_pending(chan);
|
|
|
|
return 0;
|
|
|
|
}
|
2016-08-08 20:38:28 +08:00
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static void imx_uart_clear_rx_errors(struct imx_port *sport)
|
2016-08-08 20:38:28 +08:00
|
|
|
{
|
2018-02-24 10:27:50 +08:00
|
|
|
struct tty_port *port = &sport->port.state->port;
|
2018-03-02 18:07:23 +08:00
|
|
|
u32 usr1, usr2;
|
2016-08-08 20:38:28 +08:00
|
|
|
|
2018-03-02 18:07:23 +08:00
|
|
|
usr1 = imx_uart_readl(sport, USR1);
|
|
|
|
usr2 = imx_uart_readl(sport, USR2);
|
2016-08-08 20:38:28 +08:00
|
|
|
|
2018-03-02 18:07:23 +08:00
|
|
|
if (usr2 & USR2_BRCD) {
|
2016-08-08 20:38:28 +08:00
|
|
|
sport->port.icount.brk++;
|
2018-03-02 18:07:19 +08:00
|
|
|
imx_uart_writel(sport, USR2_BRCD, USR2);
|
2018-02-24 10:27:50 +08:00
|
|
|
uart_handle_break(&sport->port);
|
|
|
|
if (tty_insert_flip_char(port, 0, TTY_BREAK) == 0)
|
|
|
|
sport->port.icount.buf_overrun++;
|
|
|
|
tty_flip_buffer_push(port);
|
|
|
|
} else {
|
2018-03-02 18:07:23 +08:00
|
|
|
if (usr1 & USR1_FRAMERR) {
|
2018-02-24 10:27:50 +08:00
|
|
|
sport->port.icount.frame++;
|
2018-03-02 18:07:19 +08:00
|
|
|
imx_uart_writel(sport, USR1_FRAMERR, USR1);
|
2018-03-02 18:07:23 +08:00
|
|
|
} else if (usr1 & USR1_PARITYERR) {
|
2018-02-24 10:27:50 +08:00
|
|
|
sport->port.icount.parity++;
|
2018-03-02 18:07:19 +08:00
|
|
|
imx_uart_writel(sport, USR1_PARITYERR, USR1);
|
2018-02-24 10:27:50 +08:00
|
|
|
}
|
2016-08-08 20:38:28 +08:00
|
|
|
}
|
|
|
|
|
2018-03-02 18:07:23 +08:00
|
|
|
if (usr2 & USR2_ORE) {
|
2016-08-08 20:38:28 +08:00
|
|
|
sport->port.icount.overrun++;
|
2018-03-02 18:07:19 +08:00
|
|
|
imx_uart_writel(sport, USR2_ORE, USR2);
|
2016-08-08 20:38:28 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2013-07-08 17:14:18 +08:00
|
|
|
|
2015-09-04 23:52:37 +08:00
|
|
|
#define TXTL_DEFAULT 2 /* reset default */
|
|
|
|
#define RXTL_DEFAULT 1 /* reset default */
|
2015-09-04 23:52:40 +08:00
|
|
|
#define TXTL_DMA 8 /* DMA burst setting */
|
|
|
|
#define RXTL_DMA 9 /* DMA burst setting */
|
2015-09-04 23:52:37 +08:00
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static void imx_uart_setup_ufcr(struct imx_port *sport,
|
|
|
|
unsigned char txwl, unsigned char rxwl)
|
2015-09-04 23:52:37 +08:00
|
|
|
{
|
|
|
|
unsigned int val;
|
|
|
|
|
|
|
|
/* set receiver / transmitter trigger level */
|
2018-03-02 18:07:19 +08:00
|
|
|
val = imx_uart_readl(sport, UFCR) & (UFCR_RFDIV | UFCR_DCEDTE);
|
2015-09-04 23:52:37 +08:00
|
|
|
val |= txwl << UFCR_TXTL_SHF | rxwl;
|
2018-03-02 18:07:19 +08:00
|
|
|
imx_uart_writel(sport, val, UFCR);
|
2015-09-04 23:52:37 +08:00
|
|
|
}
|
|
|
|
|
2013-07-08 17:14:18 +08:00
|
|
|
static void imx_uart_dma_exit(struct imx_port *sport)
|
|
|
|
{
|
|
|
|
if (sport->dma_chan_rx) {
|
2016-09-13 16:17:05 +08:00
|
|
|
dmaengine_terminate_sync(sport->dma_chan_rx);
|
2013-07-08 17:14:18 +08:00
|
|
|
dma_release_channel(sport->dma_chan_rx);
|
|
|
|
sport->dma_chan_rx = NULL;
|
2016-08-08 20:38:27 +08:00
|
|
|
sport->rx_cookie = -EINVAL;
|
2013-07-08 17:14:18 +08:00
|
|
|
kfree(sport->rx_buf);
|
|
|
|
sport->rx_buf = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sport->dma_chan_tx) {
|
2016-09-13 16:17:05 +08:00
|
|
|
dmaengine_terminate_sync(sport->dma_chan_tx);
|
2013-07-08 17:14:18 +08:00
|
|
|
dma_release_channel(sport->dma_chan_tx);
|
|
|
|
sport->dma_chan_tx = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int imx_uart_dma_init(struct imx_port *sport)
|
|
|
|
{
|
2013-08-29 16:29:25 +08:00
|
|
|
struct dma_slave_config slave_config = {};
|
2013-07-08 17:14:18 +08:00
|
|
|
struct device *dev = sport->port.dev;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
/* Prepare for RX : */
|
|
|
|
sport->dma_chan_rx = dma_request_slave_channel(dev, "rx");
|
|
|
|
if (!sport->dma_chan_rx) {
|
|
|
|
dev_dbg(dev, "cannot get the DMA channel.\n");
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
slave_config.direction = DMA_DEV_TO_MEM;
|
|
|
|
slave_config.src_addr = sport->port.mapbase + URXD0;
|
|
|
|
slave_config.src_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
|
2015-09-04 23:52:40 +08:00
|
|
|
/* one byte less than the watermark level to enable the aging timer */
|
|
|
|
slave_config.src_maxburst = RXTL_DMA - 1;
|
2013-07-08 17:14:18 +08:00
|
|
|
ret = dmaengine_slave_config(sport->dma_chan_rx, &slave_config);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "error in RX dma configuration.\n");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
2017-09-28 18:07:40 +08:00
|
|
|
sport->rx_buf = kzalloc(RX_BUF_SIZE, GFP_KERNEL);
|
2013-07-08 17:14:18 +08:00
|
|
|
if (!sport->rx_buf) {
|
|
|
|
ret = -ENOMEM;
|
|
|
|
goto err;
|
|
|
|
}
|
2016-08-08 20:38:27 +08:00
|
|
|
sport->rx_ring.buf = sport->rx_buf;
|
2013-07-08 17:14:18 +08:00
|
|
|
|
|
|
|
/* Prepare for TX : */
|
|
|
|
sport->dma_chan_tx = dma_request_slave_channel(dev, "tx");
|
|
|
|
if (!sport->dma_chan_tx) {
|
|
|
|
dev_err(dev, "cannot get the TX DMA channel!\n");
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
slave_config.direction = DMA_MEM_TO_DEV;
|
|
|
|
slave_config.dst_addr = sport->port.mapbase + URTX0;
|
|
|
|
slave_config.dst_addr_width = DMA_SLAVE_BUSWIDTH_1_BYTE;
|
2015-09-04 23:52:40 +08:00
|
|
|
slave_config.dst_maxburst = TXTL_DMA;
|
2013-07-08 17:14:18 +08:00
|
|
|
ret = dmaengine_slave_config(sport->dma_chan_tx, &slave_config);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(dev, "error in TX dma configuration.");
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
err:
|
|
|
|
imx_uart_dma_exit(sport);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static void imx_uart_enable_dma(struct imx_port *sport)
|
2013-07-08 17:14:18 +08:00
|
|
|
{
|
2018-03-02 18:07:23 +08:00
|
|
|
u32 ucr1;
|
2013-07-08 17:14:18 +08:00
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_setup_ufcr(sport, TXTL_DMA, RXTL_DMA);
|
2018-03-02 18:07:24 +08:00
|
|
|
|
2013-07-08 17:14:18 +08:00
|
|
|
/* set UCR1 */
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr1 = imx_uart_readl(sport, UCR1);
|
|
|
|
ucr1 |= UCR1_RXDMAEN | UCR1_TXDMAEN | UCR1_ATDMAEN;
|
|
|
|
imx_uart_writel(sport, ucr1, UCR1);
|
2013-07-08 17:14:18 +08:00
|
|
|
|
|
|
|
sport->dma_is_enabled = 1;
|
|
|
|
}
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static void imx_uart_disable_dma(struct imx_port *sport)
|
2013-07-08 17:14:18 +08:00
|
|
|
{
|
2018-05-08 05:36:09 +08:00
|
|
|
u32 ucr1;
|
2013-07-08 17:14:18 +08:00
|
|
|
|
|
|
|
/* clear UCR1 */
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr1 = imx_uart_readl(sport, UCR1);
|
|
|
|
ucr1 &= ~(UCR1_RXDMAEN | UCR1_TXDMAEN | UCR1_ATDMAEN);
|
|
|
|
imx_uart_writel(sport, ucr1, UCR1);
|
2013-07-08 17:14:18 +08:00
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_setup_ufcr(sport, TXTL_DEFAULT, RXTL_DEFAULT);
|
2015-09-04 23:52:40 +08:00
|
|
|
|
2013-07-08 17:14:18 +08:00
|
|
|
sport->dma_is_enabled = 0;
|
|
|
|
}
|
|
|
|
|
2010-05-05 17:47:07 +08:00
|
|
|
/* half the RX buffer size */
|
|
|
|
#define CTSTL 16
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static int imx_uart_startup(struct uart_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct imx_port *sport = (struct imx_port *)port;
|
2015-07-28 02:15:59 +08:00
|
|
|
int retval, i;
|
2018-03-02 18:07:23 +08:00
|
|
|
unsigned long flags;
|
2018-02-19 05:02:45 +08:00
|
|
|
int dma_is_inited = 0;
|
2020-02-27 06:23:19 +08:00
|
|
|
u32 ucr1, ucr2, ucr3, ucr4;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-06-28 13:39:42 +08:00
|
|
|
retval = clk_prepare_enable(sport->clk_per);
|
|
|
|
if (retval)
|
2014-10-28 00:49:38 +08:00
|
|
|
return retval;
|
2013-06-28 13:39:42 +08:00
|
|
|
retval = clk_prepare_enable(sport->clk_ipg);
|
|
|
|
if (retval) {
|
|
|
|
clk_disable_unprepare(sport->clk_per);
|
2014-10-28 00:49:38 +08:00
|
|
|
return retval;
|
2013-06-09 10:01:19 +08:00
|
|
|
}
|
2013-06-04 09:59:33 +08:00
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_setup_ufcr(sport, TXTL_DEFAULT, RXTL_DEFAULT);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/* disable the DREN bit (Data Ready interrupt enable) before
|
|
|
|
* requesting IRQs
|
|
|
|
*/
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr4 = imx_uart_readl(sport, UCR4);
|
2009-06-11 21:53:18 +08:00
|
|
|
|
2010-05-05 17:47:07 +08:00
|
|
|
/* set the trigger level for CTS */
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr4 &= ~(UCR4_CTSTL_MASK << UCR4_CTSTL_SHF);
|
|
|
|
ucr4 |= CTSTL << UCR4_CTSTL_SHF;
|
2010-05-05 17:47:07 +08:00
|
|
|
|
2018-03-02 18:07:23 +08:00
|
|
|
imx_uart_writel(sport, ucr4 & ~UCR4_DREN, UCR4);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2015-09-04 23:52:42 +08:00
|
|
|
/* Can we enable the DMA support? */
|
2018-02-19 05:02:45 +08:00
|
|
|
if (!uart_console(port) && imx_uart_dma_init(sport) == 0)
|
|
|
|
dma_is_inited = 1;
|
2015-09-04 23:52:42 +08:00
|
|
|
|
2015-04-13 17:31:43 +08:00
|
|
|
spin_lock_irqsave(&sport->port.lock, flags);
|
2014-05-21 08:56:28 +08:00
|
|
|
/* Reset fifo's and state machines */
|
2015-07-28 02:15:59 +08:00
|
|
|
i = 100;
|
|
|
|
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr2 = imx_uart_readl(sport, UCR2);
|
|
|
|
ucr2 &= ~UCR2_SRST;
|
|
|
|
imx_uart_writel(sport, ucr2, UCR2);
|
2015-07-28 02:15:59 +08:00
|
|
|
|
2018-03-02 18:07:19 +08:00
|
|
|
while (!(imx_uart_readl(sport, UCR2) & UCR2_SRST) && (--i > 0))
|
2015-07-28 02:15:59 +08:00
|
|
|
udelay(1);
|
2009-06-11 21:53:18 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Finally, clear and enable interrupts
|
|
|
|
*/
|
2018-03-02 18:07:19 +08:00
|
|
|
imx_uart_writel(sport, USR1_RTSD | USR1_DTRD, USR1);
|
|
|
|
imx_uart_writel(sport, USR2_ORE, USR2);
|
2007-04-26 15:26:13 +08:00
|
|
|
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr1 = imx_uart_readl(sport, UCR1) & ~UCR1_RRDYEN;
|
|
|
|
ucr1 |= UCR1_UARTEN;
|
2017-06-28 21:59:36 +08:00
|
|
|
if (sport->have_rtscts)
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr1 |= UCR1_RTSDEN;
|
2009-06-11 21:53:18 +08:00
|
|
|
|
2018-03-02 18:07:23 +08:00
|
|
|
imx_uart_writel(sport, ucr1, UCR1);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2020-02-27 06:23:19 +08:00
|
|
|
ucr4 = imx_uart_readl(sport, UCR4) & ~(UCR4_OREN | UCR4_INVR);
|
2017-11-17 02:14:53 +08:00
|
|
|
if (!sport->dma_is_enabled)
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr4 |= UCR4_OREN;
|
2020-02-27 06:23:19 +08:00
|
|
|
if (sport->inverted_rx)
|
|
|
|
ucr4 |= UCR4_INVR;
|
2018-03-02 18:07:23 +08:00
|
|
|
imx_uart_writel(sport, ucr4, UCR4);
|
2014-12-09 17:11:34 +08:00
|
|
|
|
2020-02-27 06:23:19 +08:00
|
|
|
ucr3 = imx_uart_readl(sport, UCR3) & ~UCR3_INVT;
|
|
|
|
/*
|
|
|
|
* configure tx polarity before enabling tx
|
|
|
|
*/
|
|
|
|
if (sport->inverted_tx)
|
|
|
|
ucr3 |= UCR3_INVT;
|
|
|
|
|
|
|
|
if (!imx_uart_is_imx1(sport)) {
|
|
|
|
ucr3 |= UCR3_DTRDEN | UCR3_RI | UCR3_DCD;
|
|
|
|
|
|
|
|
if (sport->dte_mode)
|
|
|
|
/* disable broken interrupts */
|
|
|
|
ucr3 &= ~(UCR3_RI | UCR3_DCD);
|
|
|
|
}
|
|
|
|
imx_uart_writel(sport, ucr3, UCR3);
|
|
|
|
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr2 = imx_uart_readl(sport, UCR2) & ~UCR2_ATEN;
|
|
|
|
ucr2 |= (UCR2_RXEN | UCR2_TXEN);
|
2013-05-30 21:47:04 +08:00
|
|
|
if (!sport->have_rtscts)
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr2 |= UCR2_IRTS;
|
2016-03-24 21:24:22 +08:00
|
|
|
/*
|
|
|
|
* make sure the edge sensitive RTS-irq is disabled,
|
|
|
|
* we're using RTSD instead.
|
|
|
|
*/
|
2018-03-02 18:07:30 +08:00
|
|
|
if (!imx_uart_is_imx1(sport))
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr2 &= ~UCR2_RTSEN;
|
|
|
|
imx_uart_writel(sport, ucr2, UCR2);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable modem status interrupts
|
|
|
|
*/
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_enable_ms(&sport->port);
|
2017-04-07 17:45:24 +08:00
|
|
|
|
2018-03-02 18:07:26 +08:00
|
|
|
if (dma_is_inited) {
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_enable_dma(sport);
|
|
|
|
imx_uart_start_rx_dma(sport);
|
2018-03-02 18:07:26 +08:00
|
|
|
} else {
|
|
|
|
ucr1 = imx_uart_readl(sport, UCR1);
|
|
|
|
ucr1 |= UCR1_RRDYEN;
|
|
|
|
imx_uart_writel(sport, ucr1, UCR1);
|
2018-03-02 18:07:27 +08:00
|
|
|
|
|
|
|
ucr2 = imx_uart_readl(sport, UCR2);
|
|
|
|
ucr2 |= UCR2_ATEN;
|
|
|
|
imx_uart_writel(sport, ucr2, UCR2);
|
2018-03-02 18:07:26 +08:00
|
|
|
}
|
2017-04-07 17:45:24 +08:00
|
|
|
|
2013-01-07 12:55:02 +08:00
|
|
|
spin_unlock_irqrestore(&sport->port.lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static void imx_uart_shutdown(struct uart_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct imx_port *sport = (struct imx_port *)port;
|
2012-08-27 15:36:51 +08:00
|
|
|
unsigned long flags;
|
2018-05-25 01:30:24 +08:00
|
|
|
u32 ucr1, ucr2, ucr4;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-07-08 17:14:18 +08:00
|
|
|
if (sport->dma_is_enabled) {
|
2016-09-13 16:17:05 +08:00
|
|
|
dmaengine_terminate_sync(sport->dma_chan_tx);
|
2018-05-08 05:36:10 +08:00
|
|
|
if (sport->dma_is_txing) {
|
|
|
|
dma_unmap_sg(sport->port.dev, &sport->tx_sgl[0],
|
|
|
|
sport->dma_tx_nents, DMA_TO_DEVICE);
|
|
|
|
sport->dma_is_txing = 0;
|
|
|
|
}
|
2016-09-13 16:17:05 +08:00
|
|
|
dmaengine_terminate_sync(sport->dma_chan_rx);
|
2018-05-08 05:36:10 +08:00
|
|
|
if (sport->dma_is_rxing) {
|
|
|
|
dma_unmap_sg(sport->port.dev, &sport->rx_sgl,
|
|
|
|
1, DMA_FROM_DEVICE);
|
|
|
|
sport->dma_is_rxing = 0;
|
|
|
|
}
|
2014-09-19 15:42:57 +08:00
|
|
|
|
2014-12-09 17:11:23 +08:00
|
|
|
spin_lock_irqsave(&sport->port.lock, flags);
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_stop_tx(port);
|
|
|
|
imx_uart_stop_rx(port);
|
|
|
|
imx_uart_disable_dma(sport);
|
2014-12-09 17:11:23 +08:00
|
|
|
spin_unlock_irqrestore(&sport->port.lock, flags);
|
2013-07-08 17:14:18 +08:00
|
|
|
imx_uart_dma_exit(sport);
|
|
|
|
}
|
|
|
|
|
2015-12-13 18:30:03 +08:00
|
|
|
mctrl_gpio_disable_ms(sport->gpios);
|
|
|
|
|
2012-08-27 15:36:51 +08:00
|
|
|
spin_lock_irqsave(&sport->port.lock, flags);
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr2 = imx_uart_readl(sport, UCR2);
|
2018-05-25 01:30:23 +08:00
|
|
|
ucr2 &= ~(UCR2_TXEN | UCR2_ATEN);
|
2018-03-02 18:07:23 +08:00
|
|
|
imx_uart_writel(sport, ucr2, UCR2);
|
2018-05-25 01:30:24 +08:00
|
|
|
|
|
|
|
ucr4 = imx_uart_readl(sport, UCR4);
|
|
|
|
ucr4 &= ~UCR4_OREN;
|
|
|
|
imx_uart_writel(sport, ucr4, UCR4);
|
2012-08-27 15:36:51 +08:00
|
|
|
spin_unlock_irqrestore(&sport->port.lock, flags);
|
2009-06-11 21:38:38 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Stop our timer.
|
|
|
|
*/
|
|
|
|
del_timer_sync(&sport->timer);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Disable all interrupts, port and break condition.
|
|
|
|
*/
|
|
|
|
|
2012-08-27 15:36:51 +08:00
|
|
|
spin_lock_irqsave(&sport->port.lock, flags);
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr1 = imx_uart_readl(sport, UCR1);
|
2019-08-29 02:37:55 +08:00
|
|
|
ucr1 &= ~(UCR1_TRDYEN | UCR1_RRDYEN | UCR1_RTSDEN | UCR1_UARTEN | UCR1_RXDMAEN | UCR1_ATDMAEN);
|
2009-06-11 21:53:18 +08:00
|
|
|
|
2018-03-02 18:07:23 +08:00
|
|
|
imx_uart_writel(sport, ucr1, UCR1);
|
2012-08-27 15:36:51 +08:00
|
|
|
spin_unlock_irqrestore(&sport->port.lock, flags);
|
2013-06-04 09:59:33 +08:00
|
|
|
|
2013-06-28 13:39:42 +08:00
|
|
|
clk_disable_unprepare(sport->clk_per);
|
|
|
|
clk_disable_unprepare(sport->clk_ipg);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2018-02-28 05:44:56 +08:00
|
|
|
/* called with port.lock taken and irqs off */
|
2018-03-02 18:07:30 +08:00
|
|
|
static void imx_uart_flush_buffer(struct uart_port *port)
|
2013-10-11 18:30:58 +08:00
|
|
|
{
|
|
|
|
struct imx_port *sport = (struct imx_port *)port;
|
2014-12-09 17:11:27 +08:00
|
|
|
struct scatterlist *sgl = &sport->tx_sgl[0];
|
2018-03-02 18:07:23 +08:00
|
|
|
u32 ucr2;
|
2015-02-08 01:46:41 +08:00
|
|
|
int i = 100, ubir, ubmr, uts;
|
2013-10-11 18:30:58 +08:00
|
|
|
|
2014-12-09 17:11:27 +08:00
|
|
|
if (!sport->dma_chan_tx)
|
|
|
|
return;
|
|
|
|
|
|
|
|
sport->tx_bytes = 0;
|
|
|
|
dmaengine_terminate_all(sport->dma_chan_tx);
|
|
|
|
if (sport->dma_is_txing) {
|
2018-03-02 18:07:23 +08:00
|
|
|
u32 ucr1;
|
|
|
|
|
2014-12-09 17:11:27 +08:00
|
|
|
dma_unmap_sg(sport->port.dev, sgl, sport->dma_tx_nents,
|
|
|
|
DMA_TO_DEVICE);
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr1 = imx_uart_readl(sport, UCR1);
|
|
|
|
ucr1 &= ~UCR1_TXDMAEN;
|
|
|
|
imx_uart_writel(sport, ucr1, UCR1);
|
2017-09-28 18:38:51 +08:00
|
|
|
sport->dma_is_txing = 0;
|
2013-10-11 18:30:58 +08:00
|
|
|
}
|
2015-01-13 20:00:26 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* According to the Reference Manual description of the UART SRST bit:
|
2017-10-05 00:13:27 +08:00
|
|
|
*
|
2015-01-13 20:00:26 +08:00
|
|
|
* "Reset the transmit and receive state machines,
|
|
|
|
* all FIFOs and register USR1, USR2, UBIR, UBMR, UBRC, URXD, UTXD
|
2017-10-05 00:13:27 +08:00
|
|
|
* and UTS[6-3]".
|
|
|
|
*
|
|
|
|
* We don't need to restore the old values from USR1, USR2, URXD and
|
|
|
|
* UTXD. UBRC is read only, so only save/restore the other three
|
|
|
|
* registers.
|
2015-01-13 20:00:26 +08:00
|
|
|
*/
|
2018-03-02 18:07:19 +08:00
|
|
|
ubir = imx_uart_readl(sport, UBIR);
|
|
|
|
ubmr = imx_uart_readl(sport, UBMR);
|
|
|
|
uts = imx_uart_readl(sport, IMX21_UTS);
|
2015-01-13 20:00:26 +08:00
|
|
|
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr2 = imx_uart_readl(sport, UCR2);
|
|
|
|
ucr2 &= ~UCR2_SRST;
|
|
|
|
imx_uart_writel(sport, ucr2, UCR2);
|
2015-01-13 20:00:26 +08:00
|
|
|
|
2018-03-02 18:07:19 +08:00
|
|
|
while (!(imx_uart_readl(sport, UCR2) & UCR2_SRST) && (--i > 0))
|
2015-01-13 20:00:26 +08:00
|
|
|
udelay(1);
|
|
|
|
|
|
|
|
/* Restore the registers */
|
2018-03-02 18:07:19 +08:00
|
|
|
imx_uart_writel(sport, ubir, UBIR);
|
|
|
|
imx_uart_writel(sport, ubmr, UBMR);
|
|
|
|
imx_uart_writel(sport, uts, IMX21_UTS);
|
2013-10-11 18:30:58 +08:00
|
|
|
}
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
static void
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_set_termios(struct uart_port *port, struct ktermios *termios,
|
|
|
|
struct ktermios *old)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct imx_port *sport = (struct imx_port *)port;
|
|
|
|
unsigned long flags;
|
2019-08-29 02:37:53 +08:00
|
|
|
u32 ucr2, old_ucr2, ufcr;
|
2015-12-13 18:30:03 +08:00
|
|
|
unsigned int baud, quot;
|
2005-04-17 06:20:36 +08:00
|
|
|
unsigned int old_csize = old ? old->c_cflag & CSIZE : CS8;
|
2018-03-02 18:07:23 +08:00
|
|
|
unsigned long div;
|
2019-08-29 02:37:54 +08:00
|
|
|
unsigned long num, denom, old_ubir, old_ubmr;
|
2009-06-11 21:55:22 +08:00
|
|
|
uint64_t tdiv64;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We only support CS7 and CS8.
|
|
|
|
*/
|
|
|
|
while ((termios->c_cflag & CSIZE) != CS7 &&
|
|
|
|
(termios->c_cflag & CSIZE) != CS8) {
|
|
|
|
termios->c_cflag &= ~CSIZE;
|
|
|
|
termios->c_cflag |= old_csize;
|
|
|
|
old_csize = CS8;
|
|
|
|
}
|
|
|
|
|
2019-06-11 20:05:24 +08:00
|
|
|
del_timer_sync(&sport->timer);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Ask the core to calculate the divisor for us.
|
|
|
|
*/
|
|
|
|
baud = uart_get_baud_rate(port, termios, old, 50, port->uartclk / 16);
|
|
|
|
quot = uart_get_divisor(port, baud);
|
|
|
|
|
|
|
|
spin_lock_irqsave(&sport->port.lock, flags);
|
|
|
|
|
2019-06-26 22:11:30 +08:00
|
|
|
/*
|
|
|
|
* Read current UCR2 and save it for future use, then clear all the bits
|
|
|
|
* except those we will or may need to preserve.
|
|
|
|
*/
|
|
|
|
old_ucr2 = imx_uart_readl(sport, UCR2);
|
|
|
|
ucr2 = old_ucr2 & (UCR2_TXEN | UCR2_RXEN | UCR2_ATEN | UCR2_CTS);
|
|
|
|
|
|
|
|
ucr2 |= UCR2_SRST | UCR2_IRTS;
|
2005-04-17 06:20:36 +08:00
|
|
|
if ((termios->c_cflag & CSIZE) == CS8)
|
2019-06-26 22:11:28 +08:00
|
|
|
ucr2 |= UCR2_WS;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2019-06-26 22:11:29 +08:00
|
|
|
if (!sport->have_rtscts)
|
|
|
|
termios->c_cflag &= ~CRTSCTS;
|
|
|
|
|
|
|
|
if (port->rs485.flags & SER_RS485_ENABLED) {
|
|
|
|
/*
|
|
|
|
* RTS is mandatory for rs485 operation, so keep
|
|
|
|
* it under manual control and keep transmitter
|
|
|
|
* disabled.
|
|
|
|
*/
|
2015-12-13 18:30:03 +08:00
|
|
|
if (port->rs485.flags & SER_RS485_RTS_AFTER_SEND)
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_rts_active(sport, &ucr2);
|
2017-01-30 19:12:11 +08:00
|
|
|
else
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_rts_inactive(sport, &ucr2);
|
2015-12-13 18:30:03 +08:00
|
|
|
|
2019-07-27 02:52:41 +08:00
|
|
|
} else if (termios->c_cflag & CRTSCTS) {
|
|
|
|
/*
|
|
|
|
* Only let receiver control RTS output if we were not requested
|
|
|
|
* to have RTS inactive (which then should take precedence).
|
|
|
|
*/
|
|
|
|
if (ucr2 & UCR2_CTS)
|
|
|
|
ucr2 |= UCR2_CTSC;
|
|
|
|
}
|
2019-06-26 22:11:29 +08:00
|
|
|
|
|
|
|
if (termios->c_cflag & CRTSCTS)
|
|
|
|
ucr2 &= ~UCR2_IRTS;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (termios->c_cflag & CSTOPB)
|
|
|
|
ucr2 |= UCR2_STPB;
|
|
|
|
if (termios->c_cflag & PARENB) {
|
|
|
|
ucr2 |= UCR2_PREN;
|
2006-01-14 04:51:44 +08:00
|
|
|
if (termios->c_cflag & PARODD)
|
2005-04-17 06:20:36 +08:00
|
|
|
ucr2 |= UCR2_PROE;
|
|
|
|
}
|
|
|
|
|
|
|
|
sport->port.read_status_mask = 0;
|
|
|
|
if (termios->c_iflag & INPCK)
|
|
|
|
sport->port.read_status_mask |= (URXD_FRMERR | URXD_PRERR);
|
|
|
|
if (termios->c_iflag & (BRKINT | PARMRK))
|
|
|
|
sport->port.read_status_mask |= URXD_BRK;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Characters to ignore
|
|
|
|
*/
|
|
|
|
sport->port.ignore_status_mask = 0;
|
|
|
|
if (termios->c_iflag & IGNPAR)
|
2014-12-19 03:37:14 +08:00
|
|
|
sport->port.ignore_status_mask |= URXD_PRERR | URXD_FRMERR;
|
2005-04-17 06:20:36 +08:00
|
|
|
if (termios->c_iflag & IGNBRK) {
|
|
|
|
sport->port.ignore_status_mask |= URXD_BRK;
|
|
|
|
/*
|
|
|
|
* 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 |= URXD_OVRRUN;
|
|
|
|
}
|
|
|
|
|
2014-12-09 17:11:22 +08:00
|
|
|
if ((termios->c_cflag & CREAD) == 0)
|
|
|
|
sport->port.ignore_status_mask |= URXD_DUMMY_READ;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
/*
|
|
|
|
* Update the per-port timeout.
|
|
|
|
*/
|
|
|
|
uart_update_timeout(port, termios->c_cflag, baud);
|
|
|
|
|
2015-02-24 18:17:10 +08:00
|
|
|
/* custom-baudrate handling */
|
|
|
|
div = sport->port.uartclk / (baud * 16);
|
|
|
|
if (baud == 38400 && quot != div)
|
|
|
|
baud = sport->port.uartclk / (quot * 16);
|
|
|
|
|
|
|
|
div = sport->port.uartclk / (baud * 16);
|
|
|
|
if (div > 7)
|
|
|
|
div = 7;
|
|
|
|
if (!div)
|
2008-07-05 16:02:44 +08:00
|
|
|
div = 1;
|
|
|
|
|
2009-06-11 21:52:23 +08:00
|
|
|
rational_best_approximation(16 * div * baud, sport->port.uartclk,
|
|
|
|
1 << 16, 1 << 16, &num, &denom);
|
2008-07-05 16:02:44 +08:00
|
|
|
|
2010-06-02 04:52:52 +08:00
|
|
|
tdiv64 = sport->port.uartclk;
|
|
|
|
tdiv64 *= num;
|
|
|
|
do_div(tdiv64, denom * 16 * div);
|
|
|
|
tty_termios_encode_baud_rate(termios,
|
2009-06-17 00:02:15 +08:00
|
|
|
(speed_t)tdiv64, (speed_t)tdiv64);
|
2009-06-11 21:55:22 +08:00
|
|
|
|
2009-06-11 21:52:23 +08:00
|
|
|
num -= 1;
|
|
|
|
denom -= 1;
|
2008-07-05 16:02:44 +08:00
|
|
|
|
2018-03-02 18:07:19 +08:00
|
|
|
ufcr = imx_uart_readl(sport, UFCR);
|
2009-06-11 21:53:18 +08:00
|
|
|
ufcr = (ufcr & (~UFCR_RFDIV)) | UFCR_RFDIV_REG(div);
|
2018-03-02 18:07:19 +08:00
|
|
|
imx_uart_writel(sport, ufcr, UFCR);
|
2008-07-05 16:02:44 +08:00
|
|
|
|
2019-08-29 02:37:54 +08:00
|
|
|
/*
|
|
|
|
* Two registers below should always be written both and in this
|
|
|
|
* particular order. One consequence is that we need to check if any of
|
|
|
|
* them changes and then update both. We do need the check for change
|
|
|
|
* as even writing the same values seem to "restart"
|
|
|
|
* transmission/receiving logic in the hardware, that leads to data
|
|
|
|
* breakage even when rate doesn't in fact change. E.g., user switches
|
|
|
|
* RTS/CTS handshake and suddenly gets broken bytes.
|
|
|
|
*/
|
|
|
|
old_ubir = imx_uart_readl(sport, UBIR);
|
|
|
|
old_ubmr = imx_uart_readl(sport, UBMR);
|
|
|
|
if (old_ubir != num || old_ubmr != denom) {
|
|
|
|
imx_uart_writel(sport, num, UBIR);
|
|
|
|
imx_uart_writel(sport, denom, UBMR);
|
|
|
|
}
|
2009-06-11 21:52:23 +08:00
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
if (!imx_uart_is_imx1(sport))
|
2018-03-02 18:07:19 +08:00
|
|
|
imx_uart_writel(sport, sport->port.uartclk / div / 1000,
|
|
|
|
IMX21_ONEMS);
|
2007-04-26 15:26:13 +08:00
|
|
|
|
2019-06-26 22:11:30 +08:00
|
|
|
imx_uart_writel(sport, ucr2, UCR2);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (UART_ENABLE_MS(&sport->port, termios->c_cflag))
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_enable_ms(&sport->port);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
spin_unlock_irqrestore(&sport->port.lock, flags);
|
|
|
|
}
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static const char *imx_uart_type(struct uart_port *port)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct imx_port *sport = (struct imx_port *)port;
|
|
|
|
|
|
|
|
return sport->port.type == PORT_IMX ? "IMX" : NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Configure/autoconfigure the port.
|
|
|
|
*/
|
2018-03-02 18:07:30 +08:00
|
|
|
static void imx_uart_config_port(struct uart_port *port, int flags)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct imx_port *sport = (struct imx_port *)port;
|
|
|
|
|
2014-02-22 20:01:33 +08:00
|
|
|
if (flags & UART_CONFIG_TYPE)
|
2005-04-17 06:20:36 +08:00
|
|
|
sport->port.type = PORT_IMX;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Verify the new serial_struct (for TIOCSSERIAL).
|
|
|
|
* The only change we allow are to the flags and type, and
|
|
|
|
* even then only between PORT_IMX and PORT_UNKNOWN
|
|
|
|
*/
|
|
|
|
static int
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_verify_port(struct uart_port *port, struct serial_struct *ser)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct imx_port *sport = (struct imx_port *)port;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (ser->type != PORT_UNKNOWN && ser->type != PORT_IMX)
|
|
|
|
ret = -EINVAL;
|
|
|
|
if (sport->port.irq != ser->irq)
|
|
|
|
ret = -EINVAL;
|
|
|
|
if (ser->io_type != UPIO_MEM)
|
|
|
|
ret = -EINVAL;
|
|
|
|
if (sport->port.uartclk / 16 != ser->baud_base)
|
|
|
|
ret = -EINVAL;
|
2013-09-12 12:27:53 +08:00
|
|
|
if (sport->port.mapbase != (unsigned long)ser->iomem_base)
|
2005-04-17 06:20:36 +08:00
|
|
|
ret = -EINVAL;
|
|
|
|
if (sport->port.iobase != ser->port)
|
|
|
|
ret = -EINVAL;
|
|
|
|
if (ser->hub6 != 0)
|
|
|
|
ret = -EINVAL;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-12-22 16:57:53 +08:00
|
|
|
#if defined(CONFIG_CONSOLE_POLL)
|
2014-10-28 16:28:08 +08:00
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static int imx_uart_poll_init(struct uart_port *port)
|
2014-10-28 16:28:08 +08:00
|
|
|
{
|
|
|
|
struct imx_port *sport = (struct imx_port *)port;
|
|
|
|
unsigned long flags;
|
2018-03-02 18:07:23 +08:00
|
|
|
u32 ucr1, ucr2;
|
2014-10-28 16:28:08 +08:00
|
|
|
int retval;
|
|
|
|
|
|
|
|
retval = clk_prepare_enable(sport->clk_ipg);
|
|
|
|
if (retval)
|
|
|
|
return retval;
|
|
|
|
retval = clk_prepare_enable(sport->clk_per);
|
|
|
|
if (retval)
|
|
|
|
clk_disable_unprepare(sport->clk_ipg);
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_setup_ufcr(sport, TXTL_DEFAULT, RXTL_DEFAULT);
|
2014-10-28 16:28:08 +08:00
|
|
|
|
|
|
|
spin_lock_irqsave(&sport->port.lock, flags);
|
|
|
|
|
2018-03-02 18:07:26 +08:00
|
|
|
/*
|
|
|
|
* Be careful about the order of enabling bits here. First enable the
|
|
|
|
* receiver (UARTEN + RXEN) and only then the corresponding irqs.
|
|
|
|
* This prevents that a character that already sits in the RX fifo is
|
|
|
|
* triggering an irq but the try to fetch it from there results in an
|
|
|
|
* exception because UARTEN or RXEN is still off.
|
|
|
|
*/
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr1 = imx_uart_readl(sport, UCR1);
|
2018-03-02 18:07:26 +08:00
|
|
|
ucr2 = imx_uart_readl(sport, UCR2);
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
if (imx_uart_is_imx1(sport))
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr1 |= IMX1_UCR1_UARTCLKEN;
|
2014-10-28 16:28:08 +08:00
|
|
|
|
2018-03-02 18:07:26 +08:00
|
|
|
ucr1 |= UCR1_UARTEN;
|
2019-08-29 02:37:55 +08:00
|
|
|
ucr1 &= ~(UCR1_TRDYEN | UCR1_RTSDEN | UCR1_RRDYEN);
|
2018-03-02 18:07:26 +08:00
|
|
|
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr2 |= UCR2_RXEN;
|
2018-03-02 18:07:27 +08:00
|
|
|
ucr2 &= ~UCR2_ATEN;
|
2018-03-02 18:07:26 +08:00
|
|
|
|
|
|
|
imx_uart_writel(sport, ucr1, UCR1);
|
2018-03-02 18:07:23 +08:00
|
|
|
imx_uart_writel(sport, ucr2, UCR2);
|
2014-10-28 16:28:08 +08:00
|
|
|
|
2018-03-02 18:07:26 +08:00
|
|
|
/* now enable irqs */
|
|
|
|
imx_uart_writel(sport, ucr1 | UCR1_RRDYEN, UCR1);
|
2018-03-02 18:07:27 +08:00
|
|
|
imx_uart_writel(sport, ucr2 | UCR2_ATEN, UCR2);
|
2018-03-02 18:07:26 +08:00
|
|
|
|
2014-10-28 16:28:08 +08:00
|
|
|
spin_unlock_irqrestore(&sport->port.lock, flags);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static int imx_uart_poll_get_char(struct uart_port *port)
|
2011-12-22 16:57:53 +08:00
|
|
|
{
|
2018-03-02 18:07:19 +08:00
|
|
|
struct imx_port *sport = (struct imx_port *)port;
|
|
|
|
if (!(imx_uart_readl(sport, USR2) & USR2_RDR))
|
2014-09-03 19:33:53 +08:00
|
|
|
return NO_POLL_CHAR;
|
2011-12-22 16:57:53 +08:00
|
|
|
|
2018-03-02 18:07:19 +08:00
|
|
|
return imx_uart_readl(sport, URXD0) & URXD_RX_DATA;
|
2011-12-22 16:57:53 +08:00
|
|
|
}
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static void imx_uart_poll_put_char(struct uart_port *port, unsigned char c)
|
2011-12-22 16:57:53 +08:00
|
|
|
{
|
2018-03-02 18:07:19 +08:00
|
|
|
struct imx_port *sport = (struct imx_port *)port;
|
2011-12-22 16:57:53 +08:00
|
|
|
unsigned int status;
|
|
|
|
|
|
|
|
/* drain */
|
|
|
|
do {
|
2018-03-02 18:07:19 +08:00
|
|
|
status = imx_uart_readl(sport, USR1);
|
2011-12-22 16:57:53 +08:00
|
|
|
} while (~status & USR1_TRDY);
|
|
|
|
|
|
|
|
/* write */
|
2018-03-02 18:07:19 +08:00
|
|
|
imx_uart_writel(sport, c, URTX0);
|
2011-12-22 16:57:53 +08:00
|
|
|
|
|
|
|
/* flush */
|
|
|
|
do {
|
2018-03-02 18:07:19 +08:00
|
|
|
status = imx_uart_readl(sport, USR2);
|
2011-12-22 16:57:53 +08:00
|
|
|
} while (~status & USR2_TXDC);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-02-28 05:44:56 +08:00
|
|
|
/* called with port.lock taken and irqs off or from .probe without locking */
|
2018-03-02 18:07:30 +08:00
|
|
|
static int imx_uart_rs485_config(struct uart_port *port,
|
|
|
|
struct serial_rs485 *rs485conf)
|
2015-02-24 18:17:11 +08:00
|
|
|
{
|
|
|
|
struct imx_port *sport = (struct imx_port *)port;
|
2018-03-02 18:07:23 +08:00
|
|
|
u32 ucr2;
|
2015-02-24 18:17:11 +08:00
|
|
|
|
|
|
|
/* RTS is required to control the transmitter */
|
2017-01-08 05:29:13 +08:00
|
|
|
if (!sport->have_rtscts && !sport->have_rtsgpio)
|
2015-02-24 18:17:11 +08:00
|
|
|
rs485conf->flags &= ~SER_RS485_ENABLED;
|
|
|
|
|
|
|
|
if (rs485conf->flags & SER_RS485_ENABLED) {
|
2018-04-19 23:39:16 +08:00
|
|
|
/* Enable receiver if low-active RTS signal is requested */
|
|
|
|
if (sport->have_rtscts && !sport->have_rtsgpio &&
|
|
|
|
!(rs485conf->flags & SER_RS485_RTS_ON_SEND))
|
|
|
|
rs485conf->flags |= SER_RS485_RX_DURING_TX;
|
|
|
|
|
2015-02-24 18:17:11 +08:00
|
|
|
/* disable transmitter */
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr2 = imx_uart_readl(sport, UCR2);
|
2015-02-24 18:17:11 +08:00
|
|
|
if (rs485conf->flags & SER_RS485_RTS_AFTER_SEND)
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_rts_active(sport, &ucr2);
|
2017-01-30 19:12:11 +08:00
|
|
|
else
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_rts_inactive(sport, &ucr2);
|
2018-03-02 18:07:23 +08:00
|
|
|
imx_uart_writel(sport, ucr2, UCR2);
|
2015-02-24 18:17:11 +08:00
|
|
|
}
|
|
|
|
|
2016-02-29 20:34:10 +08:00
|
|
|
/* Make sure Rx is enabled in case Tx is active with Rx disabled */
|
|
|
|
if (!(rs485conf->flags & SER_RS485_ENABLED) ||
|
2018-03-02 18:07:26 +08:00
|
|
|
rs485conf->flags & SER_RS485_RX_DURING_TX)
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_start_rx(port);
|
2016-02-29 20:34:10 +08:00
|
|
|
|
2015-02-24 18:17:11 +08:00
|
|
|
port->rs485 = *rs485conf;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static const struct uart_ops imx_uart_pops = {
|
|
|
|
.tx_empty = imx_uart_tx_empty,
|
|
|
|
.set_mctrl = imx_uart_set_mctrl,
|
|
|
|
.get_mctrl = imx_uart_get_mctrl,
|
|
|
|
.stop_tx = imx_uart_stop_tx,
|
|
|
|
.start_tx = imx_uart_start_tx,
|
|
|
|
.stop_rx = imx_uart_stop_rx,
|
|
|
|
.enable_ms = imx_uart_enable_ms,
|
|
|
|
.break_ctl = imx_uart_break_ctl,
|
|
|
|
.startup = imx_uart_startup,
|
|
|
|
.shutdown = imx_uart_shutdown,
|
|
|
|
.flush_buffer = imx_uart_flush_buffer,
|
|
|
|
.set_termios = imx_uart_set_termios,
|
|
|
|
.type = imx_uart_type,
|
|
|
|
.config_port = imx_uart_config_port,
|
|
|
|
.verify_port = imx_uart_verify_port,
|
2011-12-22 16:57:53 +08:00
|
|
|
#if defined(CONFIG_CONSOLE_POLL)
|
2018-03-02 18:07:30 +08:00
|
|
|
.poll_init = imx_uart_poll_init,
|
|
|
|
.poll_get_char = imx_uart_poll_get_char,
|
|
|
|
.poll_put_char = imx_uart_poll_put_char,
|
2011-12-22 16:57:53 +08:00
|
|
|
#endif
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static struct imx_port *imx_uart_ports[UART_NR];
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2020-07-24 15:08:14 +08:00
|
|
|
#if IS_ENABLED(CONFIG_SERIAL_IMX_CONSOLE)
|
2018-03-02 18:07:30 +08:00
|
|
|
static void imx_uart_console_putchar(struct uart_port *port, int ch)
|
2006-03-21 04:00:09 +08:00
|
|
|
{
|
|
|
|
struct imx_port *sport = (struct imx_port *)port;
|
2007-04-26 15:26:13 +08:00
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
while (imx_uart_readl(sport, imx_uart_uts_reg(sport)) & UTS_TXFULL)
|
2006-03-21 04:00:09 +08:00
|
|
|
barrier();
|
2007-04-26 15:26:13 +08:00
|
|
|
|
2018-03-02 18:07:19 +08:00
|
|
|
imx_uart_writel(sport, ch, URTX0);
|
2006-03-21 04:00:09 +08:00
|
|
|
}
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Interrupts are disabled on entering
|
|
|
|
*/
|
|
|
|
static void
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_console_write(struct console *co, const char *s, unsigned int count)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-03-02 18:07:30 +08:00
|
|
|
struct imx_port *sport = imx_uart_ports[co->index];
|
2011-12-22 16:57:52 +08:00
|
|
|
struct imx_port_ucrs old_ucr;
|
|
|
|
unsigned int ucr1;
|
2013-02-18 13:15:36 +08:00
|
|
|
unsigned long flags = 0;
|
2013-02-15 04:01:06 +08:00
|
|
|
int locked = 1;
|
2013-06-28 13:39:42 +08:00
|
|
|
int retval;
|
|
|
|
|
2015-08-18 23:43:12 +08:00
|
|
|
retval = clk_enable(sport->clk_per);
|
2013-06-28 13:39:42 +08:00
|
|
|
if (retval)
|
|
|
|
return;
|
2015-08-18 23:43:12 +08:00
|
|
|
retval = clk_enable(sport->clk_ipg);
|
2013-06-28 13:39:42 +08:00
|
|
|
if (retval) {
|
2015-08-18 23:43:12 +08:00
|
|
|
clk_disable(sport->clk_per);
|
2013-06-28 13:39:42 +08:00
|
|
|
return;
|
|
|
|
}
|
2012-08-27 15:36:51 +08:00
|
|
|
|
2013-02-15 04:01:06 +08:00
|
|
|
if (sport->port.sysrq)
|
|
|
|
locked = 0;
|
|
|
|
else if (oops_in_progress)
|
|
|
|
locked = spin_trylock_irqsave(&sport->port.lock, flags);
|
|
|
|
else
|
|
|
|
spin_lock_irqsave(&sport->port.lock, flags);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
2011-12-22 16:57:52 +08:00
|
|
|
* First, save UCR1/2/3 and then disable interrupts
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_ucrs_save(sport, &old_ucr);
|
2011-12-22 16:57:52 +08:00
|
|
|
ucr1 = old_ucr.ucr1;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
if (imx_uart_is_imx1(sport))
|
2011-06-25 02:04:33 +08:00
|
|
|
ucr1 |= IMX1_UCR1_UARTCLKEN;
|
2009-05-28 00:23:48 +08:00
|
|
|
ucr1 |= UCR1_UARTEN;
|
2019-08-29 02:37:55 +08:00
|
|
|
ucr1 &= ~(UCR1_TRDYEN | UCR1_RRDYEN | UCR1_RTSDEN);
|
2009-05-28 00:23:48 +08:00
|
|
|
|
2018-03-02 18:07:19 +08:00
|
|
|
imx_uart_writel(sport, ucr1, UCR1);
|
2007-04-26 15:26:13 +08:00
|
|
|
|
2018-03-02 18:07:19 +08:00
|
|
|
imx_uart_writel(sport, old_ucr.ucr2 | UCR2_TXEN, UCR2);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
uart_console_write(&sport->port, s, count, imx_uart_console_putchar);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Finally, wait for transmitter to become empty
|
2011-12-22 16:57:52 +08:00
|
|
|
* and restore UCR1/2/3
|
2005-04-17 06:20:36 +08:00
|
|
|
*/
|
2018-03-02 18:07:19 +08:00
|
|
|
while (!(imx_uart_readl(sport, USR2) & USR2_TXDC));
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_ucrs_restore(sport, &old_ucr);
|
2012-08-27 15:36:51 +08:00
|
|
|
|
2013-02-15 04:01:06 +08:00
|
|
|
if (locked)
|
|
|
|
spin_unlock_irqrestore(&sport->port.lock, flags);
|
2013-06-28 13:39:42 +08:00
|
|
|
|
2015-08-18 23:43:12 +08:00
|
|
|
clk_disable(sport->clk_ipg);
|
|
|
|
clk_disable(sport->clk_per);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the port was already initialised (eg, by a boot loader),
|
|
|
|
* try to determine the current setup.
|
|
|
|
*/
|
|
|
|
static void __init
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_console_get_options(struct imx_port *sport, int *baud,
|
|
|
|
int *parity, int *bits)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2005-04-30 05:46:40 +08:00
|
|
|
|
2018-03-02 18:07:19 +08:00
|
|
|
if (imx_uart_readl(sport, UCR1) & UCR1_UARTEN) {
|
2005-04-17 06:20:36 +08:00
|
|
|
/* ok, the port was enabled */
|
2013-01-07 12:55:02 +08:00
|
|
|
unsigned int ucr2, ubir, ubmr, uartclk;
|
2005-04-30 05:46:40 +08:00
|
|
|
unsigned int baud_raw;
|
|
|
|
unsigned int ucfr_rfdiv;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-03-02 18:07:19 +08:00
|
|
|
ucr2 = imx_uart_readl(sport, UCR2);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
*parity = 'n';
|
|
|
|
if (ucr2 & UCR2_PREN) {
|
|
|
|
if (ucr2 & UCR2_PROE)
|
|
|
|
*parity = 'o';
|
|
|
|
else
|
|
|
|
*parity = 'e';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ucr2 & UCR2_WS)
|
|
|
|
*bits = 8;
|
|
|
|
else
|
|
|
|
*bits = 7;
|
|
|
|
|
2018-03-02 18:07:19 +08:00
|
|
|
ubir = imx_uart_readl(sport, UBIR) & 0xffff;
|
|
|
|
ubmr = imx_uart_readl(sport, UBMR) & 0xffff;
|
2005-04-30 05:46:40 +08:00
|
|
|
|
2018-03-02 18:07:19 +08:00
|
|
|
ucfr_rfdiv = (imx_uart_readl(sport, UFCR) & UFCR_RFDIV) >> 7;
|
2005-04-30 05:46:40 +08:00
|
|
|
if (ucfr_rfdiv == 6)
|
|
|
|
ucfr_rfdiv = 7;
|
|
|
|
else
|
|
|
|
ucfr_rfdiv = 6 - ucfr_rfdiv;
|
|
|
|
|
2012-03-07 16:31:43 +08:00
|
|
|
uartclk = clk_get_rate(sport->clk_per);
|
2005-04-30 05:46:40 +08:00
|
|
|
uartclk /= ucfr_rfdiv;
|
|
|
|
|
|
|
|
{ /*
|
|
|
|
* The next code provides exact computation of
|
|
|
|
* baud_raw = round(((uartclk/16) * (ubir + 1)) / (ubmr + 1))
|
|
|
|
* without need of float support or long long division,
|
|
|
|
* which would be required to prevent 32bit arithmetic overflow
|
|
|
|
*/
|
|
|
|
unsigned int mul = ubir + 1;
|
|
|
|
unsigned int div = 16 * (ubmr + 1);
|
|
|
|
unsigned int rem = uartclk % div;
|
|
|
|
|
|
|
|
baud_raw = (uartclk / div) * mul;
|
|
|
|
baud_raw += (rem * mul + div / 2) / div;
|
|
|
|
*baud = (baud_raw + 50) / 100 * 100;
|
|
|
|
}
|
|
|
|
|
2013-01-07 12:55:02 +08:00
|
|
|
if (*baud != baud_raw)
|
2019-06-04 11:31:39 +08:00
|
|
|
dev_info(sport->port.dev, "Console IMX rounded baud rate from %d to %d\n",
|
2005-04-30 05:46:40 +08:00
|
|
|
baud_raw, *baud);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __init
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_console_setup(struct console *co, char *options)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
|
|
|
struct imx_port *sport;
|
|
|
|
int baud = 9600;
|
|
|
|
int bits = 8;
|
|
|
|
int parity = 'n';
|
|
|
|
int flow = 'n';
|
2013-06-28 13:39:42 +08:00
|
|
|
int retval;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check whether an invalid uart number has been specified, and
|
|
|
|
* if so, search for the first available port that does have
|
|
|
|
* console support.
|
|
|
|
*/
|
2018-03-02 18:07:30 +08:00
|
|
|
if (co->index == -1 || co->index >= ARRAY_SIZE(imx_uart_ports))
|
2005-04-17 06:20:36 +08:00
|
|
|
co->index = 0;
|
2018-03-02 18:07:30 +08:00
|
|
|
sport = imx_uart_ports[co->index];
|
2013-01-07 12:55:02 +08:00
|
|
|
if (sport == NULL)
|
2009-05-20 08:53:20 +08:00
|
|
|
return -ENODEV;
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2013-06-28 13:39:42 +08:00
|
|
|
/* For setting the registers, we only need to enable the ipg clock. */
|
|
|
|
retval = clk_prepare_enable(sport->clk_ipg);
|
|
|
|
if (retval)
|
|
|
|
goto error_console;
|
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
if (options)
|
|
|
|
uart_parse_options(options, &baud, &parity, &bits, &flow);
|
|
|
|
else
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_console_get_options(sport, &baud, &parity, &bits);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_setup_ufcr(sport, TXTL_DEFAULT, RXTL_DEFAULT);
|
2005-04-30 05:46:40 +08:00
|
|
|
|
2013-06-28 13:39:42 +08:00
|
|
|
retval = uart_set_options(&sport->port, co, baud, parity, bits, flow);
|
|
|
|
|
2015-08-18 23:43:12 +08:00
|
|
|
clk_disable(sport->clk_ipg);
|
|
|
|
if (retval) {
|
|
|
|
clk_unprepare(sport->clk_ipg);
|
|
|
|
goto error_console;
|
|
|
|
}
|
|
|
|
|
|
|
|
retval = clk_prepare(sport->clk_per);
|
|
|
|
if (retval)
|
2018-11-15 01:49:38 +08:00
|
|
|
clk_unprepare(sport->clk_ipg);
|
2013-06-28 13:39:42 +08:00
|
|
|
|
|
|
|
error_console:
|
|
|
|
return retval;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static struct uart_driver imx_uart_uart_driver;
|
|
|
|
static struct console imx_uart_console = {
|
2008-07-05 16:02:48 +08:00
|
|
|
.name = DEV_NAME,
|
2018-03-02 18:07:30 +08:00
|
|
|
.write = imx_uart_console_write,
|
2005-04-17 06:20:36 +08:00
|
|
|
.device = uart_console_device,
|
2018-03-02 18:07:30 +08:00
|
|
|
.setup = imx_uart_console_setup,
|
2005-04-17 06:20:36 +08:00
|
|
|
.flags = CON_PRINTBUFFER,
|
|
|
|
.index = -1,
|
2018-03-02 18:07:30 +08:00
|
|
|
.data = &imx_uart_uart_driver,
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
#define IMX_CONSOLE &imx_uart_console
|
2015-08-28 17:56:19 +08:00
|
|
|
|
2005-04-17 06:20:36 +08:00
|
|
|
#else
|
|
|
|
#define IMX_CONSOLE NULL
|
|
|
|
#endif
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static struct uart_driver imx_uart_uart_driver = {
|
2005-04-17 06:20:36 +08:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.driver_name = DRIVER_NAME,
|
2008-07-05 16:02:48 +08:00
|
|
|
.dev_name = DEV_NAME,
|
2005-04-17 06:20:36 +08:00
|
|
|
.major = SERIAL_IMX_MAJOR,
|
|
|
|
.minor = MINOR_START,
|
2018-03-02 18:07:30 +08:00
|
|
|
.nr = ARRAY_SIZE(imx_uart_ports),
|
2005-04-17 06:20:36 +08:00
|
|
|
.cons = IMX_CONSOLE,
|
|
|
|
};
|
|
|
|
|
2011-06-25 02:04:34 +08:00
|
|
|
#ifdef CONFIG_OF
|
2011-12-15 16:16:34 +08:00
|
|
|
/*
|
|
|
|
* This function returns 1 iff pdev isn't a device instatiated by dt, 0 iff it
|
|
|
|
* could successfully get all information from dt or a negative errno.
|
|
|
|
*/
|
2018-03-02 18:07:30 +08:00
|
|
|
static int imx_uart_probe_dt(struct imx_port *sport,
|
|
|
|
struct platform_device *pdev)
|
2011-06-25 02:04:34 +08:00
|
|
|
{
|
|
|
|
struct device_node *np = pdev->dev.of_node;
|
2011-09-22 14:48:13 +08:00
|
|
|
int ret;
|
2011-06-25 02:04:34 +08:00
|
|
|
|
2015-11-24 22:36:57 +08:00
|
|
|
sport->devdata = of_device_get_match_data(&pdev->dev);
|
|
|
|
if (!sport->devdata)
|
2011-12-15 16:16:34 +08:00
|
|
|
/* no device tree device */
|
|
|
|
return 1;
|
2011-06-25 02:04:34 +08:00
|
|
|
|
2011-09-22 14:48:13 +08:00
|
|
|
ret = of_alias_get_id(np, "serial");
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&pdev->dev, "failed to get alias id, errno %d\n", ret);
|
2011-12-15 04:26:51 +08:00
|
|
|
return ret;
|
2011-09-22 14:48:13 +08:00
|
|
|
}
|
|
|
|
sport->port.line = ret;
|
2011-06-25 02:04:34 +08:00
|
|
|
|
2016-04-22 23:22:21 +08:00
|
|
|
if (of_get_property(np, "uart-has-rtscts", NULL) ||
|
|
|
|
of_get_property(np, "fsl,uart-has-rtscts", NULL) /* deprecated */)
|
2011-06-25 02:04:34 +08:00
|
|
|
sport->have_rtscts = 1;
|
|
|
|
|
2013-05-30 14:07:12 +08:00
|
|
|
if (of_get_property(np, "fsl,dte-mode", NULL))
|
|
|
|
sport->dte_mode = 1;
|
|
|
|
|
2017-01-08 05:29:13 +08:00
|
|
|
if (of_get_property(np, "rts-gpios", NULL))
|
|
|
|
sport->have_rtsgpio = 1;
|
|
|
|
|
2020-02-27 06:23:19 +08:00
|
|
|
if (of_get_property(np, "fsl,inverted-tx", NULL))
|
|
|
|
sport->inverted_tx = 1;
|
|
|
|
|
|
|
|
if (of_get_property(np, "fsl,inverted-rx", NULL))
|
|
|
|
sport->inverted_rx = 1;
|
|
|
|
|
2011-06-25 02:04:34 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#else
|
2018-03-02 18:07:30 +08:00
|
|
|
static inline int imx_uart_probe_dt(struct imx_port *sport,
|
|
|
|
struct platform_device *pdev)
|
2011-06-25 02:04:34 +08:00
|
|
|
{
|
2011-12-15 16:16:34 +08:00
|
|
|
return 1;
|
2011-06-25 02:04:34 +08:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static void imx_uart_probe_pdata(struct imx_port *sport,
|
|
|
|
struct platform_device *pdev)
|
2011-06-25 02:04:34 +08:00
|
|
|
{
|
2013-07-30 16:06:57 +08:00
|
|
|
struct imxuart_platform_data *pdata = dev_get_platdata(&pdev->dev);
|
2011-06-25 02:04:34 +08:00
|
|
|
|
|
|
|
sport->port.line = pdev->id;
|
|
|
|
sport->devdata = (struct imx_uart_data *) pdev->id_entry->driver_data;
|
|
|
|
|
|
|
|
if (!pdata)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (pdata->flags & IMXUART_HAVE_RTSCTS)
|
|
|
|
sport->have_rtscts = 1;
|
|
|
|
}
|
|
|
|
|
2020-07-14 17:30:12 +08:00
|
|
|
static enum hrtimer_restart imx_trigger_start_tx(struct hrtimer *t)
|
2020-07-14 17:30:11 +08:00
|
|
|
{
|
2020-07-14 17:30:12 +08:00
|
|
|
struct imx_port *sport = container_of(t, struct imx_port, trigger_start_tx);
|
2020-07-14 17:30:11 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&sport->port.lock, flags);
|
|
|
|
if (sport->tx_state == WAIT_AFTER_RTS)
|
|
|
|
imx_uart_start_tx(&sport->port);
|
|
|
|
spin_unlock_irqrestore(&sport->port.lock, flags);
|
2020-07-14 17:30:12 +08:00
|
|
|
|
|
|
|
return HRTIMER_NORESTART;
|
2020-07-14 17:30:11 +08:00
|
|
|
}
|
|
|
|
|
2020-07-14 17:30:12 +08:00
|
|
|
static enum hrtimer_restart imx_trigger_stop_tx(struct hrtimer *t)
|
2020-07-14 17:30:11 +08:00
|
|
|
{
|
2020-07-14 17:30:12 +08:00
|
|
|
struct imx_port *sport = container_of(t, struct imx_port, trigger_stop_tx);
|
2020-07-14 17:30:11 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&sport->port.lock, flags);
|
|
|
|
if (sport->tx_state == WAIT_AFTER_SEND)
|
|
|
|
imx_uart_stop_tx(&sport->port);
|
|
|
|
spin_unlock_irqrestore(&sport->port.lock, flags);
|
2020-07-14 17:30:12 +08:00
|
|
|
|
|
|
|
return HRTIMER_NORESTART;
|
2020-07-14 17:30:11 +08:00
|
|
|
}
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static int imx_uart_probe(struct platform_device *pdev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-07-05 16:02:45 +08:00
|
|
|
struct imx_port *sport;
|
|
|
|
void __iomem *base;
|
2018-03-02 18:07:23 +08:00
|
|
|
int ret = 0;
|
|
|
|
u32 ucr1;
|
2008-07-05 16:02:45 +08:00
|
|
|
struct resource *res;
|
2015-02-24 18:17:07 +08:00
|
|
|
int txirq, rxirq, rtsirq;
|
2008-07-05 16:02:45 +08:00
|
|
|
|
2013-01-07 12:55:06 +08:00
|
|
|
sport = devm_kzalloc(&pdev->dev, sizeof(*sport), GFP_KERNEL);
|
2008-07-05 16:02:45 +08:00
|
|
|
if (!sport)
|
|
|
|
return -ENOMEM;
|
2006-05-04 21:07:42 +08:00
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
ret = imx_uart_probe_dt(sport, pdev);
|
2011-12-15 16:16:34 +08:00
|
|
|
if (ret > 0)
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_probe_pdata(sport, pdev);
|
2011-12-15 16:16:34 +08:00
|
|
|
else if (ret < 0)
|
2013-01-07 12:55:06 +08:00
|
|
|
return ret;
|
2011-06-25 02:04:34 +08:00
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
if (sport->port.line >= ARRAY_SIZE(imx_uart_ports)) {
|
2018-02-23 21:38:31 +08:00
|
|
|
dev_err(&pdev->dev, "serial%d out of range\n",
|
|
|
|
sport->port.line);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2008-07-05 16:02:45 +08:00
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
2014-02-22 20:01:33 +08:00
|
|
|
base = devm_ioremap_resource(&pdev->dev, res);
|
|
|
|
if (IS_ERR(base))
|
|
|
|
return PTR_ERR(base);
|
2008-07-05 16:02:45 +08:00
|
|
|
|
2015-02-24 18:17:07 +08:00
|
|
|
rxirq = platform_get_irq(pdev, 0);
|
2020-05-11 15:09:56 +08:00
|
|
|
if (rxirq < 0)
|
|
|
|
return rxirq;
|
2019-10-09 17:49:19 +08:00
|
|
|
txirq = platform_get_irq_optional(pdev, 1);
|
|
|
|
rtsirq = platform_get_irq_optional(pdev, 2);
|
2015-02-24 18:17:07 +08:00
|
|
|
|
2008-07-05 16:02:45 +08:00
|
|
|
sport->port.dev = &pdev->dev;
|
|
|
|
sport->port.mapbase = res->start;
|
|
|
|
sport->port.membase = base;
|
|
|
|
sport->port.type = PORT_IMX,
|
|
|
|
sport->port.iotype = UPIO_MEM;
|
2015-02-24 18:17:07 +08:00
|
|
|
sport->port.irq = rxirq;
|
2008-07-05 16:02:45 +08:00
|
|
|
sport->port.fifosize = 32;
|
2019-12-13 08:06:18 +08:00
|
|
|
sport->port.has_sysrq = IS_ENABLED(CONFIG_SERIAL_IMX_CONSOLE);
|
2018-03-02 18:07:30 +08:00
|
|
|
sport->port.ops = &imx_uart_pops;
|
|
|
|
sport->port.rs485_config = imx_uart_rs485_config;
|
2008-07-05 16:02:45 +08:00
|
|
|
sport->port.flags = UPF_BOOT_AUTOCONF;
|
2018-03-02 18:07:30 +08:00
|
|
|
timer_setup(&sport->timer, imx_uart_timeout, 0);
|
2008-07-05 16:02:46 +08:00
|
|
|
|
2015-12-13 18:30:03 +08:00
|
|
|
sport->gpios = mctrl_gpio_init(&sport->port, 0);
|
|
|
|
if (IS_ERR(sport->gpios))
|
|
|
|
return PTR_ERR(sport->gpios);
|
|
|
|
|
2012-03-07 16:31:43 +08:00
|
|
|
sport->clk_ipg = devm_clk_get(&pdev->dev, "ipg");
|
|
|
|
if (IS_ERR(sport->clk_ipg)) {
|
|
|
|
ret = PTR_ERR(sport->clk_ipg);
|
2012-08-20 15:57:04 +08:00
|
|
|
dev_err(&pdev->dev, "failed to get ipg clk: %d\n", ret);
|
2013-01-07 12:55:06 +08:00
|
|
|
return ret;
|
2008-07-05 16:02:46 +08:00
|
|
|
}
|
|
|
|
|
2012-03-07 16:31:43 +08:00
|
|
|
sport->clk_per = devm_clk_get(&pdev->dev, "per");
|
|
|
|
if (IS_ERR(sport->clk_per)) {
|
|
|
|
ret = PTR_ERR(sport->clk_per);
|
2012-08-20 15:57:04 +08:00
|
|
|
dev_err(&pdev->dev, "failed to get per clk: %d\n", ret);
|
2013-01-07 12:55:06 +08:00
|
|
|
return ret;
|
2012-03-07 16:31:43 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
sport->port.uartclk = clk_get_rate(sport->clk_per);
|
2008-07-05 16:02:45 +08:00
|
|
|
|
2015-06-18 04:35:43 +08:00
|
|
|
/* For register access, we only need to enable the ipg clock. */
|
|
|
|
ret = clk_prepare_enable(sport->clk_ipg);
|
2016-09-08 20:27:53 +08:00
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "failed to enable per clk: %d\n", ret);
|
2015-06-18 04:35:43 +08:00
|
|
|
return ret;
|
2016-09-08 20:27:53 +08:00
|
|
|
}
|
2015-06-18 04:35:43 +08:00
|
|
|
|
2018-03-02 18:07:20 +08:00
|
|
|
/* initialize shadow register values */
|
|
|
|
sport->ucr1 = readl(sport->port.membase + UCR1);
|
|
|
|
sport->ucr2 = readl(sport->port.membase + UCR2);
|
|
|
|
sport->ucr3 = readl(sport->port.membase + UCR3);
|
|
|
|
sport->ucr4 = readl(sport->port.membase + UCR4);
|
|
|
|
sport->ufcr = readl(sport->port.membase + UFCR);
|
|
|
|
|
2020-05-12 20:40:02 +08:00
|
|
|
ret = uart_get_rs485_mode(&sport->port);
|
|
|
|
if (ret) {
|
|
|
|
clk_disable_unprepare(sport->clk_ipg);
|
|
|
|
return ret;
|
|
|
|
}
|
2017-11-25 06:26:40 +08:00
|
|
|
|
2017-11-25 06:26:40 +08:00
|
|
|
if (sport->port.rs485.flags & SER_RS485_ENABLED &&
|
2018-02-19 17:24:15 +08:00
|
|
|
(!sport->have_rtscts && !sport->have_rtsgpio))
|
2017-11-25 06:26:40 +08:00
|
|
|
dev_err(&pdev->dev, "no RTS control, disabling rs485\n");
|
|
|
|
|
2018-04-19 23:39:16 +08:00
|
|
|
/*
|
|
|
|
* If using the i.MX UART RTS/CTS control then the RTS (CTS_B)
|
|
|
|
* signal cannot be set low during transmission in case the
|
|
|
|
* receiver is off (limitation of the i.MX UART IP).
|
|
|
|
*/
|
|
|
|
if (sport->port.rs485.flags & SER_RS485_ENABLED &&
|
|
|
|
sport->have_rtscts && !sport->have_rtsgpio &&
|
|
|
|
(!(sport->port.rs485.flags & SER_RS485_RTS_ON_SEND) &&
|
|
|
|
!(sport->port.rs485.flags & SER_RS485_RX_DURING_TX)))
|
|
|
|
dev_err(&pdev->dev,
|
|
|
|
"low-active RTS not possible when receiver is off, enabling receiver\n");
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_rs485_config(&sport->port, &sport->port.rs485);
|
2017-11-25 06:26:40 +08:00
|
|
|
|
2015-06-18 04:35:43 +08:00
|
|
|
/* Disable interrupts before requesting them */
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr1 = imx_uart_readl(sport, UCR1);
|
2020-09-03 14:24:01 +08:00
|
|
|
ucr1 &= ~(UCR1_ADEN | UCR1_TRDYEN | UCR1_IDEN | UCR1_RRDYEN | UCR1_RTSDEN);
|
2018-03-02 18:07:23 +08:00
|
|
|
imx_uart_writel(sport, ucr1, UCR1);
|
2015-06-18 04:35:43 +08:00
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
if (!imx_uart_is_imx1(sport) && sport->dte_mode) {
|
2017-04-04 17:18:51 +08:00
|
|
|
/*
|
|
|
|
* The DCEDTE bit changes the direction of DSR, DCD, DTR and RI
|
|
|
|
* and influences if UCR3_RI and UCR3_DCD changes the level of RI
|
|
|
|
* and DCD (when they are outputs) or enables the respective
|
|
|
|
* irqs. So set this bit early, i.e. before requesting irqs.
|
|
|
|
*/
|
2018-03-02 18:07:23 +08:00
|
|
|
u32 ufcr = imx_uart_readl(sport, UFCR);
|
|
|
|
if (!(ufcr & UFCR_DCEDTE))
|
|
|
|
imx_uart_writel(sport, ufcr | UFCR_DCEDTE, UFCR);
|
2017-04-04 17:18:51 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Disable UCR3_RI and UCR3_DCD irqs. They are also not
|
|
|
|
* enabled later because they cannot be cleared
|
|
|
|
* (confirmed on i.MX25) which makes them unusable.
|
|
|
|
*/
|
2018-03-02 18:07:19 +08:00
|
|
|
imx_uart_writel(sport,
|
|
|
|
IMX21_UCR3_RXDMUXSEL | UCR3_ADNIMP | UCR3_DSR,
|
|
|
|
UCR3);
|
2017-04-04 17:18:51 +08:00
|
|
|
|
|
|
|
} else {
|
2018-03-02 18:07:23 +08:00
|
|
|
u32 ucr3 = UCR3_DSR;
|
|
|
|
u32 ufcr = imx_uart_readl(sport, UFCR);
|
|
|
|
if (ufcr & UFCR_DCEDTE)
|
|
|
|
imx_uart_writel(sport, ufcr & ~UFCR_DCEDTE, UFCR);
|
2017-05-25 03:38:46 +08:00
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
if (!imx_uart_is_imx1(sport))
|
2017-05-25 03:38:46 +08:00
|
|
|
ucr3 |= IMX21_UCR3_RXDMUXSEL | UCR3_ADNIMP;
|
2018-03-02 18:07:19 +08:00
|
|
|
imx_uart_writel(sport, ucr3, UCR3);
|
2017-04-04 17:18:51 +08:00
|
|
|
}
|
|
|
|
|
2015-06-18 04:35:43 +08:00
|
|
|
clk_disable_unprepare(sport->clk_ipg);
|
|
|
|
|
2020-07-14 17:30:12 +08:00
|
|
|
hrtimer_init(&sport->trigger_start_tx, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
|
|
|
|
hrtimer_init(&sport->trigger_stop_tx, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
|
|
|
|
sport->trigger_start_tx.function = imx_trigger_start_tx;
|
|
|
|
sport->trigger_stop_tx.function = imx_trigger_stop_tx;
|
2020-07-14 17:30:11 +08:00
|
|
|
|
2014-10-28 00:49:37 +08:00
|
|
|
/*
|
|
|
|
* Allocate the IRQ(s) i.MX1 has three interrupts whereas later
|
|
|
|
* chips only have one interrupt.
|
|
|
|
*/
|
2015-02-24 18:17:07 +08:00
|
|
|
if (txirq > 0) {
|
2018-03-02 18:07:30 +08:00
|
|
|
ret = devm_request_irq(&pdev->dev, rxirq, imx_uart_rxint, 0,
|
2014-10-28 00:49:37 +08:00
|
|
|
dev_name(&pdev->dev), sport);
|
2016-09-08 20:27:53 +08:00
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "failed to request rx irq: %d\n",
|
|
|
|
ret);
|
2014-10-28 00:49:37 +08:00
|
|
|
return ret;
|
2016-09-08 20:27:53 +08:00
|
|
|
}
|
2014-10-28 00:49:37 +08:00
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
ret = devm_request_irq(&pdev->dev, txirq, imx_uart_txint, 0,
|
2014-10-28 00:49:37 +08:00
|
|
|
dev_name(&pdev->dev), sport);
|
2016-09-08 20:27:53 +08:00
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "failed to request tx irq: %d\n",
|
|
|
|
ret);
|
2014-10-28 00:49:37 +08:00
|
|
|
return ret;
|
2016-09-08 20:27:53 +08:00
|
|
|
}
|
2018-09-20 20:11:17 +08:00
|
|
|
|
|
|
|
ret = devm_request_irq(&pdev->dev, rtsirq, imx_uart_rtsint, 0,
|
|
|
|
dev_name(&pdev->dev), sport);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "failed to request rts irq: %d\n",
|
|
|
|
ret);
|
|
|
|
return ret;
|
|
|
|
}
|
2014-10-28 00:49:37 +08:00
|
|
|
} else {
|
2018-03-02 18:07:30 +08:00
|
|
|
ret = devm_request_irq(&pdev->dev, rxirq, imx_uart_int, 0,
|
2014-10-28 00:49:37 +08:00
|
|
|
dev_name(&pdev->dev), sport);
|
2016-09-08 20:27:53 +08:00
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "failed to request irq: %d\n", ret);
|
2014-10-28 00:49:37 +08:00
|
|
|
return ret;
|
2016-09-08 20:27:53 +08:00
|
|
|
}
|
2014-10-28 00:49:37 +08:00
|
|
|
}
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_ports[sport->port.line] = sport;
|
2006-05-04 21:07:42 +08:00
|
|
|
|
2012-09-18 16:14:58 +08:00
|
|
|
platform_set_drvdata(pdev, sport);
|
2006-05-04 21:07:42 +08:00
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
return uart_add_one_port(&imx_uart_uart_driver, &sport->port);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static int imx_uart_remove(struct platform_device *pdev)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2008-07-05 16:02:45 +08:00
|
|
|
struct imx_port *sport = platform_get_drvdata(pdev);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
return uart_remove_one_port(&imx_uart_uart_driver, &sport->port);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static void imx_uart_restore_context(struct imx_port *sport)
|
2015-08-12 01:21:23 +08:00
|
|
|
{
|
2018-09-05 09:24:26 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&sport->port.lock, flags);
|
|
|
|
if (!sport->context_saved) {
|
|
|
|
spin_unlock_irqrestore(&sport->port.lock, flags);
|
2015-08-12 01:21:23 +08:00
|
|
|
return;
|
2018-09-05 09:24:26 +08:00
|
|
|
}
|
2015-08-12 01:21:23 +08:00
|
|
|
|
2018-03-02 18:07:19 +08:00
|
|
|
imx_uart_writel(sport, sport->saved_reg[4], UFCR);
|
|
|
|
imx_uart_writel(sport, sport->saved_reg[5], UESC);
|
|
|
|
imx_uart_writel(sport, sport->saved_reg[6], UTIM);
|
|
|
|
imx_uart_writel(sport, sport->saved_reg[7], UBIR);
|
|
|
|
imx_uart_writel(sport, sport->saved_reg[8], UBMR);
|
|
|
|
imx_uart_writel(sport, sport->saved_reg[9], IMX21_UTS);
|
|
|
|
imx_uart_writel(sport, sport->saved_reg[0], UCR1);
|
|
|
|
imx_uart_writel(sport, sport->saved_reg[1] | UCR2_SRST, UCR2);
|
|
|
|
imx_uart_writel(sport, sport->saved_reg[2], UCR3);
|
|
|
|
imx_uart_writel(sport, sport->saved_reg[3], UCR4);
|
2015-08-12 01:21:23 +08:00
|
|
|
sport->context_saved = false;
|
2018-09-05 09:24:26 +08:00
|
|
|
spin_unlock_irqrestore(&sport->port.lock, flags);
|
2015-08-12 01:21:23 +08:00
|
|
|
}
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static void imx_uart_save_context(struct imx_port *sport)
|
2015-08-12 01:21:23 +08:00
|
|
|
{
|
2018-09-05 09:24:26 +08:00
|
|
|
unsigned long flags;
|
|
|
|
|
2015-08-12 01:21:23 +08:00
|
|
|
/* Save necessary regs */
|
2018-09-05 09:24:26 +08:00
|
|
|
spin_lock_irqsave(&sport->port.lock, flags);
|
2018-03-02 18:07:19 +08:00
|
|
|
sport->saved_reg[0] = imx_uart_readl(sport, UCR1);
|
|
|
|
sport->saved_reg[1] = imx_uart_readl(sport, UCR2);
|
|
|
|
sport->saved_reg[2] = imx_uart_readl(sport, UCR3);
|
|
|
|
sport->saved_reg[3] = imx_uart_readl(sport, UCR4);
|
|
|
|
sport->saved_reg[4] = imx_uart_readl(sport, UFCR);
|
|
|
|
sport->saved_reg[5] = imx_uart_readl(sport, UESC);
|
|
|
|
sport->saved_reg[6] = imx_uart_readl(sport, UTIM);
|
|
|
|
sport->saved_reg[7] = imx_uart_readl(sport, UBIR);
|
|
|
|
sport->saved_reg[8] = imx_uart_readl(sport, UBMR);
|
|
|
|
sport->saved_reg[9] = imx_uart_readl(sport, IMX21_UTS);
|
2015-08-12 01:21:23 +08:00
|
|
|
sport->context_saved = true;
|
2018-09-05 09:24:26 +08:00
|
|
|
spin_unlock_irqrestore(&sport->port.lock, flags);
|
2015-08-12 01:21:23 +08:00
|
|
|
}
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static void imx_uart_enable_wakeup(struct imx_port *sport, bool on)
|
2015-08-12 01:21:21 +08:00
|
|
|
{
|
2018-03-02 18:07:23 +08:00
|
|
|
u32 ucr3;
|
2015-08-12 01:21:21 +08:00
|
|
|
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr3 = imx_uart_readl(sport, UCR3);
|
2018-01-06 00:46:43 +08:00
|
|
|
if (on) {
|
2018-03-02 18:07:19 +08:00
|
|
|
imx_uart_writel(sport, USR1_AWAKE, USR1);
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr3 |= UCR3_AWAKEN;
|
|
|
|
} else {
|
|
|
|
ucr3 &= ~UCR3_AWAKEN;
|
2018-01-06 00:46:43 +08:00
|
|
|
}
|
2018-03-02 18:07:23 +08:00
|
|
|
imx_uart_writel(sport, ucr3, UCR3);
|
2015-08-12 01:21:22 +08:00
|
|
|
|
2018-01-05 01:58:34 +08:00
|
|
|
if (sport->have_rtscts) {
|
2018-03-02 18:07:23 +08:00
|
|
|
u32 ucr1 = imx_uart_readl(sport, UCR1);
|
2018-01-05 01:58:34 +08:00
|
|
|
if (on)
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr1 |= UCR1_RTSDEN;
|
2018-01-05 01:58:34 +08:00
|
|
|
else
|
2018-03-02 18:07:23 +08:00
|
|
|
ucr1 &= ~UCR1_RTSDEN;
|
|
|
|
imx_uart_writel(sport, ucr1, UCR1);
|
2018-01-05 01:58:34 +08:00
|
|
|
}
|
2015-08-12 01:21:21 +08:00
|
|
|
}
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static int imx_uart_suspend_noirq(struct device *dev)
|
2015-07-30 23:32:36 +08:00
|
|
|
{
|
2018-04-19 22:06:23 +08:00
|
|
|
struct imx_port *sport = dev_get_drvdata(dev);
|
2015-07-30 23:32:36 +08:00
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_save_context(sport);
|
2015-07-30 23:32:36 +08:00
|
|
|
|
|
|
|
clk_disable(sport->clk_ipg);
|
|
|
|
|
2018-09-05 09:24:27 +08:00
|
|
|
pinctrl_pm_select_sleep_state(dev);
|
|
|
|
|
2015-07-30 23:32:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static int imx_uart_resume_noirq(struct device *dev)
|
2015-07-30 23:32:36 +08:00
|
|
|
{
|
2018-04-19 22:06:23 +08:00
|
|
|
struct imx_port *sport = dev_get_drvdata(dev);
|
2015-07-30 23:32:36 +08:00
|
|
|
int ret;
|
|
|
|
|
2018-09-05 09:24:27 +08:00
|
|
|
pinctrl_pm_select_default_state(dev);
|
|
|
|
|
2015-07-30 23:32:36 +08:00
|
|
|
ret = clk_enable(sport->clk_ipg);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_restore_context(sport);
|
2015-07-30 23:32:36 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static int imx_uart_suspend(struct device *dev)
|
2015-07-30 23:32:36 +08:00
|
|
|
{
|
2018-04-19 22:06:23 +08:00
|
|
|
struct imx_port *sport = dev_get_drvdata(dev);
|
2018-01-06 00:46:43 +08:00
|
|
|
int ret;
|
2015-07-30 23:32:36 +08:00
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
uart_suspend_port(&imx_uart_uart_driver, &sport->port);
|
2017-08-14 22:27:49 +08:00
|
|
|
disable_irq(sport->port.irq);
|
2015-07-30 23:32:36 +08:00
|
|
|
|
2018-01-06 00:46:43 +08:00
|
|
|
ret = clk_prepare_enable(sport->clk_ipg);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
/* enable wakeup from i.MX UART */
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_enable_wakeup(sport, true);
|
2018-01-06 00:46:43 +08:00
|
|
|
|
|
|
|
return 0;
|
2015-07-30 23:32:36 +08:00
|
|
|
}
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static int imx_uart_resume(struct device *dev)
|
2015-07-30 23:32:36 +08:00
|
|
|
{
|
2018-04-19 22:06:23 +08:00
|
|
|
struct imx_port *sport = dev_get_drvdata(dev);
|
2015-07-30 23:32:36 +08:00
|
|
|
|
|
|
|
/* disable wakeup from i.MX UART */
|
2018-03-02 18:07:30 +08:00
|
|
|
imx_uart_enable_wakeup(sport, false);
|
2015-07-30 23:32:36 +08:00
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
uart_resume_port(&imx_uart_uart_driver, &sport->port);
|
2017-08-14 22:27:49 +08:00
|
|
|
enable_irq(sport->port.irq);
|
2015-07-30 23:32:36 +08:00
|
|
|
|
2018-01-06 00:46:43 +08:00
|
|
|
clk_disable_unprepare(sport->clk_ipg);
|
2016-01-05 23:53:31 +08:00
|
|
|
|
2015-07-30 23:32:36 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static int imx_uart_freeze(struct device *dev)
|
2017-11-01 20:51:41 +08:00
|
|
|
{
|
2018-04-19 22:06:23 +08:00
|
|
|
struct imx_port *sport = dev_get_drvdata(dev);
|
2017-11-01 20:51:41 +08:00
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
uart_suspend_port(&imx_uart_uart_driver, &sport->port);
|
2017-11-01 20:51:41 +08:00
|
|
|
|
2018-01-06 00:46:43 +08:00
|
|
|
return clk_prepare_enable(sport->clk_ipg);
|
2017-11-01 20:51:41 +08:00
|
|
|
}
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static int imx_uart_thaw(struct device *dev)
|
2017-11-01 20:51:41 +08:00
|
|
|
{
|
2018-04-19 22:06:23 +08:00
|
|
|
struct imx_port *sport = dev_get_drvdata(dev);
|
2017-11-01 20:51:41 +08:00
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
uart_resume_port(&imx_uart_uart_driver, &sport->port);
|
2017-11-01 20:51:41 +08:00
|
|
|
|
2018-01-06 00:46:43 +08:00
|
|
|
clk_disable_unprepare(sport->clk_ipg);
|
2017-11-01 20:51:41 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static const struct dev_pm_ops imx_uart_pm_ops = {
|
|
|
|
.suspend_noirq = imx_uart_suspend_noirq,
|
|
|
|
.resume_noirq = imx_uart_resume_noirq,
|
|
|
|
.freeze_noirq = imx_uart_suspend_noirq,
|
|
|
|
.restore_noirq = imx_uart_resume_noirq,
|
|
|
|
.suspend = imx_uart_suspend,
|
|
|
|
.resume = imx_uart_resume,
|
|
|
|
.freeze = imx_uart_freeze,
|
|
|
|
.thaw = imx_uart_thaw,
|
|
|
|
.restore = imx_uart_thaw,
|
2015-07-30 23:32:36 +08:00
|
|
|
};
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static struct platform_driver imx_uart_platform_driver = {
|
|
|
|
.probe = imx_uart_probe,
|
|
|
|
.remove = imx_uart_remove,
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
.id_table = imx_uart_devtype,
|
|
|
|
.driver = {
|
|
|
|
.name = "imx-uart",
|
2011-06-25 02:04:34 +08:00
|
|
|
.of_match_table = imx_uart_dt_ids,
|
2018-03-02 18:07:30 +08:00
|
|
|
.pm = &imx_uart_pm_ops,
|
2005-11-10 06:32:44 +08:00
|
|
|
},
|
2005-04-17 06:20:36 +08:00
|
|
|
};
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static int __init imx_uart_init(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-03-02 18:07:30 +08:00
|
|
|
int ret = uart_register_driver(&imx_uart_uart_driver);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
ret = platform_driver_register(&imx_uart_platform_driver);
|
2005-04-17 06:20:36 +08:00
|
|
|
if (ret != 0)
|
2018-03-02 18:07:30 +08:00
|
|
|
uart_unregister_driver(&imx_uart_uart_driver);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
2011-11-22 21:22:55 +08:00
|
|
|
return ret;
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
static void __exit imx_uart_exit(void)
|
2005-04-17 06:20:36 +08:00
|
|
|
{
|
2018-03-02 18:07:30 +08:00
|
|
|
platform_driver_unregister(&imx_uart_platform_driver);
|
|
|
|
uart_unregister_driver(&imx_uart_uart_driver);
|
2005-04-17 06:20:36 +08:00
|
|
|
}
|
|
|
|
|
2018-03-02 18:07:30 +08:00
|
|
|
module_init(imx_uart_init);
|
|
|
|
module_exit(imx_uart_exit);
|
2005-04-17 06:20:36 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Sascha Hauer");
|
|
|
|
MODULE_DESCRIPTION("IMX generic serial port driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
2008-04-16 05:34:35 +08:00
|
|
|
MODULE_ALIAS("platform:imx-uart");
|