From patchwork Thu Jul 30 16:11:21 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shenwei Wang X-Patchwork-Id: 6903761 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 DD439C05AD for ; Thu, 30 Jul 2015 16:14:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E91742055A for ; Thu, 30 Jul 2015 16:14:31 +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 A598E2058E for ; Thu, 30 Jul 2015 16:14:30 +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 1ZKqR3-0001MG-6l; Thu, 30 Jul 2015 16:11:57 +0000 Received: from mail-bn1on0131.outbound.protection.outlook.com ([157.56.110.131] helo=na01-bn1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZKqR0-0001Gw-FZ for linux-arm-kernel@lists.infradead.org; Thu, 30 Jul 2015 16:11:55 +0000 Received: from BY2PR03CA044.namprd03.prod.outlook.com (10.141.249.17) by BN3PR03MB1367.namprd03.prod.outlook.com (10.163.34.153) with Microsoft SMTP Server (TLS) id 15.1.225.19; Thu, 30 Jul 2015 16:11:32 +0000 Received: from BY2FFO11OLC007.protection.gbl (2a01:111:f400:7c0c::126) by BY2PR03CA044.outlook.office365.com (2a01:111:e400:2c5d::17) with Microsoft SMTP Server (TLS) id 15.1.225.19 via Frontend Transport; Thu, 30 Jul 2015 16:11:32 +0000 Authentication-Results: spf=fail (sender IP is 192.88.158.2) 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.158.2 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.158.2; helo=az84smr01.freescale.net; Received: from az84smr01.freescale.net (192.88.158.2) by BY2FFO11OLC007.mail.protection.outlook.com (10.1.14.254) with Microsoft SMTP Server (TLS) id 15.1.231.11 via Frontend Transport; Thu, 30 Jul 2015 16:11:32 +0000 Received: from [az84smr01.freescale.net (B38339-11.am.freescale.net [10.81.93.199]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id t6UGBTRP021355; Thu, 30 Jul 2015 09:11:31 -0700 From: Shenwei Wang To: , Subject: [PATCH v3 1/1] misc: sram: add dev_pm_ops to support module power gate Date: Thu, 30 Jul 2015 11:11:21 -0500 Message-ID: <1438272681-29338-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; BY2FFO11OLC007; 1:MKZnJl2klQ5ox3l77dEA8rG7v44vGfm0pKUwzJsKRk6u1sddUeUULdK4xMrRbw6Z1E2DeNrsaBohDgpF/DJaAKPw4An68D5yy6idcfS4Z0mpFuinZxVioLSoYxWi/9+qCoDnF9WMylTljheoe6/e+Sagr5HV7bUl0RX1AaWzw2bDTysFFuQP521iWiBZ+LOHLuq1J2LpyCaoFVK/kGxvawWwVkk6Bf+9cuzFL4D4MvKId3xFrVOpqPohmw15oXZiDUEdi9C9Y+q5k2LovA7C819HUhhqKJD36Jvsgyc8+hUkZb2EZm6f+6xmW9UGp3annfgqH+3N/MxnQEOVz8gv/g== X-Forefront-Antispam-Report: CIP:192.88.158.2; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(2980300002)(339900001)(189002)(199003)(85426001)(107886002)(92566002)(6806004)(189998001)(77096005)(19580395003)(48376002)(105606002)(106466001)(62966003)(36756003)(50986999)(77156002)(87936001)(19580405001)(50466002)(86362001)(50226001)(229853001)(5001770100001)(33646002)(104016003)(47776003)(5001960100002)(46102003)(4001430100001); DIR:OUT; SFP:1102; SCL:1; SRVR:BN3PR03MB1367; H:az84smr01.freescale.net; FPR:; SPF:Fail; MLV:sfv; MX:1; A:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Exchange-Diagnostics: 1; BN3PR03MB1367; 2:QQZzX0/gcPaJWBahL/ztBdSu4brATMpypCs3uO5XuecGCsAg88PjRqWWQWA/EUzyEHrGRQklDNxODyd4v295B2P5qVCTamHYRGWXkx2TTwVsTaohrqqpyp1Zq+JMH1PhU7opK9mYKbqJIHLzPZj0mwWhWKsuvC3BwAW1xdcr/uI=; 3:ZkB8Whg4t1k4tSs1LMGfmFU39W5yhfifjkFtc8pfgDNV5Y4X2fgQyjgWRT5B1LdOCO8lYc/p0j8CoMVZDWf1VJSaY69uLTQxzTwvzjhZThHbCEwZIsA8oEXWpaPXknjkz3K8FF+QnGA+LW6UBrTrSY4UJfy0qrXLmueTDrriCqhAuHIzlo3XdvPpuDWURL1yHyvka67fa9jDv2a5xLm9Q24XlyuhyysK1MOdDfHdtMU=; 25:3nS6L/szKETePDsHXZmtutUo/eIfQK0RS8AuR1Rf9mOazOsYGZZmoUlDd0cP369Qa43CJmLAvSNbtiN+CHG2ZAhkELYEFoFk3rOt5ed0ob+NeRsW6M9/s4WDoDwAc+hp7g5DdiEMkp4kay+GP3afW7kg9DV7dxeQHjzN2U11zGX5s44eybf/sJFLbN9c8i7N8sAkqRlzfmxf7AVU1aHPQLcRkInRPH+E7jS/0oENajtnPTb8iXQlplbjzSquOTlq41n8j63BK3bnGxfH84eLYg== X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN3PR03MB1367; X-Microsoft-Exchange-Diagnostics: 1; BN3PR03MB1367; 20:+9VuW9iJbLiKsgfa53djGINaO6ViHYWYU+24DRE/QmfV70BMqlleJQQe4wcVIzXwIJaIE7mS/GiN612scgR/mZjnrgqoS4bJtSrOq+deXlRGy7xviQhgVQqfeD+uT8lMB3M8FlbdvGyym0QKkY3HJt7jHaEWA0yAvZl2m4gzv2iCotzk/DRng9HOv7YAa7XrHgxMPEsT2W0KFRxkiap6DrMqqAdhEtU1ZU3Am3iLPQrig/rYlhoGdTWzXey7q91p2kVUVG6JRQY/FHMtUU11ne38E5TCZBF4sbf13ZZt5/NgkJROVGGmSuqfrsquaVhFS9DklNzCqEXAVMPWXKHjinKk5Ud48Unt18cVHRViM/I=; 4:FGu/GtYKnucQyI//tgbAUbmJwkALwVLg4Age88eX8GgnYgW+vbblYCfo9fbJleFIFSy8oaWqAmBcoiQx7fCxkCdQuQGinDOSpve48ZbrTDwR7JnfmVRLpM18S8J1Wr7Sz1fNtk9P/K0T34zBxOpc/d0LdbWlGWwTHKgGkRT767pZAPRy0IR4fVhM73Kyso2biKGvw66vuKLrBdQ2XKLQlgkJn/fNVWHFD9dMY1Op4zFmruMHSNmrxwQXFFvwdY3jdexQv5XJvJwWu3yqSwREM8soBWqoaBM5yswGNT8UR9U= BN3PR03MB1367: 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:BN3PR03MB1367; BCL:0; PCL:0; RULEID:; SRVR:BN3PR03MB1367; X-Forefront-PRVS: 06530126A4 X-Microsoft-Exchange-Diagnostics: 1; BN3PR03MB1367; 23:eFw60S25nlfVabzgaZGorhRDcgA9vACSx3OZtZMyVA3iTB5QM+5zNhOn01ETS+Csu/LM8MVoXPD+EaC4jSjW+VlgvkYklCdmMgDgDSF2aU4JBnMAnj/1o1L4nnm1hwh3Up8iywC39RDRZzsOkwANg98spsiCWgtINLsjna+BF+RgsntpAVPyTjtvnQLd0P9pa00nIbx9+7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riginatorOrg: freescale.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2015 16:11:32.3630 (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.158.2]; Helo=[az84smr01.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN3PR03MB1367 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150730_091154_799122_77DEEB02 X-CRM114-Status: GOOD ( 16.98 ) 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.6 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: 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,