Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754478AbbHXU0Q (ORCPT ); Mon, 24 Aug 2015 16:26:16 -0400 Received: from mail-by2on0108.outbound.protection.outlook.com ([207.46.100.108]:45664 "EHLO na01-by2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751989AbbHXU0P (ORCPT ); Mon, 24 Aug 2015 16:26:15 -0400 From: Shenwei Wang To: "gregkh@linuxfoundation.org" , "arnd@arndb.de" CC: Huang Anson , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" Subject: RE: [PATCH v3 1/1] misc: sram: add dev_pm_ops to support module power gate Thread-Topic: [PATCH v3 1/1] misc: sram: add dev_pm_ops to support module power gate Thread-Index: AQHQyuKo+jZzRF1eu0qG6sYEArAqE54bv8Og Date: Mon, 24 Aug 2015 20:26:12 +0000 Message-ID: References: <1438272681-29338-1-git-send-email-shenwei.wang@freescale.com> In-Reply-To: <1438272681-29338-1-git-send-email-shenwei.wang@freescale.com> Accept-Language: zh-CN, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Shenwei.Wang@freescale.com; x-originating-ip: [192.88.168.50] x-microsoft-exchange-diagnostics: 1;BN3PR03MB1368;5:9amd35I26jWdy3p3QEFC9CenxXhilMbygPMc3nILYfsYSYwoJ66lFJf7d7DfTqcIN/TwgFAOOHZjW85jCJbiW/HOkehYD7pLvLh3axDm+HS28/m9bBS/EXMuIR/4phvzatVtfoD7Ip20Vx0/BxW3FA==;24:UIH0GWZE/MqPAa2iPSQN0hpZ1Or1dZe9mlBn/v9wJ8hicHAR/V+7mh04I6TKsZN578hIClsggKYWQXjrSjC+dFZ8VmhQ8IlUwVZZcjt4574=;20:jgNpnJs4OgCA72Y5EeBSJ4mjDbjxtfI9pt50uabM5dhdxTQoXfhMEZKng8oDjI1VUEeC4hUonLktG0YuvmMdzw== x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BN3PR03MB1368; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:; x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(601004)(8121501046)(5005006)(3002001);SRVR:BN3PR03MB1368;BCL:0;PCL:0;RULEID:;SRVR:BN3PR03MB1368; x-forefront-prvs: 06780E24F8 x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(6009001)(189002)(13464003)(199003)(54534003)(164054003)(46102003)(106356001)(5002640100001)(5001830100001)(5001860100001)(5001770100001)(66066001)(2900100001)(5007970100001)(189998001)(76176999)(5003600100002)(101416001)(2501003)(97736004)(54356999)(5001960100002)(76576001)(1720100001)(64706001)(10400500002)(50986999)(77096005)(77156002)(92566002)(2950100001)(86362001)(106116001)(99286002)(68736005)(5004730100002)(102836002)(4001540100001)(74316001)(2656002)(62966003)(81156007)(19580405001)(15975445007)(122556002)(40100003)(87936001)(19580395003)(33656002)(105586002);DIR:OUT;SFP:1102;SCL:1;SRVR:BN3PR03MB1368;H:BY1PR0301MB0839.namprd03.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; Content-Type: text/plain; charset="gb2312" MIME-Version: 1.0 X-OriginatorOrg: freescale.com X-MS-Exchange-CrossTenant-originalarrivaltime: 24 Aug 2015 20:26:12.2005 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 710a03f5-10f6-4d38-9ff4-a80b81da590d X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN3PR03MB1368 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by mail.home.local id t7OKQMkl013657 Content-Length: 4863 Lines: 157 Hi GregKH, Can you please take a look at this patch? Thanks, Shenwei > -----Original Message----- > From: linux-arm-kernel [mailto:linux-arm-kernel-bounces@lists.infradead.org] On > Behalf Of Shenwei Wang > Sent: 2015??7??30?? 11:11 > To: gregkh@linuxfoundation.org; arnd@arndb.de > Cc: Huang Yongcai-B20788; linux-arm-kernel@lists.infradead.org > Subject: [PATCH v3 1/1] misc: sram: add dev_pm_ops to support module power > gate > > 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(+) > > 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, > -- > 2.5.0.rc2 > > > > _______________________________________________ > linux-arm-kernel mailing list > linux-arm-kernel@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ????{.n?+???????+%?????ݶ??w??{.n?+????{??G?????{ay?ʇڙ?,j??f???h?????????z_??(?階?ݢj"???m??????G????????????&???~???iO???z??v?^?m???? ????????I?