From patchwork Tue Mar 2 19:03:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Devera X-Patchwork-Id: 12113723 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A2B0C433E0 for ; Wed, 3 Mar 2021 15:36:52 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DBBB464EBD for ; Wed, 3 Mar 2021 15:36:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DBBB464EBD Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=eaxlabs.cz Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:MIME-Version:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id: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=McHEyUQNeO/xXhBB08AEOS7U6/umI9cmS60/oggUeT8=; b=f5BPZMBIc34+D+YRkV2y1hYUAf s5M0liNj0piRvlex7b9Z8Wieplan6RjyLx56VMvNqqbz1jHjZfJNHunko58PmFN/xghqNlTpnTNZJ g5uMLE0jolZkLub2GSQWrgb3O8WjlGoKQwfxHBSCGOz9H17YgwjtC31jsukeWH3BpkQKQynZljPuh ZH2sWdNriNKeUrzmP66jCuVtM0MClqftIsGdt6XJJ5Q62/agvrebJTFxO7RrWpNfRACEYGj4scHVt XzxKHOMww9z9ey4QxX1JHRBQ03MKskcO2pbDK9H0tLi2ZLbjln5XoNBbf0BiuWoBa0YRJBTllejfu CzXu/t1w==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lHTWS-005PJs-Gm; Wed, 03 Mar 2021 15:34:49 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lHSU8-0058BQ-MY for linux-arm-kernel@desiato.infradead.org; Wed, 03 Mar 2021 14:28:21 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description; bh=65e45oHZO+BxFf5UqN9fVtID/K010U91Mz2QcQ/swdo=; b=O4qswpXJCoXVQX32xS9ecx1wjT dETsa/ab7CEG7/0k9PVZJqtZMWWJzShC5a+W8fBBkGmQcjsJbmjQymIO9kkqGa6EOiB7EGLW3lOJE 7zRue/TvF73A+wPY7eQGek31rJtYLbyHkNzT7WrZLr5zL/2FQICFk6Mwfi0otSO/nqfBIOn50iIbU yLmW7OpeMpMH+sNjwNrgHPqtEePa7E0stPaJHZ7bPMYl6y5atIM3E4yI9EP3WZrkN/42xdfqyrz2M avznd2jSBZGyEk3Tavy7IopYZncpV7MPaK/cetPhU/9k9jMN6gHglQu99s2OUOVenrrTF8c+K3oJL cpJkhYVw==; Received: from ms9.eaxlabs.cz ([147.135.177.209]) by casper.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lHAIn-0007cf-IP for linux-arm-kernel@lists.infradead.org; Tue, 02 Mar 2021 19:03:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=eaxlabs.cz; s=mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=65e45oHZO+BxFf5UqN9fVtID/K010U91Mz2QcQ/swdo=; b=EDAtFQZ9mVFD65Wff/a94mHlD9FCA6zVKQueKKYilfU3rhnQR4/xuDvTEry+n7OtG5lR54ychj7JxOF2ANKxGfpGjZgsSY0uoYSHBF/LvtumbmdaaRxMbYsXU5+wcfT2VffoR89NzyhIFtMWmSSw7QtQ+RHAIqQaOqQrJqUIZd8=; Received: from [82.99.129.6] (helo=localhost.localdomain) by ms9.eaxlabs.cz with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1lHAIX-000335-MD; Tue, 02 Mar 2021 20:03:11 +0100 From: Martin Devera To: linux-kernel@vger.kernel.org Cc: Martin Devera , Greg Kroah-Hartman , Rob Herring , Maxime Coquelin , Alexandre Torgue , Jiri Slaby , Le Ray , fabrice.gasnier@foss.st.com, linux-serial@vger.kernel.org, devicetree@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 1/2] dt-bindings: serial: Add rx-tx-swap to stm32-usart Date: Tue, 2 Mar 2021 20:03:02 +0100 Message-Id: <20210302190303.28630-1-devik@eaxlabs.cz> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210302_190326_216553_E82569FB X-CRM114-Status: UNSURE ( 9.05 ) X-CRM114-Notice: Please train this message. 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: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add new rx-tx-swap property to allow for RX & TX pin swapping. Signed-off-by: Martin Devera Acked-by: Fabrice Gasnier --- .../devicetree/bindings/serial/st,stm32-uart.yaml | 32 +++++++++++++++------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/Documentation/devicetree/bindings/serial/st,stm32-uart.yaml b/Documentation/devicetree/bindings/serial/st,stm32-uart.yaml index 8631678283f9..6eab2debebb5 100644 --- a/Documentation/devicetree/bindings/serial/st,stm32-uart.yaml +++ b/Documentation/devicetree/bindings/serial/st,stm32-uart.yaml @@ -9,9 +9,6 @@ maintainers: title: STMicroelectronics STM32 USART bindings -allOf: - - $ref: rs485.yaml - properties: compatible: enum: @@ -40,6 +37,10 @@ properties: uart-has-rtscts: true + rx-tx-swap: + type: boolean + maxItems: 1 + dmas: minItems: 1 maxItems: 2 @@ -66,13 +67,24 @@ properties: linux,rs485-enabled-at-boot-time: true rs485-rx-during-tx: true -if: - required: - - st,hw-flow-ctrl -then: - properties: - cts-gpios: false - rts-gpios: false +allOf: + - $ref: rs485.yaml + - if: + required: + - st,hw-flow-ctrl + then: + properties: + cts-gpios: false + rts-gpios: false + - if: + required: + - rx-tx-swap + then: + properties: + compatible: + enum: + - st,stm32f7-uart + - st,stm32h7-uart required: - compatible From patchwork Tue Mar 2 19:03:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Devera X-Patchwork-Id: 12113665 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3F066C433DB for ; Wed, 3 Mar 2021 15:12:25 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 365AF64EEC for ; Wed, 3 Mar 2021 15:12:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 365AF64EEC Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=eaxlabs.cz Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:MIME-Version:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id: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=us7KmbpuLpnSlU7Q+kDwQ9d8joSwgXhLocJs2nplEtU=; b=PAsBkpGj1P4+6V+rNfXG0r4GTZ 76MY1urlHPjgAnoX35aDgb3HLiXVKSF+Bm3vP4+ffuhPeyWF9H4u0NRO2xz7xUiscf8nR18yULcA5 D420N3ULv2NSm/r3+/1ZF2mHo46dCqn6pB0RDhMX+omw2I5eG91tAqUYCQRx8Epvya3jujfMctJRQ Q08hhuizEozPXu6Tn43EMFbWr1NFKbMbtF0rKB0Bdna6+CePfvoG/nHcs5kBRiEM5z1s+5EEg100D 2BYPTqnXpV1oV72ePll7SZHjQTnfV1dMI1/svbrcf43N/poPu4+3GewLI6yIhOv9BINusrWnVE4K9 shN2qhKw==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lHT8S-005JmC-6J; Wed, 03 Mar 2021 15:10:00 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lHSCd-0054n6-50 for linux-arm-kernel@desiato.infradead.org; Wed, 03 Mar 2021 14:10:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description; bh=fejrz8pZgmoe2h2cqRMP5fEvXu4OT7IafZ1vBUiLz6o=; b=UH6kV90EeMgG+j1TOcqU93RmsP SCfRnv6kNMvH3iiAll5ovG+FXC5ZL5xDVSauHc5biJlTSN8PYHjHr6t2hliXGkmgG6/MRTecynsvQ 0FWczGpBRpXU1y/rxxCtryTB+VGtC+7a0wNmUgzNAGNzvKRE7Af6eHSMWHoqDC2LD87gdLDTHSkWV /MQ8X0bgW0P72lBQVbszWlwE30utadPua6tLdDOPaNRGLMvkLHklV0g2kEWXciiqEevMQQ0y3NiH+ cP3zf/7A7j7dDyBmrxRgvejClkCPJxihG/f415LgXDChYnBpkcuDe5F9xnCNygcADmkfSnBStYKWT n5Ddz8pA==; Received: from ms9.eaxlabs.cz ([147.135.177.209]) by casper.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lHAIn-0007cg-IO for linux-arm-kernel@lists.infradead.org; Tue, 02 Mar 2021 19:03:26 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=eaxlabs.cz; s=mail; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From; bh=fejrz8pZgmoe2h2cqRMP5fEvXu4OT7IafZ1vBUiLz6o=; b=2PXck11lkAs5N7RQHbGzL9cyZ68PeG7kMEAyslCK5DR6T0hBL2yHrMkukWmO6s8WH1W4Vk+Q5UPq36jqjqYggqJhCidsX+JorCsuyR79H+tAlRklfRZf9khVirPiMm6iK3x73KAw+HkkV7cXvtikafcb1glm1Hxs08Fw4QPThwU=; Received: from [82.99.129.6] (helo=localhost.localdomain) by ms9.eaxlabs.cz with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1lHAIa-000335-Eg; Tue, 02 Mar 2021 20:03:14 +0100 From: Martin Devera To: linux-kernel@vger.kernel.org Cc: Martin Devera , Greg Kroah-Hartman , Rob Herring , Maxime Coquelin , Alexandre Torgue , Jiri Slaby , Le Ray , fabrice.gasnier@foss.st.com, linux-serial@vger.kernel.org, devicetree@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 2/2] tty/serial: Add rx-tx-swap OF option to stm32-usart Date: Tue, 2 Mar 2021 20:03:03 +0100 Message-Id: <20210302190303.28630-2-devik@eaxlabs.cz> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20210302190303.28630-1-devik@eaxlabs.cz> References: <20210302190303.28630-1-devik@eaxlabs.cz> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210302_190326_246381_80F38FAF X-CRM114-Status: GOOD ( 14.14 ) 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: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org STM32 F7/H7 usarts supports RX & TX pin swapping. Add option to turn it on. Tested on STM32MP157. Signed-off-by: Martin Devera Acked-by: Fabrice Gasnier --- drivers/tty/serial/stm32-usart.c | 11 ++++++++++- drivers/tty/serial/stm32-usart.h | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/tty/serial/stm32-usart.c b/drivers/tty/serial/stm32-usart.c index b3675cf25a69..d390f7da1441 100644 --- a/drivers/tty/serial/stm32-usart.c +++ b/drivers/tty/serial/stm32-usart.c @@ -644,6 +644,12 @@ static int stm32_usart_startup(struct uart_port *port) if (ret) return ret; + if (stm32_port->swap) { + val = readl_relaxed(port->membase + ofs->cr2); + val |= USART_CR2_SWAP; + writel_relaxed(val, port->membase + ofs->cr2); + } + /* RX FIFO Flush */ if (ofs->rqr != UNDEF_REG) stm32_usart_set_bits(port, ofs->rqr, USART_RQR_RXFRQ); @@ -758,7 +764,7 @@ static void stm32_usart_set_termios(struct uart_port *port, cr1 = USART_CR1_TE | USART_CR1_RE; if (stm32_port->fifoen) cr1 |= USART_CR1_FIFOEN; - cr2 = 0; + cr2 = stm32_port->swap ? USART_CR2_SWAP : 0; cr3 = readl_relaxed(port->membase + ofs->cr3); cr3 &= USART_CR3_TXFTIE | USART_CR3_RXFTCFG_MASK | USART_CR3_RXFTIE | USART_CR3_TXFTCFG_MASK; @@ -1006,6 +1012,9 @@ static int stm32_usart_init_port(struct stm32_port *stm32port, return stm32port->wakeirq ? : -ENODEV; } + stm32port->swap = stm32port->info->cfg.has_swap && + of_property_read_bool(pdev->dev.of_node, "rx-tx-swap"); + stm32port->fifoen = stm32port->info->cfg.has_fifo; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); diff --git a/drivers/tty/serial/stm32-usart.h b/drivers/tty/serial/stm32-usart.h index cb4f327c46db..a85391e71e8e 100644 --- a/drivers/tty/serial/stm32-usart.h +++ b/drivers/tty/serial/stm32-usart.h @@ -25,6 +25,7 @@ struct stm32_usart_offsets { struct stm32_usart_config { u8 uart_enable_bit; /* USART_CR1_UE */ bool has_7bits_data; + bool has_swap; bool has_wakeup; bool has_fifo; int fifosize; @@ -76,6 +77,7 @@ struct stm32_usart_info stm32f7_info = { .cfg = { .uart_enable_bit = 0, .has_7bits_data = true, + .has_swap = true, .fifosize = 1, } }; @@ -97,6 +99,7 @@ struct stm32_usart_info stm32h7_info = { .cfg = { .uart_enable_bit = 0, .has_7bits_data = true, + .has_swap = true, .has_wakeup = true, .has_fifo = true, .fifosize = 16, @@ -271,6 +274,7 @@ struct stm32_port { int last_res; bool tx_dma_busy; /* dma tx busy */ bool hw_flow_control; + bool swap; /* swap RX & TX pins */ bool fifoen; int wakeirq; int rdr_mask; /* receive data register mask */