devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Caesar Wang <wxt@rock-chips.com>
To: broonie@kernel.org, bardliao@realtek.com
Cc: alsa-devel@alsa-project.org, oder_chiou@realtek.com,
	robh+dt@kernel.org, heiko@sntech.de, devicetree@vger.kernel.org,
	linux-rockchip@lists.infradead.org, keescook@google.com,
	linux-kernel@vger.kernel.org, jeffy.chen@rock-chips.com,
	leozwang@google.com, Caesar Wang <wxt@rock-chips.com>
Subject: [PATCH v5 7/8] ASoC: rt5616: add the mclk for the codec driver
Date: Tue,  2 Feb 2016 11:44:40 +0800	[thread overview]
Message-ID: <1454384680-7197-3-git-send-email-wxt@rock-chips.com> (raw)
In-Reply-To: <1454384680-7197-1-git-send-email-wxt@rock-chips.com>

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.

We can enable and disable the clock source if mclk provided.

Signed-off-by: Caesar Wang <wxt@rock-chips.com>
Cc:  alsa-devel@alsa-project.org
Cc:  Mark Brown <broonie@kernel.org>
Cc:  Bard Liao <bardliao@realtek.com>

---

Changes in v5:
- Cc related alsa experts.

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 <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/init.h>
+#include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/pm.h>
 #include <linux/i2c.h>
@@ -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;
-- 
1.9.1

  parent reply	other threads:[~2016-02-02  3:44 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <1454384032-6794-1-git-send-email-wxt@rock-chips.com>
     [not found] ` <1454384032-6794-1-git-send-email-wxt-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
2016-02-02  3:40   ` [PATCH v5 1/8] ARM: dts: rockchip: add hdmi/vop device node for rk3036 Caesar Wang
2016-02-02  3:40     ` [PATCH v5 3/8] ARM: dts: rockchip: add support emac for RK3036 Caesar Wang
2016-02-02  3:40     ` [PATCH v5 4/8] ARM: dts: rockchip: add mclk for rt5616 on kylin board Caesar Wang
2016-02-02 21:23       ` Heiko Stübner
2016-02-02  3:40     ` [PATCH v5 8/8] ARM: dts: rockchip: support the spi for rk3036 Caesar Wang
     [not found]       ` <1454384453-7127-4-git-send-email-wxt-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
2016-02-02 21:29         ` Heiko Stübner
     [not found]     ` <1454384453-7127-1-git-send-email-wxt-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
2016-02-21  0:03       ` [PATCH v5 1/8] ARM: dts: rockchip: add hdmi/vop device node " Heiko Stuebner
2016-02-21  2:18         ` Caesar Wang
2016-02-02  3:44 ` [PATCH v5 5/8] ASoC: rt5616: add mclk property for rt5616 document Caesar Wang
2016-02-02  3:44   ` [PATCH v5 6/8] ASoC: rt5616: trivial: fix the typo Caesar Wang
2016-02-02  3:44   ` Caesar Wang [this message]
     [not found]   ` <1454384680-7197-1-git-send-email-wxt-TNX95d0MmH7DzftRWevZcw@public.gmane.org>
2016-02-02 19:36     ` [PATCH v5 5/8] ASoC: rt5616: add mclk property for rt5616 document Mark Brown
2016-02-03  0:52       ` Caesar Wang
2016-02-02  3:48 ` [PATCH v5 2/8] clk: rockchip: rk3036: fix and add node id for emac clock Caesar Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1454384680-7197-3-git-send-email-wxt@rock-chips.com \
    --to=wxt@rock-chips.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=bardliao@realtek.com \
    --cc=broonie@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=heiko@sntech.de \
    --cc=jeffy.chen@rock-chips.com \
    --cc=keescook@google.com \
    --cc=leozwang@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=oder_chiou@realtek.com \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).