Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2648875rwd; Fri, 16 Jun 2023 06:34:11 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ77L8rxsdQ06G+16Ujm8glrLfAaWFXer3mgQsCIyEWbZImnuorI7rdDovu0MELn+sbKgMsN X-Received: by 2002:a05:6358:6158:b0:12c:9964:2394 with SMTP id 24-20020a056358615800b0012c99642394mr1403286rwt.7.1686922451267; Fri, 16 Jun 2023 06:34:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686922451; cv=none; d=google.com; s=arc-20160816; b=0Z6B+YPyaPrl/LvWo2lUwHXJ6Qkyah3ZU9FxJgZwCzzmfdG3j8i+mCHM13UUD1OcGf jmKHBodPwPvCOtLxOeNioNUi5Lc75fLcZQsN2UoVOgrSCpCt9x4VxWeJHJm3tDzGY1yv zedWkwxTnZm3bGdHGPxsW41b5ribNXUOe9A/bBxxza0Qp0Oe53ZQ0AxOBGLWKCEUiMUg kMESHXmKxJ9Di5yZiNP2gFZoaQB4iXs2kFExvMpWq7nC5IrAsxTQ8PxUAm8GZPmyS+oS hAgqZQHm3ovGQiqJ71GFHZtebwQySYLrP0U+6RAgaldlPJbCmPOmt5AlFDZ9aVotQcG5 oIPg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=t4ptAZa1ORQwPkXjGwjPtDIEOj8dbfTGgvFJByJNXPQ=; b=EJeFneCjoNUX0Jc1pwuZylHAguq75n6+JK0QtmC5KgkEuSe5QuDjb5JeH3wfvzcPji IxcOFL6NlM+CvUxBlTypycBPfaHHndSypjxalJXeTFvPplmRdM6uYcWoo2KhLi0Z4biD 14/4dqRx+n+QRuQNX6A/vcgZqt/143s0AtB/4GjwjDQ7c4IPJ0+cBu3qVlngwxRzbYpH VlpVfwp0KRU8AvA2EOJMmxYkOelGmLObpy+wdOdOQAy48eI92NdzA+0mNSsQapTxyLJi Ar6zO0vUXQb1tC/aoBjrC2Kh3nNSN9n6AWE5AohfJ3vIYjQrsagEwOaagaZmrWbp/6Mn mhjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=leVTWwra; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 126-20020a630084000000b005533cf1fdbfsi1082832pga.629.2023.06.16.06.33.59; Fri, 16 Jun 2023 06:34:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=leVTWwra; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241277AbjFPMki (ORCPT + 99 others); Fri, 16 Jun 2023 08:40:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231286AbjFPMkh (ORCPT ); Fri, 16 Jun 2023 08:40:37 -0400 Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 39E25268A; Fri, 16 Jun 2023 05:40:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1686919236; x=1718455236; h=date:from:to:cc:subject:in-reply-to:message-id: references:mime-version; bh=rr9Wv//YevBMNTQkmKpej7PgJmFxPrLjzfxfxWBHxKY=; b=leVTWwraRfup8gixHvAZ3eOnQd786B1G0WtC+q5tLKRovrg6yWwmyPxl 8XsLI0mHNDrPH3NoBFxZXRfInruJCyFgZ2n9nI1ue3PkBulx9gqKZjptE b6ef8HSbmhNPpmOeFBsjilZE9+ObRkZosG1pqilf93ouCG69nFe/NkaqO 5JMpvVNGxVnSQQkfolMe9NJKmpamca0NwcAEHsZXqwG1QAIt4XvDwT+du YY6AkoYKOAbqcmWV+L/sMcYO1exNPQRqNW2ajH/yPjhl3ezoEEUjLVnb+ aVEM71Ojmhh33/LDLC3j/N9rrKIYOAFPytxnzqni/y6/9LSh6gfIozh5j A==; X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="425140073" X-IronPort-AV: E=Sophos;i="6.00,247,1681196400"; d="scan'208";a="425140073" Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2023 05:40:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="716005263" X-IronPort-AV: E=Sophos;i="6.00,247,1681196400"; d="scan'208";a="716005263" Received: from ijarvine-mobl2.ger.corp.intel.com ([10.251.211.240]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 16 Jun 2023 05:40:32 -0700 Date: Fri, 16 Jun 2023 15:40:29 +0300 (EEST) From: =?ISO-8859-15?Q?Ilpo_J=E4rvinen?= To: Martin Fuzzey cc: linux-serial@vger.kernel.org, Greg Kroah-Hartman , Shawn Guo , Fabio Estevam , Marek Vasut , linux-kernel@vger.kernel.org Subject: Re: [PATCH] tty: serial: imx: fix rs485 rx after tx In-Reply-To: <20230616104838.2729694-1-martin.fuzzey@flowbird.group> Message-ID: References: <20230616104838.2729694-1-martin.fuzzey@flowbird.group> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="8323329-799842524-1686919234=:3967" X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323329-799842524-1686919234=:3967 Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 8BIT On Fri, 16 Jun 2023, Martin Fuzzey wrote: > Since commit 79d0224f6bf2 ("tty: serial: imx: Handle RS485 DE signal > active high") RS485 reception no longer works after a transmission. > > The following scenario shows the problem: > 1) Open a port in RS485 mode > 2) Receive data from remote (OK) > 3) Transmit data to remote (OK) > 4) Receive data from remote (Nothing received) > > In RS485 mode, imx_uart_start_tx() calls imx_uart_stop_rx() and, when the > transmission is complete, imx_uart_stop_tx() calls imx_uart_start_rx(). > > Since the above commit imx_uart_stop_rx() now sets the loopback bit but > imx_uart_start_rx() does not clear it causing the hardware to remain in > loopback mode and not receive external data. > > Fix this by moving the existing loopback disable code to a helper function > and calling it from imx_uart_start_rx() too. > > Fixes: 79d0224f6bf2 ("tty: serial: imx: Handle RS485 DE signal active high") > Cc: stable@vger.kernel.org > Signed-off-by: Martin Fuzzey > --- > drivers/tty/serial/imx.c | 18 +++++++++++++----- > 1 file changed, 13 insertions(+), 5 deletions(-) > > diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c > index c5e17569c3ad..3fe8ff241522 100644 > --- a/drivers/tty/serial/imx.c > +++ b/drivers/tty/serial/imx.c > @@ -369,6 +369,16 @@ static void imx_uart_soft_reset(struct imx_port *sport) > sport->idle_counter = 0; > } > > +static void imx_uart_disable_loopback_rs485(struct imx_port *sport) > +{ > + unsigned int uts; > + > + /* See SER_RS485_ENABLED/UTS_LOOP comment in imx_uart_probe() */ > + uts = imx_uart_readl(sport, imx_uart_uts_reg(sport)); > + uts &= ~UTS_LOOP; > + imx_uart_writel(sport, uts, imx_uart_uts_reg(sport)); > +} > + > /* called with port.lock taken and irqs off */ > static void imx_uart_start_rx(struct uart_port *port) > { > @@ -390,6 +400,7 @@ static void imx_uart_start_rx(struct uart_port *port) > /* Write UCR2 first as it includes RXEN */ > imx_uart_writel(sport, ucr2, UCR2); > imx_uart_writel(sport, ucr1, UCR1); > + imx_uart_disable_loopback_rs485(sport); > } > > /* called with port.lock taken and irqs off */ > @@ -1422,7 +1433,7 @@ static int imx_uart_startup(struct uart_port *port) > int retval; > unsigned long flags; > int dma_is_inited = 0; > - u32 ucr1, ucr2, ucr3, ucr4, uts; > + u32 ucr1, ucr2, ucr3, ucr4; > > retval = clk_prepare_enable(sport->clk_per); > if (retval) > @@ -1521,10 +1532,7 @@ static int imx_uart_startup(struct uart_port *port) > imx_uart_writel(sport, ucr2, UCR2); > } > > - /* See SER_RS485_ENABLED/UTS_LOOP comment in imx_uart_probe() */ > - uts = imx_uart_readl(sport, imx_uart_uts_reg(sport)); > - uts &= ~UTS_LOOP; > - imx_uart_writel(sport, uts, imx_uart_uts_reg(sport)); > + imx_uart_disable_loopback_rs485(sport); > > spin_unlock_irqrestore(&sport->port.lock, flags); Reviewed-by: Ilpo J?rvinen -- i. --8323329-799842524-1686919234=:3967--