From patchwork Thu Apr 18 11:34:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shengjiu Wang X-Patchwork-Id: 10907243 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C3F3313B5 for ; Thu, 18 Apr 2019 12:52:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9B93E28CA7 for ; Thu, 18 Apr 2019 12:52:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8F73628CB3; Thu, 18 Apr 2019 12:52:45 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2218A28CAC for ; Thu, 18 Apr 2019 12:52:43 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id C423A847; Thu, 18 Apr 2019 13:34:24 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz C423A847 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1555587314; bh=HY6uxgHvhfQMMp09DRELqfEDhf9LvHJoTQ8JBCCFzag=; h=From:To:Date:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=BylI77DcuH8e0WBvVn33B6tqERXHEpMGG33U5r6wY8H6179xxvqKb/ZkxmJ/Aet7j RLiA95XtIDvyD21YVVVMk8VUObFTAA1feL4QF9kZ3c7PYbHd1vVeKAXU2hVatZkY0O Gh4s46aDJnWXN/ajz96FRhjzCE306RKwg/xfLBm8= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 410ACF896E3; Thu, 18 Apr 2019 13:34:24 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id 13CEAF896E4; Thu, 18 Apr 2019 13:34:23 +0200 (CEST) Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-eopbgr30049.outbound.protection.outlook.com [40.107.3.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 5DF98F8065D for ; Thu, 18 Apr 2019 13:34:17 +0200 (CEST) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 5DF98F8065D Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="aFRyuuJ4" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=0XtjLL/FoCoMOf2i4HsN6YrT+U+pvoK/yS2Fd+WlcmQ=; b=aFRyuuJ4Ib5YWjjlVffjnYdK4IL0n8lgCtbUbmFGS2LAx3THgmpm89l82KHMEUGnDRr8x678Rsr2mkVivnNH+FWw+wlNidkm6kK4aMogYl2reLeWCP1l9Uzq1DbNf6yYSM3iU5KGz1Ft6pqdFQAYVivP7N78qn9iIwEDtDKhyEI= Received: from VE1PR04MB6479.eurprd04.prod.outlook.com (20.179.233.80) by VE1PR04MB6430.eurprd04.prod.outlook.com (20.179.232.155) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1813.14; Thu, 18 Apr 2019 11:34:16 +0000 Received: from VE1PR04MB6479.eurprd04.prod.outlook.com ([fe80::6c03:86ad:729d:e311]) by VE1PR04MB6479.eurprd04.prod.outlook.com ([fe80::6c03:86ad:729d:e311%7]) with mapi id 15.20.1813.013; Thu, 18 Apr 2019 11:34:16 +0000 From: "S.j. Wang" To: "timur@kernel.org" , "nicoleotsuka@gmail.com" , "Xiubo.Lee@gmail.com" , "festevam@gmail.com" , "broonie@kernel.org" , "alsa-devel@alsa-project.org" Thread-Topic: [PATCH V2] ASoC: fsl_esai: Add pm runtime function Thread-Index: AQHU9dqnfRTIn2pEfkucFb2lHwaFGA== Date: Thu, 18 Apr 2019 11:34:15 +0000 Message-ID: <8c78be27ef3795e9b870de7789c25454bd3774b3.1555586023.git.shengjiu.wang@nxp.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 1.9.1 x-clientproxiedby: HK0P153CA0040.APCP153.PROD.OUTLOOK.COM (2603:1096:203:17::28) To VE1PR04MB6479.eurprd04.prod.outlook.com (2603:10a6:803:11e::16) authentication-results: spf=none (sender IP is ) smtp.mailfrom=shengjiu.wang@nxp.com; x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [119.31.174.66] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: a393bc8a-f7c2-4934-cd75-08d6c3f1c984 x-ms-office365-filtering-ht: Tenant x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600141)(711020)(4605104)(4618075)(2017052603328)(7193020); SRVR:VE1PR04MB6430; x-ms-traffictypediagnostic: VE1PR04MB6430: x-microsoft-antispam-prvs: x-forefront-prvs: 0011612A55 x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(346002)(396003)(376002)(136003)(39860400002)(366004)(199004)(189003)(71200400001)(71190400001)(256004)(386003)(68736007)(2616005)(14444005)(7736002)(305945005)(99286004)(486006)(476003)(110136005)(25786009)(54906003)(316002)(2201001)(66066001)(86362001)(5660300002)(8676002)(81166006)(3846002)(6436002)(2906002)(2501003)(8936002)(4326008)(97736004)(6486002)(118296001)(478600001)(81156014)(26005)(53936002)(6512007)(14454004)(102836004)(36756003)(6506007)(186003)(50226002)(6116002)(52116002); DIR:OUT; SFP:1101; SCL:1; SRVR:VE1PR04MB6430; H:VE1PR04MB6479.eurprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; received-spf: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: qPkmijrNP1+9fs88WywdJcLN0cINd0R8wEz+FxMIENztgRgRwuO6YOjDOSCBA7X5hTf2Az14sZn6sjooHY3niwwUeQiTl3UrNAl9iFwl17dCXo8fbnG07qAEuhhc3vvEsIJ76SrokhkjqdZ/13OZvnVLJE+mnnnsRESYg8k7NGI5Ndq3ds8qidipaQMhEM9MK1Zax6vaT+7R6Q8m/447s2DRUP0w+x9+eXiluClHKWHnsJyQvZFXIZ7XHlQcUiufXysIsbjUC3zTOt94TKTrOtHR8k1h2I9JOmcm8aE5DYxVMvrjEKKnGVHLqIjE6+cI2Ne8Ld1VjKk6+rMCLq449Wr3VdGNRrwAtYbwd6qM9jzvklArpN0SDOcqBlOF3DtWw/QRmObxteTrc8RD/KI65qR3t9IyFVSYlbWlWAeLd2w= MIME-Version: 1.0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: a393bc8a-f7c2-4934-cd75-08d6c3f1c984 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Apr 2019 11:34:15.9455 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB6430 Cc: "linuxppc-dev@lists.ozlabs.org" , "linux-kernel@vger.kernel.org" Subject: [alsa-devel] [PATCH V2] ASoC: fsl_esai: Add pm runtime function X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" X-Virus-Scanned: ClamAV using ClamSMTP Add pm runtime support and move clock handling there. fsl_esai_suspend is replaced by pm_runtime_force_suspend. fsl_esai_resume is replaced by pm_runtime_force_resume. Signed-off-by: Shengjiu Wang Acked-by: Nicolin Chen --- Changes in v2 -refine the commit comments. -move regcache_mark_dirty to runtime suspend. sound/soc/fsl/fsl_esai.c | 141 ++++++++++++++++++++++++++--------------------- 1 file changed, 77 insertions(+), 64 deletions(-) diff --git a/sound/soc/fsl/fsl_esai.c b/sound/soc/fsl/fsl_esai.c index bad0dfed6b68..10d2210c91ef 100644 --- a/sound/soc/fsl/fsl_esai.c +++ b/sound/soc/fsl/fsl_esai.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -466,30 +467,6 @@ static int fsl_esai_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { struct fsl_esai *esai_priv = snd_soc_dai_get_drvdata(dai); - int ret; - - /* - * Some platforms might use the same bit to gate all three or two of - * clocks, so keep all clocks open/close at the same time for safety - */ - ret = clk_prepare_enable(esai_priv->coreclk); - if (ret) - return ret; - if (!IS_ERR(esai_priv->spbaclk)) { - ret = clk_prepare_enable(esai_priv->spbaclk); - if (ret) - goto err_spbaclk; - } - if (!IS_ERR(esai_priv->extalclk)) { - ret = clk_prepare_enable(esai_priv->extalclk); - if (ret) - goto err_extalck; - } - if (!IS_ERR(esai_priv->fsysclk)) { - ret = clk_prepare_enable(esai_priv->fsysclk); - if (ret) - goto err_fsysclk; - } if (!dai->active) { /* Set synchronous mode */ @@ -506,16 +483,6 @@ static int fsl_esai_startup(struct snd_pcm_substream *substream, return 0; -err_fsysclk: - if (!IS_ERR(esai_priv->extalclk)) - clk_disable_unprepare(esai_priv->extalclk); -err_extalck: - if (!IS_ERR(esai_priv->spbaclk)) - clk_disable_unprepare(esai_priv->spbaclk); -err_spbaclk: - clk_disable_unprepare(esai_priv->coreclk); - - return ret; } static int fsl_esai_hw_params(struct snd_pcm_substream *substream, @@ -576,20 +543,6 @@ static int fsl_esai_hw_params(struct snd_pcm_substream *substream, return 0; } -static void fsl_esai_shutdown(struct snd_pcm_substream *substream, - struct snd_soc_dai *dai) -{ - struct fsl_esai *esai_priv = snd_soc_dai_get_drvdata(dai); - - if (!IS_ERR(esai_priv->fsysclk)) - clk_disable_unprepare(esai_priv->fsysclk); - if (!IS_ERR(esai_priv->extalclk)) - clk_disable_unprepare(esai_priv->extalclk); - if (!IS_ERR(esai_priv->spbaclk)) - clk_disable_unprepare(esai_priv->spbaclk); - clk_disable_unprepare(esai_priv->coreclk); -} - static int fsl_esai_trigger(struct snd_pcm_substream *substream, int cmd, struct snd_soc_dai *dai) { @@ -658,7 +611,6 @@ static int fsl_esai_trigger(struct snd_pcm_substream *substream, int cmd, static const struct snd_soc_dai_ops fsl_esai_dai_ops = { .startup = fsl_esai_startup, - .shutdown = fsl_esai_shutdown, .trigger = fsl_esai_trigger, .hw_params = fsl_esai_hw_params, .set_sysclk = fsl_esai_set_dai_sysclk, @@ -947,6 +899,10 @@ static int fsl_esai_probe(struct platform_device *pdev) return ret; } + pm_runtime_enable(&pdev->dev); + + regcache_cache_only(esai_priv->regmap, true); + ret = imx_pcm_dma_init(pdev, IMX_ESAI_DMABUF_SIZE); if (ret) dev_err(&pdev->dev, "failed to init imx pcm dma: %d\n", ret); @@ -954,6 +910,13 @@ static int fsl_esai_probe(struct platform_device *pdev) return ret; } +static int fsl_esai_remove(struct platform_device *pdev) +{ + pm_runtime_disable(&pdev->dev); + + return 0; +} + static const struct of_device_id fsl_esai_dt_ids[] = { { .compatible = "fsl,imx35-esai", }, { .compatible = "fsl,vf610-esai", }, @@ -961,22 +924,35 @@ static int fsl_esai_probe(struct platform_device *pdev) }; MODULE_DEVICE_TABLE(of, fsl_esai_dt_ids); -#ifdef CONFIG_PM_SLEEP -static int fsl_esai_suspend(struct device *dev) -{ - struct fsl_esai *esai = dev_get_drvdata(dev); - - regcache_cache_only(esai->regmap, true); - regcache_mark_dirty(esai->regmap); - - return 0; -} - -static int fsl_esai_resume(struct device *dev) +#ifdef CONFIG_PM +static int fsl_esai_runtime_resume(struct device *dev) { struct fsl_esai *esai = dev_get_drvdata(dev); int ret; + /* + * Some platforms might use the same bit to gate all three or two of + * clocks, so keep all clocks open/close at the same time for safety + */ + ret = clk_prepare_enable(esai->coreclk); + if (ret) + return ret; + if (!IS_ERR(esai->spbaclk)) { + ret = clk_prepare_enable(esai->spbaclk); + if (ret) + goto err_spbaclk; + } + if (!IS_ERR(esai->extalclk)) { + ret = clk_prepare_enable(esai->extalclk); + if (ret) + goto err_extalclk; + } + if (!IS_ERR(esai->fsysclk)) { + ret = clk_prepare_enable(esai->fsysclk); + if (ret) + goto err_fsysclk; + } + regcache_cache_only(esai->regmap, false); /* FIFO reset for safety */ @@ -987,22 +963,59 @@ static int fsl_esai_resume(struct device *dev) ret = regcache_sync(esai->regmap); if (ret) - return ret; + goto err_regcache_sync; /* FIFO reset done */ regmap_update_bits(esai->regmap, REG_ESAI_TFCR, ESAI_xFCR_xFR, 0); regmap_update_bits(esai->regmap, REG_ESAI_RFCR, ESAI_xFCR_xFR, 0); return 0; + +err_regcache_sync: + if (!IS_ERR(esai->fsysclk)) + clk_disable_unprepare(esai->fsysclk); +err_fsysclk: + if (!IS_ERR(esai->extalclk)) + clk_disable_unprepare(esai->extalclk); +err_extalclk: + if (!IS_ERR(esai->spbaclk)) + clk_disable_unprepare(esai->spbaclk); +err_spbaclk: + clk_disable_unprepare(esai->coreclk); + + return ret; } -#endif /* CONFIG_PM_SLEEP */ + +static int fsl_esai_runtime_suspend(struct device *dev) +{ + struct fsl_esai *esai = dev_get_drvdata(dev); + + regcache_cache_only(esai->regmap, true); + regcache_mark_dirty(esai->regmap); + + if (!IS_ERR(esai->fsysclk)) + clk_disable_unprepare(esai->fsysclk); + if (!IS_ERR(esai->extalclk)) + clk_disable_unprepare(esai->extalclk); + if (!IS_ERR(esai->spbaclk)) + clk_disable_unprepare(esai->spbaclk); + clk_disable_unprepare(esai->coreclk); + + return 0; +} +#endif /* CONFIG_PM */ static const struct dev_pm_ops fsl_esai_pm_ops = { - SET_SYSTEM_SLEEP_PM_OPS(fsl_esai_suspend, fsl_esai_resume) + SET_RUNTIME_PM_OPS(fsl_esai_runtime_suspend, + fsl_esai_runtime_resume, + NULL) + SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, + pm_runtime_force_resume) }; static struct platform_driver fsl_esai_driver = { .probe = fsl_esai_probe, + .remove = fsl_esai_remove, .driver = { .name = "fsl-esai-dai", .pm = &fsl_esai_pm_ops,