From patchwork Thu Jul 16 07:40:58 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juergen Borleis X-Patchwork-Id: 6804411 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 5C1C99F3A0 for ; Thu, 16 Jul 2015 07:43:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 688FA207BB for ; Thu, 16 Jul 2015 07:43:38 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 44F3E207AE for ; Thu, 16 Jul 2015 07:43:37 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZFdnJ-00047l-6D; Thu, 16 Jul 2015 07:41:25 +0000 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZFdnG-0003wk-LG for linux-arm-kernel@lists.infradead.org; Thu, 16 Jul 2015 07:41:23 +0000 Received: from dude.hi.pengutronix.de ([2001:67c:670:100:1d::7]) by metis.ext.pengutronix.de with esmtps (TLS1.2:RSA_AES_128_CBC_SHA1:128) (Exim 4.80) (envelope-from ) id 1ZFbv8-0007aG-5s; Thu, 16 Jul 2015 07:41:22 +0200 Received: from jbe by dude.hi.pengutronix.de with local (Exim 4.86_RC4) (envelope-from ) id 1ZFdms-0002FL-HW; Thu, 16 Jul 2015 09:40:58 +0200 From: Juergen Borleis To: linux-kernel@vger.kernel.org Subject: [PATCH v3] serial: mxs-auart: keep the AUART unit in reset state when not in use Date: Thu, 16 Jul 2015 09:40:58 +0200 Message-Id: <1437032458-8577-1-git-send-email-jbe@pengutronix.de> X-Mailer: git-send-email 2.1.4 X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::7 X-SA-Exim-Mail-From: jbe@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-arm-kernel@lists.infradead.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150716_004122_872270_DF03D6E4 X-CRM114-Status: GOOD ( 17.93 ) X-Spam-Score: -3.3 (---) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stefan Wahren , kernel@pengutronix.de, Greg Kroah-Hartman , linux-serial@vger.kernel.org, Jiri Slaby , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Whenever the UART device driver gets closed from userland, the driver disables the UART unit and then stops its clock to save power. The bit which disabled the UART unit is described as: "UART Enable. If this bit is set to 1, the UART is enabled. Data transmission and reception occurs for the UART signals. When the UART is disabled in the middle of transmission or reception, it completes the current character before stopping." The important part is the "it completes the current character". Whenever a reception is ongoing when the UART gets disabled (including the clock off) the statemachine freezes and "remembers" this state on the next open() and re-enabling of the unit's clock. In this case we end up receiving an additional bogus character immediately. The solution in this change is to move the AUART unit into its reset state on close() and only release it from its reset state on the next open(). Signed-off-by: Juergen Borleis Acked-by: Stefan Wahren --- Notes: v3: - missing newline added to an error message v2: - rename mxs_auart_do_reset() to mxs_auart_keep_reset() to better reflect what it really does - adapt the delay in mxs_auart_keep_reset() to wait for the reset of the AURAT unit to what is used in mxs_auart_reset() - typo fixed drivers/tty/serial/mxs-auart.c | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/drivers/tty/serial/mxs-auart.c b/drivers/tty/serial/mxs-auart.c index 13cf773..135ee6c 100644 --- a/drivers/tty/serial/mxs-auart.c +++ b/drivers/tty/serial/mxs-auart.c @@ -858,6 +858,30 @@ static void mxs_auart_reset(struct uart_port *u) writel(AUART_CTRL0_CLKGATE, u->membase + AUART_CTRL0_CLR); } +static void mxs_auart_keep_reset(struct uart_port *u) +{ + int i; + u32 reg; + + reg = readl(u->membase + AUART_CTRL0); + /* if already in reset state, keep it untouched */ + if (reg & AUART_CTRL0_SFTRST) + return; + + writel(AUART_CTRL0_CLKGATE, u->membase + AUART_CTRL0_CLR); + writel(AUART_CTRL0_SFTRST, u->membase + AUART_CTRL0_SET); + + for (i = 0; i < 10000; i++) { + reg = readl(u->membase + AUART_CTRL0); + /* reset is finished when the clock is gated */ + if (reg & AUART_CTRL0_CLKGATE) + return; + udelay(3); + } + + dev_err(u->dev, "Failed to reset the unit.\n"); +} + static int mxs_auart_startup(struct uart_port *u) { int ret; @@ -867,7 +891,10 @@ static int mxs_auart_startup(struct uart_port *u) if (ret) return ret; - writel(AUART_CTRL0_CLKGATE, u->membase + AUART_CTRL0_CLR); + /* reset the unit if not aleady done */ + mxs_auart_keep_reset(u); + /* bring it out of reset now */ + mxs_auart_reset(u); writel(AUART_CTRL2_UARTEN, u->membase + AUART_CTRL2_SET); @@ -899,13 +926,8 @@ static void mxs_auart_shutdown(struct uart_port *u) if (auart_dma_enabled(s)) mxs_auart_dma_exit(s); - writel(AUART_CTRL2_UARTEN, u->membase + AUART_CTRL2_CLR); - - writel(AUART_INTR_RXIEN | AUART_INTR_RTIEN | AUART_INTR_CTSMIEN, - u->membase + AUART_INTR_CLR); - - writel(AUART_CTRL0_CLKGATE, u->membase + AUART_CTRL0_SET); - + /* reset the unit and keep it in reset state */ + mxs_auart_keep_reset(u); clk_disable_unprepare(s->clk); }