From patchwork Thu Dec 4 08:23:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zidan Wang X-Patchwork-Id: 5436351 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id CA57CBEEA8 for ; Thu, 4 Dec 2014 08:23:30 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BCEE120328 for ; Thu, 4 Dec 2014 08:23:29 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 6DFDF20295 for ; Thu, 4 Dec 2014 08:23:28 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 973AC2606A0; Thu, 4 Dec 2014 09:23:26 +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 5F8B9260549; Thu, 4 Dec 2014 09:23:16 +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 69BF5260560; Thu, 4 Dec 2014 09:23:14 +0100 (CET) Received: from na01-by2-obe.outbound.protection.outlook.com (mail-by2on0129.outbound.protection.outlook.com [207.46.100.129]) by alsa0.perex.cz (Postfix) with ESMTP id DACC1260525 for ; Thu, 4 Dec 2014 09:23:05 +0100 (CET) Received: from DM2PR03CA0041.namprd03.prod.outlook.com (10.141.96.40) by BY2PR0301MB0614.namprd03.prod.outlook.com (25.160.125.24) with Microsoft SMTP Server (TLS) id 15.1.31.17; Thu, 4 Dec 2014 08:23:01 +0000 Received: from BL2FFO11FD006.protection.gbl (2a01:111:f400:7c09::172) by DM2PR03CA0041.outlook.office365.com (2a01:111:e400:2428::40) with Microsoft SMTP Server (TLS) id 15.1.31.17 via Frontend Transport; Thu, 4 Dec 2014 08:23:01 +0000 Received: from az84smr01.freescale.net (192.88.158.2) by BL2FFO11FD006.mail.protection.outlook.com (10.173.161.2) with Microsoft SMTP Server (TLS) id 15.1.26.17 via Frontend Transport; Thu, 4 Dec 2014 08:23:01 +0000 Received: from b50113.ap.freescale.net (b50113.ap.freescale.net [10.192.241.89]) by az84smr01.freescale.net (8.14.3/8.14.0) with ESMTP id sB48MncY028408; Thu, 4 Dec 2014 01:22:50 -0700 From: Zidan Wang To: Date: Thu, 4 Dec 2014 16:23:45 +0800 Message-ID: <1417681425-4360-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.158.2; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10019020)(6009001)(189002)(199003)(48376002)(102836001)(104016003)(110136001)(62966003)(106466001)(68736005)(50986999)(104166001)(86362001)(47776003)(93916002)(20776003)(64706001)(77096005)(229853001)(2351001)(107046002)(31966008)(36756003)(95666004)(77156002)(81156004)(69596002)(105606002)(84676001)(88136002)(46102003)(89996001)(92726001)(92566001)(97736003)(50226001)(4396001)(50466002)(33646002)(21056001)(87936001)(44976005)(19580395003)(19580405001)(6806004)(87286001)(120916001)(99396003)(42262002); DIR:OUT; SFP:1102; SCL:1; SRVR:BY2PR0301MB0614; H:az84smr01.freescale.net; FPR:; SPF:Fail; MLV:sfv; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; MIME-Version: 1.0 X-Microsoft-Antispam: UriScan:; X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;SRVR:BY2PR0301MB0614; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(602001); SRVR:BY2PR0301MB0614; X-Forefront-PRVS: 041517DFAB Received-SPF: Fail (protection.outlook.com: domain of freescale.com does not designate 192.88.158.2 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.158.2; helo=az84smr01.freescale.net; Authentication-Results: spf=fail (sender IP is 192.88.158.2) smtp.mailfrom=B50113@freescale.com; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:; SRVR:BY2PR0301MB0614; 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 v2] 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. If platform data is not supplied, we will get MCLK from device tree and check the return code to handle probe deferral. 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. If we use PLL to generate sysclk, wm8960_set_dai_pll() will enable PLL. But PLL doesn't power down after using codec. So power down PLL in suspend(). Signed-off-by: Zidan Wang --- include/sound/wm8960.h | 1 + sound/soc/codecs/wm8960.c | 59 ++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 57 insertions(+), 3 deletions(-) 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..2c7a97a 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 @@ -978,7 +980,7 @@ static const struct regmap_config wm8960_regmap = { .volatile_reg = wm8960_volatile, }; -static void wm8960_set_pdata_from_of(struct i2c_client *i2c, +static int wm8960_set_pdata_from_of(struct i2c_client *i2c, struct wm8960_data *pdata) { const struct device_node *np = i2c->dev.of_node; @@ -988,6 +990,15 @@ 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); + + if (IS_ERR(pdata->mclk)) { + if (PTR_ERR(pdata->mclk) == -EPROBE_DEFER) + return -EPROBE_DEFER; + } + + return 0; } static int wm8960_i2c_probe(struct i2c_client *i2c, @@ -1008,8 +1019,11 @@ static int wm8960_i2c_probe(struct i2c_client *i2c, if (pdata) memcpy(&wm8960->pdata, pdata, sizeof(struct wm8960_data)); - else if (i2c->dev.of_node) - wm8960_set_pdata_from_of(i2c, &wm8960->pdata); + else if (i2c->dev.of_node) { + ret = wm8960_set_pdata_from_of(i2c, &wm8960->pdata); + if (ret != 0) + return ret; + } ret = wm8960_reset(wm8960->regmap); if (ret != 0) { @@ -1041,6 +1055,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 +1070,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 (!IS_ERR(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 (!IS_ERR(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 +1122,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,