Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1320436

[PATCH v4 8/9] ASoC: rt5616: add the mclk for the codec driver

From Caesar Wang <wxt@rock-chips.com>
Newsgroups linux.kernel
Subject [PATCH v4 8/9] ASoC: rt5616: add the mclk for the codec driver
Date 2016-01-28 09:50 +0100
Message-ID <qVQr9-MW-31@gated-at.bofh.it> (permalink)
References <qVQr8-MW-11@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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 <wxt@rock-chips.com>

---

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

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v4 0/9] Add the family patches to support for kylin board Caesar Wang <wxt@rock-chips.com> - 2016-01-28 09:50 +0100
  [PATCH v4 2/9] ARM: dts: rockchip: add hdmi/vop device node for rk3036 Caesar Wang <wxt@rock-chips.com> - 2016-01-28 09:50 +0100
  [PATCH v4 6/9] ASoC: rt5616: add mclk property for rt5616 document Caesar Wang <wxt@rock-chips.com> - 2016-01-28 09:50 +0100
    Re: [PATCH v4 6/9] ASoC: rt5616: add mclk property for rt5616  document Rob Herring <robh@kernel.org> - 2016-01-29 17:30 +0100
      Re: [PATCH v4 6/9] ASoC: rt5616: add mclk property for rt5616  document Caesar Wang <caesar.upstream@gmail.com> - 2016-01-31 10:20 +0100
  [PATCH v4 9/9] ARM: dts: rockchip: support the spi for rk3036 Caesar Wang <wxt@rock-chips.com> - 2016-01-28 09:50 +0100
    Re: [PATCH v4 9/9] ARM: dts: rockchip: support the spi for rk3036 Heiko Stuebner <heiko@sntech.de> - 2016-01-31 12:10 +0100
      Re: [PATCH v4 9/9] ARM: dts: rockchip: support the spi for rk3036 Caesar Wang <caesar.upstream@gmail.com> - 2016-02-01 07:40 +0100
  [PATCH v4 7/9] ASoC: rt5616: trivial: fix the typo Caesar Wang <wxt@rock-chips.com> - 2016-01-28 09:50 +0100
  [PATCH v4 5/9] ARM: dts: rockchip: add mclk for rt5616 on kylin board Caesar Wang <wxt@rock-chips.com> - 2016-01-28 09:50 +0100
  [PATCH v4 8/9] ASoC: rt5616: add the mclk for the codec driver Caesar Wang <wxt@rock-chips.com> - 2016-01-28 09:50 +0100
  [PATCH v4 1/9] ARM: dts: rockchip: add the leds control for kylin board Caesar Wang <wxt@rock-chips.com> - 2016-01-28 09:50 +0100
    Re: [PATCH v4 1/9] ARM: dts: rockchip: add the leds control for kylin board Heiko Stuebner <heiko@sntech.de> - 2016-01-31 11:50 +0100
      Re: [PATCH v4 1/9] ARM: dts: rockchip: add the leds control for kylin  board Caesar Wang <caesar.upstream@gmail.com> - 2016-02-01 07:50 +0100
  [PATCH v4 3/9] clk: rockchip: rk3036: fix and add node id for emac clock Caesar Wang <wxt@rock-chips.com> - 2016-01-28 09:50 +0100
  [PATCH v4 4/9] ARM: dts: rockchip: add support emac for RK3036 Caesar Wang <wxt@rock-chips.com> - 2016-01-28 09:50 +0100
  [PATCH v4.1 6/9] ASoC: rt5616: add mclk property for rt5616 document Caesar Wang <wxt@rock-chips.com> - 2016-01-31 10:20 +0100
    Re: [PATCH v4.1 6/9] ASoC: rt5616: add mclk property for rt5616  document Rob Herring <robh@kernel.org> - 2016-02-01 15:50 +0100
  [PATCH v4.1 9/9] ARM: dts: rockchip: support the spi for rk3036 Caesar Wang <wxt@rock-chips.com> - 2016-02-01 08:40 +0100

csiph-web