From patchwork Fri Dec 2 10:41:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christoph Niedermaier X-Patchwork-Id: 13062612 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 73E3BC4167B for ; Fri, 2 Dec 2022 10:45:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:CC :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=Luu6a8o79fdF8UxpaLvrwqWQ/KV7fIL3KutzHZdcarU=; b=C9cSHTu0A3ZnlS /8IRFk61fsinTTJq0KitxoWgCcIEeW9twD2h5Gv+N8A4lmYXalCjDNH/77W+COckAun1ovFGvJ0qX kUAPmly8/QJeTH8QXg/63WD+kTF7eMrJysxydeyjLHNTHC3s999UAFZbrZaZv38uL2Vz2p2YFIK// 7UhZo+awAey1gTCiKPBrqUkZ0kJiZbD2rf3HKvbmrFj8zkrbVJn7Gv3YjkRSAxnVWP5UOpPYEoOvx V+dbNVMPRagb9c7DB4jmJ/KrVKSUVn7WzrQtVbMKFq8foJh/KOKRUU/tADsbBV6V9VA4WVJEHe/Ck sbl9HE/2y80P9bA9ZEaw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p13WQ-00FfrR-1I; Fri, 02 Dec 2022 10:43:58 +0000 Received: from mx2.securetransport.de ([2a03:4000:13:6c7::1]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p13Vs-00FfW7-KT for linux-arm-kernel@lists.infradead.org; Fri, 02 Dec 2022 10:43:26 +0000 Received: from mail.dh-electronics.com (unknown [77.24.89.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx2.securetransport.de (Postfix) with ESMTPSA id A1B3D5E99E; Fri, 2 Dec 2022 11:42:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dh-electronics.com; s=dhelectronicscom; t=1669977770; bh=jqDVLZ1Ing9hJRDRxYi7bntuyllmW9Hd+BSl+I1NndE=; h=From:To:CC:Subject:Date:From; b=HU/pXZLZmRcF1uN0PFqfGG/og/EYzT8EzGJ7udmm9gEpOOkX9JCFzVSANYXIlfuMI tE5SmtRUfP/v6+Bo4GbkqEQy3Jdcrsftl2L0ti4lb+ozTgZiOyoU748gTKrc3/WkS5 c3DyGZkTyI3BuyAO78hB00QVcMV0cplew+2Ar/OSF89/zBxwVVYSqIWPl3WXXS4ZZd Buc65mtcnhfd5ppZd8xKIUXBqITPq02n/mRxeW3p+8zHWzCNJ3Tft/V9Ggru1dNMe2 00mBpEK48B3VsIy9V6vAbz/40sE1t3WpK5bN/0RbJT8+yDg5g/9UNFL2i0LOZ1PLJL nUDC4J9yaw8Vw== Received: from DHPWEX01.DH-ELECTRONICS.ORG (10.64.2.30) by DHPWEX01.DH-ELECTRONICS.ORG (10.64.2.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.20; Fri, 2 Dec 2022 11:42:37 +0100 Received: from localhost.localdomain (172.16.51.2) by DHPWEX01.DH-ELECTRONICS.ORG (10.64.2.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.20 via Frontend Transport; Fri, 2 Dec 2022 11:42:36 +0100 From: Christoph Niedermaier To: , CC: , , , Christoph Niedermaier , Greg Kroah-Hartman , Rob Herring , "Alexander Dahl" , , Subject: [PATCH V4 1/4] dt-bindings: serial: rs485: Add GPIO controlling RX enable during TX Date: Fri, 2 Dec 2022 11:41:24 +0100 Message-ID: <20221202104127.122761-1-cniedermaier@dh-electronics.com> X-Mailer: git-send-email 2.11.0 X-klartext: yes MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221202_024324_966096_D300FD74 X-CRM114-Status: GOOD ( 16.75 ) 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 Add a binding for a generic definition of an output GPIO that sets the state of rs485-rx-during-tx. The idea is that the hardware already controls the option receiving during sending before it gets to the signal receiving hardware. The standard RS485 is a half-duplex bus that in most cases is driven by an UART controller. The advantage of using this GPIO is that it is independent of the capabilities of the UART core and the UART driver. On the hardware side the interface to the bus is controlled by a transceiver, that has a pin called RE (RX Enable) or similar, which connects the bus to the RX signal of the UART controller. The GPIO can switch between two states to control the RE pin via an electrical circuit: - Active: The RE pin is always active. The UART RX see everything on the bus and therefore also what happens with the TX signal on the bus. - Inactive: The RE pin is always active, but during sending on the bus the pin RE is inactive. So basically the receiving during sending is suppressed. A possible circuit diagram could look like this: ┌──────────────────┐ │ RS485 │ TX ───────────────┤D │ │ Transceiver │ RTS ────┬──────────┤DE │ │ │ │ │ ┌─────┐ │ │ └─┤& │ │ │ │ ├──┤!RE │ !rx_during_tx_gpio ──────┤ │ │ │ └─────┘ │ │ │ │ RX ───────────────┤R │ │ │ └──────────────────┘ Here the RTS pin of the UART core is used to control TX via the transceiver pin DE (Drive Enable). RE and rx_during_tx_gpio are active low. Signed-off-by: Christoph Niedermaier Reviewed-by: Rob Herring --- Cc: Greg Kroah-Hartman Cc: Rob Herring Cc: Krzysztof Kozlowski Cc: Alexander Dahl Cc: Marek Vasut Cc: kernel@dh-electronics.com Cc: devicetree@vger.kernel.org To: linux-serial@vger.kernel.org To: linux-arm-kernel@lists.infradead.org --- V2: - Rework of the commit message - Rework GPIO property comment V3: - Rework the binding description - Rework message title - Rework of the commit message V4: - Add Reviewed-by tag --- Documentation/devicetree/bindings/serial/rs485.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/devicetree/bindings/serial/rs485.yaml b/Documentation/devicetree/bindings/serial/rs485.yaml index 90a1bab40f05..a973ab7d7e46 100644 --- a/Documentation/devicetree/bindings/serial/rs485.yaml +++ b/Documentation/devicetree/bindings/serial/rs485.yaml @@ -51,6 +51,12 @@ properties: description: GPIO pin to enable RS485 bus termination. maxItems: 1 + rs485-rx-during-tx-gpios: + description: Output GPIO pin that sets the state of rs485-rx-during-tx. This + signal can be used to control the RX part of an RS485 transceiver. Thereby + the active state enables RX during TX. + maxItems: 1 + additionalProperties: true ... From patchwork Fri Dec 2 10:41:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Niedermaier X-Patchwork-Id: 13062630 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 798BCC4321E for ; Fri, 2 Dec 2022 10:59:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=8jlV9ssLiNdBG8k3puxW26ekdxrlQKCf/scZCXUXLu8=; b=1/DZd1pKgluj6R am62PnGjlkZ0fIZQwX4sOokd3Y6ZCjhJMAHsMUgBdc7NeqeO/K3bG3kk+q7QSAVYoi3hI4oM9uFVG m6p/ZApmZ28Ms4ThFWGIjJPt6ek9Y/DXOxsROkRgxFINSL0CiQrYHfGJvIO3UQHA5A89mtDEXxID0 M02KAauUCIK2c+fN19rEKsVXRCBPAwUFWoSv2qcT5lFBKrLogV9rq9Dq5t/WBWcSZvcUIMsMABoXl ah8vJrpwVgwnOy9NSxY+9COs8Lkoic6cwiJnq5O3p0otuMhjyK+X2EsW8J5lrFeFuDOzPKH15ikYC qc55RfUOH4X86gfxtSfw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p13kK-00FnTM-Vd; Fri, 02 Dec 2022 10:58:21 +0000 Received: from mx2.securetransport.de ([2a03:4000:13:6c7::1]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p13kH-00FnQs-AM for linux-arm-kernel@lists.infradead.org; Fri, 02 Dec 2022 10:58:19 +0000 Received: from mail.dh-electronics.com (unknown [77.24.89.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx2.securetransport.de (Postfix) with ESMTPSA id 2B0B95F004; Fri, 2 Dec 2022 11:57:52 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dh-electronics.com; s=dhelectronicscom; t=1669978672; bh=GH9X3a34TqpRMNX4ntlT2tR1dTO6zJC2YpW02wfXLL8=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=eZFgYARO+/vN1THalRyjTyPjg2+sSNMLoUI477RBGeOUR/0fGnr3ysZsABAFp1AnU gr4ctbgn+ZsSKOD6GYuJKil6RTfvRyeaqgycJpPm+3Ov+per2Qjcb0FpANvBkgMWPy zIC4bnq2KyZ3y6DqG+cBTe/R4Op5PHiY5IkcPVQ14dxvHudjPsQGVCHXe3maLurFi0 bj+HAdQHxRXNLcoYdvw5u+EEqOqDVrk5hJCNbWdLFtCoW8xswll69dUiVm3LsJgZUz sHr2a5Kx2lK9haxNtkDHX7ymtjCjH05ZzM9icpzCBGJA6UsuO/X2D1ixL5BWfMiPSw kaaGggaplOS7A== Received: from DHPWEX01.DH-ELECTRONICS.ORG (10.64.2.30) by DHPWEX01.DH-ELECTRONICS.ORG (10.64.2.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.20; Fri, 2 Dec 2022 11:42:37 +0100 Received: from localhost.localdomain (172.16.51.2) by DHPWEX01.DH-ELECTRONICS.ORG (10.64.2.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.20 via Frontend Transport; Fri, 2 Dec 2022 11:42:37 +0100 From: Christoph Niedermaier To: , CC: , , , Christoph Niedermaier , Greg Kroah-Hartman , Alexander Dahl , , Linux Team Subject: [PATCH V4 2/4] serial: core: Add option to output RS485 RX_DURING_TX state via GPIO Date: Fri, 2 Dec 2022 11:41:25 +0100 Message-ID: <20221202104127.122761-2-cniedermaier@dh-electronics.com> X-Mailer: git-send-email 2.11.0 X-klartext: yes In-Reply-To: <20221202104127.122761-1-cniedermaier@dh-electronics.com> References: <20221202104127.122761-1-cniedermaier@dh-electronics.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221202_025817_632528_657BC619 X-CRM114-Status: GOOD ( 17.77 ) 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 This patch provides a generic GPIO variable for outputting the state of RS485 RX_DURING_TX. The GPIO is defined by the devicetree property "rs485-rx-during-tx-gpios". To use it in a low level serial driver, the evaluation of this variable must be implemented there accordingly. Signed-off-by: Christoph Niedermaier --- Cc: Greg Kroah-Hartman Cc: Jiri Slaby Cc: Alexander Dahl Cc: Marek Vasut Cc: kernel@dh-electronics.com Cc: Linux Team To: linux-serial@vger.kernel.org To: linux-arm-kernel@lists.infradead.org --- V2: - Rework of the commit message - Rework GPIO property comment V3: - Rework GPIO property comment V4: - No changes --- drivers/tty/serial/serial_core.c | 12 ++++++++++++ include/linux/serial_core.h | 1 + 2 files changed, 13 insertions(+) diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c index b9fbbee598b8..867f2675caca 100644 --- a/drivers/tty/serial/serial_core.c +++ b/drivers/tty/serial/serial_core.c @@ -3410,6 +3410,7 @@ int uart_get_rs485_mode(struct uart_port *port) struct device *dev = port->dev; u32 rs485_delay[2]; int ret; + int rx_during_tx_gpio_flag; ret = device_property_read_u32_array(dev, "rs485-rts-delay", rs485_delay, 2); @@ -3458,6 +3459,17 @@ int uart_get_rs485_mode(struct uart_port *port) if (port->rs485_term_gpio) port->rs485_supported.flags |= SER_RS485_TERMINATE_BUS; + rx_during_tx_gpio_flag = (rs485conf->flags & SER_RS485_RX_DURING_TX) ? + GPIOD_OUT_HIGH : GPIOD_OUT_LOW; + port->rs485_rx_during_tx_gpio = devm_gpiod_get_optional(dev, + "rs485-rx-during-tx", + rx_during_tx_gpio_flag); + if (IS_ERR(port->rs485_rx_during_tx_gpio)) { + ret = PTR_ERR(port->rs485_rx_during_tx_gpio); + port->rs485_rx_during_tx_gpio = NULL; + return dev_err_probe(dev, ret, "Cannot get rs485-rx-during-tx-gpios\n"); + } + return 0; } EXPORT_SYMBOL_GPL(uart_get_rs485_mode); diff --git a/include/linux/serial_core.h b/include/linux/serial_core.h index fd59f600094a..7d3784b18a6f 100644 --- a/include/linux/serial_core.h +++ b/include/linux/serial_core.h @@ -579,6 +579,7 @@ struct uart_port { struct serial_rs485 rs485; struct serial_rs485 rs485_supported; /* Supported mask for serial_rs485 */ struct gpio_desc *rs485_term_gpio; /* enable RS485 bus termination */ + struct gpio_desc *rs485_rx_during_tx_gpio; /* Output GPIO that sets the state of RS485 RX during TX */ struct serial_iso7816 iso7816; void *private_data; /* generic platform data pointer */ }; From patchwork Fri Dec 2 10:41:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Niedermaier X-Patchwork-Id: 13062640 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 ECD4CC4321E for ; Fri, 2 Dec 2022 11:14:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Q4WJrSIiIFZsm13pj5pRBonrPMjBGqaMGDWlYZw9yNk=; b=1DuazZFQ+3iOm+ qAnE9TBhhNS8tBO6hyw5eeOBq8p9w8/T1nZiOisr/LNfOS4ioyNttXrIQF/euWR69qX3CL0727obw XlDGG0QGRSct5lVmIbFi/vDfQSZaibMcvIdRb54nnHZ0II0oVswyYBr/EapR/AT8Xyx+0lPnjtjiq wzKL0lomCwVcGxD7o8lmRtVeHmkY/gSVmX91wqnKfJINAJOKP40+Vd9+hQFhVvGrifjIwr02DWM2T VLPRkQwjCK2KILSTtj2UTUwUMGilhfwAiM4maIClj1CY45yLwHT59Xwg8A/ubxYZlwMVYMJJrMBxI T0q3A9gyWguen0/bWg+g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p13zA-00FtuK-Og; Fri, 02 Dec 2022 11:13:40 +0000 Received: from mx3.securetransport.de ([2a01:4f8:c0c:92be::1]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p13z6-00FtpJ-4E for linux-arm-kernel@lists.infradead.org; Fri, 02 Dec 2022 11:13:38 +0000 Received: from mail.dh-electronics.com (unknown [77.24.89.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx3.securetransport.de (Postfix) with ESMTPSA id F2E745DC6B; Fri, 2 Dec 2022 12:12:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dh-electronics.com; s=dhelectronicscom; t=1669979576; bh=XiwlRoN6SFWV7lwPXeKbFNSGAtiKGfBc2C/mQAEg570=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=kRmLj+n+nYdIKS6CYD2sKTblrIRDlnJSO1U1SuTbQAucx+ZdUvkL3DlJ0QaDUyMch TsY2CN2Cv8Uj/WEAyvpoX7NDRFaaqXfKkX3vPDJFPVEoU73sHfA+Zgntsj+sLr5o4v Nl9BWjgfI+LlY+ROrn0Rog91l5gIbebWlUzEa6D2oBTyHat6WZtQkv6WgouBLlGGHf IP7escxiPrWqYHnraVOpNb65sChpKd1u3a82+3AZyW+5k0xbGoE7fGsci+FKsqOkrG roFe9vwsl7Yu63dOcQv+218qd+89HHnH7FmBsNpt1ihkTFxiW4fwmKx9K5GjRDjtcW 9Rr09ZiWL8/Fw== Received: from DHPWEX01.DH-ELECTRONICS.ORG (10.64.2.30) by DHPWEX01.DH-ELECTRONICS.ORG (10.64.2.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.20; Fri, 2 Dec 2022 11:42:38 +0100 Received: from localhost.localdomain (172.16.51.2) by DHPWEX01.DH-ELECTRONICS.ORG (10.64.2.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.20 via Frontend Transport; Fri, 2 Dec 2022 11:42:38 +0100 From: Christoph Niedermaier To: , CC: , , , Christoph Niedermaier , Greg Kroah-Hartman , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Alexander Dahl , Fabio Estevam , , Linux Team Subject: [PATCH V4 3/4] serial: imx: Add support for RS485 RX_DURING_TX output GPIO Date: Fri, 2 Dec 2022 11:41:26 +0100 Message-ID: <20221202104127.122761-3-cniedermaier@dh-electronics.com> X-Mailer: git-send-email 2.11.0 X-klartext: yes In-Reply-To: <20221202104127.122761-1-cniedermaier@dh-electronics.com> References: <20221202104127.122761-1-cniedermaier@dh-electronics.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221202_031336_478902_AA99B872 X-CRM114-Status: GOOD ( 17.19 ) 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 If a RX_DURING_TX GPIO is defined by the DT property "rs485-rx-during-tx-gpios" this patch switches this GPIO accordingly to the RS485 flag RX_DURING_TX in user space. In addition, the i.MX UART receiver is no longer turned on and off during sending, because now the hardware is responsible for connecting or disconnecting RX during TX controlled by this GPIO. Signed-off-by: Christoph Niedermaier --- Cc: Greg Kroah-Hartman Cc: Jiri Slaby Cc: Shawn Guo Cc: Sascha Hauer Cc: Pengutronix Kernel Team Cc: Alexander Dahl Cc: Fabio Estevam Cc: Marek Vasut Cc: kernel@dh-electronics.com Cc: Linux Team To: linux-serial@vger.kernel.org To: linux-arm-kernel@lists.infradead.org --- V2: - Rework of the commit message V3: - No changes V4: - Direct call of gpiod_set_value_cansleep() without if statement --- drivers/tty/serial/imx.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index 757825edb0cd..a2aea88128af 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -476,7 +476,8 @@ static void imx_uart_stop_tx(struct uart_port *port) imx_uart_rts_inactive(sport, &ucr2); imx_uart_writel(sport, ucr2, UCR2); - imx_uart_start_rx(port); + if (!port->rs485_rx_during_tx_gpio) + imx_uart_start_rx(port); sport->tx_state = OFF; } @@ -705,7 +706,8 @@ 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)) + if (!(port->rs485.flags & SER_RS485_RX_DURING_TX) && + !port->rs485_rx_during_tx_gpio) imx_uart_stop_rx(port); sport->tx_state = WAIT_AFTER_RTS; @@ -1955,6 +1957,10 @@ static int imx_uart_rs485_config(struct uart_port *port, struct ktermios *termio rs485conf->flags & SER_RS485_RX_DURING_TX) imx_uart_start_rx(port); + if (port->rs485_rx_during_tx_gpio) + gpiod_set_value_cansleep(port->rs485_rx_during_tx_gpio, + !!(rs485conf->flags & SER_RS485_RX_DURING_TX)); + return 0; } From patchwork Fri Dec 2 10:41:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Niedermaier X-Patchwork-Id: 13062642 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 D94A9C4321E for ; Fri, 2 Dec 2022 11:29:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=osnySg1AHzgJbOcgNvSrT73NDDOI6EYNUBEcpoJaLn0=; b=YzB0jkKFCbza0E 1JSKKPp9BU89mHh/z+5mMoUFbce5XxSQGmS2oZiX1KbJBhetBTZpvdcUlgvFvnIXFs90m+98DINtU gy1/MNIe0Hdeb4DvFvTu05L3Mgio2laGBynNaJULAfwnRPObzRJRhY8lqLUokDDdo2EHVtPeQC+Yf v2EiE75no9H4ynN2Yvla7QnVqayB5XfEA4H1x261gqD3TOJtnocw+38IdvP2Mqvznf+ficxD3I+Gb 2Mrx/il40ykMeJR2dlx6TvAsNZbETyp4MmmPStX2SYN3XzH2HR+pCNZ3lX+oMqADI74lK+xST6zJI +lF6tH/nEHs+zOuoBpuw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p14Dl-00Fzp0-9d; Fri, 02 Dec 2022 11:28:45 +0000 Received: from mx4.securetransport.de ([178.254.6.145]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1p14Dc-00FzlJ-Vk for linux-arm-kernel@lists.infradead.org; Fri, 02 Dec 2022 11:28:39 +0000 Received: from mail.dh-electronics.com (unknown [77.24.89.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx4.securetransport.de (Postfix) with ESMTPSA id 1A7EC7201A0; Fri, 2 Dec 2022 12:27:58 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dh-electronics.com; s=dhelectronicscom; t=1669980481; bh=Yw80B+VbXYxZbZl5QOEChJ2+lPK3kstlswLK+D6i38Q=; h=From:To:CC:Subject:Date:In-Reply-To:References:From; b=mD1aba1DxgiExqPfgQvBYDdKgKQ7a5pVMsRNPU/PeJtuMHs0nKNujCm0HI7Aus7Xa svDc7ZqtEgh2sWVAltEYrP+uJd+AGryYNwJcXwLka1bjm7eB1D0fdh4x3j/PPGextN DpEh9XgfgF73CEoV4Ycfxk1V3hp3v889Tsxddtyu5sn2Q4UFh5OPSAnINDiVEyDO7i RxImd/flNi9QiZObGhFPiQE+n7iCPIeCxslgaBqvCeaw5uhy4172belboDEa28wyZ6 o4rrjf+sITs23iWSope0G290OxeXiI/384CEJ7LcpqlYhHvwdFh0qp6/npoCTndCd5 P/vx2AaRiqMUQ== Received: from DHPWEX01.DH-ELECTRONICS.ORG (10.64.2.30) by DHPWEX01.DH-ELECTRONICS.ORG (10.64.2.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.20; Fri, 2 Dec 2022 11:42:39 +0100 Received: from localhost.localdomain (172.16.51.2) by DHPWEX01.DH-ELECTRONICS.ORG (10.64.2.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.20 via Frontend Transport; Fri, 2 Dec 2022 11:42:39 +0100 From: Christoph Niedermaier To: , CC: , , , Christoph Niedermaier , Greg Kroah-Hartman , Maxime Coquelin , Alexandre Torgue , Alexander Dahl , , Subject: [PATCH V4 4/4] serial: stm32: Add support for rs485 RX_DURING_TX output GPIO Date: Fri, 2 Dec 2022 11:41:27 +0100 Message-ID: <20221202104127.122761-4-cniedermaier@dh-electronics.com> X-Mailer: git-send-email 2.11.0 X-klartext: yes In-Reply-To: <20221202104127.122761-1-cniedermaier@dh-electronics.com> References: <20221202104127.122761-1-cniedermaier@dh-electronics.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20221202_032837_378983_D57C5A56 X-CRM114-Status: GOOD ( 15.58 ) 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 If a RX_DURING_TX GPIO is defined by the DT property "rs485-rx-during-tx-gpios" this patch switches this GPIO accordingly to the RS485 flag RX_DURING_TX in user space. Controlled by this GPIO, now the hardware is responsible for connecting or disconnecting RX during TX. Signed-off-by: Christoph Niedermaier --- Cc: Greg Kroah-Hartman Cc: Jiri Slaby Cc: Maxime Coquelin Cc: Alexandre Torgue Cc: Alexander Dahl Cc: Marek Vasut Cc: kernel@dh-electronics.com Cc: linux-stm32@st-md-mailman.stormreply.com To: linux-serial@vger.kernel.org To: linux-arm-kernel@lists.infradead.org --- V2: - Rework of the commit message V3: - No changes V4: - Direct call of gpiod_set_value_cansleep() without if statement --- drivers/tty/serial/stm32-usart.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c index a1490033aa16..f1b1df78118f 100644 --- a/drivers/tty/serial/stm32-usart.c +++ b/drivers/tty/serial/stm32-usart.c @@ -226,7 +226,11 @@ static int stm32_usart_config_rs485(struct uart_port *port, struct ktermios *ter stm32_usart_clr_bits(port, ofs->cr1, BIT(cfg->uart_enable_bit)); - rs485conf->flags |= SER_RS485_RX_DURING_TX; + if (port->rs485_rx_during_tx_gpio) + gpiod_set_value_cansleep(port->rs485_rx_during_tx_gpio, + !!(rs485conf->flags & SER_RS485_RX_DURING_TX)); + else + rs485conf->flags |= SER_RS485_RX_DURING_TX; if (rs485conf->flags & SER_RS485_ENABLED) { cr1 = readl_relaxed(port->membase + ofs->cr1);