From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 34E45C33CB1 for ; Fri, 17 Jan 2020 08:13:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 10EC62072B for ; Fri, 17 Jan 2020 08:13:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729543AbgAQINP (ORCPT ); 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 |