From patchwork Tue Aug 25 22:03:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shenwei Wang X-Patchwork-Id: 7073491 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 A30599F358 for ; Tue, 25 Aug 2015 22:05:58 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B8D06207EA for ; Tue, 25 Aug 2015 22:05:57 +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 C006B20772 for ; Tue, 25 Aug 2015 22:05:56 +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 1ZUMJh-0003AM-It; Tue, 25 Aug 2015 22:03:41 +0000 Received: from mail-by2on0131.outbound.protection.outlook.com ([207.46.100.131] helo=na01-by2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZUMJe-00037A-UK for linux-arm-kernel@lists.infradead.org; Tue, 25 Aug 2015 22:03:39 +0000 Received: from CH1PR03CA006.namprd03.prod.outlook.com (10.255.156.151) by BN3PR03MB1366.namprd03.prod.outlook.com (10.163.34.152) with Microsoft SMTP Server (TLS) id 15.1.243.23; Tue, 25 Aug 2015 22:03:16 +0000 Received: from BY2FFO11OLC011.protection.gbl (10.255.156.132) by CH1PR03CA006.outlook.office365.com (10.255.156.151) with Microsoft SMTP Server (TLS) id 15.1.231.21 via Frontend Transport; Tue, 25 Aug 2015 22:03:17 +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 BY2FFO11OLC011.mail.protection.outlook.com (10.1.15.22) with Microsoft SMTP Server (TLS) id 15.1.249.14 via Frontend Transport; Tue, 25 Aug 2015 22:03:16 +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 t7PM3CmU015383; Tue, 25 Aug 2015 15:03:15 -0700 From: Shenwei Wang To: , , , , , , Subject: [PATCH v3 1/1][Resend] misc: sram: add dev_pm_ops to support module power gate Date: Tue, 25 Aug 2015 17:03:07 -0500 Message-ID: <1440540187-6208-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; BY2FFO11OLC011; 1:DIWiFPOU7taMsT+WzDN4AC29FFGB8/KJm45ziH9KN4w4Ik7wL5T/fhWxt4Q1ULQq9bIhbUWCH2Y9gy2se8mjdm5tIb2Z0ti5SX10dfRDVVH8Ows5l3YeitxM+Yh8hZu35f8Sd7FZV1Hi0+gLuyjbNeipAvKfDA3xJOWakvLXXTrwLGToXnXfTdk0g+siJh2FzUZASLiRN17pCbdT/3fWNercQ/2uKncsrGrmKg4/WuQ6+9wQX+5KpGs5D7jwM1vK4vRJeAlP4XzMBxFPtsHheiG3XyTAjZ3sYfguJ0ZK4RZ3zrI3DK5yHL6TIlKq6dBEpHIT+tb9wWG4u0sTSw5qkq7LT4spgWxo395fe0lAtQ/2dokC3eJkJfqYBFd0YYLVEQyL4HqvoFfSWneIWEAIRQ== X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(3050300001)(339900001)(189002)(54534003)(199003)(47776003)(104016003)(229853001)(5001960100002)(189998001)(68736005)(4001540100001)(48376002)(105606002)(19580405001)(33646002)(6806004)(92566002)(36756003)(19580395003)(50986999)(77156002)(64706001)(62966003)(5001920100001)(50226001)(81156007)(107886002)(97736004)(77096005)(5001860100001)(86362001)(85426001)(5007970100001)(5001770100001)(87936001)(5003940100001)(5001830100001)(50466002)(106466001)(46102003)(4001430100001); DIR:OUT; SFP:1102; SCL:1; SRVR:BN3PR03MB1366; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; BN3PR03MB1366; 2:ieIgw1ltKLTBfcoEOVtNeuDDddUFlkVvQtaZQlE0wYEgS7KCh2PP6PN5ML2u0AvEPi2FzeZ/IyoXNkyCwCCZquHJd+fy1wB3qQVnqRG715RNmsQeLIFvHECWtWI/MY5KtGprsI1wqEB7WccMLvXqUeB/2149S9hYPr7d5x62rDk=; 3:E4mGPqI/bRJJRgXh/AgIdovcjqc5tcvDgmM1AwjIPEQbNo6/QnCStAAPkf3xUhgEMkZf1E4Eh2PJsGwhR1BhWDF0JATDKSW8rTAoci7AfG+Zsc7lM3zI49uYMs3OIqlXYvYrWMYCg+sh4rx1HKJPTq7D2ak401hUIpJhymvYo4XXdth01JTsyU17JMOR7oaWafKL89ql3XIQZB97QK3sk2rHTGAlgu2AkpvVCKZcxs4=; 25:iSUDrJHLN4LIR3UXeoM0mL9r4CtnspqKAPV5kGFDd0OgCSYMiSuY6GQOPbC5hb+nwsnxdIxwexJI9PDaxYtCpGdfZQcJedKwXZaDEyV2a1aI6J1GnkQ/Sh20rQHj02xSYOma+rILQQqhb0iF8y/H0Y9xf2y04wQEJ+WRlUI0kBiqjO/POlx4QGqVfP3MKV8b5fc4Rr7BZjpQxN7acqCp2r1ZweoNMtvH+0D3L+ys6fVYbKVroKY8h4QJSHryzeTCVlgQOlqgRfqcLrpGD2HK3A== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN3PR03MB1366; X-Microsoft-Exchange-Diagnostics: 1; BN3PR03MB1366; 20:o+NJnTmLAQj+L45IvRNdhyy/N1SbKKp0EIkSR8H24azQVcXoU4h6W/6Kt5uvZ7ciIvS5XrEnS6qVYMaRT55lIflowFrnFJEVo+MQEyXJjMpNCU+tYVszogrcou1YFOQCKZ2lR6woEiStPjW7XR2iQxwDHaRtnwK+vURkLykAcKeb8Y3l35DTR4LwZtbfifOuz72gxxlo+mcELMomG3KEk+jGDQ94kjdA/yXt4D7fPT2t6TuRWAmTuucto6P6lwIpZ4N5s7uib6n6hMJG4GpXoaCAnTzkS86OeoOr2nfttTEJ68Hd3bDolmEdBQCkKUIP8gSTgi4iKBtviN+8wp5bY/nh4mmZttpuvGeCYhn1Kiw=; 4:FFMdXarg9uZ0l7yHY4Tt3LFZjNWCPhMzG1r+cHjAmlZcEj+xmxjAn5OgCDweGgJkuZwmM2zWlJHZDsqVsFoYSBQYT7D9BY/XcSrZCm1gwMY2S96IyzhlY00kzfObclgsQttDe8r7QiowXI5dHfiOUAtQjNw6gwFStXly8mlReEDBDoRweneWLL2TLjb5WwQlZLTpMjMm43ed/8Lyn9AjwhlLPLXeV8tGVKu7KH6r0Z9Hmuq6tQil3+D3hAxhbIXj5AIKgK1h1PaKnAwQjRQw5gj6GtC531v5n2NLqlfmV+r71v2p6mXeJ3iEVKmw+Jex X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005006)(8121501046)(3002001); SRVR:BN3PR03MB1366; BCL:0; PCL:0; RULEID:; SRVR:BN3PR03MB1366; X-Forefront-PRVS: 06793E740F X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN3PR03MB1366; 23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SwT?= =?us-ascii?Q?IhIpq6odJw+YmMPItV1KYckT3OSqn9DnWQAHW9WyUevXUVnS83K8/a37aD6/?= =?us-ascii?Q?pEaP/gqzrLgDtHDCeTg3TrbQvhKDS9g7TV1j8KM8BYFVy3Lua/n4SW3j0sbi?= =?us-ascii?Q?JlMZ2AWxtRSkXU92OIj5SFiD3L89asjApQuxZZdQMSKEEuIcnhcT8PcVcWoo?= =?us-ascii?Q?WQsSxp16LaRDd9MF1moiLir+axhUXyDSZs+yYjsDdBjgrh9siw9QSzhdkOgN?= =?us-ascii?Q?fDQ9TFM1FwiiIKA7urLaM9DmzaRP6z+K7tSUNnQcFvA3696YrxzJU7Mcql+b?= =?us-ascii?Q?5DVAcKPXoDe0VEb/2zNqzRD6cZQDhqJYru4+8QjYDaf8vITul6J2DgGdw=3D?= =?us-ascii?Q?=3D?= X-Microsoft-Exchange-Diagnostics: 1; BN3PR03MB1366; 5:8WY76KGzRm2IA9+9a9WGVwNz87jBecwQMgH5tJ/27+tA1YTHB60G/dZu/45ih+sHu2+MvVXnd8tlzlO9Tfuuf1JG5F+IDk1AJ3ZGbijtrEK870/zSnytytSo+na/4v8u3DH8U3+g5FsplPqz5MgKcw==; 24:5oIqtdu52JjQOJ5Nfg9/qUOzwGAe2mkPcyUtCMrP+8U5GkmHmidWYGz+VZu38613zpNxN1MR7qvOfgn4envH8WvZD+rHBkdgu+wHM25cXro=; 20:CJNQqpZ8RpXQyJ5dOWTh/RduNC8eq6Nr0xpJNZ5Y108iB4BblMT+7iO/am3Wkm4JwCBjFIDIFu1k+GZ7zq1Q7A== X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 25 Aug 2015 22:03:16.1314 (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: BN3PR03MB1366 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150825_150339_063361_AA145770 X-CRM114-Status: GOOD ( 21.57 ) 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: devicetree@vger.kernel.org, b20788@freescale.com, linux-kernel@vger.kernel.org, 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.5 required=5.0 tests=BAD_ENC_HEADER,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. Based-on-a-patch-by: Anson Huang Signed-off-by: Shenwei Wang --- Change log: PATCH v3 Removed the unnecessary clk_enable/clk_disable. PATCH v2 Use vmalloc to allocate the SRAM backup memory. Code clean up. Documentation/devicetree/bindings/misc/sram.txt | 2 ++ drivers/misc/sram.c | 42 +++++++++++++++++++++++++ 2 files changed, 44 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..db9f1fa 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,33 @@ 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 */ + memcpy(sram->power_off_save, sram->virt_base, sram->size); + + 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; + + memcpy(sram->virt_base, sram->power_off_save, sram->size); + + return 0; +} + static int sram_probe(struct platform_device *pdev) { struct sram_dev *sram; @@ -176,6 +205,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 +233,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 +252,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 +265,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,