From patchwork Mon Apr 16 13:01:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Stefan Agner X-Patchwork-Id: 10342955 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 653F56039A for ; Mon, 16 Apr 2018 13:02:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 55726286E1 for ; Mon, 16 Apr 2018 13:02:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 49F12286E3; Mon, 16 Apr 2018 13:02:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1F337286E1 for ; Mon, 16 Apr 2018 13:02:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Message-ID:References:In-Reply-To: Subject:To:From:Date:MIME-Version:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=OW1yw+arEb+BlIpj03dy9MDV1OaxyEAOamNsLfH16G4=; b=gAxza4L1bWZtt0 /0HbOV69s1SSXT76mEzTSZXjrxeZYKkYIyIiUg+15zoCJeGrrDpGlDEyVnHdkpcGJEconxtccLjhH LuTk5arzejAT6uOuxmFR/DTlDfLTlypzsu0jHbpDOHozCuF61xUu54BXFH5N+7I/CIufmstixg7sZ WQ2t6Ru1te8GUf1aAngbgglak6JIf9EwUEoDcwschQZUyBeLhB+Fa2Xx7joMBvV882Iqi8Zo9zeJs 9FjWcOEO1Z5wCeneRzk7yhLQcLNOqYHDeV2IZI5Hlu5WHBGVbIRU08r+EesGdNujaTxjlgU6WkQl2 sirR3+oblPPYwu0t9W7g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f83ln-0005SR-7j; Mon, 16 Apr 2018 13:02:07 +0000 Received: from mail.kmu-office.ch ([2a02:418:6a02::a2]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1f83lh-0005RX-Rr for linux-arm-kernel@lists.infradead.org; Mon, 16 Apr 2018 13:02:04 +0000 Received: from webmail.kmu-office.ch (unknown [IPv6:2a02:418:6a02::a3]) by mail.kmu-office.ch (Postfix) with ESMTPSA id 6DB3D5C0E18; Mon, 16 Apr 2018 15:01:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=agner.ch; s=dkim; t=1523883705; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PtCuPhIO01PxUW+HRMg6q54gdF6NeApzJ/B3Ac62VEo=; b=hp+YmlsBfkipn52EruwXLMZzrsi1/wXqcbYOmsPnB/f7Af8v+13KRwFOCgRXY00Tc0v9oP YPjMafJlL2jw585plW0miFupgN0Fm1Ymv5RfQEC0XQPj/hbz1l0g9S7/YwM7FQnoR00MuS GP3/4vNXtb9O5X+9Ovv6hcy3UkWcYLI= MIME-Version: 1.0 Date: Mon, 16 Apr 2018 15:01:44 +0200 From: Stefan Agner To: =?UTF-8?Q?Uwe_Kleine-K=C3=B6nig?= Subject: Re: serial: imx: half-duplex RS485 operation with RTS active low In-Reply-To: References: <0e88706a05a302201be396d2f03c3e9e@agner.ch> <20180416092257.frbmooduhm4zrhhl@pengutronix.de> Message-ID: <94f7fcf8873f7607087fc3a59a9422a8@agner.ch> X-Sender: stefan@agner.ch User-Agent: Roundcube Webmail/1.3.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180416_060202_201571_F77F692F X-CRM114-Status: GOOD ( 22.19 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: s.hauer@pengutronix.de, baruch@tkos.co.il, linux-arm-kernel@lists.infradead.org, linux-serial@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP On 16.04.2018 12:29, Stefan Agner wrote: > On 16.04.2018 11:22, Uwe Kleine-König wrote: >> Hi Stefan, >> >> On Mon, Apr 16, 2018 at 11:14:32AM +0200, Stefan Agner wrote: >>> Using upstream I noticed that RS-485 does not work in the default >>> configuration for our platforms (Toradex Apalis/Colibri). Closer >> >> This is an i.MX6? >> > > Yes, sorry about that. > > But I think it is i.MX UART specific, I noticed the same behavior on > i.MX 7 too. > >>> debugging shows that it is related to "serial: imx: default to half >>> duplex rs485". >>> >>> We use the i.MX UART in DTE mode and control the RS-485 transceiver >>> using the RTS signal in low-active mode. >>> >>> uart-has-rtscts; >>> fsl,dte-mode; >>> linux,rs485-enabled-at-boot-time; >>> rs485-rts-active-low; >> >> That means you're not using a GPIO for RTS signaling, right? >> > > I use native RTS capability (which is in DTE mode the CTS signal...) > >>> Using this setting leads to the RTS signal not getting asserted (the >>> oscilloscope only shows a very short fluke before the start bit is >>> sent). > > Just FYI, the fluke looks like a proper assert, but it is really only > 50ns wide. > Also tried DCE mode, the same behavior. Two screenshots showing TX/RTS (CTS_B) in different settings: https://imgur.com/a/PbUex The little fluke disappears when disabling RX before setting CTSC: imx_uart_rts_active(sport, &ucr2); @@ -664,9 +667,6 @@ static void imx_uart_start_tx(struct uart_port *port) imx_uart_rts_inactive(sport, &ucr2); imx_uart_writel(sport, ucr2, UCR2); - if (!(port->rs485.flags & SER_RS485_RX_DURING_TX)) - imx_uart_stop_rx(port); - /* * Enable transmitter and shifter empty irq only if DMA is off. * In the DMA case this is done in the tx-callback. It seems that if the RX path is disabled, CTS_B is no longer controllable. It just stays high. That is not a problem in the high active RTS case... However, it breaks low active half-duplex... It seems that this thread is describing this situation: https://community.nxp.com/thread/385047 --- Stefan >>> >>> However, using >>> >>> uart-has-rtscts; >>> fsl,dte-mode; >>> linux,rs485-enabled-at-boot-time; >>> rs485-rts-active-low; >>> rs485-rx-during-tx; >>> >>> Asserts the RTS signal low active just fine... >>> >>> Is this a known problem? Any idea where that could come from? It looks >>> as if the receiver part is actually enabling RTS...? >> >> Which kernel version do you use? My latest rs485 related patches went >> into v4.17-rc1. With that I managed to make rs485 half duplex work on >> several customer boards. > > I used v4.17-rc1. > > I noticed your changes, but I it seems they make no difference, last > week I noticed the same issue in v4.16. > > Do those customer boards use DTE mode? > > -- > Stefan > >> >>> Also, isn't enabling RX even in half-duplex mode quite common in order >>> to detect collisions? >> >> I don't know. >> > > Probably also depends on the exact use case and the transceiver > configuration. > > -- > Stefan --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -657,6 +657,9 @@ static void imx_uart_start_tx(struct uart_port *port) if (port->rs485.flags & SER_RS485_ENABLED) { u32 ucr2; + if (!(port->rs485.flags & SER_RS485_RX_DURING_TX)) + imx_uart_stop_rx(port); + ucr2 = imx_uart_readl(sport, UCR2); if (port->rs485.flags & SER_RS485_RTS_ON_SEND)