Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp8758895ybl; Fri, 17 Jan 2020 00:14:29 -0800 (PST) X-Google-Smtp-Source: APXvYqzYPl8i6wSBjP5UJzj4Ur4QqMtEv7+gCFHmlWhbTtNNcXMzMPkOJp9VGuqZeku63ErYKBhl X-Received: by 2002:a05:6808:907:: with SMTP id w7mr2532183oih.137.1579248868857; Fri, 17 Jan 2020 00:14:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579248868; cv=none; d=google.com; s=arc-20160816; b=pNcqArm9vHw9VqntcjtUg1DTuYFxqWhVPjpwsj+SRhXBGaoMGIFVNqj1ZO/GzICOKZ hkBXwUTsZlKuSHF/vcWWAnbWxp1WRRdWOu5RPShxTqFUP3SmHr84jEuWZ6hD1QMqbUgM BwanB8DSknWfJNFD9y9hzzqTdDG6KMOzOTQpiDxKwXnIwt2gKXp+kMoyXorT8fdApF1o Cd+cf7zwj2QCQToJdwoCzlxJmqwpjMTuHIN8T1W87oUOBVIbqQ5a2L2ry+xwRCGLEL9/ jogaAtq6TUKid1NzfMAAGjCK1DcEubHIatCpPhaB1bFMPlwFNtggAjwNXd/ww0MhXx3S gAEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=zutfVne0RagAPb9ReoYYPHC2wywOxB6TykKUgRK+7rA=; b=EDfVtOm1G6+UZ1H0zVPw/zYng+HjbvYHF2UAYS+3ZmBnuB5PyAHMwK6A1GtBLS6iwg etgZ1AJyjS6U8HgzQryYU9Ad3+n7t/1rlWzgZgeIo/mUQP3F924FhHCA37lw1VCreAI+ phumZIJU+SSOiJN0unfMXAkm7ZAkMZdwx4VDuv2v5N6CYq+W+9go1mudubrIh3h/vU7+ o3/5eGzuut76T7vBlZMh+y/waH5F9Mcb8JNu4ZUKjvyp9ExoKXHtxlHJg1l8Y89CxO4i iN4vsuuLuSETygNSvcr0P0j6jnfDfepJHBhvktjLxeS+jt+YezvE6myDoOE+8ug1fgCp D4CA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d21si13220535oic.168.2020.01.17.00.14.16; Fri, 17 Jan 2020 00:14:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729536AbgAQINP (ORCPT + 99 others); Fri, 17 Jan 2020 03:13:15 -0500 Received: from metis.ext.pengutronix.de ([85.220.165.71]:40219 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729011AbgAQINO (ORCPT ); Fri, 17 Jan 2020 03:13:14 -0500 Received: from ptx.hi.pengutronix.de ([2001:67c:670:100:1d::c0]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1isMkd-0001Cc-OT; Fri, 17 Jan 2020 09:13:07 +0100 Received: from sha by ptx.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1isMkc-0004pJ-7a; Fri, 17 Jan 2020 09:13:06 +0100 Date: Fri, 17 Jan 2020 09:13:06 +0100 From: Sascha Hauer To: Han Xu Cc: Han Xu , Vignesh Raghavendra , Richard Weinberger , Esben Haabendal , linux-kernel@vger.kernel.org, vkoul@kernel.org, Boris Brezillon , linux-mtd , linux-imx@nxp.com, Fabio Estevam , Miquel Raynal , dmaengine@vger.kernel.org, Shawn Guo , linux-arm-kernel@lists.infradead.org Subject: Re: [PATCH 3/6] dmaengine: mxs: add the power management functions Message-ID: <20200117081306.eeuf3fvph5rb7tjf@pengutronix.de> References: <1579038243-28550-1-git-send-email-han.xu@nxp.com> <1579038243-28550-4-git-send-email-han.xu@nxp.com> <20200115080257.dtd4vss4uhopbvn2@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Sent-From: Pengutronix Hildesheim X-URL: http://www.pengutronix.de/ X-IRC: #ptxdist @freenode X-Accept-Language: de,en X-Accept-Content-Type: text/plain X-Uptime: 09:08:04 up 193 days, 14:18, 87 users, load average: 0.09, 0.28, 0.30 User-Agent: NeoMutt/20170113 (1.7.2) X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c0 X-SA-Exim-Mail-From: sha@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jan 16, 2020 at 10:36:33AM -0600, Han Xu wrote: > On Wed, Jan 15, 2020 at 2:03 AM Sascha Hauer wrote: > > > > On Wed, Jan 15, 2020 at 05:44:00AM +0800, Han Xu wrote: > > > add the power management functions and leverage the runtime pm for > > > system suspend/resume > > > > > > Signed-off-by: Han Xu > > > --- > > > drivers/dma/mxs-dma.c | 97 +++++++++++++++++++++++++++++++++++++++---- > > > 1 file changed, 90 insertions(+), 7 deletions(-) > > > > > > diff --git a/drivers/dma/mxs-dma.c b/drivers/dma/mxs-dma.c > > > index b458f06f9067..251492c5ea58 100644 > > > --- a/drivers/dma/mxs-dma.c > > > +++ b/drivers/dma/mxs-dma.c > > > @@ -25,6 +25,7 @@ > > > #include > > > #include > > > #include > > > +#include > > > > > > #include > > > > > > @@ -39,6 +40,8 @@ > > > #define dma_is_apbh(mxs_dma) ((mxs_dma)->type == MXS_DMA_APBH) > > > #define apbh_is_old(mxs_dma) ((mxs_dma)->dev_id == IMX23_DMA) > > > > > > +#define MXS_DMA_RPM_TIMEOUT 50 /* ms */ > > > + > > > #define HW_APBHX_CTRL0 0x000 > > > #define BM_APBH_CTRL0_APB_BURST8_EN (1 << 29) > > > #define BM_APBH_CTRL0_APB_BURST_EN (1 << 28) > > > @@ -416,6 +419,7 @@ static int mxs_dma_alloc_chan_resources(struct dma_chan *chan) > > > { > > > struct mxs_dma_chan *mxs_chan = to_mxs_dma_chan(chan); > > > struct mxs_dma_engine *mxs_dma = mxs_chan->mxs_dma; > > > + struct device *dev = &mxs_dma->pdev->dev; > > > int ret; > > > > > > mxs_chan->ccw = dma_alloc_coherent(mxs_dma->dma_device.dev, > > > @@ -431,9 +435,11 @@ static int mxs_dma_alloc_chan_resources(struct dma_chan *chan) > > > if (ret) > > > goto err_irq; > > > > > > - ret = clk_prepare_enable(mxs_dma->clk); > > > - if (ret) > > > + ret = pm_runtime_get_sync(dev); > > > + if (ret < 0) { > > > + dev_err(dev, "Failed to enable clock\n"); > > > goto err_clk; > > > > From looking at other DMA drivers I know we are in good company here, > > but I think this is wrong. Doing pm_runtime_get_sync() in > > alloc_chan_resources() and going to autosuspend in free_chan_resources() > > effectively disables runtime_pm as clients normally acquire their > > channels during driver probe and release them only in driver remove. > > Thanks for the comments. > That's why I moved acquire_dma_resource from the probe to > runtime_resume in the gpmi driver, this change won't disable the > runtime_pm function and the incremental counter always balanced. Yes, that's what I've written a few lines further down: > > > > > In the next patch you release the DMA channels in the GPMI nand drivers > > runtime_suspend hook just to somehow trigger the runtime_suspend of the > > DMA driver. And I consider doing this a crude hack. Here is what I suggested doing instead: > > > > What you should do instead is to make sure the hook runtime_pm to the > > DMA drivers activity phases, like for example the pl330 driver does. > > Then you wouldn't have to care about manually putting the DMA driver into > > suspend from the GPMI NAND driver. Sascha -- Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |