From patchwork Thu Dec 4 12:41:19 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zidan Wang X-Patchwork-Id: 5438071 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 9176C9F1C5 for ; Thu, 4 Dec 2014 12:40:56 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A61A120256 for ; Thu, 4 Dec 2014 12:40:55 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 5964620253 for ; Thu, 4 Dec 2014 12:40:54 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 5639726055A; Thu, 4 Dec 2014 13:40:53 +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 33E8B26053E; Thu, 4 Dec 2014 13:40:43 +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 E6777260540; Thu, 4 Dec 2014 13:40:41 +0100 (CET) Received: from na01-bn1-obe.outbound.protection.outlook.com (mail-bn1bon0144.outbound.protection.outlook.com [157.56.111.144]) by alsa0.perex.cz (Postfix) with ESMTP id 9C3F526052B for ; Thu, 4 Dec 2014 13:40:33 +0100 (CET) Received: from BY2PR03CA041.namprd03.prod.outlook.com (10.141.249.14) by BN1PR0301MB0609.namprd03.prod.outlook.com (25.160.170.24) with Microsoft SMTP Server (TLS) id 15.1.26.15; Thu, 4 Dec 2014 12:40:31 +0000 Received: from BL2FFO11FD045.protection.gbl (2a01:111:f400:7c09::159) by BY2PR03CA041.outlook.office365.com (2a01:111:e400:2c5d::14) with Microsoft SMTP Server (TLS) id 15.1.31.17 via Frontend Transport; Thu, 4 Dec 2014 12:40:30 +0000 Received: from tx30smr01.am.freescale.net (192.88.168.50) by BL2FFO11FD045.mail.protection.outlook.com (10.173.161.207) with Microsoft SMTP Server (TLS) id 15.1.6.13 via Frontend Transport; Thu, 4 Dec 2014 12:40:30 +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 sB4CeNjI016497; Thu, 4 Dec 2014 05:40:24 -0700 From: Zidan Wang To: Date: Thu, 4 Dec 2014 20:41:19 +0800 Message-ID: <1417696879-15402-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)(50466002)(120916001)(31966008)(97736003)(48376002)(99396003)(229853001)(77156002)(102836001)(36756003)(2351001)(62966003)(107046002)(104166001)(104016003)(95666004)(68736005)(88136002)(77096005)(106466001)(33646002)(110136001)(47776003)(575784001)(21056001)(86362001)(93916002)(105606002)(92726001)(64706001)(20776003)(92566001)(46102003)(87936001)(50986999)(87286001)(6806004)(89996001)(19580395003)(84676001)(19580405001)(4396001)(50226001)(42262002); DIR:OUT; SFP:1102; SCL:1; SRVR:BN1PR0301MB0609; 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:BN1PR0301MB0609; X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(602001); SRVR:BN1PR0301MB0609; X-Forefront-PRVS: 041517DFAB 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:BN1PR0301MB0609; 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 v3] 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. Signed-off-by: Zidan Wang Acked-by: Charles Keepax --- include/sound/wm8960.h | 1 + sound/soc/codecs/wm8960.c | 56 ++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 54 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..ea5f0b7 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,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->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); + + 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 +1119,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,