From patchwork Fri Sep 6 02:19:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: LiangCheng Wang X-Patchwork-Id: 13793145 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id B04C0CE7AA6 for ; Fri, 6 Sep 2024 02:20:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=dIW9b0DbiNOfgETQSZVCY5M0dVLOvu9t5blHuaZ3mxw=; b=NC8xkmy2M66LMqoAq4r+bWodFh VWEQ8Q6b9yk8ziu5fBNvABcAs7QepjsLwBszsL6U8vYVq7q6InJYPvqwavbW9wZGdy2PgYWIPVau2 jJIfrP/d4cbKKMGhBxODD5pqGE0NoJYHMj8bj2Fl6bUu/qTGmMx8CBLPjEut9om79rQOMrHr9HsjW n4IxcruFBa3N9j2yVYniO5k6LkhDRHdvObAZE2bwDRuE3zYnUnWTEmVEIHREw6vomviC0GuZmaOi0 qZzSx0wWEP4x6V9j9GfLDhobKsJ+VrJ5jauJzbCiczr2amIwQjP50IdtUw41i2RPgsDQT3t5h48mb 6U0Xe2iQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1smOaF-0000000AMfy-3Hrf; Fri, 06 Sep 2024 02:20:23 +0000 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1smOZH-0000000AMVa-12IU for linux-arm-kernel@lists.infradead.org; Fri, 06 Sep 2024 02:19:24 +0000 Received: by mail-pj1-x102e.google.com with SMTP id 98e67ed59e1d1-2d8fa2ca5b1so1117918a91.3 for ; Thu, 05 Sep 2024 19:19:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725589162; x=1726193962; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=dIW9b0DbiNOfgETQSZVCY5M0dVLOvu9t5blHuaZ3mxw=; b=d66bgVW8nNEJhq4CeKeC4ikeNfaQaqSJoA/bJI4kbpdIhnzpeeVTd6rkPiWg4NJeqL YNyIVGhfcesdbGinetQbJoyBNKgNEE28Spu1v+cCvGuDXfTOeJEcWxLlJRYZMYWGlu84 ZlQD9yPuAQZsom/IbWms2xNYtGQIaqQgo4B+fzRI58huTIN5R0MQXfPPYGBu/bctdGRV M+1Cn2psmYF0gJmxaV6YazY1zZXAqVtrgimRJMB7ok1CuNYoCGF/3YaZSKyF691dDyCe iyohsGRtOYkl803b7sgYkYI3BTG/2eDHNbDlv4Lyo3tQTeArp4hK7c+qsOqsW9BCSAyz EhPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725589162; x=1726193962; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=dIW9b0DbiNOfgETQSZVCY5M0dVLOvu9t5blHuaZ3mxw=; b=UebY/QsbUi3uYQyJXRFC31l6/1oxVajqrfbNelCF/IM0YAOuseufVkv7OCiNX5qpwn MAyDsH23B7q2B2RtPiCL3Ej4F+79lPm2Fp/BTFS4Ez21V8EXF8br8PGw34oo+y1WUxco Tl9QPj+xehAHLI1rEJm+5vV16jT1fGWHmVV+ozzV93YcOQylpwxwoTH4ks5rRjWanaiU JmrjgG4N6kXzGGGj4JobdlILPG4nLBg9YMcr8r2JR5Zg5nSiY2SBzjz7Y1u4yBBpHoAc lEtmxtG+mAM7+97YvHSds3HUCSNvtLXKxVCepfIqFMa9CjM0vj//7rFPzkrZrRvOtixA 4Ogw== X-Forwarded-Encrypted: i=1; AJvYcCUza48Ww2u9s2V+9iVtdmSwQp2fhCdYaktxRiIP8OCoZvmvaWeLTAjCVCXWIRx6RqQqocA+RAsoGWDe2IUzPj/U@lists.infradead.org X-Gm-Message-State: AOJu0YzvQfLua5EH817hP3J6VjJJCxSb01/ONG1U1EDRQZQFGTk8qi1e cyhg4ETqIGG14wft26tKkqCN5VoglqfSBrFDHwyh8VJ6GVTXb2y7 X-Google-Smtp-Source: AGHT+IF11BObZmFZ8H/MLIMIJdM/xn6Tn01KO3MpE/ePD6LblTS2fnwlypbI8IaypHv+HDhos0FGkg== X-Received: by 2002:a17:90b:394d:b0:2d8:8920:771c with SMTP id 98e67ed59e1d1-2dad50c2cc2mr1490538a91.32.1725589161700; Thu, 05 Sep 2024 19:19:21 -0700 (PDT) Received: from lcwang-Precision-3630-Tower.. (211-23-39-77.hinet-ip.hinet.net. [211.23.39.77]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2dadc0e3141sm265184a91.54.2024.09.05.19.19.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Sep 2024 19:19:21 -0700 (PDT) From: LiangCheng Wang To: shawnguo@kernel.org Cc: s.hauer@pengutronix.de, gregkh@linuxfoundation.org, jirislaby@kernel.org, kernel@pengutronix.de, festevam@gmail.com, u.kleine-koenig@pengutronix.de, cniedermaier@dh-electronics.com, l.sanfilippo@kunbus.com, linux@rasmusvillemoes.dk, stefan.eichenberger@toradex.com, tglx@linutronix.de, rickaran@axis.com, zaq14760@gmail.com, linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org Subject: [PATCH 1/1] drivers: tty: imx: fix flags of rs485 not work properly Date: Fri, 6 Sep 2024 10:19:05 +0800 Message-Id: <20240906021905.197891-1-zaq14760@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240905_191923_313450_663B7BAD X-CRM114-Status: GOOD ( 19.48 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The rs485.flags are lost in functions such as imx_uart_stop_tx(), causing the function of RS485 to be invalid when using the serial port as the RS485 port. Use a variable to store the state to avoid this issue. Signed-off-by: LiangCheng Wang --- drivers/tty/serial/imx.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index 67d4a72eda77..346bbd21536b 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -209,7 +209,7 @@ struct imx_port { const struct imx_uart_data *devdata; struct mctrl_gpios *gpios; - + int flags; /* counter to stop 0xff flood */ int idle_counter; @@ -434,7 +434,7 @@ static void imx_uart_stop_tx(struct uart_port *port) imx_uart_writel(sport, ucr4, UCR4); /* in rs485 mode disable transmitter */ - if (port->rs485.flags & SER_RS485_ENABLED) { + if (sport->flags & SER_RS485_ENABLED) { if (sport->tx_state == SEND) { sport->tx_state = WAIT_AFTER_SEND; @@ -454,7 +454,7 @@ static void imx_uart_stop_tx(struct uart_port *port) hrtimer_try_to_cancel(&sport->trigger_start_tx); ucr2 = imx_uart_readl(sport, UCR2); - if (port->rs485.flags & SER_RS485_RTS_AFTER_SEND) + if (sport->flags & SER_RS485_RTS_AFTER_SEND) imx_uart_rts_active(sport, &ucr2); else imx_uart_rts_inactive(sport, &ucr2); @@ -490,8 +490,8 @@ static void imx_uart_stop_rx_with_loopback_ctrl(struct uart_port *port, bool loo imx_uart_writel(sport, ucr4, UCR4); /* See SER_RS485_ENABLED/UTS_LOOP comment in imx_uart_probe() */ - if (port->rs485.flags & SER_RS485_ENABLED && - port->rs485.flags & SER_RS485_RTS_ON_SEND && + if (sport->flags & SER_RS485_ENABLED && + sport->flags & SER_RS485_RTS_ON_SEND && sport->have_rtscts && !sport->have_rtsgpio && loopback) { uts = imx_uart_readl(sport, imx_uart_uts_reg(sport)); uts |= UTS_LOOP; @@ -604,7 +604,7 @@ static void imx_uart_dma_tx_callback(void *data) if (!kfifo_is_empty(&tport->xmit_fifo) && !uart_tx_stopped(&sport->port)) imx_uart_dma_tx(sport); - else if (sport->port.rs485.flags & SER_RS485_ENABLED) { + else if (sport->flags & SER_RS485_ENABLED) { u32 ucr4 = imx_uart_readl(sport, UCR4); ucr4 |= UCR4_TCEN; imx_uart_writel(sport, ucr4, UCR4); @@ -681,10 +681,10 @@ static void imx_uart_start_tx(struct uart_port *port) * imx_uart_stop_tx(), but tx_state is still SEND. */ - if (port->rs485.flags & SER_RS485_ENABLED) { + if (sport->flags & SER_RS485_ENABLED) { if (sport->tx_state == OFF) { u32 ucr2 = imx_uart_readl(sport, UCR2); - if (port->rs485.flags & SER_RS485_RTS_ON_SEND) + if (sport->flags & SER_RS485_RTS_ON_SEND) imx_uart_rts_active(sport, &ucr2); else imx_uart_rts_inactive(sport, &ucr2); @@ -695,7 +695,7 @@ static void imx_uart_start_tx(struct uart_port *port) * with loopback enabled because that will make our * transmitted data being just looped to RX. */ - if (!(port->rs485.flags & SER_RS485_RX_DURING_TX) && + if (!(sport->flags & SER_RS485_RX_DURING_TX) && !port->rs485_rx_during_tx_gpio) imx_uart_stop_rx_with_loopback_ctrl(port, false); @@ -1078,7 +1078,7 @@ static void imx_uart_set_mctrl(struct uart_port *port, unsigned int mctrl) struct imx_port *sport = to_imx_port(port); u32 ucr3, uts; - if (!(port->rs485.flags & SER_RS485_ENABLED)) { + if (!(sport->flags & SER_RS485_ENABLED)) { u32 ucr2; /* @@ -1604,8 +1604,8 @@ static void imx_uart_shutdown(struct uart_port *port) ucr1 &= ~(UCR1_TRDYEN | UCR1_RRDYEN | UCR1_RTSDEN | UCR1_RXDMAEN | UCR1_ATDMAEN | UCR1_SNDBRK); /* See SER_RS485_ENABLED/UTS_LOOP comment in imx_uart_probe() */ - if (port->rs485.flags & SER_RS485_ENABLED && - port->rs485.flags & SER_RS485_RTS_ON_SEND && + if (sport->flags & SER_RS485_ENABLED && + sport->flags & SER_RS485_RTS_ON_SEND && sport->have_rtscts && !sport->have_rtsgpio) { uts = imx_uart_readl(sport, imx_uart_uts_reg(sport)); uts |= UTS_LOOP; @@ -1643,7 +1643,7 @@ static void imx_uart_shutdown(struct uart_port *port) * those cases, we have to wait for the hrtimer to fire and * complete the transition to OFF. */ - loops = port->rs485.flags & SER_RS485_ENABLED ? + loops = sport->flags & SER_RS485_ENABLED ? port->rs485.delay_rts_after_send : 0; while (sport->tx_state != OFF && loops--) { uart_port_unlock_irqrestore(&sport->port, flags); @@ -1659,9 +1659,9 @@ static void imx_uart_shutdown(struct uart_port *port) * signal is inactive in order not to block other * devices. */ - if (port->rs485.flags & SER_RS485_ENABLED) { + if (sport->flags & SER_RS485_ENABLED) { ucr2 = imx_uart_readl(sport, UCR2); - if (port->rs485.flags & SER_RS485_RTS_AFTER_SEND) + if (sport->flags & SER_RS485_RTS_AFTER_SEND) imx_uart_rts_active(sport, &ucr2); else imx_uart_rts_inactive(sport, &ucr2); @@ -1749,13 +1749,13 @@ imx_uart_set_termios(struct uart_port *port, struct ktermios *termios, if (!sport->have_rtscts) termios->c_cflag &= ~CRTSCTS; - if (port->rs485.flags & SER_RS485_ENABLED) { + if (sport->flags & SER_RS485_ENABLED) { /* * RTS is mandatory for rs485 operation, so keep * it under manual control and keep transmitter * disabled. */ - if (port->rs485.flags & SER_RS485_RTS_AFTER_SEND) + if (sport->flags & SER_RS485_RTS_AFTER_SEND) imx_uart_rts_active(sport, &ucr2); else imx_uart_rts_inactive(sport, &ucr2); @@ -2394,6 +2394,7 @@ static int imx_uart_probe(struct platform_device *pdev) } ret = uart_get_rs485_mode(&sport->port); + sport->flags = sport->port.rs485.flags; if (ret) goto err_clk;