From patchwork Thu Jul 30 14:32:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shenwei Wang X-Patchwork-Id: 6903271 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 5EF279F38B for ; Thu, 30 Jul 2015 14:36:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 3CF0520567 for ; Thu, 30 Jul 2015 14:36:46 +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 1854E20551 for ; Thu, 30 Jul 2015 14:36:45 +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 1ZKoti-0001WT-Ei; Thu, 30 Jul 2015 14:33:26 +0000 Received: from mail-bn1on0141.outbound.protection.outlook.com ([157.56.110.141] helo=na01-bn1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZKotc-000114-Or for linux-arm-kernel@lists.infradead.org; Thu, 30 Jul 2015 14:33:24 +0000 Received: from BN3PR0301CA0013.namprd03.prod.outlook.com (10.160.180.151) by BLUPR03MB485.namprd03.prod.outlook.com (10.141.79.16) with Microsoft SMTP Server (TLS) id 15.1.231.11; Thu, 30 Jul 2015 14:32:57 +0000 Received: from BY2FFO11OLC004.protection.gbl (2a01:111:f400:7c0c::146) by BN3PR0301CA0013.outlook.office365.com (2a01:111:e400:4000::23) with Microsoft SMTP Server (TLS) id 15.1.225.19 via Frontend Transport; Thu, 30 Jul 2015 14:32:57 +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 BY2FFO11OLC004.mail.protection.outlook.com (10.1.15.184) with Microsoft SMTP Server (TLS) id 15.1.231.11 via Frontend Transport; Thu, 30 Jul 2015 14:32:57 +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 t6UEWqgU000837; Thu, 30 Jul 2015 07:32:56 -0700 From: Shenwei Wang To: , Subject: [PATCH v4 1/1] Serial: imx: add dev_pm_ops to support suspend to ram/disk Date: Thu, 30 Jul 2015 09:32:42 -0500 Message-ID: <1438266762-4397-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; BY2FFO11OLC004; 1:Ovox618pPed8blslJd2uLci9C/x6qfciX7yWeQO3mBAtXlEDrs5gv6K9wUapChUUIoKaRp8D09TXn5bDJ7pVDQ8jI0lYraCugUAx8wOyidW/QZxv7VA3Is9r4lCKX6vvVRz1ATw/KUGWh0KCrkgzBExd8CCQMIAR6M3X0G10rJIgSR/5wz9swnMF6XYdaaE5ea7OybghzIoFV3fxD/EWmrRRWWr2Vp3Ohiza5OjFfNJpXuV5UkrYpZ5OxNgmCeq4TdwiMTt0Dd/tGWo3CaDuY+EXshweOVbcpnRbRvJ0m53AOUa8Mmgy5065zmYn9V9s X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(339900001)(189002)(199003)(189998001)(85426001)(48376002)(77096005)(229853001)(50986999)(5001770100001)(92566002)(47776003)(50226001)(5001960100002)(50466002)(86362001)(87936001)(104016003)(36756003)(33646002)(106466001)(105606002)(19580405001)(62966003)(77156002)(19580395003)(46102003)(6806004); DIR:OUT; SFP:1102; SCL:1; SRVR:BLUPR03MB485; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; MLV:sfv; MX:1; A:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; BLUPR03MB485; 2:dn0hGi1y0HE/bdyqble41Ptc3I3OnLA5loemYWYsAEn6iz01b+svwhBd8m5uxQ8RHmgtufBxPsOODpGwQizL8YFREge6lnZW0Lgk8J4q1VWexF3Z9gx85eXDYSWQDq8o7R21dLX0qysT+5agsiqJmEx2CbKMpFreQgpFKVs8mkk=; 3:PpXuRAYDOEHj2K5CCzPrho2KaSC++8orzkCyXTz1MGJr7ap/EA62wYnwoULl73i2m097HQOKKqHVpwmLsk+rl3qF9b3SY6uCDGhFTVL5w8Jg3j84DOaFlRX6VbSGaWiyl5dqWyquyhnv//PSJyXNRuuWg+IGkOwrsD/36tL4+Ydo9BqBmied1Z7STFJOCzxDVA7o59rfH2kYZOEw0r2UW3TAwR8n9TOoPRRLfTEy5iY=; 25:MCc1jVIyCryLkvHNjrqStDfBxB7fx3A/qBv8gU615234ZpIA1fYeEmZ9MRib61tzTCMWsqJm7PaFFCLHlfAzVSMUqP/RlATldYkX+fpjzvORpMi6B3Mt692/1TTAbAn8LXoQaeIYxndbqqgz2k0liTHdp+ik734nWvctzsoVoPkObNlZ87nOsGWl4wRgoEpkaN3BrsV2EAPY5vP4lL1MFgI03Nz2xGNGIRVs1ZPc+HuBVCwvNxKGKTEkh4AUL97gF5BG/tO+dDvRlsgZtwnj2w== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR03MB485; X-Microsoft-Exchange-Diagnostics: 1; BLUPR03MB485; 20:HOZbSvuyymW5d7BzZJi1z3oAUg4DvfT0hfGUSwODzqyq0HZhlcE2WJ3OwREi7sBTtQFTXoMITtfzX1X5K/E/TBKifJDttCpa7U+0nRtKwxP2hD8yBmZsuCMM+yUPOUVUI2MYRoC1nZA6Gu7wfvcDzvljTeONUIJLZZ2yvdilBzE/caQ1guQXvrm5OTWfhJkhBYQvYunhX+yxa9A7vzl+bk+qoB0HRTtmImQ2AMUqZfFLCPB/QKPL8e4XCQFVygPZCIQBdKaqesZwKggVUQvNYRlCSllxUqgXu+e4AXwJf3DdMwp8vcu7RcC/QGGlATAAu+3oduXNf6DW5pCVZCOPFKbFBrwyjfA3cVP+A6ksIUE=; 4:FcA6XX4vUbJVMT3S8tz2i68sEAFDT6p19PBZlUjzt/sgLYHBwFXqBkX0A9uASbW+n4Xt2yWFKjup1WdTbB3V3I18Cz64V4GtHdL7jUwR37DjU8UVVqsYx9f9+m+zdpDWE2KOhlTDhHvEMqsvKnfkhWJ9xqZhtY6KHegUrGttMdveoZh9PfWmISvvWbX/Hn0s4Hq5QufFWUz0oZGGCGuXUXvYfszhBUlcTowTTNAjMS5PpJU5Y3kpYReig+F/UMx+aszu2TNnFAEryOQ06+94U6eaibSNJ5C9+3ITbHjcqW8= 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:BLUPR03MB485; BCL:0; PCL:0; RULEID:; SRVR:BLUPR03MB485; X-Forefront-PRVS: 06530126A4 X-Microsoft-Exchange-Diagnostics: 1; BLUPR03MB485; 23:y+lA5X8/9uVYlBUIywtr/ZuJZdULmjU/iy1+xOD/3a0TBZIdzHB1ghq0V2WLzjNYc/3rvITyxgSXdXfgdT5OcZ9Ub5aTSbGagVssItSyKakPqqq3W1waX11xlw9bxFy2OjD7h/UA4gUnGvC82ajA9XjR+SoUlHosdJJX+hjUPmmrTrFUis7gRSczjTxv3Mu8Q3GMfmBTrWhfJk2On/s8bvdfdCzDO3+cU58LreJEmNiOKCkYOSLMm0pdlpEVuwTkJWJ9RRqvs51XLzWuVHb0NHA9OPVKIpt93FFwZhGNThRYXGRw/9MN0LqtEy+SDA05x2nO5wp2nYWjrC9vmwYenUc/SxylkGjFUEMbhzJRgdqopNFvNnnxim50n1GoHqPuEoN1Y7Nhu/dCPC0/5CmRVgjSTQ6NnS09hjcpaDGORlAxEuDsdpM1eBTTs+y2djYvtqXoKtW1+ZKAt0HDjlaF80BICh88McmAakFsS4741TODhXYcIE9aCY/9ETHagIdtiUjnMExHt5sAWIqL6tXEsA7czxrjuB9Jhu6hMoC7xhVFoV86dMxZkEzpVZohocGsfpYNTEaG5ZkoLw3b/rP56q4BANAw3svgbAvFDtjyIeQP7Nw2pssGskIDb1JnNAglffnUojGzEcEb7F5Qg150z4XXxX0E5yg9rkPynDpu4oUezvjskAl2IpT6xtvqjdDAGmv4Ac7sFkqMnC1JOmh6Bvd17rphhbZ7JgM8+hdr4R9MZ/gliXxCmKJBoYoRQLhBImwUxabW63Y8TCU+CBxGl8UON2TEnEzpXdOJ1Bg3/XlBy84tbO2sSI40TiShKqXS/dX6NXZjiuu8FFSy1yJOig== X-Microsoft-Exchange-Diagnostics: 1; BLUPR03MB485; 5:n0v232m8BFJitUwrisMSGbmVkK2oJTBIfkJSubd5bJkbGdvDaL0mL1iL0P4KYhH0DIw/A8OGbeC1k9CChRaLjQSXe5wQ6PiXx7aMdCPnzg3uMgMgGU6HtnGDHAbWwCJKhuquELWfO3CGlPDsxuLTUw==; 24:zd1ocSfLwb5oGeYPON2amBPYAjr9QKKnurlykHZurG8X4cTSkEjUvDamQwtzzX5/SAg+AAX7Md4sV25Yb2rkfsalJtwOiWvLOT20UJSxTsU=; 20:zE/156QzKDscCxzs1ZWhuuz8KfX1ftRBbwh99nwfgbcX5rmIEpZEBxCTo9UtZnHkGhyZBTDbsri/EhAjWPwT4g== X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2015 14:32:57.2572 (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: BLUPR03MB485 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150730_073321_037313_72C0C92C X-CRM114-Status: GOOD ( 22.72 ) 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 v4 Added the return value check for clk_enable. Replace the number 0x1 with UCR2_SRST. 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 | 128 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 96 insertions(+), 32 deletions(-) -- 2.5.0.rc2 diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index 2c90dc3..a935c8e 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,109 @@ 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); + int ret; + + ret = clk_enable(sport->clk_ipg); + if (ret) + dev_err(dev, "UART%d suspend error!\r\n", sport->port.line); + + /* Save necessary regs */ + 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); + + if (ret == 0) + clk_disable(sport->clk_ipg); + + 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); + int ret; + + ret = clk_enable(sport->clk_ipg); + if (ret) + dev_err(dev, "UART%d resume error!\r\n", sport->port.line); + + 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] | UCR2_SRST, sport->port.membase + UCR2); + writel(sport->saved_reg[2], sport->port.membase + UCR3); + writel(sport->saved_reg[3], sport->port.membase + UCR4); + + if (ret == 0) + clk_disable(sport->clk_ipg); + + 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, }, };