From patchwork Thu Jun 20 14:47:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Organov X-Patchwork-Id: 11006841 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 CE6A976 for ; Thu, 20 Jun 2019 14:48:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BDBA11FFBD for ; Thu, 20 Jun 2019 14:48:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B19A921327; Thu, 20 Jun 2019 14:48: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 595911FFBD for ; Thu, 20 Jun 2019 14:48:43 +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=RC8g30JEBJYT3L38reBJ7DxmAX VDff0DLWPIpAbYxFGRHROF1NLjdHYz/Sc87IbKLOYPTIbMEYIiFcpvb6Y2X0ijDwBqg+0Ubctig1I xvYmJh+GHrN6v9i5Yf1j868tD/DD+nrZ6uS9Y6colwzXkPtqdnewlVFpHsAFpbDDyxwq9DIau0QHV OH/GV/DzKXfKbHO2sebTXBUtOWP/zPNiyLRqlHNYlgKAqOTHGicYaqGwYxn1w3ISw6JYAY78bg8f5 hrX/UTRt98FS0bj7HXNdTyHUvP625MWnS+UXGpWe6f89KY2aPZRe6eBokdOPkjs2rmusFY4hg+FJh Q/2BAhoA==; 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 1hdyMk-00042q-J1; Thu, 20 Jun 2019 14:48:42 +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 1hdyMD-0003ix-LW for linux-arm-kernel@lists.infradead.org; Thu, 20 Jun 2019 14:48:10 +0000 Received: by mail-lj1-x243.google.com with SMTP id 16so2948725ljv.10 for ; Thu, 20 Jun 2019 07:48:09 -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=aqRlB+88y7te1IyXTJCENFWgDaJpY4yVvKtbZbxKe26ehEh2Xo9cv16sRswEyd1jD3 DtKwsymBxxPKb1vvY8jYXdo6bo6sgsQFjIlwHGGgcsLOMEWMQW1b2kP/+VP8FQI24AKL mbm54fHZ9EqlQC76uDpkj430XOanlM7xc1lxJQi81T+4l1SmY1bTj3yuW65KdPkJXD5I 5yvmA8XLP7qkEHuvHbm7XhJtPUQACMxxWUeIZ4KCTM/ktS61iRM+Jsnvggo0XHG1gczY IiOYjKMOtcOrILvlt8XDH34ictcBvOi+O4R5oB6oFREYtUgiFxhLD7lO3RJsen1Gs25k y3HQ== 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=QFHaunApYoOkiKeLkir0ZFvwqBZzQQrv3MN/s8olEhHUlPalS9HoZlcfCeW0WXhmXh 1Iw6ezTBCmtdaVzvNRSbPdTcBgKWsEuGLOyOJJ0RybGpumKm2xIuPD0XNWm3aMUwifxZ ppZfI5iihzlRLRx2K7lgPb9Xa4qxiEdaIMWOM6rgbnzxnXJabAv0MonotSh+t/AdgpSk iiSSF1oDKqaiMJS9Tb6Fs4mektlwCL6Olq2qbb4ceIUp+lZ2bMhqlgpP7YO9jZcVK+Am FUVY4VgBv1mRULCqFP91y3R8XHZXDNMN44Qp7oeoJNLepv+0rILTtL5yXAumd0VSR8fG wTxQ== X-Gm-Message-State: APjAAAWQxx/SjBbCxyFwqx9xoL3cgkq/Kx2istDSmyzAw9jOOYiYB6oi j6vU8XH78HBOHl8ZZkTBOiI= X-Google-Smtp-Source: APXvYqzDfRIywJKMMIfRolNAT3UYVW4ndj63y5PejziUGG/Me/WSmmsouEJI9FwyllAa+MIvX/MpGA== X-Received: by 2002:a2e:8559:: with SMTP id u25mr22892247ljj.224.1561042087903; Thu, 20 Jun 2019 07:48:07 -0700 (PDT) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id f10sm3577768ljk.95.2019.06.20.07.48.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Jun 2019 07:48:07 -0700 (PDT) From: Sergey Organov To: Sascha Hauer Subject: [PATCH RFC v1 1/7] serial: imx: fix locking in set_termios() Date: Thu, 20 Jun 2019 17:47:47 +0300 Message-Id: <1561042073-617-2-git-send-email-sorganov@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1561042073-617-1-git-send-email-sorganov@gmail.com> References: <20190614072801.3187-1-s.hauer@pengutronix.de> <1561042073-617-1-git-send-email-sorganov@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190620_074809_712419_AFB0C152 X-CRM114-Status: GOOD ( 13.52 ) 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 Thu Jun 20 14:47:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Organov X-Patchwork-Id: 11006843 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 D4C04112C for ; Thu, 20 Jun 2019 14:49:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C48961FFBD for ; Thu, 20 Jun 2019 14:49:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B8BB121327; Thu, 20 Jun 2019 14:49:09 +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 73E041FFBD for ; Thu, 20 Jun 2019 14:49: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=bjj99dfZ1AUF4SHwQZoXaCEC5Wnpsj8haFSdu3EluX4=; b=GpVO8Y+KLlRAWuh5JipHCvjcTO hnFlEtyFQ8an7dfuPUM9dXlKLXUR3wP9SpORoJnQdgD9p+CQOMK/axGYhiF+iRXjDJbHlTzcSiELN bL/T7SWHGO2m3z+gNzXOtAK3DNPNrastPKwzrwkBCyWZCw/Ah9Pkva54uysSC87vHq1UYPmj23Dwx WB966sgqLqHMINNCpxMMNs5xs2P5RVrA5NXxb21/TxKFdF6azjI4/C+DyfhF0mdBIXdAqhVHKeQMD n3g/qPoomOOusyODWJmORpqrKLxbADrjfP5hbQ+/Uz0fmQpZp/oWJvmLQv15k97M4zckxEZ88K/2v HaDwtMow==; 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 1hdyN5-0004HD-DD; Thu, 20 Jun 2019 14:49:03 +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 1hdyME-0003jh-Hy for linux-arm-kernel@lists.infradead.org; Thu, 20 Jun 2019 14:48:11 +0000 Received: by mail-lj1-x241.google.com with SMTP id a21so2965226ljh.7 for ; Thu, 20 Jun 2019 07:48:10 -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=DUoQH5nzAMQkwMgDK92LnSpcbYkdUejrkX56/rNFbK//1UyTzgqlZZFF4DshEJOCmv GBGf+9R9bZmt7SuPgQoCuh4epT0TSA267X+Y8C3Xz3P7Xt6PjtqesEBydf2QHv55oxna 824UwQN/3woBSubU7mBH4Z24yCD9/EFcycJBTUFj+wrbtfKauxbmqgY4TU6U2zTVoKsa V5Yc+3dDUclTIkoTGudTdZTU9OqIU+svFs6JEIWZnY6f4zvu4ze092StynGqssiILxqJ TbqjLLEvT5CgmFkn1oWwMXOkK90nKDWPDUw/XCUuIQO7xGQC2gi6Ae9sVpVD/v9NglzA UchQ== 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=WeYGairAg0H4+i4MKECLSqZcQ/nPiHqJIYrPLUAMcLCK6VQ1lPLWqTrM6OcHkdeKV/ VI0lHbBjm/XHoLTgdiId2Xzh90SXv/UCq82j7UsBxNM4k6CYSkozdt5aO3UwXfXANP/u C31In794wnp3UNrFS+MjuYIccuZamDJvJwZGHdnwmz2XRh9wp3xwTG7aMCisj+Q2H14z NfNuOLCgFc9CvZsBgVbeXQKoN0ks/o811TCjM3VMUEdLIn2t5ZPAS87G5z1/av9We35K p5zCT6yA4QZIfUml3SOApUUa4NKNuZMHS7A8UmextzMThZZo4p/9ckBSX3Gr+3oPLCl1 SlNg== X-Gm-Message-State: APjAAAWCo+BVqixoklumXNkOTgnCwIAgvRGdX48nD8szzuR5ej3ALRQj x0rXATTuuXxFR26N2poev+E= X-Google-Smtp-Source: APXvYqx3FATvUJqLsAjONbNQN8PduHBc6uhH3sMNqzf2nFuoCLFoZo2UvsSlmbNL+Io14cpICWaaZA== X-Received: by 2002:a2e:5548:: with SMTP id j69mr23778346ljb.48.1561042088818; Thu, 20 Jun 2019 07:48:08 -0700 (PDT) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id f10sm3577768ljk.95.2019.06.20.07.48.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Jun 2019 07:48:08 -0700 (PDT) From: Sergey Organov To: Sascha Hauer Subject: [PATCH RFC v1 2/7] serial: imx: set_termios(): factor-out 'ucr2' initial value Date: Thu, 20 Jun 2019 17:47:48 +0300 Message-Id: <1561042073-617-3-git-send-email-sorganov@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1561042073-617-1-git-send-email-sorganov@gmail.com> References: <20190614072801.3187-1-s.hauer@pengutronix.de> <1561042073-617-1-git-send-email-sorganov@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190620_074810_628288_6BBACB5B X-CRM114-Status: GOOD ( 11.09 ) 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 Thu Jun 20 14:47:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Organov X-Patchwork-Id: 11006845 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 6057676 for ; Thu, 20 Jun 2019 14:49:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4E2381FFBD for ; Thu, 20 Jun 2019 14:49:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3D6E121327; Thu, 20 Jun 2019 14:49:23 +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 DB0851FFBD for ; Thu, 20 Jun 2019 14:49:22 +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=mlVaWdSmVoeOjUJyfP8GcLh61M 47H9U/YEJHu3ilM6HTIfkAcOelS89dCraZtMabDexP2VwweA9pfrHrSA8f8leEycV4bdSSB3crOeS 91GFzEqI/gG/YLNmf4HihAUvS79eUFiOZGgZDdtwRTIsQciuXu2RqvYipj1cCpSbUEKempXHIHnhv QFIzt7mjjLRTo9N+2qRVDaObMBotgXhoAdTntkRNUfBOUS+qF901BrNIGnCHkCNnchXhBQYxMD4ft AKckpZl/a7JVCZtpvr5QJHIBXMltPdcAZCrfq4p/vR6qibTn8U2BUGbXauJ+gFNH2KSsjflq7iP4v 9NJ+DoNw==; 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 1hdyNN-0004XE-5z; Thu, 20 Jun 2019 14:49:21 +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 1hdyMF-0003k8-8o for linux-arm-kernel@lists.infradead.org; Thu, 20 Jun 2019 14:48:12 +0000 Received: by mail-lj1-x241.google.com with SMTP id k18so2943949ljc.11 for ; Thu, 20 Jun 2019 07:48:11 -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=esADZiMgQW0phjcMP5wGBWdGf0sjWXZVlUmxjk3spgkE/2OYr3lKq6mqsOhzTXqQTz ukrVC0PnYxysphIT72J+suxXuM+zzaE6PC8qMPXxAuV/4nAYBnfhsD5MoZ4XQ91mFNNJ /zowM5mm9mSgyrnhhUn/AXHgM7i5bdxbxQLSzlHmIG+DOezY6j3Usr+zlDoTIg/Y1DYR bzJ8UvMloxzecGl0ZCInvukHiBubu3yzoJPTjLfQiroCfEZqMq93myXDzXQP1uzt3f0c m/cKWIacS1yy1Ggyfq5cShrzF7N4WF73SPj6z6/NcYru+XuJmRdJNTvWL02kcSitUXjF 6J4w== 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=SiHJw28Iu5I9QM0QTlpS/ftFntKGc5tIDMydzAOj2F0MukSOKkeZBIxVYTQYqZoKnQ r+0IcfIfxr8I7S2ZICjXllhGFB1PZh3nHxMA1+w+0APi6GGB8Ve7XEPPUJbMrkQpC9/b o6pIBpIJO4vHnaVKlXrTFvAHDPe4a7iCASyDlznNyStCfnbFsJX82UyZCKhUD6jHo+PK EhwxUmvDF5BKIJno43yqZlbenm8LewRp4uIDS/VbtiS1xWfpdmITql3zWu63UIgPpbcS vx/FY2kqkpUkFdhLbBeXCkxSs4UIwTzY1FHddr9lVGc98jOnsU/ve1E+uYcaJ8fdMFWz NRRg== X-Gm-Message-State: APjAAAVgzEXgulgxLwPY8NovIf/6WsXIH8TSypURkIXisWemcFwSONkZ yGIXQcA9qRiiry/+y1kFjxI= X-Google-Smtp-Source: APXvYqyAnGzVJ/Osqss5wtdaH9tLn+JR7FRReDUCijI7YySbgQBmR2hFw/wCoPHZYc2MS5T3JLwUfw== X-Received: by 2002:a2e:989a:: with SMTP id b26mr9690786ljj.31.1561042089823; Thu, 20 Jun 2019 07:48:09 -0700 (PDT) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id f10sm3577768ljk.95.2019.06.20.07.48.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Jun 2019 07:48:09 -0700 (PDT) From: Sergey Organov To: Sascha Hauer Subject: [PATCH RFC v1 3/7] serial: imx: set_termios(): clarify RTS/CTS bits calculation Date: Thu, 20 Jun 2019 17:47:49 +0300 Message-Id: <1561042073-617-4-git-send-email-sorganov@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1561042073-617-1-git-send-email-sorganov@gmail.com> References: <20190614072801.3187-1-s.hauer@pengutronix.de> <1561042073-617-1-git-send-email-sorganov@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190620_074811_331589_762E2888 X-CRM114-Status: GOOD ( 12.72 ) 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 Thu Jun 20 14:47:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Organov X-Patchwork-Id: 11006847 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 15E2C76 for ; Thu, 20 Jun 2019 14:49:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0527E20502 for ; Thu, 20 Jun 2019 14:49:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED9AF27E63; Thu, 20 Jun 2019 14:49:48 +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 7D52120502 for ; Thu, 20 Jun 2019 14:49:48 +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=eUQNQBKjI8PyyP+QxPBmcG4E6OpBhnaMsghEbhNvbF0=; b=GIuVo2kzzDB5xGJjmQtw6Wte52 7+e2O3LcM9kV5zDeQXw0BnBk4MdQ5RmYp34hjNJIOckbaZWN2RIbkhLiJRaehEjew0jTRcY9DVV34 CxuzGFkGivcpGHtQ+mB7YCpdK5T7idH6bbDViWVyeX8xagKtcg7dXT2lYHAuEFj/VUh38LnmqbW2l oA9O0Qr+HuiqJg9miAtb5ZdcBh2zjEMqtzMm3PugHzYJ2IBYwaeyx9odHIZnkki3vuhoW1Swyn8YO hbpklMkmiVrnupjPWZ2EJ4ys5zSUc11OTJeyLjXiA3v5IkTjMq8waXZbMFjBzaI92iIQBg8sqQuA7 818JhqkA==; 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 1hdyNn-0004n6-9O; Thu, 20 Jun 2019 14:49:47 +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 1hdyMF-0003lG-TX for linux-arm-kernel@lists.infradead.org; Thu, 20 Jun 2019 14:48:13 +0000 Received: by mail-lj1-x244.google.com with SMTP id s21so2964175lji.8 for ; Thu, 20 Jun 2019 07:48:11 -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=zDXBWhuIJraZ+zpNVsz4D9shiJ9Jh7WL+xtta/xOGQA=; b=NrHeV0Jtfe5Cqfpq2CMkT9X2zY+Ip0ARkWJqZJHs7fd8VJ9rX1I0CSeu8VELzEOPdc 9yyvbF7do/4gD92Ej05poMljxb7sWPAg/wStTCMDtDl7p4gMg+0CnmPqPoH+mInbRIY9 KLpOPTMiiyOyBYP5j2yO4cPusr7zgEgUz/V3OseUjjPApgDC8hrMgLPZ2hYlaNcV4P/0 R/EK3xdjiAV+tj9FJsfLEIOEtZuFCf/lD16yXBSA1gT7mt22TXJWRNX9FomFi+yONkVv Un9QOSe91rrRhcS0cUESSNdxbNv9PtIE6mXua/1ItbporbMpSBJUOeokc+gLasWxQDi0 ZaGg== 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=zDXBWhuIJraZ+zpNVsz4D9shiJ9Jh7WL+xtta/xOGQA=; b=TghUr4ZFXHCdUVd9hGC3MxRxt1fSLFqRYfRdFsfF6nji5KljDovR7UF5ym6a+b4/Ll pnEZmfOtFrWlopNFWmt8fSZMe0IWJaCBeZPEU92VJqu/WgP1vZk2coJVYL6FWlBOCjIH fJpsa6/EbJsq6g+QfOLb55rvHKwicAO5/EvkR7pBdOgu761IZzowC7hZO/xBs+CX8xBs nMZ7bnHGYfjyg5Pg71vP/q1xyqzwAbS0Jx+wiHzde1jCY0YtlrkuB3INTJ7p/ihzmvl6 BAo0/x2Oidxcy3mYEEgYvUnhTdHMv0Nl00CKDLkPCllUbdjRq1HqePOMJPKLIinv0e0i V2JA== X-Gm-Message-State: APjAAAVN4rkrSkNRVMpVJXgvEBLUf5FU+M476P+lxSRyPr4dNG+CCtMP rYGc5vQokYvfzPUl18wRfck= X-Google-Smtp-Source: APXvYqx27D35b009mAgFwoWJHWOY4wSxlGLazVqCJGBL/1yAes9mXjxYjYj7WEfHIbsHOkEGRojWIg== X-Received: by 2002:a2e:3807:: with SMTP id f7mr29431101lja.87.1561042090600; Thu, 20 Jun 2019 07:48:10 -0700 (PDT) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id f10sm3577768ljk.95.2019.06.20.07.48.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Jun 2019 07:48:10 -0700 (PDT) From: Sergey Organov To: Sascha Hauer Subject: [PATCH RFC v1 4/7] serial: imx: set_termios(): preserve RTS state Date: Thu, 20 Jun 2019 17:47:50 +0300 Message-Id: <1561042073-617-5-git-send-email-sorganov@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1561042073-617-1-git-send-email-sorganov@gmail.com> References: <20190614072801.3187-1-s.hauer@pengutronix.de> <1561042073-617-1-git-send-email-sorganov@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190620_074812_026373_30BEB04E X-CRM114-Status: GOOD ( 12.15 ) 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 | 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 Thu Jun 20 14:47:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Organov X-Patchwork-Id: 11006851 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 694F676 for ; Thu, 20 Jun 2019 14:50:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 590CA285AA for ; Thu, 20 Jun 2019 14:50:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4D24E28622; Thu, 20 Jun 2019 14:50:16 +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 02C0B285CB for ; Thu, 20 Jun 2019 14:50:16 +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=FY7bpdWeULjOEzM3WvPPBUbAopRip7xKHS4/9Aq36T0=; b=CKFjJusSaigYZGKMbsdTFRQnNH 8cPoFU0xZ5EIBf1KTkMBslsmPKrGF2bEVlWBDszk1sMaEzxsFN3/kOJFXTh+PY6up1B0prC39azqm eI13idBnFoykxU6OZh1gKQAL/PKuePOopqikRf3AvUowcCajlAq2zk55V6MLHpWu+3owtj/jBQocP JAW3ZYd7BzAkzhc8+pRxrBfH4pWljEe+UCXZ7mjLHDgeOjB3tT4kTQ5lRgsmaU+bCC/SnkjUUxKv7 +LgRCtgh2VRAnG22wxk51dVExUM6jVsSDOVmBKJRtqznX8aiUgwpbxVpsmtpmJaToYbASINcOFFus 8qxdj1mQ==; 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 1hdyO9-0005Qf-OY; Thu, 20 Jun 2019 14:50:09 +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 1hdyMH-0003mc-LZ for linux-arm-kernel@lists.infradead.org; Thu, 20 Jun 2019 14:48:15 +0000 Received: by mail-lf1-x141.google.com with SMTP id r15so2613773lfm.11 for ; Thu, 20 Jun 2019 07:48:13 -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=6Nm3aMeYvpczSE39H4ZCdrCAyxxKPyaKxXuOXw8nA9E=; b=Ss5CQNRQyqAxUrx+3rTrr1Rso/LJZB+pJ5PVygl4RrOFXbA+QP2U8nVgNZ7aj7rzLl hxtPA9icuOeZjltVtquglSqmBtdUeF4iNI/364v3Sa6iqLOH3K7imWi8ZJCeBtNRa3eB ZGrLttd0NFhg/g+jlYkqDv0vR4u0F1NYIvOZSBmX/wBIa0mrEzG1UPqlljq9B9k4uvk8 azK6xmvKsieyTiZ1VBQj2O9a0qnpx+KSFQKyl8Rz8Spb9v9YxJr6RCJAdDJEm3Y5KFQX Bc2BlSAA0X+1VvFfjcZKYL1zFVTpVRwHm6W5cmxHc08TMe+qvXO5wixzst+FRnV00M97 VPog== 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=6Nm3aMeYvpczSE39H4ZCdrCAyxxKPyaKxXuOXw8nA9E=; b=ts/9U7ZtnFWqkP3Arvw/urxnc5UTMHrGej5IZ6a+vDnUaRLIWf9F5XlI+hEXy4Bclj 894p5LL4oZhR9uL31SO4M/GW0nNbcOkoUpxYWIY5YpqhNAO4NkY7R7pTp1b1GtDWnDsi Oq7iyPfyK/uNJrzIhFZ+BLvGj1bStcefWitVB0js1dZgp4Xnb8W+0gCvTEACghNbfwwU d+FS6PiA8voGdtq88vaUh1rscuFf6hsnU6kA4FXz2KX9EZn6FjRqW4Vo9CbpP63fn++0 FZCpntAcCH6fvWvdcGzF7CjXZLnLsrP06uHgk1y1HJyK0BSdnmMydAywvRa4K6qNR5pn P26g== X-Gm-Message-State: APjAAAXDbTIO1Ppm27yFNTWrhBdFhX4YkFwrElevDZjg8KQCCSDlq/C2 MCr6nCipY1speUp7xfqmWhPaveAh X-Google-Smtp-Source: APXvYqzEDgPvzuA9agr831Q9g4K+XHoTDD6hI1abVBYqhLYa0eXYg8rTd9FJ+1G12eq6tprD+I3D5w== X-Received: by 2002:a19:2d55:: with SMTP id t21mr1839970lft.94.1561042091891; Thu, 20 Jun 2019 07:48:11 -0700 (PDT) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id f10sm3577768ljk.95.2019.06.20.07.48.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Jun 2019 07:48:11 -0700 (PDT) From: Sergey Organov To: Sascha Hauer Subject: [PATCH RFC v1 5/7] serial: imx: set_termios(): do not enable autoRTS if RTS is unset Date: Thu, 20 Jun 2019 17:47:51 +0300 Message-Id: <1561042073-617-6-git-send-email-sorganov@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1561042073-617-1-git-send-email-sorganov@gmail.com> References: <20190614072801.3187-1-s.hauer@pengutronix.de> <1561042073-617-1-git-send-email-sorganov@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190620_074813_766560_3576285B X-CRM114-Status: GOOD ( 12.32 ) 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 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 Thu Jun 20 14:47:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Organov X-Patchwork-Id: 11006853 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 30B63112C for ; Thu, 20 Jun 2019 14:50:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 209F3286A2 for ; Thu, 20 Jun 2019 14:50:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1500528564; Thu, 20 Jun 2019 14:50:37 +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 BED0C284F9 for ; Thu, 20 Jun 2019 14:50:36 +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=PhIk6sjkvlnKLRtMTMRekcKp9olcThIb5m1Ux8bbToU=; b=DRV3dD2DwCiuRpZQZo0chSU/vV UxcYpN02AcIg2ZBKa85SRFGtf+ME2eZgx3idgmdmfhqQOnJ5OlXLgheq8dtxVxKFZsnX1hCAYplD7 NCSsfbW1DAkvqeT/GTSrnWFuy29EceK8RnBms5dAehtYs4YCkCvzu5uanPdZQLu8241js+MYtq0n4 mTOsGYsd0HNQ1u7wxYWTWcoYe1xWp4tvGw1l9T6Ypg6L4Th+5ETZvnpt51+UNRBxg18tXJ0rP9lBc 4Odmpq6ql4zResvCWyaf7z3KDQS2qMuwrBvfJS9pGoZvNcIiPVFqtfJyJfyErZpzNMzYeiDhnlr1j KR/BRo5w==; 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 1hdyOV-0006Si-Gg; Thu, 20 Jun 2019 14:50:31 +0000 Received: from mail-lf1-x144.google.com ([2a00:1450:4864:20::144]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hdyMI-0003nX-K2 for linux-arm-kernel@lists.infradead.org; Thu, 20 Jun 2019 14:48:16 +0000 Received: by mail-lf1-x144.google.com with SMTP id d11so2652413lfb.4 for ; Thu, 20 Jun 2019 07:48:14 -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=/gmvgIGLetUvFcBPF+pJa4U0pLLQ63ecHLMpqfRKqNE=; b=EW4Efxi+f4+n9tmUrRsKUWDBDeGfbd8SlIWwqFff40QnougmmpYe9PWBz3PZCpl/Nn Su75neDqxDQaHRtw6DQHe33fDum8ZGdp1JnWKQCKoONJFW8zI/g/z1+k5rut8hB32CTM vkda5ut3p2Th+ZOXgvI2amW/DS9pUAuAirYj97SfWhi7hvX5OTyHea3Vq1eZcnHepvUf 6JX9p4GsaXXop3nKoGHxZhzf0ECgcmSXGLGeZLEcq5r9Fa8CoyDexCECLu2PYNff9y0c JvIthpVuWEpeNyVyEoEQUb0O2p6sa9a8cqW4HAw2GXKvTelKnXlmfGkU+NV/3KxhpB0l FlNw== 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=/gmvgIGLetUvFcBPF+pJa4U0pLLQ63ecHLMpqfRKqNE=; b=DIO2gJ0EJKaMpXSG72O/7R8mV1M0y3mh1DjdcPCWxvo3qPNRt1ME/f4Refk8clILnA g7GV10gMtzS2pWVrk0l9rFK8OXvEn4f6qFulbDgYNC2qQiT66SMifNbpWwUAJT0Q6qXH Gug6PelEa6/zV7bT4FZGJ8Sd6aKu9ARjGMTAudrdb1fsCdCaIAlO8+AEsBUrgoLapk0C cyIdUuHRGZGoIVUMY6gruJq9ZAPGwdB621XFRBkwd8OyC0RSVg305aQiEJ9tDdfqbLtK zA56s0AB8Mj8DmDaofRsB/Y+08ZgyXSV/S6mqnd5EyJtHYpId7ECLbpTUVZx28Gn6Ua6 op9Q== X-Gm-Message-State: APjAAAVCkpkQNNVOkiElt7PGynx+4vgj/6TWI0/WWyXQ6IEOCcx+I4Xo XQVP50k1UFnKxHexCE+tCMo= X-Google-Smtp-Source: APXvYqwDmpSWVNY+4QgAKqUYLQ+RxNZ4gmwBGU7Au5lGe/bodTp2ffmy2FO8HU1Hkk13agrWqpSGCw== X-Received: by 2002:ac2:5b0c:: with SMTP id v12mr53351238lfn.184.1561042092841; Thu, 20 Jun 2019 07:48:12 -0700 (PDT) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id f10sm3577768ljk.95.2019.06.20.07.48.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Jun 2019 07:48:12 -0700 (PDT) From: Sergey Organov To: Sascha Hauer Subject: [PATCH RFC v1 6/7] serial: imx: set_mctrl(): correctly restore autoRTS state Date: Thu, 20 Jun 2019 17:47:52 +0300 Message-Id: <1561042073-617-7-git-send-email-sorganov@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1561042073-617-1-git-send-email-sorganov@gmail.com> References: <20190614072801.3187-1-s.hauer@pengutronix.de> <1561042073-617-1-git-send-email-sorganov@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190620_074814_737594_19E1AC35 X-CRM114-Status: GOOD ( 13.93 ) 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 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 Thu Jun 20 14:47:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Organov X-Patchwork-Id: 11006855 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 112E476 for ; Thu, 20 Jun 2019 14:50:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 016C726E90 for ; Thu, 20 Jun 2019 14:50:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E9FF32856F; Thu, 20 Jun 2019 14:50:51 +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 A29F328622 for ; Thu, 20 Jun 2019 14:50:51 +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=MBA1qluvTRl9WWClqDS8TFl0o+uD3r6WmG3RJMRMAZA=; b=pVpAiD4SePhMW4d1Y38ahOIpiH LiK/Jb3vLmF9K4NRx3orbb6kmjVJ/QblZfDhra/0RpppYHO64EwU/SDuYYkFwxKr7U5qNtF21vXWM pKoVJu2MJ1DUNXVq9zyFnPy4qVc5UdPqV96X4QpC/3LOPpuMQh1a+IL+IZITm5W0O926regiin8eL RY4pT20tmuTAvRMUPdL1Cp/EuG7NpbJzckQBl/1L5b5dSxZ/c2UTx35L+N9CBfK7JiwscUpVG6riy DOGBiRtHlVJDAzz9zC7DisJwP0gbN66qDgA6zJTwfaLjSWsNyyuxq9BC8+C3Bi+hrdTFlKo8H60PP 4h9qmL/g==; 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 1hdyOo-0006jl-Lk; Thu, 20 Jun 2019 14:50:50 +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 1hdyMJ-0003oO-3p for linux-arm-kernel@lists.infradead.org; Thu, 20 Jun 2019 14:48:16 +0000 Received: by mail-lf1-x141.google.com with SMTP id d11so2652471lfb.4 for ; Thu, 20 Jun 2019 07:48:15 -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=HSmA2mWGWhBQ0CiBD0AKf9JHGKelcp2PJeQT4mYweVc=; b=W0pxNpYBz82c1Zqq7Bv96jba79T4vZ/lo8okYya4azYckR7DCxMvsFFPEcU0don4Jf LeQbA/ia7ypibGfGWbZ7GvHwJfOLw2T/A/5u2EbJvD4NI8cwgploJ7X4NkZR9kgnU+RJ a2bLohuvhra2oiK8RXG9uojMHaTWMcHgLMlvix4h26Tuq34pgd/Ghvj4nA5B9+R2ULjd JmnQvtzhrDX8GaJY/gBT0sjJO0oSu9/j189Ca4DVlO6aprfgRT+KygEg9pmP2aMeQFVr XcTaMDGY3mNxQRjazj74jlFsh+ikMy+XbFaDdZdxKjbQnj2JEiQtwS3HJ0NEvqdnTi9D 5xKg== 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=HSmA2mWGWhBQ0CiBD0AKf9JHGKelcp2PJeQT4mYweVc=; b=Nn31i/B8JKj6WddAnuE8b0yrwyY/JNWZr1PjBB0ZYzebrpHmXzBJYrxLGVnoU4NX8p WQUyPdE4cewLOrhrhAZhe/hsOvNpHKWzfd+bm+7bXprmi12xdS0EDME3OpgPdOjtszyN nX53posSvR/+/vXHJ/GbpEJHd3h6hmwsJJEbTnRohxtmlxB4WaAwNjQTAhpWHYDIe5Co MGBuMmFD3MlgaAuZqwTeIwnxcCwGx6nZSoiY3JMcFPVGPTizaNz0kaA0KillFwz2J9aw achm40QDKCW4C4dYCO5WeGHl9oA6uKt++u2WV6l25tq2bdBVRdn8ggKVVGNzwX3PLY2Y 0t+g== X-Gm-Message-State: APjAAAWtSSe3810NhbK35oTPpJU0VJCMR9ird7ERPJQC8Z8rNINfmmAL wDCkZj/eqCZz4kPG4OhtD14= X-Google-Smtp-Source: APXvYqzv8uOd/bMglQArMIBQ+KTyM4uiCi+Upep288W03NpjIgQnvzv7cBQnGhuT1n69OPTqA1NXBQ== X-Received: by 2002:ac2:5922:: with SMTP id v2mr64882966lfi.180.1561042093788; Thu, 20 Jun 2019 07:48:13 -0700 (PDT) Received: from osv.localdomain ([89.175.180.246]) by smtp.gmail.com with ESMTPSA id f10sm3577768ljk.95.2019.06.20.07.48.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Jun 2019 07:48:13 -0700 (PDT) From: Sergey Organov To: Sascha Hauer Subject: [PATCH RFC v1 7/7] serial: imx: get rid of imx_uart_rts_auto() Date: Thu, 20 Jun 2019 17:47:53 +0300 Message-Id: <1561042073-617-8-git-send-email-sorganov@gmail.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1561042073-617-1-git-send-email-sorganov@gmail.com> References: <20190614072801.3187-1-s.hauer@pengutronix.de> <1561042073-617-1-git-send-email-sorganov@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190620_074815_251935_F31512D6 X-CRM114-Status: GOOD ( 12.07 ) 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 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;