From patchwork Tue Nov 17 17:11:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Moritz Fischer X-Patchwork-Id: 7639991 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 0B2469F392 for ; Tue, 17 Nov 2015 17:15:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0EE62204D5 for ; Tue, 17 Nov 2015 17:15:01 +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 1D658204D2 for ; Tue, 17 Nov 2015 17:15:00 +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 1ZyjoP-0004xa-HM; Tue, 17 Nov 2015 17:12:57 +0000 Received: from mail-pa0-x231.google.com ([2607:f8b0:400e:c03::231]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZyjoD-0004dr-4C for linux-arm-kernel@lists.infradead.org; Tue, 17 Nov 2015 17:12:48 +0000 Received: by pabfh17 with SMTP id fh17so14955231pab.0 for ; Tue, 17 Nov 2015 09:12:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ettus_com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=/Ls+Cb9DdmcIIOb+E+3MgjmKbKAIHkmonUZRSFN52uU=; b=XQifU1Mayr+q8x9uR0N0Rd8sVBneT+OasFEc0RlWMWznvbamy7HWFK6x5epCdQpg+2 F3v1D75tX9Y+DJWvIXiW5KGuj3GP0MkZqtUoxgxvHH6YLS4EmKu2x/Hj/PoJtg4zl4Lb xoYpuGfnDjtTEoKqXym6Xa+XiTS9NEoCyXh55qdJa69zdVjekEctLTG6JHTJV9XDqoE2 SJLoe9JYZi/AJjqaA2Nk3uSphMZUwVXtKKk1c7frGY3WyFo94EMpDCpc1h7e5w5ouQHb jSZP7TrCwNgc5J1uZIZnk6SU5n70Z0YBiv02L7pPuflxFKQYbEnjs2LWvse/RbigD0cl PHKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=/Ls+Cb9DdmcIIOb+E+3MgjmKbKAIHkmonUZRSFN52uU=; b=Xa1lDaqoe0s9BNweTkfIY0PY/MuTWMhGswuUUphGJpcdscIkR9Tr/k96Ly+aMLdbGi F5R81gdagacQ8wFJoxj0p5XrrSG9cDAW0O2so/c8sA6B6vQI+Nd55M3pxegB1RZKHhev ur+3NS/xjok242oNWjjxKEq+TYPlstY5Et1rsYErDOMN+fRtFAz/xsZTePt6SDw15f8E HU9nJH4tzAv0jJeDIdL9NxPtlnkMguPE9vfrVRfpscd6ENRnonCW6tX4SJ07alGGvPlP MRGKAHl6yZ7+2UxirG6jCLSMQ+Q6tSYN5eXMoMcO+jkQHpoi48i6m/PmQ+OasTrnblgQ nLUg== X-Gm-Message-State: ALoCoQmXH2S5dh4/WkR677ujyM7Voak6ZhEtsQp0n2EzSH2kXpWScWQE0hUeO/11HU8DzWVlSF48 X-Received: by 10.68.133.134 with SMTP id pc6mr50911868pbb.35.1447780343690; Tue, 17 Nov 2015 09:12:23 -0800 (PST) Received: from fenrir.amer.corp.natinst.com (207-114-172-147.static.twtelecom.net. [207.114.172.147]) by smtp.gmail.com with ESMTPSA id rn7sm44168737pab.23.2015.11.17.09.12.22 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 17 Nov 2015 09:12:22 -0800 (PST) From: Moritz Fischer To: atull@opensource.altera.com Subject: [PATCH] fpga: zynq-fpga: Avoid hammering clk_{enable/disable}. Date: Tue, 17 Nov 2015 09:11:57 -0800 Message-Id: <1447780317-27758-1-git-send-email-moritz.fischer@ettus.com> X-Mailer: git-send-email 2.4.3 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20151117_091245_581186_AD5A8B20 X-CRM114-Status: GOOD ( 16.55 ) X-Spam-Score: -2.6 (--) 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: Moritz Fischer , gregkh@linuxfoundation.org, michal.simek@xilinx.com, linux-kernel@vger.kernel.org, soren.brinkmann@xilinx.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,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 Replaced constant clock_{enable,disable} calls with pm_runtime hooks. Signed-off-by: Moritz Fischer Acked-by: Alan Tull --- drivers/fpga/zynq-fpga.c | 79 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 62 insertions(+), 17 deletions(-) diff --git a/drivers/fpga/zynq-fpga.c b/drivers/fpga/zynq-fpga.c index c2fb412..5c03fb8 100644 --- a/drivers/fpga/zynq-fpga.c +++ b/drivers/fpga/zynq-fpga.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -184,8 +185,8 @@ static int zynq_fpga_ops_write_init(struct fpga_manager *mgr, u32 flags, priv = mgr->priv; - err = clk_enable(priv->clk); - if (err) + err = pm_runtime_get_sync(priv->dev); + if (err < 0) return err; /* don't globally reset PL if we're doing partial reconfig */ @@ -271,12 +272,12 @@ static int zynq_fpga_ops_write_init(struct fpga_manager *mgr, u32 flags, ctrl = zynq_fpga_read(priv, MCTRL_OFFSET); zynq_fpga_write(priv, MCTRL_OFFSET, (~MCTRL_PCAP_LPBK_MASK & ctrl)); - clk_disable(priv->clk); + pm_runtime_put(priv->dev); return 0; out_err: - clk_disable(priv->clk); + pm_runtime_put(priv->dev); return err; } @@ -301,9 +302,8 @@ static int zynq_fpga_ops_write(struct fpga_manager *mgr, memcpy(kbuf, buf, count); - /* enable clock */ - err = clk_enable(priv->clk); - if (err) + err = pm_runtime_get_sync(priv->dev); + if (err < 0) goto out_free; zynq_fpga_write(priv, INT_STS_OFFSET, IXR_ALL_MASK); @@ -335,7 +335,7 @@ static int zynq_fpga_ops_write(struct fpga_manager *mgr, err = -EFAULT; } - clk_disable(priv->clk); + pm_runtime_put(priv->dev); out_free: dma_free_coherent(priv->dev, in_count, kbuf, dma_addr); @@ -349,8 +349,8 @@ static int zynq_fpga_ops_write_complete(struct fpga_manager *mgr, u32 flags) int err; u32 intr_status; - err = clk_enable(priv->clk); - if (err) + err = pm_runtime_get_sync(priv->dev); + if (err < 0) return err; err = zynq_fpga_poll_timeout(priv, INT_STS_OFFSET, intr_status, @@ -358,7 +358,7 @@ static int zynq_fpga_ops_write_complete(struct fpga_manager *mgr, u32 flags) INIT_POLL_DELAY, INIT_POLL_TIMEOUT); - clk_disable(priv->clk); + pm_runtime_put(priv->dev); if (err) return err; @@ -385,12 +385,12 @@ static enum fpga_mgr_states zynq_fpga_ops_state(struct fpga_manager *mgr) priv = mgr->priv; - err = clk_enable(priv->clk); - if (err) + err = pm_runtime_get_sync(priv->dev); + if (err < 0) return FPGA_MGR_STATE_UNKNOWN; intr_status = zynq_fpga_read(priv, INT_STS_OFFSET); - clk_disable(priv->clk); + pm_runtime_put(priv->dev); if (intr_status & IXR_PCFG_DONE_MASK) return FPGA_MGR_STATE_OPERATING; @@ -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); + pm_runtime_put_noidle(&pdev->dev); + pm_runtime_disable(&pdev->dev); return err; } + pm_runtime_put(&pdev->dev); + return 0; } @@ -483,11 +490,48 @@ 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); + pm_runtime_put_noidle(&pdev->dev); + pm_runtime_disable(&pdev->dev); return 0; } +#ifdef CONFIG_PM +static int 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); + + return 0; +} + +static int 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); + + return 0; +} + +#endif + +static const struct dev_pm_ops zynq_fpga_pm_ops = { + SET_RUNTIME_PM_OPS(zynq_fpga_runtime_suspend, + zynq_fpga_runtime_resume, NULL) +}; + #ifdef CONFIG_OF static const struct of_device_id zynq_fpga_of_match[] = { { .compatible = "xlnx,zynq-devcfg-1.0", }, @@ -503,6 +547,7 @@ static struct platform_driver zynq_fpga_driver = { .driver = { .name = "zynq_fpga_manager", .of_match_table = of_match_ptr(zynq_fpga_of_match), + .pm = &zynq_fpga_pm_ops, }, };