From patchwork Fri Jul 17 20:30:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shenwei Wang X-Patchwork-Id: 6819061 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 4348DC05AC for ; Fri, 17 Jul 2015 20:33:31 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 534BE20445 for ; Fri, 17 Jul 2015 20:33: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 158A8207E1 for ; Fri, 17 Jul 2015 20:33: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 1ZGCHh-0006Is-0g; Fri, 17 Jul 2015 20:31:05 +0000 Received: from mail-bn1bbn0106.outbound.protection.outlook.com ([157.56.111.106] helo=na01-bn1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZGCHd-0006Fd-UZ for linux-arm-kernel@lists.infradead.org; Fri, 17 Jul 2015 20:31:02 +0000 Received: from DM2PR03CA0004.namprd03.prod.outlook.com (10.141.96.14) by BY2PR03MB286.namprd03.prod.outlook.com (10.242.37.21) with Microsoft SMTP Server (TLS) id 15.1.225.13; Fri, 17 Jul 2015 20:30:39 +0000 Received: from BY2FFO11OLC003.protection.gbl (2a01:111:f400:7c0c::125) by DM2PR03CA0004.outlook.office365.com (2a01:111:e400:2428::14) with Microsoft SMTP Server (TLS) id 15.1.219.17 via Frontend Transport; Fri, 17 Jul 2015 20:30:39 +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 BY2FFO11OLC003.mail.protection.outlook.com (10.1.15.183) with Microsoft SMTP Server (TLS) id 15.1.213.8 via Frontend Transport; Fri, 17 Jul 2015 20:30:39 +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 t6HKUXaW032279; Fri, 17 Jul 2015 13:30:38 -0700 From: Shenwei Wang To: Subject: [PATCH 1/1] Serial: imx: add dev_pm_ops to support suspend to ram/disk Date: Fri, 17 Jul 2015 15:30:18 -0500 Message-ID: <1437165018-56026-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; BY2FFO11OLC003; 1:fRtXVwXed4Yt6wbILuQ0344c22KA+9Isbf4eE8qq8Q7jQYiRf0PEvSzeqxCvuIjQC6K96IvC+D6+HW/RyzqYjG2bot7rrRnUcBrkDpObav7K4X5FutLVANHgCYr1S5qEM4XmGKf/EJI4WoQt85vF1znn3Tyh1OUFUeOoujyHVeQPXvO0D4eLBXE5Wm4NPWD8apo0mZww+SmhXYLPZJnRqlaxd+hNeWv8l3fwZ9L+QyKV66dbca2MeyFizEMJG/rLy1zt+2Xq1Kecp3zY14EDX/AXC7HA/+tPSZvJaBZv9QI3dA79Z9ke/fIDsv35OQvFEixPuPISOP0zJYxm1qAJa4/pc54YNdW+yMK4Ihzr/J9NBsArMFFuLd2QuRoU6JZ1o/2NlaJnOyrHj3E65fcAETs+lH9GolfNU52T+l7GQeM= X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(339900001)(189002)(199003)(6806004)(106466001)(2351001)(87936001)(19580405001)(19580395003)(189998001)(33646002)(85426001)(50226001)(50466002)(229853001)(47776003)(92566002)(104016003)(77096005)(86362001)(105606002)(110136002)(5001920100001)(5001960100002)(62966003)(48376002)(46102003)(50986999)(77156002)(36756003); DIR:OUT; SFP:1102; SCL:1; SRVR:BY2PR03MB286; 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; BY2PR03MB286; 2:pzjhIXbEBz6y07GnhtpB6vvlIgQN+S3bBzcQc3QEI5tgu52EVUbc6WaJgP7TxXG20W2YYNafPb9jA71WMV3e/A0bxBCw8Kp6t/0bA+If6f14AtF/JSVWBgjZs8svwVD3LpabLEV7V+T2v2qraWQ+tr4rAGcVXJaRcbMdMTI1koo=; 3:QsjaTIc0okJLU1RddewDscXw/RnCk/GoSVIesmk9Au51T3eVRrP8w84qj+9mWxbhZDwSh1yymUlRiY/AGte7+qUVmeiAG4NxTAs4PFK/pRMwGSiuOflcyRL0/qVsxJtO0KKMNouctAfwjwdmOUnxTWGY6CGjnD0Qt4cv5ZiI9A95Xm+j8Zd67RLuxDha6TkNArpHYaXGzb7DiCU9Kl4r3H8sMee6B7MzXzk9zLnITI8=; 25:LcvupwOcgI9mPK6kEYlsPZTCUrykRlRlsp3gaLjqklyPFXYmdEyJdtYvCqFynLqn8vz4G7W27e9DNy9nst+JCQ+3p3HKSnnl6XuvA4J3qlMMiw4WsJu1eHuoJsHNXNhu6rZ3XmEJxmT2VD+/o8OC1WvzjfBoAiuIrnYgnrbWNZPTfu7nGvuxoz1cJwYmsGUmd880hZ8HuSgwxi/j0qsD/sqZnNnyk8/pS/SRUtpUqwpIXGlSbNIBn8G1Jcjf6IC9E/0hSlFbgPVtr8u51BntKg== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY2PR03MB286; X-Microsoft-Exchange-Diagnostics: 1; BY2PR03MB286; 20:2KM+nGjae3I/VAfkOTsRFmf6c1u5/tWX5hjbCgEHHMNF3UTo8fF379QwRMZAi8xz0tQ0RdOBmlScnTPV6loF0yAtjOfIWkqJ3vXLWNIlfDs6AjrBNrXR2wr3ewbVKFMhwH6hfoylD0leG0oti+XNNBN+eIj9Yln25ICTaBInaPlvKKIopwmfBiyO+8rI7f6bb5kRrEXNW7RtXyUzfnJAqYZDkw+iSObRL5FTeRqGE34nam2MZqDvfMTJkKp2626UESp+bw88t4vzrIZFo46AXFtbLJYjm0fW3wVltbyCK6z9P+pinX09DBHSXk/3MjnVO3xYZwZEMWscuUeJ4ut37NfVUjaj+SDihV9VmvDmWfk=; 4:/BWGQA8yzWZ31WhDrFSuYRGJEbBrCJ2UUSIkI1uMo4AU2EjgjI/40MqrhW8MVXFqXPwGmEw5kKFje/nb/vleBz3XYFoj65VJw5+KtBoodQJ0kf/BAVQfATCGKia9wS8d4HS6p9Y4sJob5hvOGe/OVWaHGKuyjv0KZs2JwWXgCUufSlQxkkLD760cIxL53Fh8oHRf7YwjH2Wso9oMuym/Z7LRcjUZG+ZFaEKPJbRt+IMX4bkVp2z5bHs/Sp4J02GviuI9X0y/UZ4Bl0D8YWQ4TGW9n/ENndYYLPT2mpEdLW0= BY2PR03MB286: X-MS-Exchange-Organization-RulesExecuted 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:BY2PR03MB286; BCL:0; PCL:0; RULEID:; SRVR:BY2PR03MB286; X-Forefront-PRVS: 06400060E1 X-Microsoft-Exchange-Diagnostics: 1; BY2PR03MB286; 23:6FYMRaFN9CruMecH3/obLpfV7PsSciGgwB8Lboz/TOAQY15hAu3sksBbGV+LomEH34GIaLrzaf+w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nlqrSeURk/aab6jtsI=; 20:Lkds+65EMP69saMv2t7yy/WlOh8unpHgs4hV9nRZ/OPilkPvMV3Z0PpaOtJzXX+ro1lsvLtAT/2VOXb64JG46A== X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Jul 2015 20:30:39.1919 (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: BY2PR03MB286 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150717_133102_272139_C6C9F043 X-CRM114-Status: GOOD ( 19.04 ) 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 --- drivers/tty/serial/imx.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/drivers/tty/serial/imx.c b/drivers/tty/serial/imx.c index c8cfa06..acaaa68 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 { @@ -1986,6 +1987,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); + + pr_debug("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); + + pr_debug("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, @@ -1996,6 +2049,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, }, };