From patchwork Wed Jul 29 20:58:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shenwei Wang X-Patchwork-Id: 6896321 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D84BFC05AC for ; Wed, 29 Jul 2015 21:01:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D565620607 for ; Wed, 29 Jul 2015 21:01:30 +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 BB4E7205BC for ; Wed, 29 Jul 2015 21:01:29 +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 1ZKYRx-0005tn-3m; Wed, 29 Jul 2015 20:59:41 +0000 Received: from mail-bl2on0129.outbound.protection.outlook.com ([65.55.169.129] helo=na01-bl2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZKYRq-0005dH-A7 for linux-arm-kernel@lists.infradead.org; Wed, 29 Jul 2015 20:59:35 +0000 Received: from BLUPR0301CA0020.namprd03.prod.outlook.com (10.162.113.158) by BL2PR03MB483.namprd03.prod.outlook.com (10.141.92.149) with Microsoft SMTP Server (TLS) id 15.1.231.11; Wed, 29 Jul 2015 20:59:12 +0000 Received: from BY2FFO11FD056.protection.gbl (2a01:111:f400:7c0c::199) by BLUPR0301CA0020.outlook.office365.com (2a01:111:e400:5259::30) with Microsoft SMTP Server (TLS) id 15.1.225.19 via Frontend Transport; Wed, 29 Jul 2015 20:59:11 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=freescale.com; lists.infradead.org; dkim=none (message not signed) header.d=none; Received-SPF: Fail (protection.outlook.com: domain of freescale.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BY2FFO11FD056.mail.protection.outlook.com (10.1.15.193) with Microsoft SMTP Server (TLS) id 15.1.231.11 via Frontend Transport; Wed, 29 Jul 2015 20:59:11 +0000 Received: from [tx30smr01.am.freescale.net (B38339-11.am.freescale.net [10.81.93.199]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id t6TKx7fZ004405; Wed, 29 Jul 2015 13:59:10 -0700 From: Shenwei Wang To: Subject: [PATCH v3 1/1] Serial: imx: add dev_pm_ops to support suspend to ram/disk Date: Wed, 29 Jul 2015 15:58:55 -0500 Message-ID: <1438203535-38028-1-git-send-email-shenwei.wang@freescale.com> X-Mailer: git-send-email 2.5.0.rc2 X-EOPAttributedMessage: 0 X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD056; 1:fsMmLVr+YxAQBPm7pWELdgMK7al2V5uMlGetIrLynoYGiu8IWCI/yl3NhWBjpaDVsX8JIqZSFmBpapMJE3T8GNhU+cbm4bAgSPiFT03JKCF2sGgXuFYSBCIlgZPVBy+xtUFUubxEeQBZIQQ0AJPKwFmUmaAEtCZh0zjlRaC7aBwUAziII+bIW8dbcQAKhjoux3fdXs4KZ+d3tRsy0uLNHr4KFgSRV/g+Q15NIMc0zUIJ28qA3FFvVCmFP2MJyEnwwQ8qqLirTeLEzkd+lI6Plx7vmpV5ZW9I190AgQ7AEkYFMouftGNXoCeyPAn4FAah X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(339900001)(199003)(189002)(85426001)(46102003)(77096005)(189998001)(36756003)(50466002)(48376002)(86362001)(5001960100002)(50986999)(87936001)(110136002)(6806004)(5001920100001)(19580405001)(19580395003)(92566002)(104016003)(106466001)(62966003)(229853001)(33646002)(77156002)(2351001)(50226001)(105606002)(47776003); DIR:OUT; SFP:1102; SCL:1; SRVR:BL2PR03MB483; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; MLV:sfv; A:1; MX:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; BL2PR03MB483; 2:TQAfhPq/Bg/K1eesgkY8DRlNaq8M8hE1uuURamK1y8JvuBFBkqKGMacUqXSwrKA7cqYw4LJipqGpM9VzGAp2ZUbH64wJlglENvUamnHlaZoFBp1qQpmalOfyDAQectT6qBgoDL7kYUnMuE897KF76mJue8oPxYQqMQA38SJRsH0=; 3:kb2sTiooB3PCyKJ/PG635SyqH+pprf78+/YlBBAsTl28O4nxbdsqQH83lzf3BUmXwAYfsQDv6EmqmrWnFaNp499xxAqKbC94r4UanjsjW86UjgcdL4DAaijpLufpJnbccefOF9f/++BPWENWT5OtwtI4XpZGcfud3dp7RjKlvpLFI+vJSFmOV9bFfclwJKLAGrtvUZEF1j1X9JmQZ3wK/GPSKLoZuGDwtiD5Q+JHaSY=; 25:Pk6eEcQYS/5TYbLF4eWuEgMB4xY2c0jAEUTHF0915SVn9Ml7dwiVDMaiRoWrLTmeY0brVM5b7N/yxBD+vwi7ELv+Uw0ShxzKDQvB0wFy9BQLnWoNyYCnc8nEbFNunK5NkWOBOCfXLZ6TkolKwMr+UWMZvLkWAadPe7ae6MVhJECovrzXOGcF0cH26tRK+UR+Z3lvXMK56Io93ThxdEgerMTr1QjiHfsjTggulfQJrSqg8EzWsGHljnBZf/eguzcsQdllU0qIX/0L/9tmCnu2uQ== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BL2PR03MB483; X-Microsoft-Exchange-Diagnostics: 1; BL2PR03MB483; 20:KALhzv0lrfYdsdu2v2Dr1V71/KCGF33UuzNtFfwuTh1qYLSVIC0wyWO+x5S8UPr1x+Gu0I/bhTjX0/ag6SeksxM+X/9456QCuZiH6qZ7LCWBVz8+10kvSP/B876r/GomnOXRoVV9iGfCyZv/g5anEu6oLKeIvaQK4bcJ/kicSaya4yueuzzmMUp1YjLekyJpVFKC7E5lEWA8kLZMAg52OyaFg5HQ9wlNZY6esF+sJOMQgq4GH18/SbMz8IDyBiFd/NMTvSESd+gQtIpzeieDZGpa3J7h5QnPFC7DuaS4VKslZmE3Pjt3CQhWFynZjSz7z3jAhxZ+7Hvc31MP+tejbXpA9hzr1I43h2xSM1sNqDk=; 4:B9OwTrXapnI1MeFP+8+W4QxvHC2igsJspHRM4IkEkx53qe+H30zZGI35iZYpYUxPwO2YQXienjYeRLg3Qwp/8O7j3tc4E9AmX8fDVgEFmORj5johcUgaXfrFWUUFUITknHpLeSMjNnNZVPd0szT7oI+aeQ2BoA+mnd95aqxB3UIS0fwtWNzWjHy9EVRtc89ByzYrg/3/0idR8ub5UDp+oeC8fBFES/0d54TR/94CuQN+WzhfDvMPWU6vK2171X91y3HXoI6a/cex3ue+NTVcUOSolgwxrDmFIVEbb4oUsTc= X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005006)(3002001); SRVR:BL2PR03MB483; BCL:0; PCL:0; RULEID:; SRVR:BL2PR03MB483; X-Forefront-PRVS: 0652EA5565 X-Microsoft-Exchange-Diagnostics: 1; BL2PR03MB483; 23:4rVCKtlpdnLuiyvtroV1gbF5VlO9x+MZIm78EXDb4I/fT6gDR7M08yx7v8eTV3GBN2m962HoaVscGXG1gm1W/6AkbV1tHFzJ2+xBPEtXNmPoS9RVO2liQfJqI2jgU2M1ELn/c7ZgsRUZX0J3E4B3ve4CfenRoy7b9wmFVFOz6aOSTCZsvRZfX1OGEJlM4J6o0zZa9HGiwC/47MMt1D/gRStfxzTgX1llm6u5HzgAHKxo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enant-OriginalArrivalTime: 29 Jul 2015 20:59:11.8697 (UTC) X-MS-Exchange-CrossTenant-Id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=710a03f5-10f6-4d38-9ff4-a80b81da590d; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL2PR03MB483 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150729_135934_576611_E68012A4 X-CRM114-Status: GOOD ( 22.97 ) X-Spam-Score: -1.9 (-) 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: linux-arm-kernel@lists.infradead.org, linux-serial@vger.kernel.org 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.6 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 When system goes into low power states like SUSPEND_MEM and HIBERNATION, the hardware IP block may be powered off to reduce the power consumption. This power down may cause problems on some imx platforms, because the hardware settings are reset to its power on default values which may differ from the ones when it power off. This patch added the dev_pm_ops and implemented two callbacks: suspend_noirq and resume_noirq, which will save the necessory hardware parameters right before power down and recover them before system uses the hardware. Because added the dev_pm_ops, the old suspend/resume callbacks under platform_driver will not be called any more. Changed their prototypes and moved those two callbacks into dev_pm_ops too. Signed-off-by: Shenwei Wang --- Change log: PATCH v3 After added the dev_pm_ops, the old suspend/resume callbacks under platform_driver will not be called. Changed their prototypes and moved them into dev_pm_ops too. PATCH v2 Change pr_debug to dev_dbg per GregK's review feedback. drivers/tty/serial/imx.c | 120 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 88 insertions(+), 32 deletions(-) -- 2.5.0.rc2 diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index 2c90dc3..10dece3 100644 --- a/drivers/tty/serial/imx.c +++ b/drivers/tty/serial/imx.c @@ -216,6 +216,7 @@ struct imx_port { unsigned int tx_bytes; unsigned int dma_tx_nents; wait_queue_head_t dma_wait; + unsigned int saved_reg[10]; }; struct imx_port_ucrs { @@ -1811,36 +1812,6 @@ static struct uart_driver imx_reg = { .cons = IMX_CONSOLE, }; -static int serial_imx_suspend(struct platform_device *dev, pm_message_t state) -{ - struct imx_port *sport = platform_get_drvdata(dev); - unsigned int val; - - /* enable wakeup from i.MX UART */ - val = readl(sport->port.membase + UCR3); - val |= UCR3_AWAKEN; - writel(val, sport->port.membase + UCR3); - - uart_suspend_port(&imx_reg, &sport->port); - - return 0; -} - -static int serial_imx_resume(struct platform_device *dev) -{ - struct imx_port *sport = platform_get_drvdata(dev); - unsigned int val; - - /* disable wakeup from i.MX UART */ - val = readl(sport->port.membase + UCR3); - val &= ~UCR3_AWAKEN; - writel(val, sport->port.membase + UCR3); - - uart_resume_port(&imx_reg, &sport->port); - - return 0; -} - #ifdef CONFIG_OF /* * This function returns 1 iff pdev isn't a device instatiated by dt, 0 iff it @@ -1992,16 +1963,101 @@ static int serial_imx_remove(struct platform_device *pdev) return uart_remove_one_port(&imx_reg, &sport->port); } +static int imx_serial_port_suspend_noirq(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct imx_port *sport = platform_get_drvdata(pdev); + + /* Save necessary regs */ + clk_enable(sport->clk_ipg); + sport->saved_reg[0] = readl(sport->port.membase + UCR1); + sport->saved_reg[1] = readl(sport->port.membase + UCR2); + sport->saved_reg[2] = readl(sport->port.membase + UCR3); + sport->saved_reg[3] = readl(sport->port.membase + UCR4); + sport->saved_reg[4] = readl(sport->port.membase + UFCR); + sport->saved_reg[5] = readl(sport->port.membase + UESC); + sport->saved_reg[6] = readl(sport->port.membase + UTIM); + sport->saved_reg[7] = readl(sport->port.membase + UBIR); + sport->saved_reg[8] = readl(sport->port.membase + UBMR); + sport->saved_reg[9] = readl(sport->port.membase + IMX21_UTS); + clk_disable(sport->clk_ipg); + + dev_dbg(dev, "0x%p (%d)\r\n", sport->port.membase, sport->port.line); + + return 0; +} + +static int imx_serial_port_resume_noirq(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct imx_port *sport = platform_get_drvdata(pdev); + + clk_enable(sport->clk_ipg); + writel(sport->saved_reg[4], sport->port.membase + UFCR); + writel(sport->saved_reg[5], sport->port.membase + UESC); + writel(sport->saved_reg[6], sport->port.membase + UTIM); + writel(sport->saved_reg[7], sport->port.membase + UBIR); + writel(sport->saved_reg[8], sport->port.membase + UBMR); + writel(sport->saved_reg[9], sport->port.membase + IMX21_UTS); + writel(sport->saved_reg[0], sport->port.membase + UCR1); + writel(sport->saved_reg[1] | 0x1, sport->port.membase + UCR2); + writel(sport->saved_reg[2], sport->port.membase + UCR3); + writel(sport->saved_reg[3], sport->port.membase + UCR4); + clk_disable(sport->clk_ipg); + + dev_dbg(dev, "0x%p (%d)\r\n", sport->port.membase, sport->port.line); + + return 0; +} + +static int imx_serial_port_suspend(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct imx_port *sport = platform_get_drvdata(pdev); + unsigned int val; + + /* enable wakeup from i.MX UART */ + val = readl(sport->port.membase + UCR3); + val |= UCR3_AWAKEN; + writel(val, sport->port.membase + UCR3); + + uart_suspend_port(&imx_reg, &sport->port); + + return 0; +} + +static int imx_serial_port_resume(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct imx_port *sport = platform_get_drvdata(pdev); + unsigned int val; + + /* disable wakeup from i.MX UART */ + val = readl(sport->port.membase + UCR3); + val &= ~UCR3_AWAKEN; + writel(val, sport->port.membase + UCR3); + + uart_resume_port(&imx_reg, &sport->port); + + return 0; +} + +static const struct dev_pm_ops imx_serial_port_pm_ops = { + .suspend_noirq = imx_serial_port_suspend_noirq, + .resume_noirq = imx_serial_port_resume_noirq, + .suspend = imx_serial_port_suspend, + .resume = imx_serial_port_resume, +}; + static struct platform_driver serial_imx_driver = { .probe = serial_imx_probe, .remove = serial_imx_remove, - .suspend = serial_imx_suspend, - .resume = serial_imx_resume, .id_table = imx_uart_devtype, .driver = { .name = "imx-uart", .of_match_table = imx_uart_dt_ids, + .pm = &imx_serial_port_pm_ops, }, };