Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp6220882ybl; Wed, 15 Jan 2020 00:35:07 -0800 (PST) X-Google-Smtp-Source: APXvYqzYda8sBRYwgg5f7A64kUh3LlGdd93XB469FwvEL0kGarn7eT3stzU+nm9Zo0QbMIl5p/x7 X-Received: by 2002:a54:4117:: with SMTP id l23mr19187484oic.140.1579077307121; Wed, 15 Jan 2020 00:35:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579077307; cv=none; d=google.com; s=arc-20160816; b=WpsOOspnVqUSwMXXUzW2GIXUgBsnoN/qHCt8LbiMVCwcRXVL9zTLFCKvHJD3GqkNem 9WO89PtQftolzs/QjehQxKRT5LSTnf3qvSpvskChkd/oz2rrj4cGCas39jPunieESkZa mVYQMyYmAG64usfyPNEkN0m0mkXSc/lYEbug4SGQpALbBP6Hb/A+a/rTF8BCPnVZGiLS sXPnpkDIcBTpFlzyWu8vMR4Tj6GmydMfz4vJZVZfbPZhNZji6A/93xyYnTmrWGqhux6q Sg8H2WWzhqsMySylE3GXJoCK/mP5m08MypRTK6aiew3qFzyboe5N0iFcjtL0khM+XJce Wncw== 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=naknOga2qQ0lS+czBGK9rq0E789/EvMsZH6BWYkTWLM=; b=0bKQF2//xWzWsNz2aCQhReMW+ZooJu8NxmBuPEWn2VRtk2kT4iFK9m948+KplKXP6O CzPWYHmq1FsCud4IpDoT4ip34VNTrMtc123SwNnFlnGVtP6rSHBU3ZY8CbT5gt8z/q2A QEf04kB7vLcfGVCB22DzlNwBFvtFtY4K/dB9y6AKw2kvF8SLLSi77xMHQFUNx2JV4UhQ sKDbkcMfDr03ezUogID9VLCwRSKs5H9QLp0yhTsn8jmt9HnVvg1cpUeEXgqh8qp6OsAe OsEbPTtzH4G3LWZQ4ah7psF/xE4rsIJohEoebr9BSC9NRbATB6K0zSc3F0fVSVMUVeGM wIVw== 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 d20si8933185oic.40.2020.01.15.00.34.55; Wed, 15 Jan 2020 00:35:07 -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 S1729016AbgAOIcq (ORCPT + 99 others); Wed, 15 Jan 2020 03:32:46 -0500 Received: from metis.ext.pengutronix.de ([85.220.165.71]:48731 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726088AbgAOIcq (ORCPT ); Wed, 15 Jan 2020 03:32:46 -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 1ire6G-0003Op-LB; Wed, 15 Jan 2020 09:32:28 +0100 Received: from sha by ptx.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1ire6E-0001jx-6Z; Wed, 15 Jan 2020 09:32:26 +0100 Date: Wed, 15 Jan 2020 09:32:26 +0100 From: Sascha Hauer To: Han Xu Cc: vkoul@kernel.org, shawnguo@kernel.org, miquel.raynal@bootlin.com, richard@nod.at, vigneshr@ti.com, esben@geanix.com, boris.brezillon@collabora.com, festevam@gmail.com, linux-imx@nxp.com, dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH 5/6] mtd: rawnand: gpmi: refine the runtime pm ops Message-ID: <20200115083226.lbwtfvoevp3k33qt@pengutronix.de> References: <1579038243-28550-1-git-send-email-han.xu@nxp.com> <1579038243-28550-6-git-send-email-han.xu@nxp.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1579038243-28550-6-git-send-email-han.xu@nxp.com> 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:17:31 up 191 days, 14:27, 88 users, load average: 0.39, 0.32, 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 Wed, Jan 15, 2020 at 05:44:02AM +0800, Han Xu wrote: > several changes for runtime code in gpmi-nand driver > > - Always invoke runtime get/put in same function to balance the usage > counter. > > - leverage the runtime pm for system pm, move acquire dma to runtime pm > to acquire dma only when needed. > > - add pm_runtime_dont_use_autosuspend in err path. If driver failed to > probe before runtime pm timeout, such as NAND not mounted in socket, > runtime suspend won't be called without the change. Using a bullet list in a commit message is often a sign that the patch should be split into multiple patches... > > Signed-off-by: Han Xu > --- > drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c | 56 +++++++++++----------- > 1 file changed, 29 insertions(+), 27 deletions(-) > > diff --git a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c > index fcc7325f2a10..73644c96fa9b 100644 > --- a/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c > +++ b/drivers/mtd/nand/raw/gpmi-nand/gpmi-nand.c > @@ -183,7 +183,6 @@ static int gpmi_init(struct gpmi_nand_data *this) > */ > writel(BM_GPMI_CTRL1_DECOUPLE_CS, r->gpmi_regs + HW_GPMI_CTRL1_SET); > > - return 0; > err_out: > pm_runtime_mark_last_busy(this->dev); > pm_runtime_put_autosuspend(this->dev); > @@ -556,7 +555,6 @@ static int bch_set_geometry(struct gpmi_nand_data *this) > /* Set *all* chip selects to use layout 0. */ > writel(0, r->bch_regs + HW_BCH_LAYOUTSELECT); > > - ret = 0; > err_out: > pm_runtime_mark_last_busy(this->dev); > pm_runtime_put_autosuspend(this->dev); While I agree that this "ret = 0" is unnecessary because 'ret' holds the successful return value of the last function called, I still think it's nice to make it explicit that this is the success path of this function. If you disagree please at least make this a separate patch. > @@ -1213,10 +1211,6 @@ static int acquire_resources(struct gpmi_nand_data *this) > if (ret) > goto exit_regs; > > - ret = acquire_dma_channels(this); > - if (ret) > - goto exit_regs; > - > ret = gpmi_get_clks(this); > if (ret) > goto exit_clock; > @@ -2656,15 +2650,9 @@ static int gpmi_nand_probe(struct platform_device *pdev) > if (ret) > goto exit_acquire_resources; > > - ret = __gpmi_enable_clk(this, true); > - if (ret) > - goto exit_nfc_init; > - > + pm_runtime_enable(&pdev->dev); > pm_runtime_set_autosuspend_delay(&pdev->dev, 500); > pm_runtime_use_autosuspend(&pdev->dev); > - pm_runtime_set_active(&pdev->dev); > - pm_runtime_enable(&pdev->dev); > - pm_runtime_get_sync(&pdev->dev); > > ret = gpmi_init(this); > if (ret) > @@ -2674,15 +2662,12 @@ static int gpmi_nand_probe(struct platform_device *pdev) > if (ret) > goto exit_nfc_init; > > - pm_runtime_mark_last_busy(&pdev->dev); > - pm_runtime_put_autosuspend(&pdev->dev); > - > dev_info(this->dev, "driver registered.\n"); > > return 0; > > exit_nfc_init: > - pm_runtime_put(&pdev->dev); > + pm_runtime_dont_use_autosuspend(&pdev->dev); > pm_runtime_disable(&pdev->dev); > release_resources(this); > exit_acquire_resources: > @@ -2694,7 +2679,6 @@ static int gpmi_nand_remove(struct platform_device *pdev) > { > struct gpmi_nand_data *this = platform_get_drvdata(pdev); > > - pm_runtime_put_sync(&pdev->dev); > pm_runtime_disable(&pdev->dev); > > nand_release(&this->nand); > @@ -2706,10 +2690,11 @@ static int gpmi_nand_remove(struct platform_device *pdev) > #ifdef CONFIG_PM_SLEEP > static int gpmi_pm_suspend(struct device *dev) > { > - struct gpmi_nand_data *this = dev_get_drvdata(dev); > + int ret; > > - release_dma_channels(this); > - return 0; > + ret = pm_runtime_force_suspend(dev); > + > + return ret; > } > > static int gpmi_pm_resume(struct device *dev) > @@ -2717,9 +2702,11 @@ static int gpmi_pm_resume(struct device *dev) > struct gpmi_nand_data *this = dev_get_drvdata(dev); > int ret; > > - ret = acquire_dma_channels(this); > - if (ret < 0) > + ret = pm_runtime_force_resume(dev); > + if (ret) { > + dev_err(this->dev, "Error in resume %d\n", ret); > return ret; > + } > > /* re-init the GPMI registers */ > ret = gpmi_init(this); > @@ -2743,18 +2730,33 @@ static int gpmi_pm_resume(struct device *dev) > } > #endif /* CONFIG_PM_SLEEP */ > > -static int __maybe_unused gpmi_runtime_suspend(struct device *dev) > +#define gpmi_enable_clk(x) __gpmi_enable_clk(x, true) > +#define gpmi_disable_clk(x) __gpmi_enable_clk(x, false) These defines do not add any value. 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 |