From patchwork Fri Jun 14 12:11:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Organov X-Patchwork-Id: 10995155 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1648776 for ; Fri, 14 Jun 2019 12:12:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0590A28658 for ; Fri, 14 Jun 2019 12:12:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EC90A28682; Fri, 14 Jun 2019 12:12:15 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 792C62867F for ; Fri, 14 Jun 2019 12:12:15 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=Ve2ZXChfkCywBwo2Nr1l6wXPgX1y/GKog2Ubuk3HjWA=; b=pxTR8ae2ky1sC8o9lOnfRhiCRZ 7xW9GMD3yrDotGvHgB1kwSWg9t68qftvwTI2dislNAO2Vz1HrSxIrQAHKneReCegeDsKbe0OjK7La 9EfjflWT0G2j301d6GIq8peYdk+SV/oBMN7cdGc21WRfEHny/2p1ApbfgggyCCT67es/A4W/nM7pR LNheXUFrs8q6MVXAV7F2ez4FbxZpsc0fDFXDNg0UJ7lKw3/MxyL/NPlTOMHKTUtQA4AWkLIPWujz5 uQ0FR/cXInQ7gWjokAG17UlmFyMXA0DzQZYMwz9QVZ/azlcgs0qGDxWMudU+q6gGWFW2bji6nYECD jizd34mw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hbl3v-0002xO-Oc; Fri, 14 Jun 2019 12:12:07 +0000 Received: from mail-lj1-x244.google.com ([2a00:1450:4864:20::244]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hbl3h-0002mB-QA for linux-arm-kernel@lists.infradead.org; Fri, 14 Jun 2019 12:11:55 +0000 Received: by mail-lj1-x244.google.com with SMTP id x25so2186203ljh.2 for ; Fri, 14 Jun 2019 05:11:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=SMvfNXrBGoXH5Rlv9ONYJ/L8T8ix7gsLxKZmilMNxjo=; b=OXEqXdFYrhgQa3V2TQRJ6AexhYZVCKIhb6Wb2iFCOCEBjuFOJsvlSGlw2eceWJHHuI J3HnTHQ/O69pnE7PhM11LQoC9pBVLOi8Le5efld4HJZ5cME2mtIHVpzxpwNWLYBJcNkn 18L/HO059DbOznsGU6aJUH91YebrU8EEugRNjmIql3Yzus7dzWMKtVEnzugWhHGK9TzI 6Z8vN3veiqG0OlqYRurW7nx/skf1qIoF6FnK7WLKdwM2+cjGuHE8hnyNEJMnQ0WzVSuw jx1tjf/WMkNVcvdlMfww+7kzk6IzSJXjWhD+vPQSYH2tpmrJbWd7z5wytPvrk6D7CGCG T35w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=SMvfNXrBGoXH5Rlv9ONYJ/L8T8ix7gsLxKZmilMNxjo=; b=knFy8cf64/49/sDnkf5/Loi1wiutxVa1p9hBZpRwcG2hpwp05z0pGocGfcN7Zu9b8v RCHOzkp9PZdi2kzdG4l3wlLZ+3Lxz5nkwrrogfGoiEwDOvluoDApxlivqts9apKPbGb2 sE7VSfgIAxZXFIQAgLws6akjMZqx0T0QRn1ZD7oCxA28NL8bleM92S8Lhti3MOVncyKa tvyK7USn2xYVV1MnTAbl+6r+1xpU/DyEgNF9RbUuC8Zllvt5kMYvPLvBrW1yugmHqwDl qfF7JRzHQU43+CTpakBnbOUhdmqVkKeqaNzZUv2vkkbPdQeXWnvjJygPlJxdtYMffVXc HGgA== X-Gm-Message-State: APjAAAWx4cidm2lF52lym/cBXt/n9CXC/Nbr7/P5uho4Rxh80Ye8BLZW QWH8iICfb9UqhnYPCrvU/xo= X-Google-Smtp-Source: APXvYqyfSBKlleftIibV4Y83OfC6jOJA6VbY7mUXU01V8OkZkjsW9ihhGp/DrZuxDvinUc5ATsuWFw== X-Received: by 2002:a2e:9e4c:: with SMTP id g12mr25518090ljk.3.1560514312085; Fri, 14 Jun 2019 05:11:52 -0700 (PDT) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id p27sm459683lfh.8.2019.06.14.05.11.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 14 Jun 2019 05:11:51 -0700 (PDT) From: Sergey Organov To: Sascha Hauer Subject: [PATCH RFC 1/7] serial: imx: fix locking in set_termios() Date: Fri, 14 Jun 2019 15:11:28 +0300 Message-Id: <1560514294-29111-2-git-send-email-sorganov@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1560514294-29111-1-git-send-email-sorganov@gmail.com> References: <20190614072801.3187-1-s.hauer@pengutronix.de> <1560514294-29111-1-git-send-email-sorganov@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190614_051153_843878_E4E24CBB X-CRM114-Status: GOOD ( 12.76 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pengutronix Kernel Team , NXP Linux Team , linux-arm-kernel@lists.infradead.org, linux-serial@vger.kernel.org, =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= MIME-Version: 1.0 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 imx_uart_set_termios() called imx_uart_rts_active(), or imx_uart_rts_inactive() before taking port->port.lock. As a consequence, sport->port.mctrl that these functions modify could have been changed without holding port->port.lock. Moved locking of port->port.lock above the calls to fix the issue. Signed-off-by: Sergey Organov --- drivers/tty/serial/imx.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index dff75dc..1055124 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -383,6 +383,7 @@ static void imx_uart_ucrs_restore(struct imx_port *sport, } #endif +/* called with port.lock taken and irqs caller dependent */ static void imx_uart_rts_active(struct imx_port *sport, u32 *ucr2) { *ucr2 &= ~(UCR2_CTSC | UCR2_CTS); @@ -391,6 +392,7 @@ static void imx_uart_rts_active(struct imx_port *sport, u32 *ucr2) mctrl_gpio_set(sport->gpios, sport->port.mctrl); } +/* called with port.lock taken and irqs caller dependent */ static void imx_uart_rts_inactive(struct imx_port *sport, u32 *ucr2) { *ucr2 &= ~UCR2_CTSC; @@ -400,6 +402,7 @@ static void imx_uart_rts_inactive(struct imx_port *sport, u32 *ucr2) mctrl_gpio_set(sport->gpios, sport->port.mctrl); } +/* called with port.lock taken and irqs caller dependent */ static void imx_uart_rts_auto(struct imx_port *sport, u32 *ucr2) { *ucr2 |= UCR2_CTSC; @@ -1550,6 +1553,16 @@ imx_uart_set_termios(struct uart_port *port, struct ktermios *termios, old_csize = CS8; } + del_timer_sync(&sport->timer); + + /* + * Ask the core to calculate the divisor for us. + */ + baud = uart_get_baud_rate(port, termios, old, 50, port->uartclk / 16); + quot = uart_get_divisor(port, baud); + + spin_lock_irqsave(&sport->port.lock, flags); + if ((termios->c_cflag & CSIZE) == CS8) ucr2 = UCR2_WS | UCR2_SRST | UCR2_IRTS; else @@ -1593,16 +1606,6 @@ imx_uart_set_termios(struct uart_port *port, struct ktermios *termios, ucr2 |= UCR2_PROE; } - del_timer_sync(&sport->timer); - - /* - * Ask the core to calculate the divisor for us. - */ - baud = uart_get_baud_rate(port, termios, old, 50, port->uartclk / 16); - quot = uart_get_divisor(port, baud); - - spin_lock_irqsave(&sport->port.lock, flags); - sport->port.read_status_mask = 0; if (termios->c_iflag & INPCK) sport->port.read_status_mask |= (URXD_FRMERR | URXD_PRERR); From patchwork Fri Jun 14 12:11:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Organov X-Patchwork-Id: 10995157 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A9E1B924 for ; Fri, 14 Jun 2019 12:12:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 978A328673 for ; Fri, 14 Jun 2019 12:12:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8C3972867C; Fri, 14 Jun 2019 12:12:35 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 3A4DA28673 for ; Fri, 14 Jun 2019 12:12:35 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=bjj99dfZ1AUF4SHwQZoXaCEC5Wnpsj8haFSdu3EluX4=; b=CafrRt8aJ0XaTsQL+mKlqELV+Y oiI6XalQ4vUvPh6Anedg5iuTZQWzr9FY+SL+Uv4kR/V4+iBAxiJRLwSycOgP92VDR262wm8XXdVc9 hwnJI9Y6SEeUUAclUIgq+MMGvgeJABjZh+xsbQmF2+YaBQ6oz70+ideEIqIYBpptAn6M9YY0KQ1C4 K23pZVSHVpXGYzVoWl2apFGH0bRTSCmCvml59v0FabTDF+DMUqgymXrvXWu0N6Xu5Rfx6O9JgQMMx K75SGwY4oqeA/0cp19VCZq4ZkPqImI7B9PHy2JyIslHRWTKhdIK9E/OUj4/d+Awu3555bspHDyAEQ 83tBw+VQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hbl4G-0003Ek-AW; Fri, 14 Jun 2019 12:12:28 +0000 Received: from mail-lj1-x242.google.com ([2a00:1450:4864:20::242]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hbl3i-0002mN-Ky for linux-arm-kernel@lists.infradead.org; Fri, 14 Jun 2019 12:11:55 +0000 Received: by mail-lj1-x242.google.com with SMTP id v24so2122914ljg.13 for ; Fri, 14 Jun 2019 05:11:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=D4v0SFR2nHGdYcEZZKZiUTxqoD86zDefhBuvLG6SwpU=; b=AhAtzRZR1iNbZtwwefyYQrhCxFjjjj3jcAtizT8hokoo5h70+FSnAE5y+zYDk1LWi4 NIgeJuyCHNbZ3Yt2eG0yOW3R6bUBLTGn3h7qfGUP27zs6pEW/8A4aMnI/Wi68hjjYCU0 HCWaq/sL2tY9m9vkgWU13HhB3shFp0FG6wmP91kkFY7W1y+kHkDU1+hbgRyBbNwFxztk GbVCABEY/OuCjip8EbMCR5xMi8BRHM2MeL6SqY9tEdxuAmXdw122za1xBMdNAacvx1DI jyh6DeZ/9VvOqVFBVa/q7K22U4KXBIDa7TIICQz0P2B3ZDXOE+7Dk2ZnXvhSNlw2l3Fu hIEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=D4v0SFR2nHGdYcEZZKZiUTxqoD86zDefhBuvLG6SwpU=; b=uYRV43dV1TLKpHfszyfIFDUh+zeIdBMq6HvO3IxkfLIwf9EpeYpGt2aaNsAQlhEzPS 3Jkxjo4opgdOmpEwYlqpZCjfYB/xbwkm1PYODc9c8S7ZqB2eQjBz84p53MWT6c8JwnaY 5DLmQGmFdYpalhu7q6dWZiH7HG9H1JC6YUks/jo6hKj0KcY1VQ+rC8FDeziRrSmdBR36 VxPYy8AewTFOyfGj7OtAjtlOxr4+XnyrSrmVePyKuXMzTL7mZ9uqUi6JcK0EJAp1visX 3A9OQGWhvwVgljfeYkHqeeXZYrv+9FIh13jcoU3aZyJ5HHz+Y+wKEPzDOl3H6CasOvGT 2yeg== X-Gm-Message-State: APjAAAWmwnU8ik4WaMdcIsv/lZsZtFiaK3txxdqnwsO2S1eEBlihSIF3 BmVGh7WJVgxVndPIj/NJpNg= X-Google-Smtp-Source: APXvYqwwguL28sV6oiZAQwrOvk7Z9RiemYNUnbx+FhUEesYHx8o0fOJn3igjqb2ZoreP6P9ZiZmGHA== X-Received: by 2002:a2e:824c:: with SMTP id j12mr42933549ljh.53.1560514312926; Fri, 14 Jun 2019 05:11:52 -0700 (PDT) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id p27sm459683lfh.8.2019.06.14.05.11.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 14 Jun 2019 05:11:52 -0700 (PDT) From: Sergey Organov To: Sascha Hauer Subject: [PATCH RFC 2/7] serial: imx: set_termios(): factor-out 'ucr2' initial value Date: Fri, 14 Jun 2019 15:11:29 +0300 Message-Id: <1560514294-29111-3-git-send-email-sorganov@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1560514294-29111-1-git-send-email-sorganov@gmail.com> References: <20190614072801.3187-1-s.hauer@pengutronix.de> <1560514294-29111-1-git-send-email-sorganov@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190614_051154_683478_8251D622 X-CRM114-Status: GOOD ( 10.33 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pengutronix Kernel Team , NXP Linux Team , linux-arm-kernel@lists.infradead.org, linux-serial@vger.kernel.org, =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= MIME-Version: 1.0 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 Set common bits in a separate statement to make initialization explicit and not repeat the common part. Signed-off-by: Sergey Organov --- drivers/tty/serial/imx.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index 1055124..87802fd 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -1563,10 +1563,9 @@ imx_uart_set_termios(struct uart_port *port, struct ktermios *termios, spin_lock_irqsave(&sport->port.lock, flags); + ucr2 = UCR2_SRST | UCR2_IRTS; if ((termios->c_cflag & CSIZE) == CS8) - ucr2 = UCR2_WS | UCR2_SRST | UCR2_IRTS; - else - ucr2 = UCR2_SRST | UCR2_IRTS; + ucr2 |= UCR2_WS; if (termios->c_cflag & CRTSCTS) { if (sport->have_rtscts) { From patchwork Fri Jun 14 12:11:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Organov X-Patchwork-Id: 10995159 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CCB1576 for ; Fri, 14 Jun 2019 12:12:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BB0EC28684 for ; Fri, 14 Jun 2019 12:12:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AEE672867C; Fri, 14 Jun 2019 12:12:56 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 58A4A28658 for ; Fri, 14 Jun 2019 12:12:56 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=hUogu3k/ywvT/E73aXDTJ6XVz+5R2dolbJ1BjiXrf3M=; b=adSE2FkV9nr3yEXFFdb2E1uxCy Kg4hbyZUO/Yn0k1tg3EqRGZLZYUuKKfoluQQCr8Fep8npTPCnFRTElpV+V/45oDFxE8jC1G5TbZf7 yYHoyjYiAeN6SclVsIuy/Lj+/OnotEbg3dJMU0HjlRYmnPyhXojeH4/XExRa7cuztQIsK5CKebei+ np+tSbUYcTviRIBCA5mL8sMW1SAu76WlM7JIrZYUcuWIdxyUBUxPhkzvdBUnjxNAWcayqLIbCoS5M Gc4V8z1k0e6lJvt1DyrOvSkziPPv8cg5L9oWYfik/x47cC7hbkFREoYIL3huFmj9OWHlCzYS6txLl 1aXhGbKQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hbl4Z-0003Uh-Em; Fri, 14 Jun 2019 12:12:47 +0000 Received: from mail-lj1-x243.google.com ([2a00:1450:4864:20::243]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hbl3j-0002mj-QM for linux-arm-kernel@lists.infradead.org; Fri, 14 Jun 2019 12:11:57 +0000 Received: by mail-lj1-x243.google.com with SMTP id s21so2143060lji.8 for ; Fri, 14 Jun 2019 05:11:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MnAE4r5Gl1VIMZviL9ksOeXJGJoVijEdryliB0x51XQ=; b=WU87SO0rFdKL0jGGN3E6Yp4DQcPvigBLGDldakRZfF9oHXptATGbb3eOe65YT23hUd dkf7UPpuSeYpi6DzYDXNoxAv/mWc8BepQwQVRO5NR6Xc+CaKDd6L/Sq6oCweq6YLldxE A29Df0QutRTjnn1BG6/cz2jJovdwQGI3+JxTV0sLtr2CS8gr6sfFthAaaUuJnBQT07an P+tJX6Lj5Lr4NDPk9RgIWe8h1nMMR2kqTT+xMnrfTeoRBEGZkF/kFczWQFQ2/lRPXbJL rLCHCfKS9qmAouwI9qDFy5XqlHg8tj7DD0g6RGnJ3U2Z3oOJZ2vPNkZ0M9hBm3S8Jwih MPyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=MnAE4r5Gl1VIMZviL9ksOeXJGJoVijEdryliB0x51XQ=; b=tNzechaWJ1pJnFHYCOF5n+XEUQvirsNWaNbVddqOAQvSmwCFPcq2GsMna3CeVIbRJ7 hfGwW4XBJliFvI98nycTiQN9fjuploGeXfwU65sayoDLqODcQZahxqah8zHUCBUUnjKK kWfUKTyQ/Wr7SbujyIwoFyFgKHeOzjEC/pg9P7aNCQ0uz8whFrGItNhPLQRJxAeGmWGp Gd+1I71TRi31UoSs3vnOIREec4t3yoms95AEoLinTFGY1qQ6KSYCf/A6YBrR8SGtPaHZ VUmjxDCexhH8BzDuKnHMUlikF57swRuLK8wQD2OuhoXM9q2bZe017q5Ye0YwPL9dPn3w 85DQ== X-Gm-Message-State: APjAAAX8YuadMTVvpZsN+yO9CLLkNuozr6Nr9axmAsDqBjtPz3jBZbub 5J4hfBl4P/PenZIhMqlkzW4= X-Google-Smtp-Source: APXvYqxW2PF12BhUCKAQN98WEsRpNhDJrFTYunpAY6YNMydMQgm5z9W1FQbZS6qhN/xSK/JDxqUcHw== X-Received: by 2002:a2e:4a1a:: with SMTP id x26mr35479854lja.207.1560514314037; Fri, 14 Jun 2019 05:11:54 -0700 (PDT) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id p27sm459683lfh.8.2019.06.14.05.11.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 14 Jun 2019 05:11:53 -0700 (PDT) From: Sergey Organov To: Sascha Hauer Subject: [PATCH RFC 3/7] serial: imx: set_termios(): clarify RTS/CTS bits calculation Date: Fri, 14 Jun 2019 15:11:30 +0300 Message-Id: <1560514294-29111-4-git-send-email-sorganov@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1560514294-29111-1-git-send-email-sorganov@gmail.com> References: <20190614072801.3187-1-s.hauer@pengutronix.de> <1560514294-29111-1-git-send-email-sorganov@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190614_051155_880672_83FF3E7E X-CRM114-Status: GOOD ( 11.96 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pengutronix Kernel Team , NXP Linux Team , linux-arm-kernel@lists.infradead.org, linux-serial@vger.kernel.org, =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= MIME-Version: 1.0 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 Avoid repeating the same code for rs485 twice. Make it obvious we clear CRTSCTS bit in termios->c_cflag whenever sport->have_rtscts is false. Make it obvious we clear UCR2_IRTS whenever CRTSCTS is set. Signed-off-by: Sergey Organov --- drivers/tty/serial/imx.c | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index 87802fd..17e2322 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -1567,35 +1567,25 @@ imx_uart_set_termios(struct uart_port *port, struct ktermios *termios, if ((termios->c_cflag & CSIZE) == CS8) ucr2 |= UCR2_WS; - if (termios->c_cflag & CRTSCTS) { - if (sport->have_rtscts) { - ucr2 &= ~UCR2_IRTS; + if (!sport->have_rtscts) + termios->c_cflag &= ~CRTSCTS; - if (port->rs485.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) - imx_uart_rts_active(sport, &ucr2); - else - imx_uart_rts_inactive(sport, &ucr2); - } else { - imx_uart_rts_auto(sport, &ucr2); - } - } else { - termios->c_cflag &= ~CRTSCTS; - } - } else if (port->rs485.flags & SER_RS485_ENABLED) { - /* disable transmitter */ + if (port->rs485.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) imx_uart_rts_active(sport, &ucr2); else imx_uart_rts_inactive(sport, &ucr2); - } + } else if (termios->c_cflag & CRTSCTS) + imx_uart_rts_auto(sport, &ucr2); + + if (termios->c_cflag & CRTSCTS) + ucr2 &= ~UCR2_IRTS; if (termios->c_cflag & CSTOPB) ucr2 |= UCR2_STPB; From patchwork Fri Jun 14 12:11:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Organov X-Patchwork-Id: 10995161 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B9F75924 for ; Fri, 14 Jun 2019 12:13:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A70F728684 for ; Fri, 14 Jun 2019 12:13:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9B71E28689; Fri, 14 Jun 2019 12:13:19 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 3FE6428685 for ; Fri, 14 Jun 2019 12:13:19 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=EENHpDtn/VHoPae3bb41Aa4i8k2+F8fmz4D1cHg03lQ=; b=CwZVj6tNTCSIYxDPgQU5p6uZ+Y DMv2myThcy74qRTkmwG3SEAgnteY+62MNt6tnyxxgesrXnPFtf5A8F6uBzudp5jhdGHZwdYu3nvhV IghIadPwLcUqBQ42G/LOTv6ktL6Mdt+QWDX+KVfwIDjTmBP1hGkEmIPCoA6z7uaHgzclUki5fIcgO zlRmVbIG23+X7OIJMKvpEaxQhkPSF54zLMQzbgMGvL0uTv26v0FqMvAq1RR7GDJDB8ou8PORDXJJe /vVpaLPL4yLRgeQ3ZZbaPtXjXRSP4oRg0Ai9gMPw0iE27B8ONxN2iqEl5ZYX43NYeP1jcRJTH3Rwz KA6UlRhA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hbl4t-0003m5-Ck; Fri, 14 Jun 2019 12:13:07 +0000 Received: from mail-lf1-x143.google.com ([2a00:1450:4864:20::143]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hbl3k-0002nX-Sm for linux-arm-kernel@lists.infradead.org; Fri, 14 Jun 2019 12:11:58 +0000 Received: by mail-lf1-x143.google.com with SMTP id 136so1566200lfa.8 for ; Fri, 14 Jun 2019 05:11:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=UYjsmUBIL6tntgGWQMmUG0zM7PGoxZJvICmLpEKuiKM=; b=il7i9G1w3SX0Zw4vIbZTsQplXBvEBNZ+eNvDmLzsAFQexzjH9BwvOMZhALmT9Y5DA7 RVg6hUfJwzJoRyUpD2JtLUJevdCgwMplMPfNfdiiwzyY3BvMOqYmUj+NCQFP2zBQ9YFq yJkcaArmW5G6cXeBfEObNJpRV29I+BC8bjnO0tNtniXG+fjo0rsHMPxy8NkFfaXMPaFX AlUsdxlbXNi+wd6yNy7OtljKJzeUK+mfQESTfTJ2QXA+xtC1qnE8n1dLXXnqU02x5yna ZlNnxlR0rpet7esPf7bPaEgP0kxMpnv+E+oYXmR/FmhlQmM8u2BG54xhpe8Ue2qv9Fsd 9rqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=UYjsmUBIL6tntgGWQMmUG0zM7PGoxZJvICmLpEKuiKM=; b=Ssjwke4hq2ub0HgXoG7cOWRLLZRktv07fWdCr6aVGLMtvK/VS129PLlg4vfU9QVoBg TO3cmpK7eCJpkQyuVTiqEKjwqCH46uEBJDM3xhRW5fuXwMUEqWLtELhU15gwUpouEl4q ZzhoNHc5yGndoOGq22HJbmqSdlTw1JcJid+QgstSaKpq3jddiYXl8Y3BgYWpEt7yuG0J zNXeIKy/zral63FCJ8My7U5Ymyh39EFauman0IhLoswj1QJpGfrAQ8EFKa18sFM0ZCwm e5LuUIvG2rLu1P81d3z5vxDiWhQFRpFF6vdvCmKpMqNartcoAN+dyNPrOi38Tx8lhWvG Mxcw== X-Gm-Message-State: APjAAAWPAalRwofupiCDlB+Z4qam5V98eVAMOkPj2Z4pEwoNRbOzZxKe 10q6Afl+H2OTlJJVVhM1UHY= X-Google-Smtp-Source: APXvYqwE0kQ3/SOZHOsiq+i5HI5BQIQVPxzNpqWa+XM9yTu3PSUfyxB/zEsW9U1o4rVYPTAAidt/xw== X-Received: by 2002:ac2:5382:: with SMTP id g2mr46735673lfh.92.1560514315029; Fri, 14 Jun 2019 05:11:55 -0700 (PDT) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id p27sm459683lfh.8.2019.06.14.05.11.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 14 Jun 2019 05:11:54 -0700 (PDT) From: Sergey Organov To: Sascha Hauer Subject: [PATCH RFC 4/7] serial: imx: set_termios(): do not enable autoRTS if RTS is unset Date: Fri, 14 Jun 2019 15:11:31 +0300 Message-Id: <1560514294-29111-5-git-send-email-sorganov@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1560514294-29111-1-git-send-email-sorganov@gmail.com> References: <20190614072801.3187-1-s.hauer@pengutronix.de> <1560514294-29111-1-git-send-email-sorganov@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190614_051156_953599_D87CF255 X-CRM114-Status: GOOD ( 11.53 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pengutronix Kernel Team , NXP Linux Team , linux-arm-kernel@lists.infradead.org, linux-serial@vger.kernel.org, =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= MIME-Version: 1.0 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 set_termios() shouldn't set UCR2_CTSC bit if UCR2_CTS (=TIOCM_RTS) is cleared. Added corresponding check in imx_uart_rts_auto() to fix this. Signed-off-by: Sergey Organov --- drivers/tty/serial/imx.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index 17e2322..8ee910f 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -405,7 +405,8 @@ static void imx_uart_rts_inactive(struct imx_port *sport, u32 *ucr2) /* called with port.lock taken and irqs caller dependent */ static void imx_uart_rts_auto(struct imx_port *sport, u32 *ucr2) { - *ucr2 |= UCR2_CTSC; + if (*ucr2 & UCR2_CTS) + *ucr2 |= UCR2_CTSC; } /* called with port.lock taken and irqs off */ From patchwork Fri Jun 14 12:11:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Organov X-Patchwork-Id: 10995165 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D90F976 for ; Fri, 14 Jun 2019 12:13:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C9C702866D for ; Fri, 14 Jun 2019 12:13:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD50428689; Fri, 14 Jun 2019 12:13:35 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 660FB28673 for ; Fri, 14 Jun 2019 12:13:35 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=EKhj2CZSsQ7iPo7bFMgmOdyaOkXuiVpQWJwYoPL6Etw=; b=XVkxorHR001BDNfnQ/PTtolXIB 7ybIW0Y13IdAQOPBNj59s0TfdLXAPbdVlUp4s1oEvT/GROkeVhBnp1fhmHvTJ70d1gX4/YTLnsFRp eA0PqzN6VJkEQRfFQWiO+BqKO+m51XubYoTQ3nhQtQlNm31X4e9NEv5aUVNKbzVfnUbJev1FQnnm8 woU1GlWtQNEoFVghDLuwAuc4xJrgVXcw19hhHdsxF/kAJcFXNtQYk+b62G7zk+bijdh4wMG3YcXSo EnPCYvz0/3sQgRNVC7XYoH6VHL9fogcSb1+wUHKloZGBWiN5cnp/vXSpFW/1CcC8tQK0X6Hrr/XbJ Y99tmzGQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hbl5F-00046O-F8; Fri, 14 Jun 2019 12:13:29 +0000 Received: from mail-lf1-x141.google.com ([2a00:1450:4864:20::141]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hbl3m-0002p3-6I for linux-arm-kernel@lists.infradead.org; Fri, 14 Jun 2019 12:11:59 +0000 Received: by mail-lf1-x141.google.com with SMTP id 136so1566252lfa.8 for ; Fri, 14 Jun 2019 05:11:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=p8PmpzAbRDVJoeBuit/g26TECB2oYt6y7ni9hx4zI8w=; b=fQuo2zrpMCuabBlUMf1rVUEvwsHvE6+8jPSDVc+L1fgqjP02c0JsjUR3b/Q93OxSh9 BCPlEaTD5YEdujGBF2r382+8pudMWyoEfzuvRld7V5akGTlp1xWmjDBqK5inh0H4kxlQ y9pGQ7X3pY1NbpsFFPEJE1URn7oWiV+7Qmab96JSQ3exGafQdJedX/DLXL8rzdY3gjgW Kn8h6Cj543f30W3md6b8q2aVfuIN/4N+/KgyS4FUQAtQAZ4K33J/izosMSvViZCc9nkk fsusU8pRNNOoUowMKCbkCTMOpGMRHhauy7MTB4Cd0XBz/52PQgoe9RPs/wOcPznTpfCS alQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=p8PmpzAbRDVJoeBuit/g26TECB2oYt6y7ni9hx4zI8w=; b=I7+NjqrXLqV8EkoxNDOGMNLOl1N1PBEO8y/UjVAqxf5/iLZynVk3AGgQ/M4jYb9VYY OqhlL01/DdVnxyhag/+Q9+vj9Ru+FGSo5a+2/7brHo7HN3KjXOYwUXIVWUKfd96zqI5T szaFf6lro3vWLbN3MMVGK1QgE2K/yvnheb/foQx6Yxbi3v86cvJbuME9jDix9OuNGxMR eu1QCLhZRt9eADzh6RfVAVr8vHJvh1h9AUTAM9bFRKl7Wsp0s5n0CVq97ikXuFdUd0ie yfpAUAbcqLeL3DnRuzAu1m6eSxbrOQdxxH8paCP37oVK1iWQsvdXVbZ+q1HqhbAPMo86 besA== X-Gm-Message-State: APjAAAVTkyEY+UQhBYGAaiEdffUG/9nzrtwRJQWEk1ALeyOKv3illdaO 1XL3l4skmdcMsTYUyhhZ5lSxiZKP X-Google-Smtp-Source: APXvYqytig4LM1LLSO65nkrj13abfiZO90k3Hd+raLW/m2R9YpRb/VKxxV8lIaz5AhcKUa1gQnrY8Q== X-Received: by 2002:a19:f00e:: with SMTP id p14mr4876955lfc.94.1560514316299; Fri, 14 Jun 2019 05:11:56 -0700 (PDT) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id p27sm459683lfh.8.2019.06.14.05.11.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 14 Jun 2019 05:11:55 -0700 (PDT) From: Sergey Organov To: Sascha Hauer Subject: [PATCH RFC 5/7] serial: imx: set_termios(): preserve RTS state Date: Fri, 14 Jun 2019 15:11:32 +0300 Message-Id: <1560514294-29111-6-git-send-email-sorganov@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1560514294-29111-1-git-send-email-sorganov@gmail.com> References: <20190614072801.3187-1-s.hauer@pengutronix.de> <1560514294-29111-1-git-send-email-sorganov@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190614_051158_239389_18093F12 X-CRM114-Status: GOOD ( 10.81 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pengutronix Kernel Team , NXP Linux Team , linux-arm-kernel@lists.infradead.org, linux-serial@vger.kernel.org, =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= MIME-Version: 1.0 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 imx_set_termios() cleared RTS on every call, now fixed. Signed-off-by: Sergey Organov --- drivers/tty/serial/imx.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index 8ee910f..de23068 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -1564,6 +1564,13 @@ imx_uart_set_termios(struct uart_port *port, struct ktermios *termios, spin_lock_irqsave(&sport->port.lock, flags); + /* + * Read current UCR2 and save it for future use, then clear all the bits + * except those we will or may need to preserve. + */ + old_ucr2 = imx_uart_readl(sport, UCR2); + ucr2 = old_ucr2 & (UCR2_TXEN | UCR2_RXEN | UCR2_ATEN | UCR2_CTSC); + ucr2 = UCR2_SRST | UCR2_IRTS; if ((termios->c_cflag & CSIZE) == CS8) ucr2 |= UCR2_WS; @@ -1633,7 +1640,6 @@ imx_uart_set_termios(struct uart_port *port, struct ktermios *termios, imx_uart_writel(sport, old_ucr1 & ~(UCR1_TXMPTYEN | UCR1_RRDYEN | UCR1_RTSDEN), UCR1); - old_ucr2 = imx_uart_readl(sport, UCR2); imx_uart_writel(sport, old_ucr2 & ~UCR2_ATEN, UCR2); while (!(imx_uart_readl(sport, USR2) & USR2_TXDC)) @@ -1641,7 +1647,6 @@ imx_uart_set_termios(struct uart_port *port, struct ktermios *termios, /* then, disable everything */ imx_uart_writel(sport, old_ucr2 & ~(UCR2_TXEN | UCR2_RXEN | UCR2_ATEN), UCR2); - old_ucr2 &= (UCR2_TXEN | UCR2_RXEN | UCR2_ATEN); /* custom-baudrate handling */ div = sport->port.uartclk / (baud * 16); @@ -1679,8 +1684,7 @@ imx_uart_set_termios(struct uart_port *port, struct ktermios *termios, imx_uart_writel(sport, old_ucr1, UCR1); - /* set the parity, stop bits and data size */ - imx_uart_writel(sport, ucr2 | old_ucr2, UCR2); + imx_uart_writel(sport, ucr2, UCR2); if (UART_ENABLE_MS(&sport->port, termios->c_cflag)) imx_uart_enable_ms(&sport->port); From patchwork Fri Jun 14 12:11:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Organov X-Patchwork-Id: 10995177 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6E2C7924 for ; Fri, 14 Jun 2019 12:13:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5EA8928668 for ; Fri, 14 Jun 2019 12:13:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5CF2D2866D; Fri, 14 Jun 2019 12:13:54 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 04CDC28672 for ; Fri, 14 Jun 2019 12:13:53 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=Cct0dsv1dBIa6RWBT7cvjJkVQsLUO6HGGLSCvNZEGoA=; b=NsmipmNIAH+IUZ2NcZcDRMl6j+ YE++shlgZXcja1EN43YnnD5zsle7Kosq22QAA5v0HaLmzP8/0TrrdqzNTIgMNdGP22wNV9x0FMrm7 JwEtfTlmfVIz98edeTaRlgTAc0GIWutQQYMDIJJ/4dUtxIfS1Y9PAQGP4FsNh0BTqkUSJoya8Nsh9 5ncpQnXVX7Urp66XXFEkk59fj9eEHeKb+eutSn0TSId9Obk+I0QU0wuq3vve4Bb7/objHh4VMCedX kfgVr0F2C7OrWbFOAvXEMcYsQ1/LCFwlH/oEqVgVoGEOQRIMpHBrzHGQtJmpKLcBTvqzAfqxqn8RZ zHRaSQ4g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hbl5X-0004Oi-3Q; Fri, 14 Jun 2019 12:13:47 +0000 Received: from mail-lf1-x141.google.com ([2a00:1450:4864:20::141]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hbl3m-0002pr-KY for linux-arm-kernel@lists.infradead.org; Fri, 14 Jun 2019 12:11:59 +0000 Received: by mail-lf1-x141.google.com with SMTP id y198so1602807lfa.1 for ; Fri, 14 Jun 2019 05:11:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MDH+SHphi2du8HQmnp7WkqZowZkrn1A0IGK01w7XZi4=; b=tjFyKsoOmlqoDIYNiaw0kw6MN9s1Upm314ctD6PUnNY3UjlUOhmS2tPXI+dvHPVLCS TmH9Wg8+j+AL6lAeQx10dXaWiGlnpIYAYzUw7eDTJbC0hV6zyAvCN39tAPWEbpixyf77 N6vK+d48EAdtUBSFzbgr7k2hAJ9hk2YIFEVCzxo8/fSEVxcyJVQ+HMKiDfrLuf/DGsEb mqFfqHhVZZXkoBNJfHEjaoXHL8T6P/thlKSELLZOO82Ny5/0b5g+IzuhM5+DXfZ6cXOt a8sRWPeOlQr2pf0k5sVXJLsD8nHS+6NYWmLcgH2C1E9/OMca6uOYmmrFDcxPen9Ok9/s QIEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=MDH+SHphi2du8HQmnp7WkqZowZkrn1A0IGK01w7XZi4=; b=uA2DYCHg17DY6Im7xyWjsR+IJAadefGYGdBCVxc8BZ0QmzwkPbtaMXe3f4eO5GXN6m 0huXh4GlQWWB5yTbvA1Q/u5P4IzPk5EkaZSRCeL9huRsyas+TaLPYG9CwsHSPKbFJxCH u2GARZpl2/VfxUOwWfuDL9lCKlsyCRnMeeiK+LPUZPvMwdQZe7EvJ6h8XpY6wS1dF/Uu XFbMz/16m8h9d6sG6jJohEUzXA3DQLUuj9ZuL5CAF0BHb9RiYBFDr0+e1qFjbfMXi4Cv K6vjGeafXa1JDK8sLf2usN7mg5ncMWIa0n3P63pGeH/INDB3zL0mwJqd4X133Q4lYzGv y87w== X-Gm-Message-State: APjAAAXzVUpk4nJlqHAULSB7nyX/eiV6LQ5AJZhSlxoOSPeoGijo3THj I2E2LOaSAd4mU4892T0NKQ39cBOo X-Google-Smtp-Source: APXvYqzUW0zaN2dztJMASk7r2O0ps7VxazW/j1SIteqZxnYzGbKqLOxtxLTGrUwrCTBm6XYDQeaLbQ== X-Received: by 2002:a19:230f:: with SMTP id j15mr9538698lfj.122.1560514317209; Fri, 14 Jun 2019 05:11:57 -0700 (PDT) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id p27sm459683lfh.8.2019.06.14.05.11.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 14 Jun 2019 05:11:56 -0700 (PDT) From: Sergey Organov To: Sascha Hauer Subject: [PATCH RFC 6/7] serial: imx: set_mctrl(): correctly restore autoRTS state Date: Fri, 14 Jun 2019 15:11:33 +0300 Message-Id: <1560514294-29111-7-git-send-email-sorganov@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1560514294-29111-1-git-send-email-sorganov@gmail.com> References: <20190614072801.3187-1-s.hauer@pengutronix.de> <1560514294-29111-1-git-send-email-sorganov@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190614_051158_707428_ABC5D7AB X-CRM114-Status: GOOD ( 13.06 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pengutronix Kernel Team , NXP Linux Team , linux-arm-kernel@lists.infradead.org, linux-serial@vger.kernel.org, =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= MIME-Version: 1.0 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 imx_uart_set_mctrl() happened to set UCR2_CTSC bit whenever TIOCM_RTS was set, no matter if RTS/CTS handshake is enabled or not. Now fixed by turning handshake on only when CRTSCTS bit for the port is set. Signed-off-by: Sergey Organov --- drivers/tty/serial/imx.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index de23068..bdb8b6a 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -970,10 +970,19 @@ static void imx_uart_set_mctrl(struct uart_port *port, unsigned int mctrl) if (!(port->rs485.flags & SER_RS485_ENABLED)) { u32 ucr2; + /* + * Turn off autoRTS (UCR2_CTSC) if RTS is lowered and restore + * autoRTS setting if RTS is raised. Inverted UCR2_IRTS is set + * if and only if CRTSCTS bit is set for the port, so we use it + * to get the state to restore to. + */ ucr2 = imx_uart_readl(sport, UCR2); ucr2 &= ~(UCR2_CTS | UCR2_CTSC); - if (mctrl & TIOCM_RTS) - ucr2 |= UCR2_CTS | UCR2_CTSC; + if (mctrl & TIOCM_RTS) { + ucr2 |= UCR2_CTS; + if (!(ucr2 & UCR2_IRTS)) + ucr2 |= UCR2_CTSC; + } imx_uart_writel(sport, ucr2, UCR2); } From patchwork Fri Jun 14 12:11:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Organov X-Patchwork-Id: 10995193 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 266F976 for ; Fri, 14 Jun 2019 12:14:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 173FF28688 for ; Fri, 14 Jun 2019 12:14:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0B04528678; Fri, 14 Jun 2019 12:14:22 +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=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED 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 AA3FE28688 for ; Fri, 14 Jun 2019 12:14:21 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=vAjmB1wdTrX332UKXQPmDzNhnrmynfLgYpYFry7YkTw=; b=jLWtLra0miGgBa4f8SfUiXZiBu guedF4dgNn42RN/buHK6FybEU6o1hthgm0Mantm/E7IHSHje2ZnBVHreks9PPcy/xOaBrG+xWSisJ 0K9qxxp75fwsdNozp8bymfKYpguuhB2jeIo5dbHF22GF9OjvlEELayAQG6Aa+qgLSSGn8eeIte8/q CzTMxo9bAqveouxDH0CrregZ41iI5LgohyO1fDZU/SYppNJtYEaBSFD0DUswJRPyPBTeQowOdL3IS RpugUWhK848xeoPXpQExnzMN4S61YvSfdeYvxIODY1t7ctW70qhCNTvgWKeUw/fJg280S8R5abCav B8y9zqDw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hbl5y-0004id-7d; Fri, 14 Jun 2019 12:14:14 +0000 Received: from mail-lf1-x143.google.com ([2a00:1450:4864:20::143]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hbl3o-0002rg-0H for linux-arm-kernel@lists.infradead.org; Fri, 14 Jun 2019 12:12:01 +0000 Received: by mail-lf1-x143.google.com with SMTP id q26so1587757lfc.3 for ; Fri, 14 Jun 2019 05:11:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Pvz4HiqActHfdiRpn2UDi2+QMjvhRluYztx0f3X9Mpg=; b=ALprnGLKTGKIqLJ3QZLWDYLTuJaddVtQQM8XIhhQWPKi+WmSl1BLYvmCMjWMObXSWk E2F7WblfXqBqllh9IRtujow7PcUcprDpME3bsE8aA70KNvyOsuK7uJGLoFyHd59F8OdA Jp+KkN6U2p0+HElhlmfTJmDrC4Y/7CCnsbffBt+8PaIEzmtdzvYtJYHSnK63rCe3rTBl /XicR+oanY9KVZs32ZP0FqWRnqGHxl2dQjLH8Cm8/K0vYJ6jZvGeIChZurZShL5Cjlyb ngUiITPldNa92Dkh2gLfXmUnhkZtOV7pz9wOw40Z7NYbjemsvGVnit2vzn/qASLpfaHF rOOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Pvz4HiqActHfdiRpn2UDi2+QMjvhRluYztx0f3X9Mpg=; b=otmydmRclQWoS20bTSkbzUVPop3aCEjygkQ+pUAWoMHU1mlKd2lG1SgWQVD/GR5lVz 8jmDHqNDd0vOEpmwBjX+O6bEWMj6IZKMONZnCP06PJ/0Yj7LuOD9JlWieAzgYytoaEXn K9Bn/z3Z1yIF9zz1Vp5Po4PprJQ0Ji6byZoYGFAdCUmhhIzEnrxTSh19RVnuGDaSEfHz zcfmnTlnVR609GA8OqDCY/mlbpP48jQz0CEzm+tx3FOhixFA+9u/jmtb2ONQOHWIeVgf fAWJrHirbsTLCj7wMVO91CedyX3SgE95Y/kAMxcDLAm4fWYtC2LI2r+kDJCMPHBL20nI FZAw== X-Gm-Message-State: APjAAAX7SKJqe3hME9qDSpO5ADkloUF3zBDschC/CsR2q0wx/cS07IZk 9PwP8vwQwbVl1vMl0TTtgXE= X-Google-Smtp-Source: APXvYqy4Z/aRBglvdZ5tjtESTDHX1S/1sS3lr4b01PScZdlYvgVS908OnmwCYDrE/8k36xjHntXm9g== X-Received: by 2002:ac2:5981:: with SMTP id w1mr27213594lfn.48.1560514318592; Fri, 14 Jun 2019 05:11:58 -0700 (PDT) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id p27sm459683lfh.8.2019.06.14.05.11.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 14 Jun 2019 05:11:57 -0700 (PDT) From: Sergey Organov To: Sascha Hauer Subject: [PATCH RFC 7/7] serial: imx: get rid of imx_uart_rts_auto() Date: Fri, 14 Jun 2019 15:11:34 +0300 Message-Id: <1560514294-29111-8-git-send-email-sorganov@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1560514294-29111-1-git-send-email-sorganov@gmail.com> References: <20190614072801.3187-1-s.hauer@pengutronix.de> <1560514294-29111-1-git-send-email-sorganov@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190614_051200_061936_3D58555C X-CRM114-Status: GOOD ( 11.43 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pengutronix Kernel Team , NXP Linux Team , linux-arm-kernel@lists.infradead.org, linux-serial@vger.kernel.org, =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= MIME-Version: 1.0 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 Called in only one place, for RS232, it only obscures things, as it doesn't go well with 2 similar named functions, imx_uart_rts_inactive() and imx_uart_rts_active(), that both are RS485-specific. Signed-off-by: Sergey Organov --- drivers/tty/serial/imx.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index bdb8b6a..cb28cff 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -402,13 +402,6 @@ static void imx_uart_rts_inactive(struct imx_port *sport, u32 *ucr2) mctrl_gpio_set(sport->gpios, sport->port.mctrl); } -/* called with port.lock taken and irqs caller dependent */ -static void imx_uart_rts_auto(struct imx_port *sport, u32 *ucr2) -{ - if (*ucr2 & UCR2_CTS) - *ucr2 |= UCR2_CTSC; -} - /* called with port.lock taken and irqs off */ static void imx_uart_start_rx(struct uart_port *port) { @@ -1598,8 +1591,10 @@ imx_uart_set_termios(struct uart_port *port, struct ktermios *termios, else imx_uart_rts_inactive(sport, &ucr2); - } else if (termios->c_cflag & CRTSCTS) - imx_uart_rts_auto(sport, &ucr2); + } else if (termios->c_cflag & CRTSCTS) { + if (ucr2 & UCR2_CTS) + ucr2 |= UCR2_CTSC; + } if (termios->c_cflag & CRTSCTS) ucr2 &= ~UCR2_IRTS;