From patchwork Thu Dec 7 05:29:57 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Appana Durga Kedareswara rao X-Patchwork-Id: 10097695 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1817B60325 for ; Thu, 7 Dec 2017 05:44:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0881B2A16C for ; Thu, 7 Dec 2017 05:44:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F014E2A2E8; Thu, 7 Dec 2017 05:44:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4816C2A16C for ; Thu, 7 Dec 2017 05:44:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To :From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=yTbfKr1EhMFJ8jOKEZ4Z4p0j2jxceDg10sveHBtjKP4=; b=DedBbQ2rFX2f13 ZwNjT1pG+tTFteBDZAOH0+ai+zwdqNiV04uX7mekVmoS15WWgcjojCl/dB7LZI97gIW+FsBRa2Xk5 3d/se7eQfUw/7HXrHBCIg+QlCa+yGB4J4Iyj7QhiVNH+Ha1daZCUblxF5UEZC4ean/S6BlqnmU/Sa Rd2NeyWxhHYu1RmBrAnEYQzyIZoAD0X1Z8y8+KqUnbwIb23KtvvdyyQG6cGn0jBCt1WG0OeLDGoiy dByDFvaLIm57HcafFQTJW9/xG4xQwsCXkvF7P3dTaPt6OQw9OmTvy4zPNojYnRILKadIcYtvM4elE Q5jvPW0y6mI9I3uAGa3A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1eMozR-000218-N7; Thu, 07 Dec 2017 05:44:57 +0000 Received: from mail-by2nam03on0064.outbound.protection.outlook.com ([104.47.42.64] helo=NAM03-BY2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1eMozN-0001z5-Li for linux-arm-kernel@lists.infradead.org; Thu, 07 Dec 2017 05:44:55 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector1-xilinx-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=6zMbAiCTMOwKD6bzjwFe1sHaW19nEBDc2yHGTvpmx9c=; b=0aNWF+irop08QnazRwvFgH2L2uK/cjO+s298xg8F6MrDi8hzbE43lN8xL7DHkcYOpwqUutMbPvGj4pTQiv7LPnfTBifgk5/KgggfWkWwf5c5R93r/z7JWKbM61vkmVk/Nzm/z6w9+37yskItQiLWByLs9bRWyOpuh30ajsFA21s= Received: from SN4PR0201CA0001.namprd02.prod.outlook.com (10.161.238.139) by MWHPR02MB3279.namprd02.prod.outlook.com (10.164.187.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.282.5; Thu, 7 Dec 2017 05:44:34 +0000 Received: from CY1NAM02FT060.eop-nam02.prod.protection.outlook.com (2a01:111:f400:7e45::207) by SN4PR0201CA0001.outlook.office365.com (2603:10b6:803:2b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.302.9 via Frontend Transport; Thu, 7 Dec 2017 05:44:34 +0000 Authentication-Results: spf=pass (sender IP is 149.199.60.100) smtp.mailfrom=xilinx.com; vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=bestguesspass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.60.100 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.60.100; helo=xsj-pvapsmtpgw02; Received: from xsj-pvapsmtpgw02 (149.199.60.100) by CY1NAM02FT060.mail.protection.outlook.com (10.152.74.252) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.282.5 via Frontend Transport; Thu, 7 Dec 2017 05:44:30 +0000 Received: from unknown-38-66.xilinx.com ([149.199.38.66]:36855 helo=xsj-pvapsmtp01) by xsj-pvapsmtpgw02 with esmtp (Exim 4.63) (envelope-from ) id 1eMoyz-0000ft-LO; Wed, 06 Dec 2017 21:44:29 -0800 Received: from [127.0.0.1] (helo=localhost) by xsj-pvapsmtp01 with smtp (Exim 4.63) (envelope-from ) id 1eMoyz-0005Fp-HA; Wed, 06 Dec 2017 21:44:29 -0800 Received: from xsj-pvapsmtp01 (maildrop.xilinx.com [149.199.38.66]) by xsj-smtp-dlp1.xlnx.xilinx.com (8.13.8/8.13.1) with ESMTP id vB75iRQX018928; Wed, 6 Dec 2017 21:44:27 -0800 Received: from [172.23.37.82] (helo=xhdpunnaia40.xilinx.com) by xsj-pvapsmtp01 with esmtp (Exim 4.63) (envelope-from ) id 1eMoyw-0005CM-WD; Wed, 06 Dec 2017 21:44:27 -0800 From: Kedareswara rao Appana To: , , , , , , Subject: [RESEND PATCH v2] dmaengine: zynqmp_dma: Add runtime pm support Date: Thu, 7 Dec 2017 10:59:57 +0530 Message-ID: <1512624597-14502-1-git-send-email-appanad@xilinx.com> X-Mailer: git-send-email 1.9.1 X-RCIS-Action: ALLOW X-TM-AS-Product-Ver: IMSS-7.1.0.1224-8.1.0.1062-23512.006 X-TM-AS-User-Approved-Sender: Yes;Yes X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:149.199.60.100; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(376002)(346002)(39860400002)(2980300002)(438002)(199004)(189003)(6666003)(36756003)(5660300001)(47776003)(36386004)(33646002)(8936002)(54906003)(316002)(16586007)(106002)(77096006)(63266004)(110136005)(2201001)(50226002)(106466001)(81166006)(81156014)(305945005)(4326008)(8676002)(39060400002)(9786002)(50466002)(478600001)(51416003)(2906002)(7696005)(48376002)(356003)(107986001)(217873001)(5001870100001); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR02MB3279; H:xsj-pvapsmtpgw02; FPR:; SPF:Pass; PTR:unknown-60-100.xilinx.com,xapps1.xilinx.com; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; CY1NAM02FT060; 1:LX/CFSMnqcGHMUj5DtUJEXtkvbgSFCR+omHpZz2BKCrCON6J04l4oTkL37WmomGsomv57QoMswE/Xy9zfDvzEeJlCDbrURTwxJDJmfaeEjz9m3pPW6SvBoRbAcYQu+e9 MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 42c17f8c-a2b5-4cb4-f269-08d53d35980b X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(4534020)(4602075)(4627115)(201703031133081)(201702281549075)(5600026)(4604075)(4608076)(2017052603286); SRVR:MWHPR02MB3279; X-Microsoft-Exchange-Diagnostics: 1; MWHPR02MB3279; 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+VbkdAHg+/0hKsRau5knAhlbL8914rZ/IMlDIX4k5lO/BKc4HcdMOHwPsiHGatVr9vy35J6WnUWqYDl6o/O4oSbBJStJaqbV5UuZYO1EjEqcLQQYKY9ak9gFl7hfMajCZD5ekUQEts3RnVccCCzgjX9BULJ69CmwUxw1xWJRYca1doSy5Chwr4z3SZEgokNJWPI9RVgxrW8xA6MzqftUeIU841phU1+mQRFqPcnt6Zagng/trWrhbAfLuS+eNGhbMMvISQe5YYBF7lii0ZW9IuCdMyrBZ3h5XQzE9o8JtwQKSpkgqcr7873hH5uxJXJ2PuXHqUCtIMFIOHT73fnZPDUqpegr/zVOx+zSZ81ojR5zKQGN2c34Sq0diOPE65NTuDGZ2kD3y+ASIcapQ+WkKQu5l3xtO546kBC9FrTFm+nb9mJyDTdokf9BwmoI3PLCxLG X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(192813158149592); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040450)(2401047)(5005006)(8121501046)(3231022)(3002001)(10201501046)(93006095)(93004095)(6055026)(6041248)(20161123560025)(20161123564025)(20161123555025)(20161123562025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(201708071742011); SRVR:MWHPR02MB3279; BCL:0; PCL:0; RULEID:(100000803101)(100110400095); SRVR:MWHPR02MB3279; X-Microsoft-Exchange-Diagnostics: 1; MWHPR02MB3279; 4:kceHJHoJ/YHvyUpw+JRt9VN1v+JODeh0tr0Rt5RNiKXkkoLwBsC80NvFiWO19GnxaO+thmqr6WuOwx9llxed6SUwcUf1CR1c7HMEgHG/bp2U5VoLOiE059MwPJn9YLsXF7RT3SZvnunR4XzMkihVyEt52N4nXf5c+3bS6d07vDf6ukMAilZnEL3xEs8JETW/NdeuvU2spYoJcdgSSF+50DYN+GtDpa0lRczXSdVXUgvM2lB52oenLc+gEstDkY0SJ/t8B5DSq0PdvBq6R3R0aN2I4YaOx8ZQrW+0WvHUbnDcZxnsthhafAjnePYpncIz X-Forefront-PRVS: 05143A8241 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; MWHPR02MB3279; 23:C7Cp7Hudr5v9OViGSKfuUv7bn8s3RItFHkPo8KV/Q?= =?us-ascii?Q?x2dLdQeVXg4tse1dJ9SUNacppUNWqufa7mR9U3PuR4Zg3J4ziyJ8Sp4yhZrf?= =?us-ascii?Q?tKv8Vsxa8m4fejtyaA9A6fdb8lxPXxYAYp4VpwEeqQeaDxTj2JnKpuZjcYmn?= =?us-ascii?Q?k8Jajnm1a3261lfeyOS0LKIO/ZQSJnzXjjJCjDSdij9GBoOYiM8JEUDn/q4e?= =?us-ascii?Q?0no67yKHOnXVpI4cBUXoYh8WjVw9/6HU8SYLwGKA4rTBus5fGoLnlJLYh/wW?= =?us-ascii?Q?hxr6UaAx/S2lE7tsbXb4SyG4Z1qyo+FIrRa213hxpe915oO9MP9TD4SGdDZr?= =?us-ascii?Q?++vcSmOTqJCFkY97RCiatdkANyvBgs4OCtlPwHgh9xofqLem+Cn285IX9b5G?= =?us-ascii?Q?3QCUW5AYkS5B2IqgMTn8XqNbDWVrX3tnUxEBfrDwaZe+BCDBMewvFNVc06TW?= =?us-ascii?Q?+EyUZDjkwSEGtcsmdOr9lbqxO8+pzcmMzaqjNjcyCqFdCN2V59xg/gkrAnCC?= =?us-ascii?Q?0hbOr6Gr4ve2pUp8krffdCYvnE6+K/2St3qREJtqRpafLLPOsB+mQNGkNUYD?= =?us-ascii?Q?+NqzsCfsXI59u65Yl1YcHmNbayErp8qCG+SWB6zdDPYdyPC53p3ciro37voN?= =?us-ascii?Q?qt+LEzw0PzRqUBWJfTPtHnBNhr8dDc/3n2yurgoOwaalQhK5WnnwlxixnVL9?= =?us-ascii?Q?lL0fC4HsqYzIeKepEgImqXsAFEz93XftrlMPru/H+ImknYqBCsY0T52lfIAY?= =?us-ascii?Q?ZXlXBZt2Bhqm1AX+SLMDtQWT6mUKcFlX9RuIFmddaTE4NxOzo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JHnBxwCVf6VkiGaUALRt0soXgHaaGXTUuLDywdO1ONynYQ13/nLfyTsJkMERQuhUHsfwDqUaUMRoIPquhpACsROzj9w4r0bSmUjETNJGibosnSiPAHID6eE9kkvsYLcQ9qt+DDuYVk SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Dec 2017 05:44:30.5801 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 42c17f8c-a2b5-4cb4-f269-08d53d35980b X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c; Ip=[149.199.60.100]; Helo=[xsj-pvapsmtpgw02] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR02MB3279 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171206_214453_788925_72AB42BE X-CRM114-Status: GOOD ( 15.92 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org, 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-Virus-Scanned: ClamAV using ClamSMTP This patch adds runtime pm support in the driver. Signed-off-by: Kedareswara rao Appana --- Resending the patch as there are some issues with my git send-email, patch is not showing in the dmeengine mailing list. Changes for v2: --> Fixed error path in the probe. drivers/dma/xilinx/zynqmp_dma.c | 160 ++++++++++++++++++++++++++++++++-------- 1 file changed, 128 insertions(+), 32 deletions(-) diff --git a/drivers/dma/xilinx/zynqmp_dma.c b/drivers/dma/xilinx/zynqmp_dma.c index 1ee1241..4fa14bf 100644 --- a/drivers/dma/xilinx/zynqmp_dma.c +++ b/drivers/dma/xilinx/zynqmp_dma.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "../dmaengine.h" @@ -138,6 +139,8 @@ #define ZYNQMP_DMA_BUS_WIDTH_64 64 #define ZYNQMP_DMA_BUS_WIDTH_128 128 +#define ZDMA_PM_TIMEOUT 100 + #define ZYNQMP_DMA_DESC_SIZE(chan) (chan->desc_size) #define to_chan(chan) container_of(chan, struct zynqmp_dma_chan, \ @@ -211,8 +214,6 @@ struct zynqmp_dma_desc_sw { * @bus_width: Bus width * @src_burst_len: Source burst length * @dst_burst_len: Dest burst length - * @clk_main: Pointer to main clock - * @clk_apb: Pointer to apb clock */ struct zynqmp_dma_chan { struct zynqmp_dma_device *zdev; @@ -237,8 +238,6 @@ struct zynqmp_dma_chan { u32 bus_width; u32 src_burst_len; u32 dst_burst_len; - struct clk *clk_main; - struct clk *clk_apb; }; /** @@ -246,11 +245,15 @@ struct zynqmp_dma_chan { * @dev: Device Structure * @common: DMA device structure * @chan: Driver specific DMA channel + * @clk_main: Pointer to main clock + * @clk_apb: Pointer to apb clock */ struct zynqmp_dma_device { struct device *dev; struct dma_device common; struct zynqmp_dma_chan *chan; + struct clk *clk_main; + struct clk *clk_apb; }; static inline void zynqmp_dma_writeq(struct zynqmp_dma_chan *chan, u32 reg, @@ -461,7 +464,11 @@ static int zynqmp_dma_alloc_chan_resources(struct dma_chan *dchan) { struct zynqmp_dma_chan *chan = to_chan(dchan); struct zynqmp_dma_desc_sw *desc; - int i; + int i, ret; + + ret = pm_runtime_get_sync(chan->dev); + if (ret < 0) + return ret; chan->sw_desc_pool = kzalloc(sizeof(*desc) * ZYNQMP_DMA_NUM_DESCS, GFP_KERNEL); @@ -664,6 +671,8 @@ static void zynqmp_dma_free_chan_resources(struct dma_chan *dchan) (2 * ZYNQMP_DMA_DESC_SIZE(chan) * ZYNQMP_DMA_NUM_DESCS), chan->desc_pool_v, chan->desc_pool_p); kfree(chan->sw_desc_pool); + pm_runtime_mark_last_busy(chan->dev); + pm_runtime_put_autosuspend(chan->dev); } /** @@ -841,8 +850,6 @@ static void zynqmp_dma_chan_remove(struct zynqmp_dma_chan *chan) devm_free_irq(chan->zdev->dev, chan->irq, chan); tasklet_kill(&chan->tasklet); list_del(&chan->common.device_node); - clk_disable_unprepare(chan->clk_apb); - clk_disable_unprepare(chan->clk_main); } /** @@ -907,30 +914,6 @@ static int zynqmp_dma_chan_probe(struct zynqmp_dma_device *zdev, "zynqmp-dma", chan); if (err) return err; - chan->clk_main = devm_clk_get(&pdev->dev, "clk_main"); - if (IS_ERR(chan->clk_main)) { - dev_err(&pdev->dev, "main clock not found.\n"); - return PTR_ERR(chan->clk_main); - } - - chan->clk_apb = devm_clk_get(&pdev->dev, "clk_apb"); - if (IS_ERR(chan->clk_apb)) { - dev_err(&pdev->dev, "apb clock not found.\n"); - return PTR_ERR(chan->clk_apb); - } - - err = clk_prepare_enable(chan->clk_main); - if (err) { - dev_err(&pdev->dev, "Unable to enable main clock.\n"); - return err; - } - - err = clk_prepare_enable(chan->clk_apb); - if (err) { - clk_disable_unprepare(chan->clk_main); - dev_err(&pdev->dev, "Unable to enable apb clock.\n"); - return err; - } chan->desc_size = sizeof(struct zynqmp_dma_desc_ll); chan->idle = true; @@ -953,6 +936,87 @@ static struct dma_chan *of_zynqmp_dma_xlate(struct of_phandle_args *dma_spec, } /** + * zynqmp_dma_suspend - Suspend method for the driver + * @dev: Address of the device structure + * + * Put the driver into low power mode. + * Return: 0 on success and failure value on error + */ +static int __maybe_unused zynqmp_dma_suspend(struct device *dev) +{ + if (!device_may_wakeup(dev)) + return pm_runtime_force_suspend(dev); + + return 0; +} + +/** + * zynqmp_dma_resume - Resume from suspend + * @dev: Address of the device structure + * + * Resume operation after suspend. + * Return: 0 on success and failure value on error + */ +static int __maybe_unused zynqmp_dma_resume(struct device *dev) +{ + if (!device_may_wakeup(dev)) + return pm_runtime_force_resume(dev); + + return 0; +} + +/** + * zynqmp_dma_runtime_suspend - Runtime suspend method for the driver + * @dev: Address of the device structure + * + * Put the driver into low power mode. + * Return: 0 always + */ +static int __maybe_unused zynqmp_dma_runtime_suspend(struct device *dev) +{ + struct zynqmp_dma_device *zdev = dev_get_drvdata(dev); + + clk_disable_unprepare(zdev->clk_main); + clk_disable_unprepare(zdev->clk_apb); + + return 0; +} + +/** + * zynqmp_dma_runtime_resume - Runtime suspend method for the driver + * @dev: Address of the device structure + * + * Put the driver into low power mode. + * Return: 0 always + */ +static int __maybe_unused zynqmp_dma_runtime_resume(struct device *dev) +{ + struct zynqmp_dma_device *zdev = dev_get_drvdata(dev); + int err; + + err = clk_prepare_enable(zdev->clk_main); + if (err) { + dev_err(dev, "Unable to enable main clock.\n"); + return err; + } + + err = clk_prepare_enable(zdev->clk_apb); + if (err) { + dev_err(dev, "Unable to enable apb clock.\n"); + clk_disable_unprepare(zdev->clk_main); + return err; + } + + return 0; +} + +static const struct dev_pm_ops zynqmp_dma_dev_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(zynqmp_dma_suspend, zynqmp_dma_resume) + SET_RUNTIME_PM_OPS(zynqmp_dma_runtime_suspend, + zynqmp_dma_runtime_resume, NULL) +}; + +/** * zynqmp_dma_probe - Driver probe function * @pdev: Pointer to the platform_device structure * @@ -984,12 +1048,33 @@ static int zynqmp_dma_probe(struct platform_device *pdev) p->device_config = zynqmp_dma_device_config; p->dev = &pdev->dev; + zdev->clk_main = devm_clk_get(&pdev->dev, "clk_main"); + if (IS_ERR(zdev->clk_main)) { + dev_err(&pdev->dev, "main clock not found.\n"); + return PTR_ERR(zdev->clk_main); + } + + zdev->clk_apb = devm_clk_get(&pdev->dev, "clk_apb"); + if (IS_ERR(zdev->clk_apb)) { + dev_err(&pdev->dev, "apb clock not found.\n"); + return PTR_ERR(zdev->clk_apb); + } + platform_set_drvdata(pdev, zdev); + pm_runtime_set_autosuspend_delay(zdev->dev, ZDMA_PM_TIMEOUT); + pm_runtime_use_autosuspend(zdev->dev); + pm_runtime_enable(zdev->dev); + pm_runtime_get_sync(zdev->dev); + if (!pm_runtime_enabled(zdev->dev)) { + ret = zynqmp_dma_runtime_resume(zdev->dev); + if (ret) + return ret; + } ret = zynqmp_dma_chan_probe(zdev, pdev); if (ret) { dev_err(&pdev->dev, "Probing channel failed\n"); - goto free_chan_resources; + goto err_disable_pm; } p->dst_addr_widths = BIT(zdev->chan->bus_width / 8); @@ -1005,12 +1090,19 @@ static int zynqmp_dma_probe(struct platform_device *pdev) goto free_chan_resources; } + pm_runtime_mark_last_busy(zdev->dev); + pm_runtime_put_sync_autosuspend(zdev->dev); + dev_info(&pdev->dev, "ZynqMP DMA driver Probe success\n"); return 0; free_chan_resources: zynqmp_dma_chan_remove(zdev->chan); +err_disable_pm: + if (!pm_runtime_enabled(zdev->dev)) + zynqmp_dma_runtime_suspend(zdev->dev); + pm_runtime_disable(zdev->dev); return ret; } @@ -1028,6 +1120,9 @@ static int zynqmp_dma_remove(struct platform_device *pdev) dma_async_device_unregister(&zdev->common); zynqmp_dma_chan_remove(zdev->chan); + pm_runtime_disable(zdev->dev); + if (!pm_runtime_enabled(zdev->dev)) + zynqmp_dma_runtime_suspend(zdev->dev); return 0; } @@ -1042,6 +1137,7 @@ static struct platform_driver zynqmp_dma_driver = { .driver = { .name = "xilinx-zynqmp-dma", .of_match_table = zynqmp_dma_of_match, + .pm = &zynqmp_dma_dev_pm_ops, }, .probe = zynqmp_dma_probe, .remove = zynqmp_dma_remove,