From patchwork Sat Nov 15 00:32:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Anderson X-Patchwork-Id: 5310521 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 2DB989F2ED for ; Sat, 15 Nov 2014 00:36:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 30D202012D for ; Sat, 15 Nov 2014 00:36:55 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3284D20103 for ; Sat, 15 Nov 2014 00:36:54 +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 1XpRIr-0005D8-Ke; Sat, 15 Nov 2014 00:33:25 +0000 Received: from mail-ie0-x234.google.com ([2607:f8b0:4001:c03::234]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XpRIo-0005BS-Hr for linux-arm-kernel@lists.infradead.org; Sat, 15 Nov 2014 00:33:23 +0000 Received: by mail-ie0-f180.google.com with SMTP id rl12so3634202iec.11 for ; Fri, 14 Nov 2014 16:33:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id; bh=UGo83+VwZX3IRbafHiyWwVTdA4ZEXLOAsBBelbQSD4g=; b=QgWRlu0TjeO1+bKAFF+KwJEcvcmxLBT+sYI+s+UJlYtlVWxz9wl+GYuX1ZEL3i27ms VKEW/6KRvJJE68oEP/7mxFGUMSvrRGWJ96v/N0I5RsRRCuVXSwh10rBLijMYkKwjsVNQ dwRAgv82l1lSK2MrV8gflmDpMvV3YzRmuCFO0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=UGo83+VwZX3IRbafHiyWwVTdA4ZEXLOAsBBelbQSD4g=; b=chCF+llQcrR5xzfFY5UoYhdG6UdRQKly6wC9sfm1HhBUuUlPX18VLPHx5YE2kHr2je dcoEgEd6X9588Rwp09XJmJ3ehr/kiqQo2S2Sbx1AhwxPb1Ml0kKM80oMscV5EfCjeFbY PH2zeyFVvyqgk660V8iKkpgYzemPiRd6zuCIi5JD8AfKol6540fAv2EkiWH0f220DrzQ 1ANKbkSmIC0NiIm7FjLBg6R0N81c60zJ4S78tCrHJDnItetnULGzOqAX/VpntgM8yEUm dCeUcujQojBQjGccTJXdHhV79HDUsUfOntWx6mgjeyQNywt2K/+DPMx1P+CSR6JyuRa6 dOJQ== X-Gm-Message-State: ALoCoQlEl/Rv9/wcVJLlMAYfP9FKEbSjBNSURloWVS9Smra9BTyZEJ/1uZ85swyX8Dlb2dSjuxqg X-Received: by 10.107.41.199 with SMTP id p190mr14190120iop.10.1416011580144; Fri, 14 Nov 2014 16:33:00 -0800 (PST) Received: from tictac.mtv.corp.google.com ([172.22.65.76]) by mx.google.com with ESMTPSA id o2sm2106600igj.19.2014.11.14.16.32.58 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 14 Nov 2014 16:32:59 -0800 (PST) From: Doug Anderson To: Greg Kroah-Hartman , Heiko Stuebner , Jiri Slaby Subject: [PATCH] serial: 8250_dw: Handle no_console_suspend when uart loses state Date: Fri, 14 Nov 2014 16:32:36 -0800 Message-Id: <1416011556-23422-1-git-send-email-dianders@chromium.org> X-Mailer: git-send-email 2.1.0.rc2.206.gedb03e5 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141114_163322_868834_3411C4D6 X-CRM114-Status: GOOD ( 13.83 ) X-Spam-Score: -0.8 (/) Cc: heikki.krogerus@linux.intel.com, linux-serial@vger.kernel.org, Andrew Bresticker , Doug Anderson , linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, wens@csie.org, loic.poulain@intel.com, Chris Zhong , andriy.shevchenko@linux.intel.com, mika.westerberg@linux.intel.com, linux-arm-kernel@lists.infradead.org, alan@linux.intel.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW, T_DKIM_INVALID, T_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 In certain suspend modes on certain boards the 8250 UART may lose state when the device goes to suspend. If we're using no_console_suspend this can cause lots of problems during resume. Let's cache the basic UART config registers at suspend time and if we notice that the UART loses state (by looking at a canary stored in the scratch register) we'll restore it. Signed-off-by: Doug Anderson --- Note that I don't have a board that properly suspends and resumes from the deepest sleep state that runs atop mainline, so this is tested on a local tree that is based on 3.14 with backports (specifically on rk3288-pinky). It is compile tested atop mainline. drivers/tty/serial/8250/8250_dw.c | 67 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/drivers/tty/serial/8250/8250_dw.c b/drivers/tty/serial/8250/8250_dw.c index 0bfdccc..444ff540 100644 --- a/drivers/tty/serial/8250/8250_dw.c +++ b/drivers/tty/serial/8250/8250_dw.c @@ -38,6 +38,9 @@ #define DW_UART_CPR 0xf4 /* Component Parameter Register */ #define DW_UART_UCV 0xf8 /* UART Component Version */ +/* We'll place this canary in SCR while suspending; if gone we've lost state */ +#define DW_UART_SCR_STATE 0x22 + /* Component Parameter Register bits */ #define DW_UART_CPR_ABP_DATA_WIDTH (3 << 0) #define DW_UART_CPR_AFCE_MODE (1 << 4) @@ -63,6 +66,13 @@ struct dw8250_data { struct clk *pclk; struct reset_control *rst; struct uart_8250_dma dma; + + int suspending; + int saved_lcr; + int saved_dll; + int saved_dlm; + int saved_ier; + int saved_fcr; }; #define BYT_PRV_CLK 0x800 @@ -92,10 +102,35 @@ static void dw8250_force_idle(struct uart_port *p) (void)p->serial_in(p, UART_RX); } +static void dw8250_serial_restore(struct uart_port *p) +{ + struct dw8250_data *data = p->private_data; + struct uart_8250_port *port8250 = serial8250_get_port(data->line); + + data->suspending = 0; + + serial_out(port8250, UART_LCR, data->saved_lcr | UART_LCR_DLAB); + serial_out(port8250, UART_DLL, data->saved_dll); + serial_out(port8250, UART_DLM, data->saved_dlm); + serial_out(port8250, UART_LCR, data->saved_lcr); + + serial_out(port8250, UART_IER, data->saved_ier); + serial_out(port8250, UART_FCR, data->saved_fcr); + serial_out(port8250, UART_MCR, data->last_mcr); +} + static void dw8250_serial_out(struct uart_port *p, int offset, int value) { struct dw8250_data *d = p->private_data; + /* + * If we started suspending and we see SCR went back to 0, assume we've + * suspended and resumed and lost state. Restore it now. + */ + if (d->suspending && + readb(p->membase + (UART_SCR << p->regshift)) != DW_UART_SCR_STATE) + dw8250_serial_restore(p); + if (offset == UART_MCR) d->last_mcr = value; @@ -133,6 +168,14 @@ static void dw8250_serial_out32(struct uart_port *p, int offset, int value) { struct dw8250_data *d = p->private_data; + /* + * If we started suspending and we see SCR went back to 0, assume we've + * suspended and resumed and lost state. Restore it now. + */ + if (d->suspending && + readb(p->membase + (UART_SCR << p->regshift)) != DW_UART_SCR_STATE) + dw8250_serial_restore(p); + if (offset == UART_MCR) d->last_mcr = value; @@ -487,9 +530,29 @@ static int dw8250_remove(struct platform_device *pdev) static int dw8250_suspend(struct device *dev) { struct dw8250_data *data = dev_get_drvdata(dev); + struct uart_8250_port *port8250 = serial8250_get_port(data->line); + struct uart_port *port = &port8250->port; serial8250_suspend_port(data->line); + /* We only deal with ports that were left on (no_console_suspend) */ + if (port->suspended) + return 0; + + /* We'll save our registers in case we lose state in suspend */ + data->saved_fcr = serial_in(port8250, UART_FCR); + data->saved_ier = serial_in(port8250, UART_IER); + data->saved_lcr = serial_in(port8250, UART_LCR); + + serial_out(port8250, UART_LCR, data->saved_lcr | UART_LCR_DLAB); + data->saved_dlm = serial_in(port8250, UART_DLM); + data->saved_dll = serial_in(port8250, UART_DLL); + serial_out(port8250, UART_LCR, data->saved_lcr); + + /* Put a special canary in the scratch so we tell when state is lost */ + serial_out(port8250, UART_SCR, DW_UART_SCR_STATE); + data->suspending = 1; + return 0; } @@ -497,6 +560,10 @@ static int dw8250_resume(struct device *dev) { struct dw8250_data *data = dev_get_drvdata(dev); + /* We never lost state; stop checking for canary */ + if (data->suspending) + data->suspending = 0; + serial8250_resume_port(data->line); return 0;