From patchwork Fri Jul 24 21:02:13 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shenwei Wang X-Patchwork-Id: 6862911 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 A1FC2C05AC for ; Fri, 24 Jul 2015 21:17:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id AE399205B4 for ; Fri, 24 Jul 2015 21:17:29 +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 A95A2205B3 for ; Fri, 24 Jul 2015 21:17:28 +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 1ZIkJJ-0002YR-8M; Fri, 24 Jul 2015 21:15:17 +0000 Received: from mail-bn1on0113.outbound.protection.outlook.com ([157.56.110.113] helo=na01-bn1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZIkJG-0001OR-3V for linux-arm-kernel@lists.infradead.org; Fri, 24 Jul 2015 21:15:15 +0000 Received: from CO2PR03CA0043.namprd03.prod.outlook.com (10.141.194.170) by BY1PR03MB1372.namprd03.prod.outlook.com (10.162.109.30) with Microsoft SMTP Server (TLS) id 15.1.225.19; Fri, 24 Jul 2015 21:14:49 +0000 Received: from BL2FFO11FD056.protection.gbl (2a01:111:f400:7c09::104) by CO2PR03CA0043.outlook.office365.com (2a01:111:e400:1414::42) with Microsoft SMTP Server (TLS) id 15.1.201.16 via Frontend Transport; Fri, 24 Jul 2015 21:14:51 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=freescale.com; freescale.mail.onmicrosoft.com; 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 BL2FFO11FD056.mail.protection.outlook.com (10.173.161.184) with Microsoft SMTP Server (TLS) id 15.1.231.11 via Frontend Transport; Fri, 24 Jul 2015 21:14:49 +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 t6OLEfSN005616; Fri, 24 Jul 2015 14:14:48 -0700 From: Shenwei Wang To: , Subject: [PATCH v2 1/1] misc: sram: add dev_pm_ops to support module power gate Date: Fri, 24 Jul 2015 16:02:13 -0500 Message-ID: <1437771733-55446-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; BL2FFO11FD056; 1:+SuQ1cOlJGGrLQQm4f0P70HZhqZD5szN0jtMyl6Ez9tBjCOloB3ssfQaJAp2DHMp83gb/gTAijHm7yO9EA3cpLlf5DLwWfVy8ArD7o8xP7p5K11CgCdckADx2lhwI/2AAhej7KH7x0PMsDVjaZhJhz1KvaQ2ZyqOr0ONHNMAR/2Tos63N6qQeZtSCe/i0Rq7xkhPSau0FhsMrsywNMvQt8eRLYvQngZ8tTuL/87WKHayKT7ia+k1FRZ3ymObzjb3yERQd5S8vPibsbrnKJpKkgTk4wGIrSAZAo3j7AIkCSMOYm/7CHESNU2zXqgf4kuN4XcjaBzNe+/Z9mO0c3PbQg== X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(339900001)(189002)(54534003)(199003)(229853001)(5003940100001)(105606002)(50986999)(36756003)(6806004)(19580405001)(77156002)(47776003)(33646002)(62966003)(104016003)(19580395003)(86362001)(92566002)(77096005)(5001920100001)(85426001)(107886002)(87936001)(50226001)(48376002)(46102003)(5001770100001)(5001960100002)(106466001)(189998001)(4001430100001); DIR:OUT; SFP:1102; SCL:1; SRVR:BY1PR03MB1372; 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; BY1PR03MB1372; 2:DVxfBl14SuESpqC79GZAgzrOBYKUjGrUtiDnvO7FQhVK4R7flC4iylLGroYAMbM44hY/RZJJevkFfESJpV5VtdPeVwenVFpq5yK7lPbMOPTuAfQrNU68I4+s/FKP8Itq/UHYg/IncBCT8H7uwtP6cze55Lk1y41Kk36mvEMKX8I=; 3:cpvXdeLmDaiRXK7kLfNGJBS8g47+NRu8nKLqi04KMU+aobME05u1SwlUdwVdJX8Aj5bQOvYdPv8C3nVPQswI/MS4iqd5c410FP+B3ucf42fbdv9ujULC6/o3cAkYQXEco+WkeJvex5+YOWkpXI9Br+0WfTKpgb2K66dYXrQ+n1+CYr1k/r6t9tLYCP9VzO1VMRiXCU1sUmbQ3Z6NBQEwGZSGbF8R2jyv+n2ty94r4ps=; 25:rCRMsEjcaYlvg0VsyaiBr9o7uRS8ijGLad/sWUojXNyLfwqA7vo+Mj97NRt1z44EflV0p5Vk+P4LJq0NMVnWBaclGpwGQrFGVB3kuQSt2+aphQa8vE0VfTiq7Ly2doElPtTg04LSfYYkgdJVTRmrk8lcQ2y3aLRlvnSt58mDmciOIoVYYz+dhIOGEgAbyoQsIKksR/C+k8Fg3ijRvMqgCkuFHaXzJUO+YbrqDAdhRe+7K5E2KGrVl6zeQlp1Qbl3hYEuuPDiHzJPe+PBj+cdPQ== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BY1PR03MB1372; X-Microsoft-Exchange-Diagnostics: 1; BY1PR03MB1372; 20:R4YZHuagUWCL/asPGhkcrGyJ0IfA+Bd3gyd7rEziL79OKsgB1TX/DKQm4OYZ5frp9d8olvG6BGGNFzCBypZtlRdQTHtVH1cg7t+5gTvR3PP14cJFYUP0UlCIXwEhfQIYElAgtEywI7MooxNUOkd0dyzbLxAUIUxqINYkzpZtOWJ6C9EbC9lrUiZ229m9MvKlPP9UfahHSZpRtcswdep7OsQb5trY5m9sc4YqElKLJpnldfy7HvC1LTwxfOouGLAtAistvD9/yxO9x/jdG7XwhwlftRdEurLy/iA3YHR8RRJHrSHk1R/nuqwPLc0ABZO1Al9sS6KZUyeOzFmXPROI6ArHjZ3njaMpmyGkveVRjAM=; 4:2raEulUjjWNclrA30HyIrcJH61yrVm5y7cJl8orWkYwZ7RvO5ToC4IUAVsPQy+FV0C0wG9VBB6KSe5iamyFf+l/QXqnymTxKsafUqlnv3WE+EG8ZnJC6kd9tp2VcC9NK7dRiq9XXnOEf6IWt0aRP2jOu1z9MVqOXem89CJDWsPGQQcviLc/qJvdj3tYuqyV9UZdn4hMv+8WN8Bh9pMq18pZ2ZRVcGeZc8NcZREs4EIznaXUznInm2rvuImYAZ6ZTYSTBz72FWjaI7N5yYgRQqdxm5y8AI1FB1U5nUCsic48= BY1PR03MB1372: 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:BY1PR03MB1372; BCL:0; PCL:0; RULEID:; SRVR:BY1PR03MB1372; X-Forefront-PRVS: 0647963F84 X-Microsoft-Exchange-Diagnostics: 1; BY1PR03MB1372; 23:4s09TsklgYjEQ7U6YqSsKGLc29fBLPYJiKeNPsAxrpbdsQwZG11PmQoVcEpsO3CNcvRgqP3b0mfeLL43v5m6x9fVuw//L7l8rNl7MqdGwalEcKX1pjdMbWMMHF9qXfJGe0t6H2driW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UZtQ2dCmrANqQ2eYv4KGhPQRH6zOePNirRVhJijCSNkH4PGSHQ+M=; 20:O94Zpws2K/6xUcf4WUvBcYDvoZaYxRzENCsoAtjZm9XiDaP03SFyRRbLO3k7p9ao3Ip9Je8m4EXHLGIefRN2fg== X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jul 2015 21:14:49.1793 (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: BY1PR03MB1372 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150724_141514_439340_3A3471BB X-CRM114-Status: GOOD ( 20.33 ) 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: b20788@freescale.com, linux-arm-kernel@lists.infradead.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 will lost all the data inside the ram. This patch added the dev_pm_ops and implemented two callbacks: suspend_noirq and resume_noirq, which will save the data in the on-chip-ram right before power down and restore it after system resumes. A new property string named "can-power-gate" is added to the devicetree bindings too. Signed-off-by: Shenwei Wang Signed-off-by: Anson Huang --- Change log: v2 Use vmalloc to allocate the SRAM backup memory. Code clean up. Documentation/devicetree/bindings/misc/sram.txt | 2 ++ drivers/misc/sram.c | 46 +++++++++++++++++++++++++ 2 files changed, 48 insertions(+) -- 2.5.0.rc2 diff --git a/Documentation/devicetree/bindings/misc/sram.txt b/Documentation/devicetree/bindings/misc/sram.txt index 36cbe5a..1170086 100644 --- a/Documentation/devicetree/bindings/misc/sram.txt +++ b/Documentation/devicetree/bindings/misc/sram.txt @@ -33,6 +33,8 @@ Optional properties in the area nodes: - compatible : standard definition, should contain a vendor specific string in the form ,[-] +- can-power-gate: a property to tell the driver that the sram can support + power gate Example: diff --git a/drivers/misc/sram.c b/drivers/misc/sram.c index 15c33cc..63ba01d 100644 --- a/drivers/misc/sram.c +++ b/drivers/misc/sram.c @@ -30,7 +30,9 @@ struct sram_dev { struct device *dev; + void *power_off_save; void __iomem *virt_base; + u32 size; struct gen_pool *pool; struct clk *clk; @@ -156,6 +158,37 @@ static int sram_reserve_regions(struct sram_dev *sram, struct resource *res) return ret; } +static int sram_suspend_noirq(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct sram_dev *sram = platform_get_drvdata(pdev); + + if (!sram->power_off_save) + return 0; + + /* Save necessary regs */ + clk_enable(sram->clk); + memcpy(sram->power_off_save, sram->virt_base, sram->size); + clk_disable(sram->clk); + + return 0; +} + +static int sram_resume_noirq(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct sram_dev *sram = platform_get_drvdata(pdev); + + if (!sram->power_off_save) + return 0; + + clk_enable(sram->clk); + memcpy(sram->virt_base, sram->power_off_save, sram->size); + clk_disable(sram->clk); + + return 0; +} + static int sram_probe(struct platform_device *pdev) { struct sram_dev *sram; @@ -176,6 +209,7 @@ static int sram_probe(struct platform_device *pdev) } size = resource_size(res); + sram->size = size; if (!devm_request_mem_region(sram->dev, res->start, size, pdev->name)) { dev_err(sram->dev, "could not request region for resource\n"); @@ -203,6 +237,9 @@ static int sram_probe(struct platform_device *pdev) platform_set_drvdata(pdev, sram); + if (of_property_read_bool(pdev->dev.of_node, "can-power-gate")) + sram->power_off_save = vmalloc(size); + dev_dbg(sram->dev, "SRAM pool: %zu KiB @ 0x%p\n", gen_pool_size(sram->pool) / 1024, sram->virt_base); @@ -219,6 +256,9 @@ static int sram_remove(struct platform_device *pdev) if (sram->clk) clk_disable_unprepare(sram->clk); + if (sram->power_off_save) + vfree(sram->power_off_save); + return 0; } @@ -229,10 +269,16 @@ static const struct of_device_id sram_dt_ids[] = { }; #endif +static const struct dev_pm_ops sram_pm_ops = { + .suspend_noirq = sram_suspend_noirq, + .resume_noirq = sram_resume_noirq, +}; + static struct platform_driver sram_driver = { .driver = { .name = "sram", .of_match_table = of_match_ptr(sram_dt_ids), + .pm = &sram_pm_ops, }, .probe = sram_probe, .remove = sram_remove,