From: Sherry Sun <sherry.sun@nxp.com>
To: Rasmus Villemoes <rasmus.villemoes@prevas.dk>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Jiri Slaby <jirislaby@kernel.org>,
Shawn Guo <shawnguo@kernel.org>,
Sascha Hauer <s.hauer@pengutronix.de>,
Pengutronix Kernel Team <kernel@pengutronix.de>,
Fabio Estevam <festevam@gmail.com>,
dl-linux-imx <linux-imx@nxp.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-serial@vger.kernel.org" <linux-serial@vger.kernel.org>,
"linux-arm-kernel@lists.infradead.org"
<linux-arm-kernel@lists.infradead.org>
Subject: RE: [PATCH] serial: imx: also enable Transmit Complete interrupt in rs232 mode
Date: Tue, 21 Nov 2023 06:37:27 +0000 [thread overview]
Message-ID: <AS8PR04MB8404D066C247F5B2979CBD1F92BBA@AS8PR04MB8404.eurprd04.prod.outlook.com> (raw)
In-Reply-To: <20231120132256.136625-1-rasmus.villemoes@prevas.dk>
> -----Original Message-----
> From: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
> Sent: 2023年11月20日 21:23
> To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>; Jiri Slaby
> <jirislaby@kernel.org>; Shawn Guo <shawnguo@kernel.org>; Sascha Hauer
> <s.hauer@pengutronix.de>; Pengutronix Kernel Team
> <kernel@pengutronix.de>; Fabio Estevam <festevam@gmail.com>; dl-linux-
> imx <linux-imx@nxp.com>
> Cc: Rasmus Villemoes <rasmus.villemoes@prevas.dk>; linux-
> kernel@vger.kernel.org; linux-serial@vger.kernel.org; linux-arm-
> kernel@lists.infradead.org
> Subject: [PATCH] serial: imx: also enable Transmit Complete interrupt in
> rs232 mode
>
> Currently, if one switches to rs232 mode, writes something to the device, and
> then switches to rs485 mode, the imx_port's ->tx_state is left as SEND. This
> then prevents a subsequent write in rs485 mode from properly asserting the
> rts pin (i.e. enabling the transceiver), because imx_uart_start_rx() does not
> enter the "if (sport->tx_state == OFF)" branch. Hence nothing is actually
> transmitted.
>
> The problem is that in rs232 mode, ->tx_state never gets set to OFF, due to
>
> usr2 = imx_uart_readl(sport, USR2);
> if (!(usr2 & USR2_TXDC)) {
> /* The shifter is still busy, so retry once TC triggers */
> return;
> }
>
> in imx_uart_stop_tx(), and TC never triggers because the Transmit Complete
> interrupt is not enabled for rs232.
Hi Rasmus,
I am afraid this is not right, USR2_TXDC is just a flag, it is not affected by whether UCR4_TCEN is set or not, UCR4_TCEN only determines if USR2_TXDC flag can generate a interrupt or not.
I tried on imx8mp-evk board, for rs232, sport->tx_state can get set to OFF even we don’t set UCR4_TCEN.
Best Regards
Sherry
>
> Signed-off-by: Rasmus Villemoes <rasmus.villemoes@prevas.dk>
> ---
> I'm not sure this is the best fix.
>
> At first I considered doing something much more targeted, but definitely also
> more hacky: In imx_uart_rs485_config(), if switching on rs485 mode, simply
> add "sport->tx_state = OFF;".
>
> If someone has a better suggestion, I'm all ears.
>
> drivers/tty/serial/imx.c | 24 +++++++++---------------
> 1 file changed, 9 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index
> 7341d060f85c..ffee157e13cd 100644
> --- a/drivers/tty/serial/imx.c
> +++ b/drivers/tty/serial/imx.c
> @@ -708,25 +708,19 @@ static void imx_uart_start_tx(struct uart_port
> *port)
> || sport->tx_state == WAIT_AFTER_RTS) {
>
> hrtimer_try_to_cancel(&sport->trigger_stop_tx);
> -
> - /*
> - * 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;
> }
> - } else {
> - sport->tx_state = SEND;
> }
>
> + sport->tx_state = SEND;
> +
> + /*
> + * 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);
> ucr1 = imx_uart_readl(sport, UCR1);
> imx_uart_writel(sport, ucr1 | UCR1_TRDYEN, UCR1);
> }
> --
> 2.40.1.1.g1c60b9335d
next prev parent reply other threads:[~2023-11-21 6:37 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-20 13:22 Rasmus Villemoes
2023-11-21 6:37 ` Sherry Sun [this message]
2023-11-21 7:26 ` Rasmus Villemoes
2023-11-21 20:49 ` Eberhard Stoll
2023-11-22 8:03 ` Rasmus Villemoes
2023-11-22 9:31 ` Eberhard Stoll
2023-11-22 13:01 ` Frieder Schrempf
2023-11-22 13:34 ` Rasmus Villemoes
2023-11-21 20:59 ` Eberhard Stoll
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=AS8PR04MB8404D066C247F5B2979CBD1F92BBA@AS8PR04MB8404.eurprd04.prod.outlook.com \
--to=sherry.sun@nxp.com \
--cc=festevam@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=jirislaby@kernel.org \
--cc=kernel@pengutronix.de \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-imx@nxp.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
--cc=rasmus.villemoes@prevas.dk \
--cc=s.hauer@pengutronix.de \
--cc=shawnguo@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®