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: 8147691 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.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 226F89F440 for ; Thu, 28 Jan 2016 08:45:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5284C20320 for ; Thu, 28 Jan 2016 08:45:50 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id D4E6820221 for ; Thu, 28 Jan 2016 08:45:48 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 017FD2658C8; Thu, 28 Jan 2016 09:45:47 +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, RCVD_IN_DNSWL_NONE,UNPARSEABLE_RELAY autolearn=no version=3.3.1 Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 42F192657FC; Thu, 28 Jan 2016 09:45:13 +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 D224C2657FC; Thu, 28 Jan 2016 09:45:11 +0100 (CET) Received: from mail-pa0-f65.google.com (mail-pa0-f65.google.com [209.85.220.65]) by alsa0.perex.cz (Postfix) with ESMTP id 10BD4265680 for ; Thu, 28 Jan 2016 09:45:05 +0100 (CET) Received: by mail-pa0-f65.google.com with SMTP id a20so1660564pag.3 for ; Thu, 28 Jan 2016 00:45:05 -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=XATxGC0X0cSB8Eh46EeCvFYiL70ODlIvAK26/j66wT1JHsg2SXL3DgkKCDyt44JFtY jNZ8fbrjg4HVshZL4PVuu7xPEF+X4nwAGGer6X8yjDuWmfpbRwjU4RGr0kuGDI2ddCYx 1tWRKBwW6TwufIWAFs4qlaYvhR+6aS3kP70oES95eZtC8avQHAbA8jfgdalnQTNwvx1f DeVmM5ayyZUaKqbcY+uc8LsVLVA6/r22IR6Dz1+Z6ks5OHGJAP3bLAEea5f0XNII/xPt xR97KxvdoMcbjc0Ibwlv1XGSxhhC2NrUBFGirQY2wSKFqQKTey83i/pSaS6o8jaYL2Gb 2NQg== X-Gm-Message-State: AG10YOTNBZ4oax0IZhNTCnh3Mg+UUUu6aZ4S+dV5eHcLBTmSYuFw1+WjqtFmC/izKq/QzA== 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 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> Cc: Oder Chiou , alsa-devel@alsa-project.org, hl@rock-chips.com, Liam Girdwood , sonnyrao@chromium.org, jeffy.chen@rock-chips.com, Takashi Iwai , 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 Subject: [alsa-devel] [PATCH v4 8/9] ASoC: rt5616: add the mclk for the codec 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: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.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;