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: 5310511 Return-Path: X-Original-To: patchwork-linux-rockchip@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 0EDE2C11AC for ; Sat, 15 Nov 2014 00:33:36 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0E7DA20145 for ; Sat, 15 Nov 2014 00:33:35 +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 144F02012D for ; Sat, 15 Nov 2014 00:33:34 +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 1XpRIq-0005D1-Lg; Sat, 15 Nov 2014 00:33:24 +0000 Received: from mail-ig0-x231.google.com ([2607:f8b0:4001:c05::231]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1XpRIo-0005BT-IA for linux-rockchip@lists.infradead.org; Sat, 15 Nov 2014 00:33:23 +0000 Received: by mail-ig0-f177.google.com with SMTP id uq10so1205820igb.10 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=EbvSo7qD7xzUgZmFPvw9b873V2ufwpAidDFgFnwDmM7cbUxl6wZVrkygCCUxp5h71r sHnWpA7D0qAHcdLbD9/MtRR1jxEzjOQHG19tr1Cau4Vwuhu4619dCH/r04ea35g7iAUX 3CPp+siN4ixH0uBwvV5zpC0hG5Uokd9KFqbSQKwLCIJpakO8R3+JfnK9j9iDJm5GgBdE Bam2wMo78mgusEebPWxqpNL710zL9DFLkVPT/UyxDPdKgM/IgNd6OpgDWlkv6g0MeXgD mKp3XtYv8Yqmtge/O3nN/BIYgWcbm/Hm1xQ4nc8vmcLqZfhivzqr+7+PLSUkiLfVaYGj gBlQ== X-Gm-Message-State: ALoCoQn1CHXj11fvPwd3myaaHPkBgtXvno/OWpgfVFtbgbL6kmrxNtsEuzbzrNIWa+J4udJFG4vf 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_724270_B476762E X-CRM114-Status: GOOD ( 12.30 ) 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-rockchip@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=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;