From patchwork Thu Jan 28 08:43:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Caesar Wang X-Patchwork-Id: 8147751 Return-Path: X-Original-To: patchwork-linux-rockchip@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 73E709F440 for ; Thu, 28 Jan 2016 08:47:01 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 96D0C20221 for ; Thu, 28 Jan 2016 08:47:00 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9CF13201D3 for ; Thu, 28 Jan 2016 08:46:59 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aOiEE-0005rI-P3; Thu, 28 Jan 2016 08:46:58 +0000 Received: from mail-pa0-f67.google.com ([209.85.220.67]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aOiCj-0003J1-2C for linux-rockchip@lists.infradead.org; Thu, 28 Jan 2016 08:45:30 +0000 Received: by mail-pa0-f67.google.com with SMTP id a20so1660561pag.3 for ; Thu, 28 Jan 2016 00:45:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=a3LFYg18yXmS57kRc8+JzuAHy7ugKGFySR4MuVDUSRg=; b=QbW37v1zZvtBA7MhcYaxp+6NYPBTpO7P0GvG4SB3EUe8aGFjMXegBaBYwKOwR8nAnG E3H3WMEhrnfJDQBw2KeI9J2+7WyyKb7FHXML6y6b/aZ9O/R7BSFAMdOr7LfVSVY15wT9 EQTMv5bXYeVvEAqQ3ZVz7a2MuJCbTE685GU2W41CaAty+jwiMwL7t99nzeXAJ2jBE1vU XnD1YUFNQ/vuwM4zpAlEpxBKoqiLYnNPCuSEFl8uvaVoy+vCV9/7s+IjKjRGuzUzKjMG 839g+LTx1bHtboXiT4hy/hXKc4GWe6TZ+fPqv23dSpbs0m/YklKL0iIlnUGIIs9jpmSO TGmA== X-Gm-Message-State: AG10YOSxlIZHNIakIRW4yMPBj6nBz/4XyOsx1mP3XvZjuduXweOoWu6KiSbDHqMek4KeEA== X-Received: by 10.66.90.133 with SMTP id bw5mr2862561pab.22.1453970704136; Thu, 28 Jan 2016 00:45:04 -0800 (PST) Received: from localhost.localdomain ([103.29.142.67]) by smtp.gmail.com with ESMTPSA id t67sm14422515pfa.14.2016.01.28.00.44.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 28 Jan 2016 00:45:03 -0800 (PST) From: Caesar Wang To: Heiko Stuebner , linux-kernel@vger.kernel.org Subject: [PATCH v4 8/9] ASoC: rt5616: add the mclk for the codec driver Date: Thu, 28 Jan 2016 16:43:37 +0800 Message-Id: <1453970618-4383-9-git-send-email-wxt@rock-chips.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1453970618-4383-1-git-send-email-wxt@rock-chips.com> References: <1453970618-4383-1-git-send-email-wxt@rock-chips.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160128_004526_208211_85FF9C0B X-CRM114-Status: GOOD ( 16.47 ) X-Spam-Score: -2.4 (--) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Oder Chiou , alsa-devel@alsa-project.org, hl@rock-chips.com, Liam Girdwood , sonnyrao@chromium.org, jeffy.chen@rock-chips.com, Takashi Iwai , Jaroslav Kysela , linux-rockchip@lists.infradead.org, Mark Brown , keescook@google.com, cf@rock-chips.com, Bard Liao , jay.xu@rock-chips.com, leozwang@google.com, Caesar Wang MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds the code to enable the clock to the CODEC driver if it needs the clock enabled. In some case, We need to claim the clock which is driving the codec so that when we enable clock gating, we continue to clock the codec when needed. if mclk provided, to enable and disable the clock source. Signed-off-by: Caesar Wang --- Changes in v4: - AS the previous discussed by them, add the mclk for codec. (https://patchwork.kernel.org/patch/8041001/) sound/soc/codecs/rt5616.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/sound/soc/codecs/rt5616.c b/sound/soc/codecs/rt5616.c index d4bdf9f..fdca636 100644 --- a/sound/soc/codecs/rt5616.c +++ b/sound/soc/codecs/rt5616.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -144,6 +145,7 @@ struct rt5616_priv { struct snd_soc_codec *codec; struct delayed_work patch_work; struct regmap *regmap; + struct clk *mclk; int sysclk; int sysclk_src; @@ -1159,7 +1161,34 @@ static int rt5616_set_dai_pll(struct snd_soc_dai *dai, int pll_id, int source, static int rt5616_set_bias_level(struct snd_soc_codec *codec, enum snd_soc_bias_level level) { + struct rt5616_priv *rt5616 = snd_soc_codec_get_drvdata(codec); + int ret; + switch (level) { + + case SND_SOC_BIAS_ON: + break; + + case SND_SOC_BIAS_PREPARE: + /* + * SND_SOC_BIAS_PREPARE is called while preparing for a + * transition to ON or away from ON. If current bias_level + * is SND_SOC_BIAS_ON, then it is preparing for a transition + * away from ON. Disable the clock in that case, otherwise + * enable it. + */ + if (IS_ERR(rt5616->mclk)) + break; + + if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_ON) { + clk_disable_unprepare(rt5616->mclk); + } else { + ret = clk_prepare_enable(rt5616->mclk); + if (ret) + return ret; + } + break; + case SND_SOC_BIAS_STANDBY: if (snd_soc_codec_get_bias_level(codec) == SND_SOC_BIAS_OFF) { snd_soc_update_bits(codec, RT5616_PWR_ANLG1, @@ -1198,6 +1227,11 @@ static int rt5616_probe(struct snd_soc_codec *codec) { struct rt5616_priv *rt5616 = snd_soc_codec_get_drvdata(codec); + /* Check if MCLK provided */ + rt5616->mclk = devm_clk_get(codec->dev, "mclk"); + if (PTR_ERR(rt5616->mclk) == -EPROBE_DEFER) + return -EPROBE_DEFER; + rt5616->codec = codec; return 0;