From patchwork Fri Jul 29 13:46:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Thomson X-Patchwork-Id: 9252657 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C212460757 for ; Fri, 29 Jul 2016 16:28:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B31DC283E1 for ; Fri, 29 Jul 2016 16:28:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A79E4283E3; Fri, 29 Jul 2016 16:28:23 +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=-1.9 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B9D68283E1 for ; Fri, 29 Jul 2016 16:28:22 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id B146C266497; Fri, 29 Jul 2016 18:28:20 +0200 (CEST) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id A49FB2666C5; Fri, 29 Jul 2016 18:07:57 +0200 (CEST) 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 732702666C5; Fri, 29 Jul 2016 18:07:55 +0200 (CEST) Received: from mail1.bemta3.messagelabs.com (mail1.bemta3.messagelabs.com [195.245.230.164]) by alsa0.perex.cz (Postfix) with ESMTP id 71CDE26700D for ; Fri, 29 Jul 2016 15:46:57 +0200 (CEST) Received: from [85.158.137.99] by server-4.bemta-3.messagelabs.com id BC/B2-15788-05E5B975; Fri, 29 Jul 2016 13:46:56 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrLIsWRWlGSWpSXmKPExsUSt3Opsa5/3Ox wg+7TJhZXLh5ispj68AmbxbcrHUwWl3fNYbPo3NXParHh+1pGBzaPDZ+b2Dx2zrrL7rFpVSeb x763y9g81m+5yuLxeZNcAFsUa2ZeUn5FAmvGnVu3mQpeSlecmnqJvYFxlngXIyeHkMB6Rok/L 7Mg7AqJpU+OsIHYbAIWEpNPPACzWQRUJSZc2M4EYgsL+Eg0rl/H3sXIxSEi0MUosfrVY3aQBL NAucSWTxOZuxg5OHgFHCT2v5IBCfMKCEqcnPmEBaJEQuLgixfMELsMJE4vaASLSwjYS0x/fxW sVUJAX6LxWCxE2FDi+6xvUCXmEqc/HGKdwMg/C8nUWUimLmBkWsWoUZxaVJZapGtkoJdUlJme UZKbmJmja2hgrJebWlycmJ6ak5hUrJecn7uJERjM9QwMjDsYm0/4HWKU5GBSEuVdsGJWuBBfU n5KZUZicUZ8UWlOavEhRhkODiUJ3oaY2eFCgkWp6akVaZk5wLiCSUtw8CiJ8F6NBkrzFhck5h ZnpkOkTjEqSonzngPpEwBJZJTmwbXBYvkSo6yUMC8jAwODEE9BalFuZgmq/CtGcQ5GJWHebyD jeTLzSuCmvwJazAS0uDh2BsjikkSElFQDY6oTd1D3NvlN5hee9tunTZzO/PWkbxzrxNxm7eiw xPcXljyZq/b2hDOz+pFWR65XwWduFHVbXMho/J1/fV2xxhVj3w2PLiW+qTmU/0o79LD05nPa1 y5yH1C/KpF5u8b+bVaYlPlW1uyuHNany5KXuHWLNNqHFceeb2FIqcowF7BgkFM++fK3EktxRq KhFnNRcSIAhUiSQeACAAA= X-Env-Sender: Adam.Thomson.Opensource@diasemi.com X-Msg-Ref: server-6.tower-217.messagelabs.com!1469800015!44997298!1 X-Originating-IP: [94.185.165.51] X-StarScan-Received: X-StarScan-Version: 8.77; banners=-,-,- X-VirusChecked: Checked Received: (qmail 3520 invoked from network); 29 Jul 2016 13:46:55 -0000 Received: from mailrelay2.diasemi.com (HELO sw-ex-cashub01.diasemi.com) (94.185.165.51) by server-6.tower-217.messagelabs.com with AES128-SHA encrypted SMTP; 29 Jul 2016 13:46:55 -0000 Received: from swsrvapps-01.diasemi.com (10.20.28.141) by SW-EX-CASHUB01.diasemi.com (10.20.16.140) with Microsoft SMTP Server id 14.3.248.2; Fri, 29 Jul 2016 14:46:54 +0100 Received: by swsrvapps-01.diasemi.com (Postfix, from userid 22379) id BC1F73FB13; Fri, 29 Jul 2016 14:46:54 +0100 (BST) From: Adam Thomson Date: Fri, 29 Jul 2016 14:46:54 +0100 To: Mark Brown , Liam Girdwood , Jaroslav Kysela , Takashi Iwai Message-ID: <20160729134654.BC1F73FB13@swsrvapps-01.diasemi.com> MIME-Version: 1.0 X-KSE-AttachmentFiltering-Interceptor-Info: protection disabled X-KSE-ServerInfo: sw-ex-cashub01.diasemi.com, 9 X-KSE-Antivirus-Interceptor-Info: scan successful X-KSE-Antivirus-Info: Clean, bases: 29/07/2016 11:40:00 Cc: alsa-devel@alsa-project.org, Support Opensource , linux-kernel@vger.kernel.org Subject: [alsa-devel] [PATCH] ASoC: da7219: Make more efficient use of MCLK within driver 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 Currently, if the driver has control of MCLK then it remains enabled as long as the codec is in STANDBY or above. The MCLK is only really required in STANDBY when a 3-pole jack is inserted and the HP detect procedure is required to run. This patch updates the code to enable/disable the MCLK when moving between the STANDBY and PREPARE bias level, and when a 3-pole jack is inserted and HP detection is required, thus saving power at all other times. Signed-off-by: Adam Thomson --- sound/soc/codecs/da7219-aad.c | 18 +++++++++++++++++- sound/soc/codecs/da7219.c | 18 +++++++++++------- 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/sound/soc/codecs/da7219-aad.c b/sound/soc/codecs/da7219-aad.c index f0057cd..4e369a1 100644 --- a/sound/soc/codecs/da7219-aad.c +++ b/sound/soc/codecs/da7219-aad.c @@ -13,6 +13,7 @@ #include #include +#include #include #include #include @@ -115,12 +116,23 @@ static void da7219_aad_hptest_work(struct work_struct *work) u16 tonegen_freq_hptest; u8 accdet_cfg8; - int report = 0; + int report = 0, ret = 0; /* Lock DAPM and any Kcontrols that are affected by this test */ snd_soc_dapm_mutex_lock(dapm); mutex_lock(&da7219->lock); + /* Ensure MCLK is available for HP test procedure */ + if (da7219->mclk) { + ret = clk_prepare_enable(da7219->mclk); + if (ret) { + dev_err(codec->dev, "Failed to enable mclk - %d\n", ret); + mutex_unlock(&da7219->lock); + snd_soc_dapm_mutex_unlock(dapm); + return; + } + } + /* Bypass cache so it saves current settings */ regcache_cache_bypass(da7219->regmap, true); @@ -250,6 +262,10 @@ static void da7219_aad_hptest_work(struct work_struct *work) snd_soc_update_bits(codec, DA7219_HP_R_CTRL, DA7219_HP_R_AMP_OE_MASK, DA7219_HP_R_AMP_OE_MASK); + /* Remove MCLK, if previously enabled */ + if (da7219->mclk) + clk_disable_unprepare(da7219->mclk); + mutex_unlock(&da7219->lock); snd_soc_dapm_mutex_unlock(dapm); diff --git a/sound/soc/codecs/da7219.c b/sound/soc/codecs/da7219.c index 50ea943..737e914 100644 --- a/sound/soc/codecs/da7219.c +++ b/sound/soc/codecs/da7219.c @@ -1508,11 +1508,10 @@ static int da7219_set_bias_level(struct snd_soc_codec *codec, switch (level) { case SND_SOC_BIAS_ON: - case SND_SOC_BIAS_PREPARE: break; - case SND_SOC_BIAS_STANDBY: - if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) { - /* MCLK */ + case SND_SOC_BIAS_PREPARE: + /* Enable MCLK for transition to ON state */ + if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_STANDBY) { if (da7219->mclk) { ret = clk_prepare_enable(da7219->mclk); if (ret) { @@ -1521,11 +1520,19 @@ static int da7219_set_bias_level(struct snd_soc_codec *codec, return ret; } } + } + break; + case SND_SOC_BIAS_STANDBY: + if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) { /* Master bias */ snd_soc_update_bits(codec, DA7219_REFERENCES, DA7219_BIAS_EN_MASK, DA7219_BIAS_EN_MASK); + } else { + /* Remove MCLK */ + if (da7219->mclk) + clk_disable_unprepare(da7219->mclk); } break; case SND_SOC_BIAS_OFF: @@ -1534,9 +1541,6 @@ static int da7219_set_bias_level(struct snd_soc_codec *codec, snd_soc_update_bits(codec, DA7219_REFERENCES, DA7219_BIAS_EN_MASK, 0); - /* MCLK */ - if (da7219->mclk) - clk_disable_unprepare(da7219->mclk); break; }