From patchwork Wed Jun 26 14:11:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sergey Organov X-Patchwork-Id: 11017945 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 A5D7013AF for ; Wed, 26 Jun 2019 14:14:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 94D122857D for ; Wed, 26 Jun 2019 14:14:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 88CF2286F3; Wed, 26 Jun 2019 14:14:45 +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 D42F4288BD for ; Wed, 26 Jun 2019 14:14:44 +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=do4VjB5pGYjSsOk+Y8Q+prXU9sTSmVK+NkzPutPpnRs=; b=i6o48SLtQszXkAadzXjocPmnEI 610qY0KSZFcQaZEjOQ7c8s7bMYPvdy095C7SVhH3IdqfQldudVHLsWZPKH2EJKUV2uKKF2V04ZBPw Wr8qgsa/wOuNxThF8PxK1OqhVQNkeLKm7MkTFYP/OwWAGZovDGFD9uiK91N3zurdWK37z4YSKLy9w ZzO8AMt47Ato1Uy3bMJhBsr1XYlT4QtkEwHBzvGTzHqfeY9bSwv6Trn+adOQ61JWiGlheqPrb6Q5I ryzFTyreC0M3euFJ/KEvXyLUkB6PPo5oltnTu5LyQh5iYVUS1epC9jN+2Ydnt9TNCJI38w9wlhgAT kNk1alKQ==; 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 1hg8h4-0004CL-FP; Wed, 26 Jun 2019 14:14:38 +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 1hg8gl-0003xx-Jm for linux-arm-kernel@lists.infradead.org; Wed, 26 Jun 2019 14:14:20 +0000 Received: by mail-lj1-x242.google.com with SMTP id m23so2356351lje.12 for ; Wed, 26 Jun 2019 07:14:17 -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=bZEuBr/u7QmcmUUX/8Ym5nImEHkVz1m2bXUhPQcNDuE=; b=PSS223db/d4jR+7QIlHArthBCcpQqnYC18l7YmJGLgfztQImucQ9dT1X9xs0qtTis2 gYnkmfT5qfyFRpplR2r+qA0NX5D3VfPlGczY1z1dyzCrMrGQF/rClvOTdgW72zWSUs4L Kpn2C4UfaJxv91FtrCm7Tioe0NYV4xzlllwqtJTY1qgvPfwSxZ2DtY1o9G1KJfa0dFO/ 2R3o79DIoEe2KhqfXlq44zZCe6YiMLYeJCWp3hyGx8LCFsyhwDBj/YOrCKltKhcIR+n5 AeBGt9Iy4xR8Wqgh70rpydWSZ+V4iP2y/LTSIR6uzbdT/ulcZ6Iw0GqrwyLi9NDWuLH+ kPhA== 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=bZEuBr/u7QmcmUUX/8Ym5nImEHkVz1m2bXUhPQcNDuE=; b=cS+TVFPMEO/A6IWFnKyPCRDBXldO0du5Lgr9EydUHrP6xsrL4eDy/089Xz3Sc6am1e kfJKpPHpZovBffYBJoLiHzNo2yHt/r1qf9wWUL/zs3OEe2b4dMdGpseVZUHtvJE76wB6 YUAsTypf1QyX7U2k7i6A+fcL2cLmlnwOs+6PUwcagNiGP1v+H9hE5w7bU8wikzLLVKDl L7t4yzzU3pGRR9VUGn4mlMvaiIVpR4sb637lvs86YQAcgeCbXXtvajytT5N2mToeqoEp Yi/UbWhEEKf1ZFWdOtGACOGPBmK1dRxlGhsBxGoBsYAR2Bj1XgNVxyyGYiPFGNgDNtzV 6org== X-Gm-Message-State: APjAAAXUQMXK9CPraYfA8ZKcQLr1W4nbFHYYHC7MWqVi707C21M5vfXa TRKkflCldOqxN9KmX8d6OEO9edi+ X-Google-Smtp-Source: APXvYqzoEA2Ur4kBMLRQMwb8qjOtucgHIrwKndnQ/vYw7CBLOdEYrcXt8Ekye1Bai8jgGYBgMf8BVg== X-Received: by 2002:a2e:9250:: with SMTP id v16mr3048462ljg.89.1561558455912; Wed, 26 Jun 2019 07:14:15 -0700 (PDT) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id 25sm2863825ljn.62.2019.06.26.07.14.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 26 Jun 2019 07:14:15 -0700 (PDT) From: Sergey Organov To: Sascha Hauer Subject: [PATCH v2 1/7] serial: imx: fix locking in set_termios() Date: Wed, 26 Jun 2019 17:11:27 +0300 Message-Id: <1561558293-7683-2-git-send-email-sorganov@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1561558293-7683-1-git-send-email-sorganov@gmail.com> References: <20190614072801.3187-1-s.hauer@pengutronix.de> <1561558293-7683-1-git-send-email-sorganov@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190626_071419_655882_CF6C46EA X-CRM114-Status: GOOD ( 13.48 ) 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. Reviewed-by: Sascha Hauer Tested-by: Sascha Hauer Signed-off-by: Sergey Organov Reviewed-by: Uwe Kleine-König --- 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 Wed Jun 26 14:11:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Sergey Organov X-Patchwork-Id: 11017951 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 3775913AF for ; Wed, 26 Jun 2019 14:16:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 251182871A for ; Wed, 26 Jun 2019 14:16:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1F1712880B; Wed, 26 Jun 2019 14:16:04 +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 7DC6E2880B for ; Wed, 26 Jun 2019 14:16:03 +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=QDpAb6eLspu7RsM4IAGnIUiw+eE/0eNuKIoYIReJJPU=; b=USDGf/I6M+Pz8TYgDuevRPD61w nuvgBZ/P3oMlmI7AHWErYfzeFcCTXWDbhxSX2PlDik1ggCd+h3KmVpuunXa375kIRETsr50XPLylz dkYBxQC+8PGDuWj13teIbfy/HnmKjutCT30SBF9fOMrQZMQhdHZb4C63+bUnaRK0MbEvQumI25tZn AXfKINSboUIhIDnOaW447jNsOJ1aZeks3/izfnNvW9LXIpm0heccefeGkZGz0neNroisMK+TdwyHs hQDL5BKBi3pZzFrfFH3YczAA1J+uwLLA3BOUBaYhL+fJwpHQYWh6JGWtD9lGcBUlHvIGjMPsBMq9N 6TQVoQyQ==; 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 1hg8iK-00069Q-GM; Wed, 26 Jun 2019 14:15:56 +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 1hg8gm-0003xz-I5 for linux-arm-kernel@lists.infradead.org; Wed, 26 Jun 2019 14:14:22 +0000 Received: by mail-lj1-x244.google.com with SMTP id 205so2373618ljj.8 for ; Wed, 26 Jun 2019 07:14:18 -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=SjpXSg531ioWOBzpBIFjjzIi5yRvk9QMHcPgjilDAr0=; b=qca4raonl1jkAymrg6nNDfK2OxZwaHqAPzBOVKKzmmIaGVOgkn9U5Sug8izqRqiEgq p9i945fgppbhD/Wxh3QoI+0pABdNgTcyf1KgEVPK4ZfK1k1DDgORdOn0QGmhVldkYpqE 6xF7IvU8nPR8J2G7ZKBEncmu754DR6j1HNDntCiDM8TBaYuxCC1/1MeIKkknUmdHyMK7 ifkg433l8teKUsPih39z12s1yxtg69E1kCzXyp//aXxCFI854XTxAEV+3M5axsFeMyS1 ngyjdMVS7qCt9L7eBE/yGIo0wUQxtwFCqos7DKXUQHd+a7YRPMWqf6DKBOSiTFil0L93 OsIw== 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=SjpXSg531ioWOBzpBIFjjzIi5yRvk9QMHcPgjilDAr0=; b=ZEMTclTNBqN+Wc9o4bX2QinFdqXdCfbiyu2r90x4mjIpvRAveGRAsMCQY3OSByEJ+t gQnm0zRLGdBStSW5O7UYwT3U6R2B5HFPH4IhOLYeCGC7isdtjPlINVg74K6zq8L1oxw3 DXgWbXIlH2fST3sdmcclbom7QoSbJtWy90Ex774wfrDSCfKbj8xQh7YY6tI7Tcc4qj4V 0HiBvl+E6pD87aIa3OAqxFjzgjPTOeElcrwRIBQF5JwTyuGh+M990BRBvPOuvHTfx9vT nEynOuqpx8g09k5EqSunpedl8S1QY0edwBBuNaDVS3F1m5t6CbUdfJAaNmFZ3Y/Aug92 EQsw== X-Gm-Message-State: APjAAAULC9mXXjERB8ru7pXb0u8sJL4fSrocy6PaUvfBtuHvMlE5XCQm jeHmXBUYi/uoP2ZhYupC6vU= X-Google-Smtp-Source: APXvYqw5/oAtAzvXc7HUCNpUYYoZ2KlQOF8a5I/VNuxYuw3AuZvADuJi9KXokLYHddmUnp8SlU8Vgg== X-Received: by 2002:a2e:8155:: with SMTP id t21mr3108879ljg.80.1561558456870; Wed, 26 Jun 2019 07:14:16 -0700 (PDT) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id 25sm2863825ljn.62.2019.06.26.07.14.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 26 Jun 2019 07:14:16 -0700 (PDT) From: Sergey Organov To: Sascha Hauer Subject: [PATCH v2 2/7] serial: imx: set_termios(): factor-out 'ucr2' initial value Date: Wed, 26 Jun 2019 17:11:28 +0300 Message-Id: <1561558293-7683-3-git-send-email-sorganov@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1561558293-7683-1-git-send-email-sorganov@gmail.com> References: <20190614072801.3187-1-s.hauer@pengutronix.de> <1561558293-7683-1-git-send-email-sorganov@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190626_071420_629304_6E8265E2 X-CRM114-Status: GOOD ( 10.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 Set common bits in a separate statement to make initialization explicit and not repeat the common part. Reviewed-by: Sascha Hauer Tested-by: Sascha Hauer Signed-off-by: Sergey Organov Reviewed-by: Uwe Kleine-König --- 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 Wed Jun 26 14: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: 11017949 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 8214E13AF for ; Wed, 26 Jun 2019 14:15:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 703C92811E for ; Wed, 26 Jun 2019 14:15:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 64AD628450; Wed, 26 Jun 2019 14:15:31 +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 0209C286F3 for ; Wed, 26 Jun 2019 14:15:30 +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=SxLG6zqW/wKPPMG1+pRHS0PzUUnu21pIZg6NkOjRmZs=; b=Y9R9FpG7sQddvjowKgEj9jRT/L Uyzw7Qr/waxyJUsEKjLNXNwTdxGLl4XIgBqZc+qfHLRS1QiU74YxZWPtUTi3cwa7IfRzi3bVrxv33 DYOSvCYa6KKfHoucW3LRjSxdupi1eBKK+LTs7tfWnujX7ZL90a0aQoLFzch+YOPsTJXgNs0XFX/S9 d19tPe+Nu7vdaNTJnrftRX23/vKmbdDWZNsw/sjROmk5+P8eFwfMlYwSlMHbFtWW6zWZx0xY1n/5F 6JuOpQgMHC4+KZQY1PgzPrEQZkf/aVQ40QMbhdhXYUKoFhE1EYlb9Q+FVmauoO0zyuQisrXeiaUYr wGXnuROA==; 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 1hg8ht-0005tA-G2; Wed, 26 Jun 2019 14:15:29 +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 1hg8gm-0003y2-Hy for linux-arm-kernel@lists.infradead.org; Wed, 26 Jun 2019 14:14:22 +0000 Received: by mail-lj1-x244.google.com with SMTP id h10so2408666ljg.0 for ; Wed, 26 Jun 2019 07:14:19 -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=mRhyyilptEVPd04WdgykTEukksr9XwSZnIYd4NBzYsQ=; b=WOsdVMo2sTqQcIO7BzQhJ9DHnEJ3DY7P8bNKT1VNcGqjAUlnFGAZY0dK4XZYnH5ua1 v3Tfcu8MMImCEs2vjwsLFPMQOVWRktM9ufCg39KKPc0Y1M/7trTsHbsKVTCh4IqOENH3 Ib5gg+aBvNiYqJvlRQStweOnKbfqlcSGwUwtH2gkGUm1metLMJFw2kerj8IQnanQc7l5 nRBrydWsx5dlYPJrZMiZn3Sk9gJixMNNlgSPumNI90w31xO6weAHTkbKxd2hcj2l0C68 26LkRmMyqE/okSD0EhAtIb0JR8w7amcb70WpMjaA3v1L7RRm66yMV11PFOEYxGrlRI8t +5VQ== 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=mRhyyilptEVPd04WdgykTEukksr9XwSZnIYd4NBzYsQ=; b=BMhz6DNlgL2Mf/NthtXOlAu3tsD+1e5fQTSexqVQNXvvHFjzQ/jaiCax0xNe5mJv4G FBPP55kFhtCYcd2uNs7uSjDdBOE5zcvp/0wI8AtXsY/Cpz18eUIa2YD6mPmlnixL4jld wuEKukftm1WevkBjw8HJzDu+eVqJ7MthI8MypQ/ZKGo5JM+XWuUCZlkdiTU85S97M6M9 v5eYwdifif87t2Tm50TibKmZGxUUVXOWL+W+8xUipiqe5F9uCc4UGYivBzGrImqblKoQ rCzfg2Op4jif+ST3kyjLXrkM9Zmqdl0zYJbE5/WbRhaoHKuDG35I+leqtUWHBpIpaWEJ tSxg== X-Gm-Message-State: APjAAAWONkDST8HXV8PntDyn3BWT8xB1YJSzqdFt8tydISozBAd/NviS jJBhNUv8K9KPkRmCJnXrKB8= X-Google-Smtp-Source: APXvYqxk6g01vSfZluLIWn9pL9tzMRhVHf6a8E/WPw/jzMv8uirCzehRsPM4NYsa4A7CfTEhMI0y+A== X-Received: by 2002:a2e:86cc:: with SMTP id n12mr3064173ljj.146.1561558457810; Wed, 26 Jun 2019 07:14:17 -0700 (PDT) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id 25sm2863825ljn.62.2019.06.26.07.14.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 26 Jun 2019 07:14:17 -0700 (PDT) From: Sergey Organov To: Sascha Hauer Subject: [PATCH v2 3/7] serial: imx: set_termios(): clarify RTS/CTS bits calculation Date: Wed, 26 Jun 2019 17:11:29 +0300 Message-Id: <1561558293-7683-4-git-send-email-sorganov@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1561558293-7683-1-git-send-email-sorganov@gmail.com> References: <20190614072801.3187-1-s.hauer@pengutronix.de> <1561558293-7683-1-git-send-email-sorganov@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190626_071420_613868_912B3AAA X-CRM114-Status: GOOD ( 12.68 ) 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. Reviewed-by: Sascha Hauer Tested-by: Sascha Hauer 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 Wed Jun 26 14: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: 11017947 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 B7C3613AF for ; Wed, 26 Jun 2019 14:15:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A4CE9288AF for ; Wed, 26 Jun 2019 14:15:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9875C288EA; Wed, 26 Jun 2019 14:15:17 +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 3CD6F288DD for ; Wed, 26 Jun 2019 14:15:17 +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=w47jJeNj2MXEs/AwY0ZIftgwEXKiPHkXxyL5QsXA9rI=; b=PSvoEa8XU0TBK1OascIv2v6pwj O2lEcMbzTR7G7p1/CZAY7tvL0dvt1pfc4OMCUYU/QR5GZikq9TxaOzyjrDNLC4jwEgPVN/6F3p8ce NUaEKuqRByOzqfFIo9UzjHQzKPZyYi4bo5aZndbjJSQPO9fK+PH1+5HCBYoIAv7XZ1xJq57Ujuh6n VQMM6HHAllyhSah6+l+za+/pviPVuM7+nlAJxq44DLI2YfsorBWsIw/2LWMfMSSoEmxtiFzk/u4uW kZwSjFbsJM5mWfeZBAnxKOu2dOcQ0lvg4s0t76rQOXXq3hRjIG/H5XRaThI2HEkSrVusKhMbpiGkY nZWhPWIw==; 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 1hg8ha-0004Ro-Bm; Wed, 26 Jun 2019 14:15:10 +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 1hg8gm-0003yF-I7 for linux-arm-kernel@lists.infradead.org; Wed, 26 Jun 2019 14:14:21 +0000 Received: by mail-lj1-x244.google.com with SMTP id m23so2356546lje.12 for ; Wed, 26 Jun 2019 07:14:19 -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=942xX7/V43Ir1tZd4dDu7UDtPNxQiTaRZHtBvgqzC20=; b=vEcfd1F9kU6c3snTar1pRwW46ihzxse6+Y4VUj3JAJxwmk9OCvFHmCrgXUkECXemrV Zymaf5FxHIUjJpINJX1aZv67oSwDU6yvr4+D8p9ksaTnzQqQhR2Gzvj+EsilGzI4Q/MZ eRhsSYvTl3Mmhm+fJtjBz3xzGGjmvRsS2meP6ANBFPaIwfSFG/mcAgrQQ/4mIo1hlksG 4l/x+5uF8kIXWJFbnXFgeEceXfL4zD80Rl9LO3YE9b1/bIJc6Zl6OTA4mFRMJmz0nfMn fA71nOeZTEmAjIiAFoLsnseNERzeivd+Et75vWsJo6qg0S7csKHSaFEihFyOsalu1MXP IVyw== 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=942xX7/V43Ir1tZd4dDu7UDtPNxQiTaRZHtBvgqzC20=; b=E3uohzI+YGsbfJZXVEZPRxWEh1ivAAeACibMZD4HvG/13CRHeVQY74egRvGmyjzG+s BGyjYXfTTJi0EI+JXfxNa71XK0LA3GWONw4VKQrCMA4HPtsFaFAlaU1yWuvnHywISeRV fcGJMBrrvYbb0TPBN/5eN5SlfPpjVjm9myWOUiEZ52racQuR5UYi1CaaBEz4S9NS7/Sd I9kbmZsB8OJQWwPwa3/f92UnYb1OoKNm63VO0KJZ5Wp6v9+0bZCdVELuBV2UZE/PCtcB CGOxuO63LmW4ulHKBq/qh/SXl2IAfjyxxky2/BdjMymTV3FE16N7cjPfAWueanJ1pN6U ibUQ== X-Gm-Message-State: APjAAAXQV8HMym3ztuBupj2g9RdVRGMM2N4pqgZd1aadS9EzCzqK19jG 0blp3EVl/oPgkGMzu2VN9oA= X-Google-Smtp-Source: APXvYqzBCD/3G0Iiqs94s9c+nv/izaxNQc3GweYG/4vph5agy17vywn3RK+kSgUPvaJgNmPczA31fw== X-Received: by 2002:a2e:9198:: with SMTP id f24mr3177704ljg.221.1561558458731; Wed, 26 Jun 2019 07:14:18 -0700 (PDT) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id 25sm2863825ljn.62.2019.06.26.07.14.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 26 Jun 2019 07:14:18 -0700 (PDT) From: Sergey Organov To: Sascha Hauer Subject: [PATCH v2 4/7] serial: imx: set_termios(): preserve RTS state Date: Wed, 26 Jun 2019 17:11:30 +0300 Message-Id: <1561558293-7683-5-git-send-email-sorganov@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1561558293-7683-1-git-send-email-sorganov@gmail.com> References: <20190614072801.3187-1-s.hauer@pengutronix.de> <1561558293-7683-1-git-send-email-sorganov@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190626_071420_612348_889DCBEE X-CRM114-Status: GOOD ( 12.11 ) 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. Reviewed-by: Sascha Hauer Tested-by: Sascha Hauer Signed-off-by: Sergey Organov --- drivers/tty/serial/imx.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index 17e2322..e0f5365 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -1563,7 +1563,14 @@ imx_uart_set_termios(struct uart_port *port, struct ktermios *termios, spin_lock_irqsave(&sport->port.lock, flags); - ucr2 = UCR2_SRST | UCR2_IRTS; + /* + * 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_CTS); + + ucr2 |= UCR2_SRST | UCR2_IRTS; if ((termios->c_cflag & CSIZE) == CS8) ucr2 |= UCR2_WS; @@ -1632,7 +1639,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)) @@ -1640,7 +1646,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); @@ -1678,8 +1683,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 Wed Jun 26 14: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: 11017955 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 B7560924 for ; Wed, 26 Jun 2019 14:16:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A076A287C5 for ; Wed, 26 Jun 2019 14:16:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 94BC8288B9; Wed, 26 Jun 2019 14:16:43 +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 DB22C287C5 for ; Wed, 26 Jun 2019 14:16:40 +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=1s5jGfzFGkuG5VKOHxHoU3/ZPrQwCuIWharDSgFbHIQ=; b=mERX0zoHZqK8ZBHTnEDUMay/tA XVqdQtG3ZEMu7aqvQppnIp/IpV+ZHoi0eSFmUkobZQNBX4uqJTwG+ndptwbsg7WSRJAqdgI0WjdtP 0Q1ICG/YOLY+es1zCD4UgBB8082CuzzWQD8AF69Zrmth7sjMl57AS3APDzWVKBPN9LW2yS5x9zyUf MCqsnky0x+wm4+2Fx27DUmD8C5F80qyxvAeP7tB2yVpsVdwgGBJBngh5I6p/esKAwQ3iPxpI/yQXs yqyWSrXAYFFS6/K4riIbUShKjDF44s7C1fIJe092mzfQZZS661XWNL0bTBtMEUZ23p00UrlYYXA3Q V+nzwGTQ==; 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 1hg8j0-0006bF-Qw; Wed, 26 Jun 2019 14:16:39 +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 1hg8go-0003ym-KS for linux-arm-kernel@lists.infradead.org; Wed, 26 Jun 2019 14:14:24 +0000 Received: by mail-lj1-x243.google.com with SMTP id 131so2385862ljf.4 for ; Wed, 26 Jun 2019 07:14:21 -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=PSCP97EAMw9kJ5xr2biP47mIP/F/75GsSBuiL+rMzdw=; b=mqUioiLReGnEQt+HM3TnWMKitnMv4iEElkv3Gxq/nhULQPVKwjqcrzDEiooO2YoSVo iM1wtpbL3kCH2M2N6HPi3q7Dhtr0Bxo9RY6kiySEIPyxEmbhw+FUIh5vmMV95XuR3USl 3EwQR+oSAGzlbo9eXaCP4cgS+DqXhTSHrsbt0TrpUSBBs5cRhywaFhUs4GKeOKcRiJ/x lCZVoj2RwhLu0G6nKLjevdfPaLJFpeJ/d4ID0VICG1G/csP2GrXd59yDmfUH+5hxkTxn TJhxWbOsYSHXtjqreBzsCLFGM7p0nxGCY3xLAsCbGmW5TIzMQCEpgITjWW6S3sguJKeA oC6Q== 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=PSCP97EAMw9kJ5xr2biP47mIP/F/75GsSBuiL+rMzdw=; b=ZIVROju8BMcYoNXAVWQT5bAbWBR2i9m0TWz0dVRLZQwb6ROpj27ORNo/fHA8RbEB9P q4LdFtOMHWPQ11zuGA9C9rMFKuxomUOFIfYnwjr4jlxOKhY6v+NyX8ysXHoOkdPlfU5S F057uTZSKzZhT0wiV5xJmYh23mEEfS699DRDolxl+jDcKniFr7Yp7jJgiXCiy3e7vhC9 j+hW7ri9t+3LUzFpE1VutBxkZMTFGTUSM0pW6TQFpl+NtNunq88OrD6dGTytf3f7b0xt Nth7qF2BnSxq0eEuTJsg8JRffqMPI2DlsP7njdKbQJ1+l9+HCMbCgV4hZSyhVzveeQC4 MvXQ== X-Gm-Message-State: APjAAAWdGx559vLptn4icIHBqGZxPuumYFiXMtTmRbobAm3keBxSl1E9 lATxw+4Kp2MjH4VaBUZxRjs= X-Google-Smtp-Source: APXvYqyuTVynFjGEcA3fo0upN/VPg2m8WVsm9Rnt8JOCdPSLblri7wBfunfXN82sWRjbNSecicxmbA== X-Received: by 2002:a2e:9b03:: with SMTP id u3mr3086619lji.15.1561558459745; Wed, 26 Jun 2019 07:14:19 -0700 (PDT) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id 25sm2863825ljn.62.2019.06.26.07.14.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 26 Jun 2019 07:14:19 -0700 (PDT) From: Sergey Organov To: Sascha Hauer Subject: [PATCH v2 5/7] serial: imx: set_termios(): do not enable autoRTS if RTS is unset Date: Wed, 26 Jun 2019 17:11:31 +0300 Message-Id: <1561558293-7683-6-git-send-email-sorganov@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1561558293-7683-1-git-send-email-sorganov@gmail.com> References: <20190614072801.3187-1-s.hauer@pengutronix.de> <1561558293-7683-1-git-send-email-sorganov@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190626_071422_723484_77163AE1 X-CRM114-Status: GOOD ( 12.28 ) 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. Reviewed-by: Sascha Hauer Tested-by: Sascha Hauer 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 e0f5365..4867f80 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 Wed Jun 26 14: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: 11017953 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 2D5EA924 for ; Wed, 26 Jun 2019 14:16:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C9AB2886B for ; Wed, 26 Jun 2019 14:16:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1AC5E288D8; Wed, 26 Jun 2019 14:16: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 B60AE2886B for ; Wed, 26 Jun 2019 14:16: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=0jeta4ZlEa7F5fBHpoukj8EKRvQbWIS7DFIr28pBd0A=; b=tIypKF6PvXef4QEGQ5ue189X9G 36pXxnvt5yue/vU6yC8XPzIShhQ5u4/9Fkf3EQFiBVdVMXwSDaRSxp1OfVveUukHz1IG49gnVhcgR wzIAKyNbr+w3A2irDlLIiOcFUyy7FbaF5/xixL6jz7Ltil/4GVUGMGCJYNI3law28xpF+RmEwePsG tbqxEUtsLrLhjOqGVDRVIFbeumgXm3p7Wkh0lBWPZ7JAeoIhpGG4/L6KFhUYH3ndQNGWgS7BG/udx NH3vE5/2OnSr7dsyxWmsSCZikNuLIIXAb6j6F57Tw83ooLoKIFCHGO0DmFKIfPtB270BppnAtn2FG lVwTLx6w==; 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 1hg8ic-0006MV-U3; Wed, 26 Jun 2019 14:16:15 +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 1hg8go-0003zt-2H for linux-arm-kernel@lists.infradead.org; Wed, 26 Jun 2019 14:14:23 +0000 Received: by mail-lf1-x141.google.com with SMTP id d11so1696159lfb.4 for ; Wed, 26 Jun 2019 07:14:21 -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=Cru3DQ0cf7AVa+7W6ow471nhNIp8xE7O+QraDjrOeNI=; b=oGSohR+AMbgw3RJe6dElbWB7kM/ng20QeMXi7srOmz1ae9AIpYC42091JUF7gRtRQI U6InvOg08QosR9ixVkmIIv8uBJ3Imd8Dhnj18XNyUgxhAsZRC1VDRY3xqlqT5RABwSrh J0nugtNshxwM97+dZSJs+IUkSIfEBMa8rqRMW/sYT/3vcUhXdb9kWi479vMmhCxpf24S f0Ocy1I+stdB19JV2iX4tFEtWt+b5bM29PWgVMpz4iqdgVMsRoVC1ftKK2JWKJDa3TaG 9mJ1r0Q9UbR0g/MCDrSa5X9SfOCKfKnp33T6i3zUQLNZ8GCyb7wUNyXfU08SFRW1+4qw 0g7A== 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=Cru3DQ0cf7AVa+7W6ow471nhNIp8xE7O+QraDjrOeNI=; b=PAA8w5Of2ndyQJl9to7uchIweWfp8FvBG/fI5uihM1MUXJ2TBJ6rUOAQnZn2f6xfQH LNPl2KYyEr++fmMWvhLwz1oOn6l2woXiDCuGMErszwx1hBujDXdRmE0IdidaNyihhGxH YNzLEl01LkgzCkEX9TinpC2YJgubF61ibn/5XpQujKEGFaU7MGR/4rr0cAaLFBpeH8bj xmknT962+88JrniLSkW7esVBXCOkmYyv7bf9otYQ1dA0Kjq9ETQ8LDHnTXYtsEZtiZdj O7nAisklsxEZw2ItayfAqo18z0wSb/4EF2kjy31zzysnMEpNh4mZFv3/U08J1h55Oe3V 056Q== X-Gm-Message-State: APjAAAXJB8eYW3O5LqsoGCDaqIcr0MAMfzAT830JqQR1NG0UJaGyouO8 fHAfr3Rqh6NJEFqmmV+n9f8BF7l9 X-Google-Smtp-Source: APXvYqyL1RGOMBYqi/6sv3nKZIVcrOLXsrmGA0M5Cj0IiQP51tp7X8MAQLS00+1fgkBYgDv6grPSfw== X-Received: by 2002:a19:490d:: with SMTP id w13mr2761425lfa.58.1561558460721; Wed, 26 Jun 2019 07:14:20 -0700 (PDT) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id 25sm2863825ljn.62.2019.06.26.07.14.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 26 Jun 2019 07:14:20 -0700 (PDT) From: Sergey Organov To: Sascha Hauer Subject: [PATCH v2 6/7] serial: imx: set_mctrl(): correctly restore autoRTS state Date: Wed, 26 Jun 2019 17:11:32 +0300 Message-Id: <1561558293-7683-7-git-send-email-sorganov@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1561558293-7683-1-git-send-email-sorganov@gmail.com> References: <20190614072801.3187-1-s.hauer@pengutronix.de> <1561558293-7683-1-git-send-email-sorganov@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190626_071422_145453_D6F71896 X-CRM114-Status: GOOD ( 13.78 ) 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. Reviewed-by: Sascha Hauer Tested-by: Sascha Hauer 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 4867f80..171347d 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 Wed Jun 26 14: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: 11017957 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 876F5924 for ; Wed, 26 Jun 2019 14:17:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 75FE9286F3 for ; Wed, 26 Jun 2019 14:17:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6A7EF288B2; Wed, 26 Jun 2019 14:17:10 +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 DC74B286F3 for ; Wed, 26 Jun 2019 14:17:09 +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=9QjjjJBhVvxEOusCEBcXtmTTTScCP+z68IpwtETfuu0=; b=mVr5W4+vucOtRUJTPZ/W264O71 SCcoyOVjOpy56BzNjp33Rqmp7GOdM2Dkw48bvJsa2tlwGCubnvumc6ShJTayBPiQKdGZcst1qy+kB agZ/yXqN+VKucU1GLZiXYh1ATpfqXQ8MMaVklk5jODxTDQbZA+/ZssBWEboZuId7IkMAWszXs9x5G IVtbM4s07qIy+io3NGmG4eSRIITbbDpgQyicmj/E3/8HU+Z+/2Nc0u/EU1q4+kQokBIN55B2efri+ B6loMh3AK76GA6fm0XP9E+XYqyI0k4fWZNeSqwKve1qCcqq2T9dMVdo2sezXpWRGmCh8rM9FqK0wD biREXydg==; 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 1hg8jO-0006rc-Ch; Wed, 26 Jun 2019 14:17:02 +0000 Received: from mail-lj1-x241.google.com ([2a00:1450:4864:20::241]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hg8gp-00040Y-Rq for linux-arm-kernel@lists.infradead.org; Wed, 26 Jun 2019 14:14:25 +0000 Received: by mail-lj1-x241.google.com with SMTP id m23so2356754lje.12 for ; Wed, 26 Jun 2019 07:14:22 -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=disSROzqfUTYpKBNgu+W39ygIWnnZb5HbJrhGeUkuwI=; b=BZj8H7g+wSJU3LS7Okj/+Un4KL2iGuLBDqcdcEdVq5R5tg43lDh8RHDvP8Sjk1tgAg EGPnu5JOWBCXeBM4+Fa6IUVYWxIowJrKn+Y1CXKRDUpeDChs/B1CkGmVDXZakNdU3NIG igwQWHWYjAOErhpFJF7lMMWIDcPk11H10UoxW7atwM3x2CyXcqzaCpndkP1qQZiOcke+ uUtA5tj/61A5V/YvQ12mM2yVqkYxtSN5JST2LKGOf+HX7KnWw5ycCmFylwdhAuLPEpQ8 WrlIQTH3X3fJ924sImugV+iwxzEoqwZ7m82jaLI9XAQd/ZXS7I+8A/0zCvFAhXHSelQ9 ncdw== 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=disSROzqfUTYpKBNgu+W39ygIWnnZb5HbJrhGeUkuwI=; b=IhiZFnjBW3muPpMWoEfdDAJuraxthZ6ShzqMB0AkmbHUVC/QZ4stD7xq5/GPbIKijy k4izOdvS/9gE8IzVor4IxF5+ZVFENMeMQGYUKDYWKGp//KAD9KEbasAbIxW0AdKBbc2o LslBykXZmk3/oxZTMlikj80ZKKIhOOKzALR3FdBpmKh3+IVgUBH6HtPLv9Gow7qwkvO9 5LZL5RNSXsBFiI9QNJ+l251ZX0PnLfD7Qr1un+dm0fv8h/IdzU3kIG6BuU0RER2rkbLl RhLWHq7IeWI0Qf+exmnqAXU/wA1aIaPjmBLCT091a6CSioKuQyxdMY4z2KfacVgU9iPi NYaQ== X-Gm-Message-State: APjAAAWZo3BkGYSLHFMe8FoEBz/q41wP7Gwq1ck1dQKiJv75qluPx3sf RKaMwadBeD7YwRzaURMFEqM= X-Google-Smtp-Source: APXvYqzQ3GQSF/ngOsv3mi41ox5k13SoEkk3vZAxzYGrp0VMn7mMceHw0FTkyiuSkMxqLHYFdZ3q9Q== X-Received: by 2002:a2e:988b:: with SMTP id b11mr3080348ljj.110.1561558461628; Wed, 26 Jun 2019 07:14:21 -0700 (PDT) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id 25sm2863825ljn.62.2019.06.26.07.14.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 26 Jun 2019 07:14:21 -0700 (PDT) From: Sergey Organov To: Sascha Hauer Subject: [PATCH v2 7/7] serial: imx: get rid of imx_uart_rts_auto() Date: Wed, 26 Jun 2019 17:11:33 +0300 Message-Id: <1561558293-7683-8-git-send-email-sorganov@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1561558293-7683-1-git-send-email-sorganov@gmail.com> References: <20190614072801.3187-1-s.hauer@pengutronix.de> <1561558293-7683-1-git-send-email-sorganov@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190626_071423_931282_FE60C212 X-CRM114-Status: GOOD ( 12.05 ) 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. Reviewed-by: Sascha Hauer Tested-by: Sascha Hauer 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 171347d..a5e80a0 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;