From patchwork Wed Dec 3 11:00:38 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zidan Wang X-Patchwork-Id: 5428811 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 5ECDA9F1C5 for ; Wed, 3 Dec 2014 11:00:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7DF0720303 for ; Wed, 3 Dec 2014 11:00:27 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 385C92021B for ; Wed, 3 Dec 2014 11:00:26 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 0792F261AAB; Wed, 3 Dec 2014 12:00:24 +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,NO_DNS_FOR_FROM, UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id 7EB34261ADB; Wed, 3 Dec 2014 12:00:07 +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 552D4261AAB; Wed, 3 Dec 2014 12:00:04 +0100 (CET) Received: from na01-bl2-obe.outbound.protection.outlook.com (mail-bl2on0144.outbound.protection.outlook.com [65.55.169.144]) by alsa0.perex.cz (Postfix) with ESMTP id ECEDF261A96 for ; Wed, 3 Dec 2014 11:59:55 +0100 (CET) Received: from DM2PR03CA0047.namprd03.prod.outlook.com (10.141.96.46) by CY1PR0301MB0620.namprd03.prod.outlook.com (25.160.142.27) with Microsoft SMTP Server (TLS) id 15.1.26.15; Wed, 3 Dec 2014 10:59:50 +0000 Received: from BN1AFFO11FD045.protection.gbl (2a01:111:f400:7c10::155) by DM2PR03CA0047.outlook.office365.com (2a01:111:e400:2428::46) with Microsoft SMTP Server (TLS) id 15.1.26.15 via Frontend Transport; Wed, 3 Dec 2014 10:59:49 +0000 Received: from tx30smr01.am.freescale.net (192.88.168.50) by BN1AFFO11FD045.mail.protection.outlook.com (10.58.53.60) with Microsoft SMTP Server (TLS) id 15.1.6.13 via Frontend Transport; Wed, 3 Dec 2014 10:59:49 +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 sB3AxfcZ018557; Wed, 3 Dec 2014 03:59:43 -0700 From: Zidan Wang To: Date: Wed, 3 Dec 2014 19:00:38 +0800 Message-ID: <1417604438-28362-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)(199003)(189002)(95666004)(87936001)(84676001)(19580395003)(19580405001)(44976005)(92726001)(6806004)(87286001)(50466002)(46102003)(48376002)(104166001)(33646002)(86362001)(104016003)(102836001)(92566001)(110136001)(89996001)(93916002)(88136002)(21056001)(4396001)(50226001)(50986999)(2351001)(107046002)(229853001)(77156002)(62966003)(31966008)(36756003)(97736003)(99396003)(120916001)(64706001)(105606002)(20776003)(68736005)(106466001)(47776003)(77096005)(42262002); DIR:OUT; SFP:1102; SCL:1; SRVR:CY1PR0301MB0620; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; MLV:sfv; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Antispam: UriScan:; X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;SRVR:CY1PR0301MB0620; X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:; SRVR:CY1PR0301MB0620; X-Forefront-PRVS: 0414DF926F 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:CY1PR0301MB0620; 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] 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 and power down PLL. Signed-off-by: Zidan Wang --- include/sound/wm8960.h | 1 + sound/soc/codecs/wm8960.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/include/sound/wm8960.h b/include/sound/wm8960.h index e8ce8ee..d7e84ed 100644 --- a/include/sound/wm8960.h +++ b/include/sound/wm8960.h @@ -16,6 +16,7 @@ #define WM8960_DRES_MAX 3 struct wm8960_data { + struct clk *mclk; bool capless; /* Headphone outputs configured in capless mode */ bool shared_lrclk; /* DAC and ADC LRCLKs are wired together */ diff --git a/sound/soc/codecs/wm8960.c b/sound/soc/codecs/wm8960.c index 031a1ae..6a529b1 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 @@ -988,6 +990,8 @@ static void wm8960_set_pdata_from_of(struct i2c_client *i2c, if (of_property_read_bool(np, "wlf,shared-lrclk")) pdata->shared_lrclk = true; + + pdata->mclk = devm_clk_get(&i2c->dev, NULL); } static int wm8960_i2c_probe(struct i2c_client *i2c, @@ -1011,6 +1015,14 @@ static int wm8960_i2c_probe(struct i2c_client *i2c, else if (i2c->dev.of_node) wm8960_set_pdata_from_of(i2c, &wm8960->pdata); + /* Mark the mclk pointer to NULL if no mclk assigned */ + if (IS_ERR(wm8960->pdata.mclk)) { + /* But do not ignore the request for probe defer */ + if (PTR_ERR(wm8960->pdata.mclk) == -EPROBE_DEFER) + return -EPROBE_DEFER; + wm8960->pdata.mclk = NULL; + } + ret = wm8960_reset(wm8960->regmap); if (ret != 0) { dev_err(&i2c->dev, "Failed to issue reset\n"); @@ -1041,6 +1053,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 +1068,41 @@ 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 (wm8960->pdata.mclk) { + ret = clk_prepare_enable(wm8960->pdata.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); + + /* Power down PLL to save power */ + regmap_update_bits(wm8960->regmap, WM8960_POWER2, 0x1, 0); + + if (wm8960->pdata.mclk) + clk_disable_unprepare(wm8960->pdata.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 +1120,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,