From patchwork Tue Dec 9 05:45:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zidan Wang X-Patchwork-Id: 5460521 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 178B09F1CD for ; Tue, 9 Dec 2014 05:45:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1F17F20155 for ; Tue, 9 Dec 2014 05:45:39 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id DE0FA2011D for ; Tue, 9 Dec 2014 05:45:37 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 491DC261528; Tue, 9 Dec 2014 06:45:36 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 0B1DC260657; Tue, 9 Dec 2014 06:45:26 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 5422926067A; Tue, 9 Dec 2014 06:45:25 +0100 (CET) Received: from na01-bl2-obe.outbound.protection.outlook.com (mail-bl2on0138.outbound.protection.outlook.com [65.55.169.138]) by alsa0.perex.cz (Postfix) with ESMTP id 009C1260639 for ; Tue, 9 Dec 2014 06:45:16 +0100 (CET) Received: from DM2PR0301MB1263.namprd03.prod.outlook.com (25.160.219.28) by DM2PR0301MB0654.namprd03.prod.outlook.com (25.160.96.16) with Microsoft SMTP Server (TLS) id 15.1.31.17; Tue, 9 Dec 2014 05:45:15 +0000 Received: from BY2PR03CA008.namprd03.prod.outlook.com (10.255.93.25) by DM2PR0301MB1263.namprd03.prod.outlook.com (25.160.219.28) with Microsoft SMTP Server (TLS) id 15.1.31.17; Tue, 9 Dec 2014 05:45:12 +0000 Received: from BN1BFFO11FD005.protection.gbl (10.255.93.4) by BY2PR03CA008.outlook.office365.com (10.255.93.25) with Microsoft SMTP Server (TLS) id 15.1.31.17 via Frontend Transport; Tue, 9 Dec 2014 05:45:11 +0000 Received: from tx30smr01.am.freescale.net (192.88.168.50) by BN1BFFO11FD005.mail.protection.outlook.com (10.58.144.68) with Microsoft SMTP Server (TLS) id 15.1.26.17 via Frontend Transport; Tue, 9 Dec 2014 05:45:11 +0000 Received: from b50113.ap.freescale.net (b50113.ap.freescale.net [10.192.241.89]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id sB95j4co019493; Mon, 8 Dec 2014 22:45:05 -0700 From: Zidan Wang To: Date: Tue, 9 Dec 2014 13:45:16 +0800 Message-ID: <1418103916-31295-1-git-send-email-b50113@freescale.com> X-Mailer: git-send-email 1.9.1 X-EOPAttributedMessage: 0 X-Forefront-Antispam-Report: CIP:192.88.168.50; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(189002)(199003)(84676001)(68736005)(87936001)(62966003)(97736003)(48376002)(104016003)(105606002)(46102003)(33646002)(77156002)(99396003)(110136001)(229853001)(120916001)(77096005)(89996001)(106466001)(107046002)(2351001)(92566001)(64706001)(47776003)(20776003)(4396001)(50226001)(86362001)(31966008)(50466002)(19580395003)(19580405001)(50986999)(36756003)(6806004)(21056001)(42262002); DIR:OUT; SFP:1102; SCL:1; SRVR:DM2PR0301MB1263; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; MLV:sfv; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Antispam: UriScan:;UriScan:; X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;SRVR:DM2PR0301MB1263; X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(602002); SRVR:DM2PR0301MB1263; X-Forefront-PRVS: 0420213CCD Received-SPF: Fail (protection.outlook.com: domain of freescale.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=B50113@freescale.com; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:; SRVR:DM2PR0301MB1263; X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;SRVR:DM2PR0301MB0654; X-OriginatorOrg: freescale.com Cc: alsa-devel@alsa-project.org, lars@metafoo.de, tiwai@suse.de, linux-kernel@vger.kernel.org, patches@opensource.wolfsonmicro.com, lgirdwood@gmail.com, Li.Xiubo@freescale.com, Zidan Wang , ckeepax@opensource.wolfsonmicro.com Subject: [alsa-devel] [PATCH v4] ASoC: wm8960: Let wm8960 codec driver manage its own MCLK X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 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-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP When we want to use wm8960 codec, we should enable its MCLK in machine driver. It's reasonable for wm8960 codec driver to manage its own MCLK to save power. Enable runtime power management, and auto enable/disable MCLK in pm_runtime resume and suspend. When wm8960 codec is being used, it will triger resume() to enable MCLK. When codec is not being used, it will triger suspend() to disable MCLK. Signed-off-by: Zidan Wang Acked-by: Charles Keepax --- sound/soc/codecs/wm8960.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/sound/soc/codecs/wm8960.c b/sound/soc/codecs/wm8960.c index 031a1ae..aff24a7 100644 --- a/sound/soc/codecs/wm8960.c +++ b/sound/soc/codecs/wm8960.c @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include #include #include @@ -117,6 +119,7 @@ static bool wm8960_volatile(struct device *dev, unsigned int reg) } struct wm8960_priv { + struct clk *mclk; struct regmap *regmap; int (*set_bias_level)(struct snd_soc_codec *, enum snd_soc_bias_level level); @@ -1002,6 +1005,13 @@ static int wm8960_i2c_probe(struct i2c_client *i2c, if (wm8960 == NULL) return -ENOMEM; + wm8960->mclk = devm_clk_get(&i2c->dev, "codec_mclk"); + + if (IS_ERR(wm8960->mclk)) { + if (PTR_ERR(wm8960->mclk) == -EPROBE_DEFER) + return -EPROBE_DEFER; + } + wm8960->regmap = devm_regmap_init_i2c(i2c, &wm8960_regmap); if (IS_ERR(wm8960->regmap)) return PTR_ERR(wm8960->regmap); @@ -1041,6 +1051,9 @@ static int wm8960_i2c_probe(struct i2c_client *i2c, i2c_set_clientdata(i2c, wm8960); + pm_runtime_enable(&i2c->dev); + pm_request_idle(&i2c->dev); + ret = snd_soc_register_codec(&i2c->dev, &soc_codec_dev_wm8960, &wm8960_dai, 1); @@ -1053,6 +1066,38 @@ static int wm8960_i2c_remove(struct i2c_client *client) return 0; } +#ifdef CONFIG_PM_RUNTIME +static int wm8960_runtime_resume(struct device *dev) +{ + struct wm8960_priv *wm8960 = dev_get_drvdata(dev); + int ret; + + if (!IS_ERR(wm8960->mclk)) { + ret = clk_prepare_enable(wm8960->mclk); + if (ret) { + dev_err(dev, "Failed to enable MCLK: %d\n", ret); + return ret; + } + } + + return 0; +} + +static int wm8960_runtime_suspend(struct device *dev) +{ + struct wm8960_priv *wm8960 = dev_get_drvdata(dev); + + if (!IS_ERR(wm8960->mclk)) + clk_disable_unprepare(wm8960->mclk); + + return 0; +} +#endif + +static const struct dev_pm_ops wm8960_pm = { + SET_RUNTIME_PM_OPS(wm8960_runtime_suspend, wm8960_runtime_resume, NULL) +}; + static const struct i2c_device_id wm8960_i2c_id[] = { { "wm8960", 0 }, { } @@ -1070,6 +1115,7 @@ static struct i2c_driver wm8960_i2c_driver = { .name = "wm8960", .owner = THIS_MODULE, .of_match_table = wm8960_of_match, + .pm = &wm8960_pm, }, .probe = wm8960_i2c_probe, .remove = wm8960_i2c_remove,