Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753095AbbKXMHK (ORCPT ); Tue, 24 Nov 2015 07:07:10 -0500 Received: from mx12-05.smtp.antispamcloud.com ([46.165.232.175]:40853 "EHLO mx12-05.smtp.antispamcloud.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752967AbbKXMHH convert rfc822-to-8bit (ORCPT ); Tue, 24 Nov 2015 07:07:07 -0500 Subject: Re: [PATCH v2] fpga: zynq-fpga: Enable pm_runtime (suspend, resume) To: Moritz Fischer References: <1447970832-774-1-git-send-email-moritz.fischer@ettus.com> <564ECAE7.9060900@topic.nl> CC: Alan Tull , Greg KH , Michal Simek , , =?UTF-8?Q?S=c3=b6ren_Brinkmann?= , linux-arm-kernel From: Mike Looijmans Organization: TOPIC Message-ID: <565452DB.8000300@topic.nl> Date: Tue, 24 Nov 2015 13:06:51 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8"; format=flowed Content-Transfer-Encoding: 8BIT X-Originating-IP: [192.168.80.121] X-EXCLAIMER-MD-CONFIG: 9833cda7-5b21-4d34-9a38-8d025ddc3664 X-EXCLAIMER-MD-BIFURCATION-INSTANCE: 0 X-Filter-ID: s0sct1PQhAABKnZB5plbIbbvfIHzQjPVmPLZeVYSu3xU9luQrU+8/8qthi+0Jd/W6KAUC/fjyuDn NXFr4uarw4L+0Gk8Er9EDAmooWNG6NUXhYU8Jrr8yzFMFofcPkGGaOJv1yhqRSmeI+CmjdBgg6Ta MzkscmNkGq0QLaxj17WRxCCVjKGNHHobxmphk6KCqQvGnEF5AYOOOFRrW/jtHsQmyO56CnIWdFG7 HGeBoVyYxLloU+fO6iZzJO1autPxdjxmrRG+Yr2w44GUVRd4Lx8scZPEo7N6Pf5PJywZ6bTN3Et1 R9JkebCP5t3901uwuIiWfbXmGP/7JVzpf9dZ9AlNiPSjtaF8E/p/HJFsoC5gJPC5qlgckLhODYCw jbzKgENJ/9r3xpUCmyHH/LzsqK96FsAwDJ+L/f6U7xJA+uyf9MPBD0+mPs3P8i8LnKRCiBVcTbjQ bxX/+kYmg5EHU3LYM3A6BXfvel8OEFDbU52d4QBMwRns26XOCF4YJs758eSmAkvysNuGCNDEi81V gtsfwlvSHWaU11skDPCC6TbVCZ1my7qTGj+pYSPpnV3tgSAqeihFev3wsZ/mTPLzZZsQrgz9ii6P 9NMYh5vidkhifFDKEuqo+y7SM5LKmlqk3XSq2E2jSZlKz92hhfD4QZ9WIA+d24zNKCR+8vOjc8c1 dOt47E4hX88q7EuJ0BoQmTHQX02yj7sQTBJF1UYnWcQxJoo2IkxG24CDQ98uI/0hEWyJzIkwSFAW 0Pw8uiKeFDhyrhWiOFT8srmpEcmA7F6L0DH2dm7YexLmt0wleAOuFwkDDG/lQ7mxnF16qsWYfeuT ov1vPAP3qEy01CsKm8SyJEFHLnf7plZdvFHh9EU5SJeoVHj5h7lL06fEAVxIaPd+yAYAo2e3BQ+D XZdqfgeYUOp7A73HI6oJg7w/VofLG3ZeVwLn1VF0nIrFa9Y7Gfn6GmFQDIwGeJZrj6Svnw== X-Report-Abuse-To: spam@mx99.antispamcloud.com X-Filter-Fingerprint: IFrWXGses7OKB5S5G8/dJUb3OPwsHaH0Fvg5oXltHd/JUWjZ8+qhjyB23tbDuyLOYL8Ff78gYsez 4Rl08xudmXi4esCQ0R1MchVjt7wblGlvhFgW0MjUMRkF5sMCDfftTXNFDzN17hnrWeZYOJvLq0Ic WjZ+XcEjj/7Pkld0zkmvziDInX9WdMov2kn2yXjdwv61T+KDYyYtREgszdyFwv8IxCB3p/oCKvxr eyISh3JGb7OS5oVgiO+kDxZrVPLz3MmEGC2PrUKqLq5WmHK+Nw== X-Originating-IP: 88.159.208.100 X-Spampanel-Domain: topic.nl X-Spampanel-Username: 88.159.208.100 Authentication-Results: antispamcloud.com; auth=pass smtp.auth=88.159.208.100@topic.nl X-Spampanel-Outgoing-Class: ham X-Spampanel-Outgoing-Evidence: Combined (0.00) X-Recommended-Action: accept Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3770 Lines: 133 On 23-11-15 23:02, Moritz Fischer wrote: > Hi Mike, > > thanks for your feedback. I put what I think you suggested inline below. > > On Thu, Nov 19, 2015 at 11:25 PM, Mike Looijmans > wrote: >> On 19-11-15 23:07, Moritz Fischer wrote: > >>> @@ -457,19 +457,26 @@ static int zynq_fpga_probe(struct platform_device >>> *pdev) >>> return err; >>> } >>> >>> + pm_runtime_get_noresume(&pdev->dev); >>> + pm_runtime_set_active(&pdev->dev); >>> + pm_runtime_enable(&pdev->dev); >>> + >>> /* unlock the device */ >>> zynq_fpga_write(priv, UNLOCK_OFFSET, UNLOCK_MASK); >>> >>> - clk_disable(priv->clk); >>> >>> err = fpga_mgr_register(dev, "Xilinx Zynq FPGA Manager", >>> &zynq_fpga_ops, priv); >>> if (err) { >>> dev_err(dev, "unable to register FPGA manager"); >>> - clk_unprepare(priv->clk); >>> + clk_disable_unprepare(priv->clk); > - clk_disable_unprepare(priv->clk); >>> + pm_runtime_put_noidle(&pdev->dev); >>> + pm_runtime_disable(&pdev->dev); >>> return err; >>> } >>> >>> + pm_runtime_put(&pdev->dev); >>> + >>> return 0; >>> } >>> >>> @@ -483,11 +490,45 @@ static int zynq_fpga_remove(struct platform_device >>> *pdev) >>> >>> fpga_mgr_unregister(&pdev->dev); >>> >>> - clk_unprepare(priv->clk); >>> + pm_runtime_get_sync(&pdev->dev); >>> + clk_disable_unprepare(priv->clk); > - clk_disable_unprepare(priv->clk); > >>> + pm_runtime_put_noidle(&pdev->dev); >>> + pm_runtime_disable(&pdev->dev); >>> >>> return 0; >>> } >>> >>> +static int __maybe_unused zynq_fpga_runtime_suspend(struct device *dev) >>> +{ >>> + struct zynq_fpga_priv *priv; >>> + struct fpga_manager *mgr; >>> + >>> + mgr = dev_get_drvdata(dev); >>> + priv = mgr->priv; >>> + >>> + clk_disable(priv->clk); > > - clk_disable(priv->clk) > + clk_disable_unprepare(priv->clk) >> >> >> From what I understand, this call is done in a sleepable context, so you can >> use clk_disable_unprepare here (and its counterpart in resume). And remove >> the prepare at probe time and unprepare at removal. >> >> Not all clocks can implement atomic enable/disable, for example I2C and SPI >> controlled clocks only implement the prepare/unprepare routines. >> >> I guess the "clk" here will always be a SOC provided one, so it won't make >> any difference for the Zynq, but someone is likely to some day copy/paste >> this driver and use it for some externally connected FPGA instead. > > To clarify. Is the above / below what you suggested? Indeed, that's exactly what I meant. >>> +static int __maybe_unused zynq_fpga_runtime_resume(struct device *dev) >>> +{ >>> + struct zynq_fpga_priv *priv; >>> + struct fpga_manager *mgr; >>> + >>> + mgr = dev_get_drvdata(dev); >>> + priv = mgr->priv; >>> + >>> + clk_enable(priv->clk); > > - clk_enable(priv->clk) > + clk_prepare_enable(priv->clk) >>> + >>> + return 0; >>> +} >>> + > > Cheers, > > Moritz > Kind regards, Mike Looijmans System Expert TOPIC Embedded Products Eindhovenseweg 32-C, NL-5683 KH Best Postbus 440, NL-5680 AK Best Telefoon: +31 (0) 499 33 69 79 Telefax: +31 (0) 499 33 69 70 E-mail: mike.looijmans@topicproducts.com Website: www.topicproducts.com Please consider the environment before printing this e-mail -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/