From patchwork Fri Jul 24 14:23:33 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shenwei Wang X-Patchwork-Id: 6860871 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 8166C9F358 for ; Fri, 24 Jul 2015 14:28:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 91A2F2053E for ; Fri, 24 Jul 2015 14:28:26 +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 1401920588 for ; Fri, 24 Jul 2015 14:28:25 +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 1ZIdtZ-000875-0O; Fri, 24 Jul 2015 14:24:17 +0000 Received: from mail-by2on0123.outbound.protection.outlook.com ([207.46.100.123] helo=na01-by2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZIdtW-00083D-Ju for linux-arm-kernel@lists.infradead.org; Fri, 24 Jul 2015 14:24:15 +0000 Received: from BLUPR03MB278.namprd03.prod.outlook.com (10.255.213.16) by BLUPR03MB519.namprd03.prod.outlook.com (10.141.80.144) with Microsoft SMTP Server (TLS) id 15.1.219.17; Fri, 24 Jul 2015 14:23:53 +0000 Received: from DM2PR03CA0001.namprd03.prod.outlook.com (10.141.96.11) by BLUPR03MB278.namprd03.prod.outlook.com (10.255.213.16) with Microsoft SMTP Server (TLS) id 15.1.231.11; Fri, 24 Jul 2015 14:23:52 +0000 Received: from BY2FFO11FD001.protection.gbl (2a01:111:f400:7c0c::186) by DM2PR03CA0001.outlook.office365.com (2a01:111:e400:2428::11) with Microsoft SMTP Server (TLS) id 15.1.225.19 via Frontend Transport; Fri, 24 Jul 2015 14:23:52 +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 BY2FFO11FD001.mail.protection.outlook.com (10.1.14.123) with Microsoft SMTP Server (TLS) id 15.1.231.11 via Frontend Transport; Fri, 24 Jul 2015 14:23:51 +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 t6OENnCU014349; Fri, 24 Jul 2015 07:23:51 -0700 From: Shenwei Wang To: Subject: [PATCH v2] Serial: imx: add dev_pm_ops to support suspend to ram/disk Date: Fri, 24 Jul 2015 09:23:33 -0500 Message-ID: <1437747813-9473-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; BY2FFO11FD001; 1:JCwtxpP61D4UvXr6XvK9BBehx24K99+7NGtOzoPFsczC9hqb+qT+uiCmXkJmShBgHYT6pgrAq9f5d5Ds+50rc8+w11ezZHknB/aebhVH5KjpZoSEH8v2NCOVXdlCq8kYh4wRhgKfnenPXWhnEHX8o4GlYmOL9/eOzu8uA9ZFTj8AIkSENHHGENldGmdFWaevweG7iRl3yke20CDGl4dnUSOQvmOXM40BFEBz2G58D8g4oUNw5eYpYwcmqhmdthob5IvX7xBzsCw8aAh8I/SI8y5LGEgwRsspnVV29bpmLolZL9hSqt6Oqwaz8nQz78BE X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(339900001)(54534003)(189002)(199003)(50466002)(46102003)(48376002)(110136002)(189998001)(106466001)(77156002)(62966003)(77096005)(92566002)(5003940100001)(36756003)(229853001)(86362001)(47776003)(104016003)(87936001)(6806004)(19580405001)(105606002)(5001960100002)(2351001)(85426001)(33646002)(19580395003)(5001920100001)(50986999)(50226001); DIR:OUT; SFP:1102; SCL:1; SRVR:BLUPR03MB278; 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; BLUPR03MB278; 2:ffAcyWjkTn9woBNkelW17GnUBolaAcLd7A9LaMZ4R3MsOMzQT0QI1wnQTzFp5LMwOoE0PwRDijr8s+c+y/5NXDMxwLXIcnmG4W5vA485gaOSd7CAcAsEuM/Lx9HdT4ALVqDVPTw2qIfNO3ecN1zSKc1jZUTA5GE1UIUnsRM2NMs=; 3:SIASxBAR+jpHj7TYy+3VRRFFe6rc4GO1Fa2pBXTpTv2TI7WIgU694zs00DBSqcSaaTwd35msdG8fmYQRS9xMqiXaKSK6xXBXrhUV5XLoFTcHM9IHcOelWbyCENFLXiZJTIiZmqbSStAD7tMsPIn3mUdBus1Ng6FrI+7V1ctcqZk6goFlQa2AbB9Yx4Bn171XlgdGPSDJJYH0R1p/tDoC/OMxOj0cSF1v8w2IwTfuVnA=; 25:ANd1nxzhbtLJ28VyoyvtMCTDrrXcwJwJDrOBAEzkS1WffscbDNcX62Yffot4x1t9ckNrGHu5ycgz5iRCFqkNRDfaeibCzEJnVfqzybsFIBh5GL5A6nuCyKKF8BlBotFVIxFIvRxc5hEsi1CN+dxDgfES9X6dMYep0I5Q1qPGT7yTZo0RmCgiblIWBGk6K+KYdRkkNvmwK5Ry9Ip4z8ldvge24huLINsISBPuEfs1+ix9s/4MQS0TsueWGo3q27DmVMyvCs6rm/EpLg7FMP0ghA== X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:; SRVR:BLUPR03MB278; UriScan:; BCL:0; PCL:0; RULEID:; SRVR:BLUPR03MB519; X-Microsoft-Exchange-Diagnostics: 1; BLUPR03MB278; 20:pw7byajJEEzicnceRxKu4VgSoNQtxwk/2neDkeUzXXlqAIGJIGeJl0U0gLy6OGAMLai+yn7sv+5K2U0pGv0/gV+rYiNOTLOnzrHaRyWIRDhEnrWMKIhQVvpyx80A6qROXtyG6gkf2RmmYLAU4SwmumENegHBWED/CNHujdRhiC9xNnvHblUXkuHERzEyriNeSSw7lgKCz3yCMc8Yykd7ip2/+I5nojzHu3NAW8gqkIgw/vdgU/yTSNWLX5ajbuDaNedOSyGNIX6YLA6/QjwqAJsfLJNG8b7ZObk5zcK/FEyhB/LGWDaTRMBKcbKYkMzHIwUGC2eF2Lkwu9y6BH3sCMHKYkoJN+t/d2cqK2DMCnA=; 4:3UA9WeikKzTu7I/FEwrUuILxHMZCkgDi4nm2QW0uQ5neyp2w6+RqRSaNKDw5kP7askProfBiORAk6xmf5H6nmqs+KaaCBDRJ/0rnFK+QKC8L8aQg0uADzEm1B74rzZlOG2YvvE5bD/9lMglT6PqCqPdcuCZXtrjKR4iLENH9U41h29es74RnGeVmlsdZYw8hTSo1RG+71lsuGWJp/Tkea7MMC6Zt82iTeOMzJt4OyWGgfcruw5as4bG2BCKrIyMslOwvJ1lGVbgkKCvYvwKBPWaKBmc/Z6Xukq0sWBK6fG8= 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:BLUPR03MB278; BCL:0; PCL:0; RULEID:; SRVR:BLUPR03MB278; X-Forefront-PRVS: 0647963F84 X-Microsoft-Exchange-Diagnostics: 1; BLUPR03MB278; 23:SqVazkaMrHdzAPlj7RYmbyXhQZuMXtHPII7rdhlVAHO23PlMsjpN+cAkds5PlF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XRuW9wlHVTgExcRVsHYTnHnRFnFv+OeyiXupcYkyg6JCe3Ac2JJtdZix7IFMf1itN+Qv7InNUo1gU9QqDSxtdPpaM8OgsRm29VhIwFg=; 20:Va3IZxaAAlk6ZfsI9OasawqOpQyortKQZ9u9+OejvlLGOlLVYp3N6aLrAuoO87URave0ldDsnUlKyhUok3iYNg== X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jul 2015 14:23:51.9330 (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: BLUPR03MB278 X-Microsoft-Exchange-Diagnostics: 1; BLUPR03MB519; 2:LiVytfv6YxkEw9B9I6UnHSv2ecsygOIO2IGVoCri1n4nCHSH02Ay8PpQFdG2uF7A; 3:MHZFx3IZEG7Hzy/QIPcptniG7ZnIVvmMazFAO5NrI4Pub5iT0zib3rLeBWhrtcDk64/7RLZ1Q26y2nTj2O0z0Ppxb4yvXTNVFm4fiuyMNG+VCYpbYdlfSnF31RS1vGJ+wfZZorELFZJgKZ6fsuKJls7AomiXMq9oxEdIKY6n336VxC45x/xnn5usELU3+ceNM0w4EyD9D8QAi3R3kO4MaFoPxt0kU1tq/GdXDsfXYOI=; 25:hrA5Jz7m1vn4wBcyNQsLsLPRa7ogFJHva//5Az2PEQKrwdlna3HHQCP6N17WXQ9Sc6DLxk/KkubZbYC3HZGjHLRfOP/5woKtLiHEc5afysHJ96T5n9DE/i9Jm7/XnJ4rcmbVNf8k2aQ2kdWE+SktI4GQHp4pasE7ZGbDEWRoCaArB2nF64QeRBiG6Dfd42qs/WUre+JANPuSL8mKWyR29bnxauIvEcZyYdrCkVy/tYLvwkIl9iOXpdrIDOuBx2ckq891xw11xdlwzkvaxjB/vQ==; 23:99mgAz/UvWnWC5VUIDt8bCC7E72TMgMkmBDPJtRQg3cLlHFtKG85YvwysYw9DCWiljv8gYTUJEXNzE9Ono6lKxJjuw9/62nmRU+R1UnBXgu1GXF3p07uclO289XtJyZ6XSMalYXhrnWWHLiDDbS5SBBD/dy9VmJ6U8qTg8Yk/rjs/f+2LIPtPRyeP5axhenuSVNj7z2wbe3FAxbSnYnOqMzWD+AX4xiDKp1oWZRiUSuQ2NpHcMbFx8ZSq8P3u24I X-OriginatorOrg: freescale.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150724_072414_806195_6284CD7C X-CRM114-Status: GOOD ( 19.56 ) 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.4 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. Signed-off-by: Shenwei Wang --- Change log: v2 Change pr_debug to dev_dbg per GregK's review feedback. drivers/tty/serial/imx.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) -- 2.5.0.rc2 diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index 2c90dc3..ef4d3fd 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 { @@ -1992,6 +1993,58 @@ 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 const struct dev_pm_ops imx_serial_port_pm_ops = { + .suspend_noirq = imx_serial_port_suspend_noirq, + .resume_noirq = imx_serial_port_resume_noirq, +}; + static struct platform_driver serial_imx_driver = { .probe = serial_imx_probe, .remove = serial_imx_remove, @@ -2002,6 +2055,7 @@ static struct platform_driver serial_imx_driver = { .driver = { .name = "imx-uart", .of_match_table = imx_uart_dt_ids, + .pm = &imx_serial_port_pm_ops, }, };