From patchwork Fri Jul 24 17:12:59 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shenwei Wang X-Patchwork-Id: 6862161 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 0EE2D9F380 for ; Fri, 24 Jul 2015 17:16:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 187AE204EC for ; Fri, 24 Jul 2015 17:16: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 13ABD20460 for ; Fri, 24 Jul 2015 17:16: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 1ZIgXd-0000Tj-4b; Fri, 24 Jul 2015 17:13:49 +0000 Received: from mail-by2on0718.outbound.protection.outlook.com ([2a01:111:f400:fc0c::718] helo=na01-by2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZIgXZ-0000PD-MV for linux-arm-kernel@lists.infradead.org; Fri, 24 Jul 2015 17:13:47 +0000 Received: from CH1PR03CA005.namprd03.prod.outlook.com (10.255.156.150) by BLUPR03MB1364.namprd03.prod.outlook.com (10.163.80.30) with Microsoft SMTP Server (TLS) id 15.1.219.17; Fri, 24 Jul 2015 17:13:22 +0000 Received: from BL2FFO11FD030.protection.gbl (10.255.156.132) by CH1PR03CA005.outlook.office365.com (10.255.156.150) with Microsoft SMTP Server (TLS) id 15.1.201.16 via Frontend Transport; Fri, 24 Jul 2015 17:13:22 +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 BL2FFO11FD030.mail.protection.outlook.com (10.173.161.40) with Microsoft SMTP Server (TLS) id 15.1.231.11 via Frontend Transport; Fri, 24 Jul 2015 17:13:22 +0000 Received: from [az84smr01.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 t6OHDCB7027123; Fri, 24 Jul 2015 10:13:20 -0700 From: Shenwei Wang To: , Subject: [PATCH 1/1] misc: sram: add dev_pm_ops to support module power gate Date: Fri, 24 Jul 2015 12:12:59 -0500 Message-ID: <1437757979-25889-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; BL2FFO11FD030; 1:y0FYB/jSKJstIf49d0H/NMLSd15Q1ZvrMlg6UmWSgi5pHNxDywBLDdys/uAzn9ElQzbFgcdnoNcdiRmvZrzyGIHT0MA1fG7Fzw2L0TNh+AtPJwtUWDK827+nR54HZPI7pyTorJEWBY291AuNMMpr6YRpCTGx4Xr3JlJ13aXS68qJEuiiLpLKiykFd2n4okhApPohkCGzjfrizX8bQvy+J+yLtM4Vm1/eXbhRpHpgsnMsnS/gTmOf5bHrlZ0WYL2+y6fe6fxDE690ROVgIN3ujQM7Uu8two4vR9WIQgk2xdlEJmNzup3Zqw6OBv4fKMPJgESsPVtnQKmwduHARb1LAg== X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(339900001)(189002)(199003)(92566002)(48376002)(106466001)(50466002)(36756003)(107886002)(105606002)(5001960100002)(5001770100001)(47776003)(85426001)(189998001)(87936001)(86362001)(62966003)(50226001)(77096005)(104016003)(229853001)(19580395003)(50986999)(33646002)(46102003)(6806004)(19580405001)(77156002)(4001430100001); DIR:OUT; SFP:1102; SCL:1; SRVR:BLUPR03MB1364; 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; BLUPR03MB1364; 2:jafm7TdLbgxgViBWrH6klu5pq0J7qhyV/dgQ/8iqHfFeTjwRfHTRjYOIynbBTbrz; 3:xYQvZuDVroOU1pMq/70Bz5+IujtmLFGWgcpx1+wUVlEID30Ucy0B1jh/uXlB9JmGbqEoL46CYY0r1ZZ8udvioVU1Lvtl7+MA2Ki1EhyoH1O4SSHCNvGZcfMLY3h4PGfyZmS5GW1xKq8JyBUWzZFurkzo7MAhyDKO9nroqokDSXRoXlwb/1Ls31ukt/1RAsionZdYdMkp7zr/5O+33gID7a0znu0KwKVzYJOG9DtL5D4=; 25:d392EUly/HlVG/ZhqAYVFwzc8EPptC8MLowJB4v6X0wdC9xkkZPwE4uAatJJLiHO4MnEN7cjxJ9TU3OONc4RrQCWs6ukOzy23QaKVLwJJNWLGkQCATb4ObcpB/iRi1FI3otWx+rDVVvC9hHRA8qnKaUGsUUgCJQ5Uw8pIcYPfe0Sjddzm9mJnOAl/Vh+7X5LF0cp3IBVfD71uLj+cNmJau/c7TGm6OjA5QKkgd4xaHGwOLtoQM4cys42g9rLfgt300ipQM0Pw6s6HfqXOBNHKg==; 20:tkmYksTWVCh4RwOfb2Sy7KiyIxpxrHYLyc+M6RthaRYEmKjCnuduVIYWQpFX0B4DTZA03MOK40bM+nfkTPZMV3qZiSw7bYwnv7PWVPxdCcZziA5olLUV0DbXprr4Iol+SCUrVevva56eS8SHkPM80/ERYKyUMe2YqS7ijyBx7Kk3/3YAMRRhJy4ypYB7dcX7Ud2kv9TDEyNv48BP4Aay3VcKU24L+mGc5ZsAKs7zNBEaBnMLEnV+uHR9GhptZadgzBx8Pv3E82DIaz/QqOo16l2tKDvwRip+SqoG15Oo+FcfMEvlIFThPvHKGIr3qgy2RsOoUIiYyGr6EhVtGI+5br8RlMdnAb8fZD1wwx2Z68o= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR03MB1364; BLUPR03MB1364: 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:BLUPR03MB1364; BCL:0; PCL:0; RULEID:; SRVR:BLUPR03MB1364; X-Microsoft-Exchange-Diagnostics: 1; BLUPR03MB1364; 4:xKjPD7TCzVdieHMmotH00UetxKzyanMZjL03rZdx+aYfVPxf/tHlVaKI5ZR8nwAh3dJ9US+i8Fto+XzZ5V8SYv+n0eVEMVW9N8fQ+92WeeRnPRqIMr0zLMD2XNiTI3fOvTgfQs9cQ07jebV1Lthfhvt8AJurjEyLB6oDjwvpRKr94hCbr3N427jNBE/0hh4atyuM87YgMIiGhDUCgmwIbZ2UIEVfMq3mTI9bCcfsDG8NNUh4phmCxNJfOBmfcJinJlJb6kjBGlAgC6VuQfEqkgV4GrfxFt5xodvXhpFAj2M= X-Forefront-PRVS: 0647963F84 X-Microsoft-Exchange-Diagnostics: 1; BLUPR03MB1364; 23:3m9GOze9pwvWuRK0kDqKtz0mqwbruuoJOv7j14hHCMQQg6kBlHxU0aO/XF99tmgwOtacwysbhGByroVkT/1S0J8zBUkdwuhURGh1B4d/fFPYIXHA7OWQ3KRBXqsKarRdetWNBHtnGYpfrlyWCaX4Ol0Zqi2Q90p3pDurV0lnqrKb4ddvZ5KNPpNiUCH0Oo8fWAmMugIFWWufJsXm/b7AjacRMOlO0Fjosjw1OacrR80W2XcT1atjGq40Hzt3s5VsCrt6HfP8gRpxyQXxizaPZ1dam/dnSroGUV3Tq3EOmX38AlX5/MeqdMn58TyBnRwZIZzAM58Q99R5pGNe0y8rBwvykVsVtfSpQm6oAFkbM4Q1UrB8okH/dfFi+jo9grrwtDREV56DnBtJLBiCXtTsB/djxT2abIFEK8ck0WMXVTgwKxUwpNNmlwmsp3GQJpE7jpFOVHDTE7kDtvAUOcoqjjfc0jxP6wRjKOG619Gm+XU16e7EPYbIqOqFKuYsZQlsfDwsdEGC55Z7n80lamSPV7NQ//p4xXqTRls8f0v9Ltkw0l5sliHsLb1AfKDqellNoTa7FyxFRxGHoCXRteK5b3EazRpynslyfhPKmL1/G80XnrYP8fYecBn8JFsmIV/d5EdrTz2r4FHxME1knnvF/n57bK180LfOzHMn9BBbzb2lFEAuImtc/YTufSdfPnKlQIcEjRyGrv9d6o61JRA28LkWFm+OytLvPG+s9YG9Coy9+WfxrAAkiyV3+1D9czSW2rUbcoHCWIF5cpCeRJL/Rx/+M6kSpnqH3tRkw5hx5p5CUgjDl5s3qj0Vi53kRxECfp24P7rIUrfMf3G0r6w8XnoZbfw+E4BVHShjWBDAGa/pBXSkwAgRKC009IZNjRaJ X-Microsoft-Exchange-Diagnostics: 1; BLUPR03MB1364; 5:ch8Ol/MHBClqZiERxHxLZhCfNRNfuErL404fqDeZAqTFpX+wg6OzifcOOp82watnA91CUSCGp9Rb+4ggJln+vdJvZyrt1yDYN4G1V5aptjPeHhjH1Rd2QityOJo/zaf048IzoN8t/XsCXpDtgO27WA==; 24:5RKwybwaiyZlrmoZubbj2e9niVwLEpUE/SX0xMhhQCxXb0GFI7WrWQgQWtQJ4rEJiQXqXSaOYxglOFWvtvIsEax3tJPZHXlIQP+QJAgXxVQ=; 20:Ga4p9AS5k6UyO3cFuqSNNvQyUmZ0MyfZPUSYhNUcAJ0gCZwD5WyZ4DEa9b6Pw1IwPFsPE94s/4lkHsFMBNOoGg== X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 24 Jul 2015 17:13:22.1148 (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: BLUPR03MB1364 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150724_101345_820774_F360A566 X-CRM114-Status: GOOD ( 20.44 ) 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 --- Documentation/devicetree/bindings/misc/sram.txt | 2 ++ drivers/misc/sram.c | 44 +++++++++++++++++++++++++ 2 files changed, 46 insertions(+) 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..924692c 100644 --- a/drivers/misc/sram.c +++ b/drivers/misc/sram.c @@ -30,6 +30,7 @@ struct sram_dev { struct device *dev; + void *power_off_save; void __iomem *virt_base; struct gen_pool *pool; @@ -156,6 +157,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,gen_pool_size(sram->pool)); + 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, gen_pool_size(sram->pool)); + clk_disable(sram->clk); + + return 0; +} + static int sram_probe(struct platform_device *pdev) { struct sram_dev *sram; @@ -203,6 +235,12 @@ static int sram_probe(struct platform_device *pdev) platform_set_drvdata(pdev, sram); + if (of_get_property(pdev->dev.of_node, "can-power-gate", NULL)) + { + sram->power_off_save = devm_kzalloc(&pdev->dev, + gen_pool_size(sram->pool), GFP_KERNEL); + } + dev_dbg(sram->dev, "SRAM pool: %zu KiB @ 0x%p\n", gen_pool_size(sram->pool) / 1024, sram->virt_base); @@ -229,10 +267,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,